Hello,

reading the grep-code in sbase kind of left me wondering why this enum
was implemented. In the contexts it's been used it doesn't make much
sense and obfuscates the code.

Cheers

FRIGN

-- 
FRIGN <d...@frign.de>
>From 48912a55e9122fd221d5f9c800b679ceaa622f53 Mon Sep 17 00:00:00 2001
From: FRIGN <d...@frign.de>
Date: Sun, 11 May 2014 23:16:14 +0200
Subject: [PATCH] Remove unnecessary enum to make clearer what we mean.

---
 grep.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/grep.c b/grep.c
index 269ec92..29110b8 100644
--- a/grep.c
+++ b/grep.c
@@ -8,8 +8,6 @@
 #include "text.h"
 #include "util.h"
 
-enum { Match = 0, NoMatch = 1, Error = 2 };
-
 static void addpattern(const char *);
 static bool grep(FILE *, const char *);
 
@@ -27,7 +25,7 @@ static struct plist {
 static void
 usage(void)
 {
-	enprintf(Error, "usage: %s [-Ecilnqv] [-e pattern] pattern [files...]\n", argv0);
+	eprintf("usage: %s [-Ecilnqv] [-e pattern] pattern [files...]\n", argv0);
 }
 
 int
@@ -78,7 +76,7 @@ main(int argc, char *argv[])
 			char buf[BUFSIZ];
 
 			regerror(n, &pnode->preg, buf, sizeof buf);
-			enprintf(Error, "invalid pattern: %s\n", buf);
+			eprintf("invalid pattern: %s\n", buf);
 		}
 	}
 	many = (argc > 1);
@@ -87,7 +85,7 @@ main(int argc, char *argv[])
 	} else {
 		for(i = 0; i < argc; i++) {
 			if(!(fp = fopen(argv[i], "r")))
-				enprintf(Error, "fopen %s:", argv[i]);
+				eprintf("fopen %s:", argv[i]);
 			if(grep(fp, argv[i]))
 				match = true;
 			fclose(fp);
@@ -101,7 +99,7 @@ main(int argc, char *argv[])
 		free(pnode);
 		pnode = tmp;
 	}
-	return match ? Match : NoMatch;
+	return match ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
 void
@@ -142,7 +140,7 @@ grep(FILE *fp, const char *str)
 				puts(str);
 				goto end;
 			case 'q':
-				exit(Match);
+				exit(EXIT_SUCCESS);
 			default:
 				if(many)
 					printf("%s:", str);
@@ -158,7 +156,7 @@ grep(FILE *fp, const char *str)
 		printf("%ld\n", c);
 end:
 	if(ferror(fp))
-		enprintf(Error, "%s: read error:", str);
+		eprintf("%s: read error:", str);
 	free(buf);
 	return match;
 }
-- 
1.8.3.2

Reply via email to