Skip to content

Commit 037bb7a

Browse files
committed
Support --version and --help options along with -v and -h
1 parent 900be9d commit 037bb7a

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/main.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,14 @@ extern int opterr, optind;
138138
#define APPNAME basename(argv[0])
139139
#define VERSION "1.4.0"
140140
#define OPTSTR "i:v:t:h"
141-
#define USAGE_FMT "%s -i <file.ini> [-v] [-h] [-t testname]\n"
141+
#define USAGE_FMT "%s -i <file.ini> [-v|--version] [-h|--help] [-t testname]\n"
142+
143+
static const struct option long_options[] =
144+
{
145+
{"version", no_argument, NULL, 'v'},
146+
{"help", no_argument, NULL, 'h'},
147+
{NULL, 0, NULL, 0 }
148+
};
142149

143150
static volatile sig_atomic_t kill_error = 10; // after 10 times SIGUSR1 the app exits forcefully
144151
static volatile sig_atomic_t main_alive = 1; // terminate application (1=true, 0=false)
@@ -258,7 +265,7 @@ int main(int argc, char *argv[])
258265
signal(SIGUSR2, SIGUSR2_handler); // rfu
259266

260267
// Scan parameters
261-
while((opt = getopt(argc, argv, OPTSTR)) != EOF)
268+
while((opt = getopt_long(argc, argv, OPTSTR, long_options, NULL)) != -1)
262269
{
263270
switch(opt)
264271
{

0 commit comments

Comments
 (0)