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