Annotation of researchv10no/cmd/refer/refer5.c, revision 1.1.1.1

1.1       root        1: # include "refer..c"
                      2: # define NFLAB 3000
                      3: # define NLABC 1000
                      4: # define SIGLEN 400
                      5: static char sig[SIGLEN];
                      6: 
                      7: static char bflab[NFLAB];
                      8: static char *labtab[NLABC];
                      9: char *lookat(), *artskp();
                     10: static char *lbp = bflab;
                     11: static char labc[NLABC];
                     12: static char stbuff[50];
                     13: static int  prevsig;
                     14: 
                     15: putsig (nf, flds, nref, nstline, endline)
                     16:        char *flds[], *nstline, *endline;
                     17: {
                     18: /* choose signal style */
                     19: char t[200], t1[200], t2[200], format[10], *sd;
                     20: char *fpar();
                     21: int another = 0;
                     22: int addon, addlet;
                     23: char *stline, *pr;
                     24: static FILE *fhide = 0;
                     25: # if D1
                     26: fprintf(stderr, "in putsig, bare %d labels %o nf %d nref %d\n", bare, labels, nf, nref);
                     27: # endif
                     28: if (labels)
                     29:        {
                     30:        if (nf==0) /* old */
                     31:                sprintf(t, "%s%c", labtab[nref], labc[nref]);
                     32:        else
                     33:                {
                     34:                *t=0;
                     35:                if (keywant)
                     36:                        {
                     37:                        pr = fpar(nf, flds, t1, keywant, 1, 0);
                     38:                        if (pr) strcpy(t, pr);
                     39:                        }
                     40:                if (t[0]==0)
                     41:                        {
                     42:                        if (labblkflg)
                     43:                        {
                     44:                        if (nmlen>0)
                     45:                        sprintf(format, "%%.%ds%s%%s", nmlen, labblkflg);
                     46:                        else
                     47:                        sprintf(format, "%%s%s%%s", labblkflg);
                     48:                        }
                     49:                        else
                     50:                        sprintf(format, nmlen>0 ? "%%.%ds%%s" : "%%s%%s", nmlen);
                     51: # if D1
                     52:                        fprintf(stderr, "format is /%s/\n", format);
                     53: # endif
                     54:                        /* format is %s%s for default labels or %.3s%s eg if wanted */
                     55:                        sd = fpar(nf, flds, t2, 'D', 1, 0);
                     56:                        if (sd==NULL) sd = "";
                     57:                        if (dtlen>0)
                     58:                                {
                     59:                                char *sdb;
                     60:                                for(sdb=sd; *sd; sd++);
                     61:                                sd = sd-dtlen;
                     62:                                if (sd<sdb) sd=sdb;
                     63:                                }
                     64:                        sprintf(t, format, fpar(nf, flds, t1, 'A', 1, 0), sd);
                     65: # if D1
                     66:                        fprintf(stderr, "tag is /%s/\n",t);
                     67: # endif
                     68:                        }
                     69:                if (keywant)
                     70:                        {
                     71:                        addon=0;
                     72:                        for(sd=t; *sd; sd++);
                     73:                        if (*--sd == '-')
                     74:                                {
                     75:                                addon=1;
                     76:                                *sd=0;
                     77:                                }
                     78:                        }
                     79:                addlet = keylet(t, nref);
                     80:                if (!keywant || addon)
                     81:                        addch( t, addlet);
                     82:                }
                     83:        if (sort)
                     84:                sprintf(t, "%c%d%c", FLAG, nref, FLAG);
                     85:        }
                     86: else 
                     87:        {
                     88:        if (sort)
                     89:                sprintf(t, "%c%d%c", FLAG, nref, FLAG);
                     90:        else
                     91:                sprintf(t, "%d", nref);
                     92:        }
                     93: another = prefix (".[", sd=lookat());
                     94: # if D1
                     95: fprintf(stderr, "t leng %d another %d\n",strlen(t), another);
                     96: # endif
                     97: if (another && (strcmp(".[\n", sd) != SAME))
                     98:        fprintf(stderr, "File %s, line %d- punctuation ignored from: %s", Ifile, Iline, sd);
                     99: if (bare==0)
                    100: strcat (sig, t);
                    101: # if D1
                    102: fprintf(stderr, "past strcat\n");
                    103: # endif
                    104: if (strlen(sig) >SIGLEN)
                    105:        err("signal length exceeds %d chars", SIGLEN);
                    106: # if D1
                    107: fprintf(stderr, "sig is now %s leng %d\n",sig,strlen(sig));
                    108: # endif
                    109: trimnl(nstline);
                    110: trimnl(endline);
                    111: stline=stbuff;
                    112: if (prevsig==0)
                    113:        {
                    114:        strcpy (stline, nstline);
                    115:        prevsig=1;
                    116:        }
                    117: if (stline[2] || endline[2])
                    118:        {
                    119:        stline += 2;
                    120:        endline += 2;
                    121:        }
                    122: else
                    123:        {
                    124:        stline  = "\\*([.";
                    125:        endline = "\\*(.]";
                    126:        }
                    127: # if D1
                    128: fprintf(stderr, "bare %d fhide %o fo %o another %d\n",bare, fhide, fo, another);
                    129: # endif
                    130: if (bare==0)
                    131:        {
                    132:        if (another==0)
                    133:                {
                    134:                sprintf(t1, "%s%s\%s\n", stline, sig, endline);
                    135:                append(t1);
                    136:                flout();
                    137:                sig[0]=0;
                    138:                prevsig=0;
                    139:                if (fo != NULL && fo == fhide)
                    140:                        {
                    141:                        int ch;
                    142: # if D1
                    143: fprintf(stderr, "more hiding\n");
                    144: # endif
                    145:                        fclose(fhide); fhide= fopen(hidenam, "r");
                    146:                        fo= ftemp;
                    147:                        while ((ch = getc(fhide)) != EOF)
                    148:                                putc(ch, fo);
                    149:                        fclose(fhide);
                    150:                        unlink(hidenam);
                    151: # if D1
                    152: fprintf(stderr, "past this stuff\n");
                    153: # endif
                    154:                        }
                    155:                }
                    156:        else
                    157:                {
                    158:                if (labsepstr)
                    159:                        strcat(sig, labsepstr);
                    160:                else
                    161:                strcat (sig, (labels ? ", " : ",\\|"));
                    162:                /* hide if need be */
                    163:                if (fo == ftemp)
                    164:                        {
                    165:                        sprintf(hidenam, "/tmp/rj%dc", getpid());
                    166: # if D1
                    167: fprintf(stderr, "hiding in %s\n", hidenam);
                    168: # endif
                    169:                        fhide= fopen(hidenam, "w");
                    170:                        if (fhide==NULL) err("Can't get scratch file %s", hidenam);
                    171:                        fo = fhide;
                    172:                        }
                    173:                }
                    174:        }
                    175: if (bare<2)
                    176:        if (nf>0)
                    177:                {
                    178:                fprintf(fo, ".ds [F %s%c", t, sep);
                    179:                biglab(t);
                    180:                }
                    181: if (bare>0)
                    182:        flout();
                    183: # if D1
                    184: fprintf(stderr, "sig is now %s\n",sig);
                    185: # endif
                    186: }
                    187: char *
                    188: fpar (nf, flds, out, c, seq, prepend)
                    189:        char *flds[], *out;
                    190: {
                    191: char *p, *s;
                    192: int i, fnd = 0;
                    193: for(i=0; i<nf; i++)
                    194:        if (control(flds[i][0]) &&flds[i][1]==c && ++fnd >= seq)
                    195:                {
                    196:                if (c== 'L')
                    197:                        {
                    198:                        p = flds[i]+3;
                    199:                        strcpy(out, p);
                    200:                        return(out);
                    201:                        }
                    202:                if (c!= 'A' && c != 'D') /* if not author, date use first word */
                    203:                        {
                    204:                        p=flds[i]+3;
                    205:                        p = artskp (p);
                    206:                        mycpy2(out, p, 20);
                    207:                        return(out);
                    208:                        }
                    209:                if (c=='A' && lfirst(p=flds[i]+3)) /* author in style Jones, A. */
                    210:                        {
                    211:                        for(s=out; *p!=','; p++)
                    212:                                *s++ = *p;
                    213:                        *s++ = 0;
                    214:                        if (prepend)
                    215:                                {
                    216:                                while (isspace(*p))p++;
                    217:                                *s++ = *p;
                    218:                                *s=0;
                    219:                                }
                    220:                        return(out);
                    221:                        }
                    222:                for(s=p= flds[i]+2; *p; p++);
                    223:                while (p>s && *p != ' ') p--;
                    224:                /* special wart for authors */
                    225:                if (c=='A' && (p[-1] == ',' || p[1] =='('))
                    226:                        {
                    227:                        p--;
                    228:                        while (p>s && *p != ' ') p--;
                    229:                        mycpy (out, p+1);
                    230:                        }
                    231:                else
                    232:                        strcpy (out, p+1);
                    233:                if (c=='A' && prepend)
                    234:                        initadd(out, flds[i]+2, p);
                    235:                return(out);
                    236:                }
                    237: return(0);
                    238: }
                    239: putkey(nf, flds, nref, keystr)
                    240:        char *flds[], *keystr;
                    241: {
                    242: char t1[50], *sf;
                    243: int ctype, i, count;
                    244: # if D1
                    245: int klim=0;
                    246: fprintf(stderr, "in putkey, nf %d nref %d keystr %.20s\n",nf, nref, keystr);
                    247: # endif
                    248: # if D5
                    249: return;
                    250: # endif
                    251: fprintf(fo, ".\\\"");
                    252: if (nf <= 0)
                    253:        fprintf(fo, "%s%c%c", labtab[nref], labc[nref], sep);
                    254: else
                    255:        {
                    256:        while (ctype= *keystr++)
                    257:                {
                    258: # if D1
                    259:                if (++klim>100) err("keystring ridiculous", 0);
                    260: # endif
                    261:                count = atoi(keystr);
                    262:                if (*keystr=='+') count=999;
                    263:                if (count<=0) count=1;
                    264:                for(i=1; i<=count; i++)
                    265:                        {
                    266:                        sf= fpar(nf, flds, t1, ctype, i, 1);
                    267:                        if (sf==0)
                    268:                                break;
                    269:                        sf = artskp(sf);
                    270:                        fprintf(fo, "%s%c", sf, '-');
                    271:                        }
                    272:                }
                    273:        fprintf(fo, "%d%c", nref, sep);
                    274:        }
                    275: # if D1
                    276: fprintf(stderr, "returning from putkey\n");
                    277: # endif
                    278: }
                    279: keylet(t, nref)
                    280:        char *t;
                    281: {
                    282: int i;
                    283: int x = 'a'-1;
                    284: for(i=1; i<nref;i++)
                    285:        {
                    286:        if (strcmp(labtab[i], t) == 0)
                    287:                x = labc[i];
                    288:        }
                    289: strcpy(labtab[nref]=lbp, t);
                    290: while (*lbp++);
                    291: if (lbp-bflab >NFLAB)
                    292:        err("bflab overflow (%d)", NFLAB);
                    293: if (nref >NLABC)
                    294:        err ("nref in labc overflow (%d)", NLABC);
                    295: # ifdef D1
                    296: fprintf(stderr, "lbp up to %d of 2000\n", lbp-bflab);
                    297: # endif
                    298: return (labc[nref] = x+1);
                    299: }
                    300: mycpy(s,t)
                    301:        char *s, *t;
                    302: {
                    303: while (*t && *t != ',' && *t != ' ')
                    304:        *s++ = *t++;
                    305: *s=0;
                    306: }
                    307: mycpy2 (s, t, n)
                    308:        char *s, *t;
                    309: {
                    310: int c;
                    311: while (n-- && (c= *t++)>0)
                    312:        {
                    313:        if (c==' ')c= '-';
                    314:        *s++ = c;
                    315:        }
                    316: *s=0;
                    317: }
                    318: initadd(to, from, stop)
                    319:        char *to, *from, *stop;
                    320: {
                    321:        int c, nalph= 1;
                    322: while (*to) to++;
                    323: while (from<stop)
                    324:        {
                    325:        c = *from++;
                    326:        if (!isalpha(c))
                    327:                {
                    328:                if (nalph)
                    329:                        *to++ = '.';
                    330:                nalph=0;
                    331:                continue;
                    332:                }
                    333:        if (nalph++ ==0)
                    334:                *to++ = c;
                    335:        }
                    336: *to=0;
                    337: }
                    338: 
                    339: static char *articles[] ={"the ", "an ", "a ", 0};
                    340: char *
                    341: artskp(s)
                    342:        char *s;
                    343: {
                    344: /* skips over initial "a ", "an ", or "the " in s */
                    345:        char **p, *r1, *r2;
                    346: for(p=articles; *p; p++)
                    347:        {
                    348:        r2 = s;
                    349:        for (r1= *p; ((*r1 ^ *r2) & ~040 ) == 0; r1++)
                    350:                r2++;
                    351:        if (*r1==0 && *r2 != 0)
                    352:                return(r2);
                    353:        }
                    354: return(s);
                    355: }
                    356: expkey (or, nr, fwrite)
                    357:        FILE *fwrite;
                    358: {
                    359: int uniq, less, i;
                    360: char *s, temp[100];
                    361: # if D1
                    362: fprintf(stderr, "old %d key %s: '%c' new %d\n",or, labtab[or],labc[or],nr);
                    363: # endif
                    364: /* is this unique? how many are before it ? */
                    365: uniq=1; less= 'a';
                    366: s = labtab[or];
                    367: for(i=0; i <= refnum; i++)
                    368:        {
                    369:        if (i==or) continue;
                    370:        if (strcmp(labtab[i], s)!=SAME)
                    371:                continue;
                    372:        uniq=0;
                    373:        if (newr[i] != 0 && newr[i] < nr)
                    374:                less++;
                    375:        }
                    376: if (uniq)
                    377:        sprintf(temp, "%s", s);
                    378: else
                    379:        sprintf(temp,"%s%c", s, less);
                    380: biglab(temp);
                    381: fprintf(fwrite, "%s", temp);
                    382: }
                    383: lfirst(s)
                    384:        char *s;
                    385: {
                    386: /* decides if s is name of format Jones, A */
                    387: char *strchr(), *p;
                    388: p = strchr(s, ',');
                    389: if (p==NULL) return(0);
                    390: while (isspace(*++p)) ;
                    391: if (strncmp(p, "Jr", 2)==0)
                    392:        return(0);
                    393: if (strncmp(p, "II", 2)==0)
                    394:        return(0);
                    395: if (isupper(*p))
                    396:        return(1);
                    397: return(0);
                    398: }
                    399: 
                    400: static char longlab[100]="";
                    401: biglab(s)
                    402:        char *s;
                    403: {
                    404: if (strlen(s)>strlen(longlab))
                    405:        strcpy(longlab, s);
                    406: }
                    407: 
                    408: widelab()
                    409: {
                    410: printf(".nr [W \\w'%s'\n", longlab);
                    411: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.