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

  1. # include "signal.h"
  2. # include "refer..c"
  3. main(argc,argv)
  4.     char *argv[];
  5. {
  6. char line[LLINE], *s;
  7. int nodeflt =0;
  8.  
  9. signals();
  10. while (argv[1][0] == '-')
  11.     {
  12.     switch(argv[1][1])
  13.         {
  14.         case 'e':
  15.             endpush++; break;
  16.         case 'l': 
  17.             labels++;
  18.             s = argv[1]+2;
  19.             nmlen = atoi(s);
  20.             while (*s)
  21.                 if (*s++ == ',')
  22.                     break;
  23.             dtlen = atoi(s);
  24.             break;
  25.         case 'k':
  26.             keywant = (argv[1][2] ? argv[1][2] : 'L');
  27.             labels++;
  28.             break;
  29.         case 's':
  30.             sort++;
  31.             if (argv[1][2])
  32.                 keystr= argv[1]+2;
  33.             break;
  34.         case 'p':
  35.             argc--; argv++;
  36.             *search++ = argv[1];
  37.             if (search-data>NSERCH)
  38.                 err("too many -p options (%d)", NSERCH);
  39.             break;
  40.         case 'n':
  41.             nodeflt=1;
  42.             break;
  43.         case 'b':
  44.             bare = (argv[1][2] == '1') ? 1 : 2;
  45.             break;
  46.         case 'c':
  47.             smallcaps = argv[1]+2;
  48.             break;
  49.         case 'a':
  50.             authrev = atoi (argv[1]+2);
  51.             if (authrev<=0)
  52.                 authrev = 1000;
  53.             break;
  54.         }
  55.     argc--; argv++;
  56.     }
  57. if (nodeflt==0)
  58.     *search++ = "/usr/dict/papers/Ind";
  59.  
  60. if (sort)
  61.     endpush=1;
  62. if (endpush)
  63.     {
  64.     sprintf(tfile, "/tmp/rj%da", getpid());
  65.     fo = fopen(tfile, "w");
  66.     if (fo==NULL)
  67.         {
  68.         fo = ftemp;
  69.         fprintf(stderr,"Can't open scratch file");
  70.         }
  71.     sep = 002; /* separate records without confusing sort..*/
  72.     }
  73.  
  74.  
  75. if (sort && !labels)
  76.     {
  77.     sprintf(ofile,"/tmp/rj%db", getpid());
  78.     ftemp = fopen(ofile, "w");
  79.     if (ftemp==NULL)
  80.         {
  81.         fprintf(stderr, "Can't open scratch file\n");
  82.         exit(1);
  83.         }
  84.     }
  85.  
  86. do
  87.     {
  88.     if (argc>1)
  89.         {
  90.         fclose(in);
  91.         Iline=0;
  92.         in = fopen(Ifile=argv[1], "r");
  93.         argc--; argv++;
  94.         if (in==NULL)
  95.             {
  96.             err("Can't read %s", Ifile);
  97.             continue;
  98.             }
  99.         }
  100.     while (input(line))
  101.         {
  102.         Iline++;
  103. # ifdef D1
  104.         fprintf(stderr, "line %.20s\n",line);
  105. # endif
  106.         if (!prefix(".[", line))
  107.             output(line);
  108.         else
  109.             doref(line);
  110. # if D1
  111.         fprintf(stderr, "past output/doref\n");
  112. # endif
  113.         }
  114.     }
  115.     while (argc>1);
  116. if (endpush && fo!=NULL)
  117.     dumpold();
  118. output("", ftemp);
  119. if (sort && !labels)
  120.     recopy(ofile);
  121. clfgrep();
  122. cleanup();
  123. exit(0);
  124. }
  125.  
  126. extern int intr();
  127. signals()
  128. {
  129.     int oldint;
  130. oldint = signal(SIGINT, &intr);
  131. if (oldint==1)
  132.     signal (SIGINT, 1);
  133. signal (SIGHUP, &intr);
  134. signal (SIGPIPE, &intr);
  135. signal (SIGTERM, &intr);
  136. }
  137.  
  138. intr()
  139. {
  140.     int oldsig;
  141. signal(SIGINT, 1);
  142. cleanup();
  143. exit(1);
  144. }
  145. cleanup()
  146. {
  147. if (tfile[0]) unlink(tfile);
  148. if (gfile[0]) unlink(gfile);
  149. if (ofile[0]) unlink(ofile);
  150. if (hidenam[0]) unlink(hidenam);
  151. }
  152.