1
0
mirror of https://github.com/openbsd/src.git synced 2026-04-25 06:35:46 +00:00

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@
This commit is contained in:
jca
2019-12-03 09:14:37 +00:00
parent 572fa3f576
commit e8a721176f
2 changed files with 14 additions and 10 deletions

View File

@@ -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<43>dan Sm<53>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)

View File

@@ -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<43>dan Sm<53>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;
}
}