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 #include <stdio.h>
18 #include <locale.h>
19 #include <assert.h>
20 #define SAME 0
21 #define FGCT 10
22 #define FGSIZE 150
23
24 int keepold = 1; /* keep old things for fgrep search */
25 char fgspace[FGSIZE];
26 char *fgp = fgspace;
27 char *fgnames[FGCT];
28 char **fgnamp = fgnames;
29
30 extern char *mindex();
31
32 long
33 findline(char *in, char **out, int outlen, long indexdate)
34 {
35 static char name[100] = "";
36 char *p, **ftp;
37 extern long gdate();
38 static FILE *fa = NULL;
39 long lp, llen;
40 int len, k, nofil;
41
42 #if D1
43 fprintf(stderr, "findline: %s\n", in);
44 #endif
45 if (mindex(in, '!'))
46 return (0);
47
48 nofil = in[0] == 0;
49 for (p = in; *p && *p != ':' && *p != ';'; p++)
50 ;
51 if (*p) *p++ = 0;
52 else p = in;
53 k = sscanf(p, "%ld,%ld", &lp, &llen);
54 #ifdef D1
55 fprintf(stderr, "p %s k %d lp %ld llen %ld\n", p, k, lp, llen);
56 #endif
57 if (k < 2) {
58 lp = 0;
59 llen = outlen;
60 }
99 *fgp++ = 0;
100 assert(fgp < fgspace+FGSIZE);
101 return (0);
102 }
103 fprintf(stderr, gettext(
104 "Warning: index predates file '%s'\n"),
105 name);
106 }
107 }
108 #if D1
109 else
110 fprintf(stderr, "old %s new %s same fa %o\n",
111 name, in, fa);
112 #endif
113 if (fa != NULL) {
114 fseek(fa, lp, 0);
115 *out = (char *)malloc(llen + 1);
116 if (*out == NULL) {
117 return (0);
118 }
119 len = fread(*out, 1, llen, fa);
120 *(*out + llen) = 0;
121 #ifdef D1
122 fprintf(stderr, "length as read is %d\n", len);
123 #endif
124 }
125 return (llen);
126 }
|
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 #include <stdio.h>
17 #include <locale.h>
18 #include <assert.h>
19 #define SAME 0
20 #define FGCT 10
21 #define FGSIZE 150
22
23 int keepold = 1; /* keep old things for fgrep search */
24 char fgspace[FGSIZE];
25 char *fgp = fgspace;
26 char *fgnames[FGCT];
27 char **fgnamp = fgnames;
28
29 extern char *mindex();
30
31 long
32 findline(char *in, char **out, int outlen, long indexdate)
33 {
34 static char name[100] = "";
35 char *p, **ftp;
36 extern long gdate();
37 static FILE *fa = NULL;
38 long lp, llen;
39 int k, nofil;
40
41 #if D1
42 fprintf(stderr, "findline: %s\n", in);
43 #endif
44 if (mindex(in, '!'))
45 return (0);
46
47 nofil = in[0] == 0;
48 for (p = in; *p && *p != ':' && *p != ';'; p++)
49 ;
50 if (*p) *p++ = 0;
51 else p = in;
52 k = sscanf(p, "%ld,%ld", &lp, &llen);
53 #ifdef D1
54 fprintf(stderr, "p %s k %d lp %ld llen %ld\n", p, k, lp, llen);
55 #endif
56 if (k < 2) {
57 lp = 0;
58 llen = outlen;
59 }
98 *fgp++ = 0;
99 assert(fgp < fgspace+FGSIZE);
100 return (0);
101 }
102 fprintf(stderr, gettext(
103 "Warning: index predates file '%s'\n"),
104 name);
105 }
106 }
107 #if D1
108 else
109 fprintf(stderr, "old %s new %s same fa %o\n",
110 name, in, fa);
111 #endif
112 if (fa != NULL) {
113 fseek(fa, lp, 0);
114 *out = (char *)malloc(llen + 1);
115 if (*out == NULL) {
116 return (0);
117 }
118 (void) fread(*out, 1, llen, fa);
119 *(*out + llen) = 0;
120 #ifdef D1
121 fprintf(stderr, "length as read is %d\n", len);
122 #endif
123 }
124 return (llen);
125 }
|