//Filename: add.c //Developer: Jay Suttiruttana #include "btree.h" Record_type GetRecord(char *); void main(int argc, char *argv[]) { page_type d_parent; /* Dummy parent for the root NOT an actual page */ Record_type record; Status_type retval; Item_type item, promo_item; int root, promo_rrn, rec_rrn, found_rrn, found_pos, key, total_rec; if ( argc !=2 ) Error("ERROR! No key specified"); btopen(); dta_open(); key = atoi (argv[1]); root = getroot(); if(btsearch(root, key, &found_rrn, &found_pos)) Error("Key already there"); /* Search B-Tree for key number */ rec_rrn = get_rrn(); /* Get next available RRN for new record check in availist */ item.key= key; item.rec_rrn = rec_rrn; pageinit(&d_parent); /* Initialize dummy parent */ d_parent.child[0] = root; /* Store RRN of the root in dummy parent */ retval = insert(&d_parent, NIL, 0, item, &promo_rrn, &promo_item); if(retval == PROMOTION) root = create_root(promo_item, root, promo_rrn); record = GetRecord(argv[1]); /* Prompt user for record arguments */ save_record(rec_rrn, record); /* Write record to datafile */ total_rec = get_total_rec(); total_rec++; put_total_rec(total_rec); dta_close(); btclose(); } /*******************************************************************/ Record_type GetRecord(char *RICORDI) { Record_type record; int i, j, ha; char ch; char newfield[15]="\0"; printf("Please enter the new data:"); printf("\nEnter a Ryom: "); { for( j = 0; (j < 6) && ((ch = getchar()) != EOF) && (ch != '\n'); j++ ) newfield[j] = ch; for ( ha=j; ha<6; ha++) newfield [ha] = ' '; for (i =0; i <6; i++) record.RYOM[i] = newfield[i]; record.RYOM[6] = '\0'; memset(newfield,'\0',15); } printf("\nEnter a Fanna: "); { for( j = 0; (j < 9) && ((ch = getchar()) != EOF) && (ch != '\n'); j++ ) newfield[j] = ch; for ( ha=j; ha<11; ha++) newfield [ha] = ' '; record.FANNA[0]=' '; for (i =0; i <8; i++) record.FANNA[i+1] = newfield[i]; record.FANNA[9] = '\0'; memset(newfield,'\0',15); } printf("\nEnter a Pincherele: "); { for( j = 0; (j < 12) && ((ch = getchar()) != EOF) && (ch != '\n'); j++ ) newfield[j] = ch; for ( ha=j; ha<12; ha++) newfield [ha] = ' '; for (ha =0; ha < 2; ha++) record.PINCHERLE[ha] = ' '; for (i =0; i <10; i++) record.PINCHERLE[i+2] = newfield[i]; record.PINCHERLE[12] = '\0'; memset(newfield,'\0',15); } for ( ha=0; ha<6; ha++) record.RICORDI[ha]=' '; ha = strlen(RICORDI); for (i =0 ; i