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 @@
*
* This program builds C data declarations, construction functions
* 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
* ( x.c and x.h ) which together form a module provided the
* relevent data types.
* The output produced is placed in pair of files (eg. x.c and x.h )
* which together form a module provided the relevent data types.
*/
#include <dcw.h>
......@@ -23,19 +22,39 @@
#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;
{
FILE *infile, *cfile, *hfile;
char inname[256], tempname[256];
FILE *cfile, *hfile;
char tempname[256];
declnlist declns;
int len;
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 );
if( !strcmp( basename+len-2, ".c" ) ) {
if( !strcmp( basename+len-2, ".c" ) )
{
basename[len-2] = '\0';
}
......@@ -47,16 +66,29 @@ main( argc, argv ) int argc; char **argv;
hfile = fopen( tempname, "w" );
ASSERT( hfile != NULL, ("datadec: can't create '%s'\n",tempname) );
if( argc == 3 ) {
lexfile = fopen( argv[2], "r" );
if( IS_ANOTHER_ARG ) {
lexfile = fopen( argv[arg], "r" );
ASSERT( lexfile != NULL,
("datadec: can't open '%s'\n",argv[2]) );
("datadec: can't open '%s'\n",argv[arg]) );
arg++;
} else {
lexfile = stdin;
}
ASSERT( parse_declns( &declns ),
("datadec: can't parse input properly\n") );
make_declns( declns, cfile, hfile, basename );
REQUIRE_NO_MORE_ARGS;
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( hfile );
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