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

k&r -> ansi thoughout

parent bd690078
......@@ -6,60 +6,28 @@
#include "decs.h"
/*
/^#ifdef HASPROTOS
!/endif$
stat %
*/
#ifdef HASPROTOS
static void line( char * , long , long , long , long );
static void h_declns( char * , char * , BOOL , declnlist );
static void c_declns( char * , char * , char * , declnlist );
static void data_decls( declnlist );
static void declare_type( decln );
static void declfields( paramlist );
static void protos( BOOL , char * , declnlist , BOOL );
static void proto_type( decln , BOOL );
static void cons_fns( declnlist );
static void cons_fn_proto( decln , shapelist , BOOL );
static void cons_fn( decln , shapelist );
static void decons_fns( declnlist );
static void decons_fns_type( decln );
static void deconskind_proto( decln , BOOL );
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 void literalline( char * mesg );
static void h_declns( char * base, char * exports, BOOL init, declnlist d );
static void c_declns( char * base, char * globals, char * begin, declnlist d );
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 );
static void proto_type( decln d, BOOL prot );
static void cons_fns( declnlist d );
static void cons_fn_proto( decln d, shapelist s, BOOL prot );
static void cons_fn( decln d, shapelist s );
static void decons_fns( declnlist d );
static void decons_fns_type( decln d );
static void deconskind_proto( decln d, BOOL prot );
static void deconskind_fn( decln d );
static void decons_fn_proto( decln d, shapelist s, BOOL prot );
static void decons_fn( decln d, shapelist s );
static void print_fn_proto( char * name, BOOL prot );
static void print_fns( declnlist d );
static void print_fn_shape( declnlist d, shapelist s );
static void print_all_params( declnlist d, shapelist s );
static void print_param( shapelist s, paramlist p, BOOL Union );
static int numtabs = 0;
......@@ -77,6 +45,7 @@ static FILE *outfile;
/*VARARGS*/
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;
......@@ -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;
......@@ -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 );
h_declns( base, exports, *begin != '\0', d );
......@@ -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 *exportptr;
......@@ -151,15 +120,7 @@ static void h_declns( base, exports, init, d ) char *base, *exports; BOOL init;
data_decls( d );
line( "\n/* Prototypes for all types */\n" );
#ifdef KANDR
line( "#ifdef HASPROTOS" );
#endif
protos( init, base, d, TRUE );
#ifdef KANDR
line( "#else" );
protos( init, base, d, FALSE );
line( "#endif" );
#endif
if( *exportptr != '\0' )
{
......@@ -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];
FILE *cfile;
......@@ -243,7 +204,7 @@ static void c_declns( base, globals, begin, d ) char *base, *globals, *begin; de
/* ------------------------ Declare the types ------------------------------ */
static void data_decls( decs ) declnlist decs;
static void data_decls( declnlist decs )
{
declnlist d;
......@@ -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;
......@@ -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 )
{
......@@ -349,7 +310,7 @@ static void declfields( p ) paramlist p;
/* ---------------------- 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 )
{
......@@ -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;
......@@ -427,7 +388,7 @@ static void proto_type( d, prot ) decln d; BOOL prot;
/* ------------------------------- Constructors --------------------------- */
static void cons_fns( d ) declnlist d;
static void cons_fns( declnlist d )
{
shapelist s;
......@@ -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;
BOOL first;
......@@ -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;
BOOL first;
......@@ -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 );
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 )
{
fprintf( outfile, "void" );
......@@ -519,7 +468,6 @@ static void cons_fn( d, s ) decln d; shapelist s;
fprintf( outfile, "%s %s", p->type, p->name );
}
fputs( " )", outfile );
#endif
line( "\n{" );
indent();
......@@ -560,7 +508,7 @@ static void cons_fn( d, s ) decln d; shapelist s;
/* ------------------------- Deconstructors ------------------------------- */
static void decons_fns( d ) declnlist d;
static void decons_fns( declnlist d )
{
for( ; d != NULL; d=d->next )
{
......@@ -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;
......@@ -602,7 +550,7 @@ static void decons_fns_type( d ) decln d;
/* ------------------- Deconstructor Kind procedure ----------------------- */
static void deconskind_proto( d, prot ) decln d; BOOL prot;
static void deconskind_proto( decln d, BOOL prot )
{
if( ! d->ManyShapes )
{
......@@ -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;
......@@ -640,13 +588,8 @@ static void deconskind_fn( d ) decln d;
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",
d->name, d->name, d->name );
#endif
line( "{" );
indent();
......@@ -677,7 +620,7 @@ static void deconskind_fn( d ) decln d;
/* ----------------------- 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 )
{
......@@ -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;
......@@ -720,25 +663,12 @@ static void decons_fn( d, s ) decln d; shapelist s;
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 );
for( p=s->params; p != NULL; p=p->next )
{
fprintf( outfile, ", %s *%s", p->type, p->name );
}
fprintf( outfile, " )" );
#endif
line( "\n{" );
indent();
......@@ -771,7 +701,7 @@ static void decons_fn( d, s ) decln d; shapelist s;
/* -------------------------- 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 );
if( 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 )
{
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 );
#endif
line( "{" );
indent();
s = d->shapes;
......@@ -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 );
indent();
......@@ -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;
paramlist p;
......@@ -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];
......
#ifdef HASPROTOS
extern void make_declns( char * , char * , char * , declnlist , char * );
#else
extern void make_declns();
#endif
......@@ -53,7 +53,7 @@ static int curint;
/* ----------------- Private procedures ---------------- */
static void white_space()
static void white_space( void )
{
int c;
......@@ -73,7 +73,7 @@ static void white_space()
/* ----------------- Public procedures ---------------- */
void ungettok()
void ungettok( void )
{
if( havepushedtok )
{
......@@ -87,7 +87,7 @@ printf( "lexer: ungot token %s\n", tokenname[ curtok ] );
}
TOKEN nexttok()
TOKEN nexttok( void )
{
int c;
int pos;
......@@ -183,7 +183,7 @@ printf( "returning token %s\n", tokenname[ curtok ] );
}
BOOL readnextline( line ) char *line;
BOOL readnextline( char *line )
{
int c;
char *s = line;
......
......@@ -30,12 +30,6 @@ extern FILE *lexfile;
/* ----------------- Public procedures ---------------- */
#ifdef HASPROTOS
extern TOKEN nexttok( void );
extern void ungettok( void );
extern BOOL readnextline( char * );
#else
extern TOKEN nexttok();
extern void ungettok();
extern BOOL readnextline();
#endif
extern TOKEN nexttok( void );
extern BOOL readnextline( char * line );
......@@ -13,26 +13,14 @@ BOOL opt; /* opt == perform optimizations */
BOOL verbose; /* verbose == be verbose - diagnostics */
/*
/^#ifdef HASPROTOS
!/endif$
stat %
*/
#ifdef HASPROTOS
static void optimize_decln( decln );
static BOOL tail_optimize( decln );
#else
static void optimize_decln();
static BOOL tail_optimize();
#endif
#define implies( a, b ) (!(a) || (b))
void optimize( d ) declnlist d;
void optimize( declnlist d )
{
for( ; d != NULL; d = d->next )
{
......@@ -48,7 +36,7 @@ void optimize( d ) declnlist d;
}
static void optimize_decln( d ) decln d;
static void optimize_decln( decln d )
{
int t, e, ne;
shapelist s;
......@@ -135,7 +123,7 @@ static void optimize_decln( d ) decln d;
Return TRUE if the optimization is possible.
*/
static BOOL tail_optimize( d ) decln d;
static BOOL tail_optimize( decln d )
{
shapelist s;
printlist pl;
......
......@@ -5,8 +5,4 @@ extern BOOL opt; /* perform optimizations */
extern BOOL verbose; /* be verbose */
#ifdef HASPROTOS
extern void optimize( declnlist );
#else
extern void optimize();
#endif
......@@ -36,36 +36,16 @@
#define COPYOF(new,old) {new=malloc(1+strlen(old));if(new)strcpy(new,old);}
/*
/^#ifdef HASPROTOS
!/endif$
stat %
*/
#ifdef HASPROTOS
static BOOL parse_chunk( char * );
static BOOL parse_declns( declnlist * );
static void error( char * );
static BOOL parse_decln( char ** , shapelist * );
static BOOL parse_shapes( shapelist * );
static BOOL parse_shape( char ** , paramlist * , printlist * );
static BOOL parse_params( paramlist * );
static BOOL parse_printlist( printlist * );
static BOOL parse_printitem( printitem * );
static BOOL parse_param( char ** , char ** );
#else
static BOOL parse_chunk();
static BOOL parse_declns();
static void error();
static BOOL parse_decln();
static BOOL parse_shapes();
static BOOL parse_shape();
static BOOL parse_params();
static BOOL parse_printlist();
static BOOL parse_printitem();
static BOOL parse_param();
#endif
static BOOL parse_chunk( char * s );
static BOOL parse_declns( declnlist * dp );
static void error( char * s );
static BOOL parse_decln( char ** name, shapelist * shapes );
static BOOL parse_shapes( shapelist * sp );
static BOOL parse_shape( char ** tagname, paramlist * pl, printlist * print );
static BOOL parse_params( paramlist * pp );
static BOOL parse_printlist( printlist * pp );
static BOOL parse_printitem( printitem * item );
static BOOL parse_param( char ** type, char ** name );
#define MUSTBE(t,mesg) if( nexttok() != (t) ) {error(mesg); return FALSE;}
......@@ -78,7 +58,7 @@ static BOOL parse_param();
* tTYPE tOPENCURLY declns tCLOSECURLY
*/
BOOL parse_data( exports, globals, begin, dp ) char *exports, *globals, *begin; declnlist *dp;
BOOL parse_data( char *exports, char *globals, char *begin, declnlist *dp )
{
if( nexttok() == tEXPORT )
{
......@@ -119,7 +99,7 @@ BOOL parse_data( exports, globals, begin, dp ) char *exports, *globals, *begin;
/* chunk = tOPENCURLY list_of_lines tCLOSECURLY */
static BOOL parse_chunk( s ) char *s;
static BOOL parse_chunk( char *s )
{
char line[256];
int startlineno;
......@@ -149,7 +129,7 @@ static BOOL parse_chunk( s ) char *s;
/* declns = list*( decln ) */
/* NB: a decln starts with a tID */
static BOOL parse_declns( dp ) declnlist *dp;
static BOOL parse_declns( declnlist *dp )
{
char *name;
shapelist shapes;
......@@ -166,7 +146,7 @@ static BOOL parse_declns( dp ) declnlist *dp;
}
static void error( s ) char *s;
static void error( char *s )
{
fprintf( stderr, "%s at line %d\n", s, lineno );
}
......@@ -174,7 +154,7 @@ static void error( s ) char *s;
/* decln = tID tEQ shapes tSEMI */
static BOOL parse_decln( name, shapes ) char **name; shapelist *shapes;
static BOOL parse_decln( char **name, shapelist *shapes )
{
MUSTBE( tID, "declaration expected" );
COPYOF( *name, lexidval );
......@@ -191,7 +171,7 @@ static BOOL parse_decln( name, shapes ) char **name; shapelist *shapes;
/* shapes = sep-list+( shape, tOR ) */
static BOOL parse_shapes( sp ) shapelist *sp;
static BOOL parse_shapes( shapelist *sp )
{
char *tagname;
paramlist paras;
......@@ -211,7 +191,7 @@ static BOOL parse_shapes( sp ) shapelist *sp;
/* shape = tID [ tOPENBR params tCLOSEBR ] printlist */
static BOOL parse_shape( tagname, pl, print ) char **tagname; paramlist *pl; printlist *print;
static BOOL parse_shape( char **tagname, paramlist *pl, printlist *print )
{
*pl = (paramlist) NULL;
*print = (printlist) NULL;
......@@ -235,7 +215,7 @@ static BOOL parse_shape( tagname, pl, print ) char **tagname; paramlist *pl; pri
/* params = sep-list+( param, tCOMMA ) */
static BOOL parse_params( pp ) paramlist *pp;
static BOOL parse_params( paramlist *pp )
{
char *type;
char *name;
......@@ -254,7 +234,7 @@ static BOOL parse_params( pp ) paramlist *pp;
/* printlist = list( printitem ) */
/* NB: Never fails, cos items are one token long */
static BOOL parse_printlist( pp ) printlist *pp;
static BOOL parse_printlist( printlist *pp )
{
printitem item;
......@@ -271,7 +251,7 @@ static BOOL parse_printlist( pp ) printlist *pp;
/* printitem = tSTR | tNUM */
static BOOL parse_printitem( item ) printitem *item;
static BOOL parse_printitem( printitem *item )
{
char *temp;
......@@ -292,7 +272,7 @@ static BOOL parse_printitem( item ) printitem *item;
/* param = tID tID */
static BOOL parse_param( type, name ) char **type, **name;
static BOOL parse_param( char **type, char **name )
{
MUSTBE( tID, "Field type expected" );
COPYOF( *type, lexidval );
......
#ifdef HASPROTOS
extern BOOL parse_data( char * , char * , char * , declnlist * );
#else
extern BOOL parse_data();
#endif
extern BOOL parse_data( char * exports, char * globals, char * begin, declnlist * dp );
......@@ -18,7 +18,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include "struct.h"
......@@ -27,7 +26,7 @@
#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;
declnlist build_declnlist( char *name, shapelist s, declnlist next )
{
declnlist new = NEW(declnlist);
......@@ -38,7 +37,7 @@ declnlist build_declnlist(name,s,next) char *name; shapelist s; declnlist next;
}
void print_declnlist(d) declnlist d;