aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorschnetter <schnetter@83718e91-0e4f-0410-abf4-91180603181f>2006-04-02 18:25:48 +0000
committerschnetter <schnetter@83718e91-0e4f-0410-abf4-91180603181f>2006-04-02 18:25:48 +0000
commit8d6781e6c7c7ddf8c549019a8c4c11ad18987e89 (patch)
treef15dbd25099f009b69f01e89b28f36f04ad221ac /src/util
parentabe332db19896e7a172261cf24f4d705fb2a2803 (diff)
Convert helper programmes from C to perl to make them more portable.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusUtils/Formaline/trunk@71 83718e91-0e4f-0410-abf4-91180603181f
Diffstat (limited to 'src/util')
-rw-r--r--src/util/makeblob.c144
-rwxr-xr-xsrc/util/makeblob.pl93
-rw-r--r--src/util/makemetablob.c48
-rwxr-xr-xsrc/util/makemetablob.pl44
4 files changed, 137 insertions, 192 deletions
diff --git a/src/util/makeblob.c b/src/util/makeblob.c
deleted file mode 100644
index 15af99f..0000000
--- a/src/util/makeblob.c
+++ /dev/null
@@ -1,144 +0,0 @@
-/* $Header$ */
-
-#include <assert.h>
-#include <stdio.h>
-
-int
-main (int argc, char * * argv)
-{
- char const * arrangement;
- char const * thorn;
- char const * output;
-#if 0
- char filename [10000];
-#endif
- 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 == 4);
- arrangement = argv[1];
- 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;
-
- 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)
- {
-#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);
- }
- fprintf (file, "\n");
- fprintf (file, "};\n");
- fprintf (file, "\n");
- if (! done)
- {
- fprintf (file, "struct datainfo const cactus_data_%04d_%s;\n",
- fcount + 1, thorn);
- }
- 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
- }
-
-#if 0
- fclose (file);
-#endif
-
- return 0;
-}
diff --git a/src/util/makeblob.pl b/src/util/makeblob.pl
new file mode 100755
index 0000000..11f5aa6
--- /dev/null
+++ b/src/util/makeblob.pl
@@ -0,0 +1,93 @@
+#! /usr/bin/perl -w
+# $Header$
+
+use strict;
+
+my $items_per_line = 16;
+my $items_per_file = 1024 * 1024;
+
+$#ARGV == 2 or die;
+
+my $arrangement = $ARGV[0];
+$arrangement ne '' or die;
+my $thorn = $ARGV[1];
+$thorn ne '' or die;
+my $output = $ARGV[2];
+$output ne '' or die;
+
+print <<EOF;
+/* This is an auto-generated file -- do not edit */
+
+\#include <stddef.h>
+
+struct datainfo
+{
+ unsigned char const * data;
+ size_t length;
+ struct datainfo const * next;
+};
+
+struct sourceinfo
+{
+ struct datainfo const * first;
+ char const * arrangement;
+ char const * thorn;
+};
+
+struct datainfo const cactus_data_0000_$thorn;
+struct sourceinfo const cactus_source_$thorn =
+{
+ & cactus_data_0000_$thorn,
+ \"$arrangement\",
+ \"$thorn\"
+};
+EOF
+
+my $done = 0;
+for (my $fcount = 0; ! $done; ++ $fcount)
+{
+ printf ("\n");
+ printf ("static unsigned char const data_%04d [] = {", $fcount);
+ my $count;
+ for ($count = 0; $count < $items_per_file; ++ $count)
+ {
+ my $ch = getc;
+ if (! defined $ch)
+ {
+ $done = 1;
+ last;
+ }
+ if ($count != 0)
+ {
+ printf (",");
+ }
+ if ($count % $items_per_line == 0)
+ {
+ printf ("\n");
+ printf (" ");
+ }
+ printf ("%3d", ord $ch);
+ }
+ printf ("\n");
+ printf ("};\n");
+ printf ("\n");
+ if (! $done)
+ {
+ printf ("struct datainfo const cactus_data_%04d_%s;\n",
+ $fcount + 1, $thorn);
+ }
+ printf ("struct datainfo const cactus_data_%04d_%s =\n",
+ $fcount, $thorn);
+ printf ("{\n");
+ printf (" data_%04d,\n", $fcount);
+ printf (" %dUL,\n", $count);
+ if (! $done)
+ {
+ printf (" & cactus_data_%04d_%s\n", $fcount + 1, $thorn);
+ }
+ else
+ {
+ printf (" NULL\n");
+ }
+ printf ("};\n");
+}
diff --git a/src/util/makemetablob.c b/src/util/makemetablob.c
deleted file mode 100644
index e5f0d52..0000000
--- a/src/util/makemetablob.c
+++ /dev/null
@@ -1,48 +0,0 @@
-/* $Header$ */
-
-#include <stdio.h>
-
-int
-main (int argc, char * * argv)
-{
- int count;
-
- printf ("/* This is an auto-generated file -- do not edit */\n");
- printf ("\n");
- printf ("#include <stddef.h>\n");
- printf ("\n");
- printf ("struct datainfo\n");
- printf ("{\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");
- printf ("\n");
- for (count = 1; count < argc; ++ count)
- {
- printf ("extern struct sourceinfo cactus_source_%s;\n", argv[count]);
- }
- printf ("\n");
- printf ("struct sourceinfo const * const cactus_source [] = {");
- for (count = 1; count < argc; ++ count)
- {
- if (count != 1)
- {
- printf (",");
- }
- printf ("\n");
- printf (" & cactus_source_%s", argv[count]);
- }
- printf ("\n");
- printf ("};\n");
- printf ("size_t const cactus_source_length = %d;\n", argc - 1);
-
- return 0;
-}
diff --git a/src/util/makemetablob.pl b/src/util/makemetablob.pl
new file mode 100755
index 0000000..49ffcde
--- /dev/null
+++ b/src/util/makemetablob.pl
@@ -0,0 +1,44 @@
+#! /usr/bin/perl -w
+# $Header$
+
+use strict;
+
+print <<EOF;
+/* This is an auto-generated file -- do not edit */
+
+\#include <stddef.h>
+
+struct datainfo
+{
+ unsigned char const * data;
+ size_t length;
+ struct datainfo const * next;
+};
+
+struct sourceinfo
+{
+ struct datainfo const * first;
+ char const * arrangement;
+ char const * thorn;
+};
+
+EOF
+
+for (my $count = 0; $count <= $#ARGV; ++ $count)
+{
+ printf ("extern struct sourceinfo cactus_source_%s;\n", $ARGV[$count]);
+}
+printf ("\n");
+printf ("struct sourceinfo const * const cactus_source [] = {");
+for (my $count = 0; $count <= $#ARGV; ++ $count)
+{
+ if ($count != 0)
+ {
+ printf (",");
+ }
+ printf ("\n");
+ printf (" & cactus_source_%s", $ARGV[$count]);
+}
+printf ("\n");
+printf ("};\n");
+printf ("size_t const cactus_source_length = %d;\n", $#ARGV + 1);