From 9847614871e861c216425b95a8300dba37b0f6e6 Mon Sep 17 00:00:00 2001 From: grm Date: Sun, 2 Mar 2025 13:53:54 +0200 Subject: Also improve midi and add tt for templating --- src/tt.c | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 src/tt.c (limited to 'src/tt.c') diff --git a/src/tt.c b/src/tt.c new file mode 100644 index 0000000..01c9614 --- /dev/null +++ b/src/tt.c @@ -0,0 +1,124 @@ +#include +#include +#include +#include +#include +#include + +#define DEFAULT_DELIMITER "$" + +void compile_c_code(char * s) { + printf("%.*s\n", (int) strlen(s), s); +} + +void compile_byte_array(char * s) { + printf("write(OUT, \""); + uint64_t slen = strlen(s); + for (uint64_t i = 0; i < slen; ++i) { + printf("\\x%02x", s[i]); + } + printf("\", %lu);\n", strlen(s)); +} + +char *read_file_to_string(const char *filename) { + FILE *file = fopen(filename, "rb"); + if (!file) { + perror("Error opening file"); + return NULL; + } + + fseek(file, 0, SEEK_END); + long file_size = ftell(file); + rewind(file); + + char *buffer = (char *)malloc(file_size + 1); + if (!buffer) { + perror("Memory allocation failed"); + fclose(file); + return NULL; + } + + fread(buffer, 1, file_size, file); + buffer[file_size] = '\0'; + + fclose(file); + return buffer; +} + +#define CHARSET_SIZE 128 // Covering standard ASCII characters + +int print_good_delimiters(const char * s) { + int seen[CHARSET_SIZE] = {0}; // Array to track seen characters + + size_t len = strlen(s); + for (size_t i = 0; i < len; i++) { + if (s[i] >= 0 && (int)s[i] < CHARSET_SIZE) { + seen[(int)s[i]] = 1; + } + } + + // Define the characters to check: A-Za-z0-9 and common symbols + char *valid_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_=+[{]}\\|;:'\",<.>/?`~"; + + int flag = 0; + printf("Good options for delimiters:\n"); + for (int i = 0; valid_chars[i] != '\0'; i++) { + if (!seen[(unsigned char)valid_chars[i]]) { + putchar(valid_chars[i]); + flag++; + } + } + if (!flag) { + printf(" :( none found, compromises shall be made"); + } + putchar('\n'); + + return 0; +} + + +int main(int argc, char *argv[]) +{ + if (argc < 2) { + fprintf(stderr, "Usage: %s