1: #if defined(DOSCCS) && !defined(lint)
   2: static char *sccsid = "@(#)refer5.c	4.7.1 (2.11BSD GTE) 1/1/94";
   3: #endif
   4: 
   5: #include "refer..c"
   6: #define SAME 0
   7: #ifdef pdp11
   8: #define NFLAB 1500      /* number of bytes to record all labels */
   9: #define NLABC 500       /* max number of labels */
  10: #else
  11: #define NFLAB 3000      /* number of bytes to record all labels */
  12: #define NLABC 1000      /* max number of labels */
  13: #endif
  14: 
  15: static char sig[MXSIG];
  16: static char bflab[NFLAB];
  17: static char *labtab[NLABC];
  18: static char *lbp = bflab;
  19: static char labc[NLABC];
  20: static char stbuff[50];
  21: static int  prevsig;
  22: 
  23: putsig (nf, flds, nref, nstline, endline, toindex)   /* choose signal style */
  24: char *flds[], *nstline, *endline;
  25: {
  26:     char t[100], t1[MXSIG], t2[100], format[10], *sd, *stline;
  27:     int addon, another = 0;
  28:     static FILE *fhide = 0;
  29:     int i;
  30:     char tag;
  31: 
  32:     if (labels) {
  33:         if (nf == 0)    /* old */
  34:             sprintf(t, "%s%c", labtab[nref], labc[nref]);
  35:         else {
  36:             *t = 0;
  37:             if (keywant)
  38:                 sprintf(t, "%s", fpar(nf,flds,t1,keywant,1,0));
  39:             if (science && t[0] == 0) {
  40:                 sd = fpar(nf, flds, t2, 'D', 1, 0);
  41:                 sprintf(t, "%s, %s", fpar(nf,flds,t1,'A',1,0),
  42:                     sd);
  43:             }
  44:             else if (t[0] == 0) {
  45:                 sprintf(format,
  46:                     nmlen>0 ? "%%.%ds%%s" : "%%s%%s",
  47:                     nmlen);
  48:                 /* format is %s%s for default labels */
  49:                 /* or %.3s%s eg if wanted */
  50:                 sd = fpar(nf, flds, t2, 'D', 1, 0);
  51:                 if (dtlen > 0) {
  52:                     char *sdb;
  53:                     for (sdb = sd; *sd; sd++)
  54:                         ;
  55:                     sd = sd - dtlen;
  56:                     if (sd < sdb)
  57:                         sd = sdb;
  58:                 }
  59:                 sprintf(t, format, fpar(nf,flds,t1,'A',1,0),
  60:                     sd);
  61:             }
  62:             if (keywant) {
  63:                 addon = 0;
  64:                 for (sd = t; *sd; sd++)
  65:                     ;
  66:                 if (*--sd == '-') {
  67:                     addon = 1;
  68:                     *sd = 0;
  69:                 }
  70:             }
  71:             if ((!keywant || addon) && !science) {
  72:                 addch(t, keylet(t, nref));
  73:             }
  74:             else {
  75:                 tokeytab (t,nref);
  76:             }
  77:         }
  78:     }
  79:     else {
  80:         sprintf(t, "%c%d%c", FLAG, nref, FLAG);
  81:     }
  82:     another = prefix (".[", sd=lookat());
  83:     if (another && (strcmp(".[\n", sd) != SAME))
  84:         fprintf(stderr, "File %s line %d: punctuation ignored from: %s",
  85:             Ifile, Iline, sd);
  86:     if ((strlen(sig) + strlen(t)) > MXSIG)
  87:         err("sig overflow (%d)", MXSIG);
  88:     strcat(sig, t);
  89: #if EBUG
  90:     fprintf(stderr, "sig is now %s leng %d\n",sig,strlen(sig));
  91: #endif
  92:     trimnl(nstline);
  93:     trimnl(endline);
  94:     stline = stbuff;
  95:     if (prevsig == 0) {
  96:         strcpy (stline, nstline);
  97:         prevsig=1;
  98:     }
  99:     if (stline[2] || endline[2]) {
 100:         stline += 2;
 101:         endline += 2;
 102:     }
 103:     else {
 104:         stline  = "\\*([.";
 105:         endline = "\\*(.]";
 106:     }
 107:     if (science) {
 108:         stline = " (";
 109:         endline = ")";
 110:     }
 111:     if (bare == 0) {
 112:         if (!another) {
 113:             sprintf(t1, "%s%s\%s\n", stline, sig, endline);
 114:             if (strlen(t1) > MXSIG)
 115:                 err("t1 overflow (%d)", MXSIG);
 116:             append(t1);
 117:             flout();
 118:             sig[0] = 0;
 119:             prevsig = 0;
 120:             if (fo == fhide) {
 121:                 int ch;
 122:                 fclose(fhide);
 123:                 fhide = fopen(hidenam, "r");
 124:                 fo = ftemp;
 125:                 while ((ch = getc(fhide)) != EOF)
 126:                     putc(ch, fo);
 127:                 fclose(fhide);
 128:                 unlink(hidenam);
 129:             }
 130:         }
 131:         else {
 132:             if (labels) {
 133:                 strcat(sig, ",\\|");
 134:             } else {
 135:                 /*
 136: 				 * Seperate reference numbers with AFLAG
 137: 				 * for later sorting and condensing.
 138: 				 */
 139:                 t1[0] = AFLAG;
 140:                 t1[1] = '\0';
 141:                 strcat(sig, t1);
 142:             }
 143:             if (fo == ftemp) {  /* hide if need be */
 144:                 sprintf(hidenam, "/tmp/rj%dc", getpid());
 145: #if EBUG
 146:                 fprintf(stderr, "hiding in %s\n", hidenam);
 147: #endif
 148:                 fhide = fopen(hidenam, "w");
 149:                 if (fhide == NULL)
 150:                     err("Can't get scratch file %s",
 151:                         hidenam);
 152:                 fo = fhide;
 153:             }
 154:         }
 155:     }
 156:     if (bare < 2)
 157:         if (nf > 0 && toindex)
 158:             fprintf(fo,".ds [F %s%c",t,sep);
 159:     if (bare > 0)
 160:         flout();
 161: #if EBUG
 162:     fprintf(stderr, "sig is now %s\n",sig);
 163: #endif
 164: }
 165: 
 166: char *
 167: fpar (nf, flds, out, c, seq, prepend)
 168: char *flds[], *out;
 169: {
 170:     char *p, *s;
 171:     int i, fnd = 0;
 172: 
 173:     for(i = 0; i < nf; i++)
 174:         if (flds[i][1] == c && ++fnd >= seq) {
 175:             /* for titles use first word otherwise last */
 176:             if (c == 'T' || c == 'J') {
 177:                 p = flds[i]+3;
 178:                 if (prefix("A ", p))
 179:                     p += 2;
 180:                 if (prefix("An ", p))
 181:                     p += 3;
 182:                 if (prefix("The ", p))
 183:                     p += 4;
 184:                 mycpy2(out, p, 20);
 185:                 return(out);
 186:             }
 187:             /* if its not 'L' then use just the last word */
 188:             s = p = flds[i]+2;
 189:             if (c != 'L') {
 190:                 for(; *p; p++);
 191:                 while (p > s && *p != ' ')
 192:                     p--;
 193:             }
 194:             /* special wart for authors */
 195:             if (c == 'A' && (p[-1] == ',' || p[1] =='(')) {
 196:                 p--;
 197:                 while (p > s && *p != ' ')
 198:                     p--;
 199:                 mycpy(out, p+1);
 200:             }
 201:             else
 202:                 strcpy(out, p+1);
 203:             if (c == 'A' && prepend)
 204:                 initadd(out, flds[i]+2, p);
 205:             return(out);
 206:         }
 207:     return(0);
 208: }
 209: 
 210: putkey(nf, flds, nref, keystr)
 211: char *flds[], *keystr;
 212: {
 213:     char t1[50], *sf;
 214:     int ctype, i, count;
 215: 
 216:     fprintf(fo, ".\\\"");
 217:     if (nf <= 0)
 218:         fprintf(fo, "%s%c%c", labtab[nref], labc[nref], sep);
 219:     else {
 220:         while (ctype = *keystr++) {
 221:             count = atoi(keystr);
 222:             if (*keystr=='+')
 223:                 count=999;
 224:             if (count <= 0)
 225:                 count = 1;
 226:             for(i = 1; i <= count; i++) {
 227:                 sf = fpar(nf, flds, t1, ctype, i, 1);
 228:                 if (sf == 0)
 229:                     break;
 230:                 sf = artskp(sf);
 231:                 fprintf(fo, "%s%c", sf, '-');
 232:             }
 233:         }
 234:         fprintf(fo, "%c%d%c%c", FLAG, nref, FLAG, sep);
 235:     }
 236: }
 237: 
 238: 
 239: tokeytab (t, nref)
 240: char *t;
 241: {
 242:     strcpy(labtab[nref]=lbp, t);
 243:     while (*lbp++)
 244:         ;
 245: }
 246: 
 247: keylet(t, nref)
 248: char *t;
 249: {
 250:     int i;
 251:     int x = 'a' - 1;
 252: 
 253:     for(i = 1; i < nref; i++) {
 254:         if (strcmp(labtab[i], t) == 0)
 255:             x = labc[i];
 256:     }
 257:     tokeytab (t, nref);
 258:     if (lbp-bflab > NFLAB)
 259:         err("bflab overflow (%d)", NFLAB);
 260:     if (nref > NLABC)
 261:         err("nref in labc overflow (%d)", NLABC);
 262: #if EBUG
 263:     fprintf(stderr, "lbp up to %d of %d\n", lbp-bflab, NFLAB);
 264: #endif
 265:     return(labc[nref] = x+1);
 266: }
 267: 
 268: mycpy(s, t)
 269: char *s, *t;
 270: {
 271:     while (*t && *t != ',' && *t != ' ')
 272:         *s++ = *t++;
 273:     *s = 0;
 274: }
 275: 
 276: mycpy2(s, t, n)
 277: char *s, *t;
 278: {
 279:     int c;
 280: 
 281:     while (n-- && (c= *t++) > 0) {
 282:         if (c == ' ')
 283:             c = '-';
 284:         *s++ = c;
 285:     }
 286:     *s = 0;
 287: }
 288: 
 289: initadd(to, from, stop)
 290: char *to, *from, *stop;
 291: {
 292:     int c, nalph = 1;
 293: 
 294:     while (*to)
 295:         to++;
 296:     while (from < stop) {
 297:         c = *from++;
 298:         if (!isalpha(c)) {
 299:             if (nalph)
 300:                 *to++ = '.';
 301:             nalph = 0;
 302:             continue;
 303:         }
 304:         if (nalph++ == 0)
 305:             *to++ = c;
 306:     }
 307:     *to = 0;
 308: }
 309: 
 310: static char *articles[] = {
 311:     "the ", "an ", "a ", 0
 312: };
 313: 
 314: char *
 315: artskp(s)   /* skips over initial "a ", "an ", "the " in s */
 316: char *s;
 317: {
 318: 
 319:     char **p, *r1, *r2;
 320: 
 321:     for (p = articles; *p; p++) {
 322:         r2 = s;
 323:         for (r1 = *p; ((*r1 ^ *r2) & ~040 ) == 0; r1++)
 324:             r2++;
 325:         if (*r1 == 0 && *r2 != 0)
 326:             return(r2);
 327:     }
 328:     return(s);
 329: }

Defined functions

artskp defined in line 314; used 2 times
fpar defined in line 166; used 7 times
initadd defined in line 289; used 1 times
keylet defined in line 247; used 1 times
  • in line 72
mycpy defined in line 268; used 1 times
mycpy2 defined in line 276; used 1 times
putkey defined in line 210; used 1 times
putsig defined in line 23; used 2 times
tokeytab defined in line 239; used 2 times

Defined variables

articles defined in line 310; used 1 times
bflab defined in line 16; used 3 times
labc defined in line 19; used 4 times
labtab defined in line 17; used 4 times
lbp defined in line 18; used 4 times
prevsig defined in line 21; used 3 times
sccsid defined in line 2; never used
sig defined in line 15; used 9 times
stbuff defined in line 20; used 1 times
  • in line 94

Defined macros

NFLAB defined in line 11; used 4 times
NLABC defined in line 12; used 4 times
SAME defined in line 6; used 1 times
  • in line 83
Last modified: 1994-01-11
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3387
Valid CSS Valid XHTML 1.0 Strict