* Copyright (c) 1987 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
"@(#) Copyright (c) 1987 Regents of the University of California.\n\
static char sccsid
[] = "@(#)look.c 4.4 (Berkeley) %G%";
static int fold
, dict
, len
;
static char *filename
= "/usr/dict/words";
register off_t bot
, mid
, top
;
char entry
[MAXLINELEN
], copy
[MAXLINELEN
];
while ((c
= getopt(argc
, argv
, "df")) != EOF
)
case 1: /* if nothing set, default to dictionary order and folding */
if (!freopen(filename
, "r", stdin
)) {
fprintf(stderr
,"look: can't read %s.\n", filename
);
if (fstat(fileno(stdin
), &sb
)) {
len
= strlen(*argv
); /* may have changed */
if (len
> MAXLINELEN
- 1) {
fputs("look: search string is too long.\n", stderr
);
for (bot
= 0, top
= sb
.st_size
;;) {
(void)fseek(stdin
, mid
, L_SET
);
for (++mid
; (c
= getchar()) != EOF
&& c
!= '\n'; ++mid
);
if (strncmp(*argv
, copy
, len
) <= 0) {
(void)fseek(stdin
, bot
, L_SET
);
while (ftell(stdin
) < top
) {
if (!(val
= strncmp(*argv
, copy
, len
))) {
if (strncmp(*argv
, copy
, len
))
if ((c
= getchar()) == EOF
)
* create canonical version of word
register char *src
, *copy
;
for (cnt
= len
+ 1; (c
= *src
++) && cnt
; --cnt
)
*copy
++ = fold
&& isupper(c
) ? tolower(c
) : c
;
* print a usage message and die
fputs("usage: look [-df] string [file]\n", stderr
);