Skip to content
Snippets Groups Projects
Commit 261b7c79 authored by dcw's avatar dcw
Browse files

rewrote arg processing a bit,

added verbose flag.
parent 05647625
No related branches found
No related tags found
No related merge requests found
...@@ -10,11 +10,10 @@ ...@@ -10,11 +10,10 @@
* *
* This program builds C data declarations, construction functions * This program builds C data declarations, construction functions
* and print functions from a series of HOPE/Miranda style recursive * and print functions from a series of HOPE/Miranda style recursive
* data declarations. (with hints on printing) * data declarations. (with optional hints on printing)
* *
* The output produced is placed in pair of files * The output produced is placed in pair of files (eg. x.c and x.h )
* ( x.c and x.h ) which together form a module provided the * which together form a module provided the relevent data types.
* relevent data types.
*/ */
#include <dcw.h> #include <dcw.h>
...@@ -23,19 +22,39 @@ ...@@ -23,19 +22,39 @@
#include "parser.h" #include "parser.h"
#define MUSTBE(b) ASSERT(b,("Usage: datadec [-v] outfile [infile]\n"))
#define NEED_ANOTHER_ARG MUSTBE( IS_ANOTHER_ARG )
#define REQUIRE_NO_MORE_ARGS MUSTBE( argc == arg )
#define IS_ANOTHER_ARG (argc > arg)
main( argc, argv ) int argc; char **argv; main( argc, argv ) int argc; char **argv;
{ {
FILE *infile, *cfile, *hfile; FILE *cfile, *hfile;
char inname[256], tempname[256]; char tempname[256];
declnlist declns; declnlist declns;
int len; int len;
char *basename; char *basename;
BOOL verbose;
int arg;
ASSERT( argc==2 || argc==3, ("Usage: datadec outfile [infile]\n") ); arg = 1;
NEED_ANOTHER_ARG;
verbose = FALSE;
if( strcmp( argv[arg], "-v" )==0 )
{
arg++;
verbose = TRUE;
}
basename = argv[1]; NEED_ANOTHER_ARG;
basename = argv[arg++];
len = strlen( basename ); len = strlen( basename );
if( !strcmp( basename+len-2, ".c" ) ) { if( !strcmp( basename+len-2, ".c" ) )
{
basename[len-2] = '\0'; basename[len-2] = '\0';
} }
...@@ -47,16 +66,29 @@ main( argc, argv ) int argc; char **argv; ...@@ -47,16 +66,29 @@ main( argc, argv ) int argc; char **argv;
hfile = fopen( tempname, "w" ); hfile = fopen( tempname, "w" );
ASSERT( hfile != NULL, ("datadec: can't create '%s'\n",tempname) ); ASSERT( hfile != NULL, ("datadec: can't create '%s'\n",tempname) );
if( argc == 3 ) { if( IS_ANOTHER_ARG ) {
lexfile = fopen( argv[2], "r" ); lexfile = fopen( argv[arg], "r" );
ASSERT( lexfile != NULL, ASSERT( lexfile != NULL,
("datadec: can't open '%s'\n",argv[2]) ); ("datadec: can't open '%s'\n",argv[arg]) );
arg++;
} else { } else {
lexfile = stdin; lexfile = stdin;
} }
ASSERT( parse_declns( &declns ),
("datadec: can't parse input properly\n") ); REQUIRE_NO_MORE_ARGS;
make_declns( declns, cfile, hfile, basename );
if( parse_declns( &declns ) )
{
if( verbose )
{
printf( "parsed declns: they are:\n\n" );
print_declnlist( declns );
}
make_declns( declns, cfile, hfile, basename );
} else
{
fprintf( stderr, "datadec: can't parse input properly\n" );
}
fclose( cfile ); fclose( cfile );
fclose( hfile ); fclose( hfile );
exit(0); exit(0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment