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

Defined functions

caps defined in line 157; used 2 times
class defined in line 128; used 2 times
hastype defined in line 147; used 6 times
last defined in line 227; used 5 times
putref defined in line 9; used 1 times
revauth defined in line 195; used 2 times
tabs defined in line 112; used 4 times

Defined variables

sccsid defined in line 2; never used

Defined macros

dsde defined in line 6; never used
ifnl defined in line 7; never used
Last modified: 1983-05-08
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1339
Valid CSS Valid XHTML 1.0 Strict