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

Defined functions

artskp defined in line 258; used 1 times
fpar defined in line 136; used 4 times
initadd defined in line 236; used 1 times
keylet defined in line 197; used 1 times
  • in line 57
mycpy defined in line 218; used 1 times
mycpy2 defined in line 225; used 1 times
putkey defined in line 170; used 1 times
putsig defined in line 14; used 2 times

Defined variables

articles defined in line 257; used 1 times
bflab defined in line 9; used 2 times
labc defined in line 10; used 4 times
labtab defined in line 8; used 4 times
lbp defined in line 9; used 4 times
prevsig defined in line 12; used 3 times
sig defined in line 5; used 7 times
stbuff defined in line 11; used 1 times
  • in line 76

Defined macros

NFLAB defined in line 3; used 3 times
NLABC defined in line 4; used 5 times
SAME defined in line 2; used 1 times
  • in line 68
Last modified: 1981-07-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1012
Valid CSS Valid XHTML 1.0 Strict