/* @(#)chgen.c 2.1 93/05/18 */ /******************************************************************************/ /* function : chgen.c (application's main) */ /* */ /* subsystem : chgen */ /* */ /* input : command line arguments (argv, argc) */ /* */ /* output : (generates output schema handling code, and/or errors)*/ /* */ /* returns : exit status (integer, 0 = success) */ /* */ /* author : Steve Smith / Craig Smith */ /* */ /* created : July, 1991 */ /* */ /* */ /* description : This routine is the main module for the chgen compiler. */ /* The main purpose of this module is to parse, validate and */ /* interpret the command line arguments. Next, various */ /* routines are called to parse the schema and generate output */ /* files. */ /* This system was originally developed by Cheng in 1989. */ /* In 1990, Steve and Craig Smith implemented extensive changes */ /* to the original code, including breaking it up into several */ /* modules (the original system was a sinle .c file), adding */ /* functionality, improving parsing, and documentation. */ /* */ /******************************************************************************/ /*****************************************************************************/ /* CHGEN V9.0 94sgen - mcook, hsano, jhyun */ /* */ /* */ /* Basic enhancements include the ability to read in both a gendb and a */ /* schema file, by specifying a command line switch. */ /* */ /* Revision history: */ /* */ /* 5/18/94 - mcook - Changed the command line qualifier from "-datafile" */ /* to "-metafile". And no longer allow the user to */ /* enter in a filename, we use the convention - */ /* "schemafilename.msdat". */ /* Got rid of error message CHGEN-W-DEFDFN. No longer */ /* applicable the new naming convention. */ /* */ /* 5/16/94 - mcook - Added the command line qualifier "-nosource". */ /* If this option is specified, no .c or .h files will */ /* be outputted. Not practical if you are not also */ /* specifying "-datafile". Useful to create datafile */ /* only. */ /* */ /* 5/15/94 - mcook - Added warning CHGEN-W-DEFDFN which causes the */ /* datafile name to be defaulted to "metaschema.dat" if */ /* no datafile name was specified. */ /* */ /* 5/09/94 - mcook - Added the command line qualifier "-datafile=*". */ /* If this is specified, an output file will be created */ /* called the name specified, and it will contain the */ /* TT and TA tables, along with information about their */ /* relationship. */ /* */ /* 5/01/94 - mcook - Added the command line qualifier "-gendbschema". */ /* The default is to read in a chgen schema file. If */ /* "-gendbschema" is specified on the command line, a */ /* gendb schema file will be read. */ /*****************************************************************************/ /*****************************************************************************/ /* */ /* 5/06/96 - B. Rideout - Additions to allow optional logging of */ /* database changes with command line qualifier */ /* "-log". The default is to generate no code */ /* to support logging. If "-log" is specified */ /* on the command line, then pr_* files are */ /* modified to support logging, and a new file, */ /* pr_log.c is output. */ /* */ /*****************************************************************************/ /*****************************************************************************/ /* CHGEN V11.0 99s523 - kspinney, jkarner */ /* */ /* */ /* Basic enhancements include the ability to read in a metaschema file in */ /* .dat (or .msdat) format. */ /* */ /* Revision history: */ /* */ /* 4/11/99 - kspinney - initial modifications. These consisted of */ /* generating pr*.c and metaschema.h files from */ /* chgenv10 using the schema file metaschema.sch - */ /* which contains the metadata for the SV/TT/TA/TS/VV*/ /* scructs- and including these files in chgenv11. */ /* Modifications were made to read input in .dat */ /* format if the option -datinput is specified */ /* Also, a .viewdefs file must accompany */ /* the .dat input file, and the -viewname */ /* command line option must be specified */ /* 11/30/00 - kmiu - Return type of main is int */ /*****************************************************************************/ #define MAIN #include "chgen_define.h" #include "chgen_externs.h" #include "prototypes.h" #ifndef FALSE #define FALSE 0 #define TRUE 1 #endif #ifdef sun4 #define EXIT_FAILURE 1 #define EXIT_SUCCESS 0 #endif int main(int argc, char **argv) { static char rcsid[] = "$Id: chgen.c,v 1.4.4.2 1999/05/07 01:25:00 jkarner Exp $"; int i,j,file_found_yet,validate_only, key_set; char temp_int[20],temp_filename[SCHEMA_HEADER_FILE_NAME_LENGTH]; /* sch_header_file_name in the begining is the same with schema.txt file name which is keyed in by the user . But sooner we change its file extention from ".txt" (or anything else ) to ".h" . */ pc_table = NULL; /* parent-child table */ cp_table = NULL; /* child-parent table */ tt = NULL; /* list of tables */ tt_curr = NULL; tt_tmp = NULL; ta_curr = NULL; /* list of fields */ ta_tmp = NULL; PXindex = 0; hcg_abbr_size = 2; /* default table abbrev size (and thus key size) */ key_set = 0; if (argc < 2) { /* removed the % before CHGEN-F-INVARGS. I don't know why it was there */ /* but it caused a seg fault when executed. maldred 22-Nov-95 */ printf("%CHGEN-F-INVARGS, Usage: chgen 'schema-filename'[.sch] [-keysize=n] [-nobp] [-ansi] [-quiet] [-validate] [-noforward] [-maxviews=n] [-noorder] [-gendbschema] [-metafile] [-nosource] [-datinput] [-viewname ]\n"); exit(EXIT_FAILURE); } file_found_yet = FALSE; cli_ansi = FALSE; cli_nobp = FALSE; cli_quiet = FALSE; cli_noforward = FALSE; cli_maxviews = FALSE; cli_noorder = FALSE; cli_gendbschema = FALSE; cli_datafile = FALSE; cli_nosource = FALSE; cli_datinput = FALSE; cli_viewname = FALSE; cli_log = FALSE; validate_only = FALSE; user_maxviews = MAXVIEWS; for (j = 1; j SCHEMA_HEADER_FILE_NAME_LENGTH )) { /* removed the % before CHGEN-F-FILENAMELEN. I don't know why it was there */ /* but it caused a seg fault when executed. maldred 22-Nov-95 */ printf ("CHGEN-F-FILENAMELEN, input schema filename length (%d) exceeds the max of %d\n",strlen(argv[j]),SCHEMA_HEADER_FILE_NAME_LENGTH); exit(EXIT_FAILURE); } strcpy(sch_text_file_name,argv[j]); for ( i = strlen(sch_text_file_name); (i>=0) && (sch_text_file_name[i] != '.') && (sch_text_file_name[i] != ']') && (sch_text_file_name[i] != ':') && (sch_text_file_name[i] != '/'); i-- ); if ((i<0) || (sch_text_file_name[i] != '.')) /* no extention, add one */ strcat(sch_text_file_name,".sch"); for ( i = strlen(sch_text_file_name); (i>=0) && (sch_text_file_name[i] != ']') && (sch_text_file_name[i] != ':') && (sch_text_file_name[i] != '/'); i-- ); if ((i>=0) && /* name has a directory spec, figure out real filename */ ((sch_text_file_name[i] == ']') || (sch_text_file_name[i] == ':') || (sch_text_file_name[i] == '/'))) strcpy(temp_filename,sch_text_file_name+i+1); else strcpy(temp_filename,sch_text_file_name); } else if (strcmp(argv[j],"-ansi") == 0) cli_ansi = TRUE; else if (strcmp(argv[j],"-nobp") == 0) cli_nobp = TRUE; else if (strcmp(argv[j],"-validate") == 0) validate_only = TRUE; else if (strcmp(argv[j],"-quiet") == 0) cli_quiet = TRUE; else if (strcmp(argv[j],"-noforward") == 0) cli_noforward = TRUE; else if (strncmp(argv[j], "-keysize=",9) == 0) { key_set = 1; strcpy(temp_int, argv[j]); i = atoi(temp_int+9); if(i == 8); else if(i == 12) hcg_abbr_size = 4; else { printf("CHGEN-F-BADKEYSIZE, %d is an invalid value for the keysize qualifier\n", argv[j]); exit(1); } } else if (strncmp(argv[j],"-maxviews=",10) == 0) { cli_maxviews = TRUE; strcpy(temp_int,argv[j]); i = atoi(temp_int+10); if (i <= 0) { printf("CHGEN-F-BADMAXVIEWS, %d is an invalid value for the maxviews qualifier\n", argv[j]); exit(EXIT_FAILURE); } user_maxviews = i; } else if (strcmp(argv[j],"-noorder") == 0) cli_noorder = TRUE; else if (strcmp(argv[j],"-gendbschema") == 0) cli_gendbschema = TRUE; else if (strcmp(argv[j],"-metafile") == 0) { cli_datafile = TRUE; strcpy (datafile, ""); } else if (strcmp(argv[j],"-nosource") == 0) cli_nosource = TRUE; else if (strcmp(argv[j],"-datinput") == 0) { cli_datinput = TRUE; strcpy((char *)strstr(sch_text_file_name,".sch"),".dat"); /* change the .sch extension to .dat */ strcpy(sch_viewdef_file_name, sch_text_file_name); /* the viewdef & sch file have same base */ strcpy((char *)strstr(sch_viewdef_file_name,".dat"),".viewdefs"); /* change the .dat extension to .viewdefs */ } else if (strcmp(argv[j],"-viewname") == 0) { cli_viewname = TRUE; if (++j >= argc) { printf ("CHGEN-F-NOVIEWNAME, command-line qualifier -viewname is not followed by a view name\n"); exit(EXIT_FAILURE); } strcpy(view_name,argv[j]); } else if (strcmp(argv[j], "-log") == 0) cli_log = TRUE; else { printf("CHGEN-F-BADQUAL, unknown qualifier %s specified in command line\n", argv[j]); exit(EXIT_FAILURE); } } /* for j */ if (!file_found_yet) { printf("CHGEN-F-NOSCHEMAFILE, no schema file specified\n"); exit(EXIT_FAILURE); } if (!cli_quiet) { /*printf("\nCHGEN %s, released %s, Copyright 1991, University of Mass - Lowell\n\n",CHGEN_VERSION,CHGEN_RELEASE_DATE());*/ printf("\nCHGEN %s, released Thu May 06 11:00:00 GMT 1999, Copyright 1999, University of Mass - Lowell\n\n", CHGEN_VERSION); if (!key_set) printf("CHGEN-I-DEFAULTQUAL, Using default key size of 8 characters\n"); if (cli_ansi) printf("CHGEN-I-NONDEFAULTQUAL, Using non-default command-line qualifier -ansi\n"); if (cli_nobp) printf("CHGEN-I-NONDEFAULTQUAL, Using non-default command-line qualifier -nobp\n"); if (validate_only) printf("CHGEN-I-NONDEFAULTQUAL, Using non-default command-line qualifier -validate\n"); if (cli_noforward) printf("CHGEN-I-NONDEFAULTQUAL, Using non-default command-line qualifier -noforward\n"); if (cli_maxviews) printf("CHGEN-I-NONDEFAULTQUAL, Using non-default command-line qualifier -maxviews\n"); if (cli_noorder) printf("CHGEN-I-NONDEFAULTQUAL, Using non-default command-line qualifier -noorder\n"); if (cli_gendbschema) printf("CHGEN-I-NONDEFAULTQUAL, Using non-default command-line qualifier -gendbschema\n"); if (cli_datafile) printf ("CHGEN-I-NONDEFAULTQUAL, Using non-default command-line qualifier -metafile\n"); if (cli_datinput) printf ("CHGEN-I-NONDEFAULTQUAL, Using non-default command-line qualifier -datinput\n"); if (cli_viewname) printf ("CHGEN-I-NONDEFAULTQUAL, Using non-default command-line qualifier -viewname with view_name = %s\n",view_name); if (cli_log) printf ("CHGEN-I-NONDEFAULTQUAL, Using non-default command-line qualifier -log\n"); } if (cli_datinput && cli_gendbschema) { printf ("CHGEN-F-INCOMPATINPUT, command-line qualifiers -datinput and -gendbschema are incompatible\n"); exit(EXIT_FAILURE); } if (cli_datinput && (hcg_abbr_size == 4)) { printf ("CHGEN-F-INCOMPATINPUT, command-line qualifier -datinput is incompatible with a keysize of 12\n"); exit(EXIT_FAILURE); } if (cli_datinput && !cli_viewname) { printf ("CHGEN-F-NOCLIVIEWNAME, command line qualifier -viewname must be entered if -datinput qualifier is used\n"); exit(EXIT_FAILURE); } strcpy(sch_header_file_name, temp_filename); change_file_exten (sch_header_file_name , "h" ); if ((schtxt_fp=fopen(sch_text_file_name,"r")) == NULL) { /* removed the % before CHGEN-F-FILNOTFND. I don't know why it was there */ /* but it caused a seg fault when executed. maldred 22-Nov-95 */ printf("CHGEN-F-FILNOTFND, can not open %s, file not found\n", sch_text_file_name); exit(EXIT_FAILURE); } if (cli_datafile) { strncpy (datafile, sch_text_file_name, strlen(sch_text_file_name) - 4); strcat (datafile, ".msdat"); printf ("temp = %s\n", datafile); } lut_init(&hcg_table_abbrev_lut, ABBR_TBL_TYPE); /* init lookup table */ parse_schema(); validate_schema(); if (validate_only) exit(EXIT_SUCCESS); if (cli_datafile && !cli_datinput) /* if cli_datinput, then the .msdat file was pr_dumped */ Output_MetaSchema(); if (!cli_nosource) { open_files(); gen_defines(); write_rr_table(); gen_rr_matrix(); gen_macros(); gen_structures(); gen_cc_files(); close_files(); } if (!cli_quiet) printf("Processing Complete\n"); exit(EXIT_SUCCESS); return(0); }