Annotation of researchv8dc/cmd/refer/refer6.c, revision 1.1.1.1

1.1       root        1: # include "refer..c"
                      2: char *class();
                      3: char seenstr[60];
                      4: putref (n, tvec)
                      5:        char *tvec[];
                      6: {
                      7: char *s, *tx, *sq;
                      8: char *caps(), *revauth();
                      9: char buf1[LLINE], buf2[50];
                     10: int nauth = 0, i, lastype = 0, cch, macro = 0, la;
                     11: int lauth =0, ltitle =0, lother =0;
                     12: 
                     13: # if D1
                     14: fprintf(stderr, "in putref, fo is %o\n",fo);
                     15: # endif
                     16: if (!preserve)
                     17: fprintf(fo, ".]-%c", sep);
                     18: else
                     19:        fprintf(fo, ".[%c", sep);
                     20: # define dsde (macro? "de" : "ds")
                     21: # define ifnl (macro? sep : ' ')
                     22: seenstr[0]=0;
                     23: for (i=0; i<n; i++)
                     24:        {
                     25:        s = tvec[i];
                     26:        if (*s==0) continue;
                     27:        if (control(s[0]) )
                     28:                {
                     29:                if (lastype && macro)
                     30:                        fprintf(fo, "..%c", sep);
                     31:                if (control(s[1]))
                     32:                        {
                     33:                        cch = s[2];
                     34:                        tx = s+3;
                     35:                        macro=1;
                     36:                        }
                     37:                else
                     38:                        {
                     39:                        cch = s[1];
                     40:                        tx = s+2;
                     41:                        macro=0;
                     42:                        }
                     43:                }
                     44:        else
                     45:                {
                     46:                cch = lastype;
                     47:                tx=s;
                     48:                }
                     49: # if D1
                     50: fprintf(stderr, "smallcaps %s cch %c\n",smallcaps, cch);
                     51: # endif
                     52:        if (preserve)
                     53:                {
                     54:                fprintf(fo, "%s%c", s, sep);
                     55:                continue;
                     56:                }
                     57:        if (mindex (smallcaps, cch))
                     58:                tx = caps(tx, buf1);
                     59: # if D1
                     60: fprintf(stderr, " s %o tx %o %s\n",s,tx,tx);
                     61: # endif
                     62:        if (!control(s[0]) || (index(appfld, s[1]) && seen(s[1]))) /* append to previous item */
                     63:                {
                     64:                if (control(s[0]))
                     65:                        lastype = s[1];
                     66:                if (lastype!=0)
                     67:                        {
                     68:                        if (macro)
                     69:                                fprintf(fo, "%s%c", tx, sep);
                     70:                        else
                     71:                                fprintf(fo, ".as [%c \" %s%c",lastype,tx,sep);
                     72:                        if (lastype == 'T')
                     73:                                ltitle = (mindex(".;,?", last(tx))!=0);
                     74:                        if (lastype == 'A')
                     75:                                lauth = last(tx) == '.';
                     76:                        if (lastype == 'O')
                     77:                                lother = (mindex(".;,?", last(tx)) != 0);
                     78:                        }
                     79:                continue;
                     80:                }
                     81:        if (mindex(ignfld, cch)) /* skip XYZ[] */
                     82:                {
                     83:                lastype=0;
                     84:                continue;
                     85:                }
                     86:        else
                     87:        if (cch == 'A')
                     88:                {
                     89:                if (nauth < authrev)
                     90:                        tx = revauth(tx, buf2);
                     91:                if (nauth++ ==0)
                     92:                        if (macro)
                     93:                                fprintf(fo, ".de [%c%c%s%c",cch,sep,tx,sep);
                     94:                        else
                     95:                                fprintf(fo, ".ds [%c%s%c", cch,tx,sep);
                     96:                else
                     97:                        {
                     98:                        la = (tvec[i+1][1]!='A');
                     99:                        fprintf(fo, ".as [A \"");
                    100:                        if (la == 0 || nauth != 2)
                    101:                                fprintf(fo, ",");
                    102:                        if (la)
                    103:                        fprintf(fo,"%s", 
                    104:                                mindex(smallcaps, 'A')? " \\s-2AND\\s+2" : " and");
                    105:                        fprintf(fo, "%s%c", tx, sep);
                    106:                        }
                    107:                lauth = last(tx)=='.';
                    108:                }
                    109:        else
                    110:                {
                    111:                if (cch == 'D' && yearonly)
                    112:                        {
                    113:                        sq = tx+strlen(tx);
                    114:                        while (*--sq!=' ' && sq>tx)
                    115:                                ;
                    116:                        if (sq>tx) tx=sq;
                    117:                        }
                    118:                if (macro)
                    119:                        fprintf(fo, ".de [%c%c%s%c",cch,sep, tx, sep);
                    120:                else
                    121:                        fprintf(fo, ".ds [%c%s%c",cch,tx, sep);
                    122:                }
                    123:        if (cch=='P')
                    124:                fprintf(fo, ".nr [P %d%c", mindex(s, '-')!=0, sep);
                    125:        lastype = cch;
                    126:        if (cch == 'T')
                    127:                ltitle = (mindex(".;,?", last(tx)) != 0);
                    128:        if (cch == 'O')
                    129:                lother = (mindex(".;,?", last(tx)) != 0);
                    130:        }
                    131: if (lastype && macro)
                    132:        fprintf(fo, "..%c", sep);
                    133: if (!preserve)
                    134:        {
                    135:        fprintf(fo, ".nr [T %d%c", ltitle, sep);
                    136:        fprintf(fo, ".nr [A %d%c", lauth, sep);
                    137:        fprintf(fo, ".nr [O %d%c", lother, sep);
                    138:        fprintf (fo, ".][ %s%c", class(n, tvec), '\n');
                    139:        }
                    140: else
                    141:        fprintf(fo, ".]\n");
                    142: }
                    143: tabs (sv, line)
                    144:        char *sv[], *line;
                    145: {
                    146: char *p;
                    147: int n = 0;
                    148: sv[n++] = line;
                    149: for( p= line; *p; p++)
                    150:        {
                    151:        if (*p == '\n')
                    152:                {
                    153:                *p=0;
                    154:                sv[n++] = p+1;
                    155:                }
                    156:        }
                    157: return(n-1);
                    158: }
                    159: char *
                    160: class (nt, tv)
                    161:        char *tv[];
                    162: {
                    163: if (hastype (nt, tv, 'J'))
                    164:        return("1 journal-article");
                    165: if (hastype (nt, tv, 'B'))
                    166:        return("3 article-in-book");
                    167: if (hastype (nt, tv, 'R'))
                    168:        return ("4 tech-report");
                    169: if (hastype (nt, tv, 'G'))
                    170:        return ("4 tech-report");
                    171: if (hastype (nt, tv, 'I'))
                    172:        return("2 book");
                    173: if (hastype (nt, tv,'M'))
                    174:        return ("5 bell-tm");
                    175: return("0 other");
                    176: }
                    177: hastype (nt, tv, c)
                    178:        char *tv[];
                    179: {
                    180: int i;
                    181: for(i=0; i<nt; i++)
                    182:        if ( control(tv[i][0]) && tv[i][1]==c )
                    183:                return(1);
                    184: return(0);
                    185: }
                    186: char *
                    187: caps(a, b)
                    188:        char *a, *b;
                    189: {
                    190: char *p;
                    191: int c, alph, this;
                    192: p=b;
                    193: alph = 0;
                    194: while (c = *a++)
                    195:        {
                    196:        this = isalpha(c);
                    197:        if (this && alph==1)
                    198:                {
                    199:                *b++ = '\\';
                    200:                *b++ = 's';
                    201:                *b++ = '-';
                    202:                *b++ = '2';
                    203:                }
                    204:        if (!this && alph>1)
                    205:                {
                    206:                *b++ = '\\';
                    207:                *b++ = 's';
                    208:                *b++ = '+';
                    209:                *b++ = '2';
                    210:                }
                    211:        if (this)
                    212:                c &= (~040);
                    213:        *b++ = c;
                    214:        alph = this ? alph+1 : 0;
                    215:        }
                    216: if (alph>1)
                    217:        {
                    218:        *b++ = '\\';
                    219:        *b++ = 's';
                    220:        *b++ = '+';
                    221:        *b++ = '2';
                    222:        }
                    223: *b=0;
                    224: return (p);
                    225: }
                    226: char *
                    227: revauth(s, b)
                    228:        char *s, *b;
                    229: {
                    230: char *init, *name, *jr, *p, *bcop;
                    231: bcop = b;
                    232: init=name=s;
                    233: while (*name)name++;
                    234: jr=name;
                    235: while (name>init && *name!= ' ')
                    236:        name--;
                    237: if (name[-1] == ',' || name[-1]== '(' )
                    238:        {
                    239:        jr = --name;
                    240:        while (name>init && *name != ' ')
                    241:                name--;
                    242:        }
                    243: p=name;
                    244: while (p<jr)
                    245:        *b++ = *p++;
                    246: if (init<name && nocomma==0)
                    247:        *b++ = ',';
                    248: while (init<name)
                    249:        *b++ = *init++;
                    250: if (*jr)jr++;
                    251: while(*jr)
                    252:        *b++ = *jr++;
                    253: *b++ = 0;
                    254: return(bcop);
                    255: }
                    256: last(s)
                    257:        char *s;
                    258: {
                    259: while (*s) s++;
                    260: return(*--s);
                    261: }
                    262: seen(c)
                    263: {
                    264: char *s, *index();
                    265: s = index(seenstr,c);
                    266: if (s!=NULL) return(1);
                    267: for(s=seenstr; *s; s++)
                    268:        ;
                    269: *s++ = c;
                    270: *s=0;
                    271: return(0);
                    272: }

unix.superglobalmegacorp.com

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