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

Defined functions

choices defined in line 153; used 1 times
control defined in line 183; used 5 times
doref defined in line 14; used 3 times
newline defined in line 142; used 2 times

Defined variables

dr defined in line 12; used 2 times
one defined in line 10; used 7 times
onelen defined in line 11; never used
sccsid defined in line 2; never used

Defined macros

NFLD defined in line 6; used 3 times
TLEN defined in line 7; used 3 times
Last modified: 1985-08-06
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 935
Valid CSS Valid XHTML 1.0 Strict