/* @(#)gen_load_data.c 2.1 93/05/19 */ /******************************************************************************/ /* function : gen_load_data */ /* */ /* subsystem : chgen */ /* */ /* input : */ /* */ /* output : (writes to pr_load.c output file) */ /* */ /* returns : void */ /* */ /* author : Steve Smith / Craig Smith */ /* */ /* created : July, 1991 */ /* */ /* revisions : 99/4/24 99s523 gen merge - Added rcs lines - JK/KS */ /* 00/11/30 kmiu NT port: included prototypes.h */ /* 00/11/30 kmiu Removed unreferenced variables */ /* 2kf522 mottesen & kmiu STL modifications: Moved pr_parse */ /* and pr_link into load_data. pr_parse and */ /* pr_link obsolete */ /* */ /* description : This routine writes out the code for the load_data routine */ /* to the pr_load.c output file. For a description of output */ /* code, see the output comments below. */ /* */ /******************************************************************************/ #include #include #include "chgen_define.h" #include "chgen_externs.h" #include "prototypes.h" void gen_pr_parse(); /* generating function pr_parse() */ /* 93su523 PGEN merge */ void gen_load_data() /* generating function load_data() */ { static char rcsid[] = "$Id: gen_load_data.c,v 1.2.4.1 1999/05/04 16:59:44 jkarner Exp $"; fprintf(prload_fp,"\ /******************************************************************************/\n\ /* This routine is used to read the (already open datafile) and call pr_add */\n\ /* with each row, to add it to the database. Validations for valid table-id, */\n\ /* table is within view, and the version number is the right one for this */\n\ /* table in this view. if all this passes, pr_add is called. A special flag */\n\ /* is set telling pr_add not to perform these same validations. */\n\ /******************************************************************************/\n\ void load_data(char *viewname)\n\ {\n\ static char rcsid[] = \"$Id\";\n\ int idx, ver_chars;\n\ char temp_verstring[ABBREV_NAME_LENGTH];\n\ int tbl_encoding; /* 93su523 PGEN merge */ \n\ hcg_tbl_idx = 0;\n\ hcg_read_next();\n\ while ( !feof(hcg_ascii_fp) )\n\ {\n\ \n\ idx = 0;\n\ hcg_parse(hcg_buffer,hcg_t,&idx);\n\ \n\ if (!find_tbl_idx(hcg_t))\n\ {\n\ strncpy_null(temp_verstring, hcg_t, HCG_ABBR_SIZE);\n\ printf(\"Warning: unknown table (%%s) found in datafile, ignored.\\n\",temp_verstring);\n\ hcg_read_next();\n\ continue;\n\ }\n\ \n\ "); #ifndef NEW_VERSION fprintf(prload_fp,"\ if (hcg_view_list.view_list[hcg_view_idx].version_list[hcg_tbl_idx] == '\\0')\n\ {\n\ hcg_read_next();\n\ continue;\n\ }\n\ \n\ "); #endif fprintf(prload_fp,"\ if(strlen(hcg_t) != HCG_KEY_SIZE)\n\ {\n\ printf(\"Warning: invalid keysize %%d for key %%s, must be %%d, ignored.\\n\", strlen(hcg_t), hcg_t, HCG_KEY_SIZE);\n\ hcg_read_next();\n\ continue;\n\ }\n\ \n\ if(HCG_KEY_SIZE == 8)\n\ ver_chars = 2;\n\ else ver_chars = 3;\n\ strncpy_null(temp_verstring, &hcg_t[HCG_ABBR_SIZE], ver_chars);\n\ \n\ if(encode(hcg_t, &hcg_k) != 1)\n\ {\n\ printf(\"Warning: invalid key %%s, ignored.\\n\", hcg_t);\n\ hcg_read_next();\n\ continue;\n\ }\n\ \n\ hcg_row = get_row(&hcg_k);\n\ hcg_version = get_version(&hcg_k);\n\ \n\ \n\ if (((char) hcg_version) != hcg_view_list.view_list[hcg_view_idx].version_list[hcg_tbl_idx])\n\ {\n\ hcg_read_next();\n\ continue;\n\ }\n\ \n\ hcg_table_seq_list[hcg_tbl_idx].rcount++;\n\ hcg_ts_list[hcg_tbl_idx].ts_list[hcg_version].rcount++;\n\ if (hcg_row > hcg_ts_list[hcg_tbl_idx].ts_list[hcg_version].maxrow)\n\ hcg_ts_list[hcg_tbl_idx].ts_list[hcg_version].maxrow = hcg_row;\n\ \n\ #ifndef USE_STL\n\ /* 93su523 PGEN merge (BEGIN) */\n\ tbl_encoding = encoding( hcg_table_seq_list[hcg_tbl_idx].ttabbrev );\n\ pr_parse(viewname, hcg_buffer, tbl_encoding, idx, hcg_k);\n\ pr_link( tbl_encoding );\n\ /* 93su523 PGEN merge (END) */\n\ #else\n\ tbl_encoding = encoding( hcg_table_seq_list[hcg_tbl_idx].ttabbrev );\n\ \n\ "); fprintf(prload_fp,"\n\ /* This code is from pr_parse, and it calls XXrow's constructor */\n\ switch( tbl_encoding )\n\ {\n\ "); /* * generating cases' branches */ tt_curr = tt; while (tt_curr != NULL) { fprintf(prload_fp," case %d :\t/* encoding of %s */\n",encoding(tt_curr->TTabbr), tt_curr->TTabbr); fprintf(prload_fp," %s *%snewRow;\n",tt_curr->TTabbr,tt_curr->TTabbr); fprintf(prload_fp," %snewRow = new %s;\n",tt_curr->TTabbr,tt_curr->TTabbr); fprintf(prload_fp," %snewRow->parse_row(hcg_buffer, idx, hcg_k);\n", tt_curr->TTabbr); fprintf(prload_fp," %snewRow->link_row();\n",tt_curr->TTabbr); fprintf(prload_fp," break;\n\n" ); tt_curr = tt_curr->next_ptr; } /* while tt */ fprintf(prload_fp," }\n" ); fprintf(prload_fp,"#endif /* USE_STL */\n"); fprintf(prload_fp,"\ \n\ hcg_read_next();\n\ }\n\ }\n\ \n\ \n\ "); gen_pr_parse(); /* 93su523 PGEN merge */ return; } /* 93su523 PGEN merge (BEGIN) */ void gen_pr_parse() /* generating function pr_parse() */ { fprintf(prload_fp,"\ \n\ /******************************************************************************/\n\ /* This routine is used to parse a single row to a virtual database table. */\n\ /* Validations for valid table-id, table is within view, and the version */\n\ /* number is the right one for this table in this view. if all this passes, */\n\ /* the row is added to the database, and linked in to its parents, etc... */\n\ /******************************************************************************/\n\ #ifndef USE_STL\n\ void pr_parse (char *viewname, char *buffer, int tbl_encoding, int idx, hcg_key hcg_k)\n\ {\n\ \n\ #ifdef DEBUG\n\ printf(\"Row to be added = %%s\\n\", buffer);\n\ #endif\n\ \n\ switch( tbl_encoding )\n\ {\n\ "); /* * generating cases' branches */ tt_curr = tt; while ( tt_curr != NULL) { fprintf(prload_fp,"\t\tcase %d :\t/* encoding of %s */\n",encoding(tt_curr->TTabbr), tt_curr->TTabbr); fprintf(prload_fp,"\t\t\t%selt = %selt->create_row();\n", tt_curr->TTabbr, tt_curr->TTabbr ); fprintf(prload_fp,"\t\t\t%selt->parse_row(buffer, idx, hcg_k);\n", tt_curr->TTabbr, tt_curr->TTabbr ); fprintf(prload_fp,"\t\t\tbreak;\n\n" ); tt_curr = tt_curr->next_ptr; } /* while tt */ fprintf(prload_fp,"\t}\n\n" ); fprintf(prload_fp,"}\n"); fprintf(prload_fp,"#endif /* USE_STL */\n\n"); } /* 93su523 PGEN merge (END) */