/* Output from p2c 1.21alpha-07.Dec.93, the Pascal-to-C translator */ /* From input file "dbpull.p" */ #include /* dbpull: database access program by matthew yarus module libraries required: delman, delmods */ /* used to halt program */ /* begin module version */ #define version 2.49 /* of dbpull.p 1998 July 16 1998 July 16: upgrade to datetimearray, upgrade to use accession instead of locus name. origin before 1983 july 14 */ /* end module version */ /* begin module describe.dbpull */ /* name dbpull: database extraction program. synopsis dbpull (fin: in, fout: out, dbl1, dbl2, dbl3, dbl4, dbl5, dbl6, dbl7, dbl8: in, ecat: in, gcat: in, output: out) files fin: User requests for extractions from libraries. Each request takes up a single line and consists of a genetic sequence identi- fication code followed by either a single special extraction code or a series of line code requests. If an entry request is to be found in embl format the request line must have a line containing simply 'embl' somewhere above it. A line containing only 'genb' will instruct dbpull to look only for genbank format entries on the following request lines. Important note: the exact form of fin instructions is found in delman.use.dbpull.instructions. If no request is given, then ALL is assumed. This means that the program will now run using a raw list of entry names. fout: contains fulfilled requests in the same entry order as fin. this file may serve, itself, as a database library for dbpull as long as 'id ' or 'loc' occur with every request.(one of these two line codes identifies the beginning of each entry and holds its id) dbl1-dbl8: same files, in the same order, as dbcat. see delman. describe.dbcat. ecat: same as in dbcat also. gcat: same as in dbcat also. output: messages to the user. description this program uses catalogs generated by the dbcat program to quickly extract all or part of embl or genb type entries from data base lib- raries. the user may choose one of two special requests('all', which pulls out an entire entry or 'raw', which pulls out only the genetic sequence) or s-he may simply request a number of line codes. the wild- card character '*' represents any number of unspecified characters in an id request. this allows one fin line to extract several entries whose ids have characters in common. the id 'every' extracts all ids it is compared to. dbpull also checks the production dates of all the catalogs and libraries to see that they are consistent. documentation dbhelp, delman.describe.dbcat, embl and genbank libaries. see also dbcat.p author matthew yarus bugs technical notes 1:dbpull functions on genbank(tm) release 9 (june 1, 1983). 2: if the value of the constant checknum is increased, dbpull will do a more complete check of its catalogs. */ /* end module describe.dbpull */ /* begin module dbpull.constant */ /* 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' */ /* more constants */ #define idlength 20 /* length of identification code of a library entry */ #define namelength idlength /* length of computer system date */ #define lclength 3 /* length of code at beginning of each library line */ #define libtotal 8 /* number of libraries used in program */ #define lctotal 20 /* maximum number of line code requests */ #define checknum 1 /* controls the number of times certain procedures run */ /* the following constants are used for string comparisons by the functions lcequal and idequal. if your computer system does not do these packed array comparisons, the functions must be re- written and the constants replaced by a series of assignment statements to declared arrays. */ #define spraw "RAW" /* special fin request that pulls only sequence */ #define spall "ALL" /* special request that pulls whole entry */ #define lcloc "LOC" /* short for locus, line code(lc) for genb entry beginning point. this line contains id of entry */ #define lcid "ID " /* begining point of embl entry, also holds id */ #define lc3spc " " /* three space line code always identifies sequence lines of an embl type entry */ #define lcxx "XX " /* marks the end of a string of one or more embl lines having the same line code */ #define lct " T" /* first letter of title, part of reference section of genb entry. if you pull 'ref', you pull ' t' */ #define lca " A" /* first letter of author, part of reference section of a genb entry. if you pull 'ref', you pull ' a' */ #define lcj " J" /* first letter of journal, part of ref also */ #define lcori "ORI" /* short for origin, code for line just above sequence in genbank entries */ #define lcsit "SIT" /* short for sites, line just below sequence in genb */ #define lcterm "// " /* terminus code at the end of every entry */ #define lcdat "DAT" /* short for date, used for dateline of libraries */ #define idembl "EMBL " /* fin line indicating that following lines contain embl requests */ #define idgenb "GENB " /* following lines are for genb requests */ #define idgenbank "GENBANK " /* ' ' */ #define iddate "DATE " /* catalogs of undated libraries use this as the date */ #define idevery "EVERY " /* special id that matches any id it is compared to */ /* end module dbpull.constant */ /* begin module datetime.type */ /* array for dates */ typedef Char datetimearray[datetimearraylength]; /* end module datetime.type version = 'cdatemod.p 1.19 1999Dec13'; */ /* begin module dbpull.type */ /* a 'u' after the 'lc' or 'id' in 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]; /* holds id for reading-writing before packing */ typedef Char idptype[idlength]; /* holds 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 a library where an entry begins */ } catrec; typedef struct dbcat { FILE *f; FILEBUFNC(f,catrec); Char name[_FNSIZE]; } dbcat; /* structure of whole catalog */ typedef Char lcutype[lclength]; /* holds library line code for reading-writing before packing */ typedef Char lcptype[lclength]; /* holds line code for string comparisons */ typedef Char lcstype[lctotal][lclength]; /* holds fin line code requests */ typedef char countype; /* subrange for handling line codes */ typedef enum { embl, genb } libsused; /* used to indicate whether requested entry is of embl or genbank type */ typedef enum { notwc, xwc, wcx, xwcx } wctype; /* used to indicate whether or not an id request is wildcard and if wc whether the set characters are in front, in back, or in the middle of the variable characters. the 'x' represents the variable part of the id */ /* end module dbpull.type */ /* begin module dbpull.var */ Static dbcat cat; /* any catalog */ Static _TEXT lib; /* any library */ Static dbcat gcat, ecat; /* embl and genbank catalogs from dbcat program */ Static _TEXT dbl1, dbl2, dbl3, dbl4, dbl5, dbl6, dbl7, dbl8; /* 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 */ Static _TEXT fin, fout; Static jmp_buf _JL1; /* requests for extraction from libraries and output file with fulfilled requests */ /* end module dbpull.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.40; {of delmod.p 2000 Feb 18} */ /* 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.40; {of delmod.p 2000 Feb 18} */ /* 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.40; {of delmod.p 2000 Feb 18} */ /* ************************************************************************ */ /* end module package.primitive version = 7.40; {of delmod.p 2000 Feb 18} */ /* 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: dbpull.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: dbpull.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: dbpull.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] = ' '; } } /* the following loop fills out id if id is too short */ while (index < idlength) { index++; finidu[index-1] = ' '; } memcpy(finidp, finidu, sizeof(idptype)); } /* getid */ /* end module dbpull.getid */ /* 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: dbpull.p, line 348: 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 dbpull.findaline */ Static Void findaline(lib, line, current) _TEXT *lib; long line, *current; { /* see global */ /* the line requested */ /* the line where the lib cursor currently lies */ /* get to a line in lib from current line. the variable current = line after findaline is done */ if (*current >= line) { 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); *current = 1; } /* the line is above where we are or we are in the middle of a line we want to get to the beginning of */ while ((*current < line) & (!BUFEOF(lib->f))) { (*current)++; fscanf(lib->f, "%*[^\n]"); getc(lib->f); } if (!BUFEOF(lib->f)) return; printf(" DBCAT REFERS TO A LINE (%ld) THAT IS PAST THE END OF A LIBRARY.\n", line); printf(" ARE ALL LIBRARIES PRESENT ?\n"); halt(); } /* findaline */ Local Void checklc(lib) _TEXT *lib; { /* data base library */ /* checks to see if a catalog referred entry starts with a proper line code */ lcutype liblcu; /* holds line code for reading-writing before packing */ lcptype liblcp; /* holds a line code for string comparisons */ readlcu(lib, liblcu, liblcp); /*zzz This check can't be done anymore because the ACCESSION is used and not the locus name! if not ( lcequal ( liblcp, lcid ) or lcequal ( liblcp, lcloc )) then begin writeln ( output, ' DATA BASE LIBARIES ARE EITHER IN THE WRONG' ); writeln ( output, ' ORDER OR THEY ARE NOT EVEN EMBL OR GENBANK' ); writeln ( output, ' FORMAT AT ALL' ); halt end; */ } /* checklc */ Local Void getentry(dbl1, dbl2, dbl3, dbl4, dbl5, dbl6, dbl7, dbl8, cat, c1, c2, c3, c4, c5, c6, c7, c8) _TEXT *dbl1, *dbl2, *dbl3, *dbl4, *dbl5, *dbl6, *dbl7, *dbl8; dbcat *cat; long *c1, *c2, *c3, *c4, *c5, *c6, *c7, *c8; { /* catalog produced by dbcat */ /* 'c' stands for current library line */ /* gets to an entry referred to in a catalog and then calls checklc */ switch (GETFBUF(cat->f, catrec).libnum) { case 1: findaline(dbl1, GETFBUF(cat->f, catrec).linenumber, c1); checklc(dbl1); break; case 2: findaline(dbl2, GETFBUF(cat->f, catrec).linenumber, c2); checklc(dbl2); break; case 3: findaline(dbl3, GETFBUF(cat->f, catrec).linenumber, c3); checklc(dbl3); break; case 4: findaline(dbl4, GETFBUF(cat->f, catrec).linenumber, c4); checklc(dbl4); break; case 5: findaline(dbl5, GETFBUF(cat->f, catrec).linenumber, c5); checklc(dbl5); break; case 6: findaline(dbl6, GETFBUF(cat->f, catrec).linenumber, c6); checklc(dbl6); break; case 7: findaline(dbl7, GETFBUF(cat->f, catrec).linenumber, c7); checklc(dbl7); break; case 8: findaline(dbl8, GETFBUF(cat->f, catrec).linenumber, c8); checklc(dbl8); break; } } /* getentry */ /* end module dbpull.findaline */ /* begin module dbpull.entrycheck */ Static Void entrycheck(dbl1, dbl2, dbl3, dbl4, dbl5, dbl6, dbl7, dbl8, cat1, cat2, c1, c2, c3, c4, c5, c6, c7, c8) _TEXT *dbl1, *dbl2, *dbl3, *dbl4, *dbl5, *dbl6, *dbl7, *dbl8; dbcat *cat1, *cat2; long *c1, *c2, *c3, *c4, *c5, *c6, *c7, *c8; { /* libs of data bases, cats produced by dbcat */ /* 'c' stands for current library line */ /* checks libaries by looking for a few entries referred to in the catalogs */ long index; /* loop counter */ 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); *c1 = 1; *c2 = 1; *c3 = 1; *c4 = 1; *c5 = 1; *c6 = 1; *c7 = 1; *c8 = 1; for (index = 1; index <= checknum; index++) { if (!BUFEOF(cat1->f)) { GET(cat1->f, catrec); if (!BUFEOF(cat1->f)) getentry(dbl1, dbl2, dbl3, dbl4, dbl5, dbl6, dbl7, dbl8, cat1, c1, c2, c3, c4, c5, c6, c7, c8); } if (!BUFEOF(cat2->f)) { GET(cat2->f, catrec); if (!BUFEOF(cat2->f)) getentry(dbl1, dbl2, dbl3, dbl4, dbl5, dbl6, dbl7, dbl8, cat2, c1, c2, c3, c4, c5, c6, c7, c8); } } 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 (*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); *c1 = 1; *c2 = 1; *c3 = 1; *c4 = 1; *c5 = 1; *c6 = 1; *c7 = 1; *c8 = 1; /* all libraries start at line one */ } /* entrycheck */ /* Local variables for datecheck: */ struct LOC_datecheck { lcutype liblcu; /* holds the line code of the first line of a lib */ lcptype liblcp; } ; Local Void libcheck(lib, libpresent, libmatch, libcount, adatetime, LINK) _TEXT *lib; boolean *libpresent, *libmatch; lnrange *libcount; Char *adatetime; struct LOC_datecheck *LINK; { /* global */ /* counts non-empty libs */ /* counts libaries and checks dates for match to catalog dates */ long index; /* loop counter */ Char dumpchar; /* holds unwanted character */ datetimearray libidp; /* the id, in this case, is the date of a lib */ if (BUFEOF(lib->f)) return; *libpresent = true; (*libcount)++; readlcu(lib, LINK->liblcu, LINK->liblcp); if (!lcequal(LINK->liblcp, lcdat)) { /* no date line in the library */ libidp[0] = 'D'; libidp[1] = 'A'; libidp[2] = 'T'; libidp[3] = 'E'; /* 'date' with 16 spaces after it will match the catalog null date code */ for (index = 4; index < idlength; index++) libidp[index] = ' '; } else { dumpchar = getc(lib->f); /* dumps the 'e' in 'date' */ if (dumpchar == '\n') dumpchar = ' '; do { getc(lib->f); } while (P_peek(lib->f) == ' '); readdatetime(lib, libidp); } if (*libmatch) *libmatch = datesequal(libidp, adatetime); } /* libcheck */ /* end module dbpull.entrycheck */ /* begin module dbpull.datecheck */ Static Void datecheck(dbl1, dbl2, dbl3, dbl4, dbl5, dbl6, dbl7, dbl8, cat1, cat2) _TEXT *dbl1, *dbl2, *dbl3, *dbl4, *dbl5, *dbl6, *dbl7, *dbl8; dbcat *cat1, *cat2; { /* see global for all */ /* checks to see that there are the proper number of libraries and catalogs and that all files have the same date */ struct LOC_datecheck V; long index; /* loop counter */ /* same as liblcu but used for string comparison to string constant lcdat */ datetimearray adatetime; /* holds the date of a catalog for comparison to the dates of other cats and libs */ boolean libpresent = false; /* 'true' if at least one lib is not empty */ boolean libmatch = true; /* 'true' indicates that two dates are equal */ lnrange libcount = 0; /* holds number of non-empty libraries */ 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 (*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 (BUFEOF(cat1->f) | BUFEOF(cat2->f)) { printf(" A DATABASE CATALOG IS MISSING\n"); halt(); } else { for (index = 0; index < idlength; index++) adatetime[index] = GETFBUF(cat1->f, catrec).idp[index]; if (!datesequal(adatetime, GETFBUF(cat2->f, catrec).idp)) { printf(" DATABASE CATALOGS DO NOT MATCH\n"); halt(); } } libcheck(dbl1, &libpresent, &libmatch, &libcount, adatetime, &V); libcheck(dbl2, &libpresent, &libmatch, &libcount, adatetime, &V); libcheck(dbl3, &libpresent, &libmatch, &libcount, adatetime, &V); libcheck(dbl4, &libpresent, &libmatch, &libcount, adatetime, &V); libcheck(dbl5, &libpresent, &libmatch, &libcount, adatetime, &V); libcheck(dbl6, &libpresent, &libmatch, &libcount, adatetime, &V); libcheck(dbl7, &libpresent, &libmatch, &libcount, adatetime, &V); libcheck(dbl8, &libpresent, &libmatch, &libcount, adatetime, &V); if (!libpresent) { printf(" NO DATABASE LIBRARIES ARE PRESENT\n"); halt(); } else if (!libmatch) { printf(" DATABASE LIBRARIES DO NOT MATCH CATALOGS\n"); halt(); } if (!((libcount != GETFBUF(cat1->f, catrec).libnum) | (libcount != GETFBUF(cat2->f, catrec).libnum))) return; printf(" YOU HAVE A DIFFERENT NUMBER OF LIBRARIES\n"); printf(" THEN YOUR CATALOGS REFER TO.\n"); halt(); } /* datecheck */ /* end module dbpull.datecheck */ /* begin module dbpull.makearray */ Static Void makearray(fin, finlcs, lcnum) _TEXT *fin; Char (*finlcs)[lclength]; long *lcnum; { /* see global */ /* holds all requested library line codes for a given id */ /* holds number of line codes requested */ /* builds a two dimensional array(finlcs) containing all requested library line codes for a given id request */ long index; /* counter for repeat loop */ *lcnum = 0; /* no codes counted yet */ do { /* makes a slot for each 3-letter code */ (*lcnum)++; while ((P_peek(fin->f) == ' ') & (!P_eoln(fin->f))) getc(fin->f); index = 0; /* loop initialization value */ do { /* stores line code */ index++; if (P_eoln(fin->f) | (P_peek(fin->f) == ' ')) finlcs[*lcnum - 1][index-1] = ' '; else { finlcs[*lcnum - 1][index-1] = getc(fin->f); if (finlcs[*lcnum - 1][index-1] == '\n') finlcs[*lcnum - 1][index-1] = ' '; } } while (index != lclength); while ((!P_eoln(fin->f)) & (P_peek(fin->f) != ' ')) /* only first few characters of line request used */ getc(fin->f); while ((P_peek(fin->f) == ' ') & (!P_eoln(fin->f))) /* gets rid of extra spaces on end of fin line */ getc(fin->f); } while (!(P_eoln(fin->f) || *lcnum == lctotal)); fscanf(fin->f, "%*[^\n]"); getc(fin->f); } /* makearray */ /* end module dbpull.makearray */ /* begin module dbpull.wccheck */ Static Void wccheck(finidp, finidnum, wildcard) Char *finidp; long *finidnum; wctype *wildcard; { /* holds a requested id */ /* holds number of characters in finidp */ /* holds one of four id request types */ /* decides how many characters are in each finidp and to which of the four wildcard types the id belongs */ long index = 1; /* counter for loop */ boolean done = false; /* 'true' indicates that finidp is full of chars */ /* loop initialization */ /* ' ' */ if (finidp[index-1] == '*') { index++; while (finidp[index-1] != ' ' && !done) { if (finidp[index-1] == '*') *wildcard = xwcx; else *wildcard = xwc; if (index < idlength) index++; else done = true; } } else { index++; while (finidp[index-1] != ' ' && !done) { if (finidp[index-1] == '*') *wildcard = wcx; else *wildcard = notwc; if (index < idlength) index++; else done = true; } } if (index == idlength) *finidnum = index; else { *finidnum = index - 1; /* the index is one ahead because it has to be initialized at 1 instead of 0(the array definition is 1..idlength) */ } } /* wccheck */ /* end module dbpull.wccheck */ /* begin module dbpull.idhandle */ Static Void idhandle(cat, unequal, wildcard, finidp, finidnum) dbcat *cat; boolean *unequal; wctype wildcard; Char *finidp; long finidnum; { /* see global */ /* 'true' indicates that finidp <> catalog id */ /* holds one of four id request types(three are wc) */ /* holds fin id request code */ /* number of chars in finidp */ /* decides whether finidp and cat^.idp are equal */ long index; /* loop counter */ long catidnum = 0; /* holds number of non-space characters in catalog id */ long placef; /* index for the position of the finidp array that is being used in comparisons */ long startf; /* starting point for placef */ long placec; /* same function as placef, but used on cat^idp */ long startc; /* starting point for placec */ long sclimit; /* holds upper limit of startc */ for (index = 0; index < idlength; index++) { if (GETFBUF(cat->f, catrec).idp[index] != ' ') catidnum++; } if (finidnum > catidnum) { *unequal = true; return; } *unequal = false; switch (wildcard) { case notwc: *unequal = !(idequal(GETFBUF(cat->f, catrec).idp, finidp) | idequal(finidp, idevery)); break; /* 'every' request matches all ids */ case xwc: placef = 2; /* skips first '*' */ placec = catidnum - finidnum + 2; /* previous assignment lines up the right hand ends of the two compared ids */ while (placef <= finidnum && !*unequal) { if (finidp[placef-1] != GETFBUF(cat->f, catrec).idp[placec-1]) *unequal = true; placef++; placec++; } break; case wcx: placef = 1; placec = 1; while (!*unequal && placef < finidnum) { if (finidp[placef-1] != GETFBUF(cat->f, catrec).idp[placec-1]) *unequal = true; placef++; placec++; } break; case xwcx: startf = 2; /* skips the first '*' */ startc = 1; sclimit = catidnum - finidnum + 2; /* previous assignment stops the matching procedure at the point where the right hand ends are lined up */ *unequal = true; /* the first while loop advances the section of the cat^.idp being checked while the second loop does the actual check */ while (startc <= sclimit && *unequal) { placef = startf; placec = startc; *unequal = false; while (!*unequal && placef < finidnum) { if (finidp[placef-1] != GETFBUF(cat->f, catrec).idp[placec-1]) *unequal = true; placef++; placec++; } startc++; } break; } } /* idhandle */ /* end module dbpull.idhandle */ /* begin module dbpull.alphacheck */ Static Void alphacheck(cat, wildcard, finidp) dbcat *cat; wctype wildcard; Char *finidp; { /* see global */ /* holds one of four id request types (three are wc) */ /* holds a requested library id */ /* checks id to see whether or not it will be found nearer to beginning of catalog than current cursor position. if so, catalog is reset. */ long index = 0; /* counter for repeat loop */ boolean closertoa = false; /* 'true' indicates current idp is nearer to beginning of catalog than cursor */ if (BUFEOF(cat->f)) { 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); /* skips date */ GET(cat->f, catrec); /* loop initialization value */ return; } /* '' */ do { index++; if ((finidp[index-1] < GETFBUF(cat->f, catrec).idp[index-1] || wildcard != notwc) | idequal(finidp, idevery)) { /* all wilcard ids reset catalog because there is an indeterminable possibility of a match with a previous id */ closertoa = true; 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); /* skips date */ GET(cat->f, catrec); } } while (!(closertoa || index == idlength)); } /* alphacheck */ /* end module dbpull.alphacheck */ /* begin module dbpull.copylib */ Static Void copylib(lib, c, libtitle, lcnum, finlcs) _TEXT *lib; long *c; libsused libtitle; long lcnum; Char (*finlcs)[lclength]; { /* see global */ /* the current line of library */ /* indicates whether reqested entry is of embl or genbank type */ /* holds the number of line codes requested for each id */ /* holds line codes */ /* copies lines from an entry which correspond to requested line codes */ long index; /* loop counter */ long index2; /* '' */ long dumpint; /* a place for unwanted integers */ long lccount; /* counts the number of line code requests that have been satisfied */ Char lcsfound[lctotal]; /* indicates which line codes from a request line occur in an entry */ boolean nextlc; /* 'true' indicates that all lines pertaining to a particular line code have been copied */ lcptype finlcp; /* holds a requested line code */ lcptype liblcp; /* holds line code of line being compared to reqested code */ lcutype liblcu; /* holds lib line code for reading-writing before packing */ lcptype liblcp2; /* holds linecode for comparison to previous code */ lcutype liblcu2; /* holds second line code, like liblcp2, but used reading in */ for (index = 0; index < lclength; index++) finlcp[index] = finlcs[0][index]; if (lcequal(finlcp, spall)) { /* first special request code */ do { readlcu(lib, liblcu, liblcp); for (index = 0; index < lclength; index++) putc(liblcu[index], fout.f); copyaline(lib, &fout); (*c)++; } while (!lcequal(liblcp, lcterm)); } else if (lcequal(finlcp, spraw)) { /* second special code */ switch (libtitle) { case embl: do { readlcu(lib, liblcu, liblcp); if (lcequal(liblcp, lc3spc)) copyaline(lib, &fout); else { fscanf(lib->f, "%*[^\n]"); getc(lib->f); } (*c)++; fprintf(fout.f, ".\n"); } while (!lcequal(liblcp, lcterm)); break; case genb: do { /* finds line, marked 'origin', which is right above sequence */ readlcu(lib, liblcu, liblcp); fscanf(lib->f, "%*[^\n]"); getc(lib->f); (*c)++; } while (!lcequal(liblcp, lcori)); /* following loop copies lib until a line, marked 'sites', that is found right after sequence */ while ((!lcequal(liblcp, lcsit)) & (!lcequal(liblcp, lcterm))) { fscanf(lib->f, "%ld", &dumpint); /* coordinate value unneeded */ copyaline(lib, &fout); (*c)++; readlcu(lib, liblcu, liblcp); } /* above line required because sometimes there is no sites section after sequence */ fprintf(fout.f, ".\n"); break; } } else { /* ' ' */ nextlc = false; /* loop initialization */ lccount = 0; for (index = 0; index < lctotal; index++) lcsfound[index] = 'N'; /* 'n' represents an lc yet to be found */ do { if (nextlc) { for (index = 0; index < lclength; index++) liblcp[index] = liblcp2[index]; } else readlcu(lib, liblcu, liblcp); index2 = 0; /* loop initialization */ do { /* checks fin line codes against current lib lc */ index2++; index = 0; /* loop initialization */ do { /* grabs a fin line code request */ index++; finlcp[index-1] = finlcs[index2-1][index-1]; } while (index != lclength); } while (!((index2 == lcnum) | lcequal(finlcp, liblcp))); if ((!lcequal(finlcp, liblcp)) | lcequal(finlcp, lc3spc) | lcequal(finlcp, lcterm)) { /* ' ' represents an error of extra spaces after fin line code and '// ' is unnecessary because terminus is installed after every embl request, so both these codes are ignored */ nextlc = false; /* we have not advanced to next code */ if (!BUFEOF(lib->f)) { fscanf(lib->f, "%*[^\n]"); getc(lib->f); } (*c)++; } else { lcsfound[index2-1] = 'F'; /* liblcp = finlcp so, 'f' represents found */ memcpy(liblcu, liblcp, sizeof(lcutype)); for (index = 0; index < lclength; index++) putc(liblcu[index], fout.f); copyaline(lib, &fout); (*c)++; do { /* this loop copies lines that are 1: not marked by line codes but are related to previous code or 2: have codes equal to previous requested code */ readlcu(lib, liblcu2, liblcp2); if (lcequal(liblcp2, liblcp) | lcequal(liblcp2, lc3spc) | lcequal(liblcp2, lct) | lcequal(liblcp2, lca) | lcequal(liblcp2, lcj) | lcequal(liblcp2, lcxx)) { for (index = 0; index < lclength; index++) putc(liblcu2[index], fout.f); copyaline(lib, &fout); (*c)++; } else nextlc = true; /* we have advanced to next code */ } while (!nextlc); lccount++; } } while (!((lcequal(liblcp, lcterm) || lccount == lcnum) | BUFEOF(lib->f))); fprintf(fout.f, "// \n"); /* fout library terminus code */ index = 0; do { index++; } while (index != lcnum && lcsfound[index-1] != 'N'); if (lcsfound[index-1] == 'N') { /* at least one lc not found */ printf(" REQUESTED ENTRY DID NOT CONTAIN THESE\n"); printf(" LINE CODES-- "); for (index = 0; index < lcnum; index++) { if (lcsfound[index] == 'N') { for (index2 = 0; index2 < lclength; index2++) putchar(finlcs[index][index2]); putchar(' '); } } putchar('\n'); /* no special codes requested */ } } putc('\n', fout.f); /* blank between entries */ /*zzz*/ } /* copylib */ /* end module dbpull.copylib */ /* 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 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); } /* end module writedatetime version = 'cdatemod.p 1.19 1999Dec13'; */ /* begin module dbpull.getlib */ Static Void getlib(cat, dbl1, dbl2, dbl3, dbl4, dbl5, dbl6, dbl7, dbl8, c1, c2, c3, c4, c5, c6, c7, c8, libtitle, wildcard, finlcs_, finidp, finidnum, lcnum, dated) dbcat *cat; _TEXT *dbl1, *dbl2, *dbl3, *dbl4, *dbl5, *dbl6, *dbl7, *dbl8; long *c1, *c2, *c3, *c4, *c5, *c6, *c7, *c8; libsused libtitle; wctype wildcard; Char (*finlcs_)[lclength]; Char *finidp; long finidnum, lcnum; boolean *dated; { /* see global for cat and libs below */ /* 'c' stands for current library line */ /* holds one of four id request types (three are wc) */ /* contains all line codes for a given id request */ /* holds a requested id */ /* holds number of chars in finidp */ /* holds the number of line codes for a given id request */ /* 'true' indicates that the computer system date has been added to fout */ /* finds position in library of requested id by looking in catalog and gets to appropriate position in library */ lcstype finlcs; long index; /* repeat loop counter */ idutype finidu; /* holds id for writing it to output */ datetimearray adatetime; /* holds the computer system date */ boolean unequal; /* 'true' indicates that catalog id does not match fin requested id */ boolean finish = false; /* 'true' indicates that fin id request has been satisfied */ boolean idnotfound = true; /* 'true' indicates that fin id request does not match any ids occuring in a catalog */ lcptype lchold; /* holds first line code stored in finlcs */ memcpy(finlcs, finlcs_, sizeof(lcstype)); for (index = 0; index < lclength; index++) lchold[index] = finlcs[0][index]; if (lcequal(lchold, lc3spc)) { /* writeln ( output, ' CODE(S) REQUESTING PART OR ALL OF AN ENTRY' ); writeln ( output, ' MUST NORMALLY FOLLOW EACH ID REQUEST' ); writeln (output, 'However, I''ll be nice and make them ALL'); */ /* If no request was found, make the request be ALL */ memcpy(lchold, spall, sizeof(lcptype)); finlcs[0][0] = 'A'; finlcs[0][1] = 'L'; finlcs[0][2] = 'L'; } if (!*dated) { if (lcequal(lchold, spraw)) *dated = true; /* 'raw' requests are not dated */ else { getdatetime(adatetime); fprintf(fout.f, "DATE "); adatetime[19] = ' '; writedatetime(&fout, adatetime); putc('\n', fout.f); *dated = true; } } /* loop initialization */ /* ' ' */ do { idhandle(cat, &unequal, wildcard, finidp, finidnum); if (unequal & BUFEOF(cat->f)) { 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 (unequal & (!BUFEOF(cat->f))) GET(cat->f, catrec); else { idnotfound = false; switch (GETFBUF(cat->f, catrec).libnum) { case 0: printf(" PROGRAM ERROR IN GETLIB\n"); /* this should never happen, 0 allowed for purposes of loop initialization */ halt(); break; case 1: findaline(dbl1, GETFBUF(cat->f, catrec).linenumber, c1); copylib(dbl1, c1, libtitle, lcnum, finlcs); break; case 2: findaline(dbl2, GETFBUF(cat->f, catrec).linenumber, c2); copylib(dbl2, c2, libtitle, lcnum, finlcs); break; case 3: findaline(dbl3, GETFBUF(cat->f, catrec).linenumber, c3); copylib(dbl3, c3, libtitle, lcnum, finlcs); break; case 4: findaline(dbl4, GETFBUF(cat->f, catrec).linenumber, c4); copylib(dbl4, c4, libtitle, lcnum, finlcs); break; case 5: findaline(dbl5, GETFBUF(cat->f, catrec).linenumber, c5); copylib(dbl5, c5, libtitle, lcnum, finlcs); break; case 6: findaline(dbl6, GETFBUF(cat->f, catrec).linenumber, c6); copylib(dbl6, c6, libtitle, lcnum, finlcs); break; case 7: findaline(dbl7, GETFBUF(cat->f, catrec).linenumber, c7); copylib(dbl7, c7, libtitle, lcnum, finlcs); break; case 8: findaline(dbl8, GETFBUF(cat->f, catrec).linenumber, c8); copylib(dbl8, c8, libtitle, lcnum, finlcs); break; } if ((wildcard == notwc) & (!idequal(finidp, idevery))) /* wc id might match other cat id"s */ finish = true; GET(cat->f, catrec); } } while (!(BUFEOF(cat->f) || finish)); /* id"s are equal */ if (!idnotfound) return; printf(" ID "); memcpy(finidu, finidp, sizeof(idutype)); for (index = 0; index < idlength; index++) putchar(finidu[index]); printf(" NOT FOUND"); if (libtitle == embl) printf(" IN EMBL\n"); else printf(" IN GENBANK\n"); if (wildcard == notwc) { /* wc searches are more general, so they allow for guesses at possible ids */ halt(); } } /* getlib */ /* end module dbpull.getlib */ /* begin module dbpull.order */ Static Void order(dbl1, dbl2, dbl3, dbl4, dbl5, dbl6, dbl7, dbl8, ecat, gcat) _TEXT *dbl1, *dbl2, *dbl3, *dbl4, *dbl5, *dbl6, *dbl7, *dbl8; dbcat *ecat, *gcat; { /* see global for all */ /* orders all other procedures */ idptype finidp; /* holds requested id */ long finidnum; /* holds number of chars(non-space) in finidp */ long lcnum; /* represents the total number of different line codes associated with a given request */ lcstype finlcs; /* 2d array that holds fin line code requests */ wctype wildcard; /* holds one of four id request types, three of which are wildcard and one just regular. one wc type has the variable length wc section in front of the set request chars, one has it in back, and one has it in front and back */ libsused libtitle; /* indicates whether lib request is of embl or genbank type */ long c1, c2, c3, c4, c5, c6, c7, c8; /* 'c' stands for current library line */ boolean firstline = true; /* 'true' indicates that file cursor is on the first line of fin */ boolean dated = false; /* 'true' indicates that the computer system date has been added to fout(except in 'raw' special request where no date is required) */ if (*fin.name != '\0') { if (fin.f != NULL) fin.f = freopen(fin.name, "r", fin.f); else fin.f = fopen(fin.name, "r"); } else rewind(fin.f); if (fin.f == NULL) _EscIO2(FileNotFound, fin.name); RESETBUF(fin.f, Char); if (*fout.name != '\0') { if (fout.f != NULL) fout.f = freopen(fout.name, "w", fout.f); else fout.f = fopen(fout.name, "w"); } else { if (fout.f != NULL) rewind(fout.f); else fout.f = tmpfile(); } if (fout.f == NULL) _EscIO2(FileNotFound, fout.name); SETUPBUF(fout.f, Char); if (BUFEOF(fin.f)) { printf(" INPUT FILE FIN IS EMPTY\n"); halt(); } datecheck(dbl1, dbl2, dbl3, dbl4, dbl5, dbl6, dbl7, dbl8, ecat, gcat); entrycheck(dbl1, dbl2, dbl3, dbl4, dbl5, dbl6, dbl7, dbl8, ecat, gcat, &c1, &c2, &c3, &c4, &c5, &c6, &c7, &c8); while (!BUFEOF(fin.f)) { getid(&fin, finidp); makearray(&fin, finlcs, &lcnum); wccheck(finidp, &finidnum, &wildcard); if (firstline) { if (idequal(finidp, idembl)) { /* fin line indicating that following lines are for embl entry type requests */ libtitle = embl; } else if (idequal(finidp, idgenbank) | idequal(finidp, idgenb)) /* following lines genb */ libtitle = genb; else { printf(" Since the first line of fin does indicate which database to use,\n"); printf(" GENBANK was assumed\n"); if (*fin.name != '\0') { if (fin.f != NULL) fin.f = freopen(fin.name, "r", fin.f); else fin.f = fopen(fin.name, "r"); } else rewind(fin.f); if (fin.f == NULL) _EscIO2(FileNotFound, fin.name); RESETBUF(fin.f, Char); /* go back for the first entry! */ libtitle = genb; } } else { if (idequal(finidp, idembl)) /* embl lines follow this line */ libtitle = embl; else if (idequal(finidp, idgenb) | idequal(finidp, idgenbank)) /* following lines genb */ libtitle = genb; else if (libtitle == embl) { alphacheck(ecat, wildcard, finidp); getlib(ecat, dbl1, dbl2, dbl3, dbl4, dbl5, dbl6, dbl7, dbl8, &c1, &c2, &c3, &c4, &c5, &c6, &c7, &c8, embl, wildcard, finlcs, finidp, finidnum, lcnum, &dated); } else { alphacheck(gcat, wildcard, finidp); getlib(gcat, dbl1, dbl2, dbl3, dbl4, dbl5, dbl6, dbl7, dbl8, &c1, &c2, &c3, &c4, &c5, &c6, &c7, &c8, libtitle, wildcard, finlcs, finidp, finidnum, lcnum, &dated); } } firstline = false; } } /* order */ /* end module dbpull.order */ main(argc, argv) int argc; Char *argv[]; { PASCAL_MAIN(argc, argv); if (setjmp(_JL1)) goto _L1; fout.f = NULL; strcpy(fout.name, "fout"); fin.f = NULL; strcpy(fin.name, "fin"); 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"); ecat.f = NULL; strcpy(ecat.name, "ecat"); gcat.f = NULL; strcpy(gcat.name, "gcat"); lib.f = NULL; *lib.name = '\0'; cat.f = NULL; *cat.name = '\0'; printf(" DBPULL %4.2f\n", version); order(&dbl1, &dbl2, &dbl3, &dbl4, &dbl5, &dbl6, &dbl7, &dbl8, &ecat, &gcat); _L1: if (cat.f != NULL) fclose(cat.f); if (lib.f != NULL) fclose(lib.f); if (gcat.f != NULL) fclose(gcat.f); if (ecat.f != NULL) fclose(ecat.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); if (fin.f != NULL) fclose(fin.f); if (fout.f != NULL) fclose(fout.f); exit(EXIT_SUCCESS); } /* dbpull */ /* End. */