/* * * *.NAME * * dwoutex1.c * *.TITLE * * Extract Outmod * *.AUTHOR * * Wayne Moran * *.DATE * * 06/01/2000 * *.WHAT * * This program will write the data that is passed to it from * * a fast export to 1 output file. * *.HOW * * This program gets the output file name from the environment * * variarable outmod_file_name * *.ENTRY * * _dynamn * *.PARAMETERS * * entrytype,stmtno,resplen,resprec,outlen,outrec * *.EXIT * * N/A * *.RETURN * * N/A * * * ************************************************************************* */ #include #include #include #include #include struct in_struct { char FIELD1 [2048]; }; struct out_rec { char FIELD1 [2049]; }; /* File Pointers containing information about an open file */ FILE *file1_fp; #define EQUAL 0 #define NUM_OF_RCDS_WRITTEN 1 #define BAD_OPEN 50 #define BAD_WRITE 52 #define FILE_CTR 1 /* Entry Point into Program dwoutex1.c */ int _dynamn(entrytype, stmtno, resplen, resprec, outlen, outrec) /* Fastexport passes parameters by reference that is the address of the value rather than the value itself */ /* Declaring Fastexport parameters as pointers */ int *entrytype; int *stmtno; int *resplen; struct in_struct *resprec; int *outlen; char *outrec; /* Start of Program */ { /* Declaring output file pointer structures */ struct out_rec out_dtl ; struct out_rec *out_dtl_ptr = &out_dtl; char fname [150]; /* Declaring static variables to keep for life of program */ static int Record_Size = 0; static int File_Size = 0; static int Num_Files = 0; static unsigned long int tot_record_ctr = 0; /* Case on entrytype */ switch(*entrytype) /* start of switch for entrytype */ { /* entrytype = 1 : Normal Start */ /* entrytype = 6 : Host restart same as normal since there are no checkpoints */ case 1: case 6: /* Open output file1 for the fast export data */ strcpy(fname,getenv( "outmod_file_name" )); if ((file1_fp=fopen(fname,"w")) == NULL) { fprintf(stderr,"%s %d:Bad Open on file <%s>,errno=%d\n", __FILE__,__LINE__,fname,errno); fflush(stderr); dw_kill_parnt_child(); exit(BAD_OPEN); } break; /* entrytype = 2 EOF for response data */ case 2: /* file1 is the fast export data */ fclose(file1_fp); printf("\nThe extract is done \n"); printf("\nTotal outmod_records Written: %d \n",tot_record_ctr); break; /* entrytype = 3 : Response row entry */ case 3: /* Process data */ Record_Size=*resplen; File_Size=Record_Size+1; /* need newline character added to end for UNIX */ *resplen = 0; /* create the output file */ memcpy(out_dtl_ptr->FIELD1,resprec->FIELD1, Record_Size); out_dtl_ptr->FIELD1[Record_Size] = '\n'; /* Write output record to disk */ if ( fwrite(out_dtl_ptr,File_Size,1,file1_fp) != NUM_OF_RCDS_WRITTEN ) { fprintf(stderr,"%s %d:Bad Write on file <%s>,errno=%d\n", __FILE__,__LINE__,fname,errno); perror(fname); fflush(stderr); dw_kill_parnt_child(); exit(BAD_WRITE); } tot_record_ctr++; break; /* entrytype = 4 : No checkpoints to worry about */ case 4: break; /* entrytype = 5 : DBC restart - close and reopen the output files */ case 5: if ((file1_fp=freopen(fname,"w",file1_fp)) == NULL) { fprintf(stderr,"%s %d:Bad ReOpen on file <%s>,errno=%d\n", __FILE__,__LINE__,fname,errno); fflush(stderr); dw_kill_parnt_child(); exit(BAD_OPEN); } break; /* Invalid entrytype passed from the Fastexport Utility */ default: fprintf(stderr,"Fastexport Entry code = %d is invalid \n", *entrytype); fflush(stderr); dw_kill_parnt_child(); exit(99); break; /* End of switch for entrytype */ } return(0); /* End of program */ }