fixes for minix grep

This commit is contained in:
Ben Gras 2010-06-20 11:55:19 +00:00
parent bb830fc0d3
commit 28663f45d6
5 changed files with 21 additions and 14 deletions

View file

@ -12,7 +12,7 @@ SUBDIR= aal add_route adduser advent arp ash at autil awk \
dhrystone diff dirname dis88 du dumpcore easypack \
ed eject elle elvis env expand factor file \
find finger fingerd fix fold format fortune fsck \
fsck1 ftp101 ftpd200 getty gomoku head host \
fsck1 ftp101 ftpd200 getty grep gomoku head host \
hostaddr id ifconfig ifdef indent install \
intr ipcrm ipcs irdpd isoread join kill last leave \
lex life loadkeys loadramdisk logger login look lp \

View file

@ -17,11 +17,12 @@ MLINKS= grep.1 egrep.1 \
CFLAGS+= -Wall
.if ${OPSYS} == "Minix"
CPPFLAGS+= -DNOZ -D_POSIX_SOURCE -D_MINIX
.include <minix.prog.mk>
.else
LDADD= -lz
DPADD= ${LIBZ}
.if ${OPSYS} == "Minix"
CPPFLAGS+= -D_POSIX_SOURCE -D_MINIX
.include <minix.prog.mk>
.else
.include <bsd.prog.mk>
.endif

View file

@ -42,7 +42,9 @@ static size_t lnbuflen;
#endif
#define FILE_STDIO 0
#ifndef __minix
#define FILE_MMAP 1
#endif
#define FILE_GZIP 2
struct file {
@ -142,11 +144,13 @@ grep_open(char *path, char *mode)
} else
#endif
{
#ifdef FILE_MMAP
/* try mmap first; if it fails, try stdio */
if ((f->mmf = mmopen(fname, mode)) != NULL) {
f->type = FILE_MMAP;
return f;
}
#endif
f->type = FILE_STDIO;
if ((f->f = fopen(path, mode)) != NULL)
return f;
@ -165,8 +169,10 @@ grep_bin_file(file_t *f)
switch (f->type) {
case FILE_STDIO:
return bin_file(f->f);
#ifdef FILE_MMAP
case FILE_MMAP:
return mmbin_file(f->mmf);
#endif
#ifndef NOZ
case FILE_GZIP:
return gzbin_file(f->gzf);
@ -183,8 +189,10 @@ grep_fgetln(file_t *f, size_t *l)
switch (f->type) {
case FILE_STDIO:
return fgetln(f->f, l);
#ifdef FILE_MMAP
case FILE_MMAP:
return mmfgetln(f->mmf, l);
#endif
#ifndef NOZ
case FILE_GZIP:
return gzfgetln(f->gzf, l);
@ -202,9 +210,11 @@ grep_close(file_t *f)
case FILE_STDIO:
fclose(f->f);
break;
#ifdef FILE_MMAP
case FILE_MMAP:
mmclose(f->mmf);
break;
#endif
#ifndef NOZ
case FILE_GZIP:
gzclose(f->gzf);

View file

@ -102,8 +102,6 @@ struct patfile {
};
SLIST_HEAD(, patfile) patfilelh;
extern char *__progname;
static void
usage(void)
{
@ -114,7 +112,7 @@ usage(void)
"usage: %s [-abcEFGHhIiLlnoPqRSsUVvwxZ] [-A num] [-B num] [-C[num]]\n"
#endif
"\t[-e pattern] [-f file] [--binary-files=value] [--context[=num]]\n"
"\t[--line-buffered] [pattern] [file ...]\n", __progname);
"\t[--line-buffered] [pattern] [file ...]\n", getprogname());
exit(2);
}
@ -240,11 +238,7 @@ main(int argc, char *argv[])
SLIST_INIT(&patfilelh);
#ifdef __minix
setprogname(argv[0]);
#endif
switch (__progname[0]) {
switch (getprogname()[0]) {
case 'e':
Eflag++;
break;
@ -257,7 +251,7 @@ main(int argc, char *argv[])
#ifndef NOZ
case 'z':
Zflag++;
switch(__progname[1]) {
switch(getprogname()[1]) {
case 'e':
Eflag++;
break;

View file

@ -1,3 +1,4 @@
#ifndef __minix
/* $OpenBSD: mmfile.c,v 1.11 2006/09/19 05:52:23 otto Exp $ */
/*-
@ -100,3 +101,4 @@ mmfgetln(mmf_t *mmf, size_t *l)
++mmf->ptr;
return p;
}
#endif