summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorengelsman <engelsman>2010-10-23 14:10:26 +0000
committerengelsman <engelsman>2010-10-23 14:10:26 +0000
commit0cbfd64a282ac8fe40122820154f6d36f619ad07 (patch)
treec3036c3c669740624402781c3e1a61bdc9938e57
parenta69425441ac8ea71aeab55d84288df299c1d0f09 (diff)
examples/howto-parse-args.cxx: now with added comments and svn:keywords
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7728 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
-rw-r--r--examples/howto-parse-args.cxx24
1 files changed, 20 insertions, 4 deletions
diff --git a/examples/howto-parse-args.cxx b/examples/howto-parse-args.cxx
index e2d8d9f72..15b3f4b74 100644
--- a/examples/howto-parse-args.cxx
+++ b/examples/howto-parse-args.cxx
@@ -1,5 +1,5 @@
//
-// "$Id:$"
+// "$Id$"
//
// How to parse command line arguments - Duncan Gibson 2010-10-23
// First posted in http://www.fltk.org/newsgroups.php?gfltk.general+v:31449
@@ -7,6 +7,10 @@
// Shows how to decode additional command line arguments using Fl::args()
// on top of the "standard" options used by the toolkit itself.
//
+// Note that this only handles "option separateValue" rather than the
+// usual *nix idiom of "option=value", and provides no validation nor
+// conversion of the paramter string into ints or floats.
+//
// Copyright 1998-2010 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
@@ -28,15 +32,25 @@
//
// http://www.fltk.org/str.php
//
+#include <stdio.h>
+#include <string.h>
#include <FL/Fl.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Window.H>
-#include "stdio.h"
-#include "string.h"
int helpFlag = 0;
char *optionString = 0;
+/*
+ * callback function passed to Fl::args() to parse individual argument.
+ * If there is a match, 'i' must be incremented by 2 or 1 as appropriate.
+ * If there is no match, Fl::args() will then call Fl::arg() as fallback
+ * to try to match the "standard" FLTK parameters.
+ *
+ * Returns 2 if argv[i] matches with required parameter in argv[i+1],
+ * returns 1 if argv[i] matches on its own,
+ * returns 0 if argv[i] does not match.
+ */
int arg(int argc, char **argv, int &i)
{
if (strcmp("-h", argv[i]) == 0 || strcmp("--help", argv[i]) == 0) {
@@ -77,10 +91,12 @@ int main(int argc, char** argv)
Fl_Box* textBox = new Fl_Box(0, 0, 300, 200);
if (optionString != 0)
textBox->label(optionString);
+ else
+ textBox->label("re-run with [-o|--option] text");
mainWin->show(argc, argv);
return Fl::run();
}
//
-// End of "$Id:$".
+// End of "$Id$".
//