diff options
author | schnetter <schnetter@83718e91-0e4f-0410-abf4-91180603181f> | 2005-08-22 12:05:04 +0000 |
---|---|---|
committer | schnetter <schnetter@83718e91-0e4f-0410-abf4-91180603181f> | 2005-08-22 12:05:04 +0000 |
commit | c13b863133b6b1e841689d6751bb38f96e9643d1 (patch) | |
tree | fe1391f058b2c55d86f7b3969d7cab85326c2e6e /src/util | |
parent | f7c121bd07e0936ca5faabc011d44053da807f18 (diff) |
Initialise large data arrays in several smaller chunks, not all at
once. Still does it in one file, which may still be problematic.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusUtils/Formaline/trunk@53 83718e91-0e4f-0410-abf4-91180603181f
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/makeblob.c | 152 | ||||
-rw-r--r-- | src/util/makemetablob.c | 13 |
2 files changed, 128 insertions, 37 deletions
diff --git a/src/util/makeblob.c b/src/util/makeblob.c index f77e8a1..80759bb 100644 --- a/src/util/makeblob.c +++ b/src/util/makeblob.c @@ -8,51 +8,135 @@ main (int argc, char * * argv) { char const * arrangement; char const * thorn; + char const * output; + char filename [10000]; + FILE * file; + int fcount; + int done; unsigned long count; + unsigned long const items_per_line = 16; + unsigned long const items_per_file = 1024 * 1024; - assert (argc == 3); + assert (argc == 4); arrangement = argv[1]; - thorn = argv[2]; assert (arrangement); + thorn = argv[2]; assert (thorn); + output = argv[3]; + assert (output); + +#if 0 + snprintf (filename, sizeof filename, "%s.c", output); + file = fopen (filename, "w"); + assert (file); +#endif + file = stdout; - printf ("/* This is an auto-generated file -- do not edit */\n"); - printf ("\n"); - printf ("#include <stddef.h>\n"); - printf ("\n"); - printf ("struct sourceinfo\n"); - printf ("{\n"); - printf (" char const * data;\n"); - printf (" size_t length;\n"); - printf (" char const * arrangement;\n"); - printf (" char const * thorn;\n"); - printf ("};\n"); - printf ("\n"); - printf ("static char const data [] = {"); - for (count = 0; ; ++ count) + fprintf (file, "/* This is an auto-generated file -- do not edit */\n"); + fprintf (file, "\n"); + fprintf (file, "#include <stddef.h>\n"); + fprintf (file, "\n"); + fprintf (file, "struct datainfo\n"); + fprintf (file, "{\n"); + fprintf (file, " unsigned char const * data;\n"); + fprintf (file, " size_t length;\n"); + fprintf (file, " struct datainfo const * next;\n"); + fprintf (file, "};\n"); + fprintf (file, "\n"); + fprintf (file, "struct sourceinfo\n"); + fprintf (file, "{\n"); + fprintf (file, " struct datainfo const * first;\n"); + fprintf (file, " char const * arrangement;\n"); + fprintf (file, " char const * thorn;\n"); + fprintf (file, "};\n"); + + fprintf (file, "\n"); + fprintf (file, "struct datainfo const cactus_data_%04d_%s;\n", 0, thorn); + fprintf (file, "struct sourceinfo const cactus_source_%s =\n", thorn); + fprintf (file, "{\n"); + fprintf (file, " & cactus_data_%04d_%s,\n", 0, thorn); + fprintf (file, " \"%s\",\n", arrangement); + fprintf (file, " \"%s\"\n", thorn); + fprintf (file, "};\n"); + + for (fcount = 0, done = 0; ! done; ++ fcount) { - int const ch = getc (stdin); - if (feof (stdin)) break; - if (ferror (stdin)) return 1; - if (count != 0) { - printf (","); +#if 0 + snprintf (filename, sizeof filename, "%s-%04d.c", output, fcount); + file = fopen (filename, "w"); + assert (file); + + fprintf (file, "/* This is an auto-generated file -- do not edit */\n"); + fprintf (file, "\n"); + fprintf (file, "#include <stddef.h>\n"); + fprintf (file, "\n"); + fprintf (file, "struct datainfo\n"); + fprintf (file, "{\n"); + fprintf (file, " unsigned char const * data;\n"); + fprintf (file, " size_t length;\n"); + fprintf (file, " struct datainfo const * next;\n"); + fprintf (file, "};\n"); + fprintf (file, "\n"); + fprintf (file, "struct sourceinfo\n"); + fprintf (file, "{\n"); + fprintf (file, " struct datainfo const * first;\n"); + fprintf (file, " char const * arrangement;\n"); + fprintf (file, " char const * thorn;\n"); + fprintf (file, "};\n"); +#endif + + fprintf (file, "\n"); + fprintf (file, "static unsigned char const data_%04d [] = {", fcount); + for (count = 0; count < items_per_file; ++ count) + { + int const ch = getc (stdin); + if (feof (stdin)) + { + done = 1; + break; + } + if (ferror (stdin)) return 1; + if (count != 0) + { + fprintf (file, ","); + } + if (count % items_per_line == 0) + { + fprintf (file, "\n"); + } + fprintf (file, "%3d", ch); } - if (count % 16 == 0) + fprintf (file, "\n"); + fprintf (file, "};\n"); + fprintf (file, "\n"); + if (! done) { - printf ("\n"); + fprintf (file, "struct datainfo const cactus_data_%04d_%s;\n", + fcount + 1, thorn); } - printf ("%3d", ch); + fprintf (file, "struct datainfo const cactus_data_%04d_%s =\n", + fcount, thorn); + fprintf (file, "{\n"); + fprintf (file, " data_%04d,\n", fcount); + fprintf (file, " %luUL,\n", count); + if (! done) + { + fprintf (file, " & cactus_data_%04d_%s\n", fcount + 1, thorn); + } + else + { + fprintf (file, " NULL\n"); + } + fprintf (file, "};\n"); + +#if 0 + fclose (file); +#endif } - printf ("\n"); - printf ("};\n"); - printf ("\n"); - printf ("struct sourceinfo const cactus_source_%s =\n", thorn); - printf ("{\n"); - printf (" data,\n"); - printf (" %luUL,\n", count); - printf (" \"%s\",\n", arrangement); - printf (" \"%s\"\n", thorn); - printf ("};\n"); + +#if 0 + fclose (file); +#endif return 0; } diff --git a/src/util/makemetablob.c b/src/util/makemetablob.c index bc871a6..e5f0d52 100644 --- a/src/util/makemetablob.c +++ b/src/util/makemetablob.c @@ -11,10 +11,16 @@ main (int argc, char * * argv) printf ("\n"); printf ("#include <stddef.h>\n"); printf ("\n"); - printf ("struct sourceinfo\n"); + printf ("struct datainfo\n"); printf ("{\n"); - printf (" char const * data;\n"); + printf (" unsigned char const * data;\n"); printf (" size_t length;\n"); + printf (" struct datainfo const * next;\n"); + printf ("};\n"); + printf ("\n"); + printf ("struct sourceinfo\n"); + printf ("{\n"); + printf (" struct datainfo const * first;\n"); printf (" char const * arrangement;\n"); printf (" char const * thorn;\n"); printf ("};\n"); @@ -27,7 +33,8 @@ main (int argc, char * * argv) printf ("struct sourceinfo const * const cactus_source [] = {"); for (count = 1; count < argc; ++ count) { - if (count != 1) { + if (count != 1) + { printf (","); } printf ("\n"); |