Commit 2fc0bb95 authored by dcw's avatar dcw

added begin section

parent b681a4a5
......@@ -34,6 +34,8 @@
#define CHUNKSIZE 10000
typedef char bigstr[ CHUNKSIZE ];
void main( argc, argv ) int argc; char **argv;
{
......@@ -42,7 +44,7 @@ void main( argc, argv ) int argc; char **argv;
declnlist declns;
int len;
int arg;
char exports[CHUNKSIZE], globals[CHUNKSIZE];
bigstr exports, globals, begin;
arg = 1;
NEED_ANOTHER_ARG;
......@@ -89,7 +91,7 @@ void main( argc, argv ) int argc; char **argv;
REQUIRE_NO_MORE_ARGS;
if( parse_data( exports, globals, &declns ) )
if( parse_data( exports, globals, begin, &declns ) )
{
if( verbose )
{
......@@ -97,9 +99,10 @@ void main( argc, argv ) int argc; char **argv;
print_declnlist( declns );
printf( "exports = {%s}\n", exports );
printf( "globals = {%s}\n", globals );
printf( "begin = {%s}\n", begin );
}
optimize( declns );
make_declns( exports, globals, declns, basename );
make_declns( exports, globals, begin, declns, basename );
} else
{
fprintf( stderr, "datadec: can't parse input properly\n" );
......
......@@ -12,12 +12,12 @@ stat %
#ifdef HASPROTOS
static void line( char * , long , long , long , long );
static void h_declns( char * , char * , declnlist );
static void c_declns( char * , char * , declnlist );
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( declnlist , BOOL );
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 );
......@@ -27,12 +27,12 @@ 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 , char * , shapelist );
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( char * , paramlist , BOOL );
static void print_param( shapelist , paramlist , BOOL );
#else
static void line();
static void h_declns();
......@@ -83,21 +83,21 @@ static void line( fmt, a, b, c, d ) char *fmt; long a, b, c, d;
}
void make_declns( exports, globals, d, basename ) declnlist d; char *exports, *globals, *basename;
void make_declns( exports, globals, begin, d, base ) declnlist d; char *exports, *globals, *begin, *base;
{
printf( "datadec: Making data declarations in %s.[ch]\n", basename );
h_declns( basename, exports, d );
c_declns( basename, globals, d );
printf( "datadec: Making data declarations in %s.[ch]\n", base );
h_declns( base, exports, *begin != '\0', d );
c_declns( base, globals, begin, d );
}
static void h_declns( basename, exports, d ) char *basename, *exports; declnlist d;
static void h_declns( base, exports, init, d ) char *base, *exports; BOOL init; declnlist d;
{
char tempname[256];
char *exportptr;
FILE *hfile;
sprintf( tempname, "%s.h", basename );
sprintf( tempname, "%s.h", base );
hfile = fopen( tempname, "w" );
ASSERT( hfile != NULL, ("datadec: can't create '%s'\n",tempname) );
......@@ -134,9 +134,9 @@ static void h_declns( basename, exports, d ) char *basename, *exports; declnlist
line( "\n/* Prototypes for all types */\n" );
line( "#ifdef HASPROTOS" );
protos( d, TRUE );
protos( init, base, d, TRUE );
line( "#else" );
protos( d, FALSE );
protos( init, base, d, FALSE );
line( "#endif" );
if( *exportptr != '\0' )
......@@ -151,13 +151,13 @@ static void h_declns( basename, exports, d ) char *basename, *exports; declnlist
}
static void c_declns( basename, globals, d ) char *basename, *globals; declnlist d;
static void c_declns( base, globals, begin, d ) char *base, *globals, *begin; declnlist d;
{
char tempname[256];
FILE *cfile;
char *globalptr;
sprintf( tempname, "%s.c", basename );
sprintf( tempname, "%s.c", base );
cfile = fopen( tempname, "w" );
ASSERT( cfile != NULL, ("datadec: can't create '%s'\n",tempname) );
......@@ -168,7 +168,7 @@ static void c_declns( basename, globals, d ) char *basename, *globals; declnlist
line( " */\n" );
line( "#include <stdio.h>" );
line( "#include <malloc.h>" );
line( "#include \"%s.h\"\n\n", basename );
line( "#include \"%s.h\"\n\n", base );
if( *globals != '\0' )
{
......@@ -201,6 +201,14 @@ static void c_declns( basename, globals, d ) char *basename, *globals; declnlist
nl();
}
if( *begin != '\0' )
{
line( "/* Contents of BEGIN section */" );
line( "void init_%s()", base );
line( "{" );
line( begin );
line( "}" );
}
fclose( cfile );
}
......@@ -314,12 +322,21 @@ static void declfields( p ) paramlist p;
/* ---------------------- Declare all prototypes -------------------------- */
static void protos( d, prot ) declnlist d; BOOL prot;
static void protos( init, base, d, prot ) BOOL init; char *base; declnlist d; BOOL prot;
{
for( ; d != NULL; d = d->next )
{
proto_type( d, prot );
}
if( init )
{
fprintf( outfile, "extern void init_%s( ", base );
if( prot )
{
fputs( "void ", outfile );
}
fputs( ");\n", outfile );
}
}
......
#ifdef HASPROTOS
extern void make_declns( char * , char * , declnlist , char * );
extern void make_declns( char * , char * , char * , declnlist , char * );
#else
extern void make_declns();
#endif
......@@ -11,7 +11,7 @@
******* Tokens:
*
* tERROR tEOF tSEMI tID tEQ tOR tOPENBR tCOMMA tCLOSEBR
* tSTR tNUM tEXPORT tGLOBAL tOPENCURLY tCLOSECURLY tTYPE
* tSTR tNUM tEXPORT tGLOBAL tBEGIN tOPENCURLY tCLOSECURLY tTYPE
*/
......@@ -24,7 +24,7 @@
static char *tokenname[] = {
"tERROR", "tEOF", "tSEMI", "tID", "tEQ", "tOR", "tOPENBR",
"tCOMMA", "tCLOSEBR", "tSTR", "tNUM", "tEXPORT", "tGLOBAL",
"tOPENCURLY", "tCLOSECURLY", "tTYPE"
"tBEGIN", "tOPENCURLY", "tCLOSECURLY", "tTYPE"
};
#endif
......@@ -137,6 +137,9 @@ TOKEN nexttok()
} else if( streq( curid, "GLOBAL" ) )
{
curtok = tGLOBAL;
} else if( streq( curid, "BEGIN" ) )
{
curtok = tBEGIN;
} else if( streq( curid, "TYPE" ) )
{
curtok = tTYPE;
......
......@@ -15,7 +15,7 @@
typedef enum {
tERROR, tEOF, tSEMI, tID, tEQ, tOR,
tOPENBR, tCOMMA, tCLOSEBR, tSTR, tNUM,
tEXPORT, tGLOBAL, tOPENCURLY, tCLOSECURLY, tTYPE
tEXPORT, tGLOBAL, tBEGIN, tOPENCURLY, tCLOSECURLY, tTYPE
} TOKEN;
......
......@@ -17,7 +17,7 @@ stat %
static void line( char * , long , long , long , long );
static void defn_declns( char * , char * , declnlist );
static void defn_onetype( decln );
static void impln_declns( char * , char * , declnlist );
static void impln_declns( char * , char * , char * , declnlist );
static void impln_onetype( decln );
static void variantfields( decln );
static void normalfields( decln );
......@@ -70,27 +70,26 @@ static int predefined_type();
#endif
static int numtabs = 0;
static FILE *outfile;
/* ------------------------- PUBLIC PROCEDURES --------------------------- */
void make_declns( exports, globals, d, basename ) declnlist d; char *exports, *globals, *basename;
void make_declns( exports, globals, begin, d, base ) declnlist d; char *exports, *globals, *begin, *base;
{
printf( "m2datadec: Making data declarations in %s.{def,mod}\n",
basename );
printf( "m2datadec: Making data declarations in %s.{def,mod}\n", base );
defn_declns( exports, basename, d );
defn_declns( exports, base, d );
impln_declns( globals, basename, d );
impln_declns( globals, begin, base, d );
}
/* ------------------------- PRIVATE PROCEDURES -------------------------- */
static int numtabs = 0;
static FILE *outfile;
#define indent() numtabs++
#define outdent() numtabs--
......@@ -252,7 +251,7 @@ static void defn_onetype( d ) decln d;
/* ----------------------- Implementation module ------------------------- */
static void impln_declns( globals, modulename, decs ) char *globals, *modulename; declnlist decs;
static void impln_declns( globals, begin, modulename, decs ) char *globals, *begin, *modulename; declnlist decs;
{
FILE *implnfile;
char tempname[256];
......@@ -330,6 +329,11 @@ static void impln_declns( globals, modulename, decs ) char *globals, *modulename
}
line( "BEGIN" );
if( *begin != '\0' )
{
line( "\t(* Contents of BEGIN section *)" );
line( begin );
}
line( "END %s.", modulename );
fclose( implnfile );
}
......
......@@ -12,6 +12,7 @@
*
* data = [ tEXPORT chunk ]
* [ tGLOBAL chunk ]
* [ tBEGIN chunk ]
* tTYPE tOPENCURLY declns tCLOSECURLY
* chunk = tOPENCURLY list_of_lines tCLOSECURLY
* declns = list*( decln ) tEOF
......@@ -68,10 +69,11 @@ static BOOL parse_param();
/*
* data = [ tEXPORT tOPENCURLY crap_to_} ]
* [ tGLOBAL tOPENCURLY crap_to_} ]
* [ tBEGIN tOPENCURLY crap_to_} ]
* tTYPE tOPENCURLY declns tCLOSECURLY
*/
BOOL parse_data( exports, globals, dp ) char *exports, *globals; declnlist *dp;
BOOL parse_data( exports, globals, begin, dp ) char *exports, *globals, *begin; declnlist *dp;
{
if( nexttok() == tEXPORT )
{
......@@ -90,7 +92,17 @@ BOOL parse_data( exports, globals, dp ) char *exports, *globals; declnlist *dp;
*globals = '\0';
ungettok();
}
MUSTBE( tTYPE, "TYPE/EXPORT/GLOBAL expected" );
if( nexttok() == tBEGIN )
{
if( ! parse_chunk( begin ) ) return FALSE;
} else
{
*begin = '\0';
ungettok();
}
MUSTBE( tTYPE, "TYPE/EXPORT/GLOBAL/BEGIN expected" );
MUSTBE( tOPENCURLY, "{ expected" );
if( ! parse_declns( dp ) ) return FALSE;
MUSTBE( tCLOSECURLY, "{ expected" );
......
#ifdef HASPROTOS
extern BOOL parse_data( char * , char * , declnlist * );
extern BOOL parse_data( char * , char * , char * , declnlist * );
#else
extern BOOL parse_data();
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment