home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V7 / usr / src / cmd / refer / refer6.c < prev    next >
Encoding:
C/C++ Source or Header  |  1979-01-12  |  3.7 KB  |  225 lines

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