summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2017-03-16 11:50:41 +0100
committerTor Andersson <tor.andersson@artifex.com>2017-03-21 22:28:02 +0100
commit86d07c5bd8cbd0ddae3b5fe42cf0410295296748 (patch)
tree3236232b555ef9f71e9545c51a9107767de75b98 /scripts
parent87b0a4d253ab1549b351389f658238fe32a28da1 (diff)
downloadmupdf-86d07c5bd8cbd0ddae3b5fe42cf0410295296748.tar.xz
Replace fontdump, bin2hex and cquote with one tool: hexdump.
Still need specialty tools for namedump and cmapdump.
Diffstat (limited to 'scripts')
-rw-r--r--scripts/bin2hex.c99
-rw-r--r--scripts/cquote.c134
-rw-r--r--scripts/hexdump.c (renamed from scripts/fontdump.c)37
3 files changed, 19 insertions, 251 deletions
diff --git a/scripts/bin2hex.c b/scripts/bin2hex.c
deleted file mode 100644
index f7b9d8cf..00000000
--- a/scripts/bin2hex.c
+++ /dev/null
@@ -1,99 +0,0 @@
-/* bin2hex.c -- Turn the contents of a file into an array of unsigned chars */
-
-#include <stdio.h>
-#include <string.h>
-
-/* We never want to build memento versions of the cquote util */
-#undef MEMENTO
-
-static void
-clean(char *p)
-{
- while (*p)
- {
- if ((*p == '/') || (*p == '.') || (*p == '\\') || (*p == '-'))
- *p = '_';
- p ++;
- }
-}
-
-int
-main(int argc, char **argv)
-{
- FILE *fi, *fo;
- char name[256];
- char *realname;
- int i, j, c;
-
- if (argc < 3)
- {
- fprintf(stderr, "usage: bin2hex output.h lots of text files\n");
- return 1;
- }
-
- fo = fopen(argv[1], "wb");
- if (!fo)
- {
- fprintf(stderr, "cquote: could not open output file '%s'\n", argv[1]);
- return 1;
- }
-
- fprintf(fo, "/* This is an automatically generated file. Do not edit. */\n");
-
- for (i = 2; i < argc; i++)
- {
- realname = strrchr(argv[i], '/');
- if (!realname)
- realname = strrchr(argv[i], '\\');
- if (realname)
- realname ++;
- else
- realname = argv[i];
-
- if (strlen(realname) > (sizeof name - 1))
- {
- fprintf(stderr, "bin2hex: file name too long\n");
- if (fclose(fo))
- {
- fprintf(stderr, "bin2hex: could not close output file '%s'\n", argv[1]);
- return 1;
- }
- return 1;
- }
-
- strcpy(name, realname);
- clean(name);
-
- fi = fopen(argv[i], "rb");
-
- j = 0;
- while ((c = fgetc(fi)) != EOF)
- {
- if (j != 0)
- {
- fputc(',', fo);
- fputc(j%8 == 0 ? '\n' : ' ', fo);
- }
-
- fprintf(fo, "0x%02x", c);
- j++;
- }
-
- fputc('\n', fo);
-
- if (fclose(fi))
- {
- fprintf(stderr, "bin2hex: could not close input file '%s'\n", argv[i]);
- return 1;
- }
-
- }
-
- if (fclose(fo))
- {
- fprintf(stderr, "bin2hex: could not close output file '%s'\n", argv[1]);
- return 1;
- }
-
- return 0;
-}
diff --git a/scripts/cquote.c b/scripts/cquote.c
deleted file mode 100644
index 4544d2e1..00000000
--- a/scripts/cquote.c
+++ /dev/null
@@ -1,134 +0,0 @@
-/* cquote.c -- Turn the contents of a file into a quoted string */
-
-#include <stdio.h>
-#include <string.h>
-
-/* We never want to build memento versions of the cquote util */
-#undef MEMENTO
-
-static void
-clean(char *p)
-{
- while (*p)
- {
- if ((*p == '/') || (*p == '.') || (*p == '\\') || (*p == '-'))
- *p = '_';
- p ++;
- }
-}
-
-int
-main(int argc, char **argv)
-{
- FILE *fi, *fo;
- char name[256];
- char *realname;
- int i, c;
- int bol = 1;
-
- if (argc < 3)
- {
- fprintf(stderr, "usage: cquote output.c lots of text files\n");
- return 1;
- }
-
- fo = fopen(argv[1], "wb");
- if (!fo)
- {
- fprintf(stderr, "cquote: could not open output file '%s'\n", argv[1]);
- return 1;
- }
-
- fprintf(fo, "/* This is an automatically generated file. Do not edit. */\n");
-
- for (i = 2; i < argc; i++)
- {
- realname = strrchr(argv[i], '/');
- if (!realname)
- realname = strrchr(argv[i], '\\');
- if (realname)
- realname ++;
- else
- realname = argv[i];
-
- if (strlen(realname) > (sizeof name - 1))
- {
- fprintf(stderr, "cquote: file name too long\n");
- if (fclose(fo))
- {
- fprintf(stderr, "cquote: could not close output file '%s'\n", argv[1]);
- return 1;
- }
- return 1;
- }
-
- strcpy(name, realname);
- clean(name);
-
- fi = fopen(argv[i], "rb");
-
- fprintf(fo, "\n/* %s */\n\n", name);
-
- c = fgetc(fi);
- while (c != EOF)
- {
- int eol = 0;
-
- if (bol)
- {
- fputc('\"', fo);
- bol = 0;
- }
-
- switch (c)
- {
- case '\"':
- fprintf(fo, "\\\"");
- break;
-
- case '\\':
- fprintf(fo, "\\\\");
- break;
-
- case '\r':
- case '\n':
- eol = 1;
- break;
-
- default:
- fputc(c, fo);
- break;
- }
-
- if (eol)
- {
- fprintf(fo, "\\n\"\n");
- while ((c = fgetc(fi)) == '\r' || c == '\n')
- ;
- bol = 1;
- }
- else
- {
- c = fgetc(fi);
- }
- }
-
- if (!bol)
- fprintf(fo, "\\n\"\n");
-
- if (fclose(fi))
- {
- fprintf(stderr, "cquote: could not close input file '%s'\n", argv[i]);
- return 1;
- }
-
- }
-
- if (fclose(fo))
- {
- fprintf(stderr, "cquote: could not close output file '%s'\n", argv[1]);
- return 1;
- }
-
- return 0;
-}
diff --git a/scripts/fontdump.c b/scripts/hexdump.c
index 4669b6ee..728afc33 100644
--- a/scripts/fontdump.c
+++ b/scripts/hexdump.c
@@ -1,4 +1,4 @@
-/* fontdump.c -- an "xxd -i" workalike for dumping binary fonts as source code */
+/* hexdump.c -- an "xxd -i" workalike for dumping binary files as source code */
#include <stdio.h>
#include <stdlib.h>
@@ -29,21 +29,21 @@ main(int argc, char **argv)
{
FILE *fo;
FILE *fi;
- char fontname[256];
+ char filename[256];
char *basename;
char *p;
int i, size;
if (argc < 3)
{
- fprintf(stderr, "usage: fontdump output.c input.dat\n");
+ fprintf(stderr, "usage: hexdump output.c input.dat\n");
return 1;
}
fo = fopen(argv[1], "wb");
if (!fo)
{
- fprintf(stderr, "fontdump: could not open output file '%s'\n", argv[1]);
+ fprintf(stderr, "hexdump: could not open output file '%s'\n", argv[1]);
return 1;
}
@@ -61,7 +61,7 @@ main(int argc, char **argv)
if (!fi)
{
fclose(fo);
- fprintf(stderr, "fontdump: could not open input file '%s'\n", argv[i]);
+ fprintf(stderr, "hexdump: could not open input file '%s'\n", argv[i]);
return 1;
}
@@ -73,16 +73,16 @@ main(int argc, char **argv)
else
basename = argv[i];
- if (strlen(basename) >= sizeof(fontname))
+ if (strlen(basename) >= sizeof(filename))
{
fclose(fi);
fclose(fo);
- fprintf(stderr, "fontdump: filename '%s' too long\n", basename);
+ fprintf(stderr, "hexdump: filename '%s' too long\n", basename);
return 1;
}
- strcpy(fontname, basename);
- for (p = fontname; *p; ++p)
+ strcpy(filename, argv[i]);
+ for (p = filename; *p; ++p)
{
if (*p == '/' || *p == '.' || *p == '\\' || *p == '-')
*p = '_';
@@ -93,19 +93,20 @@ main(int argc, char **argv)
fseek(fi, 0, SEEK_SET);
fprintf(fo, "\n#ifdef HAVE_INCBIN\n");
- fprintf(fo, "const int fz_font_%s_size = %d;\n", fontname, size);
+ fprintf(fo, "const int fz_%s_size = %d;\n", filename, size);
+ fprintf(fo, "extern const char fz_%s[];\n", filename);
fprintf(fo, "asm(\".section .rodata\");\n");
- fprintf(fo, "asm(\".global fz_font_%s\");\n", fontname);
- fprintf(fo, "asm(\".type fz_font_%s STT_OBJECT\");\n", fontname);
- fprintf(fo, "asm(\".size fz_font_%s, %d\");\n", fontname, size);
+ fprintf(fo, "asm(\".global fz_%s\");\n", filename);
+ fprintf(fo, "asm(\".type fz_%s STT_OBJECT\");\n", filename);
+ fprintf(fo, "asm(\".size fz_%s, %d\");\n", filename, size);
fprintf(fo, "asm(\".balign 64\");\n");
- fprintf(fo, "asm(\"fz_font_%s:\");\n", fontname);
+ fprintf(fo, "asm(\"fz_%s:\");\n", filename);
fprintf(fo, "asm(\".incbin \\\"%s\\\"\");\n", argv[i]);
fprintf(fo, "#else\n");
- fprintf(fo, "const int fz_font_%s_size = %d;\n", fontname, size);
- fprintf(fo, "const char fz_font_%s[] = {\n", fontname);
+ fprintf(fo, "const int fz_%s_size = %d;\n", filename, size);
+ fprintf(fo, "const char fz_%s[] = {\n", filename);
hexdump(fo, fi);
- fprintf(fo, "};\n");
+ fprintf(fo, "0};\n"); /* zero-terminate so we can hexdump text files into C strings */
fprintf(fo, "#endif\n");
fclose(fi);
@@ -113,7 +114,7 @@ main(int argc, char **argv)
if (fclose(fo))
{
- fprintf(stderr, "fontdump: could not close output file '%s'\n", argv[1]);
+ fprintf(stderr, "hexdump: could not close output file '%s'\n", argv[1]);
return 1;
}