From c1fb612bad85ab74bdff9778deb9bea59ccf202e Mon Sep 17 00:00:00 2001 From: kintel Date: Wed, 7 Apr 2010 20:54:29 +0000 Subject: Added --help -h/-v --version options to commandline interface git-svn-id: http://svn.clifford.at/openscad/trunk@514 b57f626f-c46c-0410-a088-ec61d464b74c diff --git a/src/openscad.cc b/src/openscad.cc index f01d831..27935ac 100644 --- a/src/openscad.cc +++ b/src/openscad.cc @@ -56,6 +56,14 @@ static void help(const char *progname) exit(1); } +#define STRINGIFY(x) #x +#define TOSTRING(x) STRINGIFY(x) +static void version() +{ + printf("openscad version %s\n",TOSTRING(OPENSCAD_VERSION)); + exit(1); +} + QString commandline_commands; const char *make_command = NULL; QSet dependencies; @@ -115,13 +123,37 @@ int main(int argc, char **argv) const char *off_output_file = NULL; const char *dxf_output_file = NULL; const char *deps_output_file = NULL; - + + static struct option long_options[] = + { + {"version", no_argument, 0, 'v'}, + {"help", no_argument, 0, 'h'}, + {0, 0, 0, 0} + }; + int option_index = 0; + int opt; - - while ((opt = getopt(argc, argv, "s:o:x:d:m:D:")) != -1) + while ((opt = getopt_long(argc, argv, "s:o:x:d:m:D:vh", long_options, &option_index)) != -1) { switch (opt) { + case 0: + switch (option_index) + { + case 'v': + version(); + break; + case 'h': + help(argv[0]); + break; + } + break; + case 'v': + version(); + break; + case 'h': + help(argv[0]); + break; case 's': if (stl_output_file || off_output_file || dxf_output_file) help(argv[0]); -- cgit v0.10.1