Commit 8ad1cf7d authored by dcw's avatar dcw
Browse files

moved opening/closing of files into make_declns;

added exports and globals sections to the parse language..
parent 88a01743
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "lexer.h" #include "lexer.h"
#include "parser.h" #include "parser.h"
#include "decs.h" #include "decs.h"
#include "optimize.h"
#define MUSTBE(b) ASSERT(b,("Usage: datadec [-vpo] outfile [infile]\n")) #define MUSTBE(b) ASSERT(b,("Usage: datadec [-vpo] outfile [infile]\n"))
...@@ -30,15 +31,17 @@ ...@@ -30,15 +31,17 @@
#define IS_ANOTHER_ARG (argc > arg) #define IS_ANOTHER_ARG (argc > arg)
main( argc, argv ) int argc; char **argv; #define CHUNKSIZE 10000
void main( argc, argv ) int argc; char **argv;
{ {
FILE *cfile, *hfile;
char tempname[256];
char *basename; char *basename;
char *s; char *s;
declnlist declns; declnlist declns;
int len; int len;
int arg; int arg;
char exports[CHUNKSIZE], globals[CHUNKSIZE];
arg = 1; arg = 1;
NEED_ANOTHER_ARG; NEED_ANOTHER_ARG;
...@@ -74,14 +77,6 @@ main( argc, argv ) int argc; char **argv; ...@@ -74,14 +77,6 @@ main( argc, argv ) int argc; char **argv;
basename[len-2] = '\0'; basename[len-2] = '\0';
} }
sprintf( tempname, "%s.c", basename );
cfile = fopen( tempname, "w" );
ASSERT( cfile != NULL, ("datadec: can't create '%s'\n",tempname) );
sprintf( tempname, "%s.h", basename );
hfile = fopen( tempname, "w" );
ASSERT( hfile != NULL, ("datadec: can't create '%s'\n",tempname) );
if( IS_ANOTHER_ARG ) { if( IS_ANOTHER_ARG ) {
lexfile = fopen( argv[arg], "r" ); lexfile = fopen( argv[arg], "r" );
ASSERT( lexfile != NULL, ASSERT( lexfile != NULL,
...@@ -93,19 +88,21 @@ main( argc, argv ) int argc; char **argv; ...@@ -93,19 +88,21 @@ main( argc, argv ) int argc; char **argv;
REQUIRE_NO_MORE_ARGS; REQUIRE_NO_MORE_ARGS;
if( parse_declns( &declns ) ) if( parse_data( exports, globals, &declns ) )
{ {
if( verbose ) if( verbose )
{ {
printf( "datadec: declns are:\n\n" ); printf( "datadec: declns are:\n\n" );
print_declnlist( declns ); print_declnlist( declns );
printf( "exports = {%s}\n", exports );
printf( "globals = {%s}\n", globals );
} }
make_declns( declns, cfile, hfile, basename ); optimize( declns );
make_declns( exports, globals, declns, basename );
} else } else
{ {
fprintf( stderr, "datadec: can't parse input properly\n" ); fprintf( stderr, "datadec: can't parse input properly\n" );
} }
fclose( cfile );
fclose( hfile );
exit(0); exit(0);
/*NOTREACHED*/
} }
Supports Markdown
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