Deleted Added
full compact
locate.code.c (17592) locate.code.c (17776)
1/*
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * James A. Woods.
7 *
8 * Redistribution and use in source and binary forms, with or without

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

27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
1/*
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * James A. Woods.
7 *
8 * Redistribution and use in source and binary forms, with or without

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

27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * $Id$
35 */
36
37#ifndef lint
38static char copyright[] =
39"@(#) Copyright (c) 1989, 1993\n\
40 The Regents of the University of California. All rights reserved.\n";
41#endif /* not lint */
42

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

88#include "locate.h"
89
90#define BGBUFSIZE (NBG * 2) /* size of bigram buffer */
91
92u_char buf1[MAXPATHLEN] = " ";
93u_char buf2[MAXPATHLEN];
94char bigrams[BGBUFSIZE + 1] = { 0 };
95
37 */
38
39#ifndef lint
40static char copyright[] =
41"@(#) Copyright (c) 1989, 1993\n\
42 The Regents of the University of California. All rights reserved.\n";
43#endif /* not lint */
44

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

90#include "locate.h"
91
92#define BGBUFSIZE (NBG * 2) /* size of bigram buffer */
93
94u_char buf1[MAXPATHLEN] = " ";
95u_char buf2[MAXPATHLEN];
96char bigrams[BGBUFSIZE + 1] = { 0 };
97
96#define LOOKUP 1
98#define LOOKUP 1 /* use a lookup array instead a function, 3x faster */
99
97#ifdef LOOKUP
98#define BGINDEX(x) (big[(u_int)*x][(u_int)*(x+1)])
99typedef u_char bg_t;
100bg_t big[UCHAR_MAX][UCHAR_MAX];
100#ifdef LOOKUP
101#define BGINDEX(x) (big[(u_int)*x][(u_int)*(x+1)])
102typedef u_char bg_t;
103bg_t big[UCHAR_MAX][UCHAR_MAX];
101
102#else
103#define BGINDEX(x) bgindex(x)
104typedef int bg_t;
104#else
105#define BGINDEX(x) bgindex(x)
106typedef int bg_t;
105#endif
106
107int bgindex __P((char *));
107int bgindex __P((char *));
108#endif /* LOOKUP */
109
110
108void usage __P((void));
109extern int optind;
110extern int optopt;
111
112int
113main(argc, argv)
114 int argc;
115 char *argv[];

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

130 if (argc != 1)
131 usage();
132
133 if ((fp = fopen(argv[0], "r")) == NULL)
134 err(1, "%s", argv[0]);
135
136 /* First copy bigram array to stdout. */
137 (void)fgets(bigrams, BGBUFSIZE + 1, fp);
111void usage __P((void));
112extern int optind;
113extern int optopt;
114
115int
116main(argc, argv)
117 int argc;
118 char *argv[];

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

133 if (argc != 1)
134 usage();
135
136 if ((fp = fopen(argv[0], "r")) == NULL)
137 err(1, "%s", argv[0]);
138
139 /* First copy bigram array to stdout. */
140 (void)fgets(bigrams, BGBUFSIZE + 1, fp);
141
138 if (fwrite(bigrams, 1, BGBUFSIZE, stdout) != BGBUFSIZE)
139 err(1, "stdout");
140 (void)fclose(fp);
141
142#ifdef LOOKUP
143 /* init lookup table */
144 for (i = 0; i < UCHAR_MAX; i++)
145 for (j = 0; j < UCHAR_MAX; j++)
146 big[i][j] = (bg_t)-1;
147
148 for (cp = bigrams, i = 0; *cp != NULL; i += 2, cp += 2)
149 big[(int)*cp][(int)*(cp + 1)] = (bg_t)i;
142 if (fwrite(bigrams, 1, BGBUFSIZE, stdout) != BGBUFSIZE)
143 err(1, "stdout");
144 (void)fclose(fp);
145
146#ifdef LOOKUP
147 /* init lookup table */
148 for (i = 0; i < UCHAR_MAX; i++)
149 for (j = 0; j < UCHAR_MAX; j++)
150 big[i][j] = (bg_t)-1;
151
152 for (cp = bigrams, i = 0; *cp != NULL; i += 2, cp += 2)
153 big[(int)*cp][(int)*(cp + 1)] = (bg_t)i;
150#endif
154#endif /* LOOKUP */
151
152 oldpath = buf1;
153 path = buf2;
154 oldcount = 0;
155
156 oldpath = buf1;
157 path = buf2;
158 oldcount = 0;
159
155 while (fgets(path, sizeof(buf2), stdin) != NULL) {
156
157 /* skip empty lines */
158 if (*path == '\n')
159 continue;
160
161 /* Squelch characters that would botch the decoding. */
162 for (cp = path; *cp != NULL; cp++) {
163 /* chop newline */
164 if (*cp == '\n')
165 *cp = NULL;
166 /* range */
167 else if (*cp < ASCII_MIN || *cp > ASCII_MAX)
168 *cp = '?';
169 }
170
171 /* Skip longest common prefix. */
160 while (fgets(path, sizeof(buf2), stdin) != NULL) {
161
162 /* skip empty lines */
163 if (*path == '\n')
164 continue;
165
166 /* Squelch characters that would botch the decoding. */
167 for (cp = path; *cp != NULL; cp++) {
168 /* chop newline */
169 if (*cp == '\n')
170 *cp = NULL;
171 /* range */
172 else if (*cp < ASCII_MIN || *cp > ASCII_MAX)
173 *cp = '?';
174 }
175
176 /* Skip longest common prefix. */
172 for (cp = path; *cp == *oldpath && *cp; cp++, oldpath++);
177 for (cp = path; *cp == *oldpath && *cp != NULL; cp++, oldpath++);
173
174 count = cp - path;
175 diffcount = count - oldcount + OFFSET;
176 oldcount = count;
177 if (diffcount < 0 || diffcount > 2 * OFFSET) {
178 if (putchar(SWITCH) == EOF ||
179 putw(diffcount, stdout) == EOF)
180 err(1, "stdout");

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

220{
221 register char bg0, bg1, *p;
222
223 bg0 = bg[0];
224 bg1 = bg[1];
225 for (p = bigrams; *p != NULL; p++)
226 if (*p++ == bg0 && *p == bg1)
227 break;
178
179 count = cp - path;
180 diffcount = count - oldcount + OFFSET;
181 oldcount = count;
182 if (diffcount < 0 || diffcount > 2 * OFFSET) {
183 if (putchar(SWITCH) == EOF ||
184 putw(diffcount, stdout) == EOF)
185 err(1, "stdout");

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

225{
226 register char bg0, bg1, *p;
227
228 bg0 = bg[0];
229 bg1 = bg[1];
230 for (p = bigrams; *p != NULL; p++)
231 if (*p++ == bg0 && *p == bg1)
232 break;
228 return (*p == NULL ? -1 : --p - bigrams);
233 return (*p == NULL ? -1 : (--p - bigrams));
229}
230#endif /* !LOOKUP */
231
232void
233usage()
234{
235 (void)fprintf(stderr,
236 "usage: locate.code common_bigrams < list > squozen_list\n");
237 exit(1);
238}
234}
235#endif /* !LOOKUP */
236
237void
238usage()
239{
240 (void)fprintf(stderr,
241 "usage: locate.code common_bigrams < list > squozen_list\n");
242 exit(1);
243}