glue4.c (0:68f95e015346) glue4.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
18
19#include <stdio.h>
20#include <ctype.h>
21
22extern char gfile[];
23
18#include <stdio.h>
19#include <ctype.h>
20
21extern char gfile[];
22
24grepcall (in, out, arg)
25char *in, *out, *arg;
23void
24grepcall(char *in, char *out, char *arg)
26{
27 char line[200], *s, argig[100], *cv[50];
28 char *inp, inb[500];
29 FILE *qf, *gf;
30 int c, oldc = 0, alph = 0, nv = 0;
31 int sv0, sv1;
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;
32 strcpy (argig, arg);
31 strcpy(argig, arg);
33 strcat(argig, ".ig");
32 strcat(argig, ".ig");
34 strcpy (inp=inb, in);
35 if (gfile[0]==0)
33 strcpy(inp = inb, in);
34 if (gfile[0] == 0)
36 sprintf(gfile, "/tmp/rj%dg", getpid());
35 sprintf(gfile, "/tmp/rj%dg", getpid());
37# if D1
38 fprintf(stderr, "in grepcall, gfile %s in %o out %o\n", gfile,in,out);
39# endif
40 for(cv[nv++] = "fgrep"; c = *inp; inp++)
41 {
42 if (c== ' ')
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 == ' ')
43 c = *inp = 0;
44 else if (isupper(c))
45 *inp = tolower(c);
42 c = *inp = 0;
43 else if (isupper(c))
44 *inp = tolower(c);
46 alph = (c==0) ? 0 : alph+1;
45 alph = (c == 0) ? 0 : alph+1;
47 if (alph == 1)
48 cv[nv++] = inp;
49 if (alph > 6)
50 *inp = 0;
46 if (alph == 1)
47 cv[nv++] = inp;
48 if (alph > 6)
49 *inp = 0;
51 oldc=c;
50 oldc = c;
52 }
51 }
53# if D1
52#if D1
54 fprintf(stderr, "%d args set up\n", nv);
53 fprintf(stderr, "%d args set up\n", nv);
55# endif
54#endif
56 {
57 sv0 = dup(0);
58 close(0);
55 {
56 sv0 = dup(0);
57 close(0);
59 if (open (argig, 0) != 0)
58 if (open(argig, 0) != 0)
60 err("Can't read fgrep index %s", argig);
61 sv1 = dup(1);
62 close(1);
63 if (creat(gfile, 0666) != 1)
64 err("Can't write fgrep output %s", gfile);
65 fgrep(nv, cv);
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);
66# if D1
65#if D1
67 fprintf(stderr, "fgrep returned, output is..\n");
66 fprintf(stderr, "fgrep returned, output is..\n");
68# endif
69 close (0);
70 dup(sv0);
67#endif
68 close(0);
69 dup(sv0);
71 close(sv0);
70 close(sv0);
72 close (1);
73 dup(sv1);
71 close(1);
72 dup(sv1);
74 close(sv1);
75 }
76
73 close(sv1);
74 }
75
77# if D1
76#if D1
78 fprintf(stderr, "back from fgrep\n");
77 fprintf(stderr, "back from fgrep\n");
79# endif
78#endif
80 gf = fopen(gfile, "r");
79 gf = fopen(gfile, "r");
81 if (gf==NULL)
80 if (gf == NULL)
82 err("can't read fgrep output %s", gfile);
81 err("can't read fgrep output %s", gfile);
83 while (fgets(line, 100, gf) == line)
84 {
85 line[100]=0;
86# if D1
87 fprintf(stderr, "read line as //%s//\n",line);
88# endif
89 for(s=line; *s && (*s != '\t'); s++);
90 if (*s == '\t')
91 {
82 while (fgets(line, 100, gf) == line) {
83 line[100] = 0;
84#if D1
85 fprintf(stderr, "read line as //%s//\n", line);
86#endif
87 for (s = line; *s && (*s != '\t'); s++)
88 ;
89 if (*s == '\t') {
92 *s++ = '\n';
93 *s++ = 0;
94 }
95 if (line[0])
96 strcat(out, line);
90 *s++ = '\n';
91 *s++ = 0;
92 }
93 if (line[0])
94 strcat(out, line);
97# if D1
98 fprintf(stderr, "out now /%s/\n",out);
99# endif
95#if D1
96 fprintf(stderr, "out now /%s/\n", out);
97#endif
100 while (*s) s++;
98 while (*s) s++;
101# if D1
102 fprintf(stderr, "line %o s %o s-1 %o\n",line,s,s[-1]);
103# endif
104 if (s[-1]!= '\n')
105 while (!feof(gf) && getc(gf)!= '\n') ;
99#if D1
100 fprintf(stderr, "line %o s %o s-1 %o\n", line, s, s[-1]);
101#endif
102 if (s[-1] != '\n')
103 while (!feof(gf) && getc(gf) != '\n')
104 ;
106 }
107 fclose(gf);
105 }
106 fclose(gf);
108# if D1
109 fprintf(stderr, "back from reading %, out %s\n",out);
110# else
111 unlink (gfile);
112# endif
113 return(0);
107#if D1
108 fprintf(stderr, "back from reading %, out %s\n", out);
109#else
110 unlink(gfile);
111#endif
114}
115
112}
113
116clfgrep()
114void
115clfgrep(void)
117{
118 if (gfile[0])
119 unlink(gfile);
120}
116{
117 if (gfile[0])
118 unlink(gfile);
119}