sbase

suckless unix tools
git clone git://git.2f30.org/sbase
Log | Files | Refs | README | LICENSE

commit ff474a8cbc9514424c9d18013febfb8faca001c7
parent 3e49e946b76e235dfa08e461041f6ae36151062b
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Wed,  9 Apr 2014 14:12:34 +0200

tr: add dflag, error with usage() on invalid flag combination

Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>

Diffstat:
Mtr.c | 18+++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/tr.c b/tr.c @@ -12,7 +12,7 @@ static void usage(void) { - eprintf("usage: %s set1 [set2]\n", argv0); + eprintf("usage: %s [-d] set1 [set2]\n", argv0); } static void @@ -117,6 +117,7 @@ main(int argc, char *argv[]) char *buf = NULL; size_t size = 0; void (*mapfunc)(const wchar_t*, char*); + int dflag = 0; setlocale(LC_ALL, ""); @@ -126,6 +127,9 @@ main(int argc, char *argv[]) eprintf("mmap:"); ARGBEGIN { + case 'd': + dflag = 1; + break; default: usage(); } ARGEND; @@ -133,12 +137,16 @@ main(int argc, char *argv[]) if(argc == 0) usage(); - if(argc >= 2) { - parsemapping(argv[0], argv[1], mappings); - mapfunc = maptoset; - } else { + if(dflag) { + if(argc >= 2) + usage(); parsemapping(argv[0], NULL, mappings); mapfunc = maptonull; + } else { + if(argc != 2) + usage(); + parsemapping(argv[0], argv[1], mappings); + mapfunc = maptoset; } while(afgets(&buf, &size, stdin))