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 = "";
  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, *c;
  20:     int stat, nf, nr, query = 0, alph, digs, baselength;
  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:             /*
  88: 			 * Absolute pathnames are only returned by hunt if an
  89: 			 * indexed database is searched.  This means that in
  90: 			 * order to search unindexed databases not in the
  91: 			 * current working directory, we must prefix the
  92: 			 * returned value with a valid path if it isn't
  93: 			 * already a full pathname.
  94: 			 */
  95:             baselength = (c = (char *) rindex(*sr, '/')) ?
  96:                         (int) (c - *sr) + 1 : 0;
  97:             if (temp[0] == '\0' || temp[0] == '/')
  98:                 baselength = 0;
  99:             if (strlen(temp)+baselength+strlen(answer) > BUFSIZ)
 100:                 err("Accumulated answers too large",0);
 101:             if (baselength)
 102:                 strcat(answer, *sr);
 103:             strcat(answer, temp);
 104:             if (strlen(answer)>BUFSIZ)
 105:                 err("answer too long (%d)", strlen(answer));
 106:             if (newline(answer) > 0)
 107:                 break;
 108:         }
 109:     }
 110:     assert(strlen(one) < ANSLEN);
 111:     assert(strlen(answer) < ANSLEN);
 112:     if (buff[0])
 113:         switch (newline(answer)) {
 114:         case 0:
 115:             fprintf(stderr, "No such paper: %s\n", buff);
 116:             return;
 117:         default:
 118:             fprintf(stderr, "Too many hits: %s\n", trimnl(buff));
 119:             choices(answer);
 120:             p = buff;
 121:             while (*p != '\n')
 122:                 p++;
 123:             *++p = 0;
 124:         case 1:
 125:             if (endpush)
 126:                 if (nr = chkdup(answer)) {
 127:                     if (bare < 2) {
 128:                         nf = tabs(flds, one);
 129:                         nf += tabs(flds+nf, dbuff);
 130:                         assert(nf < NFLD);
 131:                         putsig(nf,flds,nr,line1,line,0);
 132:                     }
 133:                     return;
 134:                 }
 135:             if (one[0] == 0)
 136:                 corout(answer, one, "deliv", dr, QLEN);
 137:             break;
 138:         }
 139:     assert(strlen(buff) < QLEN);
 140:     assert(strlen(one) < ANSLEN);
 141:     nf = tabs(flds, one);
 142:     nf += tabs(flds+nf, dbuff);
 143:     assert(nf < NFLD);
 144:     refnum++;
 145:     if (sort)
 146:         putkey(nf, flds, refnum, keystr);
 147:     if (bare < 2)
 148:         putsig(nf, flds, refnum, line1, line, 1);
 149:     else
 150:         flout();
 151:     putref(nf, flds);
 152:     if (biblio && line[0] == '\n')
 153:         goto again;
 154:     if (biblio && line[0] == '%' && line[1] == *convert)
 155:         fprintf(fo, "%s%c%s", convert+1, sep, line+3);
 156: }
 157: 
 158: newline(s)
 159: char *s;
 160: {
 161:     int k = 0, c;
 162: 
 163:     while (c = *s++)
 164:         if (c == '\n')
 165:             k++;
 166:     return(k);
 167: }
 168: 
 169: choices(buff)
 170: char *buff;
 171: {
 172:     char ob[BUFSIZ], *p, *r, *q, *t;
 173:     int nl;
 174: 
 175:     for (r = p = buff; *p; p++) {
 176:         if (*p == '\n') {
 177:             *p++ = 0;
 178:             corout(r, ob, "deliv", dr, BUFSIZ);
 179:             nl = 1;
 180:             for (q = ob; *q; q++) {
 181:                 if (nl && (q[0]=='.'||q[0]=='%') && q[1]=='T') {
 182:                     q += 3;
 183:                     for (t = q; *t && *t != '\n'; t++)
 184:                         ;
 185:                     *t = 0;
 186:                     fprintf(stderr, "%.70s\n", q);
 187:                     q = 0;
 188:                     break;
 189:                 }
 190:                 nl = *q == '\n';
 191:             }
 192:             if (q)
 193:                 fprintf(stderr, "??? at %s\n",r);
 194:             r=p;
 195:         }
 196:     }
 197: }
 198: 
 199: control(c)
 200: {
 201:     if (c == '.')
 202:         return(1);
 203:     if (c == '%')
 204:         return(1);
 205:     return(0);
 206: }

Defined functions

choices defined in line 169; used 1 times
control defined in line 199; used 5 times
doref defined in line 14; used 3 times
newline defined in line 158; 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: 1988-12-26
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3199
Valid CSS Valid XHTML 1.0 Strict