[hackers] [sbase] tr: add dflag, error with usage() on invalid flag combination || Hiltjo Posthuma

From: <git_AT_suckless.org>
Date: Wed, 09 Apr 2014 16:40:26 +0200

commit ff474a8cbc9514424c9d18013febfb8faca001c7
Author: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Wed Apr 9 14:12:34 2014 +0200

    tr: add dflag, error with usage() on invalid flag combination
    
    Signed-off-by: Hiltjo Posthuma <hiltjo_AT_codemadness.org>

diff --git a/tr.c b/tr.c
index 0ac0c86..aad2245 100644
--- a/tr.c
+++ b/tr.c
_AT_@ -12,7 +12,7 @@
 static void
 usage(void)
 {
- eprintf("usage: %s set1 [set2]
", argv0);
+ eprintf("usage: %s [-d] set1 [set2]
", argv0);
 }
 
 static void
_AT_@ -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, "");
 
_AT_@ -126,6 +127,9 @@ main(int argc, char *argv[])
                 eprintf("mmap:");
 
         ARGBEGIN {
+ case 'd':
+ dflag = 1;
+ break;
         default:
                 usage();
         } ARGEND;
_AT_@ -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))
Received on Wed Apr 09 2014 - 16:40:26 CEST

This archive was generated by hypermail 2.3.0 : Wed Apr 09 2014 - 16:48:25 CEST