/* @(#)gen_pr_load.c 05/11/95 */ /******************************************************************************/ /* function : gen_pr_load.c */ /* */ /* 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.) */ /* */ /* */ /* description : This routine writes out the code for the pr_load routine */ /* to the pr_load.c output file. For a description of output */ /* code, see the output comments below. */ /* */ /******************************************************************************/ /******************************************************************************/ /* 95s523 (V10), chwang modifies the file to generate the pr_find_bt() */ /* routine and routines which can clear the btree. 5,11,95 */ /******************************************************************************/ /******************************************************************************/ /* Modified by Genlog 5/8/96 to include logging if cli_log == TRUE */ /******************************************************************************/ #include #include #include "chgen_define.h" #include "chgen_externs.h" #include "prototypes.h" void gen_pr_find_bt(); /* forward declaration - genMerge 99s523 */ void gen_pr_clear_bt(); /* forward declaration - genMerge 99s523 */ void gen_pr_load() /* generating function pr_load() */ { static char rcsid[] = ""; fprintf(prload_fp, "/******************************************************************************/\n"); fprintf(prload_fp, "/* This routine is used to load the contents of the virtual database from the */\n"); fprintf(prload_fp, "/* specified file, using the specified view. All rows from the file that */\n"); fprintf(prload_fp, "/* meet the criteria of the view will be loaded. This routine itself really */\n"); fprintf(prload_fp, "/* just verifys the view name, opens the file, and then calls load_data. */\n"); fprintf(prload_fp, "/* It also closes the file. */\n"); fprintf(prload_fp, "/******************************************************************************/\n"); fprintf(prload_fp, "void pr_load ( char *viewname, char *file_name)\n"); fprintf(prload_fp, "{\n"); fprintf(prload_fp,"static char rcsid[] = \"\";\n"); if (cli_log == TRUE) { fprintf(prload_fp, "/* Added by Genlog 5/8/96 to log pr_load */\n"); fprintf(prload_fp, "char log_text[BUFSIZE];\n"); fprintf(prload_fp, "int doReplay;\n"); fprintf(prload_fp, " if ( hcg_log == 1 ) {\n"); fprintf(prload_fp, " logwait();\n"); fprintf(prload_fp, " sprintf(log_text,\"LD %%s %%s\\n\", viewname, file_name);\n"); fprintf(prload_fp, " logstr(log_text);\n"); fprintf(prload_fp, "/* End Genlog Addition */\n"); fprintf(prload_fp, " }\n"); } fprintf(prload_fp, " if (!hcg_initialized)\n"); fprintf(prload_fp, " {\n"); fprintf(prload_fp, " printf(\"Error: pr_load() called when database is not yet initialized.\\n\");\n"); fprintf(prload_fp, " exit(1);\n"); fprintf(prload_fp, " }\n\n"); fprintf(prload_fp,"\t if (!find_view_idx(viewname))\n"); fprintf(prload_fp,"\t {\n"); fprintf(prload_fp,"\t printf(\"Error: view %%s passed to pr_load is not defined.\\n\",viewname);\n"); fprintf(prload_fp,"\t exit(2);\n"); fprintf(prload_fp,"\t }\n"); fprintf(prload_fp, " if ((hcg_ascii_fp=fopen(file_name,\"r\")) == NULL)\n"); fprintf(prload_fp, " {\n"); fprintf(prload_fp, " printf(\"can not open %%s\\n\", file_name);\n"); fprintf(prload_fp, " exit(2);\n"); fprintf(prload_fp, " }\n"); fprintf(prload_fp, " doReplay = load_data (viewname);\n"); fprintf(prload_fp, " fclose(hcg_ascii_fp);\n"); fprintf(prload_fp, " if( doReplay ) { \n"); fprintf(prload_fp, " replayStatus = pr_replay(viewname, file_name, 1, 1); \n"); fprintf(prload_fp, " } \n"); fprintf(prload_fp, "}\n\n"); /*** 95s523,chwang,5,11,95. Add two routines to find and to clear the btree. ***/ /*** ---lines begin --- ***/ gen_pr_find_bt(); gen_pr_clear_bt(); /*** ---lines end --- ***/ return; } /******************************************************************************/ /* function : gen_pr_find_bt() */ /* input : */ /* output : (writes to pr_load.c output file) */ /* returns : void */ /* author : Chien-Yuan Wang */ /* created : 5,11,1995 */ /* description : This routine writes out the code of pr_find_bt() routine */ /* to the pr_load.c output file. */ /******************************************************************************/ void gen_pr_find_bt() { fprintf(prload_fp, "/******************************************************************************/\n"); fprintf(prload_fp, "/* Description: This routine is used to find the pkey location by using btree.*/\n"); fprintf(prload_fp, "/* Input: the special table name and its pkey value. */\n"); fprintf(prload_fp, "/* *temp1 is the table name. *temp2 is the pkey value. */\n"); fprintf(prload_fp, "/* Output: none.( it will move table position to the specific row. */\n"); fprintf(prload_fp, "/******************************************************************************/\n"); fprintf(prload_fp, "void pr_find_bt(char *temp1,hcg_key *temp2)\n"); fprintf(prload_fp, "{\n"); fprintf(prload_fp, " int tbl_encoding;\n"); tt_curr = tt; while ( tt_curr != NULL) { if( tt_curr->comment[0] != '\0' ) if( tt_curr->comment[2] == '1' ) fprintf(prload_fp, " struct %sbtree *%stmpbt; \n",tt_curr->TTabbr,tt_curr->TTabbr); tt_curr = tt_curr->next_ptr; } /* while tt */ fprintf(prload_fp, "\n\ if (!find_tbl_idx(temp1)) \n\ { \n\ printf(\"Error: unknown table (%%s) passed to pr_find.\\n\",temp1); \n\ exit(3);\n\ } \n\n\ tbl_encoding = encoding( hcg_table_seq_list[hcg_tbl_idx].ttabbrev ); \n\ switch( tbl_encoding ) \n\ { \n "); tt_curr = tt; while ( tt_curr != NULL) { if( tt_curr->comment[0] != '\0' ) if( tt_curr->comment[2] == '1' ) { fprintf(prload_fp,"\tcase %d :\t/* encoding of %s */\n", encoding(tt_curr->TTabbr), tt_curr->TTabbr); fprintf(prload_fp," %stmpbt = %sbtroot;\n",tt_curr->TTabbr,tt_curr->TTabbr); fprintf(prload_fp," while( %stmpbt != NULL && finish == FALSE)\n",tt_curr->TTabbr); fprintf(prload_fp," {\n"); fprintf(prload_fp," result = key_compare(temp2,&%stmpbt->key);\n",tt_curr->TTabbr); fprintf(prload_fp," if( result == 0 )\n"); fprintf(prload_fp," finish = TRUE ;\n"); fprintf(prload_fp," else if ( result > 0 )\n"); fprintf(prload_fp," %stmpbt = %stmpbt->right;\n",tt_curr->TTabbr,tt_curr->TTabbr); fprintf(prload_fp," else \n"); fprintf(prload_fp," %stmpbt = %stmpbt->left; \n",tt_curr->TTabbr,tt_curr->TTabbr); fprintf(prload_fp," } \n"); fprintf(prload_fp," if( %stmpbt == NULL ) \n",tt_curr->TTabbr); fprintf(prload_fp," %scurr = NULL; \n",tt_curr->TTabbr); fprintf(prload_fp," else \n"); fprintf(prload_fp," %scurr = %stmpbt->ptr; \n",tt_curr->TTabbr,tt_curr->TTabbr); fprintf(prload_fp," %sbtcurr=%stmpbt; \n",tt_curr->TTabbr,tt_curr->TTabbr); fprintf(prload_fp," break; \n\n"); } tt_curr = tt_curr->next_ptr; } /* while tt */ fprintf(prload_fp," default: printf(\"\\n\\t pr_find_bt called, but NOT implemented!\\n\");\n\n"); fprintf(prload_fp, " }\n"); fprintf(prload_fp, "}\n\n"); } /******************************************************************************/ /* function : gen_pr_clear_bt() */ /* input : */ /* output : (writes to pr_load.c output file) */ /* returns : void */ /* author : Chien-Yuan Wang */ /* created : 5,11,1995 */ /* description : This routine writes out the code of clear_TBL_bt() routine */ /* to the pr_load.c output file. */ /* ps: TBL mean the tables name which search the pkey by btree. /******************************************************************************/ void gen_pr_clear_bt() { tt_curr = tt; while ( tt_curr != NULL) { if( tt_curr->comment[0] != '\0' ) if( tt_curr->comment[2] == '1' ) { fprintf(prload_fp, "/******************************************************************************/\n"); fprintf(prload_fp, "/* Description: This routine is used to clear btree built for %s table. .*/\n",tt_curr->TTabbr); fprintf(prload_fp, "/* Input: the btree root of table %s. */\n",tt_curr->TTabbr); fprintf(prload_fp, "/* Output: none.( it will free table %s 's btree. */\n",tt_curr->TTabbr); fprintf(prload_fp, "/******************************************************************************/\n"); fprintf(prload_fp, "\ clear_%s_bt(temproot) \n\ struct %sbtree *temproot; \n\ { \n\ if( temproot->left != NULL ) \n\ clear_%s_bt( temproot->left) ; \n\ if( temproot->right != NULL ) \n\ clear_%s_bt( temproot->right) ; \n\ if( temproot != NULL ) \n\ { \n\ free( temproot ); \n\ temproot=NULL; \n\ } \n\ } \n\n",tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr); } tt_curr = tt_curr->next_ptr; } }