#include #include #include #include "tstring.h" #include "futil.h" int main(int argc, char** argv) { char input[1024] = { 0 }; char glyph[8] = { 0 }; char buffer[11] = { 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; } if (input[0] == 'g') { 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); //char* text = TStringGetStringRange(num, count, string); TStringGetStringRange(string, num, count, sizeof buffer, buffer); printf("Returned String:\n'%s'\n", buffer); for (int i = 0; i < sizeof buffer; i++) printf("%02X ", buffer[i] & 0xFF); printf("\n"); continue; } } if (input[0] == 't') { TStringPrintDetails(string, 0); TStringTruncate(string); printf("TString truncated\n"); continue; } TStringAppendText(input, string); } TStringFree(string); }