/* @(#)gen_macros.c 2.1 93/05/19 */ /******************************************************************************/ /* function : gen_macros.c */ /* */ /* subsystem : chgen */ /* */ /* input : */ /* */ /* output : (writes to schema .h output file) */ /* */ /* returns : void */ /* */ /* author : Cheng */ /* */ /* created : July, 1989 */ /* */ /* revisions : 93s523: modified code to work with table abbrev's of size */ /* hcg_abbr_size. */ /* */ /* description : This routine traverses the contents of the PINDEX and */ /* PATHTABLE structures, outputing access macro definitions */ /* to the output schema .h file. */ /* */ /******************************************************************************/ #include #include #include "chgen_define.h" #include "chgen_externs.h" void gen_macros() { static char rcsid[] = ""; char child_abbrev[ABBREV_NAME_LENGTH], parent_abbrev[ABBREV_NAME_LENGTH]; char temp_string[ABBREV_NAME_LENGTH]; struct rr_type *curr_ptr ; int i, j, m, n ; fprintf(schh_fp,"/******************************************************************************/\n"); fprintf(schh_fp,"/* The following macros are called access macros. Each macro represents */\n"); fprintf(schh_fp,"/* a path upwards through the schema from the first listed table (the child) */\n"); fprintf(schh_fp,"/* to the second listed table (the parent). Actually, the parent could be */\n"); fprintf(schh_fp,"/* an ancestor (grandparent, etc...). The macro itself is designed to be */\n"); fprintf(schh_fp,"/* used in code where the user would normally type in a potentially long */\n"); fprintf(schh_fp,"/* structure access statement, up along xxid_pp pointers. The macros not only*/\n"); fprintf(schh_fp,"/* minimize typing and chances of error, they also give the user a very small */\n"); fprintf(schh_fp,"/* degree of data independence. For example, if a new table is developed and */\n"); fprintf(schh_fp,"/* is placed between two tables in the original schema, the macros will */\n"); fprintf(schh_fp,"/* reflect the change, and the user does not have to change any code. */\n"); fprintf(schh_fp,"/* One major restriction is that a macro will only be generated if the path */\n"); fprintf(schh_fp,"/* is unique. However, access macros can be compounded together, letting */\n"); fprintf(schh_fp,"/* the user specify what to do to get around a point of ambiguity in the */\n"); fprintf(schh_fp,"/* parent chain. */\n"); fprintf(schh_fp,"/******************************************************************************/\n"); for ( i = 0 ; i < MAXTABLES ; i++ ) for ( j = 0 ; j < MAXTABLES ; j++ ) { if (PINDEX[i][j].PathIsUnique == 1) { strncpy_null(child_abbrev,PATHTABLE[PINDEX[i][j].UniqPathindex].PathName,hcg_abbr_size); strncpy_null(parent_abbrev,(char *)&(PATHTABLE[PINDEX[i][j].UniqPathindex].PathName[hcg_abbr_size+2]),hcg_abbr_size); fprintf ( schh_fp, "#define " ); fprintf ( schh_fp, "%s__%s ",child_abbrev,parent_abbrev); if (PINDEX[i][j].PathIsUnique > 1) fprintf ( schh_fp, "/* path is not unique */" ) ; m = hcg_abbr_size ; while ( m < hcg_abbr_size*PATHTABLE[PINDEX[i][j].UniqPathindex].PathLength) { strncpy_null(temp_string, (char *)&PATHTABLE[PINDEX[i][j].UniqPathindex].PathBody[m], hcg_abbr_size); fprintf ( schh_fp, "%sid_pp->", temp_string); m += hcg_abbr_size ; } strncpy_null(temp_string, (char *)&PATHTABLE[PINDEX[i][j].UniqPathindex].PathBody[m], hcg_abbr_size); fprintf ( schh_fp, "%sid_pp", temp_string); fprintf ( schh_fp, "\n" ) ; curr_ptr = cp_table; while (curr_ptr) /* Looking for alternative paths. */ { if((strncmp(child_abbrev, curr_ptr->firstid, hcg_abbr_size)==0)&& (strncmp(parent_abbrev, curr_ptr->secondid, hcg_abbr_size)==0)&& (strlen(curr_ptr->secondid)>hcg_abbr_size+2)) { fprintf ( schh_fp, "#define " ); strncpy_null(temp_string,curr_ptr->secondid, hcg_abbr_size); fprintf ( schh_fp, "%s__%s ", child_abbrev, temp_string); if (PINDEX[i][j].PathIsUnique > 1) fprintf ( schh_fp, "/* path is not unique */" ) ; m = hcg_abbr_size ; while ( m < hcg_abbr_size*PATHTABLE[PINDEX[i][j].UniqPathindex].PathLength) { strncpy_null(temp_string, (char *)&PATHTABLE[PINDEX[i][j].UniqPathindex].PathBody[m], hcg_abbr_size); fprintf ( schh_fp, "%sid_pp->", temp_string); m += hcg_abbr_size; } fprintf ( schh_fp, "%s_pp",curr_ptr->secondid ) ; fprintf ( schh_fp, "\n" ) ; } curr_ptr = curr_ptr->next_ptr ; } } } fprintf ( schh_fp, "\n\n\n"); return; }