From 51b8205a513e86c62121a927a067632c1a933839 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Thu, 29 Mar 2018 22:25:09 +0200 Subject: Remove need for namedump by using macros and preprocessor. Add a PDF_NAME(Foo) macro that evaluates to a pdf_obj for /Foo. Use the C preprocessor to create the enum values and string table from one include file instead of using a separate code generator tool. --- scripts/namedump.c | 99 ------------------------------------------------------ 1 file changed, 99 deletions(-) delete mode 100644 scripts/namedump.c (limited to 'scripts') diff --git a/scripts/namedump.c b/scripts/namedump.c deleted file mode 100644 index 46d4d4e3..00000000 --- a/scripts/namedump.c +++ /dev/null @@ -1,99 +0,0 @@ -/* namedump.c -- parse an alphabetically sorted list of PDF names - * and generate header files from it. */ - -#include -#include -#include - -char buffer[256]; - -static char *get_line(FILE *in) -{ - size_t l; - - if (fgets(buffer, sizeof(buffer), in) == NULL) - { - buffer[0] = 0; - return buffer; - } - l = strlen(buffer); - while (l > 0 && buffer[l-1] <= ' ') - l--; - buffer[l] = 0; - - return buffer; -} - -int -main(int argc, char **argv) -{ - FILE *in; - FILE *out_c; - FILE *out_h; - - if (argc != 4) - { - fprintf(stderr, "Syntax:\nnamedump \n"); - return EXIT_FAILURE; - } - - in = fopen(argv[1], "rb"); - if (!in) - { - fprintf(stderr, "Failed to open '%s' for reading\n", argv[1]); - return EXIT_FAILURE; - } - - out_h = fopen(argv[2], "wb"); - if (!out_h) - { - fprintf(stderr, "Failed to open '%s' for writing\n", argv[2]); - return EXIT_FAILURE; - } - - out_c = fopen(argv[3], "wb"); - if (!out_c) - { - fprintf(stderr, "Failed to open '%s' for writing\n", argv[3]); - return EXIT_FAILURE; - } - - fprintf(out_c, "static const char *PDF_NAMES[] =\n{\n\t\"\",\n"); - - fprintf(out_h, "enum\n{\n\tPDF_OBJ_ENUM__DUMMY,\n"); - - while (!feof(in)) - { - char *line = get_line(in); - if (*line == 0) - continue; - - fprintf(out_c, "\t\"%s\",\n", line); - - { - char *l; - for (l = line; *l; l++) - { - if (*l == '.' || *l == '-') - *l = '_'; - } - } - - fprintf(out_h, "#define PDF_NAME_%s ((pdf_obj *)(intptr_t)PDF_OBJ_ENUM_NAME_%s)\n", line, line); - fprintf(out_h, "\tPDF_OBJ_ENUM_NAME_%s,\n", line); - } - - fprintf(out_h, "#define PDF_OBJ_NAME__LIMIT ((pdf_obj *)(intptr_t)PDF_OBJ_ENUM_NAME__LIMIT)\n\tPDF_OBJ_ENUM_NAME__LIMIT,\n"); - fprintf(out_h, "#define PDF_OBJ_FALSE ((pdf_obj *)(intptr_t)PDF_OBJ_ENUM_BOOL_FALSE)\n\tPDF_OBJ_ENUM_BOOL_FALSE = PDF_OBJ_ENUM_NAME__LIMIT,\n"); - fprintf(out_h, "#define PDF_OBJ_TRUE ((pdf_obj *)(intptr_t)PDF_OBJ_ENUM_BOOL_TRUE)\n\tPDF_OBJ_ENUM_BOOL_TRUE,\n"); - fprintf(out_h, "#define PDF_OBJ_NULL ((pdf_obj *)(intptr_t)PDF_OBJ_ENUM_NULL)\n\tPDF_OBJ_ENUM_NULL,\n"); - fprintf(out_h, "#define PDF_OBJ__LIMIT ((pdf_obj *)(intptr_t)PDF_OBJ_ENUM__LIMIT)\n\tPDF_OBJ_ENUM__LIMIT\n};\n"); - - fprintf(out_c, "};\n"); - - fclose(out_c); - fclose(out_h); - fclose(in); - - return EXIT_SUCCESS; -} -- cgit v1.2.3