diff options
| author | Wolfram Schneider <wosch@FreeBSD.org> | 1996-08-22 18:46:13 +0000 |
|---|---|---|
| committer | Wolfram Schneider <wosch@FreeBSD.org> | 1996-08-22 18:46:13 +0000 |
| commit | 7ec1929d534d4f06b8812ad69570337772c34df1 (patch) | |
| tree | 72d248c17a7252aeec5a920535090abe27057f50 /usr.bin/locate/code/locate.code.c | |
| parent | aa7e9146d799d6eacc018490b57cd9d7d5134a49 (diff) | |
Notes
Diffstat (limited to 'usr.bin/locate/code/locate.code.c')
| -rw-r--r-- | usr.bin/locate/code/locate.code.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/usr.bin/locate/code/locate.code.c b/usr.bin/locate/code/locate.code.c index 60be32a44ee0..4846c73ba5ed 100644 --- a/usr.bin/locate/code/locate.code.c +++ b/usr.bin/locate/code/locate.code.c @@ -32,6 +32,8 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. + * + * $Id$ */ #ifndef lint @@ -93,18 +95,19 @@ u_char buf1[MAXPATHLEN] = " "; u_char buf2[MAXPATHLEN]; char bigrams[BGBUFSIZE + 1] = { 0 }; -#define LOOKUP 1 +#define LOOKUP 1 /* use a lookup array instead a function, 3x faster */ + #ifdef LOOKUP #define BGINDEX(x) (big[(u_int)*x][(u_int)*(x+1)]) typedef u_char bg_t; bg_t big[UCHAR_MAX][UCHAR_MAX]; - #else #define BGINDEX(x) bgindex(x) typedef int bg_t; -#endif - int bgindex __P((char *)); +#endif /* LOOKUP */ + + void usage __P((void)); extern int optind; extern int optopt; @@ -135,6 +138,7 @@ main(argc, argv) /* First copy bigram array to stdout. */ (void)fgets(bigrams, BGBUFSIZE + 1, fp); + if (fwrite(bigrams, 1, BGBUFSIZE, stdout) != BGBUFSIZE) err(1, "stdout"); (void)fclose(fp); @@ -147,11 +151,12 @@ main(argc, argv) for (cp = bigrams, i = 0; *cp != NULL; i += 2, cp += 2) big[(int)*cp][(int)*(cp + 1)] = (bg_t)i; -#endif +#endif /* LOOKUP */ oldpath = buf1; path = buf2; oldcount = 0; + while (fgets(path, sizeof(buf2), stdin) != NULL) { /* skip empty lines */ @@ -169,7 +174,7 @@ main(argc, argv) } /* Skip longest common prefix. */ - for (cp = path; *cp == *oldpath && *cp; cp++, oldpath++); + for (cp = path; *cp == *oldpath && *cp != NULL; cp++, oldpath++); count = cp - path; diffcount = count - oldcount + OFFSET; @@ -225,7 +230,7 @@ bgindex(bg) /* Return location of bg in bigrams or -1. */ for (p = bigrams; *p != NULL; p++) if (*p++ == bg0 && *p == bg1) break; - return (*p == NULL ? -1 : --p - bigrams); + return (*p == NULL ? -1 : (--p - bigrams)); } #endif /* !LOOKUP */ |
