| 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
| |
18#include <stdio.h> 19#include <locale.h> 20#include <assert.h>
| 17#include <stdio.h> 18#include <locale.h> 19#include <assert.h>
|
21#define SAME 0 22#define FGCT 10 23#define FGSIZE 150
| 20#define SAME 0 21#define FGCT 10 22#define FGSIZE 150
|
24 25int keepold = 1; /* keep old things for fgrep search */ 26char fgspace[FGSIZE]; 27char *fgp = fgspace; 28char *fgnames[FGCT]; 29char **fgnamp = fgnames; 30
| 23 24int keepold = 1; /* keep old things for fgrep search */ 25char fgspace[FGSIZE]; 26char *fgp = fgspace; 27char *fgnames[FGCT]; 28char **fgnamp = fgnames; 29
|
31findline(in, out, outlen, indexdate) 32long indexdate; 33char *in, **out;
| 30extern char *mindex(); 31 32long 33findline(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
| 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
| 42#if D1
|
43 fprintf(stderr, "findline: %s\n", in);
| 43 fprintf(stderr, "findline: %s\n", in);
|
44# endif
| 44#endif
|
45 if (mindex(in, '!'))
| 45 if (mindex(in, '!'))
|
46 /* return(remote(in, *out)); /* Does NOTHING */ 47 return(0);
| 46 return (0);
|
48
| 47
|
49 nofil = in[0]==0; 50 for(p=in; *p && *p != ':' && *p != ';'; p++)
| 48 nofil = in[0] == 0; 49 for (p = in; *p && *p != ':' && *p != ';'; p++)
|
51 ;
| 50 ;
|
52 if (*p) *p++=0; 53 else p=in;
| 51 if (*p) *p++ = 0; 52 else p = in;
|
54 k = sscanf(p, "%ld,%ld", &lp, &llen);
| 53 k = sscanf(p, "%ld,%ld", &lp, &llen);
|
55# ifdef D1 56 fprintf(stderr, "p %s k %d lp %ld llen %ld\n",p,k,lp,llen); 57# endif 58 if (k<2) 59 {
| 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) {
|
60 lp = 0;
| 58 lp = 0;
|
61 llen=outlen;
| 59 llen = outlen;
|
62 }
| 60 }
|
63# ifdef D1 64 fprintf(stderr, "lp %ld llen %ld\n",lp, llen); 65# endif 66# ifdef D1 67 fprintf(stderr, "fa now %o, p %o in %o %s\n",fa, p,in,in); 68# endif 69 if (nofil) 70 { 71# if D1
| 61#ifdef D1 62 fprintf(stderr, "lp %ld llen %ld\n", lp, llen); 63#endif 64#ifdef D1 65 fprintf(stderr, "fa now %o, p %o in %o %s\n", fa, p, in, in); 66#endif 67 if (nofil) { 68#if D1
|
72 fprintf(stderr, "set fa to stdin\n");
| 69 fprintf(stderr, "set fa to stdin\n");
|
73# endif
| 70#endif
|
74 fa = stdin;
| 71 fa = stdin;
|
75 } 76 else 77 if (strcmp (name, in) != 0 || 1) 78 { 79# if D1 80 fprintf(stderr, "old: %s new %s not equal\n",name,in); 81# endif
| 72 } else 73 if (strcmp(name, in) != 0 || 1) { 74#if D1 75 fprintf(stderr, "old: %s new %s not equal\n", name, in); 76#endif
|
82 if (fa != NULL) 83 fa = freopen(in, "r", fa); 84 else 85 fa = fopen(in, "r");
| 77 if (fa != NULL) 78 fa = freopen(in, "r", fa); 79 else 80 fa = fopen(in, "r");
|
86# if D1 87 if (fa==NULL) 88 fprintf(stderr, "failed to (re)open *%s*\n",in); 89# endif
| 81#if D1
|
90 if (fa == NULL)
| 82 if (fa == NULL)
|
91 return(0);
| 83 fprintf(stderr, "failed to (re)open *%s*\n", 84 in); 85#endif 86 if (fa == NULL) 87 return (0);
|
92 /* err("Can't open %s", in); */ 93 strcpy(name, in);
| 88 /* err("Can't open %s", in); */ 89 strcpy(name, in);
|
94 if (gdate(fa) > indexdate && indexdate != 0) 95 { 96 if (keepold) 97 { 98 for(ftp=fgnames; ftp<fgnamp; ftp++) 99 if (strcmp(*ftp, name)==SAME) 100 return(0); 101 strcpy (*fgnamp++ = fgp, name); 102 assert(fgnamp<fgnames+FGCT); 103 while (*fgp && *fgp!=':')
| 90 if (gdate(fa) > indexdate && indexdate != 0) { 91 if (keepold) { 92 for (ftp = fgnames; ftp < fgnamp; ftp++) 93 if (strcmp(*ftp, name) == SAME) 94 return (0); 95 strcpy(*fgnamp++ = fgp, name); 96 assert(fgnamp < fgnames+FGCT); 97 while (*fgp && *fgp != ':')
|
104 fgp++; 105 *fgp++ = 0;
| 98 fgp++; 99 *fgp++ = 0;
|
106 assert (fgp<fgspace+FGSIZE); 107 return(0);
| 100 assert(fgp < fgspace+FGSIZE); 101 return (0);
|
108 }
| 102 }
|
109 fprintf(stderr, gettext("Warning: index predates file '%s'\n"), name);
| 103 fprintf(stderr, gettext( 104 "Warning: index predates file '%s'\n"), 105 name);
|
110 } 111 }
| 106 } 107 }
|
112# if D1
| 108#if D1
|
113 else
| 109 else
|
114 fprintf(stderr, "old %s new %s same fa %o\n", name,in,fa); 115# endif 116 if (fa != NULL) 117 {
| 110 fprintf(stderr, "old %s new %s same fa %o\n", 111 name, in, fa); 112#endif 113 if (fa != NULL) {
|
118 fseek(fa, lp, 0);
| 114 fseek(fa, lp, 0);
|
119 *out = (char *) malloc(llen + 1); 120 if (*out == NULL) { 121 return(0); 122 }
| 115 *out = (char *)malloc(llen + 1); 116 if (*out == NULL) { 117 return (0); 118 }
|
123 len = fread(*out, 1, llen, fa); 124 *(*out + llen) = 0;
| 119 len = fread(*out, 1, llen, fa); 120 *(*out + llen) = 0;
|
125# ifdef D1 126 fprintf(stderr, "length as read is %d\n",len); 127# endif
| 121#ifdef D1 122 fprintf(stderr, "length as read is %d\n", len); 123#endif
|
128 }
| 124 }
|
129 return(llen);
| 125 return (llen);
|
130}
| 126}
|