bore

basic core utilities (PD)
git clone git://bvnf.space/bore.git
Log | Files | Refs | README

commit bf2ed908f62d6b74402bddf408b8bb15ea1f1487
parent 3350a41744998de1b153f50d3e96be8bf7787e3d
Author: phoebos <ben@bvnf.space>
Date:   Sat, 19 Feb 2022 16:42:41 +0000

grep, ls: remove -h option, print usage on ?

Diffstat:
Mgrep.c | 9+++++----
Mls.c | 8++++----
2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/grep.c b/grep.c @@ -68,7 +68,7 @@ main(int argc, char **argv) { int c; int REGFLAGS = REG_NOSUB; int flags = 0; - while ((c = getopt(argc, argv, "EFchiv")) != -1) { + while ((c = getopt(argc, argv, "EFciv")) != -1) { switch (c) { case 'E': REGFLAGS |= REG_EXTENDED; @@ -79,9 +79,6 @@ main(int argc, char **argv) { case 'c': flags |= FLAG_c; break; - case 'h': - print_usage(); - return 0; case 'i': REGFLAGS |= REG_ICASE; break; @@ -103,6 +100,10 @@ main(int argc, char **argv) { return 1; } + /* TODO: allow '--' after pattern_list + * make a list of regex_ts to do for the -e and -f options + */ + char *regexp = *++argv; regex_t re; int regerr = regcomp(&re, regexp, REGFLAGS); diff --git a/ls.c b/ls.c @@ -371,7 +371,7 @@ main(int argc, char **argv) { int c, ret_val; flags = ret_val = 0; - while ((c = getopt(argc, argv, "1AFSacfghilmnopqrtu")) != -1) { + while ((c = getopt(argc, argv, "1AFSacfgilmnopqrtu")) != -1) { switch (c) { case '1': flags |= FLAG_1 | FLAG_q; @@ -400,9 +400,6 @@ main(int argc, char **argv) { flags |= FLAG_g | FLAG_l | FLAG_1; flags &= ~FLAG_m; break; - case 'h': - printf("usage: %s [-1AFSacfgilmnopqrtu]\n", argv[0]); - return 0; case 'i': flags |= FLAG_i; break; @@ -439,6 +436,9 @@ main(int argc, char **argv) { flags |= FLAG_t; flags &= ~FLAG_S; break; + case '?': + fprintf(stderr, "usage: %s [-1AFSacfgilmnopqrtu]\n", argv[0]); + return 1; } } argv += optind - 1;