[hackers] [sbase][PATCH] Add egrep and fgrep

From: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
Date: Tue, 5 Jan 2016 14:01:38 +0100

These tools are not part of POSIX, but they were part of the original
UNIX and even today they are still wide used. The work done by this
tools can be done by grep, so this implementation is only masking the
code with different names to get the work done.
---
 Makefile | 4 +++-
 grep.c   | 5 +++++
 2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
index 1c09cac..f6f8dc8 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -196,7 +196,9 @@ confstr_l.h limits_l.h sysconf_l.h pathconf_l.h: getconf.sh
 install: all
 	mkdir -p $(DESTDIR)$(PREFIX)/bin
 	cp -f $(BIN) $(DESTDIR)$(PREFIX)/bin
-	cd $(DESTDIR)$(PREFIX)/bin && ln -f test [ && chmod 755 $(BIN)
+	ln $(DESTDIR)$(PREFIX)/bin/grep $(DESTDIR)$(PREFIX)/bin/egrep
+	ln $(DESTDIR)$(PREFIX)/bin/grep $(DESTDIR)$(PREFIX)/bin/fgrep
+	cd $(DESTDIR)$(PREFIX)/bin && ln -f test [ && chmod 755 $(BIN) egrep fgrep
 	mkdir -p $(DESTDIR)$(MANPREFIX)/man1
 	for m in $(MAN); do sed "s/^\.Os sbase/.Os sbase $(VERSION)/g" < "$$m" > $(DESTDIR)$(MANPREFIX)/man1/"$$m"; done
 	cd $(DESTDIR)$(MANPREFIX)/man1 && chmod 644 $(MAN)
diff --git a/grep.c b/grep.c
index ca255ff..c01d151 100644
--- a/grep.c
+++ b/grep.c
_AT_@ -180,6 +180,11 @@ main(int argc, char *argv[])
 
 	SLIST_INIT(&phead);
 
+	if (!strcmp(argv[0], "egrep"))
+		Eflag =1, flags |= REG_EXTENDED;
+	else if (!strcmp(argv[0], "fgrep"))
+		Fflag = 1;
+
 	ARGBEGIN {
 	case 'E':
 		Eflag = 1;
-- 
2.1.4
Received on Tue Jan 05 2016 - 14:01:38 CET

This archive was generated by hypermail 2.3.0 : Tue Jan 05 2016 - 14:12:13 CET