/* @(#)gen_pr_delete.c 2.1 5/16/95 */ /******************************************************************************/ /* function : gen_pr_delete.c */ /* */ /* subsystem : chgen */ /* */ /* input : */ /* */ /* output : (writes to pr_delete.c output file) */ /* */ /* returns : void */ /* */ /* author : Sathyanarayan Jaganathan */ /* */ /* created : July, 1991 */ /* */ /* revisions : Nov 2001: modified to fix warnings for BDE - sjaganat */ /* (code change for 15 lines approx.) */ /* */ /* 93s523: Changed strncpys to use vbl hcg_abbr_size, added */ /* code to decode keys for use by error messages. */ /* 96s523: Added void * to generated unlink_child_bp_m */ /* macro to avoid type conflicts */ /* 96s523: Added code to create logging code GENLOG-DN */ /* 99s523: Placed rcsId lines in */ /* */ /* description : This routine writes out the code for the pr_delete routine */ /* to the pr_delete.c output file. For a description of output */ /* code, see the output comments below. */ /* */ /******************************************************************************/ /******************************************************************************/ /* 95s523 (V10), chwang modifies the file to generate the pr_del_bt() */ /* routine and pr_find_btr() routine. It also modifies pr_del(). 5,11,95 */ /******************************************************************************/ #include #include #include "chgen_define.h" #include "chgen_externs.h" void gen_pr_delete() /* generating function pr_del() */ { static char rcsid[] = ""; int foundnum, i ; char parent_pkey[NAMELENGTH]; fprintf(prdel_fp,"/******************************************************************************/\n"); fprintf(prdel_fp,"/* File : pr_delete.c */\n"); fprintf(prdel_fp,"/* Schema : %-58s */\n",sch_text_file_name); fprintf(prdel_fp,"/* Chgen Version : %-58s */\n",CHGEN_VERSION); fprintf(prdel_fp,"/******************************************************************************/\n\n"); fprintf(prdel_fp,"#include \n") ; fprintf(prdel_fp,"#include \n") ;/* Sathya */ fprintf(prdel_fp,"#include \"%s\"\n\n",sch_header_file_name) ; fprintf(prdel_fp,"void pr_del_bt(char*, hcg_key*); \n");/* Sathya */ fprintf(prdel_fp,"extern void pr_find_bt(char*, hcg_key*); \n");/* Sathya */ fprintf(prdel_fp,"extern int lut_insert_element(lut_st *, char *) ; \n");/* Sathya */ fprintf(prdel_fp,"extern void logwait(void); \n");/* Sathya */ fprintf(prdel_fp,"extern void logstr(char*); \n");/* Sathya */ gen_pr_unlink_macros(); /*** 93su523 PGEN merge ***/ fprintf(prdel_fp,"/******************************************************************************/\n"); fprintf(prdel_fp,"/* This routine will delete a single row from the database. The row is the */\n"); fprintf(prdel_fp,"/* one pointed to by the XXcurr variable. */\n"); fprintf(prdel_fp,"/******************************************************************************/\n"); fprintf(prdel_fp,"void pr_del(tbl_idx)\n"); fprintf(prdel_fp,"int tbl_idx;\n"); fprintf(prdel_fp,"{\n"); fprintf(prdel_fp," static char rcsid[] = \"$Id\";\n"); fprintf(prdel_fp," char temp_key[HCG_KEY_SIZE+1];\n"); /* added for GENLOG logging 96s523 */ if (cli_log ==1) { fprintf(prdel_fp,"char log_text[BUFSIZE];\n\n"); fprintf(prdel_fp,"\tlogwait();\n\n"); } fprintf(prdel_fp, "\tswitch( encoding(hcg_table_seq_list[tbl_idx].ttabbrev) )\n" ); fprintf(prdel_fp, "\t{\n"); /* * generating cases' branches */ tt_curr = tt; while ( tt_curr != NULL) { fprintf(prdel_fp,"\t\tcase %d :\t/* encoding of %s */\n",encoding(tt_curr->TTabbr), tt_curr->TTabbr); /* for each of the pc_table entries, generating a while loop linking all the rings accordingly */ tmp = pc_table; while ( tmp != NULL ) { if (strncmp(tmp->firstid,tt_curr->TTabbr,hcg_abbr_size) != 0) { tmp = tmp->next_ptr; continue; } /* getting table type and abbreviates for parent and child */ strncpy_null(prnt_abbrev,tmp->firstid,hcg_abbr_size); strcpy(parent,tmp->firstid); strncpy_null(child_abbrev,tmp->secondid,hcg_abbr_size); strcpy(child,tmp->secondid); strcpy(parent_pkey,parent); foundnum = 0; i = 0 ; while ( (!foundnum) && (i < strlen(parent))) if (isdigit(parent[i]) != 0) foundnum = 1; else i++ ; if (foundnum) parent_pkey[i] = '\0'; fprintf(prdel_fp,"\t\t\tunlink_child_"); if (tmp->Singleton) fprintf(prdel_fp,"1"); else { if ((!cli_nobp) && (tmp->HasBp)) fprintf(prdel_fp,"bp_m"); else fprintf(prdel_fp,"nobp_m"); } fprintf(prdel_fp,"(%s,%s,%s,%s);\n",child_abbrev,prnt_abbrev,parent,child); tmp = tmp->next_ptr; } /* for each of the cp_table entries, generating a while loop linking all the rings accordingly */ tmp = cp_table; while ( tmp != NULL ) { if (strncmp(tmp->firstid,tt_curr->TTabbr,hcg_abbr_size) != 0) { tmp = tmp->next_ptr; continue; } /* getting table type and abbreviates for parent and child */ strncpy_null(child_abbrev,tmp->firstid,hcg_abbr_size); strcpy(child,tmp->firstid); strncpy_null(prnt_abbrev,tmp->secondid,hcg_abbr_size); strcpy(parent,tmp->secondid); strcpy(parent_pkey,parent); foundnum = 0; i = 0 ; while ( (!foundnum) && (i < strlen(parent))) if (isdigit(parent[i]) != 0) foundnum = 1; else i++ ; if (foundnum) parent_pkey[i] = '\0'; fprintf(prdel_fp,"\t\t\tunlink_parent_"); if (tmp->Singleton) fprintf(prdel_fp,"1"); else { if ((!cli_nobp) && (tmp->HasBp)) fprintf(prdel_fp,"bp_m"); else fprintf(prdel_fp,"nobp_m"); } fprintf(prdel_fp,"(%s,%s,%s,%s);\n",child_abbrev,prnt_abbrev,parent,child); tmp = tmp->next_ptr; } fprintf(prdel_fp,"#ifdef DEBUG\n"); fprintf(prdel_fp,"\t\tdecode(temp_key, &%scurr->%sid);\n", tt_curr->TTabbr, tt_curr->TTabbr); fprintf(prdel_fp,"\t\tprintf(\"The primary key deleted is %%s\\n\",temp_key);\n"); fprintf(prdel_fp,"#endif\n"); fprintf(prdel_fp,"\t\t\tdel_row(%s);\n", tt_curr->TTabbr); /* added for GENLOG logging 96s523 */ if (cli_log==1) { fprintf(prdel_fp,"\n\t\t\t/* The following is to support logging */\n"); fprintf(prdel_fp,"\t\t\tdecode(temp_key, &%scurr->%sid);\n", tt_curr->TTabbr, tt_curr->TTabbr); fprintf(prdel_fp,"\t\t\tsprintf(log_text,\"DL %%s\\n\",temp_key);\n"); fprintf(prdel_fp,"\t\t\tlogstr(log_text);\n\n"); } /* (END) GENLOG 96s523 */ fprintf(prdel_fp,"\t\t\tbreak;\n\n"); tt_curr = tt_curr->next_ptr; } fprintf(prdel_fp,"\t}\n"); fprintf(prdel_fp,"}\n"); /*** 95s523,chwang,5,11,95. Add pr_del_bt() routine into pr_delete.c file ***/ gen_pr_del_bt(); return; } /* 93su523 PGEN Merge (BEGIN) */ gen_pr_unlink_macros() { char *sep = (cli_ansi)? "##" : "/**/" ; fprintf(prdel_fp,"/******************************************************************************/\n"); fprintf(prdel_fp,"/* This private macro is used by pr_delete to physically delete a row. It */\n"); fprintf(prdel_fp,"/* also unlinks the row from its table's row chain. */\n"); fprintf(prdel_fp,"/******************************************************************************/\n"); fprintf(prdel_fp, "/* New version of del_row - 93/2/8 by RJL and CMurphy: */\n"); fprintf(prdel_fp, "/* tbl == tbl*//*end != NULL (and rcount = 1) means a single-row table */\n"); fprintf(prdel_fp, "/* tbl == tbl*//*end == NULL (and rcount = 0) means an empty table -RJL */\n"); fprintf(prdel_fp, "#define del_row(tbl) \\\n"); fprintf(prdel_fp, "if (tbl%send == NULL) \\\n",sep); fprintf(prdel_fp, "printf(\"del_row error: empty table\");\\\n"); fprintf(prdel_fp, "else \\\n"); fprintf(prdel_fp, "if (tbl%scurr == NULL) \\\n",sep); fprintf(prdel_fp, " printf(\"del_row error: NULL curr row ptr\");\\\n"); fprintf(prdel_fp, "else\\\n"); fprintf(prdel_fp, "{\\\n"); /*** 95s523,chwang,5,11,95. Add few lines to delete arow from btree. ***/ /*** ---lines begin--- ***/ fprintf(prdel_fp, "if( tbl%sbtidx == BTREESEARCH ) \\\n",sep); fprintf(prdel_fp, "{ \\\n"); fprintf(prdel_fp, " sprintf(tempbtree,\"tbl\"); \\\n"); fprintf(prdel_fp, " tempbtree[HCG_ABBR_SIZE]=\'\\0\'; \\\n"); fprintf(prdel_fp, " pr_del_bt(tempbtree,&(tbl%scurr->tbl%sid)); \\\n",sep,sep); fprintf(prdel_fp, "} \\\n"); /*** ---lines end--- ***/ fprintf(prdel_fp, "if (tbl%send == tbl%scurr) /*last row: next_ptr = NULL - RJL 93/2/8 */\\\n",sep,sep); fprintf(prdel_fp, " tbl%send = tbl%scurr->prev_ptr; /* = NULL iff curr row = first row */\\\n",sep,sep); fprintf(prdel_fp, "if (tbl == tbl%scurr) /* first row: prev_ptr = NULL - RJL 93/2/8 */\\\n",sep); fprintf(prdel_fp, " tbl = tbl%scurr->next_ptr; /* = NULL iff curr row = last row */\\\n",sep); fprintf(prdel_fp, "if (tbl%scurr->prev_ptr != NULL) \\\n",sep); fprintf(prdel_fp, " { \\\n"); fprintf(prdel_fp, " tbl%scurr->prev_ptr->next_ptr = tbl%scurr->next_ptr; \\\n",sep,sep); fprintf(prdel_fp, " } \\\n"); fprintf(prdel_fp, "if (tbl%scurr->next_ptr != NULL) \\\n",sep); fprintf(prdel_fp, " { \\\n"); fprintf(prdel_fp, " tbl%scurr->next_ptr->prev_ptr = tbl%scurr->prev_ptr; \\\n",sep,sep); fprintf(prdel_fp, " } \\\n"); /*** 93s523 ***/ #ifdef NOTNOW fprintf(prdel_fp, "tbl%scurr->tbl%sid[4] = '\\0'; /* sentinel for next line char[2] */\\\n",sep,sep); /* I don't know about this one - MM */ #endif fprintf(prdel_fp, "hcg_ts_list[tbl%s_idx].ts_list[get_version(&tbl%scurr->tbl%sid)].rcount--; \\\n",sep,sep,sep); fprintf(prdel_fp, "hcg_table_seq_list[tbl%s_idx].rcount--;\\\n",sep); fprintf(prdel_fp, "free(tbl%scurr);\\\n",sep); fprintf(prdel_fp, "}\n\n"); fprintf(prdel_fp,"/******************************************************************************/\n"); fprintf(prdel_fp,"/* This private macro is used by pr_del to unlink a row from the specified */\n"); fprintf(prdel_fp,"/* parent table. It is identical to unlink_parent_nobp except that its is */\n"); fprintf(prdel_fp,"/* for a singleton child. */\n"); fprintf(prdel_fp,"/******************************************************************************/\n"); fprintf(prdel_fp, "#define unlink_parent_1(ca,pa,p,c) \\\n"); fprintf(prdel_fp, "pa%stemp = ca%scurr->p%s_pp; \\\n",sep,sep,sep); fprintf(prdel_fp, "if (pa%stemp != NULL) \\\n",sep); fprintf(prdel_fp, " pa%stemp->c%s_fcp = NULL\n\n",sep,sep); if (!cli_nobp) { fprintf(prdel_fp,"/******************************************************************************/\n"); fprintf(prdel_fp,"/* This private macro is used by pr_del to unlink a row from the specified */\n"); fprintf(prdel_fp,"/* parent table. It is identical to unlink_parent_nobp except that back */\n"); fprintf(prdel_fp,"/* pointers are also unlinked. */\n"); fprintf(prdel_fp,"/******************************************************************************/\n"); fprintf(prdel_fp, "#define unlink_parent_bp_m(ca,pa,p,c) \\\n"); fprintf(prdel_fp, "pa%stemp = ca%scurr->p%s_pp; \\\n",sep,sep,sep); fprintf(prdel_fp, "ca%stemp = ca%scurr; /* Change CEM & RJL 20 APR 93*/ \\\n",sep,sep,sep); fprintf(prdel_fp, "if (pa%stemp != NULL) \\\n",sep); fprintf(prdel_fp, " { \\\n"); fprintf(prdel_fp, " if (( pa%stemp->c%s_fcp == ca%stemp) && \\\n",sep,sep,sep); fprintf(prdel_fp, " ( (struct pa *) ca%scurr->p%s_fpp == pa%stemp))\t/* only child case */ \\\n",sep,sep,sep); fprintf(prdel_fp, " { \\\n"); fprintf(prdel_fp, " pa%stemp->c%s_fcp = NULL; \\\n",sep,sep); fprintf(prdel_fp, " pa%stemp->c%s_bcp = NULL; \\\n",sep,sep); fprintf(prdel_fp, " } \\\n"); fprintf(prdel_fp, " else \\\n"); fprintf(prdel_fp, " if ( pa%stemp->c%s_fcp == ca%stemp )\t/* first child case */ \\\n",sep,sep,sep); fprintf(prdel_fp, " { \\\n"); fprintf(prdel_fp, " pa%stemp->c%s_fcp = (struct ca *)ca%scurr->p%s_fpp; \\\n",sep,sep,sep,sep); /* 93su523 PGEN merge */ fprintf(prdel_fp, " ca%scurr2 = (struct ca *)ca%scurr->p%s_fpp; \\\n",sep,sep,sep); /* 93su523 PGEN merge */ fprintf(prdel_fp, " (struct pa *) ca%scurr2->p%s_bpp = pa%stemp; \\\n",sep,sep,sep); fprintf(prdel_fp, " } \\\n"); fprintf(prdel_fp, " else \\\n"); fprintf(prdel_fp, " if ( (struct pa *) ca%scurr->p%s_fpp == pa%stemp)\t/* last child case */ \\\n",sep,sep,sep); fprintf(prdel_fp, " { \\\n"); fprintf(prdel_fp, " pa%stemp->c%s_bcp = (struct ca *)ca%scurr->p%s_bpp; \\\n",sep,sep,sep,sep); /* 93su523 PGEN merge */ fprintf(prdel_fp, " ca%scurr2 = (struct ca *)ca%scurr->p%s_bpp; \\\n",sep,sep,sep); /* 93su523 PGEN merge */ fprintf(prdel_fp, " (struct pa *) ca%scurr2->p%s_fpp = pa%stemp; \\\n",sep,sep,sep); fprintf(prdel_fp, " } \\\n"); fprintf(prdel_fp, " else\t\t\t\t\t\t\t\t/* middle of child chain case */ \\\n"); fprintf(prdel_fp, " { \\\n"); fprintf(prdel_fp, " ca%scurr2 = (struct ca *)ca%scurr->p%s_bpp; \\\n",sep,sep,sep); /* 93su523 PGEN merge */ fprintf(prdel_fp, " ca%scurr2->p%s_fpp = ca%scurr->p%s_fpp; \\\n",sep,sep,sep,sep); fprintf(prdel_fp, " ca%scurr2 = (struct ca *)ca%scurr->p%s_fpp; \\\n",sep,sep,sep); /* 93su523 PGEN merge */ fprintf(prdel_fp, " ca%scurr2->p%s_bpp = ca%scurr->p%s_bpp; \\\n",sep,sep,sep,sep); fprintf(prdel_fp, " } \\\n"); fprintf(prdel_fp, " }\n\n"); } fprintf(prdel_fp,"/******************************************************************************/\n"); fprintf(prdel_fp,"/* This private macro is used by pr_del to unlink a row from the specified */\n"); fprintf(prdel_fp,"/* parent table. It is identical to unlink_parent_bp except that back */\n"); fprintf(prdel_fp,"/* pointers are not unlinked. */\n"); fprintf(prdel_fp,"/******************************************************************************/\n"); fprintf(prdel_fp, "#define unlink_parent_nobp_m(ca,pa,p,c) \\\n"); fprintf(prdel_fp, "pa%stemp = ca%scurr->p%s_pp; \\\n",sep,sep,sep); fprintf(prdel_fp, "ca%stemp = ca%scurr; /* Change CEM & RJL 20 APR 93*/ \\\n",sep,sep,sep); fprintf(prdel_fp, "if (pa%stemp != NULL) \\\n",sep); fprintf(prdel_fp, " { \\\n"); fprintf(prdel_fp, " if (( pa%stemp->c%s_fcp == ca%stemp) && \\\n",sep,sep,sep); fprintf(prdel_fp, " ( (struct pa *) ca%scurr->p%s_fpp == pa%stemp))\t/* only child case */ \\\n",sep,sep,sep); fprintf(prdel_fp, " { \\\n"); fprintf(prdel_fp, " pa%stemp->c%s_fcp = NULL; \\\n",sep,sep); fprintf(prdel_fp, " } \\\n"); fprintf(prdel_fp, " else \\\n"); fprintf(prdel_fp, " if ( pa%stemp->c%s_fcp == ca%stemp )\t/* first child case */ \\\n",sep,sep,sep); fprintf(prdel_fp, " { \\\n"); fprintf(prdel_fp, " pa%stemp->c%s_fcp = (struct ca *)ca%scurr->p%s_fpp; \\\n",sep,sep,sep,sep); /* 93su523 PGEN merge */ fprintf(prdel_fp, " ca%scurr2 = (struct ca *)ca%scurr->p%s_fpp; \\\n",sep,sep,sep); /* 93su523 PGEN merge */ fprintf(prdel_fp, " } \\\n"); fprintf(prdel_fp, " else /* middle or last child case */ \\\n"); fprintf(prdel_fp, " { \\\n"); fprintf(prdel_fp, " ca%scurr2 = pa%stemp->c%s_fcp;\\\n", sep, sep, sep); fprintf(prdel_fp, " while((struct ca*) ca%scurr2->p%s_fpp != ca%stemp) \\\n", sep, sep, sep); fprintf(prdel_fp, " ca%scurr2 = (struct ca *) ca%scurr2->p%s_fpp; \\\n", sep, sep, sep); fprintf(prdel_fp, " assert((struct ca*) ca%scurr2->p%s_fpp == ca%stemp); \\\n", sep, sep, sep); fprintf(prdel_fp, " ca%scurr2->p%s_fpp = ca%stemp->p%s_fpp; \\\n", sep, sep, sep, sep); fprintf(prdel_fp, " } \\\n"); fprintf(prdel_fp, " }\n\n"); fprintf(prdel_fp,"/******************************************************************************/\n"); fprintf(prdel_fp,"/* This private macro is used by pr_del to unlink a row from the specified */\n"); fprintf(prdel_fp,"/* child table. It is identical to link_child_nobp except that it is for a */\n"); fprintf(prdel_fp,"/* singleton child. */\n"); fprintf(prdel_fp,"/******************************************************************************/\n"); fprintf(prdel_fp, "#define unlink_child_1(ca,pa,p,c) \\\n"); fprintf(prdel_fp, "ca%stemp = (struct ca *) pa%scurr->c%s_fcp; \\\n",sep,sep,sep); fprintf(prdel_fp, "if (ca%stemp != NULL) \\\n",sep); fprintf(prdel_fp, " ca%stemp->p%s_pp = NULL\n\n",sep,sep); if (!cli_nobp) { fprintf(prdel_fp,"/******************************************************************************/\n"); fprintf(prdel_fp,"/* This private macro is used by pr_del to unlink a row from the specified */\n"); fprintf(prdel_fp,"/* child table. It is identical to link_child_nobp except that back pointers */\n"); fprintf(prdel_fp,"/* are also unlinked. */\n"); fprintf(prdel_fp,"/******************************************************************************/\n"); fprintf(prdel_fp, "#define unlink_child_bp_m(ca,pa,p,c) \\\n"); fprintf(prdel_fp, "ca%stemp = (struct ca *) pa%scurr->c%s_fcp; \\\n",sep,sep,sep); fprintf(prdel_fp, "while ((ca%stemp != NULL) && \\\n",sep); fprintf(prdel_fp, " ((struct pa *) ca%stemp != pa%scurr)) \\\n",sep,sep); fprintf(prdel_fp, " { \\\n"); fprintf(prdel_fp, " ca%stemp2 = (struct ca *)ca%stemp->p%s_fpp; \\\n",sep,sep,sep); /* 93su523 PGEN merge */ fprintf(prdel_fp, " ca%stemp->p%s_bpp = (void *)ca%stemp->p%s_fpp = (void *)ca%stemp->p%s_pp = NULL; \\\n",sep,sep,sep,sep,sep,sep); fprintf(prdel_fp, " ca%stemp = ca%stemp2; \\\n",sep,sep); fprintf(prdel_fp, " }\n\n"); } fprintf(prdel_fp,"/******************************************************************************/\n"); fprintf(prdel_fp,"/* This private macro is used by pr_del to unlink a row from the specified */\n"); fprintf(prdel_fp,"/* child table. It is identical to link_child_bp except that back pointers */\n"); fprintf(prdel_fp,"/* are not unlinked. */\n"); fprintf(prdel_fp,"/******************************************************************************/\n"); fprintf(prdel_fp, "#define unlink_child_nobp_m(ca,pa,p,c) \\\n"); fprintf(prdel_fp, "ca%stemp = (struct ca *) pa%scurr->c%s_fcp; \\\n",sep,sep,sep); fprintf(prdel_fp, "while ((ca%stemp != NULL) && \\\n",sep); fprintf(prdel_fp, " ((struct pa *) ca%stemp != pa%scurr)) \\\n",sep,sep); fprintf(prdel_fp, " { \\\n"); fprintf(prdel_fp, " ca%stemp2 = (struct ca *) ca%stemp->p%s_fpp; \\\n",sep,sep,sep); /* 93su523 PGEN merge */ fprintf(prdel_fp, " ca%stemp->p%s_fpp = NULL; \\\n",sep,sep); /* Sathya */ fprintf(prdel_fp, " ca%stemp->p%s_pp = NULL; \\\n",sep,sep); /* Sathya */ fprintf(prdel_fp, " ca%stemp = ca%stemp2; \\\n",sep,sep); fprintf(prdel_fp, " }\n\n"); } /* 93su523 PGEN Merge (END) */ /*** 95s523,chwang,5,11,95. ***************************************************/ /* This routine writes out the code for the pr_del_bt to the pr_delete.c */ /* output file. */ /******************************************************************************/ gen_pr_del_bt() { fprintf(prdel_fp, "/******************************************************************************/\n"); fprintf(prdel_fp, "/* Description: This routine is used to delete a row in btree. */\n"); fprintf(prdel_fp, "/* Input: the special table name and its pkey value. */\n"); fprintf(prdel_fp, "/* *temp1 is the table name. temp2 is the pkey value. */\n"); fprintf(prdel_fp, "/* Output: none.( it will delete the specific row from btree. ) */\n"); fprintf(prdel_fp, "/******************************************************************************/\n"); fprintf(prdel_fp, "void pr_del_bt(char* temp1, hcg_key* temp2)\n"); /* Sathya */ fprintf(prdel_fp, "{\n"); fprintf(prdel_fp, " int tbl_encoding;\n"); /* Sathya */ /*fprintf(prdel_fp, " hcg_key result;\n "); Sathya */ tt_curr = tt; while ( tt_curr != NULL) { if( tt_curr->comment[0] != '\0' ) if( tt_curr->comment[2] == '1' ) fprintf(prdel_fp, " struct %sbtree *%stmpbt,*%stmpbt2; \n",tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr); tt_curr = tt_curr->next_ptr; } /* while tt */ fprintf(prdel_fp, " pr_find_bt( temp1, temp2);\n"); /* Sathya */ fprintf(prdel_fp, "\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(prdel_fp,"\tcase %d :\t/* encoding of %s */\n", encoding(tt_curr->TTabbr),tt_curr->TTabbr); fprintf(prdel_fp,"\ %stmpbt = %sbtcurr; \n\ if( (%stmpbt->left == NULL) && (%stmpbt->right == NULL )) \n\ { \n\ if( %stmpbt == %sbtroot ) \n\ %sbtroot = NULL ; \n\ else \n\ { \n\ if( (%stmpbt->parent)->left == %stmpbt ) \n\ (%stmpbt->parent)->left=NULL; \n\ else \n\ (%stmpbt->parent)->right=NULL; \n\ } \n\ } \n",tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr ,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr); fprintf(prdel_fp,"\ else if( %stmpbt->left != NULL && %stmpbt->right != NULL) \n\ { \n\ %stmpbt2=%stmpbt->left; \n\ while( %stmpbt2->right != NULL ) \n\ %stmpbt2=%stmpbt2->right; \n\ if( %stmpbt2->left == NULL && %stmpbt2->right == NULL ) \n\ { \n\ (%stmpbt2->parent)->right=NULL; \n\ if( %stmpbt->left != %stmpbt2 ) \n\ { \n\ %stmpbt2->left=%stmpbt->left; \n\ %stmpbt2->right=%stmpbt->right; \n\ if( %stmpbt2->right != NULL ) \n\ %stmpbt2->right->parent=%stmpbt2; \n\ if( %stmpbt2->left != NULL ) \n\ %stmpbt2->left->parent=%stmpbt2; \n\ } \n\ %stmpbt2->parent= %stmpbt->parent; \n\ if( %stmpbt2->parent != NULL ) \n\ %stmpbt2->parent->left=%stmpbt2; \n\ else \n\ %sbtroot=%stmpbt2; \n\ } \n",tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr ,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr ,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr ,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr ,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr); fprintf(prdel_fp,"\ else \n\ { \n\ if( %stmpbt->left != %stmpbt2 ) \n\ { \n\ %stmpbt2->parent->right=%stmpbt2->left; \n\ %stmpbt2->left->parent=%stmpbt2->parent; \n\ %stmpbt2->left=%stmpbt->left; \n\ %stmpbt2->right=%stmpbt->right; \n\ if( %stmpbt2->left != NULL ) \n\ %stmpbt2->left->parent=%stmpbt2; \n\ if( %stmpbt2->right != NULL ) \n\ %stmpbt2->right->parent=%stmpbt2; \n\ } \n\ %stmpbt2->parent=%stmpbt->parent; \n\ if( %stmpbt2->parent != NULL ) \n\ %stmpbt2->parent->left=%stmpbt2; \n\ else \n\ %sbtroot=%stmpbt2; \n\ } \n\ } \n ",tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr ,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr ,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr ,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr ); fprintf(prdel_fp,"\ else \n\ { \n\ if( %stmpbt->left == NULL ) \n\ { \n\ if( %stmpbt->parent == NULL ) \n\ { \n\ %sbtroot=%stmpbt->right ; \n\ } \n\ else \n\ { \n\ if( (%stmpbt->parent)->left == %stmpbt ) \n\ (%stmpbt->parent)->left = %stmpbt->right; \n\ else \n\ (%stmpbt->parent)->right= %stmpbt->right; \n\ } \n\ (%stmpbt->right)->parent = %stmpbt->parent; \n\ } \n\ else \n\ { \n\ if( %stmpbt->parent == NULL ) \n\ { \n\ %sbtroot=%stmpbt->left ; \n\ } \n\ else \n\ { \n\ if( (%stmpbt->parent)->left == %stmpbt ) \n\ (%stmpbt->parent)->left = %stmpbt->left; \n\ else \n\ (%stmpbt->parent)->right= %stmpbt->left; \n\ } \n\ (%stmpbt->left)->parent = %stmpbt->parent; \n\ } \n\ } \n\ free(%sbtcurr); \n\ %sbtcurr=NULL; \n",tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr ,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr ,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr ,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr ,tt_curr->TTabbr,tt_curr->TTabbr,tt_curr->TTabbr ); fprintf(prdel_fp," break; \n\n"); } tt_curr = tt_curr->next_ptr; } fprintf(prdel_fp,"default: printf(\"\\n\\tWARNING: pr_del_bt(%%s, %%x) called: not implemented \\n\\n\",\n temp1, (unsigned int) *temp2);\n");/* Sathya */ fprintf(prdel_fp, " }\n"); fprintf(prdel_fp, "}\n\n"); }