89 lines
2.2 KiB
C
89 lines
2.2 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include "tstring.h"
|
|
#include "futil.h"
|
|
|
|
int main(int argc, char** argv) {
|
|
char input[1024] = { 0 };
|
|
char glyph[8] = { 0 };
|
|
char* file;
|
|
size_t bytesRead;
|
|
|
|
TString* string = TStringCreate();
|
|
|
|
while(1) {
|
|
printf("> ");
|
|
fgets(input, sizeof input, stdin);
|
|
|
|
input[strlen(input) - 1] = '\0';
|
|
|
|
if (input[0] == 'q') break;
|
|
|
|
if (input[0] == 'p') {
|
|
if (input[1] == '\0') TStringPrintDetails(string, 0);
|
|
else TStringPrintDetails(string, 1);
|
|
continue;
|
|
}
|
|
|
|
if (input[0] == 'i') {
|
|
printf("Select index: ");
|
|
fgets(input, sizeof input, stdin);
|
|
|
|
int num = strtol(input, NULL, 10);
|
|
|
|
printf("Enter text to insert at index %d: ", num);
|
|
|
|
fgets(input, sizeof input, stdin);
|
|
|
|
input[strlen(input) - 1] = '\0';
|
|
|
|
TStringInsertText(input, num, string);
|
|
|
|
continue;
|
|
}
|
|
|
|
if (input[0] == 'f') {
|
|
printf("Enter file path to open: ");
|
|
fgets(input, sizeof input, stdin);
|
|
input[strlen(input) - 1] = '\0';
|
|
|
|
if (ReadAllString(input, &file, &bytesRead)) {
|
|
TStringAppendText(file, string);
|
|
printf("Read %ld byte(s)\n", bytesRead);
|
|
free(file);
|
|
}
|
|
|
|
continue;
|
|
}
|
|
|
|
if (input[0] == 'r') {
|
|
if (input[1] != '\0') {
|
|
printf("Select index: ");
|
|
fgets(input, sizeof input, stdin);
|
|
|
|
int num = strtol(input, NULL, 10);
|
|
printf("Enter count: ");
|
|
|
|
fgets(input, sizeof input, stdin);
|
|
|
|
int count = strtol(input, NULL, 10);
|
|
|
|
TStringRemoveRange(num, count, string);
|
|
|
|
continue;
|
|
}
|
|
TStringPop(glyph, string);
|
|
printf("Popped '%s'\n", glyph);
|
|
continue;
|
|
}
|
|
|
|
TStringAppendText(input, string);
|
|
}
|
|
//fgets(glyph, 10, stdin);
|
|
|
|
//glyph[strlen(glyph) - 1] = 0;
|
|
|
|
//printf("Width %d byte(s).\n", GetGlyphByteWidth(glyph));
|
|
TStringFree(string);
|
|
} |