Commit 62989cb6 authored by Duncan White's avatar Duncan White
Browse files

k&r -> ansi thoughout

parent bd690078
...@@ -6,60 +6,28 @@ ...@@ -6,60 +6,28 @@
#include "decs.h" #include "decs.h"
/* static void literalline( char * mesg );
/^#ifdef HASPROTOS static void h_declns( char * base, char * exports, BOOL init, declnlist d );
!/endif$ static void c_declns( char * base, char * globals, char * begin, declnlist d );
stat % static void data_decls( declnlist decs );
*/ static void declare_type( decln d );
static void declfields( paramlist p );
static void protos( BOOL init, char * base, declnlist d, BOOL prot );
#ifdef HASPROTOS static void proto_type( decln d, BOOL prot );
static void line( char * , long , long , long , long ); static void cons_fns( declnlist d );
static void h_declns( char * , char * , BOOL , declnlist ); static void cons_fn_proto( decln d, shapelist s, BOOL prot );
static void c_declns( char * , char * , char * , declnlist ); static void cons_fn( decln d, shapelist s );
static void data_decls( declnlist ); static void decons_fns( declnlist d );
static void declare_type( decln ); static void decons_fns_type( decln d );
static void declfields( paramlist ); static void deconskind_proto( decln d, BOOL prot );
static void protos( BOOL , char * , declnlist , BOOL ); static void deconskind_fn( decln d );
static void proto_type( decln , BOOL ); static void decons_fn_proto( decln d, shapelist s, BOOL prot );
static void cons_fns( declnlist ); static void decons_fn( decln d, shapelist s );
static void cons_fn_proto( decln , shapelist , BOOL ); static void print_fn_proto( char * name, BOOL prot );
static void cons_fn( decln , shapelist ); static void print_fns( declnlist d );
static void decons_fns( declnlist ); static void print_fn_shape( declnlist d, shapelist s );
static void decons_fns_type( decln ); static void print_all_params( declnlist d, shapelist s );
static void deconskind_proto( decln , BOOL ); static void print_param( shapelist s, paramlist p, BOOL Union );
static void deconskind_fn( decln );
static void decons_fn_proto( decln , shapelist , BOOL );
static void decons_fn( decln , shapelist );
static void print_fn_proto( char * , BOOL );
static void print_fns( declnlist );
static void print_fn_shape( declnlist , shapelist );
static void print_all_params( declnlist , shapelist );
static void print_param( shapelist , paramlist , BOOL );
#else
static void line();
static void h_declns();
static void c_declns();
static void data_decls();
static void declare_type();
static void declfields();
static void protos();
static void proto_type();
static void cons_fns();
static void cons_fn_proto();
static void cons_fn();
static void decons_fns();
static void decons_fns_type();
static void deconskind_proto();
static void deconskind_fn();
static void decons_fn_proto();
static void decons_fn();
static void print_fn_proto();
static void print_fns();
static void print_fn_shape();
static void print_all_params();
static void print_param();
#endif
static int numtabs = 0; static int numtabs = 0;
...@@ -77,6 +45,7 @@ static FILE *outfile; ...@@ -77,6 +45,7 @@ static FILE *outfile;
/*VARARGS*/ /*VARARGS*/
static void line( fmt, a, b, c, d ) char *fmt; long a, b, c, d; static void line( fmt, a, b, c, d ) char *fmt; long a, b, c, d;
//static void line( char *fmt, long a, long b, long c, long d )
{ {
int i; int i;
...@@ -86,7 +55,7 @@ static void line( fmt, a, b, c, d ) char *fmt; long a, b, c, d; ...@@ -86,7 +55,7 @@ static void line( fmt, a, b, c, d ) char *fmt; long a, b, c, d;
} }
static void literalline( mesg ) char *mesg; static void literalline( char *mesg )
{ {
int i; int i;
...@@ -96,7 +65,7 @@ static void literalline( mesg ) char *mesg; ...@@ -96,7 +65,7 @@ static void literalline( mesg ) char *mesg;
} }
void make_declns( exports, globals, begin, d, base ) declnlist d; char *exports, *globals, *begin, *base; void make_declns( char *exports, char *globals, char *begin, declnlist d, char *base )
{ {
printf( "datadec: Making data declarations in %s.[ch]\n", base ); printf( "datadec: Making data declarations in %s.[ch]\n", base );
h_declns( base, exports, *begin != '\0', d ); h_declns( base, exports, *begin != '\0', d );
...@@ -104,7 +73,7 @@ void make_declns( exports, globals, begin, d, base ) declnlist d; char *exports, ...@@ -104,7 +73,7 @@ void make_declns( exports, globals, begin, d, base ) declnlist d; char *exports,
} }
static void h_declns( base, exports, init, d ) char *base, *exports; BOOL init; declnlist d; static void h_declns( char *base, char *exports, BOOL init, declnlist d )
{ {
char tempname[256]; char tempname[256];
char *exportptr; char *exportptr;
...@@ -151,15 +120,7 @@ static void h_declns( base, exports, init, d ) char *base, *exports; BOOL init; ...@@ -151,15 +120,7 @@ static void h_declns( base, exports, init, d ) char *base, *exports; BOOL init;
data_decls( d ); data_decls( d );
line( "\n/* Prototypes for all types */\n" ); line( "\n/* Prototypes for all types */\n" );
#ifdef KANDR
line( "#ifdef HASPROTOS" );
#endif
protos( init, base, d, TRUE ); protos( init, base, d, TRUE );
#ifdef KANDR
line( "#else" );
protos( init, base, d, FALSE );
line( "#endif" );
#endif
if( *exportptr != '\0' ) if( *exportptr != '\0' )
{ {
...@@ -173,7 +134,7 @@ static void h_declns( base, exports, init, d ) char *base, *exports; BOOL init; ...@@ -173,7 +134,7 @@ static void h_declns( base, exports, init, d ) char *base, *exports; BOOL init;
} }
static void c_declns( base, globals, begin, d ) char *base, *globals, *begin; declnlist d; static void c_declns( char *base, char *globals, char *begin, declnlist d )
{ {
char tempname[256]; char tempname[256];
FILE *cfile; FILE *cfile;
...@@ -243,7 +204,7 @@ static void c_declns( base, globals, begin, d ) char *base, *globals, *begin; de ...@@ -243,7 +204,7 @@ static void c_declns( base, globals, begin, d ) char *base, *globals, *begin; de
/* ------------------------ Declare the types ------------------------------ */ /* ------------------------ Declare the types ------------------------------ */
static void data_decls( decs ) declnlist decs; static void data_decls( declnlist decs )
{ {
declnlist d; declnlist d;
...@@ -267,7 +228,7 @@ static void data_decls( decs ) declnlist decs; ...@@ -267,7 +228,7 @@ static void data_decls( decs ) declnlist decs;
} }
static void declare_type( d ) decln d; static void declare_type( decln d )
{ {
shapelist s; shapelist s;
...@@ -337,7 +298,7 @@ static void declare_type( d ) decln d; ...@@ -337,7 +298,7 @@ static void declare_type( d ) decln d;
} }
static void declfields( p ) paramlist p; static void declfields( paramlist p )
{ {
for( ; p != NULL; p=p->next ) for( ; p != NULL; p=p->next )
{ {
...@@ -349,7 +310,7 @@ static void declfields( p ) paramlist p; ...@@ -349,7 +310,7 @@ static void declfields( p ) paramlist p;
/* ---------------------- Declare all prototypes -------------------------- */ /* ---------------------- Declare all prototypes -------------------------- */
static void protos( init, base, d, prot ) BOOL init; char *base; declnlist d; BOOL prot; static void protos( BOOL init, char *base, declnlist d, BOOL prot )
{ {
for( ; d != NULL; d = d->next ) for( ; d != NULL; d = d->next )
{ {
...@@ -367,7 +328,7 @@ static void protos( init, base, d, prot ) BOOL init; char *base; declnlist d; BO ...@@ -367,7 +328,7 @@ static void protos( init, base, d, prot ) BOOL init; char *base; declnlist d; BO
} }
static void proto_type( d, prot ) decln d; BOOL prot; static void proto_type( decln d, BOOL prot )
{ {
shapelist s; shapelist s;
...@@ -427,7 +388,7 @@ static void proto_type( d, prot ) decln d; BOOL prot; ...@@ -427,7 +388,7 @@ static void proto_type( d, prot ) decln d; BOOL prot;
/* ------------------------------- Constructors --------------------------- */ /* ------------------------------- Constructors --------------------------- */
static void cons_fns( d ) declnlist d; static void cons_fns( declnlist d )
{ {
shapelist s; shapelist s;
...@@ -451,7 +412,7 @@ static void cons_fns( d ) declnlist d; ...@@ -451,7 +412,7 @@ static void cons_fns( d ) declnlist d;
} }
static void cons_fn_proto( d, s, prot ) decln d; shapelist s; BOOL prot; static void cons_fn_proto( decln d, shapelist s, BOOL prot )
{ {
paramlist p; paramlist p;
BOOL first; BOOL first;
...@@ -483,7 +444,7 @@ static void cons_fn_proto( d, s, prot ) decln d; shapelist s; BOOL prot; ...@@ -483,7 +444,7 @@ static void cons_fn_proto( d, s, prot ) decln d; shapelist s; BOOL prot;
} }
static void cons_fn( d, s ) decln d; shapelist s; static void cons_fn( decln d, shapelist s )
{ {
paramlist p; paramlist p;
BOOL first; BOOL first;
...@@ -497,18 +458,6 @@ static void cons_fn( d, s ) decln d; shapelist s; ...@@ -497,18 +458,6 @@ static void cons_fn( d, s ) decln d; shapelist s;
fprintf( outfile, "%s %s_%s( ", d->name, d->name, s->name ); fprintf( outfile, "%s %s_%s( ", d->name, d->name, s->name );
first = TRUE; first = TRUE;
#ifdef KANDR
for( p=s->params; p != NULL; p=p->next, first=FALSE )
{
if( !first ) fputs( ", ", outfile );
fputs( p->name, outfile );
}
fputs( " )", outfile );
for( p=s->params; p != NULL; p=p->next )
{
fprintf( outfile, " %s %s;", p->type, p->name );
}
#else
if( s->params == NULL ) if( s->params == NULL )
{ {
fprintf( outfile, "void" ); fprintf( outfile, "void" );
...@@ -519,7 +468,6 @@ static void cons_fn( d, s ) decln d; shapelist s; ...@@ -519,7 +468,6 @@ static void cons_fn( d, s ) decln d; shapelist s;
fprintf( outfile, "%s %s", p->type, p->name ); fprintf( outfile, "%s %s", p->type, p->name );
} }
fputs( " )", outfile ); fputs( " )", outfile );
#endif
line( "\n{" ); line( "\n{" );
indent(); indent();
...@@ -560,7 +508,7 @@ static void cons_fn( d, s ) decln d; shapelist s; ...@@ -560,7 +508,7 @@ static void cons_fn( d, s ) decln d; shapelist s;
/* ------------------------- Deconstructors ------------------------------- */ /* ------------------------- Deconstructors ------------------------------- */
static void decons_fns( d ) declnlist d; static void decons_fns( declnlist d )
{ {
for( ; d != NULL; d=d->next ) for( ; d != NULL; d=d->next )
{ {
...@@ -573,7 +521,7 @@ static void decons_fns( d ) declnlist d; ...@@ -573,7 +521,7 @@ static void decons_fns( d ) declnlist d;
} }
static void decons_fns_type( d ) decln d; static void decons_fns_type( decln d )
{ {
shapelist s; shapelist s;
...@@ -602,7 +550,7 @@ static void decons_fns_type( d ) decln d; ...@@ -602,7 +550,7 @@ static void decons_fns_type( d ) decln d;
/* ------------------- Deconstructor Kind procedure ----------------------- */ /* ------------------- Deconstructor Kind procedure ----------------------- */
static void deconskind_proto( d, prot ) decln d; BOOL prot; static void deconskind_proto( decln d, BOOL prot )
{ {
if( ! d->ManyShapes ) if( ! d->ManyShapes )
{ {
...@@ -625,7 +573,7 @@ static void deconskind_proto( d, prot ) decln d; BOOL prot; ...@@ -625,7 +573,7 @@ static void deconskind_proto( d, prot ) decln d; BOOL prot;
} }
static void deconskind_fn( d ) decln d; static void deconskind_fn( decln d )
{ {
shapelist s = d->shapes; shapelist s = d->shapes;
...@@ -640,13 +588,8 @@ static void deconskind_fn( d ) decln d; ...@@ -640,13 +588,8 @@ static void deconskind_fn( d ) decln d;
exit(1); exit(1);
} }
#ifdef KANDR
fprintf( outfile, "kind_of_%s %s_kind( this ) %s this;\n",
d->name, d->name, d->name );
#else
fprintf( outfile, "kind_of_%s %s_kind( %s this )\n", fprintf( outfile, "kind_of_%s %s_kind( %s this )\n",
d->name, d->name, d->name ); d->name, d->name, d->name );
#endif
line( "{" ); line( "{" );
indent(); indent();
...@@ -677,7 +620,7 @@ static void deconskind_fn( d ) decln d; ...@@ -677,7 +620,7 @@ static void deconskind_fn( d ) decln d;
/* ----------------------- Deconstructor functions ------------------------ */ /* ----------------------- Deconstructor functions ------------------------ */
static void decons_fn_proto( d, s, prot ) decln d; shapelist s; BOOL prot; static void decons_fn_proto( decln d, shapelist s, BOOL prot )
{ {
if( ! d->Struct ) if( ! d->Struct )
{ {
...@@ -705,7 +648,7 @@ static void decons_fn_proto( d, s, prot ) decln d; shapelist s; BOOL prot; ...@@ -705,7 +648,7 @@ static void decons_fn_proto( d, s, prot ) decln d; shapelist s; BOOL prot;
} }
static void decons_fn( d, s ) decln d; shapelist s; static void decons_fn( decln d, shapelist s )
{ {
paramlist p; paramlist p;
...@@ -720,25 +663,12 @@ static void decons_fn( d, s ) decln d; shapelist s; ...@@ -720,25 +663,12 @@ static void decons_fn( d, s ) decln d; shapelist s;
exit(1); exit(1);
} }
#ifdef KANDR
fprintf( outfile, "void get_%s_%s( this", d->name, s->name );
for( p=s->params; p != NULL; p=p->next )
{
fprintf( outfile, ", %s ", p->name );
}
fprintf( outfile, ") %s this;", d->name );
for( p=s->params; p != NULL; p=p->next )
{
fprintf( outfile, " %s *%s;", p->type, p->name );
}
#else
fprintf( outfile, "void get_%s_%s( %s this", d->name, s->name, d->name ); fprintf( outfile, "void get_%s_%s( %s this", d->name, s->name, d->name );
for( p=s->params; p != NULL; p=p->next ) for( p=s->params; p != NULL; p=p->next )
{ {
fprintf( outfile, ", %s *%s", p->type, p->name ); fprintf( outfile, ", %s *%s", p->type, p->name );
} }
fprintf( outfile, " )" ); fprintf( outfile, " )" );
#endif
line( "\n{" ); line( "\n{" );
indent(); indent();
...@@ -771,7 +701,7 @@ static void decons_fn( d, s ) decln d; shapelist s; ...@@ -771,7 +701,7 @@ static void decons_fn( d, s ) decln d; shapelist s;
/* -------------------------- Print functions ----------------------------- */ /* -------------------------- Print functions ----------------------------- */
static void print_fn_proto( name, prot ) char *name; BOOL prot; static void print_fn_proto( char *name, BOOL prot )
{ {
fprintf( outfile, "extern void print_%s(", name ); fprintf( outfile, "extern void print_%s(", name );
if( prot ) if( prot )
...@@ -782,17 +712,13 @@ static void print_fn_proto( name, prot ) char *name; BOOL prot; ...@@ -782,17 +712,13 @@ static void print_fn_proto( name, prot ) char *name; BOOL prot;
} }
static void print_fns( d ) declnlist d; static void print_fns( declnlist d )
{ {
for( ; d != NULL; d = d->next ) for( ; d != NULL; d = d->next )
{ {
shapelist s; shapelist s;
#ifdef KANDR
line( "void print_%s( f, p ) FILE *f; %s p;",d->name, d->name );
#else
line( "void print_%s( FILE *f, %s p )",d->name, d->name ); line( "void print_%s( FILE *f, %s p )",d->name, d->name );
#endif
line( "{" ); line( "{" );
indent(); indent();
s = d->shapes; s = d->shapes;
...@@ -853,7 +779,7 @@ static void print_fns( d ) declnlist d; ...@@ -853,7 +779,7 @@ static void print_fns( d ) declnlist d;
} }
static void print_fn_shape( d, s ) declnlist d; shapelist s; static void print_fn_shape( declnlist d, shapelist s )
{ {
line( "case %s_is_%s:", d->name, s->name ); line( "case %s_is_%s:", d->name, s->name );
indent(); indent();
...@@ -863,7 +789,7 @@ static void print_fn_shape( d, s ) declnlist d; shapelist s; ...@@ -863,7 +789,7 @@ static void print_fn_shape( d, s ) declnlist d; shapelist s;
} }
static void print_all_params( d, s ) declnlist d; shapelist s; static void print_all_params( declnlist d, shapelist s )
{ {
printlist pl; printlist pl;
paramlist p; paramlist p;
...@@ -917,7 +843,7 @@ static void print_all_params( d, s ) declnlist d; shapelist s; ...@@ -917,7 +843,7 @@ static void print_all_params( d, s ) declnlist d; shapelist s;
} }
static void print_param( s, p, Union ) shapelist s; paramlist p; BOOL Union; static void print_param( shapelist s, paramlist p, BOOL Union )
{ {
char pname[200]; char pname[200];
......
#ifdef HASPROTOS
extern void make_declns( char * , char * , char * , declnlist , char * ); extern void make_declns( char * , char * , char * , declnlist , char * );
#else
extern void make_declns();
#endif
...@@ -53,7 +53,7 @@ static int curint; ...@@ -53,7 +53,7 @@ static int curint;
/* ----------------- Private procedures ---------------- */ /* ----------------- Private procedures ---------------- */
static void white_space() static void white_space( void )
{ {
int c; int c;
...@@ -73,7 +73,7 @@ static void white_space() ...@@ -73,7 +73,7 @@ static void white_space()
/* ----------------- Public procedures ---------------- */ /* ----------------- Public procedures ---------------- */
void ungettok() void ungettok( void )
{ {
if( havepushedtok ) if( havepushedtok )
{ {
...@@ -87,7 +87,7 @@ printf( "lexer: ungot token %s\n", tokenname[ curtok ] ); ...@@ -87,7 +87,7 @@ printf( "lexer: ungot token %s\n", tokenname[ curtok ] );
} }
TOKEN nexttok() TOKEN nexttok( void )
{ {
int c; int c;
int pos; int pos;
...@@ -183,7 +183,7 @@ printf( "returning token %s\n", tokenname[ curtok ] ); ...@@ -183,7 +183,7 @@ printf( "returning token %s\n", tokenname[ curtok ] );
} }
BOOL readnextline( line ) char *line; BOOL readnextline( char *line )
{ {
int c; int c;
char *s = line; char *s = line;
......
...@@ -30,12 +30,6 @@ extern FILE *lexfile; ...@@ -30,12 +30,6 @@ extern FILE *lexfile;
/* ----------------- Public procedures ---------------- */ /* ----------------- Public procedures ---------------- */
#ifdef HASPROTOS
extern TOKEN nexttok( void );
extern void ungettok( void ); extern void ungettok( void );
extern BOOL readnextline( char * ); extern TOKEN nexttok( void );
#else extern BOOL readnextline( char * line );
extern TOKEN nexttok();
extern void ungettok();
extern BOOL readnextline();
#endif
...@@ -13,26 +13,14 @@ BOOL opt; /* opt == perform optimizations */ ...@@ -13,26 +13,14 @@ BOOL opt; /* opt == perform optimizations */
BOOL verbose; /* verbose == be verbose - diagnostics */ BOOL verbose; /* verbose == be verbose - diagnostics */
/*
/^#ifdef HASPROTOS
!/endif$
stat %
*/
#ifdef HASPROTOS
static void optimize_decln( decln ); static void optimize_decln( decln );
static BOOL tail_optimize( decln ); static BOOL tail_optimize( decln );
#else
static void optimize_decln();
static BOOL tail_optimize();
#endif
#define implies( a, b ) (!(a) || (b)) #define implies( a, b ) (!(a) || (b))
void optimize( d ) declnlist d; void optimize( declnlist d )
{ {