From a7f48478e5126a8cd4b729109ab7aacabc615c66 Mon Sep 17 00:00:00 2001 From: Daniel Brahneborg Date: Tue, 19 Mar 2002 13:33:40 +0000 Subject: Support long options. --- sisinstall/sismain.cpp | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'sisinstall') diff --git a/sisinstall/sismain.cpp b/sisinstall/sismain.cpp index 8420733..21d6f55 100644 --- a/sisinstall/sismain.cpp +++ b/sisinstall/sismain.cpp @@ -13,27 +13,65 @@ #include #include +#define _GNU_SOURCE +#include + static void error(int line) { fprintf(stderr, "Got errno = %d on line %d\n", errno, line); exit(1); } +static struct option opts[] = { + { "help", no_argument, 0, 'h' }, + { "version", no_argument, 0, 'V' }, + { "loglevel", required_argument, 0, 'l' }, + { "dry-run", no_argument, 0, 'n' }, + { "force", no_argument, 0, 'f' }, + { NULL, 0, 0, 0 }, +}; + +void printHelp() +{ + printf( + _("Usage: sisinstall [OPTIONS]... SISFILE\n" + "\n" + "Supported options:\n" + "\n" + " -h, --help Display this text.\n" + " -V, --version Print version and exit.\n" + " -l, --loglevel=LEVEL Set the log level, by default 0.\n" + " -n, --dry-run Just parse file file.\n" + " -f, --force Ignore any earlier installations.\n" + )); +} + void main(int argc, char* argv[]) { char* filename = 0; char option; bool dryrun = false; + bool forced = false; #ifdef LC_ALL setlocale(LC_ALL, ""); #endif textdomain(PACKAGE); - while ((option = getopt(argc, argv, "nl:")) != -1) + while (1) { + option = getopt_long(argc, argv, "fhnl:", opts, NULL); + if (option == -1) + break; switch (option) { + case 'h': + case '?': + printHelp(); + exit(0); + case 'f': + forced = true; + break; case 'l': logLevel = atoi(optarg); break; @@ -80,6 +118,7 @@ void main(int argc, char* argv[]) { SISInstaller installer; installer.setPsion(psion); + installer.setForced(forced); installer.run(&sisFile, buf, len); } } -- cgit v1.2.3