/* @(#)gen_defines.c 2.1 95/05/11 */ /******************************************************************************/ /* function : gen_defines */ /* */ /* subsystem : chgen */ /* */ /* input : */ /* */ /* output : */ /* */ /* returns : void */ /* */ /* author : Sathyanarayan Jaganathan */ /* */ /* created : July, 1991 */ /* */ /* revisions : Nov 2001: modified to fix warnings for BDE - sjaganat */ /* (code change for 40 lines approx.) */ /* */ /* Oct 29 1991: fixed typo in #define last_child macro -RJL */ /* and put this version back into case/gen/ver_6/src. */ /* 93s523: added #define MAXVERSIONS, extensive modifications */ /* to most macros (marked by 93s523) to incorported int pkeys */ /* */ /* Mar 4 1997: Fixed var_last_child bug: - RJL */ /* Mar21 1997: Changed encode prototype as in genv10 - RJL */ /* May14 1997 Merged v9 and v10 - AS */ /* Apr24 1999 Added #include - JSK */ /* Apr26 1999 Hand merged ctwang updates of pr_set_key, pr_set_ */ /* flt, pr_set_int, and pr_set_str, - clearly */ /* delineated by wang's BEGIN and END markers. */ /* */ /* description : This routine generates the schema's .h file, up to (but not */ /* including) the actual table structures. Most of the logic */ /* is simply massive volumes of print statements, but a few */ /* sections loop over the internal structures generating */ /* schema dependent output. Another important point is that */ /* it is this module that outputs potentially different */ /* macro code, based off the cli_ qualifiers used. */ /* */ /******************************************************************************/ /******************************************************************************/ /* 95s523 (V10), chwang modifies the file to generate the btree_add_row() */ /* macro and add few lines into pr_find(). 5,11,95 */ /******************************************************************************/ /******************************************************************************/ /* Modified by Genlog 5/8/96 to support logging */ /******************************************************************************/ #include #include #include "chgen_define.h" #include "chgen_externs.h" #include "lut_h_file.h" #include "prototypes.h" void gen_defines (void) { static char rcsid[] = ""; int i; char sep[5]; if (cli_ansi) strcpy(sep,"##"); else strcpy(sep,"/**/"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* File : %-58s */\n",sch_header_file_name); fprintf(schh_fp,"/* Schema : %-58s */\n",sch_text_file_name); fprintf(schh_fp,"/* Chgen Version : %-58s */\n",CHGEN_VERSION); if(hcg_abbr_size == 2) fprintf(schh_fp,"/* Chgen keysize : 8 characters */\n"); else fprintf(schh_fp,"/* Chgen keysize : 12 characters */\n"); fprintf(schh_fp,"/******************************************************************************/\n\n"); fprintf(schh_fp, "#ifndef __SCHEMA_LOADED\n") ; fprintf(schh_fp, "#define __SCHEMA_LOADED 1\n") ; fprintf(schh_fp, "#include \n\n") ; /* 93su523 PGEN merge */ fprintf(schh_fp, "#include \n\n"); /* Sathya */ fprintf(schh_fp, "#include \n\n") ; fprintf(schh_fp, "#include \n\n") ; /* 99s523 gen log merge */ /* These should not need to be defined here. It should be fixed */ /* maldred 10-Dec-95 */ fprintf(schh_fp, "#define TRUE 1\n"); fprintf(schh_fp, "#define FALSE 0\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* These macros indicate which version of CHGEN was used to produce this */\n"); fprintf(schh_fp,"/* code, and the command-line qualifiers used as well. */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp, "#define CHGEN_VERSION \"%s\"\n",CHGEN_VERSION); fprintf(schh_fp, "#define CHGEN_RELEASE_DATE \"%s\"\n",CHGEN_RELEASE_DATE); fprintf(schh_fp, "#define CHGEN_QUALIFIERS \""); if (cli_ansi) fprintf(schh_fp, " -ansi"); if (cli_nobp) fprintf(schh_fp, " -nobp"); if (cli_quiet) fprintf(schh_fp, " -quiet"); if (cli_noforward) fprintf(schh_fp, " -noforward"); if (cli_maxviews) fprintf(schh_fp, " -maxviews"); if (cli_noorder) fprintf(schh_fp, " -noorder"); fprintf(schh_fp, "\"\n\n"); if (cli_ansi) { fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* NOTE: The symbol ## found throughout this include file is called the */\n"); fprintf(schh_fp,"/* identifier concatenation symbol. This symbol is ansi 'C' specific, */\n"); fprintf(schh_fp,"/* and its equivalent in K&R 'C' is the empty comment (which cannot */\n"); fprintf(schh_fp,"/* be typed here, to avoid nested comments). By using this symbol, */\n"); fprintf(schh_fp,"/* macros are able to construct larger identifier names out of smaller */\n"); fprintf(schh_fp,"/* ones. For example, given a table name AA, the AAcurr variable can */\n"); fprintf(schh_fp,"/* be 'referenced' by concatenating AA with curr. This concept is */\n"); fprintf(schh_fp,"/* exploited throughout the macros in this system. */\n"); fprintf(schh_fp,"/******************************************************************************/\n\n"); } else { fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* NOTE: The empty comment symbol (which cannot be typed here, to avoid */\n"); fprintf(schh_fp,"/* nested comments) found throughout this include file is called the */\n"); fprintf(schh_fp,"/* identifier concatenation symbol. This symbol is K&R 'C' specific, */\n"); fprintf(schh_fp,"/* and its equivalent in ansi 'C' is ##. By using this symbol, */\n"); fprintf(schh_fp,"/* macros are able to construct larger identifier names out of smaller */\n"); fprintf(schh_fp,"/* ones. For example, given a table name AA, the AAcurr variable can */\n"); fprintf(schh_fp,"/* be 'referenced' by concatenating AA with curr. This concept is */\n"); fprintf(schh_fp,"/* exploited throughout the macros in this system. */\n"); fprintf(schh_fp,"/******************************************************************************/\n\n"); } fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* This macro will either declare or define the table variables for each */\n"); fprintf(schh_fp,"/* table in the schema. This general approach (#ifdef MAIN) is used often */\n"); fprintf(schh_fp,"/* to distinguish between a main module and a non-main module. In a main, */\n"); fprintf(schh_fp,"/* a definition can occur, and variable initialization can occur. In a non- */\n"); fprintf(schh_fp,"/* main, only a declaration can occur, so the word extern is used. Although */\n"); fprintf(schh_fp,"/* VAX 'C' can handle redundant definitions, several versions of 'C' for UNIX */\n"); fprintf(schh_fp,"/* cannot. */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); /* fprintf(schh_fp, "#ifdef MAIN\n") ; */ /* 93su523 PGEN merge (BEGIN) */ /* I moved '#ifdef MAIN' below pr_add's definition - RJL 96/8/31 * * pr_add generates 'implicit function decl and undefined' errors without it * * (also done by Mark Aldred for gen/ver_10/chgen/src/gen_defines.c - RJL) * * 97/05/13 AS: V10 did not have main commented out. Commented by GENMERGE */ /* 93su523 PGEN merge (BEGIN) (deleted 99s523 chgenbootstrap) */ /*if (cli_ansi) fprintf(schh_fp, "#define pr_add(view,tbl_abbr,tbl_ptr) gen_pr_add(view, #tbl_abbr, tbl_ptr)\n"); else fprintf(schh_fp, "#define pr_add(view,tbl_abbr,tbl_ptr) gen_pr_add(view, \"tbl_abbr\", tbl_ptr)\n" ); */ /* 93su523 PGEN merge (END) */ fprintf(schh_fp, "#ifdef MAIN\n") ; /* moved here by RJL 96/8/31 */ fprintf(schh_fp, "#define hcg_declare(tbl) *tbl = NULL , *tbl%scurr = NULL , *tbl%stemp = NULL , *tbl%send = NULL , *tbl%selt = NULL,\\\n",sep,sep,sep,sep) ; /*fprintf(schh_fp, " *tbl%scurr2 = NULL , *tbl%stemp2 = NULL;\n",sep,sep) ; Sathya */ fprintf(schh_fp, " *tbl%scurr2 = NULL , *tbl%stemp2 = NULL\n",sep,sep) ; fprintf(schh_fp, "#else\n") ; /* define pr_add here also to fix compile time but for bde. */ /* maldred 22-Nov-95 */ /*fprintf(schh_fp, "#define pr_add(view,tbl_abbr,tbl_ptr) gen_pr_add(view, #tbl_abbr, tbl_ptr)\n");*/ /*fprintf(schh_fp, "#define hcg_declare(tbl) *tbl, *tbl%scurr, *tbl%stemp, *tbl%send, *tbl%selt, *tbl%scurr2, *tbl%stemp2;\n", sep,sep,sep,sep,sep,sep) ; Sathya*/ fprintf(schh_fp, "#define hcg_declare(tbl) *tbl, *tbl%scurr, *tbl%stemp, *tbl%send, *tbl%selt, *tbl%scurr2, *tbl%stemp2\n", sep,sep,sep,sep,sep,sep) ; fprintf(schh_fp, "#endif\n\n") ; fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* This macro allows the optional insertion of the word 'extern' in various */\n"); fprintf(schh_fp,"/* structures and variables. */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp, "#ifndef MAIN\n") ; fprintf(schh_fp, "#define hcg_extern extern\n") ; fprintf(schh_fp, "#else\n") ; fprintf(schh_fp, "#define hcg_extern\n") ; fprintf(schh_fp, "#endif\n\n") ; fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* These macros are constants, which are copys of the same constants embedded */\n"); fprintf(schh_fp,"/* in CHGEN. */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp, "#define SCHEMA_TEXT_FILE_NAME \"%s\"\n", sch_text_file_name) ; fprintf(schh_fp, "#define SCHEMA_HEADER_FILE_NAME \"%s\"\n",sch_header_file_name ) ; fprintf(schh_fp, "#define SCHEMA_HEADER_FILE_NAME_LENGTH %d\n",SCHEMA_HEADER_FILE_NAME_LENGTH ) ; fprintf(schh_fp, "#define BUFSIZE %d\n", BUFSIZE); fprintf(schh_fp, "#define NAMELENGTH %d\n", NAMELENGTH); fprintf(schh_fp, "#define MAXVIEWS %d\n", user_maxviews); fprintf(schh_fp, "#define MAXVIEWNAMELEN %d\n", MAXVIEWNAMELEN); fprintf(schh_fp, "#define ABBREV_NAME_LENGTH %d\n\n", ABBREV_NAME_LENGTH); /**** 93s523 ****/ if(hcg_abbr_size == 2) fprintf(schh_fp, "#define MAXVERSIONS 99\n"); else fprintf(schh_fp, "#define MAXVERSIONS 255\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* These macros are based on the schema itself. */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp, "#define HCG_NUM_TABLES %d\n\n", num_tables); /**********************************************************/ /* This next statement takes a static string from include */ /* file lut_h_file.h and prints the lut.h info to the */ /* schema file .... */ /**********************************************************/ fprintf(schh_fp, "%s", p_lut_h); fprintf(schh_fp, "/****************************************************/\n"); fprintf(schh_fp, "/* The following decls are for key manipulation. */\n"); fprintf(schh_fp, "/* The key type is defined here as well. */\n"); fprintf(schh_fp, "/****************************************************/\n"); fprintf(schh_fp, "typedef unsigned long hcg_key;\n"); if (cli_ansi) fprintf(schh_fp,"#ifndef __cplusplus\n"); fprintf(schh_fp, "int encode();\n"); fprintf(schh_fp, "int decode();\n"); fprintf(schh_fp, "void pr_find_bt(char*, hcg_key*); \n\n"); /* Sathya */ fprintf(schh_fp, "char* decode_retstr(hcg_key*);\n"); /* Sathya */ fprintf(schh_fp, "int key_compare();\n"); fprintf(schh_fp, "char* get_abbr();\n"); fprintf(schh_fp, "int get_version();\n"); fprintf(schh_fp, "int get_row();\n"); fprintf(schh_fp, "int set_abbr();\n"); fprintf(schh_fp, "int set_version();\n"); fprintf(schh_fp, "int set_row();\n"); fprintf(schh_fp, "hcg_key* null_key();\n"); fprintf(schh_fp, "int is_null_key();\n"); fprintf(schh_fp, "int set_external_key_length();\n"); if (cli_ansi) fprintf(schh_fp,"#endif /*__cplusplus*/\n"); /* Sathya */ fprintf(schh_fp, "/******** End of key manipulation decls ****************/\n\n"); /*** 95s523,chwang,5,11,95. Add btree structures and other relative btree arguments. ***/ /*** 95f523,maldred 19-Nov-95 moved here from gen_structures.c for OSF ***/ /*** ---lines begin--- ***/ fprintf(schh_fp,"\n\n/******************************************************************************/\n"); fprintf(schh_fp,"/* The following define the btree structures and relative variables for each */\n"); fprintf(schh_fp,"/* table which defines btree search in schema file. */\n"); fprintf(schh_fp,"/******************************************************************************/\n\n"); fprintf(schh_fp,"\n#define BTREESEARCH 1 \n"); fprintf(schh_fp,"#define SEQUENCESEARCH 0 \n"); fprintf(schh_fp,"#define LEFT 2 \n"); fprintf(schh_fp,"#define RIGHT 3 \n\n"); tt_curr = tt; while (tt_curr != NULL) { /* made this an extern int and declared them as ints in */ /* gen_pr_utils.c to fix mulitiply defined problem on OSF. maldred 22-Nov-95 */ fprintf(schh_fp,"extern int %sbtidx; \n",tt_curr->TTabbr); if (tt_curr->comment[0] != '\0') if (tt_curr->comment[2] == '1') { fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* Table %s btree structure : %sbtree */\n",tt_curr->TTabbr,tt_curr->TTabbr); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"struct %sbtree \n",tt_curr->TTabbr); fprintf(schh_fp,"{ \n"); fprintf(schh_fp,"hcg_key key; /* primary key */ \n"); fprintf(schh_fp,"struct %s *ptr; \n",tt_curr->TTabbr); fprintf(schh_fp,"struct %sbtree *parent; \n",tt_curr->TTabbr); fprintf(schh_fp,"struct %sbtree *left; \n",tt_curr->TTabbr); fprintf(schh_fp,"struct %sbtree *right; \n",tt_curr->TTabbr); fprintf(schh_fp,"}; \n"); fprintf(schh_fp,"hcg_extern struct %sbtree *%sbtroot,*%sbtelt,*%sbttemp,*%sbtcurr; \n\n" ,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr ,tt_curr->TTabbr,tt_curr->TTabbr); } tt_curr=tt_curr->next_ptr; } /* end while tt_cur */ fprintf(schh_fp,"hcg_extern char tempbtree[BUFSIZE]; \n"); fprintf(schh_fp,"hcg_extern hcg_key btfinish,btresult;\n"); /*** ---lines end--- ***/ fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* This structure holds all information about a single view. Version list */\n"); fprintf(schh_fp,"/* is really a list of numbers, but since version numbers are in the range */\n"); fprintf(schh_fp,"/* 01->99, they can be stored in a single byte. This was done to minimize */\n"); fprintf(schh_fp,"/* the storage requirements of internal structures. In the future, even if */\n"); fprintf(schh_fp,"/* the 2-character version number embedded inside key fields becomes a 2-digit*/\n"); fprintf(schh_fp,"/* hexadecimal value, it can still be stored in a single byte. */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp, "struct view_elt_type\n{\n"); fprintf(schh_fp, "\tchar view_name[MAXVIEWNAMELEN];\n"); fprintf(schh_fp, "\tchar mode;\n"); fprintf(schh_fp, "\tchar version_list[HCG_NUM_TABLES];\n} ;\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* This structure variable holds all information about all views that have */\n"); fprintf(schh_fp,"/* been defined (by calling pr_init). */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp, "hcg_extern\n") ; fprintf(schh_fp, "struct hcg_view_list_type\n{\n"); fprintf(schh_fp, "\tint num_views;\n"); fprintf(schh_fp, "\tstruct view_elt_type view_list[MAXVIEWS];\n"); fprintf(schh_fp, "} hcg_view_list;\n\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* This structure holds all table-statistics maintained for a single table */\n"); fprintf(schh_fp,"/* at a single version. Currently, only rcount (number of rows in this table */\n"); fprintf(schh_fp,"/* at this version), and maxrow (highest embedded row-number for this table/ */\n"); fprintf(schh_fp,"/* version). While the code depends heavily on max-row (specifically, for */\n"); fprintf(schh_fp,"/* generating pkeys), the rcount value is maintained for users who may need */\n"); fprintf(schh_fp,"/* it (via the pr_rcount() macro). */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp, "struct ts_list_elt_type\n{\n"); fprintf(schh_fp, "\tint maxrow;\n"); fprintf(schh_fp, "\tint rcount;\n};\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* This structure holds all table-statistics structs (see above) for each */\n"); fprintf(schh_fp,"/* version that could exist for a single table. The value 100 would have */\n"); fprintf(schh_fp,"/* to be changed if hexadecimal version numbers were introduced. */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp, "struct ts_list_type\n{\n"); /**** 93s523 ****/ fprintf(schh_fp, "\tstruct ts_list_elt_type ts_list[MAXVERSIONS];\n};\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* This structure variable holds all table-statistics information for all */\n"); fprintf(schh_fp,"/* tables, and for each possible version of them. */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp, "hcg_extern\n"); fprintf(schh_fp, "struct ts_list_type hcg_ts_list[HCG_NUM_TABLES];\n\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* This structure is used to simplify type casting pointers within table */\n"); fprintf(schh_fp,"/* rows. */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp, "struct dummy_type\n{\n\tint dummy ;\n} ;\n\n"); /* 93su523 PGEN merge (BEGIN) */ /* Add support for get/set field */ fprintf(schh_fp,"\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* This following is a type definition for generic porinters */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"#ifdef __STDC__\n"); fprintf(schh_fp,"typedef void * hcg_ptr;\n"); fprintf(schh_fp,"#else\n"); fprintf(schh_fp,"typedef char * hcg_ptr;\n"); fprintf(schh_fp,"#endif\n"); fprintf(schh_fp,"\n"); fprintf(schh_fp,"extern hcg_ptr pr_gen_create();\n"); fprintf(schh_fp,"\n"); fprintf(schh_fp,"#define pr_create(tbl_abbr) \\\n"); fprintf(schh_fp,"\t(struct tbl_abbr *) pr_gen_create( sizeof( struct tbl_abbr))\n"); fprintf(schh_fp,"\n"); fprintf(schh_fp,"\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* This following macros are used to get/set table fields. */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"\n"); fprintf(schh_fp,"\n/* BEGIN MODIFICATION, ctwang, 12/20/97 */\n\n"); fprintf(schh_fp,"/*hcg_key key_value; -- for pr_set_key() */\n"); /* Sathya */ fprintf(schh_fp,"/*int PARSE;*/\n\n"); /* Sathya */ fprintf(schh_fp,"#define pr_set_int(tbl,fld,value) \\\n"); fprintf(schh_fp," do{\\\n"); fprintf(schh_fp," if((tbl)->RFLAG==1 && /*!PARSE && */ hcg_log ==1 )\\\n"); /* Sathya */ fprintf(schh_fp," {\\\n"); fprintf(schh_fp," fprintf( hcg_logfileptr, \"PR_SET_INT %%s %%s %%d\\n\",\\\n"); fprintf(schh_fp," decode_retstr( (hcg_key*)(tbl) ),\"fld\", (value) );\\\n"); /* Sathya */ fprintf(schh_fp," }\\\n"); fprintf(schh_fp," (tbl)->fld = (value); \\\n"); fprintf(schh_fp," }while(0)\n\n"); fprintf(schh_fp,"#define pr_set_flt(tbl,fld,value) \\\n"); fprintf(schh_fp," do{\\\n"); fprintf(schh_fp," if((tbl)->RFLAG==1 && /*!PARSE && */ hcg_log ==1 )\\\n"); /* Sathya */ fprintf(schh_fp," {\\\n"); fprintf(schh_fp," fprintf( hcg_logfileptr, \"PR_SET_FLT %%s %%s %%f\\n\",\\\n"); fprintf(schh_fp," decode_retstr( (hcg_key*)(tbl) ),\"fld\", (value) );\\\n"); /* Sathya*/ fprintf(schh_fp," }\\\n"); fprintf(schh_fp," (tbl)->fld = (value); \\\n"); fprintf(schh_fp," }while(0)\n\n"); fprintf(schh_fp,"#define pr_set_key(tbl,fld,value) \\\n"); fprintf(schh_fp," do{\\\n"); fprintf(schh_fp," if((tbl)->RFLAG==1 && /*!PARSE && */ hcg_log ==1 )\\\n"); /* Sathya */ fprintf(schh_fp," {\\\n"); fprintf(schh_fp," hcg_key key_value = ( value ); \\\n"); /* Sathya */ fprintf(schh_fp," fprintf( hcg_logfileptr, \"PR_SET_KEY %%s %%s %%s\\n\",\\\n"); fprintf(schh_fp," decode_retstr( (hcg_key*)(tbl) ),\"fld\", decode_retstr(&key_value) );\\\n");/* Sathya */ fprintf(schh_fp," }\\\n"); fprintf(schh_fp," (tbl)->fld = (value); \\\n"); fprintf(schh_fp," }while(0)\n\n"); fprintf(schh_fp,"#define pr_set_str(tbl,fld,value) \\\n"); fprintf(schh_fp," do{\\\n"); fprintf(schh_fp," if ( strlen(value) >= sizeof((tbl)->fld) ) \\\n"); fprintf(schh_fp," fprintf(stderr, \\\n"); fprintf(schh_fp," \"Warning: field %%s in table at %%s is too long- truncated\\n\", \"fld\", \"decode_retstr( (hcg_key*)(tbl)\");\\\n"); fprintf(schh_fp," if((tbl)->RFLAG==1 && /*!PARSE &&*/ hcg_log ==1 )\\\n"); /*Sathya*/ fprintf(schh_fp," {\\\n"); fprintf(schh_fp," fprintf( hcg_logfileptr, \"PR_SET_STR %%s %%s %%s\\n\",\\\n"); fprintf(schh_fp," decode_retstr( (hcg_key*)(tbl) ),\"fld\", (value) );\\\n"); fprintf(schh_fp," } \\\n"); fprintf(schh_fp," strncpy((tbl)->fld, (value), sizeof((tbl)->fld)-1); \\\n"); fprintf(schh_fp," }while(0)\n\n"); fprintf(schh_fp,"/* END MODIFICATION, ctwang, 12/20/97 */\n\n"); fprintf(schh_fp,"\n"); fprintf(schh_fp,"#define pr_get_int(tbl,fld) (tbl)->fld\n"); fprintf(schh_fp,"#define pr_get_flt(tbl,fld) (tbl)->fld\n"); fprintf(schh_fp,"#define pr_get_str(tbl,fld) (tbl)->fld\n"); fprintf(schh_fp,"#define pr_get_key(tbl,fld) (tbl)->fld\n"); /* 93su523 PGEN merge new macro */ fprintf(schh_fp,"\n"); fprintf(schh_fp,"#define pr_set_default(val) hcg_default_fkey = (val)\n"); fprintf(schh_fp,"#define pr_get_default(val) hcg_default_fkey\n"); fprintf(schh_fp,"\n"); fprintf(schh_fp,"\n"); /* 93su523 PGEN merge (END) */ fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* This following variables are for internal use only. Users should never */\n"); fprintf(schh_fp,"/* modify them, and should never have a need to use them. Again, either */\n"); fprintf(schh_fp,"/* a definition or a declaration will actually be compiled. */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); /* 93su523 PGEN merge - moved the following 2 lines from inside the MAIN to outside */ fprintf(schh_fp, "#define HCG_KEY_SIZE %d\n", (hcg_abbr_size + 2)*2); fprintf(schh_fp, "#define HCG_ABBR_SIZE %d\n", hcg_abbr_size); fprintf(schh_fp, "#ifdef MAIN\n") ; /**** 93s523 ****/ /*** key size (characters) equals (abbreviation size + 2) * 2 ****/ /*** (2+2)*2 ==> 8, (4+2)*2 ==> 12 ***/ fprintf(schh_fp, "\n\thcg_key hcg_k; /* Temp var to hold integer version of character keys */\n"); fprintf(schh_fp, "\tlut_st hcg_table_abbrev_lut;/* Holds lookup table of table abbrev's and indexes */\n"); fprintf(schh_fp, "\tint hcg_initialized = 0; /* Has pr_init been called yet ? */\n"); fprintf(schh_fp, "\tint hcg_default_fkey = 0; /* default pkey assignment flag */\n"); /* 93su523 PGEN merge */ /* 93su523 PGEN merge - removed hcg_within_load which is no longer necessary */ fprintf(schh_fp, "\tint hcg_version = 0; /* Temp var to hold version number of key in question */\n"); fprintf(schh_fp, "\tint hcg_row = 0; /* Temp var to hold row number of key in question */\n"); fprintf(schh_fp, "\tint hcg_tbl_idx = 0; /* Integer mapping of table abbrev, used extensively */\n"); fprintf(schh_fp, "\tint hcg_view_idx = 0; /* Integer mapping of view name, used extensively */\n"); /* Added by Genlog 5/8/96 */ fprintf(schh_fp, "\tint hcg_log; /* Integer indicating log on (1) off (0) replay (2) */\n"); fprintf(schh_fp, "\tchar hcg_buffer[BUFSIZE]; /* File read buffer (holds one line) */\n"); fprintf(schh_fp, "\tchar hcg_t[BUFSIZE]; /* Holds a parsed key value. */\n"); /* 93su523 PGEN merge (NAMELENGTH -> BUFSIZE) */ /* Added by Genlog 5/8/96 */ fprintf(schh_fp, "\tchar hcg_logfile[NAMELENGTH]; /* File name of log file */\n"); /* Added by Genlog 5/8/96 */ fprintf(schh_fp, "\tchar hcg_viewname[NAMELENGTH] = \"\\0\"; /* Last viewname used by pr_add */\n"); fprintf(schh_fp, "\tFILE *hcg_ascii_fp; /* File variable for any data file or viewdef file */\n"); fprintf(schh_fp, "\tFILE *hcg_dump_fp; /* File variable for output data files */\n"); /* Added by Genlog 5/8/96 */ fprintf(schh_fp, "\tFILE *hcg_logfileptr; /* File variable for hcg_logfile */\n"); fprintf(schh_fp, "\tFILE *hcg_stats_fp; /* File variable for output statistics files */\n"); fprintf(schh_fp, "#else\n") ; /*** 93s523 ***/ fprintf(schh_fp, "\n\textern hcg_key hcg_k;\n"); fprintf(schh_fp, "\textern lut_st hcg_table_abbrev_lut;\n"); fprintf(schh_fp, "\textern int hcg_initialized;\n"); fprintf(schh_fp, "\textern int hcg_default_fkey;\n"); /* 93su523 PGEN merge */ /* 93su523 PGEN merge - removed hcg_within_load which is no longer necessary */ fprintf(schh_fp, "\textern int hcg_version;\n"); fprintf(schh_fp, "\textern int hcg_row;\n"); fprintf(schh_fp, "\textern int hcg_tbl_idx;\n"); fprintf(schh_fp, "\textern int hcg_view_idx;\n"); /* Added by Genlog 5/8/96 */ fprintf(schh_fp, "\textern int hcg_log;\n"); fprintf(schh_fp, "\textern char hcg_buffer[BUFSIZE];\n"); fprintf(schh_fp, "\textern char hcg_t[BUFSIZE];\n"); /* 93su523 PGEN merge (NAMELENGTH -> BUFSIZE) */ /* Added by Genlog 5/8/96 */ fprintf(schh_fp, "\textern char hcg_logfile[NAMELENGTH];\n"); /* Added by Genlog 5/8/96 */ fprintf(schh_fp, "\textern char hcg_viewname[NAMELENGTH];\n"); fprintf(schh_fp, "\textern FILE *hcg_ascii_fp;\n"); fprintf(schh_fp, "\textern FILE *hcg_dump_fp;\n"); /* Added by Genlog 5/8/96 */ fprintf(schh_fp, "\textern FILE *hcg_logfileptr;\n"); fprintf(schh_fp, "\textern FILE *hcg_stats_fp;\n"); fprintf(schh_fp, "#endif\n\n") ; fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* This structure variable holds all general information and global statistics*/\n"); fprintf(schh_fp,"/* for each table in the schema. It also populates the structure with the */\n"); fprintf(schh_fp,"/* table abbrevs. */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp, "hcg_extern\n") ; fprintf(schh_fp, "struct hcg_table_seq_list_type {\n"); fprintf(schh_fp, "\tchar ttabbrev[ABBREV_NAME_LENGTH] ;\n"); fprintf(schh_fp, "\tint rcount ;\n"); fprintf(schh_fp, "\tint maxver ;\n"); fprintf(schh_fp, "} hcg_table_seq_list[%d]\n",num_tables); fprintf(schh_fp, "#ifdef MAIN\n") ; fprintf(schh_fp, " =\t{\n"); /* Why the heck isn't this done the same way as below using lut_get_name??? - MM */ tt_curr = tt; while (tt_curr) { fprintf(schh_fp, "\t\t{\"%s\",0,0}",tt_curr->TTabbr); /* Sathya */ tt_curr = tt_curr->next_ptr; if (tt_curr != NULL) fprintf(schh_fp, ",\n"); else fprintf(schh_fp, "\n"); } fprintf(schh_fp, "\t}\n"); fprintf(schh_fp, "#endif\n") ; fprintf(schh_fp, ";\n\n") ; fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* This set of macros defines an integer mapping for each table. This value */\n"); fprintf(schh_fp,"/* is used as an array index in various structures. */\n"); fprintf(schh_fp,"/* The table hcg_table_abbrev_lut contains the index values for each table */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); /*** 93s523 ***/ for(i=0; ifkey%s_fcp\n\n",sep,sep,sep); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* This macro is used to continue a child traversal started by start_child_ */\n"); fprintf(schh_fp,"/* chain (see above). */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"#define next_child(child,fkey) child%scurr = (struct child *) child%scurr->fkey%s_fpp\n\n",sep,sep,sep); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* This macro will determine if any rows exist for the specified table. */\n"); fprintf(schh_fp,"/* This should always be equivalent to (pr_rcount_all(tbl) != 0) if integrity */\n"); fprintf(schh_fp,"/* is maintained. */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"#define exists(tbl) (tbl%scurr)\n\n",sep); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* This macro is used to begin a traversal of the specified entire table. */\n"); fprintf(schh_fp,"/* This includes all versions. */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"#define start_chain_all(tbl) tbl%scurr = tbl\n\n",sep); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* This macro is used to continue a full table traversal, started by start_ */\n"); fprintf(schh_fp,"/* chain_all (see above). */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"#define next_all(tbl) tbl%scurr = tbl%scurr->next_ptr\n\n",sep,sep); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* This macro will determine if the specified child is the first in the child */\n"); fprintf(schh_fp,"/* chain under the specified parent. */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"#define first_child(parent,child,pkey) (parent%scurr->pkey%s_fcp == child%scurr)\n\n",sep,sep,sep); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* This macro will determine if the specified child is the last in the child */\n"); fprintf(schh_fp,"/* chain under the specified parent. */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); /* in the following fprintf I changed the declaration of open_file to be extern and declared */ /* open_file in gen_pr_utils.c to fix a 'multiply defined' problem on OSF. maldred 22-Nov-95 */ fprintf(schh_fp, "#define last_child(parent,child,ckey) ((struct parent *) child%scurr->ckey%s_fpp == parent%scurr)\n\n",sep,sep,sep); /*** 95s523,added by chwang on 5,11,95. --- lines begin --- ***/ /*** The macro is used to add a row into btree. ***/ fprintf(schh_fp,"\ /******************************************************************************/\n\ /* The macro defines pr_dump_row() as dump_row(). */\n\ /******************************************************************************/\n"); if (cli_ansi) { fprintf(schh_fp, "#define pr_dump_row(tbl,viewname,file_name,new_version,modestr) dump_row(#tbl,viewname,file_name,new_version,modestr) \n"); } else { fprintf(schh_fp, "#define pr_dump_row(tbl,viewname,file_name,new_version,modestr) dump_row(\"tbl\",viewname,file_name,new_version,modestr) \n"); } fprintf(schh_fp, "extern int open_file; \n\ /******************************************************************************/\n\ /* This macro is used to add the row into a binary tree. It is for internal */\n\ /* use to build a binary tree. */\n\ /******************************************************************************/\n\ \n\ #define btree_add_row(tbl) \\\n\ tbl%sbtelt = (struct tbl%sbtree *)malloc( sizeof(struct tbl%sbtree) ); \\\n\ tbl%sbtelt->ptr = tbl%selt; \\\n\ tbl%sbtelt->key = tbl%selt->tbl%sid; \\\n\ tbl%sbtelt->parent = NULL; \\\n\ tbl%sbtelt->left = NULL; \\\n\ tbl%sbtelt->right = NULL; \\\n\ btfinish = FALSE; \\\n\ btresult = -1; \\\n\ tbl%sbttemp = tbl%sbtroot; \\\n\ while( tbl%sbttemp != NULL && btfinish == FALSE) \\\n\ { \\\n\ btresult = key_compare(&tbl%sbtelt->key,&tbl%sbttemp->key); \\\n\ if( btresult == 0 ) \\\n\ { \\\n\ printf(\"Error: duplicate pkey in building pr_find btree.\\n\"); \\\n\ exit(3); \\\n\ } \\\n\ else if ( btresult < 0 ) \\\n\ { \\\n\ if( tbl%sbttemp->left == NULL ) \\\n\ btfinish = LEFT ; \\\n\ else \\\n\ tbl%sbttemp = tbl%sbttemp->left; \\\n\ } \\\n\ else \\\n\ { \\\n\ if( tbl%sbttemp->right == NULL ) \\\n\ btfinish = RIGHT ; \\\n\ else \\\n\ tbl%sbttemp = tbl%sbttemp->right; \\\n\ } \\\n\ } \\\n\ if ( btfinish == FALSE ) \\\n\ tbl%sbtroot = tbl%sbtelt; \\\n\ else if( btfinish == LEFT ) \\\n\ { \\\n\ tbl%sbttemp->left = tbl%sbtelt; \\\n\ tbl%sbtelt->parent = tbl%sbttemp; \\\n\ } \\\n\ else \\\n\ { \\\n\ tbl%sbttemp->right = tbl%sbtelt; \\\n\ tbl%sbtelt->parent = tbl%sbttemp; \\\n\ } ",sep,sep,sep,sep,sep,sep,sep,sep,sep,sep,sep,sep,sep,sep,sep,sep,sep,sep,sep,sep ,sep,sep,sep,sep,sep,sep,sep,sep,sep,sep,sep,sep); /*** 95s523,added by chwang on 5,11,95. --- lines end --- ***/ fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* This macro is used to locate the row in the specified table whose primary */\n"); fprintf(schh_fp,"/* key is the one specified. */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); /*** 93s523: changed strcmps to key_compares ***/ fprintf(schh_fp, "#define pr_find(tbl,pkey,value) \\\n"); /*** 95s523,chwang,5,11,95. Added for btree search ---lines begin--- ***/ fprintf(schh_fp, " if( tbl%sbtidx == BTREESEARCH ) \\\n",sep); fprintf(schh_fp, " { \\\n"); fprintf(schh_fp, " sprintf(tempbtree,\"tbl\"); \\\n"); fprintf(schh_fp, " tempbtree[HCG_ABBR_SIZE]=\'\\0\'; \\\n"); fprintf(schh_fp, " pr_find_bt(tempbtree,&value); \\\n"); fprintf(schh_fp, " } \\\n"); fprintf(schh_fp, " else \\\n"); /*** 95s523,chwang,5,11,95. ---lines end--- ***/ if (!cli_noorder) fprintf(schh_fp, " for (tbl%scurr = tbl; (tbl%scurr != NULL) && (key_compare(&tbl%scurr->pkey,&value) < 0); tbl%scurr = tbl%scurr->next_ptr); \\\n",sep,sep,sep,sep,sep,sep); else fprintf(schh_fp, " for (tbl%scurr = tbl; (tbl%scurr != NULL) && (key_compare(&tbl%scurr->pkey,&value) != 0); tbl%scurr = tbl%scurr->next_ptr); \\\n",sep,sep,sep,sep,sep,sep); fprintf(schh_fp, " if ((tbl%scurr != NULL) && (key_compare(&tbl%scurr->pkey,&value) != 0)) \\\n",sep,sep); fprintf(schh_fp, " tbl%scurr = NULL\n\n",sep); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* This looping macro will traverse the entire table (ie, all versions), */\n"); fprintf(schh_fp,"/* stopping at each row whose specified string field equals the specified */\n"); fprintf(schh_fp,"/* string value. */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp, "#define find_str_loop_all(tbl,field,value) \\\n"); fprintf(schh_fp, " for (tbl%scurr = tbl; tbl%scurr != NULL; tbl%scurr = tbl%scurr->next_ptr) \\\n",sep,sep,sep,sep); fprintf(schh_fp, " if (strcmp(tbl%scurr->field,value) == 0)\n\n",sep); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* This looping macro is the same as find_str_loop_all, but uses a view. */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp, "#define find_str_loop(viewname,tbl,field,value) \\\n"); fprintf(schh_fp," if (find_view_idx(viewname)) \\\n"); fprintf(schh_fp," for (tbl%scurr = tbl; tbl%scurr != NULL; tbl%scurr = tbl%scurr->next_ptr)\\\n",sep,sep,sep,sep); fprintf(schh_fp," if ((meets_view(tbl%s_idx,hcg_view_idx,tbl%scurr->tbl%sid)) &&\\\n",sep,sep,sep); fprintf(schh_fp, " (strcmp(tbl%scurr->field,value) == 0))\n\n",sep); /******** 93s523: New macros to loop and find key values ***********/ fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp, "#define find_key_loop_all(tbl,field,value) \\\n"); fprintf(schh_fp, " for (tbl%scurr = tbl; tbl%scurr != NULL; tbl%scurr = tbl%scurr->next_ptr) \\\n",sep,sep,sep,sep); fprintf(schh_fp, " if (key_compare(&tbl%scurr->field, &value) == 0)\n\n",sep); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* This looping macro is the same as find_key_loop_all, but uses a view. */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp, "#define find_key_loop(viewname,tbl,field,value) \\\n"); fprintf(schh_fp," if (find_view_idx(viewname)) \\\n"); fprintf(schh_fp," for (tbl%scurr = tbl; tbl%scurr != NULL; tbl%scurr = tbl%scurr->next_ptr)\\\n",sep,sep,sep,sep); fprintf(schh_fp," if ((meets_view(tbl%s_idx,hcg_view_idx,tbl%scurr->tbl%sid)) &&\\\n",sep,sep,sep); fprintf(schh_fp, " (key_compare(&tbl%scurr->field,&value) == 0))\n\n",sep); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* This looping macro is identical to find_str_loop_all, except that integer */\n"); fprintf(schh_fp,"/* fields and values are used. */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp, "#define find_int_loop_all(tbl,field,value) \\\n"); fprintf(schh_fp, " for (tbl%scurr = tbl; tbl%scurr != NULL; tbl%scurr = tbl%scurr->next_ptr) \\\n",sep,sep,sep,sep); fprintf(schh_fp, " if (tbl%scurr->field == value)\n\n",sep); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* This looping macro is identical to find_int_loop_all, but uses a view. */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp, "#define find_int_loop(viewname,tbl,field,value) \\\n"); fprintf(schh_fp," if (find_view_idx(viewname)) \\\n"); fprintf(schh_fp," for (tbl%scurr = tbl; tbl%scurr != NULL; tbl%scurr = tbl%scurr->next_ptr)\\\n",sep,sep,sep,sep); fprintf(schh_fp," if ((meets_view(tbl%s_idx,hcg_view_idx,tbl%scurr->tbl%sid)) &&\\\n",sep,sep,sep); fprintf(schh_fp, " (tbl%scurr->field == value))\n\n",sep); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* This looping macro will traverse all children of a parent, stopping at */\n"); fprintf(schh_fp,"/* each child row. */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"#define child_loop(parent,child,pkey,ckey) \\\n"); fprintf(schh_fp," for (child%scurr = parent%scurr->pkey%s_fcp; \\\n",sep,sep,sep); fprintf(schh_fp," ((child%scurr != NULL) && ((struct parent *) child%scurr) != (parent%scurr)); \\\n",sep,sep,sep); fprintf(schh_fp," child%scurr = (struct child *) child%scurr->ckey%s_fpp)\n\n",sep,sep,sep); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* This looping macro will traverse the entire specified table (ie, all */\n"); fprintf(schh_fp,"/* versions), stopping at every row. */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"#define table_loop_all(tbl) for (tbl%scurr = tbl; tbl%scurr != NULL; tbl%scurr = tbl%scurr->next_ptr)\n\n",sep,sep,sep,sep); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* This looping macro will traverse the specified table, stopping at every */\n"); fprintf(schh_fp,"/* row that that meets the view (based on version number). */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"#define table_loop(viewname,tbl) \\\n"); fprintf(schh_fp,"if (find_view_idx(viewname)) \\\n"); fprintf(schh_fp," for (tbl%scurr = tbl; tbl%scurr != NULL; tbl%scurr = tbl%scurr->next_ptr)\\\n",sep,sep,sep,sep); fprintf(schh_fp," if (meets_view(tbl%s_idx,hcg_view_idx,tbl%scurr->tbl%sid))\n\n",sep,sep,sep); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* This macro is identical to pr_find, except that the user can specify */\n"); fprintf(schh_fp,"/* his/her own looping variable. */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); /*** 93s523: changed strcmps to key_compares ***/ fprintf(schh_fp, "#define pr_var_find(tbl,tblvar,pkey,value) \\\n"); if (!cli_noorder) fprintf(schh_fp, " for (tblvar = tbl; (tblvar != NULL) && (key_compare(&tblvar->pkey,&value) < 0); tblvar = tblvar->next_ptr); \\\n"); else fprintf(schh_fp, " for (tblvar = tbl; (tblvar != NULL) && (key_compare(&tblvar->pkey,&value) != 0); tblvar = tblvar->next_ptr); \\\n"); fprintf(schh_fp, " if ((tblvar != NULL) && (key_compare(&tblvar->pkey,&value) != 0)) \\\n"); fprintf(schh_fp, " tblvar = NULL\n\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* This macro is identical to find_str_loop_all, except that the user can */\n"); fprintf(schh_fp,"/* specify his/her own looping variable. */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp, "#define var_find_str_loop_all(tbl,tblvar,field,value) \\\n"); fprintf(schh_fp," for (tblvar = tbl; tblvar != NULL; tblvar = tblvar->next_ptr)\\\n"); fprintf(schh_fp," if (strcmp(tblvar->field,value) == 0)\n\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* This macro is identical to find_str_loop, except that the user can specify */\n"); fprintf(schh_fp,"/* his/her own looping variable. */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp, "#define var_find_str_loop(viewname,tbl,tblvar,field,value) \\\n"); fprintf(schh_fp," if (find_view_idx(viewname)) \\\n"); fprintf(schh_fp," for (tblvar = tbl; tblvar != NULL; tblvar = tblvar->next_ptr)\\\n"); fprintf(schh_fp," if ((meets_view(tbl%s_idx,hcg_view_idx,tblvar->tbl%sid)) &&\\\n",sep,sep); fprintf(schh_fp, " (strcmp(tblvar->field,value) == 0))\n\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* This macro is identical to find_int_loop_all, except that the user can */\n"); fprintf(schh_fp,"/* specify his/her own looping variable. */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp, "#define var_find_int_loop_all(tbl,tblvar,field,value) \\\n"); fprintf(schh_fp, " for (tblvar = tbl; tblvar != NULL; tblvar = tblvar->next_ptr) \\\n"); fprintf(schh_fp, " if (tblvar->field == value)\n\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* This macro is identical to var_find_int_loop_all, but uses a view. */\n"); fprintf(schh_fp,"/* specify his/her own looping variable. */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp, "#define var_find_int_loop(viewname,tbl,tblvar,field,value) \\\n"); fprintf(schh_fp," if (find_view_idx(viewname)) \\\n"); fprintf(schh_fp," for (tblvar = tbl; tblvar != NULL; tblvar = tblvar->next_ptr)\\\n"); fprintf(schh_fp," if ((meets_view(tbl%s_idx,hcg_view_idx,tblvar->tbl%sid)) &&\\\n",sep,sep); fprintf(schh_fp, " (tblvar->field == value))\n\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* This macro is identical to child_loop, except that the user can specify */\n"); fprintf(schh_fp,"/* his/her own looping variable. */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"#define var_child_loop(tbl,parent,pkey,tbl2,child,ckey) \\\n"); fprintf(schh_fp,"for (child = parent->pkey%s_fcp; \\\n",sep); fprintf(schh_fp," ((child != NULL) && ((struct tbl *) child) != (parent)); \\\n"); fprintf(schh_fp," child = (struct tbl2 *) child->ckey%s_fpp)\n\n",sep); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* This macro is identical to table_loop_all, except that the user can specify*/\n"); fprintf(schh_fp,"/* his/her own looping variable. */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"#define var_table_loop_all(tbl,tblvar) for (tblvar = tbl; tblvar != NULL; tblvar = tblvar->next_ptr)\n\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* This macro is identical to table_loop, except that the user can specify */\n"); fprintf(schh_fp,"/* his/her own looping variable. */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"#define var_table_loop(viewname,tbl,tblvar) \\\n"); fprintf(schh_fp,"if (find_view_idx(viewname)) \\\n"); fprintf(schh_fp," for (tblvar = tbl; tblvar != NULL; tblvar = tblvar->next_ptr)\\\n"); fprintf(schh_fp," if (meets_view(tbl%s_idx,hcg_view_idx,tblvar->tbl%sid))\n\n",sep,sep); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* This macro is identical to first_child, except that the user can specify */\n"); fprintf(schh_fp,"/* his/her own parent and child pointer variables. */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"#define var_first_child(tbl,parent,child,pkey) (parent->pkey%s_fcp == child)\n\n",sep); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* This macro is identical to last_child, except that the user can specify */\n"); fprintf(schh_fp,"/* his/her own parent and child pointer variables. */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"#define var_last_child(tbl,parent,child,ckey) ((struct tbl *) child->ckey%s_fpp == parent)\n\n\n",sep); /* Replaced != by == RJL97/3/4 */ fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* Macro for checking error in file writes */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"#define PrintCheck(x) if((x) == -1) { printf(\"Error in outputing file. Exiting\\n\"); exit(1);}\n"); /* 93su523 PGEN merge (== -1 added) */ if (cli_ansi) { fprintf(schh_fp,"\n\ /* C function prototypes for the C++ compiler */ \n#define pr_add(a,b,c) do_pr_add(a,#b,c) \n#ifdef __cplusplus\n\ extern \"C\" {\n\ extern int find_tbl_idx(char *);\n\ extern int find_view_idx(char *);\n\ extern int encode( char *, hcg_key * );\n\ extern void pr_find_bt(char *, hcg_key *);\n\ extern char *decode_retstr(hcg_key *);\n\ extern int decode(char *, hcg_key *);\n\ extern int key_compare(hcg_key *, hcg_key *);\n\ extern char *get_abbr(hcg_key *, char *);\n\ extern int get_version(hcg_key *);\n\ extern int get_row(hcg_key *);\n\ extern int set_abbr(hcg_key *, char *);\n\ extern int set_version(hcg_key *, int);\n\ extern int set_row(hcg_key *, int);\n\ extern hcg_key *null_key(void);\n\ extern int is_null_key(hcg_key *);\n\ extern void pr_init (char *, char *);\n\ extern hcg_ptr pr_gen_create(int);\n\ extern void do_pr_add(char *, char *, hcg_ptr);\n\ extern void pr_load(char *, char *);\n\ extern void pr_del(int);\n\ extern void pr_free(void);\n\ extern void pr_stats(char *, char *);\n\ extern void pr_dump(char *, char *, int, char *);\n\ }\n\ #endif\n\ \n\ "); } return; }