refer1.c (0:68f95e015346) refer1.c (719:6c26331bc6b8)
1/*
2 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
4 */
5
1/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
2/* All Rights Reserved */
3
6/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
7/* All Rights Reserved */
8
4
5/*
6 * Copyright (c) 1980 Regents of the University of California.
7 * All rights reserved. The Berkeley software License Agreement
8 * specifies the terms and conditions for redistribution.
9 */
10
9/*
10 * Copyright (c) 1980 Regents of the University of California.
11 * All rights reserved. The Berkeley software License Agreement
12 * specifies the terms and conditions for redistribution.
13 */
14
11/*
12 * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
13 * All Rights Reserved.
14 */
15#pragma ident "%Z%%M% %I% %E% SMI"
15
16
16#pragma ident "%Z%%M% %I% %E% SMI"
17
17#include <stdlib.h>
18#include <signal.h>
19#include <locale.h>
20#include "refer..c"
21
18#include <signal.h>
19#include <locale.h>
20#include "refer..c"
21
22main(argc,argv) /* process command-line arguments */
23char *argv[];
22extern void clfgrep();
23extern void doref();
24extern void dumpold();
25extern void err();
26extern void output();
27extern int prefix();
28extern void recopy();
29
30void cleanup(void);
31void signals(void);
32
33int
34main(int argc, char *argv[]) /* process command-line arguments */
24{
25 char line[BUFSIZ], *s;
26 int nodeflt = 0;
27
28 (void) setlocale(LC_ALL, "");
29#if !defined(TEXT_DOMAIN)
35{
36 char line[BUFSIZ], *s;
37 int nodeflt = 0;
38
39 (void) setlocale(LC_ALL, "");
40#if !defined(TEXT_DOMAIN)
30#define TEXT_DOMAIN "SYS_TEST"
41#define TEXT_DOMAIN "SYS_TEST"
31#endif
32 (void) textdomain(TEXT_DOMAIN);
33
34 signals();
35 while (argc > 1 && argv[1][0] == '-') {
42#endif
43 (void) textdomain(TEXT_DOMAIN);
44
45 signals();
46 while (argc > 1 && argv[1][0] == '-') {
36 switch(argv[1][1]) {
47 switch (argv[1][1]) {
37 case 'e':
48 case 'e':
38 endpush++;
49 endpush++;
39 break;
40 case 's':
41 sort++;
42 endpush = 1;
43 if (argv[1][2])
44 keystr = argv[1]+2;
45 break;
50 break;
51 case 's':
52 sort++;
53 endpush = 1;
54 if (argv[1][2])
55 keystr = argv[1]+2;
56 break;
46 case 'l':
57 case 'l':
47 labels++;
48 s = argv[1]+2;
49 nmlen = atoi(s);
50 while (*s)
51 if (*s++ == ',')
52 break;
53 dtlen = atoi(s);
54 break;
55 case 'k':
56 keywant = (argv[1][2] ? argv[1][2] : 'L');
57 labels++;
58 break;
59 case 'n':
60 nodeflt = 1;
61 break;
62 case 'p':
58 labels++;
59 s = argv[1]+2;
60 nmlen = atoi(s);
61 while (*s)
62 if (*s++ == ',')
63 break;
64 dtlen = atoi(s);
65 break;
66 case 'k':
67 keywant = (argv[1][2] ? argv[1][2] : 'L');
68 labels++;
69 break;
70 case 'n':
71 nodeflt = 1;
72 break;
73 case 'p':
63 argc--;
74 argc--;
64 argv++;
65 *search++ = argv[1];
66 if (search-rdata > NSERCH)
75 argv++;
76 *search++ = argv[1];
77 if (search-rdata > NSERCH)
67 err(gettext("too many -p options (%d)"), NSERCH);
78 err(gettext(
79 "too many -p options (%d)"), NSERCH);
68 break;
69 case 'a':
70 authrev = atoi(argv[1]+2);
80 break;
81 case 'a':
82 authrev = atoi(argv[1]+2);
71 if (authrev<=0)
83 if (authrev <= 0)
72 authrev = 1000;
73 break;
74 case 'b':
75 bare = (argv[1][2] == '1') ? 1 : 2;
76 break;
77 case 'c':
78 smallcaps = argv[1]+2;
79 break;

--- 9 unchanged lines hidden (view full) ---

89 case 'S':
90 science++;
91 labels = 1;
92 break;
93 case 'P':
94 postpunct++;
95 break;
96 }
84 authrev = 1000;
85 break;
86 case 'b':
87 bare = (argv[1][2] == '1') ? 1 : 2;
88 break;
89 case 'c':
90 smallcaps = argv[1]+2;
91 break;

--- 9 unchanged lines hidden (view full) ---

101 case 'S':
102 science++;
103 labels = 1;
104 break;
105 case 'P':
106 postpunct++;
107 break;
108 }
97 argc--;
109 argc--;
98 argv++;
99 }
100 if (getenv("REFER") != NULL)
101 *search++ = getenv("REFER");
102 else if (nodeflt == 0)
103 *search++ = "/usr/lib/refer/papers/Ind";
104 if (sort && !labels) {
105 sprintf(ofile, "/tmp/rj%db", getpid());

--- 5 unchanged lines hidden (view full) ---

111 }
112 if (endpush) {
113 sprintf(tfile, "/tmp/rj%da", getpid());
114 fo = fopen(tfile, "w");
115 if (fo == NULL) {
116 fo = ftemp;
117 fprintf(stderr, gettext("Can't open scratch file"));
118 }
110 argv++;
111 }
112 if (getenv("REFER") != NULL)
113 *search++ = getenv("REFER");
114 else if (nodeflt == 0)
115 *search++ = "/usr/lib/refer/papers/Ind";
116 if (sort && !labels) {
117 sprintf(ofile, "/tmp/rj%db", getpid());

--- 5 unchanged lines hidden (view full) ---

123 }
124 if (endpush) {
125 sprintf(tfile, "/tmp/rj%da", getpid());
126 fo = fopen(tfile, "w");
127 if (fo == NULL) {
128 fo = ftemp;
129 fprintf(stderr, gettext("Can't open scratch file"));
130 }
119 sep = 002; /* separate records without confusing sort..*/
120 } else
131 sep = 002; /* separate records without confusing sort.. */
132 } else
121 fo = ftemp;
122 do {
123 if (argc > 1) {
124 fclose(in);
125 Iline = 0;
126 in = fopen(Ifile = argv[1], "r");
133 fo = ftemp;
134 do {
135 if (argc > 1) {
136 fclose(in);
137 Iline = 0;
138 in = fopen(Ifile = argv[1], "r");
127 argc--;
139 argc--;
128 argv++;
129 if (in == NULL) {
130 err(gettext("Can't read %s"), Ifile);
131 continue;
132 }
133 }
134 while (input(line)) {
135 Iline++;

--- 10 unchanged lines hidden (view full) ---

146
147 if (endpush && fo != NULL)
148 dumpold();
149 output("");
150 if (sort && !labels)
151 recopy(ofile);
152 clfgrep();
153 cleanup();
140 argv++;
141 if (in == NULL) {
142 err(gettext("Can't read %s"), Ifile);
143 continue;
144 }
145 }
146 while (input(line)) {
147 Iline++;

--- 10 unchanged lines hidden (view full) ---

158
159 if (endpush && fo != NULL)
160 dumpold();
161 output("");
162 if (sort && !labels)
163 recopy(ofile);
164 clfgrep();
165 cleanup();
154 exit(0);
155 /* NOTREACHED */
166 return (0);
156}
157
158extern void intr();
159
167}
168
169extern void intr();
170
160signals()
171void
172signals(void)
161{
162 if (signal(SIGINT, SIG_IGN) != SIG_IGN)
163 signal(SIGINT, intr);
164 signal(SIGHUP, intr);
165 signal(SIGPIPE, intr);
166 signal(SIGTERM, intr);
167}
168
173{
174 if (signal(SIGINT, SIG_IGN) != SIG_IGN)
175 signal(SIGINT, intr);
176 signal(SIGHUP, intr);
177 signal(SIGPIPE, intr);
178 signal(SIGTERM, intr);
179}
180
169void intr()
181void
182intr(void)
170{
171 signal(SIGINT, SIG_IGN);
172 cleanup();
173 exit(1);
174}
175
183{
184 signal(SIGINT, SIG_IGN);
185 cleanup();
186 exit(1);
187}
188
176cleanup()
189void
190cleanup(void)
177{
178 if (tfile[0])
179 unlink(tfile);
180 if (gfile[0])
181 unlink(gfile);
182 if (ofile[0])
183 unlink(ofile);
184 if (hidenam[0])
185 unlink(hidenam);
186}
191{
192 if (tfile[0])
193 unlink(tfile);
194 if (gfile[0])
195 unlink(gfile);
196 if (ofile[0])
197 unlink(ofile);
198 if (hidenam[0])
199 unlink(hidenam);
200}