Deleted Added
full compact
locate.code.c (17776) locate.code.c (17972)
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

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

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 *
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

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

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$
36 * $Id: locate.code.c,v 1.4 1996/08/22 18:46:13 wosch Exp $
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

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

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
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

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

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)
152 for (cp = bigrams, i = 0; *cp != '\0'; i += 2, cp += 2)
153 big[(int)*cp][(int)*(cp + 1)] = (bg_t)i;
154#endif /* LOOKUP */
155
156 oldpath = buf1;
157 path = buf2;
158 oldcount = 0;
159
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. */
153 big[(int)*cp][(int)*(cp + 1)] = (bg_t)i;
154#endif /* LOOKUP */
155
156 oldpath = buf1;
157 path = buf2;
158 oldcount = 0;
159
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++) {
167 for (cp = path; *cp != '\0'; cp++) {
168 /* chop newline */
169 if (*cp == '\n')
168 /* chop newline */
169 if (*cp == '\n')
170 *cp = NULL;
170 *cp = '\0';
171 /* range */
172 else if (*cp < ASCII_MIN || *cp > ASCII_MAX)
173 *cp = '?';
174 }
175
176 /* Skip longest common prefix. */
171 /* range */
172 else if (*cp < ASCII_MIN || *cp > ASCII_MAX)
173 *cp = '?';
174 }
175
176 /* Skip longest common prefix. */
177 for (cp = path; *cp == *oldpath && *cp != NULL; cp++, oldpath++);
177 for (cp = path; *cp == *oldpath && *cp != '\0'; cp++, oldpath++);
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");
186 } else
187 if (putchar(diffcount) == EOF)
188 err(1, "stdout");
189
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");
186 } else
187 if (putchar(diffcount) == EOF)
188 err(1, "stdout");
189
190 while (*cp != NULL) {
191 if (*(cp + 1) == NULL) {
190 while (*cp != '\0') {
191 if (*(cp + 1) == '\0') {
192 if (putchar(*cp) == EOF)
193 err(1, "stdout");
194 break;
195 }
196 if ((code = BGINDEX(cp)) == (bg_t)-1) {
197 if (putchar(*cp++) == EOF ||
198 putchar(*cp++) == EOF)
199 err(1, "stdout");

--- 44 unchanged lines hidden ---
192 if (putchar(*cp) == EOF)
193 err(1, "stdout");
194 break;
195 }
196 if ((code = BGINDEX(cp)) == (bg_t)-1) {
197 if (putchar(*cp++) == EOF ||
198 putchar(*cp++) == EOF)
199 err(1, "stdout");

--- 44 unchanged lines hidden ---