diff options
author | Jeremie Courreges-Anglas <jca@cvs.openbsd.org> | 2019-12-03 09:14:38 +0000 |
---|---|---|
committer | Jeremie Courreges-Anglas <jca@cvs.openbsd.org> | 2019-12-03 09:14:38 +0000 |
commit | 6a1b27f1ba1d870dd24f1d2c98893b83442e504d (patch) | |
tree | bcddafd4f747e8867ea4b710d1b61cdfd93c6735 /usr.bin | |
parent | 836f76b760c83baef9c6aaf7b81d83c9829f89bf (diff) |
With -R and an implicit ".", don't prepend file paths with "./"
Looks nicer and matches the output of GNU grep.
ok millert@ deraadt@ visa@ miod@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/grep/grep.c | 10 | ||||
-rw-r--r-- | usr.bin/grep/util.c | 14 |
2 files changed, 14 insertions, 10 deletions
diff --git a/usr.bin/grep/grep.c b/usr.bin/grep/grep.c index 8321c54a495..55563095404 100644 --- a/usr.bin/grep/grep.c +++ b/usr.bin/grep/grep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: grep.c,v 1.63 2019/12/02 21:50:11 jca Exp $ */ +/* $OpenBSD: grep.c,v 1.64 2019/12/03 09:14:37 jca Exp $ */ /*- * Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav @@ -473,12 +473,6 @@ main(int argc, char *argv[]) ++argv; } - if (Rflag && argc == 0) { - /* default to . if no path given */ - static char *dot_argv[] = { ".", NULL }; - argv = dot_argv; - argc = 1; - } if (Eflag) cflags |= REG_EXTENDED; if (Fflag) @@ -516,7 +510,7 @@ main(int argc, char *argv[]) if ((argc == 0 || argc == 1) && !Rflag && !Hflag) hflag = 1; - if (argc == 0) + if (argc == 0 && !Rflag) exit(!procfile(NULL)); if (Rflag) diff --git a/usr.bin/grep/util.c b/usr.bin/grep/util.c index b683e8510b7..db605e99cee 100644 --- a/usr.bin/grep/util.c +++ b/usr.bin/grep/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.61 2019/10/07 17:47:32 tedu Exp $ */ +/* $OpenBSD: util.c,v 1.62 2019/12/03 09:14:37 jca Exp $ */ /*- * Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav @@ -61,6 +61,12 @@ grep_tree(char **argv) FTS *fts; FTSENT *p; int c, fts_flags; + char *dot_argv[] = { ".", NULL }; + char *path; + + /* default to . if no path given */ + if (argv[0] == NULL) + argv = dot_argv; c = 0; @@ -81,7 +87,11 @@ grep_tree(char **argv) case FTS_DP: break; default: - c += procfile(p->fts_path); + path = p->fts_path; + /* skip "./" if implied */ + if (argv == dot_argv && p->fts_pathlen >= 2) + path += 2; + c += procfile(path); break; } } |