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