/* Output from p2c 1.21alpha-07.Dec.93, the Pascal-to-C translator */ /* From input file "dbcat.p" */ #include /* dbcat: database catalog production and sorting program by matthew yarus modified by: Dr. Thomas D. Schneider National Cancer Institute Laboratory of Experimental and Computational Biology Molecular Information Theory Group Frederick, Maryland 21702-1201 toms@ncifcrf.gov permanent email: toms@alum.mit.edu (use only if first address fails) http://www.lecb.ncifcrf.gov/~toms/ module libraries required: delman, prgmods, delmods */ /* used to halt program */ /* begin module version */ #define version 2.19 /* of dbcat.p 2004 Sep 8 2004 Sep 8, 2.19: upgrade to GPC 1998 Jul 16, 2.18: upgrade to datetimearray, upgrade to use accession instead of locus name. origin before 1983 july 13 */ /* end module version */ /* begin module describe.dbcat */ /* name dbcat: database catalog production and sorting program. synopsis dbcat (dbl1, dbl2, dbl3, dbl4, dbl5, dbl6, dbl7, dbl8: inout, ecat: out, gcat: out, output: out ) files dbl1, dbl2, dbl3, dbl4, dbl5, dbl6, dbl7, dbl8: text libraries that contain entries of either embl(european molecular biology labratory) or genbank(genetic sequence data bank) types. in both cases the general format is a series of entries, each entry beginning with a twenty letter identification code name for a particular genetic sequence followed by many lines of other relevant information. all lines begin with a two or three letter code identifying the purpose of the line. however, the two entry types have different line codes and contain similar but not identical kinds of information. ecat: catalog of embl type library entries. each catalog entry contains the location of the beginning of the library entry, a number signifying which library the entry is found in, and the special identification code of the entry's genetic sequence. gcat: same as ecat except containing information on genbank entries. output: messages to the user. description this program makes catalogs for use in the program dbpull. in addition to sorting catalog entries in the innate alphanumeric order of the computer it is run on, dbcat marks both catalogs and libraries with the date of the run so that dbpull never uses mis- matched sets of information. documentation delman.describe.dbpull, embl and genbank libraries. see also loocat.p, catal.p, dbpull.p author matthew yarus bugs technical notes dbcat functions on genbank(tm) release 9 (june 1, 1983) */ /* end module describe.dbcat */ /* more constants */ #define idlength 20 /* length of identification code for each library or catalog entry */ #define namelength idlength /* length of computer system date */ #define libtotal 8 /* number of libraries used in program */ #define lclength 3 /* length of code at beginning of each library line */ #define lcdat "DAT" /* short for date, used for dating cats and libs */ /* LOCK begin module datetime.const */ /* THIS IS LOCKED TO 20 TO KEEP IT THE SAME AS idlength! */ #define datetimearraylength 20 /* length of dataarray for dates, It is just long enough to include the 4 digit year - solving the year 2000 problem: 1980/06/09 18:49:11 123456789 123456789 1 2 */ /* LOCK end module datetime.const version = 'delmod 6.88 98 Jul 10 tds/gds' */ /* begin module dbcat.type */ /* a 'u' after the 'lc' or 'id' of a type name indicates that the array is unpacked; a 'p' indicates that the array is packed; an 's' indicates that the array has more than one dimension */ typedef Char idutype[idlength]; /* used to read-write library entry ids */ typedef Char idptype[idlength]; /* holds a library entry id for string comparisons */ typedef idptype alpha; /* holds computer system date */ typedef char lnrange; /* subrange for handling number of libraries */ typedef struct catrec { /* structure of each catalog entry */ idptype idp; /* holds id of entry */ lnrange libnum; /* identifies in which of 8 libraries entry is found */ long linenumber; /* holds the line in library where an entry begins */ } catrec; typedef struct dbcats { FILE *f; FILEBUFNC(f,catrec); Char name[_FNSIZE]; } dbcats; /* structure of whole catalog */ typedef enum { embl, genb } libsused; /* used to indicate whether requested library entry is embl or genbank type */ typedef Char lcutype[lclength]; /* holds library line code for reading-writing before packing */ typedef Char lcptype[lclength]; /* holds lib line code for string comparisons */ typedef char countype; /* subrange for handling library line codes */ /* end module dbcat.type */ /* begin module datetime.type */ /* array for dates */ typedef Char datetimearray[datetimearraylength]; /* end module datetime.type version = 'cdatemod.p 1.19 1999Dec13'; */ /* begin module dbcat.var */ Static dbcats cat; /* any catalog */ Static _TEXT lib; /* any library */ Static dbcats ecatunsort, ecat; /* internal unsorted catalog and finished version (of embl libraries) */ Static dbcats gcatunsort, gcat; /* same for genbank */ Static _TEXT dbl1, dbl2, dbl3, dbl4, dbl5, dbl6, dbl7, dbl8; Static jmp_buf _JL1; /* ordinarily, the first three libraries are embl and the rest are genbank. however, program can handle any case of one to eight libraries containing both types of entries */ /* end module dbcat.var */ /* begin module package.primitive */ /* ************************************************************************ */ /* begin module halt */ Static Void halt() { /* stop the program. the procedure performs a goto to the end of the program. you must have a label: label 1; declared, and also the end of the program must have this label: 1: end. examples are in the module libraries. this is the only goto in the delila system. */ printf(" program halt.\n"); longjmp(_JL1, 1); } /* end module halt version = 7.67; {of delmod.p 2004 Sep 8} */ /* begin module copyaline */ Static Void copyaline(fin, fout) _TEXT *fin, *fout; { /* copy a line from file fin to file fout */ while (!P_eoln(fin->f)) { putc(P_peek(fin->f), fout->f); getc(fin->f); } fscanf(fin->f, "%*[^\n]"); getc(fin->f); putc('\n', fout->f); } /* copyaline */ /* end module copyaline version = 7.67; {of delmod.p 2004 Sep 8} */ /* begin module copylines */ Static long copylines(fin, fout, n) _TEXT *fin, *fout; long n; { /* copy n lines of file fin to file fout. the actual number of lines copied is returned. */ long index = 0; /* the current line number */ while (!BUFEOF(fin->f) && index < n) { copyaline(fin, fout); index++; } return index; } /* copylines */ /* end module copylines version = 7.67; {of delmod.p 2004 Sep 8} */ /* ************************************************************************ */ /* end module package.primitive version = 7.67; {of delmod.p 2004 Sep 8} */ /* begin module skipblanks */ /* 2003 July 31: tab is considered a blank character */ Static boolean isblank(c) Char c; { /* is the character c blank or tab? */ return (c == ' ' || c == '\t'); } Static Void skipblanks(thefile) _TEXT *thefile; { /* skip over blanks until a non-blank, or end of line, is found */ while (isblank(P_peek(thefile->f)) & (!P_eoln(thefile->f))) getc(thefile->f); } Static Void skipnonblanks(thefile) _TEXT *thefile; { /* skip over nonblanks until a blank, or end of line, is found */ while ((!isblank(P_peek(thefile->f))) & (!P_eoln(thefile->f))) getc(thefile->f); } Static Void skipcolumn(thefile) _TEXT *thefile; { /* skip over a data column */ skipblanks(thefile); skipnonblanks(thefile); } /* end module skipblanks version = 7.67; {of delmod.p 2004 Sep 8} */ /* begin module dbpull.readlcu */ Static Void readlcu(lib, liblcu, liblcp) _TEXT *lib; Char *liblcu; Char *liblcp; { /* grabs a library line code and then packs it for string comparisons */ countype index; /* for loop counter */ for (index = 0; index <= lclength - 1; index++) { if (P_eoln(lib->f)) liblcu[index] = ' '; else { liblcu[index] = getc(lib->f); if (liblcu[index] == '\n') liblcu[index] = ' '; } } memcpy(liblcp, liblcu, sizeof(lcptype)); } /* readlcu */ /* end module dbpull.readlcu */ /* begin module dbpull.lcequal */ Static boolean lcequal(lcp1, lcp2) Char *lcp1, *lcp2; { /* tests two line codes for equality. if your computer system version of pascal does not do string comparisons simply change lcequal and the program will be fixed throughout */ /* p2c: dbcat.p: Note: Eliminated unused assignment statement [338] */ if (!strncmp(lcp1, lcp2, sizeof(lcptype))) return true; return false; } /* lcequal */ /* end module dbpull.lcequal */ /* begin module dbpull.idequal */ Static boolean idequal(idp1, idp2) Char *idp1, *idp2; { /* tests two ids for equality. if your computer system version of pascal does not do string comparisons simply change idequal and the program will be fixed throughout */ /* p2c: dbcat.p: Note: Eliminated unused assignment statement [338] */ if (!strncmp(idp1, idp2, sizeof(idptype))) return true; return false; } /* idequal */ /* end module dbpull.idequal */ /* begin module dbpull.datesequal */ Static boolean datesequal(idp1, idp2) Char *idp1, *idp2; { /* idequal */ /* tests two dates for equality. if your computer system version of pascal does not do string comparisons simply change idequal and the program will be fixed throughout. */ /* p2c: dbcat.p: Note: Eliminated unused assignment statement [338] */ if (!strncmp(idp1, idp2, sizeof(datetimearray))) return true; return false; } /* idequal */ /* end module dbpull.datesequal */ /* begin module dbpull.getid */ Static Void getid(fin, finidp) _TEXT *fin; Char *finidp; { /* see global */ /* holds requested library id */ /* finds the next string of non-space characters following the file cursor, adding spaces at the end if the string is too short, and then packs the string into the finidp array */ long index = 0; /* counter for loop */ idutype finidu; /* holds id for reading in before packing */ while (P_peek(fin->f) == ' ') /* advances to first id character */ getc(fin->f); /* loop initialization value */ /* the following loop grabs all id characters */ while (P_peek(fin->f) != ' ' && index < idlength) { index++; if (P_eoln(fin->f)) finidu[index-1] = ' '; else { finidu[index-1] = getc(fin->f); if (finidu[index-1] == '\n') finidu[index-1] = ' '; } putchar(finidu[index-1]); /*zzz*/ } /* the following loop fills out id if id is too short */ while (index < idlength) { index++; finidu[index-1] = ' '; } memcpy(finidp, finidu, sizeof(idptype)); putchar('\n'); /*zzz*/ } /* getid */ /* end module dbpull.getid */ /* begin module dbcat.makecat */ Static Void makecat(lib, cat, libtitle, libnumhold) _TEXT *lib; dbcats *cat; libsused libtitle; lnrange libnumhold; { /* see global */ /* see global */ /* holds which type of library entry is being handled */ /* holds which library entry is found in */ /* creates embl and genbank catalogue entries in cat corresponding to entries in the library lib. each catalogue entry (catrec) contains the entry name, the library it is in and the line it is on in the library */ countype index; /* loop counter */ long linenum = 1; /* holds the current library line */ boolean entry_; /* 'true' indicates that current line is the start of an entry */ Char ch; /* a character in the library */ Char trigger[lclength]; /* the string of characters to look for as the start of an entry */ boolean done; /* done searching for ACCESSION */ long recordinglocation; /* the place to record the start of an entry */ idptype TEMP; /* lib starts on line one */ if (lclength > 3) { printf("ERROR IN MAKECAT: LCLENGTH TOO BIG\n"); halt(); } switch (libtitle) { case genb: trigger[0] = 'L'; trigger[1] = 'O'; trigger[2] = 'C'; break; case embl: trigger[0] = 'I'; trigger[1] = 'D'; trigger[2] = ' '; break; } while (!BUFEOF(lib->f)) { entry_ = true; /* we try to disprove this */ index = 0; /* loop initialization */ /* check for id line code one character at a time, but do not even start if the line has no characters */ if (P_eoln(lib->f)) entry_ = false; else { do { index++; ch = getc(lib->f); if (ch == '\n') ch = ' '; if (P_eoln(lib->f)) entry_ = false; else entry_ = (trigger[index-1] == ch); } while (entry_ && index != lclength); } if (entry_) { /* did pass test */ if (libtitle == genb) { /* get ( lib ); get ( lib ); (* dumps 'us' of 'locus' *) */ /* the locus name is irrelevant since genbank uses accession numbers now. So move to the ACCESSION line */ recordinglocation = linenum; fscanf(lib->f, "%*[^\n]"); getc(lib->f); linenum++; done = false; while (!done) { if (P_peek(lib->f) == 'A') { getc(lib->f); if (P_peek(lib->f) == 'C') { getc(lib->f); if (P_peek(lib->f) == 'C') done = true; } } if (done) break; fscanf(lib->f, "%*[^\n]"); getc(lib->f); linenum++; } skipnonblanks(lib); /*zzz*/ } memcpy(TEMP, GETFBUF(cat->f, catrec).idp, sizeof(idptype)); getid(lib, TEMP); /* cat^.linenumber := linenum; */ GETFBUF(cat->f, catrec).linenumber = recordinglocation; GETFBUF(cat->f, catrec).libnum = libnumhold; PUT(cat->f, catrec); } fscanf(lib->f, "%*[^\n]"); getc(lib->f); linenum++; /* a line has been completed */ } } /* makecat */ #define maxdata 3000 /* maximum number of data items that can be quick sorted */ typedef short position; typedef catrec dataarray[maxdata]; /* for internal storage */ /* Local variables for mergesort: */ struct LOC_mergesort { dbcats *fin; dataarray store; /* for internal storage */ long size; /* amount of store used */ } ; Local Void readin(f, s, size, LINK) dbcats *f; catrec *s; long *size; struct LOC_mergesort *LINK; { /* read from f into s as much data as possible */ *size = 0; while (!BUFEOF(f->f) && *size < maxdata) { (*size)++; fread(&s[*size - 1], sizeof(catrec), 1, f->f); } /*; if debugging then write(output, 'datain(', size:1,')')*/ } /* readin */ Local Void copy_(f, t, LINK) dbcats *f, *t; struct LOC_mergesort *LINK; { /* copy the rest of file f into file t */ while (!BUFEOF(f->f)) { PUTFBUF(t->f, catrec, GETFBUF(f->f, catrec)); GET(f->f, catrec); PUT(t->f, catrec); } } /* copy */ Local boolean datalessthan(a, b, LINK) catrec a, b; struct LOC_mergesort *LINK; { /* compare data in a and b for order */ return (strncmp(a.idp, b.idp, sizeof(idptype)) < 0); /* can your system handle this ? */ } /* datalessthan */ Local boolean lessthan(a, b, LINK) position a, b; struct LOC_mergesort *LINK; { /* compare data at positions a and b in array store for order */ return (datalessthan(LINK->store[a-1], LINK->store[b-1], LINK)); } /* lessthan */ Local Void swap_(a, b, LINK) position a, b; struct LOC_mergesort *LINK; { /* swap the data in store at a and b */ catrec hold; hold = LINK->store[a-1]; LINK->store[a-1] = LINK->store[b-1]; LINK->store[b-1] = hold; } /* swap */ /* end module dbcat.mergesort.upper */ /* begin module quicksort */ Local Void quicksort(left, right, LINK) long left, right; struct LOC_mergesort *LINK; { /* quick sort a list between positions left and right, into ascending order. a position is simply a scalar of the form 0..max. the array to be sorted is dimensioned 1..max. (the difference in the ranges is important to the correct operation of the sort...) two external routines are used: function lessthan(a, b: integer): boolean is a generalized test for value-at-a < value-at-b. procedure swap(a, b: integer) switches the items at positions a and b. since these routines are external, the procedure is general. this procedure taken from the book 'algorithms + data structures = programs' by niklaus wirth, prentice-hall, inc., englewood cliffs, n.j.(1976), pp. 76-82 */ long lower = left; long upper; /* the positions looked at currently */ long center; /* the rough center of the region being sorted */ center = (left + right) / 2; upper = right; do { while (lessthan((int)lower, (int)center, LINK)) lower++; while (lessthan((int)center, (int)upper, LINK)) upper--; if (lower <= upper) { /* keep track of the center through the map: */ if (lower == center) center = upper; else if (upper == center) center = lower; swap_((int)lower, (int)upper, LINK); lower++; upper--; } } while (lower <= upper); if (left < upper) quicksort(left, upper, LINK); if (lower < right) quicksort(lower, right, LINK); } /* end module quicksort version = 4.86; (@ of prgmod.p 2004 Sep 8 */ /* begin module dbcat.mergesort.lower */ Local Void merge(a, asize, b, c, LINK) catrec *a; long asize; dbcats *b, *c; struct LOC_mergesort *LINK; { /* size of a */ /* merge all items in a with those in b (note different types) and place them into c */ long aindex = 1; /* index to a */ catrec acurrent; /* the value of a pointed to by aindex */ catrec TEMP; if (*b->name != '\0') { if (b->f != NULL) b->f = freopen(b->name, "rb", b->f); else b->f = fopen(b->name, "rb"); } else rewind(b->f); if (b->f == NULL) _EscIO2(FileNotFound, b->name); RESETBUF(b->f, catrec); /* start reading from b */ if (*c->name != '\0') { if (c->f != NULL) c->f = freopen(c->name, "wb", c->f); else c->f = fopen(c->name, "wb"); } else { if (c->f != NULL) rewind(c->f); else c->f = tmpfile(); } if (c->f == NULL) _EscIO2(FileNotFound, c->name); SETUPBUF(c->f, catrec); /* write the merged result to c */ acurrent = a[aindex-1]; /* if debugging then writeln(output, 'merge, asize=', asize:1); */ while ((aindex <= asize) & (!BUFEOF(b->f))) { if (datalessthan(acurrent, GETFBUF(b->f, catrec), LINK)) { /* if debugging then writeln(output, '1. aindex=', aindex:1);*/ fwrite(&acurrent, sizeof(catrec), 1, c->f); aindex++; if (aindex <= LINK->size) acurrent = a[aindex-1]; } else { TEMP = GETFBUF(b->f, catrec); /* if debugging then writeln(output, '2.'); */ fwrite(&TEMP, sizeof(catrec), 1, c->f); GET(b->f, catrec); } } /* finish copy of remaining data to c */ if (!BUFEOF(b->f)) { copy_(b, c, LINK); return; } while (aindex <= asize) { fwrite(&a[aindex-1], sizeof(catrec), 1, c->f); aindex++; } } /* merge */ Local Void pass(i, o, LINK) dbcats *i, *o; struct LOC_mergesort *LINK; { /* make one pass through the data */ /* if debugging then write(output,'r'); */ readin(LINK->fin, LINK->store, &LINK->size, LINK); /* if debugging then write(output,'q'); */ quicksort(1L, LINK->size, LINK); /* store is sorted */ /* if debugging then write(output,'m'); */ /* merge array store with file i to produce file o */ merge(LINK->store, LINK->size, i, o, LINK); } /* pass */ /* end module dbcat.makecat version = 2.06; (@ of dbcat 1985 may 30 */ /* begin module dbcat.mergesort.upper */ Static Void mergesort(fin_, fout) dbcats *fin_, *fout; { /* merge sort fin to produce fout. a quicksort is used to sort sublists from fin. these are merged with an internal file (or fout) until all data is sorted. */ struct LOC_mergesort V; boolean tofout = false; /* direction to send data */ dbcats internal; /* internal file */ V.fin = fin_; internal.f = NULL; *internal.name = '\0'; if (*V.fin->name != '\0') { if (V.fin->f != NULL) V.fin->f = freopen(V.fin->name, "rb", V.fin->f); else V.fin->f = fopen(V.fin->name, "rb"); } else rewind(V.fin->f); if (V.fin->f == NULL) _EscIO2(FileNotFound, V.fin->name); RESETBUF(V.fin->f, catrec); if (*fout->name != '\0') { if (fout->f != NULL) fout->f = freopen(fout->name, "wb", fout->f); else fout->f = fopen(fout->name, "wb"); } else { if (fout->f != NULL) rewind(fout->f); else fout->f = tmpfile(); } if (fout->f == NULL) _EscIO2(FileNotFound, fout->name); SETUPBUF(fout->f, catrec); /* besure that any previous list is gone */ /* start by storing to internal */ while (!BUFEOF(V.fin->f)) { if (tofout) pass(&internal, fout, &V); else pass(fout, &internal, &V); tofout = !tofout; } /* if debugging then writeln(output, 'now copy to fout');*/ /* be sure that fout contains the data */ if (tofout) { if (*internal.name != '\0') { if (internal.f != NULL) internal.f = freopen(internal.name, "rb", internal.f); else internal.f = fopen(internal.name, "rb"); } else rewind(internal.f); if (internal.f == NULL) _EscIO2(FileNotFound, internal.name); RESETBUF(internal.f, catrec); if (*fout->name != '\0') { if (fout->f != NULL) fout->f = freopen(fout->name, "wb", fout->f); else fout->f = fopen(fout->name, "wb"); } else { if (fout->f != NULL) rewind(fout->f); else fout->f = tmpfile(); } if (fout->f == NULL) _EscIO2(FileNotFound, fout->name); SETUPBUF(fout->f, catrec); copy_(&internal, fout, &V); } if (internal.f != NULL) fclose(internal.f); } /* mergesort */ #undef maxdata /* end module dbcat.mergesort.lower */ /* begin module getdatetime */ Static Void getdatetime(adatetime) Char *adatetime; { /* Get the date and time into a single array from the system clock. adatetime contains the date: 1980/06/09 18:49:11 ye mo da ho mi se (year, month, day, hour, minute, second) This version works after translation of the pascal by p2c to C and then compiling with gcc. */ Char adate[11], atime[11]; /* adate, atime: alfa; (* ie, packed array[1..10] of char; *) This old method won't work, since the last digit gets cut off! */ Char month[3]; long index; /* index for times */ /* 1 12345678901 adate[13-DEC-1999] atime[17:39:44.00] */ VAXdate(adate); VAXtime(atime); /* writeln(output,'br: adate[',adate,'] atime[',atime,']'); */ /* transfer the year */ for (index = 1; index <= 4; index++) adatetime[index-1] = adate[index+6]; adatetime[4] = '/'; for (index = 4; index <= 6; index++) month[index-4] = adate[index-1]; if (!strncmp(month, "JAN", 3)) { adatetime[5] = '0'; adatetime[6] = '1'; } else if (!strncmp(month, "FEB", 3)) { adatetime[5] = '0'; adatetime[6] = '2'; } else if (!strncmp(month, "MAR", 3)) { adatetime[5] = '0'; adatetime[6] = '3'; } else if (!strncmp(month, "APR", 3)) { adatetime[5] = '0'; adatetime[6] = '4'; } else if (!strncmp(month, "MAY", 3)) { adatetime[5] = '0'; adatetime[6] = '5'; } else if (!strncmp(month, "JUN", 3)) { adatetime[5] = '0'; adatetime[6] = '6'; } else if (!strncmp(month, "JUL", 3)) { adatetime[5] = '0'; adatetime[6] = '7'; } else if (!strncmp(month, "AUG", 3)) { adatetime[5] = '0'; adatetime[6] = '8'; } else if (!strncmp(month, "SEP", 3)) { adatetime[5] = '0'; adatetime[6] = '9'; } else if (!strncmp(month, "OCT", 3)) { adatetime[5] = '1'; adatetime[6] = '0'; } else if (!strncmp(month, "NOV", 3)) { adatetime[5] = '1'; adatetime[6] = '1'; } else if (!strncmp(month, "DEC", 3)) { adatetime[5] = '1'; adatetime[6] = '2'; } adatetime[7] = '/'; for (index = 7; index <= 8; index++) adatetime[index+1] = adate[index-7]; /* replace blanks with spaces in dates */ if (adatetime[5] == ' ') adatetime[5] = '0'; if (adatetime[8] == ' ') adatetime[8] = '0'; adatetime[10] = ' '; for (index = 10; index <= 17; index++) adatetime[index+1] = atime[index-10]; for (index = 19; index <= datetimearraylength + 1; index++) adatetime[index] = ' '; } /* end module getdatetime version = 'cdatemod.p 1.19 1999Dec13'; */ /* begin module readdatetime */ Static Void readdatetime(thefile, adatetime) _TEXT *thefile; Char *adatetime; { /* read the date and time from the file */ long index; /* to the udatetime */ /* the following is an unpacked date time array, to avoid reading into a packed array. reading into a packed array is not transportable */ Char udatetime[datetimearraylength]; for (index = 0; index < datetimearraylength; index++) { udatetime[index] = getc(thefile->f); if (udatetime[index] == '\n') udatetime[index] = ' '; } memcpy(adatetime, udatetime, sizeof(datetimearray)); if (adatetime[2] == '/' && adatetime[11] == ':') printf(" old datetime (only 2 year digits) read: %.*s\n", datetimearraylength, adatetime); /* p2c: dbcat.p, line 689: Note: * Format for packed-array-of-char will work only if width < length [321] */ /* if (adatetime[3]<>'/') or (adatetime[12]<>':') then begin writeln(output,' bad date time read: ',adatetime:1); halt end; for index:=18 to datetimearraylength do adatetime[index]:=' ' */ } /* end module readdatetime version = 'cdatemod.p 1.19 1999Dec13'; */ /* begin module writedatetime */ Static Void writedatetime(thefile, adatetime) _TEXT *thefile; Char *adatetime; { /* expand the date and time out and print in the file */ long index; /* index of datetime */ for (index = 0; index < datetimearraylength; index++) putc(adatetime[index], thefile->f); } Local Void libcheck(lib, libpresent, libmatch, libcount, adatetime) _TEXT *lib; boolean *libpresent, *libmatch; lnrange *libcount; Char *adatetime; { /* global variable */ /* counts and checks date of a single library */ long index; /* loop counter */ Char dumpchar; /* holds unwanted character */ lcutype liblcu; /* holds the line code of the first line of a lib */ lcptype liblcp; /* same as liblcu but used for string comparison to lcdat */ datetimearray libidp; /* in this special case, this holds the lib date, not an entry identification code */ if (*lib->name != '\0') { if (lib->f != NULL) lib->f = freopen(lib->name, "r", lib->f); else lib->f = fopen(lib->name, "r"); } else rewind(lib->f); if (lib->f == NULL) _EscIO2(FileNotFound, lib->name); RESETBUF(lib->f, Char); if (BUFEOF(lib->f)) return; (*libcount)++; readlcu(lib, liblcu, liblcp); if (!lcequal(liblcp, lcdat)) { /* undated library is treated as null date case */ libidp[0] = 'D'; libidp[1] = 'A'; libidp[2] = 'T'; libidp[3] = 'E'; /* 'date' with 16 spaces after it is the null date code */ for (index = 4; index < idlength; index++) libidp[index] = ' '; } else { dumpchar = getc(lib->f); /* dumps 'e' of 'date' */ if (dumpchar == '\n') dumpchar = ' '; do { getc(lib->f); } while (P_peek(lib->f) == ' '); readdatetime(lib, libidp); } if (!*libpresent) { for (index = 0; index < idlength; index++) adatetime[index] = libidp[index]; } *libpresent = true; if (*libmatch) { /* if not libmatch, libcheck will no longer test for equality when it is called */ *libmatch = idequal(libidp, adatetime); } } /* libcheck */ /* end module writedatetime version = 'cdatemod.p 1.19 1999Dec13'; */ /* begin module dbcat.getlibdate */ Static Void getlibdate(dbl1, dbl2, dbl3, dbl4, dbl5, dbl6, dbl7, dbl8, libpresent, libmatch, libcount, adatetime) _TEXT *dbl1, *dbl2, *dbl3, *dbl4, *dbl5, *dbl6, *dbl7, *dbl8; boolean *libpresent, *libmatch; lnrange *libcount; Char *adatetime; { /* global */ /* 'true' if at least one non- empty lib is present */ /* 'true' if two libs have matching dates */ /* holds the number of non- empty libraries */ /* holds the date of a lib for comparison to all the other dates */ /* counts non-empty libs and checks to see that their dates match */ *libpresent = false; *libmatch = true; *libcount = 0; libcheck(dbl1, libpresent, libmatch, libcount, adatetime); libcheck(dbl2, libpresent, libmatch, libcount, adatetime); libcheck(dbl3, libpresent, libmatch, libcount, adatetime); libcheck(dbl4, libpresent, libmatch, libcount, adatetime); libcheck(dbl5, libpresent, libmatch, libcount, adatetime); libcheck(dbl6, libpresent, libmatch, libcount, adatetime); libcheck(dbl7, libpresent, libmatch, libcount, adatetime); libcheck(dbl8, libpresent, libmatch, libcount, adatetime); } /* getlibdate */ /* end module dbcat.getlibdate */ /* begin module dbcat.datecat */ Static Void datecat(catin, cat, catout, adatetime, libcount) dbcats *catin, *cat, *catout; Char *adatetime; lnrange libcount; { /* catalog without date */ /* intermediate file */ /* dated catalog */ /* holds computer system date or date of libraries if they all match */ /* holds number of non-empty libraries */ /* puts the date and library count in the first record of the catalog and then recopies the rest of the cat */ long index; /* loop counter */ catrec TEMP; if (*catin->name != '\0') { if (catin->f != NULL) catin->f = freopen(catin->name, "rb", catin->f); else catin->f = fopen(catin->name, "rb"); } else rewind(catin->f); if (catin->f == NULL) _EscIO2(FileNotFound, catin->name); RESETBUF(catin->f, catrec); if (*cat->name != '\0') { if (cat->f != NULL) cat->f = freopen(cat->name, "wb", cat->f); else cat->f = fopen(cat->name, "wb"); } else { if (cat->f != NULL) rewind(cat->f); else cat->f = tmpfile(); } if (cat->f == NULL) _EscIO2(FileNotFound, cat->name); SETUPBUF(cat->f, catrec); /* the following loop adds date even if catalog is empty because the other catalog has entries(double checked by catentry) */ for (index = 0; index < idlength; index++) GETFBUF(cat->f, catrec).idp[index] = adatetime[index]; GETFBUF(cat->f, catrec).libnum = libcount; PUT(cat->f, catrec); while (!BUFEOF(catin->f)) { PUTFBUF(cat->f, catrec, GETFBUF(catin->f, catrec)); GET(catin->f, catrec); PUT(cat->f, catrec); } if (*cat->name != '\0') { if (cat->f != NULL) cat->f = freopen(cat->name, "rb", cat->f); else cat->f = fopen(cat->name, "rb"); } else rewind(cat->f); if (cat->f == NULL) _EscIO2(FileNotFound, cat->name); RESETBUF(cat->f, catrec); if (*catout->name != '\0') { if (catout->f != NULL) catout->f = freopen(catout->name, "wb", catout->f); else catout->f = fopen(catout->name, "wb"); } else { if (catout->f != NULL) rewind(catout->f); else catout->f = tmpfile(); } if (catout->f == NULL) _EscIO2(FileNotFound, catout->name); SETUPBUF(catout->f, catrec); do { TEMP = GETFBUF(cat->f, catrec); fwrite(&TEMP, sizeof(catrec), 1, catout->f); GET(cat->f, catrec); } while (!BUFEOF(cat->f)); } /* datecat */ /* end module dbcat.datecat */ /* begin module dbcat.datelib */ Static Void datelib(libin, lib, libout, adatetime) _TEXT *libin, *lib, *libout; Char *adatetime; { /* undated library */ /* intermediate file */ /* dated library */ /* holds computer system date */ /* adds date line to front of library and then recopies the rest of the lib */ long index; /* loop counter */ lcutype liblcu; /* holds the line code of the first line of a lib */ lcptype liblcp; /* same as liblcu but used for string comparison to string constant lcdat */ boolean dateskip = false; /* 'true' means that old libin dateline has been passed over */ if (*libin->name != '\0') { if (libin->f != NULL) libin->f = freopen(libin->name, "r", libin->f); else libin->f = fopen(libin->name, "r"); } else rewind(libin->f); if (libin->f == NULL) _EscIO2(FileNotFound, libin->name); RESETBUF(libin->f, Char); if (*lib->name != '\0') { if (lib->f != NULL) lib->f = freopen(lib->name, "w", lib->f); else lib->f = fopen(lib->name, "w"); } else { if (lib->f != NULL) rewind(lib->f); else lib->f = tmpfile(); } if (lib->f == NULL) _EscIO2(FileNotFound, lib->name); SETUPBUF(lib->f, Char); if (BUFEOF(libin->f)) return; do { readlcu(libin, liblcu, liblcp); if (lcequal(liblcp, lcdat)) { fscanf(libin->f, "%*[^\n]"); getc(libin->f); } else dateskip = true; } while (!dateskip); fprintf(lib->f, "DATE "); writedatetime(lib, adatetime); putc('\n', lib->f); for (index = 0; index < lclength; index++) /* cursor is past code */ putc(liblcu[index], lib->f); do { /* copies the rest of the first non-date line */ copyaline(libin, lib); } while (!BUFEOF(libin->f)); if (*lib->name != '\0') { if (lib->f != NULL) lib->f = freopen(lib->name, "r", lib->f); else lib->f = fopen(lib->name, "r"); } else rewind(lib->f); if (lib->f == NULL) _EscIO2(FileNotFound, lib->name); RESETBUF(lib->f, Char); if (*libout->name != '\0') { if (libout->f != NULL) libout->f = freopen(libout->name, "w", libout->f); else libout->f = fopen(libout->name, "w"); } else { if (libout->f != NULL) rewind(libout->f); else libout->f = tmpfile(); } if (libout->f == NULL) _EscIO2(FileNotFound, libout->name); SETUPBUF(libout->f, Char); do { /* copies the rest of the library */ copyaline(lib, libout); } while (!BUFEOF(lib->f)); } /* datelib */ /* end module dbcat.datelib */ /* begin module dbcat.catlibdate */ Static Void catlibdate(dbl1, dbl2, dbl3, dbl4, dbl5, dbl6, dbl7, dbl8, cat1, cat2) _TEXT *dbl1, *dbl2, *dbl3, *dbl4, *dbl5, *dbl6, *dbl7, *dbl8; dbcats *cat1, *cat2; { /* global */ /* global */ /* structures whole dating process */ boolean libpresent; /* 'true' if at least one non-empty lib is found */ boolean libmatch; /* 'true' if two lib dates matched */ lnrange libcount; /* holds the number of non-empty libaries */ datetimearray adatetime; /* holds computer system date or date of libraries(if they all match) */ getlibdate(dbl1, dbl2, dbl3, dbl4, dbl5, dbl6, dbl7, dbl8, &libpresent, &libmatch, &libcount, adatetime); if (!libpresent) { printf(" NO DATABASE LIBRARIES ARE PRESENT\n"); halt(); } if (libmatch) { datecat(&ecat, &cat, &ecat, adatetime, libcount); datecat(&gcat, &cat, &gcat, adatetime, libcount); return; } getdatetime(adatetime); adatetime[19] = ' '; datecat(&ecat, &cat, &ecat, adatetime, libcount); datecat(&gcat, &cat, &gcat, adatetime, libcount); datelib(dbl1, &lib, dbl1, adatetime); datelib(dbl2, &lib, dbl2, adatetime); datelib(dbl3, &lib, dbl3, adatetime); datelib(dbl4, &lib, dbl4, adatetime); datelib(dbl5, &lib, dbl5, adatetime); datelib(dbl6, &lib, dbl6, adatetime); datelib(dbl7, &lib, dbl7, adatetime); datelib(dbl8, &lib, dbl8, adatetime); } /* catlibdate */ Local Void call(lib, cat1, cat2, libnumhold) _TEXT *lib; dbcats *cat1, *cat2; lnrange libnumhold; { /* calls makecat procedure for each library. both embl and genb entries are catalogued. libnumhold indicates in which of 8 libs entry is found */ libsused libtitle = embl; /* indicates whether procedure will search for embl or genbank type entries */ makecat(lib, cat1, libtitle, libnumhold); if (*lib->name != '\0') { if (lib->f != NULL) lib->f = freopen(lib->name, "r", lib->f); else lib->f = fopen(lib->name, "r"); } else rewind(lib->f); if (lib->f == NULL) _EscIO2(FileNotFound, lib->name); RESETBUF(lib->f, Char); libtitle = genb; makecat(lib, cat2, libtitle, libnumhold); } /* call */ Local Void catentry(cat1, cat2) dbcats *cat1, *cat2; { /* catalogs produced by repeated uses of call */ /* if no entries are found in any libraries, the program halts */ if (*cat1->name != '\0') { if (cat1->f != NULL) cat1->f = freopen(cat1->name, "rb", cat1->f); else cat1->f = fopen(cat1->name, "rb"); } else rewind(cat1->f); if (cat1->f == NULL) _EscIO2(FileNotFound, cat1->name); RESETBUF(cat1->f, catrec); if (*cat2->name != '\0') { if (cat2->f != NULL) cat2->f = freopen(cat2->name, "rb", cat2->f); else cat2->f = fopen(cat2->name, "rb"); } else rewind(cat2->f); if (cat2->f == NULL) _EscIO2(FileNotFound, cat2->name); RESETBUF(cat2->f, catrec); if (!(BUFEOF(cat1->f) & BUFEOF(cat2->f))) return; printf(" YOUR DATA BASE LIBRARIES CONTAIN NO ENTRIES\n"); printf(" OF EITHER EMBL OR GENBANK FORMAT\n"); halt(); } /* catentry */ /* end module dbcat.catlibdate */ /* begin module dbcat.order */ Static Void order(dbl1, dbl2, dbl3, dbl4, dbl5, dbl6, dbl7, dbl8, ecatunsort, ecat, gcatunsort, gcat) _TEXT *dbl1, *dbl2, *dbl3, *dbl4, *dbl5, *dbl6, *dbl7, *dbl8; dbcats *ecatunsort, *ecat, *gcatunsort, *gcat; { /* see global for all */ /* orders other procedures */ if (*dbl1->name != '\0') { if (dbl1->f != NULL) dbl1->f = freopen(dbl1->name, "r", dbl1->f); else dbl1->f = fopen(dbl1->name, "r"); } else rewind(dbl1->f); if (dbl1->f == NULL) _EscIO2(FileNotFound, dbl1->name); RESETBUF(dbl1->f, Char); if (*dbl2->name != '\0') { if (dbl2->f != NULL) dbl2->f = freopen(dbl2->name, "r", dbl2->f); else dbl2->f = fopen(dbl2->name, "r"); } else rewind(dbl2->f); if (dbl2->f == NULL) _EscIO2(FileNotFound, dbl2->name); RESETBUF(dbl2->f, Char); if (*dbl3->name != '\0') { if (dbl3->f != NULL) dbl3->f = freopen(dbl3->name, "r", dbl3->f); else dbl3->f = fopen(dbl3->name, "r"); } else rewind(dbl3->f); if (dbl3->f == NULL) _EscIO2(FileNotFound, dbl3->name); RESETBUF(dbl3->f, Char); if (*dbl4->name != '\0') { if (dbl4->f != NULL) dbl4->f = freopen(dbl4->name, "r", dbl4->f); else dbl4->f = fopen(dbl4->name, "r"); } else rewind(dbl4->f); if (dbl4->f == NULL) _EscIO2(FileNotFound, dbl4->name); RESETBUF(dbl4->f, Char); if (*dbl5->name != '\0') { if (dbl5->f != NULL) dbl5->f = freopen(dbl5->name, "r", dbl5->f); else dbl5->f = fopen(dbl5->name, "r"); } else rewind(dbl5->f); if (dbl5->f == NULL) _EscIO2(FileNotFound, dbl5->name); RESETBUF(dbl5->f, Char); if (*dbl6->name != '\0') { if (dbl6->f != NULL) dbl6->f = freopen(dbl6->name, "r", dbl6->f); else dbl6->f = fopen(dbl6->name, "r"); } else rewind(dbl6->f); if (dbl6->f == NULL) _EscIO2(FileNotFound, dbl6->name); RESETBUF(dbl6->f, Char); if (*dbl7->name != '\0') { if (dbl7->f != NULL) dbl7->f = freopen(dbl7->name, "r", dbl7->f); else dbl7->f = fopen(dbl7->name, "r"); } else rewind(dbl7->f); if (dbl7->f == NULL) _EscIO2(FileNotFound, dbl7->name); RESETBUF(dbl7->f, Char); if (*dbl8->name != '\0') { if (dbl8->f != NULL) dbl8->f = freopen(dbl8->name, "r", dbl8->f); else dbl8->f = fopen(dbl8->name, "r"); } else rewind(dbl8->f); if (dbl8->f == NULL) _EscIO2(FileNotFound, dbl8->name); RESETBUF(dbl8->f, Char); if (*ecatunsort->name != '\0') { if (ecatunsort->f != NULL) ecatunsort->f = freopen(ecatunsort->name, "wb", ecatunsort->f); else ecatunsort->f = fopen(ecatunsort->name, "wb"); } else { if (ecatunsort->f != NULL) rewind(ecatunsort->f); else ecatunsort->f = tmpfile(); } if (ecatunsort->f == NULL) _EscIO2(FileNotFound, ecatunsort->name); SETUPBUF(ecatunsort->f, catrec); if (*gcatunsort->name != '\0') { if (gcatunsort->f != NULL) gcatunsort->f = freopen(gcatunsort->name, "wb", gcatunsort->f); else gcatunsort->f = fopen(gcatunsort->name, "wb"); } else { if (gcatunsort->f != NULL) rewind(gcatunsort->f); else gcatunsort->f = tmpfile(); } if (gcatunsort->f == NULL) _EscIO2(FileNotFound, gcatunsort->name); SETUPBUF(gcatunsort->f, catrec); /* in the following each lib is searched for its embl type entries, is reset, and then searched for its genbank entries */ call(dbl1, ecatunsort, gcatunsort, 1); call(dbl2, ecatunsort, gcatunsort, 2); call(dbl3, ecatunsort, gcatunsort, 3); call(dbl4, ecatunsort, gcatunsort, 4); call(dbl5, ecatunsort, gcatunsort, 5); call(dbl6, ecatunsort, gcatunsort, 6); call(dbl7, ecatunsort, gcatunsort, 7); call(dbl8, ecatunsort, gcatunsort, 8); catentry(ecatunsort, gcatunsort); /* catalogs contain every lib entry, but perhaps not in alphanumeric order */ mergesort(ecatunsort, ecat); mergesort(gcatunsort, gcat); /* next section adds computer system date to catalogs and libraries to make checking for mismatched information quick and simple */ catlibdate(dbl1, dbl2, dbl3, dbl4, dbl5, dbl6, dbl7, dbl8, ecat, gcat); } /* order */ /* end module dbcat.order */ main(argc, argv) int argc; Char *argv[]; { PASCAL_MAIN(argc, argv); if (setjmp(_JL1)) goto _L1; dbl8.f = NULL; strcpy(dbl8.name, "dbl8"); dbl7.f = NULL; strcpy(dbl7.name, "dbl7"); dbl6.f = NULL; strcpy(dbl6.name, "dbl6"); dbl5.f = NULL; strcpy(dbl5.name, "dbl5"); dbl4.f = NULL; strcpy(dbl4.name, "dbl4"); dbl3.f = NULL; strcpy(dbl3.name, "dbl3"); dbl2.f = NULL; strcpy(dbl2.name, "dbl2"); dbl1.f = NULL; strcpy(dbl1.name, "dbl1"); gcat.f = NULL; strcpy(gcat.name, "gcat"); gcatunsort.f = NULL; *gcatunsort.name = '\0'; ecat.f = NULL; strcpy(ecat.name, "ecat"); ecatunsort.f = NULL; *ecatunsort.name = '\0'; lib.f = NULL; *lib.name = '\0'; cat.f = NULL; *cat.name = '\0'; printf(" DBCAT %4.2f\n", version); order(&dbl1, &dbl2, &dbl3, &dbl4, &dbl5, &dbl6, &dbl7, &dbl8, &ecatunsort, &ecat, &gcatunsort, &gcat); _L1: if (cat.f != NULL) fclose(cat.f); if (lib.f != NULL) fclose(lib.f); if (ecatunsort.f != NULL) fclose(ecatunsort.f); if (ecat.f != NULL) fclose(ecat.f); if (gcatunsort.f != NULL) fclose(gcatunsort.f); if (gcat.f != NULL) fclose(gcat.f); if (dbl1.f != NULL) fclose(dbl1.f); if (dbl2.f != NULL) fclose(dbl2.f); if (dbl3.f != NULL) fclose(dbl3.f); if (dbl4.f != NULL) fclose(dbl4.f); if (dbl5.f != NULL) fclose(dbl5.f); if (dbl6.f != NULL) fclose(dbl6.f); if (dbl7.f != NULL) fclose(dbl7.f); if (dbl8.f != NULL) fclose(dbl8.f); exit(EXIT_SUCCESS); } /* dbcat */ /* End. */