/* @(#)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 : Sathyanarayan Jaganathan / Steve Smith / Craig Smith */ /* */ /* created : July, 1991 */ /* */ /* revisions : Nov 2001: modified to fix warnings for BDE -sjaganat */ /* (code change for 15 lines approx.) */ /* */ /* : 99/4/24 99s523 gen merge - Added rcs lines - JK/KS */ /* */ /* 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" void gen_pr_parse(); /* generating function pr_parse() */ /* 93su523 PGEN merge */ void gen_load_data() /* generating function load_data() */ { static char rcsid[] = ""; 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(viewname)\n\ 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\ void pr_parse(); /* 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\", (int)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\ /* 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\ \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() */ { int foundnum, i; char parent_pkey[NAMELENGTH]; char unpad; 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\ 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 = pr_create(%s);\n", tt_curr->TTabbr, tt_curr->TTabbr ); ta_curr = tt_curr->ta_ptr; while ( ta_curr != NULL) { /* 93su523 PGEN merge (BEGIN) - taken from gen7 */ if(ta_curr->IsKey) { if(ta_curr == tt_curr->ta_ptr) /* pkey, already encoded*/ fprintf(prload_fp,"\t\t\t%selt->%s = hcg_k;\n", tt_curr->TTabbr, ta_curr->FieldName); else { fprintf(prload_fp,"\t\t\thcg_parse(buffer, hcg_t, &idx);\n"); fprintf(prload_fp,"\t\t\tencode(hcg_t, &hcg_k);\n"); fprintf(prload_fp,"\t\t\t%selt->%s = hcg_k;\n", tt_curr->TTabbr, ta_curr->FieldName); } } /* 93su523 PGEN merge (END) */ else switch ( ta_curr->FieldType[0] ) { case 'i': fprintf(prload_fp,"\t\t\thcg_parse(buffer,hcg_t,&idx);\n"); fprintf(prload_fp,"\t\t\tpr_set_int(%selt,%s,atoi(hcg_t));\n",tt_curr->TTabbr,ta_curr->FieldName); break; case 'f': fprintf(prload_fp,"\t\t\thcg_parse(buffer,hcg_t,&idx);\n"); if ( ta_curr->FieldType[1] == '4' ) fprintf(prload_fp,"\t\t\tpr_set_flt(%selt,%s, (float) atof(hcg_t));\n", tt_curr->TTabbr, ta_curr->FieldName); else fprintf(prload_fp,"\t\t\tpr_set_flt(%selt,%s, atof(hcg_t));\n", tt_curr->TTabbr, ta_curr->FieldName); break; case 'd': if (ta_curr->next_ptr != NULL) /* not first and not last field, so parse and mystrcpy */ { fprintf(prload_fp,"\t\t\thcg_parse(buffer,hcg_t,&idx);\n"); fprintf(prload_fp,"\t\t\tmystrcpy(%selt->%s,hcg_t,26,1);\n",tt_curr->TTabbr,ta_curr->FieldName); } else /* last field of table is a date, so dont parse so it can have spaces within */ fprintf(prload_fp,"\t\t\tmystrcpy(%selt->%s,buffer+idx,26,1);\n",tt_curr->TTabbr,ta_curr->FieldName); break; default: if (ta_curr->FieldType[0] == 't') unpad = '1'; else unpad = '0'; if (ta_curr == tt_curr->ta_ptr) /* first field is pkey, and its already been parsed */ fprintf(prload_fp,"\t\t\tmystrcpy(%selt->%s,hcg_t,%d,%c);\n",tt_curr->TTabbr,ta_curr->FieldName, atoi(&(ta_curr->FieldType[1])),unpad); else if (ta_curr->next_ptr != NULL) /* not first and not last field, so parse and mystrcpy */ { fprintf(prload_fp,"\t\t\thcg_parse(buffer,hcg_t,&idx);\n"); fprintf(prload_fp,"\t\t\tmystrcpy(%selt->%s,hcg_t,%d,%c);\n", tt_curr->TTabbr,ta_curr->FieldName, atoi(&(ta_curr->FieldType[1])),unpad); } else /* last field of table is a string, so dont parse so it can have spaces within */ fprintf(prload_fp,"\t\t\tmystrcpy(%selt->%s,buffer+idx,%d,%c);\n",tt_curr->TTabbr,ta_curr->FieldName, atoi(&(ta_curr->FieldType[1])),unpad); } ta_curr = ta_curr->next_ptr; } 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\n"); } /* 93su523 PGEN merge (END) */