/*------------------------------------------------------------------------- ** This program will read a weekly APS (Green Book Lite) ftp'd data file with ** 81-character records which include a terminating line feed in position 81, ** and create an output fms file and the corresponding report file. ** ** It's adapted from the older issue.c code for creating the same file from ** the old stream data on 6250 bpi mag tapes. All the mods were in the ** read_rec routine. ** ** Created : 9/2/97 ll ** ** File Name : lf2fms.c ** **------------------------------------------------------------------------- */ #include #include #include #include #include #include #include #include "istruc.h" #include "ivar.h" #include "iprot.h" FILE *pIn=NULL; FILE *pFms=NULL; FILE *out = NULL; char patent [ 20 ], patent_old [ 20 ], type [ 20 ], /* patent type ("D", "RE" ) */ type_old [ 20 ], word1[20], word2[20], word3[20], word4[20]; char pat_type [ 6 ] [ 10 ], pat_first [ 6 ] [ 10 ], pat_last [ 6 ] [ 10 ]; long pat_cnt [ 6 ], pat_mis [ 6 ], pat_num, pat_num_old, diff; int patent_types_encountered = 0; int ii; long type_count = 0, total_count = 0; char rpt_path [ 80 ]; /*------------------------------------------------------------------------*/ void main ( int argc, char **argv ) { int good,bad=0; abstflg=0; number_of_patents=0; first=1; if ( argc == 4 ) { strcpy ( dat_path, argv[1] ); strcpy ( fms_path, argv[2] ); strcpy ( rpt_path, argv[3] ); good = 2; } else { fprintf ( stderr, "%s input fms rpt\n", argv[0] ); good = getpath(); } bad = openall(); if (bad) { fprintf ( stderr, "\nCould not open %d files as listed above",bad); exit(0); } fprintf( stderr, "\nStarting the DATA transfer NOW *****\n"); if (good) good = get_header(); if (!good) printf("\n\n BAD REPORT FROM GET HEADER REC ******$$$$$ "); while(finish!=EOF) {if(strncmp(tape_rec.fullrec,"PATN",4)==0) good=process_patn(); else if(strncmp(tape_rec.fullrec,"INVT",4)==0) good=process_invt(); else if(strncmp(tape_rec.fullrec,"ASSG",4)==0) good=process_assg(); else if(strncmp(tape_rec.fullrec,"CLAS",4)==0) good=process_clas(); else if(strncmp(tape_rec.fullrec,"ABST",4)==0) good=process_abst(); else { while(!(check_main_tags())) {;} } /* end last else */ } /* end WHILE !finish */ /* if (!abstflg) ix=write_fms(); */ fclose(pFms); fclose(pIn); printf ( "Last %-2s patent is %s (%d patents)\n", type_old, patent_old, type_count ); fprintf ( out, "Last %-2s patent is %s (%d patents)\n", type_old, patent_old, type_count ); sprintf ( pat_last[patent_types_encountered], "%s", patent_old ); patent_types_encountered++; printf ( "TOTAL %ld patents in file %s.\n", total_count, dat_path ); fprintf ( out, "TOTAL %ld patents in file %s.\n\n", total_count, dat_path ); printf("\n The total number of PATENT files written is : %d", number_of_patents); fprintf ( out, "\n\nSUMMARY\n\n" ); fprintf ( out, "%5s %8s %8s %8s %8s %8s\n", "Type", "First", "Last", "Count", "Missing", "Total" ); printf ( "\n\nSUMMARY\n" ); printf ( "%5s %8s %8s %8s %8s %8s\n", "Type", "First", "Last", "Count", "Missing", "Total" ); sprintf ( pat_type[patent_types_encountered], "TOTAL" ); pat_first[patent_types_encountered][0] = 0; pat_last[patent_types_encountered][0] = 0; pat_cnt[patent_types_encountered] = 0; pat_mis[patent_types_encountered] = 0; for ( ii = 0; ii <= patent_types_encountered; ii++ ) { fprintf ( out, "%5s %8s %8s %8ld %8ld %8ld\n", pat_type[ii], pat_first[ii], pat_last[ii], pat_cnt[ii], pat_mis[ii], pat_cnt[ii] + pat_mis[ii] ); printf ( "%5s %8s %8s %8ld %8ld %8ld\n", pat_type[ii], pat_first[ii], pat_last[ii], pat_cnt[ii], pat_mis[ii], pat_cnt[ii] + pat_mis[ii] ); pat_cnt [patent_types_encountered] += pat_cnt[ii]; pat_mis [patent_types_encountered] += pat_mis[ii]; } } /* end main */ /*------------------------------------------------------------------------*/ int getpath() { /* int i; */ char c; fflush(stdin); fflush(stdin); c='N'; while((c!='Y')&&(c!='y')) { printf("\n\n Enter a path for the input file eg c:\\prep\\dat\\filename "); printf("\nPath ="); gets(dat_path); printf("\nINPUT file name = %s",dat_path); printf("\n Is this correct ?? (enter Y=yes N=no) = "); c=getchar(); fflush(stdin); } fflush(stdin); c='N'; while((c!='Y')&&(c!='y')) { printf("\n\n Enter a path for the output file eg c:\\prep\\filename"); printf("\nPath ="); gets(fms_path); printf("\nINPUT file name = %s",fms_path); printf("\n Is this correct ?? (enter Y=yes N=no) = "); c=getchar(); fflush(stdin); } fflush(stdin); c='N'; while((c!='Y')&&(c!='y')) { printf("\n\n Enter a path for the report file eg c:\\prep\\filename"); printf("\nPath ="); gets(rpt_path); printf("\nINPUT file name = %s",rpt_path); printf("\n Is this correct ?? (enter Y=yes N=no) = "); c=getchar(); fflush(stdin); } fflush(stdin); return(1); } /* end getpath */ /*------------------------------------------------------------------------*/ int openall() { rtncode=0; if ((pIn=fopen(dat_path,"r")) == NULL) {printf("\nCAN'T OPEN INPUT FILE ####### %s\n",dat_path); rtncode++; } if ((pFms=fopen(fms_path,"a+t")) == NULL) {printf("CAN'T OPEN OUTPUT FILE ******* %s\n",fms_path); rtncode++; } else {fprintf(pFms," WEEKLY PATENT ISSUES FILE \n"); } if ((out=fopen(rpt_path,"a+t")) == NULL) { fprintf(stderr,"CAN'T OPEN REPORT FILE ******* %s\n",rpt_path); } return(rtncode); } /* end openall */ /*------------------------------------------------------------------------*/ int get_header() { /* int i; */ sucess=0; while((strncmp(tape_rec.header.headertag,"HHHHH",5)!=0)&&(sucess != EOF)) {sucess = read_rec();} sucess=read_rec(); while(!sucess) /* 11/23/93 added while to the read */ {sucess=read_rec();} fsize=0; return(sucess); } /*------------------------------------------------------------------------*/ int read_rec() /* read an 81-character, line feed-terminated record */ { int i,last=0; int bytes_read; for(i=0;i<81;i++) /* initialize input array */ tape_rec.fullrec[i] = ' '; tape_rec.fullrec[0] = '\0'; while(strlen(tape_rec.fullrec)==0) /* read 81 character record */ { fgets ( tape_rec.fullrec, 81, pIn ); bytes_read = strlen ( tape_rec.fullrec ); if ( bytes_read == NULL ) { finish = EOF; /* printf("\n\n GOT EOF in read_rec ******$$$$$ finish=%d",finish); */ return(EOF); } if ( bytes_read != 81 ) fprintf ( stderr, "%d bytes\r", bytes_read ); for(i=0;i<80;i++) /* find end of data in line. ignore char 81, which must be a \n. */ { if (tape_rec.fullrec[i]=='\n') tape_rec.fullrec[i]='\0'; if (tape_rec.fullrec[i] != ' ') last = i; } } tape_rec.fullrec[++last]='\0'; return(strlen(tape_rec.fullrec)); } /* end read_rec */ /*------------------------------------------------------------------------*/ int process_patn() { int i,ttl=0; /* char title_as[81]; */ number_of_patents++; if(first) {assignee_flag=0; first=0; clearit(); } abstflg=0; ttl=0; fprintf(pFms,"\n"); while(!(check_main_tags())) {memset(&fms.full,' ',80); fms.full[0]='\0'; if(strncmp(tape_rec.subrec.tag,"WKU ",4)==0) {ch=tape_rec.subrec.info[0]; if (ch=='0') memmove(&tape_rec.subrec.info[0],&tape_rec.subrec.info[1],7); else if ((ch=='P')||(ch=='T')||(ch=='R')||(ch=='H')) memmove(&tape_rec.subrec.info[2],&tape_rec.subrec.info[3],5); else if (ch=='D') memmove(&tape_rec.subrec.info[1],&tape_rec.subrec.info[2],6); else { printf("\n\ninvalid patent number"); exit(0); } tape_rec.subrec.info[7]='\0'; strncat(fms.full,"PATENT NUMBER = ",16); fms.full[16]='\0'; strncat(fms.full,tape_rec.subrec.info,8); fprintf ( pFms, "%s\n",fms.full); /* printf("\n\n writing patent number =%s",tape_rec.subrec.info ); */ strncpy ( patent, tape_rec.subrec.info, 8 ); patent[8] = 0; /* for ( ii = 0; patent[ii] > '0'; ii++ ); strcpy ( patent+ii, patent+ii+1 ); */ for ( ii = 0; patent[ii] > '9'; ii++ ); strncpy ( type, patent, ii ); type[ii] = 0; pat_num = atol ( patent+ii ); if ( number_of_patents == 1 ) { printf ( "First %-2s patent is %s\n", type, patent ); fprintf ( out, "First %-2s patent is %s\n", type, patent ); sprintf ( pat_type[0], "%s", type ); sprintf ( pat_first[0], "%s", patent ); pat_cnt[0] = 1; pat_mis[0] = 0; type_count = 1; total_count = 1; } else { total_count++; if ( total_count % 1 == 0 ) printf ( " %ld patent is %s\r", total_count, patent ); if ( strcmp ( type, type_old ) != 0 ) { printf ( "Last %-2s patent is %s (%ld patents)\n", type_old, patent_old, type_count ); fprintf ( out, "Last %-2s patent is %s (%ld patents)\n", type_old, patent_old, type_count ); sprintf ( pat_last[patent_types_encountered], "%s", patent_old ); patent_types_encountered++; sprintf ( pat_type [patent_types_encountered], "%s", type ); sprintf ( pat_first [patent_types_encountered], "%s", patent ); pat_cnt [ patent_types_encountered ] = 1; pat_mis [ patent_types_encountered ] = 0; printf ( "First %-2s patent is %s\n", type, patent ); fprintf ( out, "First %-2s patent is %s\n", type, patent ); type_count = 1; } else { type_count++; pat_cnt [ patent_types_encountered ] ++; diff = pat_num - pat_num_old; if ( diff != 1L ) { if ( diff == 2L ) { printf ( "Patent %s%ld is not in file %s.\n", type, pat_num-1, dat_path ); fprintf ( out, "Patent %s%ld is not in file %s.\n", type, pat_num-1, dat_path ); pat_mis [ patent_types_encountered ] ++; } else { printf ( "ERROR: Gap of %ld patents from %s to %s\n", diff-1, patent_old, patent ); fprintf ( out, "ERROR: Gap of %ld patents from %s to %s\n", diff-1, patent_old, patent ); pat_mis [ patent_types_encountered ] += diff - 1; } } } } strcpy ( patent_old, patent ); strcpy ( type_old, type ); pat_num_old = pat_num; } /* end if WKU */ if((strncmp(tape_rec.subrec.tag,"TTL ",4)==0) || ((ttl)&&(!subtag()))) {if (!ttl) strcat(fms.full,"TITLE = "); i=strlen(tape_rec.fullrec); /* was 3 */ memmove(&tape_rec.fullrec[0],&tape_rec.fullrec[5],(i-5)); tape_rec.fullrec[i-5]='\0'; ttl=1; strncat(fms.full,tape_rec.fullrec,strlen(tape_rec.fullrec)); fprintf(pFms,"%s\n",fms.full); } if(strncmp(tape_rec.subrec.tag,"ISD ",4)==0) {ttl=0; convert_date(); day_date(); strncat(fms.full,"ISSUE DATE = ",13); fms.full[14]='\0'; strncat(fms.full,dates,9); fprintf(pFms,"%s\n",fms.full); } } /* end while */ return(0); } /*------------------------------------------------------------------------*/ int check_main_tags() { char group_tags[21][5]= {"XXXX","PATN","INVT","ASSG","PRIR","REIS","RLAP","CLAS","UREF","FREF","OREF", "LREP","PCTA","ABST","GOVT","PARN","BSUM","DRWD","DETD","CLMS","DCLM"}; /*{"XXXX","PATN","INVT","ASSG","CLAS","ABST"};*/ int i=0; finish = read_rec(); if (finish==EOF) return(finish); while((strncmp(tape_rec.fullrec,group_tags[i],4) != 0)&&(i < 21)) { i++; } if (i>20) i=0; else {if (last_tag==i) first_time=0; else {first_time=1; last_tag=i; } } return(i); } /*------------------------------------------------------------------------*/ int subtag() { char tags[18][5]= {"WKU ","SRC ","APN ","APT ","PBL ","ART ","APD ","TTL ","ISD ","NCL ","ECL ", "EXA ","EXP ","NDR ","NFG ","DCD ","NPS ","TRM "}; int i=0; while((strncmp(tape_rec.fullrec,tags[i],4) != 0)&&(i < 18)) { i++; } if (i>17) i=0; return(i); } /*----------------------------------------------------------------------*/ int process_invt() { int i /* ,it */; while(!(check_main_tags())) {memset(&fms.full,' ',80); fms.full[0]='\0'; for(i=0;i<80;i++) {if (tape_rec.fullrec[i]=='\n') {tape_rec.fullrec[i]='\0'; i=90;} } if (i==80) tape_rec.fullrec[strlen(tape_rec.fullrec)]='\0'; if(strncmp(tape_rec.fullrec,"NAM ",4)==0) {strcat(fms.full,"INVENTOR = "); i = strlen(tape_rec.subrec.info); strncat(fms.full,tape_rec.subrec.info,i); fprintf(pFms,"%s\n",fms.full); } else if( (strncmp(tape_rec.fullrec,"STR ",4)==0) || (strncmp(tape_rec.fullrec,"CTY ",4)==0) || (strncmp(tape_rec.fullrec,"STA ",4)==0) || (strncmp(tape_rec.fullrec,"CNT ",4)==0) || (strncmp(tape_rec.fullrec,"ZIP ",4)==0) ) { if ( strncmp(tape_rec.fullrec,"STR ",4) == 0 ) strcat(fms.full," STREET = "); else if ( strncmp(tape_rec.fullrec,"CTY ",4) == 0 ) strcat(fms.full," CITY = "); else if ( strncmp(tape_rec.fullrec,"STA ",4) == 0 ) strcat(fms.full," STATE = "); else if ( strncmp(tape_rec.fullrec,"CNT ",4) == 0 ) strcat(fms.full," COUNTRY = "); else if ( strncmp(tape_rec.fullrec,"ZIP ",4) == 0 ) strcat(fms.full," ZIP = "); else strcat(fms.full," "); i = strlen(tape_rec.subrec.info); strncat(fms.full,tape_rec.subrec.info,i); fprintf(pFms,"%s\n",fms.full); } } return(i); } /*----------------------------------------------------------------------*/ int process_assg() { int i /*, it */; assignee_flag=1; while(!(check_main_tags())) {memset(&fms.full,' ',80); fms.full[0]='\0'; if(strncmp(tape_rec.fullrec,"NAM ",4)==0) {strcat(fms.full,"ASSIGNEE = "); assign_row=frow; i = strlen(tape_rec.subrec.info); if (i>69) {fms.full[12]='\0'; fprintf(pFms,"%s\n",fms.full); fprintf(pFms,"%s\n",tape_rec.subrec.info); } else {strncat(fms.full,tape_rec.subrec.info,i); fprintf(pFms,"%s\n",fms.full); } } /* end if */ else if ( (strncmp(tape_rec.fullrec,"CTY ",4)==0) || (strncmp(tape_rec.fullrec,"STA ",4)==0) ) { if ( strncmp(tape_rec.fullrec,"CTY ",4)==0 ) strcat(fms.full," CITY = "); else if (strncmp(tape_rec.fullrec,"STA ",4) == 0) strcat(fms.full," STATE = "); assign_row=frow; i = strlen(tape_rec.subrec.info); if (i>69) {fms.full[12]='\0'; fprintf(pFms,"%s\n",fms.full); fprintf(pFms,"%s\n",tape_rec.subrec.info); } else {strncat(fms.full,tape_rec.subrec.info,i); fprintf(pFms,"%s\n",fms.full); } } /* end if */ } /* end while */ return(i); } /*----------------------------------------------------------------------*/ int process_clas() { int not_first=0; int i,xcl=0; char strr[20]={" TYPE= "}; char stra[30]={"CLASS="}; memset(&fms.full,' ',80); fms.full[0]='\0'; while(!(check_main_tags())) {i=strlen(tape_rec.subrec.info); if(strncmp(tape_rec.fullrec,"OCL ",4)==0) {clas_prep(); for(i=0,ix=12;i<3;i++,ix++) strr[ix]=clas[i]; strr[ix]='\0'; for(i=0,ix=6;i