From 90adf0efde09cea75dd2f0929dfdd022645a0980 Mon Sep 17 00:00:00 2001 From: ees1dw Date: Mon, 7 Feb 1994 10:58:16 +0000 Subject: [PATCH] trashed dcw.h; replaced assertions with if's etc.. --- datadec.c | 17 +++++++--- decs.c | 92 +++++++++++++++++++++++++++++++++++++++++++----------- lexer.c | 9 ++++-- optimize.c | 48 +++++++++++++++++++++------- parser.c | 7 ++++- struct.c | 20 +++++++++--- 6 files changed, 151 insertions(+), 42 deletions(-) diff --git a/datadec.c b/datadec.c index 1966fcf..b6bab71 100644 --- a/datadec.c +++ b/datadec.c @@ -17,7 +17,8 @@ * which together form a module provided the relevent data types. */ -#include +#include +#include #include "struct.h" #include "lexer.h" #include "parser.h" @@ -25,7 +26,7 @@ #include "optimize.h" -#define MUSTBE(b) ASSERT(b,("Usage: datadec [-vno] outfile [infile]\n")) +#define MUSTBE(b) {if(!(b)){fprintf(stderr,"Usage: datadec [-vno] outfile [infile]\n");exit(1);}} #define NEED_ANOTHER_ARG MUSTBE( IS_ANOTHER_ARG ) #define REQUIRE_NO_MORE_ARGS MUSTBE( argc == arg ) @@ -66,7 +67,9 @@ void main( argc, argv ) int argc; char **argv; opt = TRUE; break; default: - ABORT( ("datadec: illegal option -%c\n",*s) ); + fprintf( stderr, + "datadec: illegal option -%c\n", *s ); + exit(1); } } arg++; @@ -82,8 +85,12 @@ void main( argc, argv ) int argc; char **argv; if( IS_ANOTHER_ARG ) { lexfile = fopen( argv[arg], "r" ); - ASSERT( lexfile != NULL, - ("datadec: can't open '%s'\n",argv[arg]) ); + if( lexfile == NULL ) + { + fprintf( stderr, "datadec: can't open '%s'\n", + argv[arg] ); + exit(1); + } arg++; } else { lexfile = stdin; diff --git a/decs.c b/decs.c index c74cb30..5000cb6 100644 --- a/decs.c +++ b/decs.c @@ -1,4 +1,4 @@ -#include +#include #include "struct.h" #include "decs.h" @@ -99,7 +99,11 @@ static void h_declns( base, exports, init, d ) char *base, *exports; BOOL init; sprintf( tempname, "%s.h", base ); hfile = fopen( tempname, "w" ); - ASSERT( hfile != NULL, ("datadec: can't create '%s'\n",tempname) ); + if( hfile == NULL ) + { + fprintf( stderr, "datadec: can't create '%s'\n", tempname ); + exit(1); + } usefile( hfile ); @@ -160,7 +164,11 @@ static void c_declns( base, globals, begin, d ) char *base, *globals, *begin; de sprintf( tempname, "%s.c", base ); cfile = fopen( tempname, "w" ); - ASSERT( cfile != NULL, ("datadec: can't create '%s'\n",tempname) ); + if( cfile == NULL ) + { + fprintf( stderr, "datadec: can't create '%s'\n", tempname ); + exit(1); + } usefile( cfile ); @@ -431,7 +439,11 @@ static void cons_fn_proto( d, s, prot ) decln d; shapelist s; BOOL prot; paramlist p; BOOL first; - ASSERT( d->Struct, ("cons_fn_proto: d->Struct is false!\n") ); + if( ! d->Struct ) + { + fprintf( stderr, "cons_fn_proto: d->Struct is false!\n" ); + exit(1); + } fprintf( outfile, "extern %s %s_%s( ", d->name, d->name, s->name ); if( prot ) @@ -459,7 +471,11 @@ static void cons_fn( d, s ) decln d; shapelist s; paramlist p; BOOL first; - ASSERT( d->Struct, ("cons_fn: d->Struct is FALSE!\n") ); + if( ! d->Struct ) + { + fprintf( stderr, "cons_fn: d->Struct is FALSE!\n" ); + exit(1); + } fprintf( outfile, "%s %s_%s( ", d->name, d->name, s->name ); first = TRUE; @@ -530,7 +546,11 @@ static void decons_fns_type( d ) decln d; { shapelist s; - ASSERT( d->Struct, ("decons_fns_type: d->Struct is FALSE!\n") ); + if( ! d->Struct ) + { + fprintf( stderr, "decons_fns_type: d->Struct is FALSE!\n" ); + exit(1); + } if( d->ManyShapes ) { @@ -553,9 +573,17 @@ static void decons_fns_type( d ) decln d; static void deconskind_proto( d, prot ) decln d; BOOL prot; { - ASSERT( d->ManyShapes, - ("deconskind_proto: d->ManyShapes is FALSE!\n") ); - ASSERT( d->Struct, ("deconskind_proto: d->Struct is FALSE!\n") ); + if( ! d->ManyShapes ) + { + fprintf( stderr, + "deconskind_proto: d->ManyShapes is FALSE!\n" ); + exit(1); + } + if( ! d->Struct ) + { + fprintf( stderr, "deconskind_proto: d->Struct is FALSE!\n" ); + exit(1); + } fprintf( outfile, "extern kind_of_%s %s_kind( ", d->name, d->name ); if( prot ) @@ -570,8 +598,16 @@ static void deconskind_fn( d ) decln d; { shapelist s = d->shapes; - ASSERT( d->ManyShapes, ("deconskind_fn: d->ManyShapes is FALSE!\n") ); - ASSERT( d->Struct, ("deconskind_fn: d->Struct is FALSE!\n") ); + if( ! d->ManyShapes ) + { + fprintf( stderr, "deconskind_fn: d->ManyShapes is FALSE!\n" ); + exit(1); + } + if( ! d->Struct ) + { + fprintf( stderr, "deconskind_fn: d->Struct is FALSE!\n" ); + exit(1); + } fprintf( outfile, "kind_of_%s %s_kind( this ) %s this;\n", d->name, d->name, d->name ); @@ -607,9 +643,16 @@ static void deconskind_fn( d ) decln d; static void decons_fn_proto( d, s, prot ) decln d; shapelist s; BOOL prot; { - ASSERT( d->Struct, ("decons_fn_proto: d->Struct is FALSE!\n") ); - ASSERT( s->params != NULL, - ("decons_fn_proto: no fields in shape!!\n") ); + if( ! d->Struct ) + { + fprintf( stderr, "decons_fn_proto: d->Struct is FALSE!\n" ); + exit(1); + } + if( s->params == NULL ) + { + fprintf( stderr, "decons_fn_proto: no fields in shape!!\n" ); + exit(1); + } fprintf( outfile, "extern void get_%s_%s(", d->name, s->name ); if( prot ) @@ -630,8 +673,16 @@ static void decons_fn( d, s ) decln d; shapelist s; { paramlist p; - ASSERT( d->Struct, ("decons_fn: d->Struct is FALSE!\n") ); - ASSERT( s->params != NULL, ("decons_fn: no fields in shape!!\n") ); + if( ! d->Struct ) + { + fprintf( stderr, "decons_fn: d->Struct is FALSE!\n" ); + exit(1); + } + if( s->params == NULL ) + { + fprintf( stderr, "decons_fn: no fields in shape!!\n" ); + exit(1); + } fprintf( outfile, "void get_%s_%s( this", d->name, s->name ); for( p=s->params; p != NULL; p=p->next ) @@ -797,8 +848,13 @@ static void print_all_params( d, s ) declnlist d; shapelist s; n = pl->item->num; for( p = s->params; --n; p = p->next ) { - ASSERT( p != NULL, -("datadec: bad printitem in shape %s of type %s\n",s->name,d->name)); + if( p == NULL ) + { + fprintf( stderr, + "datadec: bad printitem in shape %s of type %s\n", + s->name, d->name ); + exit(1); + } } print_param( s, p, d->Union ); } diff --git a/lexer.c b/lexer.c index b5767a6..d626da5 100644 --- a/lexer.c +++ b/lexer.c @@ -15,8 +15,9 @@ */ -#include +#include #include +#include "struct.h" #include "lexer.h" @@ -71,7 +72,11 @@ static void white_space() void ungettok() { - ASSERT( ! havepushedtok, ("ungettok: can't push 2 tokens\n") ); + if( havepushedtok ) + { + fprintf( stderr, "ungettok: can't push 2 tokens\n" ); + exit(1); + } havepushedtok = TRUE; #ifdef DEBUGGING printf( "lexer: ungot token %s\n", tokenname[ curtok ] ); diff --git a/optimize.c b/optimize.c index e730d29..e3422d9 100644 --- a/optimize.c +++ b/optimize.c @@ -1,9 +1,10 @@ /* optimize.c */ -#include +#include #include #include "struct.h" +#include "optimize.h" BOOL opt; /* opt == perform optimizations */ @@ -86,16 +87,41 @@ static void optimize_decln( d ) decln d; #undef XXX } - ASSERT( implies(d->Union,d->Struct), - ("optimizer error: type %s has Union&!Struct\n",d->name) ); - ASSERT( implies(d->TagField,d->Struct), - ("optimizer error: type %s has TagField&!Struct\n",d->name) ); - ASSERT( implies(d->UseNull,d->Struct), - ("optimizer error: type %s has UseNull&!Struct\n",d->name) ); - ASSERT( implies(d->TagField,d->ManyShapes), - ("optimizer error: type %s has TagField&!ManyShapes\n",d->name) ); - ASSERT( implies(d->Union,d->TagField), - ("optimizer error: type %s has Union&!TagField\n",d->name) ); + if( ! implies(d->Union,d->Struct) ) + { + fprintf( stderr, + "optimizer error: type %s has Union&!Struct\n", + d->name ); + exit(1); + } + if( ! implies(d->TagField,d->Struct) ) + { + fprintf( stderr, + "optimizer error: type %s has TagField&!Struct\n", + d->name ); + exit(1); + } + if( ! implies(d->UseNull,d->Struct) ) + { + fprintf( stderr, + "optimizer error: type %s has UseNull&!Struct\n", + d->name ); + exit(1); + } + if( ! implies(d->TagField,d->ManyShapes) ) + { + fprintf( stderr, + "optimizer error: type %s has TagField&!ManyShapes\n", + d->name ); + exit(1); + } + if( ! implies(d->Union,d->TagField) ) + { + fprintf( stderr, + "optimizer error: type %s has Union&!TagField\n", + d->name ); + exit(1); + } } diff --git a/parser.c b/parser.c index 4569d06..a83538a 100644 --- a/parser.c +++ b/parser.c @@ -25,12 +25,17 @@ */ -#include +#include +#include +#include #include "struct.h" #include "lexer.h" #include "parser.h" +#define COPYOF(new,old) {new=malloc(1+strlen(old));if(new)strcpy(new,old);} + + /* /^#ifdef HASPROTOS !/endif$ diff --git a/struct.c b/struct.c index a65d879..7ba069c 100644 --- a/struct.c +++ b/struct.c @@ -15,10 +15,13 @@ */ -#include +#include +#include #include "struct.h" #define Puts(s) fputs(s,stdout) +#define NEW(t) (t) malloc( sizeof(struct t) ) +#define COPYOF(new,old) {new=malloc(1+strlen(old));if(new)strcpy(new,old);} declnlist build_declnlist(name,s,next) char *name; shapelist s; declnlist next; @@ -142,7 +145,10 @@ void print_printitem(i) printitem i; printf("\"%s\" ", i->str); break; default: - ABORT( ("datadec: print_printitem called with printitem tag = %d\n", i->tag ) ); + fprintf( stderr, + "datadec: print_printitem called with tag = %d\n", + i->tag ); + exit(1); } } @@ -172,9 +178,13 @@ param findnthparam( n, p, sname, dname ) int n; paramlist p; char *sname, *dname for( ; p != NULL && --m; p = p->next ); - ASSERT( p != NULL, - ("datadec: bad print number %d in shape %s of type %s\n", - m, sname, dname)); + if( p == NULL ) + { + fprintf( stderr, + "datadec: bad print number %d in shape %s of type %s\n", + m, sname, dname ); + exit(1); + } return p; } -- GitLab