summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/grijp.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/grijp.c b/src/grijp.c
index 0884be6..feb92c1 100644
--- a/src/grijp.c
+++ b/src/grijp.c
@@ -29,6 +29,8 @@ static void **patterns = NULL; // can hold `char*` or `regex_t*`
static size_t nfiles;
+static bool anyMatch = false;
+
static void usage(FILE *f) {
fprintf(f,
"Gebruik: grijp [-hV] [PATRONEN] [BESTAND]...\n"
@@ -78,7 +80,7 @@ static char** parse_options(int argc, char **argv) {
case '?':
fprintf(stderr, "grijp: Ongeldige optie: -%c\n", optopt);
usage(stderr);
- exit(1);
+ exit(2);
}
}
@@ -113,7 +115,7 @@ static void compile_regexps() {
if (regcomp(regexp, patterns[i], flags) != 0) {
fprintf(stderr, "grijp: fout tijdens compileren van reguliere expressie\n");
- exit(1);
+ exit(2);
}
free(patterns[i]);
@@ -138,10 +140,10 @@ static int process(char *fname, bool isstdin) {
FILE *stream = isstdin ? stdin : fopen(fname, binary ? "rb" : "r");
if (stream == NULL && !isstdin) {
fprintf(stderr, "grijp: %s: fout tijdens openen bestand\n", fname);
- return 1;
+ return 2;
} else if (stream == NULL && isstdin) {
fprintf(stderr, "grijp: fout tijdens lezen standaard invoer\n");
- return 1;
+ return 2;
}
char *line = NULL;
@@ -163,6 +165,7 @@ static int process(char *fname, bool isstdin) {
if (invert) matches = !matches;
if (matches) {
+ anyMatch = true;
printMatch(fname, line);
if (list) goto done;
}
@@ -179,7 +182,7 @@ int entry_grijp(int argc, char **argv) {
char **args = parse_options(argc, argv);
if (*args == NULL) {
fprintf(stderr, "grijp: geen patroon gegeven\n");
- return 1;
+ return 2;
}
gpats = *args;
@@ -204,5 +207,7 @@ int entry_grijp(int argc, char **argv) {
}
for (size_t i = 0; i < npat; i++) free(patterns[i]);
free(patterns);
+
+ if (res == 0 && !anyMatch) res = 1;
return res;
}