1 /*
2 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
4 */
5
6 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
7 /* All Rights Reserved */
8
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
15 #pragma ident "%Z%%M% %I% %E% SMI"
16
17
18 #include <stdio.h>
19 #include <ctype.h>
20
21 extern char gfile[];
22
23 void
24 grepcall(char *in, char *out, char *arg)
25 {
26 char line[200], *s, argig[100], *cv[50];
27 char *inp, inb[500];
28 FILE *qf, *gf;
29 int c, oldc = 0, alph = 0, nv = 0;
30 int sv0, sv1;
31 strcpy(argig, arg);
32 strcat(argig, ".ig");
33 strcpy(inp = inb, in);
34 if (gfile[0] == 0)
35 sprintf(gfile, "/tmp/rj%dg", getpid());
36 #if D1
37 fprintf(stderr, "in grepcall, gfile %s in %o out %o\n",
38 gfile, in, out);
39 #endif
40 for (cv[nv++] = "fgrep"; c = *inp; inp++) {
41 if (c == ' ')
42 c = *inp = 0;
43 else if (isupper(c))
44 *inp = tolower(c);
45 alph = (c == 0) ? 0 : alph+1;
46 if (alph == 1)
47 cv[nv++] = inp;
48 if (alph > 6)
49 *inp = 0;
50 oldc = c;
51 }
52 #if D1
53 fprintf(stderr, "%d args set up\n", nv);
54 #endif
55 {
56 sv0 = dup(0);
57 close(0);
58 if (open(argig, 0) != 0)
59 err("Can't read fgrep index %s", argig);
60 sv1 = dup(1);
61 close(1);
62 if (creat(gfile, 0666) != 1)
63 err("Can't write fgrep output %s", gfile);
64 fgrep(nv, cv);
65 #if D1
66 fprintf(stderr, "fgrep returned, output is..\n");
67 #endif
68 close(0);
69 dup(sv0);
70 close(sv0);
|
1 /*
2 * Copyright 2017 Gary Mills
3 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
4 * Use is subject to license terms.
5 */
6
7 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
8 /* All Rights Reserved */
9
10 /*
11 * Copyright (c) 1980 Regents of the University of California.
12 * All rights reserved. The Berkeley software License Agreement
13 * specifies the terms and conditions for redistribution.
14 */
15
16
17 #include <stdio.h>
18 #include <ctype.h>
19
20 extern char gfile[];
21
22 void
23 grepcall(char *in, char *out, char *arg)
24 {
25 char line[200], *s, argig[100], *cv[50];
26 char *inp, inb[500];
27 FILE *qf, *gf;
28 int c, alph = 0, nv = 0;
29 int sv0, sv1;
30 strcpy(argig, arg);
31 strcat(argig, ".ig");
32 strcpy(inp = inb, in);
33 if (gfile[0] == 0)
34 sprintf(gfile, "/tmp/rj%dg", getpid());
35 #if D1
36 fprintf(stderr, "in grepcall, gfile %s in %o out %o\n",
37 gfile, in, out);
38 #endif
39 for (cv[nv++] = "fgrep"; c = *inp; inp++) {
40 if (c == ' ')
41 c = *inp = 0;
42 else if (isupper(c))
43 *inp = tolower(c);
44 alph = (c == 0) ? 0 : alph+1;
45 if (alph == 1)
46 cv[nv++] = inp;
47 if (alph > 6)
48 *inp = 0;
49 }
50 #if D1
51 fprintf(stderr, "%d args set up\n", nv);
52 #endif
53 {
54 sv0 = dup(0);
55 close(0);
56 if (open(argig, 0) != 0)
57 err("Can't read fgrep index %s", argig);
58 sv1 = dup(1);
59 close(1);
60 if (creat(gfile, 0666) != 1)
61 err("Can't write fgrep output %s", gfile);
62 fgrep(nv, cv);
63 #if D1
64 fprintf(stderr, "fgrep returned, output is..\n");
65 #endif
66 close(0);
67 dup(sv0);
68 close(sv0);
|