/******************************************************************************/ /* File : pr_log.cc */ /* Schema : bdeschema.sch */ /* GENCPP Version : Chgen V 12 - Sathya */ /******************************************************************************/ #include #include #include #include #include #include "bdeschema.h" #include "SVschema.h" #include "TTschema.h" #include "TAschema.h" #include "VVschema.h" #include "TSschema.h" #include "FOschema.h" #include "GDschema.h" #include "HGschema.h" #include "HNschema.h" #include "HAschema.h" #include "HLschema.h" #include "HPschema.h" #include "HIschema.h" #include "CGschema.h" #include "GXschema.h" int usleep(struct timeval *t); /******************************************************************************/ /* Function prototypes */ /******************************************************************************/ /******************************************************************************/ /* Global variables */ /******************************************************************************/ static struct timeval timestamp; static int time_flag = -1; /**************************************************************************** * * * trivial function for signal handler * ***************************************************************************/ static void func(int signo) { return; } /************************************************************/ /* Function: log_sleep */ /* */ /* This function is used to pause the execution based on */ /* a parameter indicatings the number of milliseconds of */ /* the desired pause */ /* */ /* Arguments: mseconds - integer of the number of sleep */ /* milliseconds. */ /************************************************************/ #ifdef __STDC__ int log_sleep(int milliseconds) #else int log_sleep(milliseconds) int milliseconds; #endif /* __STDC__ */ { struct timeval t; int status; if (milliseconds < 0) { fprintf(stderr, "%s: %d: log_sleep: milliseconds must be >= 0\n", __FILE__,__LINE__); return -1; } t.tv_sec = milliseconds/1000; t.tv_usec = (milliseconds % 1000)*1000; status = usleep(&t); if (status < 0) { fprintf(stderr, "%s: %d: log_sleep: usleep failed with status %d\n", status); return -1; } return 0; } /**************************************************************************** * usleep * * This routine blocks until the amount of time specified in the timeval * * referred to be t has elapsed. The method used is to set an interval * * timer and to wait until the signal is delivered with a sigpause. * * side effects: * * The SIGALRM handler is reset for the duration of the call, * * When the interval timer expires, A SIGALRM is delivered to the process * * * * preconditions: * * t is not null * * t refers to a timeval struct * * t->tv_sec >= 0 * * t->tv_usec >= 0 * * t->tv_usec < 1*10^6 * * * * postcondition: * * if the return value of usleep is 0, then * * time = time' + t->tv_sec + t->tv_usec * * * * returns: 0 if no errors occurred, -1 otherwise * ***************************************************************************/ int usleep(struct timeval *t) { struct sigaction newact, oldact; sigset_t newmask, oldmask, zeromask; struct itimerval tv1, tv2; /* validate arg */ if (t == NULL) { fprintf(stderr, "%s: %d: usleep: bad argument\n", __FILE__,__LINE__); return -1; } /* don't wait if no time specified */ if (t->tv_sec == 0 && t->tv_usec == 0) { return 0; } /* block signals */ sigemptyset(&newmask); sigemptyset(&zeromask); sigaddset(&newmask, SIGALRM); if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0) { perror("sigprocmask"); fprintf(stderr, "%s: %d: usleep: sigprocmask failed\n", __FILE__,__LINE__); return -1; } /* set handler */ newact.sa_handler = func; sigemptyset(&newact.sa_mask); newact.sa_flags = 0; if (sigaction(SIGALRM, &newact, &oldact) < 0) { perror("sigaction"); fprintf(stderr, "%s: %d: usleep: sigaction failed\n", __FILE__, __LINE__); return -1; } /* set interval timer */ tv2.it_value.tv_sec = t->tv_sec; tv2.it_value.tv_usec = t->tv_usec; tv2.it_interval.tv_sec = 0; tv2.it_interval.tv_usec = 0; if (setitimer(ITIMER_REAL, &tv2, &tv1) < 0) { fprintf(stderr, "%s: %d: usleep: setitimer failed\n", __FILE__, __LINE__); return -1; } if (tv1.it_value.tv_sec > 0 || tv1.it_value.tv_usec > 0) { fprintf(stderr, "%s: %d: usleep: interval timer is already set!\n", __FILE__,__LINE__); return -1; } /* sleep until signal delivered */ if (sigsuspend(&zeromask) != -1) { fprintf(stderr, "%s: %d: usleep: sigsuspend didn't return -1\n", __FILE__, __LINE__); return -1; } /* reset signal mask */ if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0) { perror("sigprocmask"); fprintf(stderr, "%s: %d: usleep: sigprocmask failed\n", __FILE__, __LINE__); return -1; } /* reset signal handler */ if (sigaction(SIGALRM, &oldact, NULL) < 0 ) { perror("sigaction"); fprintf(stderr, "%s: %d: usleep: sigaction failed\n", __FILE__, __LINE__); return -1; } return 0; } /******************************************************************************/ /* time_initialize */ /* Sets the timestamp global with the current time and clear the time_flag */ /******************************************************************************/ void time_initialize() { struct timezone t; gettimeofday(×tamp, &t); time_flag = 0; } int get_delta_tee(struct timeval *t) { struct timeval now, delta; struct timezone tz; if (!t) { fprintf(stderr, "%s: %d: get_delta_tee: t is null\n",__FILE__, __LINE__); return -1; } if (gettimeofday(&now, &tz) < 0) { perror("gettimeofday"); fprintf(stderr, "%s: %d: gettimeofday failed\n", __FILE__, __LINE__); return -1; } if (time_flag != 0) { /* the first time through report elapsed time of zero, and initialize */ t->tv_sec = 0; t->tv_usec = 0; time_initialize(); return 0; } if (now.tv_usec < timestamp.tv_usec) { if (now.tv_sec <= 0) { fprintf(stderr, "%s: %d: get_delta_tee: bad tv_sec value\n", __FILE__, __LINE__); return -1; } delta.tv_sec = now.tv_sec - 1; delta.tv_usec = now.tv_usec + 1000000; } else { delta.tv_sec = now.tv_sec; delta.tv_usec = now.tv_usec; } t->tv_sec = delta.tv_sec - timestamp.tv_sec; t->tv_usec = delta.tv_usec - timestamp.tv_usec; timestamp.tv_sec = now.tv_sec; timestamp.tv_usec = now.tv_usec; return 0; } /********************************************************** * Function: timeval2millisec(int *, struct timeval *) * * * * This function converts the time in the timeval struct * * into the equiv number of milliseconds, and places the * * result in the first argument. * * On success it returns 0, -1 otherwise * *********************************************************/ static int timeval2millisec(int *millisec, const struct timeval *t) { int temp; if (!millisec || !t) { fprintf(stderr, "%s: %d: timeval2millisec: bad argument\n", __FILE__, __LINE__); return -1; } temp = t->tv_sec*1000; temp = temp + t->tv_usec/1000; *millisec = temp; } /**********************************************************/ /* Function: logstr() */ /* Arguments: text - contains the string to be printed */ /* to the log file. */ /* */ /* This function writes the text string to the logfile */ /* if logging is active */ /* */ /**********************************************************/ void logstr(char text[BUFSIZE]) { if (hcg_log == 1) /* && RFLAG - RJL 021110 */ fprintf(hcg_logfileptr, "%s", text); } /**********************************************************/ /* Function: logwait() */ /* Arguments: none */ /* */ /* This function calculates the wait time based on the */ /* value of setitimer. */ /* waitTime = initial_val_of_itimer - cur_val_of_itimer */ /* Writes the waitTime to the log file and re-initializes*/ /* the value of the itimer. */ /* */ /**********************************************************/ void logwait() { struct timeval tv; char text[BUFSIZE]; int waitTime; if (hcg_log == 1) { /* && RFLAG - RJL 021110 */ get_delta_tee(&tv); if (timeval2millisec(&waitTime, &tv) < 0) { fprintf(stderr, "%s: %d: logwait: timeval2millisec failed\n"); return; } sprintf(text,"WA %d\n", waitTime); logstr(text); } } /********************************************************************************/ /* Function : pr_startlog */ /* */ /* Abstract : This function is used to start a logging session. */ /* It opens a logfile and dumps a current copy of the database */ /* */ /* Created by : B. Rideout */ /* */ /* Creation Date : 4/24/96 */ /* */ /* Modified : */ /* */ /********************************************************************************/ int pr_startlog (char *file_name, char *viewname) { static char rcsid[] = "$Id: gen_pr_log.c,v 1.2.4.1 1999/05/04 17:00:00 jkarner Exp $"; char DB1string[10] = "DB1.dat"; char logfileDB1_name[NAMELENGTH]; char temp_file_name[NAMELENGTH]="\0"; int i; /* check that pr_init has been called - if not, return without starting log*/ if (!hcg_initialized) { printf("Error: pr_startlog() called when database is not yet initialized.\n"); return (-1); } /* check that viewname is valid - if not, return without starting log*/ if (!find_view_idx(viewname)) { printf("Error: view %s passed to pr_startlog is not defined.\n",viewname); return (-2); } /* check that logging is off - if not, return without starting log*/ if (hcg_log) { printf("Error: pr_startlog called when logging was not off.\n"); return (-3); } /* Check that file_name is not null */ if (!strcmp(file_name, "\0")) { printf("Error: log file name null; logging not on.\n"); return (-4); } /* set global hcg_logfile to file name of log file (w/out extention) */ for (i = strlen(file_name); (i>=0) && (file_name[i]!= '.'); i--); if (i<0) /* no extention */ strcpy (hcg_logfile, file_name); else /* remove extention */ strncpy (hcg_logfile, file_name, (i)); strcpy (temp_file_name, hcg_logfile); strcat (temp_file_name, ".txt"); /* check that logfile opened - if not, return without starting log*/ if ((hcg_logfileptr=fopen(temp_file_name, "w")) == NULL) { printf("Error: pr_startlog() cannot open %s\n", file_name); return (-3); } /* Call pr_dump to save a current version of the database */ /* Database saved to name of log file + "DB1" */ strcat (strcpy(logfileDB1_name, hcg_logfile), DB1string); pr_dump (viewname, logfileDB1_name, FALSE, "w" ); /* Initiate logging by setting global hcg_log = 1 */ hcg_log =1; /* Log call to pr_startlog as first record */ logstr("SR\n"); /* Set timer info - to be done */ time_initialize(); return (0); } /* End pr_startlog */ /********************************************************************************/ /* Function : pr_stoplog */ /* */ /* Abstract : This function is used to stop a logging session. */ /* It optionally dumps a current copy of the database and closes */ /* the logfile */ /* */ /* Created by : B. Rideout */ /* */ /* Creation Date : 4/26/96 */ /* */ /* Modified : */ /* */ /********************************************************************************/ int pr_stoplog (char *viewname, int dump_flag) { char DB2string[10] = "DB2.dat"; char logfileDB2_name[NAMELENGTH]; /* check that logging is active - if not, return without stopping log*/ if (!hcg_log) { printf("Error: pr_stoplog() called when logging not active.\n"); return (-1); } /* check that viewname is valid - if not, return without starting log*/ if (!find_view_idx(viewname)) { printf("Error: view %s passed to pr_startlog is not defined.\n",viewname); return (-2); } /* 4/24/96 - other error checking functions to be added */ /* Generate Wait statement */ logwait(); /* Log pr_stoplog */ logstr("SP\n"); /* Terminate logging by setting global hcg_log = 0 */ hcg_log =0; /* Call pr_dump to save a current version of the database if dump_flag set */ /* Database saved to name of log file + "DB2" */ if (dump_flag) { strcat (strcpy(logfileDB2_name, hcg_logfile), DB2string); pr_dump (viewname, logfileDB2_name, FALSE, "w" ); } fclose(hcg_logfileptr); return (0); } /* End pr_stoplog */ /************************************************************/ /* Function: log_parselogdata */ /* */ /* This function is used to parse the data file(logdata.txt)*/ /* & create temporary files that contain the data of the */ /* original data files. It returns a string list with */ /* the names of the new files. The new file names are */ /* separated by spaces. It returns a value to indicate */ /* success or failure. */ /* */ /* Arguments: newlist - a list of files separated by commas */ /* */ /* Preconditions: */ /* newlist must be a character string of size BUFSIZE */ /* */ /* returns: 0 - success */ /* <0 - failure */ /* -3 - open file failure */ /* -5 - invalid file format */ /************************************************************/ int log_parselogdata(char *newlist) { char datafile[NAMELENGTH],token[BUFSIZE],tempfname[NAMELENGTH],tempnewlist[BUFSIZE]; FILE *data_fp, *temp_fp; int idx; /* open logdata.txt */ strcpy(datafile,"logdata.txt"); if ((data_fp = fopen(datafile, "r")) ==NULL) return(-3); hcg_ascii_fp = data_fp; hcg_read_next(); /* read first line of data file */ idx = 0; hcg_parse(hcg_buffer,token,&idx); if (strcmp(token,"LogDataFile") != 0) { /* invalid file format */ return(-5); } hcg_parse(hcg_buffer,token,&idx); /* get filename */ tempnewlist[0] = '\0'; while (!feof(data_fp)) { /* open temp file */ sprintf(tempfname,"temp%s\0",token); if ((temp_fp = fopen(tempfname, "w")) ==NULL) return(-3); strcat(tempnewlist,tempfname); strcat(tempnewlist," \0"); hcg_read_next(); /* read next line in data file */ idx = 0; hcg_parse(hcg_buffer,token,&idx); while (!feof(data_fp) && (strcmp(token,"LogDataFile") != 0)) { /* write buffer in temp file */ fprintf(temp_fp,"%s\n",hcg_buffer); hcg_read_next(); idx = 0; hcg_parse(hcg_buffer,token,&idx); } /* end while !feof loop */ fclose(temp_fp); hcg_parse(hcg_buffer,token,&idx); /* get filename */ } fclose(data_fp); strcpy(newlist,tempnewlist); return(0); } /************************************************************/ /* Function: del_tempfiles */ /* */ /* This function is used to delete the temporary files that */ /* were created during the replay session. */ /* */ /* Arguments: filelist - a list of files separated by */ /* commas. */ /************************************************************/ void del_tempfiles(char *filelist) { int idx = 0; char token[BUFSIZE]; while (idx < strlen(filelist)) { hcg_parse(filelist,token,&idx); #ifdef DEBUG printf("Unlinked %s.\n",token); #endif DEBUG unlink(token); } } /************************************************************/ /* Function: log_do_add */ /* */ /* This function is used to do the add given the viewname */ /* the tablename and a string of the additional information */ /* */ /* Arguments: view - the viewname */ /* tablename - the tablename of the record to */ /* be added. */ /* theRest - a string of the additional info */ /* of the record to be added */ /* Returns: 0 - success */ /* <0 - error with the add */ /* */ /* Genlog 96s523 */ /************************************************************/ int log_do_add(char *view, char *tablename, char *theRest) { int status = 0; /* the return status of the function */ int idx = 0; /* parsing temp index */ char pkey[HCG_KEY_SIZE+1]; int tablename_size; int tbl_encoding; #ifndef USE_STL struct SV *SV_elt; struct TT *TT_elt; struct TA *TA_elt; struct VV *VV_elt; struct TS *TS_elt; struct FO *FO_elt; struct GD *GD_elt; struct HG *HG_elt; struct HN *HN_elt; struct HA *HA_elt; struct HL *HL_elt; struct HP *HP_elt; struct HI *HI_elt; struct CG *CG_elt; struct GX *GX_elt; #else SV *SV_elt; TT *TT_elt; TA *TA_elt; VV *VV_elt; TS *TS_elt; FO *FO_elt; GD *GD_elt; HG *HG_elt; HN *HN_elt; HA *HA_elt; HL *HL_elt; HP *HP_elt; HI *HI_elt; CG *CG_elt; GX *GX_elt; #endif if (!find_tbl_idx(tablename)) { fprintf(stderr, "%s: %d: log_do_add: unknown table (%s) found in log\n", __FILE__, __LINE__, tablename); return -1; } tbl_encoding = encoding(hcg_table_seq_list[hcg_tbl_idx].ttabbrev); /* global hcg_tbl_idx is set by find_tbl_idx */ /* the following switch statement is adapted from the one in pr_parse */ switch( tbl_encoding ) { case 0: /* encoding of SV */ #ifndef USE_STL SV_elt = SV_elt->create_row(); #else SV_elt = new SV; #endif if (!SV_elt) fprintf(stderr,"%s: %d: do_log_add: pr_create failed\n", __FILE__, __LINE__); else SV_elt->log_do_add_row (view, theRest, idx); break; case 1: /* encoding of TT */ #ifndef USE_STL TT_elt = TT_elt->create_row(); #else TT_elt = new TT; #endif if (!TT_elt) fprintf(stderr,"%s: %d: do_log_add: pr_create failed\n", __FILE__, __LINE__); else TT_elt->log_do_add_row (view, theRest, idx); break; case 2: /* encoding of TA */ #ifndef USE_STL TA_elt = TA_elt->create_row(); #else TA_elt = new TA; #endif if (!TA_elt) fprintf(stderr,"%s: %d: do_log_add: pr_create failed\n", __FILE__, __LINE__); else TA_elt->log_do_add_row (view, theRest, idx); break; case 3: /* encoding of VV */ #ifndef USE_STL VV_elt = VV_elt->create_row(); #else VV_elt = new VV; #endif if (!VV_elt) fprintf(stderr,"%s: %d: do_log_add: pr_create failed\n", __FILE__, __LINE__); else VV_elt->log_do_add_row (view, theRest, idx); break; case 4: /* encoding of TS */ #ifndef USE_STL TS_elt = TS_elt->create_row(); #else TS_elt = new TS; #endif if (!TS_elt) fprintf(stderr,"%s: %d: do_log_add: pr_create failed\n", __FILE__, __LINE__); else TS_elt->log_do_add_row (view, theRest, idx); break; case 5: /* encoding of FO */ #ifndef USE_STL FO_elt = FO_elt->create_row(); #else FO_elt = new FO; #endif if (!FO_elt) fprintf(stderr,"%s: %d: do_log_add: pr_create failed\n", __FILE__, __LINE__); else FO_elt->log_do_add_row (view, theRest, idx); break; case 6: /* encoding of GD */ #ifndef USE_STL GD_elt = GD_elt->create_row(); #else GD_elt = new GD; #endif if (!GD_elt) fprintf(stderr,"%s: %d: do_log_add: pr_create failed\n", __FILE__, __LINE__); else GD_elt->log_do_add_row (view, theRest, idx); break; case 7: /* encoding of HG */ #ifndef USE_STL HG_elt = HG_elt->create_row(); #else HG_elt = new HG; #endif if (!HG_elt) fprintf(stderr,"%s: %d: do_log_add: pr_create failed\n", __FILE__, __LINE__); else HG_elt->log_do_add_row (view, theRest, idx); break; case 8: /* encoding of HN */ #ifndef USE_STL HN_elt = HN_elt->create_row(); #else HN_elt = new HN; #endif if (!HN_elt) fprintf(stderr,"%s: %d: do_log_add: pr_create failed\n", __FILE__, __LINE__); else HN_elt->log_do_add_row (view, theRest, idx); break; case 9: /* encoding of HA */ #ifndef USE_STL HA_elt = HA_elt->create_row(); #else HA_elt = new HA; #endif if (!HA_elt) fprintf(stderr,"%s: %d: do_log_add: pr_create failed\n", __FILE__, __LINE__); else HA_elt->log_do_add_row (view, theRest, idx); break; case 10: /* encoding of HL */ #ifndef USE_STL HL_elt = HL_elt->create_row(); #else HL_elt = new HL; #endif if (!HL_elt) fprintf(stderr,"%s: %d: do_log_add: pr_create failed\n", __FILE__, __LINE__); else HL_elt->log_do_add_row (view, theRest, idx); break; case 11: /* encoding of HP */ #ifndef USE_STL HP_elt = HP_elt->create_row(); #else HP_elt = new HP; #endif if (!HP_elt) fprintf(stderr,"%s: %d: do_log_add: pr_create failed\n", __FILE__, __LINE__); else HP_elt->log_do_add_row (view, theRest, idx); break; case 12: /* encoding of HI */ #ifndef USE_STL HI_elt = HI_elt->create_row(); #else HI_elt = new HI; #endif if (!HI_elt) fprintf(stderr,"%s: %d: do_log_add: pr_create failed\n", __FILE__, __LINE__); else HI_elt->log_do_add_row (view, theRest, idx); break; case 13: /* encoding of CG */ #ifndef USE_STL CG_elt = CG_elt->create_row(); #else CG_elt = new CG; #endif if (!CG_elt) fprintf(stderr,"%s: %d: do_log_add: pr_create failed\n", __FILE__, __LINE__); else CG_elt->log_do_add_row (view, theRest, idx); break; case 14: /* encoding of GX */ #ifndef USE_STL GX_elt = GX_elt->create_row(); #else GX_elt = new GX; #endif if (!GX_elt) fprintf(stderr,"%s: %d: do_log_add: pr_create failed\n", __FILE__, __LINE__); else GX_elt->log_do_add_row (view, theRest, idx); break; } } /************************************************************/ /* Function: convert2temp */ /* */ /* This function is used to convert an inputted string of */ /* datfiles separated by spaces to the filenames with the */ /* prefix 'temp'. Returns the string of altered names. */ /* */ /* Arguments: instr - string of size BUFSIZE that */ /* containts the string to add the */ /* temp infront of each word */ /* out - string that will place the */ /* altered string. */ /* Preconditions: */ /* instr must be a string of size BUFSIZE */ /* out must be a string of size BUFSIZE */ /************************************************************/ void convert2temp(char instr[BUFSIZE], char out[BUFSIZE]) { char token[BUFSIZE]; char outstr[BUFSIZE]; int idx = 0; if (strlen(instr)==0) { strcpy(out,"\0"); return; } /* get first token in string instr */ hcg_parse(instr,token,&idx); sprintf(outstr,"temp%s\0",token); /* get the rest of the tokens in the string instr */ hcg_parse(instr,token,&idx); while (idx < strlen(instr)) { char temp[BUFSIZE]; sprintf(temp," temp%s\0",token); strcat(outstr,temp); hcg_parse(instr,token,&idx); } strcpy(out,outstr); return; } /************************************************************/ /* Function: log_do_delete */ /* */ /* This function is used to delete a record given the pkey. */ /* */ /* Arguments: pkeychar - char string of the primary key. */ /************************************************************/ void log_do_delete(const char pkeychar[HCG_KEY_SIZE+1]) { char pkey[HCG_KEY_SIZE+1]; int tbl_encoding; strcpy(pkey,pkeychar); find_tbl_idx((char *)pkeychar); if(encode(pkey,&hcg_k) ==1) { #ifdef DEBUG printf("Found DL with pkey %s.\n",pkeychar); #endif DEBUG tbl_encoding = encoding(hcg_table_seq_list[hcg_tbl_idx].ttabbrev); switch(tbl_encoding) { case 0: /* SV table */ pr_find(SV, SVid, hcg_k); if (SVcurr == NULL) printf("log_delete: %s not found.\n", pkeychar); else SVcurr->delete_row(); break; case 1: /* TT table */ pr_find(TT, TTid, hcg_k); if (TTcurr == NULL) printf("log_delete: %s not found.\n", pkeychar); else TTcurr->delete_row(); break; case 2: /* TA table */ pr_find(TA, TAid, hcg_k); if (TAcurr == NULL) printf("log_delete: %s not found.\n", pkeychar); else TAcurr->delete_row(); break; case 3: /* VV table */ pr_find(VV, VVid, hcg_k); if (VVcurr == NULL) printf("log_delete: %s not found.\n", pkeychar); else VVcurr->delete_row(); break; case 4: /* TS table */ pr_find(TS, TSid, hcg_k); if (TScurr == NULL) printf("log_delete: %s not found.\n", pkeychar); else TScurr->delete_row(); break; case 5: /* FO table */ pr_find(FO, FOid, hcg_k); if (FOcurr == NULL) printf("log_delete: %s not found.\n", pkeychar); else FOcurr->delete_row(); break; case 6: /* GD table */ pr_find(GD, GDid, hcg_k); if (GDcurr == NULL) printf("log_delete: %s not found.\n", pkeychar); else GDcurr->delete_row(); break; case 7: /* HG table */ pr_find(HG, HGid, hcg_k); if (HGcurr == NULL) printf("log_delete: %s not found.\n", pkeychar); else HGcurr->delete_row(); break; case 8: /* HN table */ pr_find(HN, HNid, hcg_k); if (HNcurr == NULL) printf("log_delete: %s not found.\n", pkeychar); else HNcurr->delete_row(); break; case 9: /* HA table */ pr_find(HA, HAid, hcg_k); if (HAcurr == NULL) printf("log_delete: %s not found.\n", pkeychar); else HAcurr->delete_row(); break; case 10: /* HL table */ pr_find(HL, HLid, hcg_k); if (HLcurr == NULL) printf("log_delete: %s not found.\n", pkeychar); else HLcurr->delete_row(); break; case 11: /* HP table */ pr_find(HP, HPid, hcg_k); if (HPcurr == NULL) printf("log_delete: %s not found.\n", pkeychar); else HPcurr->delete_row(); break; case 12: /* HI table */ pr_find(HI, HIid, hcg_k); if (HIcurr == NULL) printf("log_delete: %s not found.\n", pkeychar); else HIcurr->delete_row(); break; case 13: /* CG table */ pr_find(CG, CGid, hcg_k); if (CGcurr == NULL) printf("log_delete: %s not found.\n", pkeychar); else CGcurr->delete_row(); break; case 14: /* GX table */ pr_find(GX, GXid, hcg_k); if (GXcurr == NULL) printf("log_delete: %s not found.\n", pkeychar); else GXcurr->delete_row(); break; } /* end switch */ } /* end if decode */ } /************************************************************/ /* Function: log_do_set_int */ /* */ /* This function is used to set the value of an int field. */ /* */ /* Created by : Rob Rassmann */ /* */ /* Creation Date : 12/12/98 */ /* */ /* Arguments: pkeychar - char string of the primary key. */ /* fieldname - char string of the changing field. */ /* newval - int value to be set. */ /************************************************************/ void log_do_set_int(const char pkeychar[HCG_KEY_SIZE+1],const char fieldname[NAMELENGTH+1], const int newval) { char pkey[HCG_KEY_SIZE+1]; int tbl_encoding, fld_encoding; strcpy(pkey,pkeychar); find_tbl_idx((char *)pkeychar); if(encode(pkey,&hcg_k) ==1) { #ifdef DEBUG printf("Found DL with pkey %s.\n",pkeychar); #endif DEBUG tbl_encoding = encoding(hcg_table_seq_list[hcg_tbl_idx].ttabbrev); switch(tbl_encoding) { case 0: /* SV table */ pr_find(SV, SVid, hcg_k); if (SVcurr == NULL) printf("log_do_set_int %s not found.\n", pkeychar); else SVcurr->log_do_set_int_row(fieldname, newval); break; case 1: /* TT table */ pr_find(TT, TTid, hcg_k); if (TTcurr == NULL) printf("log_do_set_int %s not found.\n", pkeychar); else TTcurr->log_do_set_int_row(fieldname, newval); break; case 2: /* TA table */ pr_find(TA, TAid, hcg_k); if (TAcurr == NULL) printf("log_do_set_int %s not found.\n", pkeychar); else TAcurr->log_do_set_int_row(fieldname, newval); break; case 3: /* VV table */ pr_find(VV, VVid, hcg_k); if (VVcurr == NULL) printf("log_do_set_int %s not found.\n", pkeychar); else VVcurr->log_do_set_int_row(fieldname, newval); break; case 4: /* TS table */ pr_find(TS, TSid, hcg_k); if (TScurr == NULL) printf("log_do_set_int %s not found.\n", pkeychar); else TScurr->log_do_set_int_row(fieldname, newval); break; case 5: /* FO table */ pr_find(FO, FOid, hcg_k); if (FOcurr == NULL) printf("log_do_set_int %s not found.\n", pkeychar); else FOcurr->log_do_set_int_row(fieldname, newval); break; case 6: /* GD table */ pr_find(GD, GDid, hcg_k); if (GDcurr == NULL) printf("log_do_set_int %s not found.\n", pkeychar); else GDcurr->log_do_set_int_row(fieldname, newval); break; case 7: /* HG table */ pr_find(HG, HGid, hcg_k); if (HGcurr == NULL) printf("log_do_set_int %s not found.\n", pkeychar); else HGcurr->log_do_set_int_row(fieldname, newval); break; case 8: /* HN table */ pr_find(HN, HNid, hcg_k); if (HNcurr == NULL) printf("log_do_set_int %s not found.\n", pkeychar); else HNcurr->log_do_set_int_row(fieldname, newval); break; case 9: /* HA table */ pr_find(HA, HAid, hcg_k); if (HAcurr == NULL) printf("log_do_set_int %s not found.\n", pkeychar); else HAcurr->log_do_set_int_row(fieldname, newval); break; case 10: /* HL table */ pr_find(HL, HLid, hcg_k); if (HLcurr == NULL) printf("log_do_set_int %s not found.\n", pkeychar); else HLcurr->log_do_set_int_row(fieldname, newval); break; case 11: /* HP table */ pr_find(HP, HPid, hcg_k); if (HPcurr == NULL) printf("log_do_set_int %s not found.\n", pkeychar); else HPcurr->log_do_set_int_row(fieldname, newval); break; case 12: /* HI table */ pr_find(HI, HIid, hcg_k); if (HIcurr == NULL) printf("log_do_set_int %s not found.\n", pkeychar); else HIcurr->log_do_set_int_row(fieldname, newval); break; case 13: /* CG table */ pr_find(CG, CGid, hcg_k); if (CGcurr == NULL) printf("log_do_set_int %s not found.\n", pkeychar); else CGcurr->log_do_set_int_row(fieldname, newval); break; case 14: /* GX table */ pr_find(GX, GXid, hcg_k); if (GXcurr == NULL) printf("log_do_set_int %s not found.\n", pkeychar); else GXcurr->log_do_set_int_row(fieldname, newval); break; } /* end switch */ } /* end if decode */ } /************************************************************/ /* Function: log_do_set_flt */ /* */ /* This function is used to set the value of an float field.*/ /* */ /* Created by : Rob Rassmann */ /* */ /* Creation Date : 12/12/98 */ /* */ /* Arguments: pkeychar - char string of the primary key. */ /* fieldname - char string of the changing field. */ /* newval - flt value to be set. */ /************************************************************/ void log_do_set_flt(const char pkeychar[HCG_KEY_SIZE+1], const char fieldname[NAMELENGTH+1], const float newval) { char pkey[HCG_KEY_SIZE+1]; int tbl_encoding, fld_encoding; strcpy(pkey,pkeychar); find_tbl_idx((char *)pkeychar); if(encode(pkey,&hcg_k) ==1) { #ifdef DEBUG printf("Found DL with pkey %s.\n",pkeychar); #endif DEBUG tbl_encoding = encoding(hcg_table_seq_list[hcg_tbl_idx].ttabbrev); switch(tbl_encoding) { case 0: /* SV table */ pr_find(SV, SVid, hcg_k); if (SVcurr == NULL) printf("log_do_set_flt %s not found.\n", pkeychar); else SVcurr->log_do_set_flt_row(fieldname, newval); break; case 1: /* TT table */ pr_find(TT, TTid, hcg_k); if (TTcurr == NULL) printf("log_do_set_flt %s not found.\n", pkeychar); else TTcurr->log_do_set_flt_row(fieldname, newval); break; case 2: /* TA table */ pr_find(TA, TAid, hcg_k); if (TAcurr == NULL) printf("log_do_set_flt %s not found.\n", pkeychar); else TAcurr->log_do_set_flt_row(fieldname, newval); break; case 3: /* VV table */ pr_find(VV, VVid, hcg_k); if (VVcurr == NULL) printf("log_do_set_flt %s not found.\n", pkeychar); else VVcurr->log_do_set_flt_row(fieldname, newval); break; case 4: /* TS table */ pr_find(TS, TSid, hcg_k); if (TScurr == NULL) printf("log_do_set_flt %s not found.\n", pkeychar); else TScurr->log_do_set_flt_row(fieldname, newval); break; case 5: /* FO table */ pr_find(FO, FOid, hcg_k); if (FOcurr == NULL) printf("log_do_set_flt %s not found.\n", pkeychar); else FOcurr->log_do_set_flt_row(fieldname, newval); break; case 6: /* GD table */ pr_find(GD, GDid, hcg_k); if (GDcurr == NULL) printf("log_do_set_flt %s not found.\n", pkeychar); else GDcurr->log_do_set_flt_row(fieldname, newval); break; case 7: /* HG table */ pr_find(HG, HGid, hcg_k); if (HGcurr == NULL) printf("log_do_set_flt %s not found.\n", pkeychar); else HGcurr->log_do_set_flt_row(fieldname, newval); break; case 8: /* HN table */ pr_find(HN, HNid, hcg_k); if (HNcurr == NULL) printf("log_do_set_flt %s not found.\n", pkeychar); else HNcurr->log_do_set_flt_row(fieldname, newval); break; case 9: /* HA table */ pr_find(HA, HAid, hcg_k); if (HAcurr == NULL) printf("log_do_set_flt %s not found.\n", pkeychar); else HAcurr->log_do_set_flt_row(fieldname, newval); break; case 10: /* HL table */ pr_find(HL, HLid, hcg_k); if (HLcurr == NULL) printf("log_do_set_flt %s not found.\n", pkeychar); else HLcurr->log_do_set_flt_row(fieldname, newval); break; case 11: /* HP table */ pr_find(HP, HPid, hcg_k); if (HPcurr == NULL) printf("log_do_set_flt %s not found.\n", pkeychar); else HPcurr->log_do_set_flt_row(fieldname, newval); break; case 12: /* HI table */ pr_find(HI, HIid, hcg_k); if (HIcurr == NULL) printf("log_do_set_flt %s not found.\n", pkeychar); else HIcurr->log_do_set_flt_row(fieldname, newval); break; case 13: /* CG table */ pr_find(CG, CGid, hcg_k); if (CGcurr == NULL) printf("log_do_set_flt %s not found.\n", pkeychar); else CGcurr->log_do_set_flt_row(fieldname, newval); break; case 14: /* GX table */ pr_find(GX, GXid, hcg_k); if (GXcurr == NULL) printf("log_do_set_flt %s not found.\n", pkeychar); else GXcurr->log_do_set_flt_row(fieldname, newval); break; } /* end switch */ } /* end if decode */ } /************************************************************/ /* Function: log_do_set_key */ /* */ /* This function is used to set the value of an key field. */ /* */ /* Created by : Rob Rassmann */ /* */ /* Creation Date : 12/12/98 */ /* */ /* Arguments: pkeychar - char string of the primary key. */ /* fieldname - char string of the changing field. */ /* newval - char string key value to be set.*/ /************************************************************/ void log_do_set_key(const char pkeychar[HCG_KEY_SIZE+1] ,const char fieldname[NAMELENGTH+1], const char newval[HCG_KEY_SIZE+1]) { char pkey[HCG_KEY_SIZE+1]; int tbl_encoding, fld_encoding; hcg_key new_key; strcpy(pkey,pkeychar); find_tbl_idx((char *)pkeychar); if(encode(pkey,&hcg_k) ==1) { #ifdef DEBUG printf("Found DL with pkey %s.\n",pkeychar); #endif DEBUG if(encode((char *)newval,&new_key) ==1) { #ifdef DEBUG printf("Found DL with key %s.\n",fieldname); #endif DEBUG tbl_encoding = encoding(hcg_table_seq_list[hcg_tbl_idx].ttabbrev); switch(tbl_encoding) { case 0: /* SV table */ pr_find(SV, SVid, hcg_k); if (SVcurr == NULL) printf("log_do_set_key %s not found.\n", pkeychar); else SVcurr->log_do_set_key_row(fieldname, new_key); break; case 1: /* TT table */ pr_find(TT, TTid, hcg_k); if (TTcurr == NULL) printf("log_do_set_key %s not found.\n", pkeychar); else TTcurr->log_do_set_key_row(fieldname, new_key); break; case 2: /* TA table */ pr_find(TA, TAid, hcg_k); if (TAcurr == NULL) printf("log_do_set_key %s not found.\n", pkeychar); else TAcurr->log_do_set_key_row(fieldname, new_key); break; case 3: /* VV table */ pr_find(VV, VVid, hcg_k); if (VVcurr == NULL) printf("log_do_set_key %s not found.\n", pkeychar); else VVcurr->log_do_set_key_row(fieldname, new_key); break; case 4: /* TS table */ pr_find(TS, TSid, hcg_k); if (TScurr == NULL) printf("log_do_set_key %s not found.\n", pkeychar); else TScurr->log_do_set_key_row(fieldname, new_key); break; case 5: /* FO table */ pr_find(FO, FOid, hcg_k); if (FOcurr == NULL) printf("log_do_set_key %s not found.\n", pkeychar); else FOcurr->log_do_set_key_row(fieldname, new_key); break; case 6: /* GD table */ pr_find(GD, GDid, hcg_k); if (GDcurr == NULL) printf("log_do_set_key %s not found.\n", pkeychar); else GDcurr->log_do_set_key_row(fieldname, new_key); break; case 7: /* HG table */ pr_find(HG, HGid, hcg_k); if (HGcurr == NULL) printf("log_do_set_key %s not found.\n", pkeychar); else HGcurr->log_do_set_key_row(fieldname, new_key); break; case 8: /* HN table */ pr_find(HN, HNid, hcg_k); if (HNcurr == NULL) printf("log_do_set_key %s not found.\n", pkeychar); else HNcurr->log_do_set_key_row(fieldname, new_key); break; case 9: /* HA table */ pr_find(HA, HAid, hcg_k); if (HAcurr == NULL) printf("log_do_set_key %s not found.\n", pkeychar); else HAcurr->log_do_set_key_row(fieldname, new_key); break; case 10: /* HL table */ pr_find(HL, HLid, hcg_k); if (HLcurr == NULL) printf("log_do_set_key %s not found.\n", pkeychar); else HLcurr->log_do_set_key_row(fieldname, new_key); break; case 11: /* HP table */ pr_find(HP, HPid, hcg_k); if (HPcurr == NULL) printf("log_do_set_key %s not found.\n", pkeychar); else HPcurr->log_do_set_key_row(fieldname, new_key); break; case 12: /* HI table */ pr_find(HI, HIid, hcg_k); if (HIcurr == NULL) printf("log_do_set_key %s not found.\n", pkeychar); else HIcurr->log_do_set_key_row(fieldname, new_key); break; case 13: /* CG table */ pr_find(CG, CGid, hcg_k); if (CGcurr == NULL) printf("log_do_set_key %s not found.\n", pkeychar); else CGcurr->log_do_set_key_row(fieldname, new_key); break; case 14: /* GX table */ pr_find(GX, GXid, hcg_k); if (GXcurr == NULL) printf("log_do_set_key %s not found.\n", pkeychar); else GXcurr->log_do_set_key_row(fieldname, new_key); break; } /* end switch */ } /* end if decode of fieldname */ } /* end if decode of pkey */ } /***************************************************************/ /* Function: log_do_set_str */ /* */ /* This function is used to set the value of an string field. */ /* */ /* Created by : Rob Rassmann */ /* */ /* Creation Date : 12/12/98 */ /* */ /* Arguments: pkeychar - char string of the primary key. */ /* fieldname - char string of the changing field. */ /* newval - char string value to be set. */ /***************************************************************/ void log_do_set_str(const char pkeychar[HCG_KEY_SIZE+1],const char fieldname[NAMELENGTH+1],const char newval[BUFSIZE+1]) { char pkey[HCG_KEY_SIZE+1]; int tbl_encoding, fld_encoding; strcpy(pkey,pkeychar); find_tbl_idx((char *)pkeychar); if(encode(pkey,&hcg_k) ==1) { #ifdef DEBUG printf("Found DL with pkey %s.\n",pkeychar); #endif DEBUG tbl_encoding = encoding(hcg_table_seq_list[hcg_tbl_idx].ttabbrev); switch(tbl_encoding) { case 0: /* SV table */ pr_find(SV, SVid, hcg_k); if (SVcurr == NULL) printf("log_do_set_str %s not found.\n", pkeychar); else SVcurr->log_do_set_str_row(fieldname, newval); break; case 1: /* TT table */ pr_find(TT, TTid, hcg_k); if (TTcurr == NULL) printf("log_do_set_str %s not found.\n", pkeychar); else TTcurr->log_do_set_str_row(fieldname, newval); break; case 2: /* TA table */ pr_find(TA, TAid, hcg_k); if (TAcurr == NULL) printf("log_do_set_str %s not found.\n", pkeychar); else TAcurr->log_do_set_str_row(fieldname, newval); break; case 3: /* VV table */ pr_find(VV, VVid, hcg_k); if (VVcurr == NULL) printf("log_do_set_str %s not found.\n", pkeychar); else VVcurr->log_do_set_str_row(fieldname, newval); break; case 4: /* TS table */ pr_find(TS, TSid, hcg_k); if (TScurr == NULL) printf("log_do_set_str %s not found.\n", pkeychar); else TScurr->log_do_set_str_row(fieldname, newval); break; case 5: /* FO table */ pr_find(FO, FOid, hcg_k); if (FOcurr == NULL) printf("log_do_set_str %s not found.\n", pkeychar); else FOcurr->log_do_set_str_row(fieldname, newval); break; case 6: /* GD table */ pr_find(GD, GDid, hcg_k); if (GDcurr == NULL) printf("log_do_set_str %s not found.\n", pkeychar); else GDcurr->log_do_set_str_row(fieldname, newval); break; case 7: /* HG table */ pr_find(HG, HGid, hcg_k); if (HGcurr == NULL) printf("log_do_set_str %s not found.\n", pkeychar); else HGcurr->log_do_set_str_row(fieldname, newval); break; case 8: /* HN table */ pr_find(HN, HNid, hcg_k); if (HNcurr == NULL) printf("log_do_set_str %s not found.\n", pkeychar); else HNcurr->log_do_set_str_row(fieldname, newval); break; case 9: /* HA table */ pr_find(HA, HAid, hcg_k); if (HAcurr == NULL) printf("log_do_set_str %s not found.\n", pkeychar); else HAcurr->log_do_set_str_row(fieldname, newval); break; case 10: /* HL table */ pr_find(HL, HLid, hcg_k); if (HLcurr == NULL) printf("log_do_set_str %s not found.\n", pkeychar); else HLcurr->log_do_set_str_row(fieldname, newval); break; case 11: /* HP table */ pr_find(HP, HPid, hcg_k); if (HPcurr == NULL) printf("log_do_set_str %s not found.\n", pkeychar); else HPcurr->log_do_set_str_row(fieldname, newval); break; case 12: /* HI table */ pr_find(HI, HIid, hcg_k); if (HIcurr == NULL) printf("log_do_set_str %s not found.\n", pkeychar); else HIcurr->log_do_set_str_row(fieldname, newval); break; case 13: /* CG table */ pr_find(CG, CGid, hcg_k); if (CGcurr == NULL) printf("log_do_set_str %s not found.\n", pkeychar); else CGcurr->log_do_set_str_row(fieldname, newval); break; case 14: /* GX table */ pr_find(GX, GXid, hcg_k); if (GXcurr == NULL) printf("log_do_set_str %s not found.\n", pkeychar); else GXcurr->log_do_set_str_row(fieldname, newval); break; } /* end switch */ } /* end if decode */ } /************************************************************/ /* Function:replay_log */ /* */ /* This function is used to parse the logfile and execute */ /* the action of the log entry. */ /* */ /* Arguments: logfile - logfile to replay */ /* near_realtime - flag indicates to */ /* replay in near realtime */ /* 0 = not real time */ /* 1 = real time */ /* Return values: */ /* 0 - success parsing and replay */ /* -3 - cannot open file */ /* -5 - incorrect logfile format */ /* Effects: /* hcg_buffer - altered /* hcg_ascii_fp - altered /* hcg_t - altered /* value of database may be altered based on the error in */ /* the format of the data file. If no SP was found, */ /* the replay will be done already. */ /************************************************************/ int replay_log(char logfile[NAMELENGTH],int near_realtime) { int idx; char token[BUFSIZE]; FILE *logfile_fp; /* check variables */ if ((near_realtime != 1) && (near_realtime !=0)) printf("replay_log: warning invalid value of near_realtime %d.\n",near_realtime); /* open the log file */ if ((logfile_fp = fopen(logfile, "r")) ==NULL) { hcg_log = 0; return(-3); } hcg_ascii_fp = logfile_fp; idx = 0; hcg_read_next(); /* read first line of log file */ /* check logfile header format */ hcg_parse(hcg_buffer,token,&idx); if (strcmp(token, "SR")!=0) { fclose(logfile_fp); return(-5); /* log file is not opend with SR entry */ } #ifdef DEBUG printf("Found SR\n"); #endif DEBUG hcg_read_next(); while (!feof(hcg_ascii_fp)) { idx = 0; hcg_parse(hcg_buffer,token,&idx); if (strcmp(token,"LD") == 0) { char logviewname[NAMELENGTH]; char datafile[NAMELENGTH]; char newdatafile[NAMELENGTH]; hcg_parse(hcg_buffer,logviewname,&idx); hcg_parse(hcg_buffer,datafile,&idx); sprintf(newdatafile,"temp%s\0",datafile); #ifdef DEBUG printf("Found LD: viewname:%s,datafile:%s.\n",logviewname,newdatafile); #endif DEBUG pr_load(logviewname,newdatafile); hcg_ascii_fp = logfile_fp; /* reset the file pointer */ hcg_read_next(); continue; } if (strcmp(token, "SP") == 0) { hcg_read_next(); #ifdef DEBUG printf("Found SP\n"); #endif DEBUG if (feof(hcg_ascii_fp)) { fclose(logfile_fp); return(0); /* successful completion of log parsing */ } else { fclose(logfile_fp); return(-5); /* log file has stuff after the SP entry */ } } if (strcmp(token,"WA") == 0) { char temp[BUFSIZE]; int totMsec; /* get the wait times */ hcg_parse(hcg_buffer,temp,&idx); /* convert seconds and milliseconds to milliseconds */ totMsec = atoi(temp); #ifdef DEBUG printf("Found WA with total milliseconds %d.\n",totMsec); #endif DEBUG /* must do the wait */ if ((near_realtime ==1)&& (totMsec > 0)) log_sleep(totMsec); hcg_read_next(); continue; } if (strcmp(token,"IN") == 0) { char viewname[NAMELENGTH],datalist[BUFSIZE],temp[BUFSIZE],tempdatalist[BUFSIZE]; hcg_parse(hcg_buffer,viewname,&idx); hcg_parse(hcg_buffer,temp,&idx); strcpy(datalist,strstr(hcg_buffer, temp)); convert2temp(datalist,tempdatalist); #ifdef DEBUG printf("Found IN with viewname %s, datalist=%s.\n",viewname,temp); #endif DEBUG pr_init(viewname,tempdatalist); hcg_ascii_fp = logfile_fp; /* reset the file pointer */ hcg_read_next(); continue; } if (strcmp(token,"DL") == 0) { char temp[HCG_KEY_SIZE+1]; hcg_parse(hcg_buffer,temp,&idx); log_do_delete(temp); hcg_read_next(); continue; } if (strcmp(token,"PR_SET_INT") == 0) { char temp_tbl[HCG_KEY_SIZE+1]; char temp_field[NAMELENGTH+1]; char temp_newval[BUFSIZE+1]; int temp_newint; hcg_parse(hcg_buffer,temp_tbl,&idx); hcg_parse(hcg_buffer,temp_field,&idx); hcg_parse(hcg_buffer,temp_newval,&idx); temp_newint = atoi(temp_newval); log_do_set_int(temp_tbl,temp_field,temp_newint); hcg_read_next(); continue; } if (strcmp(token,"PR_SET_FLT") == 0) { char temp_tbl[HCG_KEY_SIZE+1]; char temp_field[NAMELENGTH+1]; char temp_newval[BUFSIZE+1]; float temp_newflt; hcg_parse(hcg_buffer,temp_tbl,&idx); hcg_parse(hcg_buffer,temp_field,&idx); hcg_parse(hcg_buffer,temp_newval,&idx); temp_newflt = atof(temp_newval); log_do_set_flt(temp_tbl,temp_field,temp_newflt); hcg_read_next(); continue; } if (strcmp(token,"PR_SET_KEY") == 0) { char temp_tbl[HCG_KEY_SIZE+1]; char temp_field[NAMELENGTH+1]; char temp_newkey[HCG_KEY_SIZE+1]; hcg_parse(hcg_buffer,temp_tbl,&idx); hcg_parse(hcg_buffer,temp_field,&idx); hcg_parse(hcg_buffer,temp_newkey,&idx); log_do_set_key(temp_tbl,temp_field,temp_newkey); hcg_read_next(); continue; } if (strcmp(token,"PR_SET_STR") == 0) { char temp_tbl[HCG_KEY_SIZE+1]; char temp_field[NAMELENGTH+1]; char temp_newstr[BUFSIZE+1]; hcg_parse(hcg_buffer,temp_tbl,&idx); hcg_parse(hcg_buffer,temp_field,&idx); hcg_parse(hcg_buffer,temp_newstr,&idx); log_do_set_str(temp_tbl,temp_field,temp_newstr); hcg_read_next(); continue; } if (strcmp(token,"FR") == 0) { #ifdef DEBUG printf("Found FR.\n"); #endif DEBUG pr_free(); hcg_read_next(); continue; } if (strcmp(token,"VN") == 0) { char viewname[NAMELENGTH]; hcg_parse(hcg_buffer,viewname,&idx); #ifdef DEBUG printf("Found VN with viewname %s.\n",viewname); #endif DEBUG strcpy(hcg_viewname,viewname); hcg_read_next(); continue; } { char temppkey[BUFSIZE],temp[BUFSIZE], *addlist; int tbl_encoding; strcpy(temppkey,token); hcg_parse(hcg_buffer,temp,&idx); addlist = (char *)strstr(hcg_buffer, temp); if (find_tbl_idx(temppkey)==0) { #ifdef DEBUG printf("Unknown format: skipping \n"); #endif DEBUG hcg_read_next(); continue; } #ifdef DEBUG printf("Found Add with pkey %s, rest %s.\n",temppkey,addlist); #endif DEBUG log_do_add(hcg_viewname,hcg_table_seq_list[hcg_tbl_idx].ttabbrev,addlist); hcg_read_next(); continue; } } /* end while !feof */ fclose(logfile_fp); return(-5); /* log file is not closed with SP entry */ } /************************************************************/ /* Function: pr_replay */ /* */ /* This function is used to replay a logsession based on */ /* a log file. It will destroy the current database, */ /* replace the DB from the start of the log session, */ /* reproduce the DB modifications based on the logfile. */ /* */ /* Arguments: view - the viewname of the log session */ /* logfile - the name of the logfile to replay */ /* near_realtime - a boolean flag indicating if */ /* the replay should approx realtime */ /* 0 - no near_realtime playback */ /* 1 - playback in near-realtime */ /* take_endsnapshot - a boolean flag indicating if the */ /* database should be dumped at the */ /* end of the replay. */ /* 0 - do not take the end DB snapshot */ /* 1 - take the end DB snapshot */ /* Return values: */ /* 0 - success */ /* -1 - Replay error - null view name */ /* -2 - Replay error - null log file */ /* -3 - Replay error - unable to open file */ /* -4 - Replay error - log session in progress */ /* -5 - Replay error - incorrect log file format */ /* */ /************************************************************/ int pr_replay(char *view, char logfile[NAMELENGTH], int near_realtime, int take_endsnapshot) { FILE *log_fp; char filelist[BUFSIZE], tempfilelist[BUFSIZE],tempvar[BUFSIZE], logfiledb[NAMELENGTH]; int retval; if (hcg_log ==1 ) { printf("pr_replay error: logging in progress\n"); return(-4); } /* set replay to be on & save logfilename*/ hcg_log = 2; strcpy(hcg_logfile,logfile); /* validate the arguments */ if (view == NULL) { printf("pr_replay error: null view name\n"); hcg_log = 0; return(-1); } if (logfile == NULL) { printf("pr_replay error: null log file\n"); hcg_log = 0; return(-2); } /* free the existing database */ if (hcg_initialized) { pr_free(); } /* generate the data files */ strtok(logfile,"."); sprintf(logfiledb,"%sDB1.dat",logfile); log_parselogdata(tempfilelist); sprintf(filelist,"%s %s\0",tempfilelist, logfiledb); /* initialize & load the database */ pr_init("enroll.viewdefs",filelist); pr_load(view,logfiledb); /* replay the log */ if ((retval = replay_log(hcg_logfile,near_realtime)) != 0) { return(retval); } /* take final snapshot */ if (take_endsnapshot==1) { sprintf(tempvar,"%sDB3.dat",logfile); pr_dump(view, tempvar,0,"w"); } /* delete interim datafiles */ del_tempfiles(tempfilelist); hcg_log = 0; return (0); }