From 48d76596883b569d9736d9a4267665ed1a9262bb Mon Sep 17 00:00:00 2001
From: dcw <dcw>
Date: Tue, 28 Nov 1989 16:08:43 +0000
Subject: [PATCH] major change: fields now unionised. also: TRUE and FALSE were
 wrong way round (oops) and I have removed ABORT.. explicit error mesgs on
 stderr now.

---
 decs.c | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)

diff --git a/decs.c b/decs.c
index a142c20..9b1242c 100644
--- a/decs.c
+++ b/decs.c
@@ -35,8 +35,8 @@ static void init( h, c, basename ) FILE *c, *h; char *basename;
 	fprintf( h, " */\n\n");
 	fprintf( h, "typedef char *string;\n\n" );
 	fprintf( h, "typedef char BOOL;\n" );
-	fprintf( h, "#define TRUE 0\n" );
-	fprintf( h, "#define FALSE 1\n\n" );
+	fprintf( h, "#define TRUE 1\n" );
+	fprintf( h, "#define FALSE 0\n\n" );
 
 	fprintf( c, "/*\n" );
 	fprintf( c, "\tAutomatically Generated by DataDec\n" );
@@ -45,8 +45,7 @@ static void init( h, c, basename ) FILE *c, *h; char *basename;
 	fprintf( c, "#include <stdio.h>\n" );
 	fprintf( c, "#include \"%s.h\"\n\n\n", basename );
 
-	fprintf( c, "#define NEW(t) ((t *)malloc(sizeof(t)))\n\n" );
-	fprintf( c, "#define ABORT(m) {printf m; exit(1);}\n\n\n" );
+	fprintf( c, "#define NEW(t) ((t *)malloc(sizeof(t)))\n\n\n" );
 }
 
 
@@ -77,16 +76,21 @@ static void data_decls( f, dl ) FILE *f; declnlist dl;
 		}
 		fprintf( f, "\nstruct %s_str {\n", name );
 		fprintf( f, "\tint\ttag;\n" );
+		fprintf( f, "\tunion {\n" );
 		for( s = d->shapes; s; s=s->next )
 		{
-			tag = s->tagname;
-			for( p = s->params; p; p=p->next )
+			if( s->params )
 			{
-				fprintf( f, "\t%s\t%s_%s;\n",
-					p->type, tag, p->name );
+				fprintf( f, "\t\tstruct {\n" );
+				for( p = s->params; p; p=p->next )
+				{
+					fprintf( f, "\t\t\t%s\t%s;\n",
+						p->type, p->name );
+				}
+				fprintf( f, "\t\t} %s;\n", s->tagname );
 			}
 		}
-		fprintf( f, "};\n\n" );
+		fprintf( f, "\t} u;\n};\n\n" );
 	}
 }
 
@@ -175,7 +179,7 @@ static void cons_fn_body( f, name, s ) FILE *f; char *name; shapelist s;
 	fprintf( f, "\tnew->tag = %s_%s_tag;\n", name, tag );
 	for( p=s->params; p; p=p->next )
 	{
-		fprintf( f, "\tnew->%s_%s = %s;\n", tag, p->name, p->name );
+		fprintf( f, "\tnew->u.%s.%s = %s;\n", tag, p->name, p->name );
 	}
 	fprintf( f, "\treturn new;\n}\n" );
 }
@@ -203,7 +207,7 @@ static void print_param( f, shape, ftype, fname ) FILE *f; char *shape, *ftype,
 {
 	char pname[200];
 
-	sprintf( pname, "p->%s_%s", shape, fname );
+	sprintf( pname, "p->u.%s.%s", shape, fname );
 	if( streq( ftype, "int" ) )
 	{
 		fprintf( f, "\t\tfprintf( f, \"%%d\", %s );\n", pname );
@@ -276,10 +280,11 @@ static void print_fns( f, d ) FILE *f ; declnlist d;
 			print_fn_shape( f, d->name, s );
 		}
 		fprintf( f, "\tdefault:\n" );
+		fprintf( f, "\t\tfprintf( stderr," );
 		fprintf( f,
-		"\tABORT((\"print_%s: impossible tag %%d\\n\",p->tag));\n",
-			d->name );
-		fprintf( f, "\t}\n}\n\n" );
+		" \"print_%s: impossible tag %%d\\n\", p->tag );\n",
+		d->name );
+		fprintf( f, "\t\texit(1);\n\t}\n}\n\n" );
 	}
 }
 
-- 
GitLab