From 2748ee6a784c01b03eca6f8c9ba16ed705e90068 Mon Sep 17 00:00:00 2001 From: Steffen Nurpmeso Date: Tue, 1 May 2018 20:22:21 +0200 Subject: [PATCH] a_main_getopt(): treat --version as -V --- main.c | 14 +++++++++----- nail.1 | 8 +++++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/main.c b/main.c index 0ab01ddd..dc073fb0 100644 --- a/main.c +++ b/main.c @@ -118,7 +118,7 @@ VL ui16_t const n_class_char[1 + 0x7F] = { static char const *a_main_oarg; static int a_main_oind, /*_oerr,*/ a_main_oopt; -/* Our own little getopt(3); note --help is special-treated as 'h' */ +/* A little getopt(3). Note: --help/--version == -h/-v */ static int a_main_getopt(int argc, char * const argv[], char const *optstring); /* */ @@ -207,12 +207,16 @@ a_main_getopt(int argc, char * const argv[], char const *optstring){ goto jleave; } - /* Special support for --help, which is quite common */ - if(a_main_oopt == '-' && !strcmp(curp, "-help") && - &curp[-1] == argv[a_main_oind]){ + /* Special support for --help and --version, which are quite common */ + if(a_main_oopt == '-' && &curp[-1] == argv[a_main_oind]){ ++a_main_oind; rv = 'h'; - goto jleave; + if(!strcmp(curp, "-help")) + goto jleave; + rv = 'V'; + if(!strcmp(curp, "-version")) + goto jleave; + --a_main_oind; } /* Definitive error */ diff --git a/nail.1 b/nail.1 index 94402a84..db3a8667 100644 --- a/nail.1 +++ b/nail.1 @@ -77,9 +77,6 @@ . .\" Keep in SYNC: ./nail.1:"SYNOPSIS, main() .Nm \*(uA -.Fl h | Fl Fl help -.Pp -.Nm \*(uA .Bk -words .Op Fl BDdEFinv~# .Op Fl \&: Ar spec @@ -131,6 +128,11 @@ .Op Ar file .Op Fl Fl \~ Ns : Ns Ar mta-option Ns \&: .Ek +.Pp +.Nm \*(uA +.Fl h | Fl Fl help +.Nm \*(uA +.Fl V | Fl Fl version . .\" }}} . -- 2.11.4.GIT