summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2018-03-29 22:25:09 +0200
committerTor Andersson <tor.andersson@artifex.com>2018-04-24 16:47:43 +0200
commit51b8205a513e86c62121a927a067632c1a933839 (patch)
treec2882a6c253a715bfc2ea72854c75350f0b2024b /scripts
parent67a7449fc1f186f318942b9c6b8d66d4458b7d87 (diff)
downloadmupdf-51b8205a513e86c62121a927a067632c1a933839.tar.xz
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.
Diffstat (limited to 'scripts')
-rw-r--r--scripts/namedump.c99
1 files changed, 0 insertions, 99 deletions
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 <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-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 <in-file> <public header> <private header>\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;
-}