/* @(#)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 : Steve Smith / Craig Smith */ /* */ /* created : July, 1991 */ /* */ /* revisions : 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 */ /* 11/30/00 kmiu: NT port: included prototypes.h */ /* 11/30/00 kmiu: Removed unreferenced variables */ /* 11/30/00 kmiu: Replaced hardcoded file extensions with outfile_ext */ /* 11/30/00 kmiu: Added void type to gen_pr_del_bt() to match its */ /* prototype and to fprintf statement for pr_del_bt */ /* 2kf522 mottesen & kmiu: STL modifications: ifdef'd out pr_del_bt */ /* */ /* 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" #include "prototypes.h" void gen_pr_delete() /* generating function pr_del() */ { static char rcsid[] = "$Id: gen_pr_delete.c,v 1.5.4.1 1999/05/04 16:59:52 jkarner Exp $"; fprintf(prdel_fp,"/******************************************************************************/\n"); /* kmiu-replace cc ext with mach dep var in next line */ fprintf(prdel_fp,"/* File : pr_delete.%s */\n",outfile_ext); fprintf(prdel_fp,"/* Schema : %-58s */\n",sch_text_file_name); fprintf(prdel_fp,"/* GENCPP Version : %-58s */\n",CHGEN_VERSION); fprintf(prdel_fp,"/******************************************************************************/\n\n"); fprintf(prdel_fp,"#include \n") ; fprintf(prdel_fp,"#include \"%s\"\n",sch_header_file_name) ; tt_curr=tt; while(tt_curr != NULL) { fprintf(prdel_fp, "#include \"%sschema.h\"\n", tt_curr->TTabbr) ; tt_curr=tt_curr->next_ptr; } fprintf(prdel_fp, "\n") ; /* gen_pr_unlink_macros(); has moved to gen_macros.c by ntansala 2k0430 */ /* move pr_del() to make_delete_row in gen_ops.c by ntansala */ /*** 95s523,chwang,5,11,95. Add pr_del_bt() routine into pr_delete.c file ***/ gen_pr_del_bt(); return; } /*** 95s523,chwang,5,11,95. ***************************************************/ /* This routine writes out the code for the pr_del_bt to the pr_delete.c */ /* output file. */ /******************************************************************************/ void gen_pr_del_bt(void) { fprintf(prdel_fp, "#ifndef USE_STL\n"); 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"); /* kmiu-add void return type to pr_del_bt */ fprintf(prdel_fp, "void pr_del_bt(char *temp1, hcg_key temp2)\n"); fprintf(prdel_fp, "{\n"); fprintf(prdel_fp, " int tbl_encoding, finish=FALSE ;\n"); fprintf(prdel_fp, " hcg_key result;\n "); 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"); 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, " }\n"); fprintf(prdel_fp, "}\n\n"); fprintf(prdel_fp, "#endif /* USE_STL */\n"); }