summaryrefslogtreecommitdiff
path: root/src/expr.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1993-10-04 21:20:37 +0000
committerJim Meyering <jim@meyering.net>1993-10-04 21:20:37 +0000
commit3134fad324dee63431db43cf9fc82072cb004770 (patch)
treebed6afd9e143b51ee02ee2aa84a81a020daf3e15 /src/expr.c
parentae0074289cd7d70cf8fb1d96f2625b2b9bb62b29 (diff)
downloadcoreutils-3134fad324dee63431db43cf9fc82072cb004770.tar.xz
merge with 1.8.1a
Diffstat (limited to 'src/expr.c')
-rw-r--r--src/expr.c54
1 files changed, 42 insertions, 12 deletions
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 <ctype.h>
#include <sys/types.h>
#include <regex.h>
+#include <getopt.h>
#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;