head 1.16; access; symbols netbsd-6-1:1.15.0.10 netbsd-6-0-2-RELEASE:1.15 netbsd-6-1-RELEASE:1.15 netbsd-6-1-RC4:1.15 netbsd-6-1-RC3:1.15 agc-symver:1.16.0.6 agc-symver-base:1.16 netbsd-6-1-RC2:1.15 tls-maxphys-nbase:1.16.0.4 netbsd-6-1-RC1:1.15 yamt-pagecache-base8:1.16 netbsd-5-2:1.12.0.2 netbsd-6-0-1-RELEASE:1.15 yamt-pagecache-base7:1.16 netbsd-5-2-RELEASE:1.12 netbsd-5-2-RC1:1.12 matt-nb6-plus-nbase:1.15 yamt-pagecache-base6:1.16 netbsd-6-0:1.15.0.8 netbsd-6-0-RELEASE:1.15 netbsd-6-0-RC2:1.15 tls-maxphys:1.16.0.2 tls-maxphys-base:1.16 matt-nb6-plus:1.15.0.6 matt-nb6-plus-base:1.15 netbsd-6-0-RC1:1.15 yamt-pagecache-base5:1.16 yamt-pagecache-base4:1.16 netbsd-6:1.15.0.4 netbsd-6-base:1.15 netbsd-5-1-2-RELEASE:1.12 netbsd-5-1-1-RELEASE:1.12 yamt-pagecache-base3:1.15 yamt-pagecache-base2:1.15 yamt-pagecache:1.15.0.2 yamt-pagecache-base:1.15 cherry-xenmp:1.14.0.4 cherry-xenmp-base:1.14 bouyer-quota2-nbase:1.14 bouyer-quota2:1.14.0.2 bouyer-quota2-base:1.14 matt-mips64-premerge-20101231:1.14 matt-nb5-mips64-premerge-20101231:1.12 matt-nb5-pq3:1.12.0.14 matt-nb5-pq3-base:1.12 netbsd-5-1:1.12.0.12 netbsd-5-1-RELEASE:1.12 netbsd-5-1-RC4:1.12 matt-nb5-mips64-k15:1.12 netbsd-5-1-RC3:1.12 netbsd-5-1-RC2:1.12 netbsd-5-1-RC1:1.12 netbsd-5-0-2-RELEASE:1.12 matt-nb5-mips64-premerge-20091211:1.12 matt-premerge-20091211:1.14 matt-nb5-mips64-u2-k2-k4-k7-k8-k9:1.12 matt-nb4-mips64-k7-u2a-k9b:1.12 matt-nb5-mips64-u1-k1-k5:1.12 matt-nb5-mips64:1.12.0.10 netbsd-5-0-1-RELEASE:1.12 jym-xensuspend-nbase:1.14 netbsd-5-0:1.12.0.8 netbsd-5-0-RELEASE:1.12 netbsd-5-0-RC4:1.12 netbsd-5-0-RC3:1.12 netbsd-5-0-RC2:1.12 jym-xensuspend:1.12.0.6 jym-xensuspend-base:1.14 netbsd-5-0-RC1:1.12 netbsd-5:1.12.0.4 netbsd-5-base:1.12 matt-mips64-base2:1.12 matt-mips64:1.11.0.36 netbsd-4-0-1-RELEASE:1.11 wrstuden-revivesa-base-3:1.12 wrstuden-revivesa-base-2:1.12 wrstuden-fixsa-newbase:1.11 wrstuden-revivesa-base-1:1.11 yamt-pf42-base4:1.11 yamt-pf42-base3:1.11 hpcarm-cleanup-nbase:1.11 yamt-pf42-baseX:1.11 yamt-pf42-base2:1.11 wrstuden-revivesa:1.11.0.34 wrstuden-revivesa-base:1.11 yamt-pf42:1.11.0.32 yamt-pf42-base:1.11 keiichi-mipv6-nbase:1.11 keiichi-mipv6:1.11.0.30 keiichi-mipv6-base:1.11 matt-armv6-nbase:1.11 matt-armv6-prevmlocking:1.11 wrstuden-fixsa-base-1:1.11 netbsd-4-0:1.11.0.28 netbsd-4-0-RELEASE:1.11 cube-autoconf:1.11.0.26 cube-autoconf-base:1.11 netbsd-4-0-RC5:1.11 netbsd-4-0-RC4:1.11 netbsd-4-0-RC3:1.11 netbsd-4-0-RC2:1.11 netbsd-4-0-RC1:1.11 matt-armv6:1.11.0.24 matt-armv6-base:1.11 matt-mips64-base:1.11 hpcarm-cleanup:1.11.0.22 hpcarm-cleanup-base:1.11 netbsd-3-1-1-RELEASE:1.11 netbsd-3-0-3-RELEASE:1.11 wrstuden-fixsa:1.11.0.20 wrstuden-fixsa-base:1.11 abandoned-netbsd-4-base:1.11 abandoned-netbsd-4:1.11.0.14 netbsd-3-1:1.11.0.16 netbsd-3-1-RELEASE:1.11 netbsd-3-0-2-RELEASE:1.11 netbsd-3-1-RC4:1.11 netbsd-3-1-RC3:1.11 netbsd-3-1-RC2:1.11 netbsd-3-1-RC1:1.11 netbsd-4:1.11.0.18 netbsd-4-base:1.11 chap-midi-nbase:1.11 netbsd-3-0-1-RELEASE:1.11 chap-midi:1.11.0.12 chap-midi-base:1.11 netbsd-3-0:1.11.0.10 netbsd-3-0-RELEASE:1.11 netbsd-3-0-RC6:1.11 netbsd-3-0-RC5:1.11 netbsd-3-0-RC4:1.11 netbsd-3-0-RC3:1.11 netbsd-3-0-RC2:1.11 netbsd-3-0-RC1:1.11 netbsd-2-0-3-RELEASE:1.11 netbsd-2-1:1.11.0.8 netbsd-2-1-RELEASE:1.11 netbsd-2-1-RC6:1.11 netbsd-2-1-RC5:1.11 netbsd-2-1-RC4:1.11 netbsd-2-1-RC3:1.11 netbsd-2-1-RC2:1.11 netbsd-2-1-RC1:1.11 netbsd-2-0-2-RELEASE:1.11 netbsd-3:1.11.0.6 netbsd-3-base:1.11 netbsd-2-0-1-RELEASE:1.11 netbsd-2:1.11.0.4 netbsd-2-base:1.11 netbsd-2-0-RELEASE:1.11 netbsd-2-0-RC5:1.11 netbsd-2-0-RC4:1.11 netbsd-2-0-RC3:1.11 netbsd-2-0-RC2:1.11 netbsd-2-0-RC1:1.11 netbsd-2-0:1.11.0.2 netbsd-2-0-base:1.11 netbsd-1-6-PATCH002-RELEASE:1.10 netbsd-1-6-PATCH002:1.10 netbsd-1-6-PATCH002-RC4:1.10 netbsd-1-6-PATCH002-RC3:1.10 netbsd-1-6-PATCH002-RC2:1.10 netbsd-1-6-PATCH002-RC1:1.10 netbsd-1-6-PATCH001:1.10 netbsd-1-6-PATCH001-RELEASE:1.10 netbsd-1-6-PATCH001-RC3:1.10 netbsd-1-6-PATCH001-RC2:1.10 netbsd-1-6-PATCH001-RC1:1.10 fvdl_fs64_base:1.10 netbsd-1-6-RELEASE:1.10 netbsd-1-6-RC3:1.10 netbsd-1-6-RC2:1.10 netbsd-1-6-RC1:1.10 netbsd-1-6:1.10.0.12 netbsd-1-6-base:1.10 netbsd-1-5-PATCH003:1.10 netbsd-1-5-PATCH002:1.10 netbsd-1-5-PATCH001:1.10 netbsd-1-5-RELEASE:1.10 netbsd-1-5-BETA2:1.10 netbsd-1-5-BETA:1.10 netbsd-1-4-PATCH003:1.10 netbsd-1-5-ALPHA2:1.10 netbsd-1-5:1.10.0.10 netbsd-1-5-base:1.10 minoura-xpg4dl-base:1.10 minoura-xpg4dl:1.10.0.8 netbsd-1-4-PATCH002:1.10 wrstuden-devbsize-19991221:1.10 wrstuden-devbsize:1.10.0.6 wrstuden-devbsize-base:1.10 comdex-fall-1999:1.10.0.4 comdex-fall-1999-base:1.10 netbsd-1-4-PATCH001:1.10 netbsd-1-4-RELEASE:1.10 netbsd-1-4:1.10.0.2 netbsd-1-4-base:1.10 netbsd-1-3-PATCH003:1.8 netbsd-1-3-PATCH003-CANDIDATE2:1.8 netbsd-1-3-PATCH003-CANDIDATE1:1.8 netbsd-1-3-PATCH003-CANDIDATE0:1.8 netbsd-1-3-PATCH002:1.8 netbsd-1-3-PATCH001:1.8 netbsd-1-3-RELEASE:1.8 netbsd-1-3-BETA:1.8 netbsd-1-3:1.8.0.2 netbsd-1-3-base:1.8 netbsd-1-2-PATCH001:1.7 netbsd-1-2-RELEASE:1.7 netbsd-1-2-BETA:1.7 netbsd-1-2:1.7.0.6 netbsd-1-2-base:1.7 netbsd-1-1-PATCH001:1.7 netbsd-1-1-RELEASE:1.7 netbsd-1-1:1.7.0.2 netbsd-1-1-base:1.7 lite-2:1.1.1.2 lite-1:1.1.1.1 CSRG:1.1.1 netbsd-1-0-PATCH06:1.5 netbsd-1-0-PATCH05:1.5 netbsd-1-0-PATCH04:1.5 netbsd-1-0-PATCH03:1.5 netbsd-1-0-PATCH02:1.5 netbsd-1-0-PATCH1:1.5 netbsd-1-0-PATCH0:1.5 netbsd-1-0-RELEASE:1.5 netbsd-1-0:1.5.0.2 netbsd-1-0-base:1.5 netbsd-0-9-RELEASE:1.2 netbsd-0-9-BETA:1.2 netbsd-0-9-ALPHA2:1.2 netbsd-0-9-ALPHA:1.2 netbsd-0-9:1.2.0.2 netbsd-0-9-base:1.2 netbsd-0-8:1.1 netbsd-alpha-1:1.1; locks; strict; comment @ * @; 1.16 date 2012.02.23.22.57.53; author joerg; state Exp; branches; next 1.15; 1.15 date 2011.09.04.20.29.32; author joerg; state Exp; branches 1.15.2.1; next 1.14; 1.14 date 2009.04.26.15.55.50; author christos; state Exp; branches; next 1.13; 1.13 date 2009.04.12.14.01.20; author lukem; state Exp; branches; next 1.12; 1.12 date 2008.07.21.14.19.24; author lukem; state Exp; branches 1.12.6.1; next 1.11; 1.11 date 2003.08.07.11.14.28; author agc; state Exp; branches 1.11.34.1; next 1.10; 1.10 date 98.02.20.09.26.00; author mycroft; state Exp; branches; next 1.9; 1.9 date 98.02.17.17.45.55; author augustss; state Exp; branches; next 1.8; 1.8 date 97.10.19.04.21.27; author lukem; state Exp; branches; next 1.7; 1.7 date 95.08.31.22.41.02; author jtc; state Exp; branches; next 1.6; 1.6 date 94.12.23.01.11.01; author jtc; state Exp; branches; next 1.5; 1.5 date 94.03.28.02.16.57; author cgd; state Exp; branches; next 1.4; 1.4 date 93.10.13.18.34.30; author jtc; state Exp; branches; next 1.3; 1.3 date 93.08.01.18.13.24; author mycroft; state Exp; branches; next 1.2; 1.2 date 93.04.19.07.03.56; author mycroft; state Exp; branches; next 1.1; 1.1 date 93.04.09.12.59.32; author cgd; state Exp; branches 1.1.1.1; next ; 1.15.2.1 date 2012.04.17.00.09.35; author yamt; state Exp; branches; next ; 1.12.6.1 date 2009.05.13.19.19.55; author jym; state Exp; branches; next ; 1.11.34.1 date 2008.09.18.04.29.15; author wrstuden; state Exp; branches; next ; 1.1.1.1 date 94.12.22.21.08.40; author jtc; state Exp; branches; next 1.1.1.2; 1.1.1.2 date 95.08.31.22.38.05; author jtc; state Exp; branches; next ; desc @@ 1.16 log @Don't use while-loop with empty body. @ text @/* $NetBSD: look.c,v 1.15 2011/09/04 20:29:32 joerg Exp $ */ /*- * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * David Hitz of Auspex Systems, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * 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. */ #include #ifndef lint __COPYRIGHT("@@(#) Copyright (c) 1991, 1993\ The Regents of the University of California. All rights reserved."); #endif /* not lint */ #ifndef lint #if 0 static char sccsid[] = "@@(#)look.c 8.2 (Berkeley) 5/4/95"; #endif __RCSID("$NetBSD: look.c,v 1.15 2011/09/04 20:29:32 joerg Exp $"); #endif /* not lint */ /* * look -- find lines in a sorted list. * * The man page said that TABs and SPACEs participate in -d comparisons. * In fact, they were ignored. This implements historic practice, not * the manual page. */ #include #include #include #include #include #include #include #include #include #include #include #include #include "pathnames.h" /* * FOLD and DICT convert characters to a normal form for comparison, * according to the user specified flags. * * DICT expects integers because it uses a non-character value to * indicate a character which should not participate in comparisons. */ #define EQUAL 0 #define GREATER 1 #define LESS (-1) #define NO_COMPARE (-2) #define FOLD(c) (isascii(c) && isupper(c) ? tolower(c) : (c)) #define DICT(c) (isascii(c) && isalnum(c) ? (c) : NO_COMPARE) static int dflag, fflag; static char *binary_search(char *, char *, char *); static int compare(char *, char *, char *); static char *linear_search(char *, char *, char *); static int look(char *, char *, char *); static void print_from(char *, char *, char *); __dead static void usage(void); int main(int argc, char *argv[]) { struct stat sb; int ch, fd, termchar; char *back, *front, *string, *p; const char *file; size_t len; string = NULL; file = _PATH_WORDS; termchar = '\0'; while ((ch = getopt(argc, argv, "dft:")) != -1) switch(ch) { case 'd': dflag = 1; break; case 'f': fflag = 1; break; case 't': termchar = *optarg; break; case '?': default: usage(); } argc -= optind; argv += optind; switch (argc) { case 2: /* Don't set -df for user. */ string = *argv++; file = *argv; break; case 1: /* But set -df by default. */ dflag = fflag = 1; string = *argv; break; default: usage(); } if (termchar != '\0' && (p = strchr(string, termchar)) != NULL) *++p = '\0'; if ((fd = open(file, O_RDONLY, 0)) < 0 || fstat(fd, &sb)) err(2, "%s", file); len = (size_t)sb.st_size; if ((off_t)len != sb.st_size) { errno = EFBIG; err(2, "%s", file); } if ((front = mmap(NULL, len, PROT_READ, MAP_FILE|MAP_SHARED, fd, (off_t)0)) == NULL) err(2, "%s", file); back = front + len; exit(look(string, front, back)); } static int look(char *string, char *front, char *back) { int ch; char *readp, *writep; /* Reformat string string to avoid doing it multiple times later. */ for (readp = writep = string; (ch = *readp++) != 0; ) { if (fflag) ch = FOLD(ch); if (dflag) ch = DICT(ch); if (ch != NO_COMPARE) *(writep++) = ch; } *writep = '\0'; front = binary_search(string, front, back); front = linear_search(string, front, back); if (front) print_from(string, front, back); return (front ? 0 : 1); } /* * Binary search for "string" in memory between "front" and "back". * * This routine is expected to return a pointer to the start of a line at * *or before* the first word matching "string". Relaxing the constraint * this way simplifies the algorithm. * * Invariants: * front points to the beginning of a line at or before the first * matching string. * * back points to the beginning of a line at or after the first * matching line. * * Base of the Invariants. * front = NULL; * back = EOF; * * Advancing the Invariants: * * p = first newline after halfway point from front to back. * * If the string at "p" is not greater than the string to match, * p is the new front. Otherwise it is the new back. * * Termination: * * The definition of the routine allows it return at any point, * since front is always at or before the line to print. * * In fact, it returns when the chosen "p" equals "back". This * implies that there exists a string is least half as long as * (back - front), which in turn implies that a linear search will * be no more expensive than the cost of simply printing a string or two. * * Trying to continue with binary search at this point would be * more trouble than it's worth. */ #define SKIP_PAST_NEWLINE(p, back) \ while (p < back && *p++ != '\n') continue; static char * binary_search(char *string, char *front, char *back) { char *p; p = front + (back - front) / 2; SKIP_PAST_NEWLINE(p, back); /* * If the file changes underneath us, make sure we don't * infinitely loop. */ while (p < back && back > front) { if (compare(string, p, back) == GREATER) front = p; else back = p; p = front + (back - front) / 2; SKIP_PAST_NEWLINE(p, back); } return (front); } /* * Find the first line that starts with string, linearly searching from front * to back. * * Return NULL for no such line. * * This routine assumes: * * o front points at the first character in a line. * o front is before or at the first line to be printed. */ static char * linear_search(char *string, char *front, char *back) { while (front < back) { switch (compare(string, front, back)) { case EQUAL: /* Found it. */ return (front); break; case LESS: /* No such string. */ return (NULL); break; case GREATER: /* Keep going. */ break; } SKIP_PAST_NEWLINE(front, back); } return (NULL); } /* * Print as many lines as match string, starting at front. */ static void print_from(char *string, char *front, char *back) { for (; front < back && compare(string, front, back) == EQUAL; ++front) { for (; front < back && *front != '\n'; ++front) if (putchar(*front) == EOF) err(2, "stdout"); if (putchar('\n') == EOF) err(2, "stdout"); } } /* * Return LESS, GREATER, or EQUAL depending on how the string1 compares with * string2 (s1 ??? s2). * * o Matches up to len(s1) are EQUAL. * o Matches up to len(s2) are GREATER. * * Compare understands about the -f and -d flags, and treats comparisons * appropriately. * * The string "s1" is null terminated. The string s2 is '\n' terminated (or * "back" terminated). */ static int compare(char *s1, char *s2, char *back) { int ch; for (; *s1 && s2 < back && *s2 != '\n'; ++s1, ++s2) { ch = *s2; if (fflag) ch = FOLD(ch); if (dflag) ch = DICT(ch); if (ch == NO_COMPARE) { ++s2; /* Ignore character in comparison. */ continue; } if (*s1 != ch) return (*s1 < ch ? LESS : GREATER); } return (*s1 ? GREATER : EQUAL); } static void usage(void) { (void)fprintf(stderr, "usage: look [-df] [-t char] string [file]\n"); exit(2); } @ 1.15 log @ANSIfy + static + __dead @ text @d1 1 a1 1 /* $NetBSD: look.c,v 1.14 2009/04/26 15:55:50 christos Exp $ */ d45 1 a45 1 __RCSID("$NetBSD: look.c,v 1.14 2009/04/26 15:55:50 christos Exp $"); d221 1 a221 1 while (p < back && *p++ != '\n'); @ 1.15.2.1 log @sync with head @ text @d1 1 a1 1 /* $NetBSD$ */ d45 1 a45 1 __RCSID("$NetBSD$"); d221 1 a221 1 while (p < back && *p++ != '\n') continue; @ 1.14 log @fix broken overflow test. @ text @d1 1 a1 1 /* $NetBSD: look.c,v 1.13 2009/04/12 14:01:20 lukem Exp $ */ d45 1 a45 1 __RCSID("$NetBSD: look.c,v 1.13 2009/04/12 14:01:20 lukem Exp $"); d87 1 a87 1 int dflag, fflag; d89 6 a94 7 char *binary_search __P((char *, char *, char *)); int compare __P((char *, char *, char *)); char *linear_search __P((char *, char *, char *)); int look __P((char *, char *, char *)); int main __P((int, char **)); void print_from __P((char *, char *, char *)); void usage __P((void)); d97 1 a97 3 main(argc, argv) int argc; char *argv[]; d156 2 a157 3 int look(string, front, back) char *string, *front, *back; d223 2 a224 3 char * binary_search(string, front, back) char *string, *front, *back; d257 2 a258 3 char * linear_search(string, front, back) char *string, *front, *back; d279 2 a280 3 void print_from(string, front, back) char *string, *front, *back; d304 2 a305 3 int compare(s1, s2, back) char *s1, *s2, *back; d326 2 a327 2 void usage() @ 1.13 log @Fix WARNS=4 issues @ text @d1 1 a1 1 /* $NetBSD: look.c,v 1.12 2008/07/21 14:19:24 lukem Exp $ */ d45 1 a45 1 __RCSID("$NetBSD: look.c,v 1.12 2008/07/21 14:19:24 lukem Exp $"); d106 1 d147 6 a152 3 if (sb.st_size > (off_t)SIZE_T_MAX) err(2, "%s: %s", file, strerror(EFBIG)); if ((front = mmap(NULL, (size_t)sb.st_size, d155 1 a155 1 back = front + sb.st_size; @ 1.12 log @Remove the \n and tabs from the __COPYRIGHT() strings. Tweak to use a consistent format. @ text @d1 1 a1 1 /* $NetBSD: look.c,v 1.11 2003/08/07 11:14:28 agc Exp $ */ d45 1 a45 1 __RCSID("$NetBSD: look.c,v 1.11 2003/08/07 11:14:28 agc Exp $"); d104 2 a105 1 char *back, *file, *front, *string, *p; d146 1 a146 1 if (sb.st_size > SIZE_T_MAX) @ 1.12.6.1 log @Sync with HEAD. Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html @ text @d1 1 a1 1 /* $NetBSD: look.c,v 1.14 2009/04/26 15:55:50 christos Exp $ */ d45 1 a45 1 __RCSID("$NetBSD: look.c,v 1.14 2009/04/26 15:55:50 christos Exp $"); d104 1 a104 3 char *back, *front, *string, *p; const char *file; size_t len; d145 3 a147 6 len = (size_t)sb.st_size; if ((off_t)len != sb.st_size) { errno = EFBIG; err(2, "%s", file); } if ((front = mmap(NULL, len, d150 1 a150 1 back = front + len; @ 1.11 log @Move UCB-licensed code from 4-clause to 3-clause licence. Patches provided by Joel Baker in PR 22365, verified by myself. @ text @d1 1 a1 1 /* $NetBSD: look.c,v 1.10 1998/02/20 09:26:00 mycroft Exp $ */ d37 2 a38 2 __COPYRIGHT("@@(#) Copyright (c) 1991, 1993\n\ The Regents of the University of California. All rights reserved.\n"); d45 1 a45 1 __RCSID("$NetBSD: look.c,v 1.10 1998/02/20 09:26:00 mycroft Exp $"); @ 1.11.34.1 log @Sync with wrstuden-revivesa-base-2. @ text @d1 1 a1 1 /* $NetBSD: look.c,v 1.11 2003/08/07 11:14:28 agc Exp $ */ d37 2 a38 2 __COPYRIGHT("@@(#) Copyright (c) 1991, 1993\ The Regents of the University of California. All rights reserved."); d45 1 a45 1 __RCSID("$NetBSD: look.c,v 1.11 2003/08/07 11:14:28 agc Exp $"); @ 1.10 log @Nit: Use MAP_SHARED for read-only mappings where appropriate. @ text @d1 1 a1 1 /* $NetBSD: look.c,v 1.9 1998/02/17 17:45:55 augustss Exp $ */ d18 1 a18 5 * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors d45 1 a45 1 __RCSID("$NetBSD: look.c,v 1.9 1998/02/17 17:45:55 augustss Exp $"); @ 1.9 log @Add MAP_PRIVATE|MAP_FILE to mmap() call. @ text @d1 1 a1 1 /* $NetBSD: look.c,v 1.8 1997/10/19 04:21:27 lukem Exp $ */ d49 1 a49 1 __RCSID("$NetBSD: look.c,v 1.8 1997/10/19 04:21:27 lukem Exp $"); d151 2 a152 3 if ((front = mmap(NULL, (size_t)sb.st_size, PROT_READ, MAP_PRIVATE|MAP_FILE, fd, (off_t)0)) == NULL) @ 1.8 log @WARNSify, fix .Nm usage, getopt returns -1 not EOF, deprecate register @ text @d1 1 a1 1 /* $NetBSD: look.c,v 1.7 1995/08/31 22:41:02 jtc Exp $ */ d49 1 a49 1 __RCSID("$NetBSD$"); d152 2 a153 1 (size_t)sb.st_size, PROT_READ, 0, fd, (off_t)0)) == NULL) @ 1.7 log @Sync with 4.4lite2 @ text @d1 1 a1 1 /* $NetBSD: look.c,v 1.6 1994/12/23 01:11:01 jtc Exp $ */ d39 1 d41 2 a42 3 static char copyright[] = "@@(#) Copyright (c) 1991, 1993\n\ The Regents of the University of California. All rights reserved.\n"; d49 1 a49 1 static char rcsid[] = "$NetBSD: look.c,v 1.6 1994/12/23 01:11:01 jtc Exp $"; d97 1 d110 1 d113 1 a113 1 while ((ch = getopt(argc, argv, "dft:")) != EOF) d162 2 a163 2 register int ch; register char *readp, *writep; d166 1 a166 1 for (readp = writep = string; ch = *readp++;) { d228 1 a228 1 register char *string, *front, *back; d230 1 a230 1 register char *p; d286 1 a286 1 register char *string, *front, *back; d312 1 a312 1 register char *s1, *s2, *back; d314 1 a314 1 register int ch; @ 1.6 log @Merged with 4.4lite. Changed to conform to NetBSD's new RCS Id convention. Changed to use err() and errx(). @ text @d1 1 a1 1 /* $NetBSD: $ */ d47 1 a47 1 static char sccsid[] = "@@(#)look.c 8.1 (Berkeley) 6/14/93"; d49 1 a49 1 static char rcsid[] = "$NetBSD: $"; d64 1 a64 1 #include d67 1 a70 1 #include d73 1 @ 1.5 log @no more MAP_FILE @ text @d1 2 d4 2 a5 2 * Copyright (c) 1991 The Regents of the University of California. * All rights reserved. d40 3 a42 3 char copyright[] = "@@(#) Copyright (c) 1991 The Regents of the University of California.\n\ All rights reserved.\n"; d46 4 a49 2 /*static char sccsid[] = "from: @@(#)look.c 5.1 (Berkeley) 7/21/91";*/ static char rcsid[] = "$Id: look.c,v 1.4 1993/10/13 18:34:30 jtc Exp $"; d63 2 d72 1 a93 1 void err __P((const char *fmt, ...)); d97 1 a97 1 static void usage __P((void)); d99 1 d105 2 a106 2 int ch, fd; char *back, *file, *front, *string; d109 2 a110 1 while ((ch = getopt(argc, argv, "df")) != EOF) d118 3 d141 10 a150 4 if ((fd = open(file, O_RDONLY, 0)) < 0 || fstat(fd, &sb) || (front = mmap(NULL, sb.st_size, PROT_READ, 0, fd, (off_t)0)) == NULL) err("%s: %s", file, strerror(errno)); d155 1 d232 5 a236 1 while (p != back) { d288 1 a288 1 err("stdout: %s", strerror(errno)); d290 1 a290 1 err("stdout: %s", strerror(errno)); d330 1 a330 1 static void d333 1 a333 29 (void)fprintf(stderr, "usage: look [-df] string [file]\n"); exit(2); } #if __STDC__ #include #else #include #endif void #if __STDC__ err(const char *fmt, ...) #else err(fmt, va_alist) char *fmt; va_dcl #endif { va_list ap; #if __STDC__ va_start(ap, fmt); #else va_start(ap); #endif (void)fprintf(stderr, "look: "); (void)vfprintf(stderr, fmt, ap); va_end(ap); (void)fprintf(stderr, "\n"); a334 1 /* NOTREACHED */ @ 1.4 log @#include , so getopt(), optarg, opterr, optind, and optopt declarations can be removed from . @ text @d45 1 a45 1 static char rcsid[] = "$Id: look.c,v 1.3 1993/08/01 18:13:24 mycroft Exp $"; d131 1 a131 1 (front = mmap(NULL, sb.st_size, PROT_READ, MAP_FILE, fd, @ 1.3 log @Add RCS identifiers. @ text @d45 1 a45 1 static char rcsid[] = "$Id: $"; d65 1 @ 1.2 log @Cleanup for GCC 2. @ text @d44 2 a45 1 static char sccsid[] = "@@(#)look.c 5.1 (Berkeley) 7/21/91"; @ 1.1 log @added, from net/2 (patch 124). @ text @d89 1 a89 1 void usage __P((void)); @ 1.1.1.1 log @imported from 44lite @ text @d2 2 a3 2 * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. d38 3 a40 3 static char copyright[] = "@@(#) Copyright (c) 1991, 1993\n\ The Regents of the University of California. All rights reserved.\n"; d44 1 a44 1 static char sccsid[] = "@@(#)look.c 8.1 (Berkeley) 6/14/93"; a57 2 #include d89 1 a89 2 static void usage __P((void)); d96 2 a97 2 int ch, fd, termchar; char *back, *file, *front, *string, *p; d100 1 a100 2 termchar = '\0'; while ((ch = getopt(argc, argv, "dft:")) != EOF) a107 3 case 't': termchar = *optarg; break; d128 3 a130 9 if (termchar != '\0' && (p = strchr(string, termchar)) != NULL) *++p = '\0'; if ((fd = open(file, O_RDONLY, 0)) < 0 || fstat(fd, &sb)) err("%s: %s", file, strerror(errno)); if (sb.st_size > SIZE_T_MAX) err("%s: %s", file, strerror(EFBIG)); if ((front = mmap(NULL, (size_t)sb.st_size, PROT_READ, 0, fd, (off_t)0)) == NULL) d212 1 a212 5 /* * If the file changes underneath us, make sure we don't * infinitely loop. */ while (p < back && back > front) { d309 1 a309 1 (void)fprintf(stderr, "usage: look [-df] [-t char] string [file]\n"); @ 1.1.1.2 log @imported from 44lite2 @ text @d44 1 a44 1 static char sccsid[] = "@@(#)look.c 8.2 (Berkeley) 5/4/95"; d59 1 a59 1 #include a61 1 #include d65 1 a65 2 #include @