summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLieuwe Rooijakkers <lieuwerooijakkers@gmail.com>2024-08-08 16:12:17 +0200
committerLieuwe Rooijakkers <lieuwerooijakkers@gmail.com>2024-08-08 16:12:17 +0200
commit21ef7b9f4a7b4a774e70d7a27abf02ff114b26d9 (patch)
tree4ab42443d82b3959872e7626f1373e9fe411288d
parentcfab982de06423026bd273f3c4818c1b8dca03be (diff)
grijp: don't open files as binary per default
-rw-r--r--src/grijp.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/grijp.c b/src/grijp.c
index 29a13b1..2a039b8 100644
--- a/src/grijp.c
+++ b/src/grijp.c
@@ -20,6 +20,7 @@ static char *gpats;
static bool fixed = false;
static bool extended = false;
static bool icase = false;
+static bool binary = false;
static size_t npat = 0;
static void **patterns = NULL; // can hold `char*` or `regex_t*`
@@ -37,7 +38,7 @@ static void usage(FILE *f) {
// Returns pointer to argument array containing patterns and then the file names
static char** parse_options(int argc, char **argv) {
int opt;
- while ((opt = getopt(argc, argv, "FiEhV")) != -1) {
+ while ((opt = getopt(argc, argv, "FiEUhV")) != -1) {
switch (opt) {
case 'F':
fixed = true;
@@ -48,6 +49,9 @@ static char** parse_options(int argc, char **argv) {
case 'E':
extended = true;
break;
+ case 'U':
+ binary = true;
+ break;
case 'h':
usage(stdout);
@@ -104,7 +108,7 @@ static void compile_regexps() {
}
static int process_regex(char *fname, bool isstdin) {
- FILE *stream = isstdin ? stdin : fopen(fname, "rb");
+ FILE *stream = isstdin ? stdin : fopen(fname, binary ? "rb" : "r");
char *line = NULL;
size_t linen = 0;
@@ -127,7 +131,7 @@ static int process_regex(char *fname, bool isstdin) {
}
static int process_fixed(char *fname, bool isstdin) {
- FILE *stream = isstdin ? stdin : fopen(fname, "rb");
+ FILE *stream = isstdin ? stdin : fopen(fname, binary ? "rb" : "r");
char *line = NULL;
size_t linen = 0;