From 3134fad324dee63431db43cf9fc82072cb004770 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Mon, 4 Oct 1993 21:20:37 +0000 Subject: merge with 1.8.1a --- src/expr.c | 54 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 12 deletions(-) (limited to 'src/expr.c') diff --git a/src/expr.c b/src/expr.c index c4fbc2161..a9f376942 100644 --- a/src/expr.c +++ b/src/expr.c @@ -32,6 +32,7 @@ #include #include #include +#include #include "system.h" #include "version.h" @@ -98,6 +99,13 @@ static void tostring (); static void trace (); #endif +static struct option const long_options[] = +{ + {"help", no_argument, 0, 'h'}, + {"version", no_argument, 0, 'v'}, + {0, 0, 0, 0} +}; + static void usage () { @@ -106,28 +114,50 @@ usage () exit (1); } -void -main (argc, argv) +/* Process long options that precede all other command line arguments. */ + +static void +parse_long_options (argc, argv) int argc; char **argv; { - VALUE *v; - - program_name = argv[0]; + int c; - if (argc > 1) + while ((c = getopt_long (argc, argv, "+", long_options, (int *) 0)) != EOF) { - if (strcmp (argv[1], "--version") == 0) - { + switch (c) + { + case 'h': + usage (); + + case 'v': printf ("%s\n", version_string); exit (0); - } - else if (strcmp (argv[1], "--help") == 0) - { + + default: usage (); - } + } } + /* Restore optind in case it has advanced past a leading `--'. We can use a + simple assignment here because all brances of the above switch statement + exit. Otherwise, we'd have to be careful to decrement only when optind + is larger than 1 and the last argument processed was `--'. */ + + optind = 1; +} + +void +main (argc, argv) + int argc; + char **argv; +{ + VALUE *v; + + program_name = argv[0]; + + parse_long_options (argc, argv); + if (argc == 1) usage (); args = argv + 1; -- cgit v1.2.3-54-g00ecf