1: # include "refer..c" 2: extern FILE *in; 3: # define NFLD 30 4: # define TLEN 400 5: char one[ANSLEN]; 6: int onelen ANSLEN; 7: static char dr [100] ""; 8: doref(firline) 9: char *firline; 10: { 11: char buff[QLEN], dbuff[3*QLEN], answer[ANSLEN], temp[TLEN]; 12: char line[LLINE]; 13: char *p, **sr, *flds[NFLD], *r; 14: int nf, nr, alph, query 0, chp, digs; 15: 16: /* get query */ 17: buff[0] = dbuff[0] = 0; 18: while (input(line)) 19: { 20: if (prefix(".]", line)) 21: break; 22: if (control(line[0])) query=1; 23: strcat (query ? dbuff: buff, line); 24: if (strlen(buff)>QLEN) 25: err("buff too big (%d)", strlen(buff)); 26: assert (strlen(dbuff) <3*QLEN); 27: } 28: if (strcmp (buff, "$LIST$\n")==0) 29: { 30: # if D1 31: fprintf(stderr, "dump sorted list\n"); 32: # endif 33: assert ( dbuff[0]==0); 34: dumpold(); 35: return; 36: } 37: answer[0] = 0; 38: # ifdef D1 39: fprintf(stderr, "query is %s\n",buff); 40: # endif 41: for( p=buff; *p; p++) 42: { 43: if (isupper(*p)) *p |= 040; 44: } 45: alph = digs =0; 46: for(p=buff; *p; p++) 47: { 48: if (isalpha(chp = *p)) alph++; 49: else 50: if (isdigit(*p)) digs++; 51: else 52: { 53: *p=0; 54: if ( (alph+digs<3) || common(p-alph)) 55: { 56: r = p-alph; 57: while (r < p) 58: *r++ = ' '; 59: } 60: if ( alph==0 && digs >0) 61: { 62: r = p-digs; 63: # if D1 64: fprintf(stderr, "number, %d long, text is %s\n",digs,r); 65: # endif 66: if (digs != 4 || (atoi(r)/100 != 19)) 67: { 68: while (r<p) 69: *r++ = ' '; 70: } 71: } 72: *p=' '; 73: alph = digs = 0; 74: } 75: } 76: # ifdef D1 77: fprintf(stderr, "query translated to %s\n", buff); 78: # endif 79: one[0]=0; 80: if (buff[0]) /* do not search if no query */ 81: for( sr= data; sr < search; sr++) 82: { 83: # ifdef D1 84: fprintf(stderr, "now searching %s\n", *sr); 85: # endif 86: temp[0]=0; 87: corout (buff, temp, "hunt", *sr, TLEN); 88: assert (strlen(temp)<TLEN); 89: if (strlen(temp)+strlen(answer)>LLINE) 90: err("Accumulated answers too large",0); 91: strcat (answer, temp); 92: if (strlen(answer)>LLINE) 93: err("answer too long (%d)", strlen(answer)); 94: if (newline(answer) > 0) break; 95: } 96: # if D1 97: fprintf(stderr, "answer:\n%s****\n", answer); 98: # endif 99: assert (strlen(one)<ANSLEN); 100: assert (strlen(answer)<ANSLEN); 101: if (buff[0]) 102: switch (newline(answer)) 103: { 104: case 0: 105: fprintf (stderr, "No such paper %s\n", buff); 106: return; 107: default: 108: fprintf(stderr, "too many hits for '%s'\n", trimnl(buff)); 109: choices(answer); 110: p = buff; 111: while (*p != '\n') p++; 112: *++p=0; 113: case 1: 114: # ifdef D1 115: fprintf(stderr, "found one\n"); 116: # endif 117: if (endpush) 118: if (nr = chkdup(answer)) 119: { 120: if (bare<2) 121: putsig (0, flds, nr, firline, line); 122: return; 123: } 124: # if D1 125: fprintf(stderr, "one[0] was %o\n",one[0]); 126: # endif 127: if (one[0]==0) 128: corout (answer, one, "deliv", dr, QLEN); 129: # if D1 130: fprintf(stderr, "one now %o\n",one[0]); 131: # endif 132: break; 133: } 134: assert (strlen(buff)<QLEN); 135: assert (strlen(one)<ANSLEN); 136: nf = tabs(flds, one); 137: nf += tabs(flds+nf, dbuff); 138: # if D1 139: fprintf(stderr, "one %.20s dbuff %.20s nf %d\n",one,dbuff, nf); 140: # endif 141: assert (nf < NFLD); 142: refnum++; 143: if (sort) putkey (nf, flds, refnum, keystr); 144: if (bare<2) 145: putsig (nf, flds, refnum, firline, line); 146: else 147: flout(); 148: # if D1 149: fprintf(stderr, "put signal\n"); 150: # endif 151: putref (nf, flds); 152: # if D1 153: fprintf(stderr, "put ref\n"); 154: # endif 155: } 156: newline(s) 157: char *s; 158: { 159: int k 0, c; 160: while (c = *s++) 161: if (c == '\n') 162: k++; 163: return(k); 164: } 165: choices( buff ) 166: char *buff; 167: { 168: char ob[LLINE], *p, *r, *q, *t; 169: int nl; 170: for(r=p= buff; *p; p++) 171: { 172: if (*p == '\n') 173: { 174: *p++ = 0; 175: { 176: corout (r, ob, "deliv", dr, LLINE); 177: nl = 1; 178: for( q=ob; *q; q++) 179: { 180: if (nl && (q[0] == '.' || q[0] == '%') && q[1] == 'T') 181: { 182: q += 3; 183: for (t=q; *t && *t != '\n'; t++); 184: *t = 0; 185: fprintf(stderr, "%.70s\n", q); 186: q=0; break; 187: } 188: nl = *q == '\n'; 189: } 190: if (q) 191: fprintf(stderr, "??? at %s\n",r); 192: } 193: r=p; 194: } 195: } 196: } 197: 198: control(c) 199: { 200: if (c=='.') return(1); 201: if (c=='%') return(1); 202: return(0); 203: }