Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=yaxmenu.git;a=commitdiff;h=ada625ff9b58bd6ffaf5d08a72df9efc4b0b7afc

commit ada625ff9b58bd6ffaf5d08a72df9efc4b0b7afc
Author: James Buren <r...@frugalware.org>
Date:   Sun Dec 6 11:01:34 2009 -0600

options.c
* initial draft

diff --git a/src/options.c b/src/options.c
new file mode 100644
index 0000000..cc8841e
--- /dev/null
+++ b/src/options.c
@@ -0,0 +1,56 @@
+#include "globals.h"
+#include "utility.h"
+#include "options.h"
+
+static const char version[] = "git";
+static const char date[] = __DATE__;
+static const char options[] = ":ih";
+static const char info_format[] = "%s version %s\n"
+                                  "\n"
+                                  "Built on %s.\n";
+static const char help_format[] = "Usage: %s\n"
+                                  "\n"
+                                  "Valid options:\n"
+                                  "\n"
+                                  "-i -> Print miscellaneous information\n"
+                                  "-h -> Print help information\n";
+static const char missing_format[] = "Missing argument: %c\n";
+static const char invalid_format[] = "Invalid option: %c\n";
+
+bool options_parse(int argc,char **argv) {
+  int opt;
+
+  assert(argc > 0 && argv);
+
+  G->progname = xstrdup(*argv);
+
+  G->progver = xstrdup(version);
+
+  G->progdate = xstrdup(date);
+
+  while((opt = getopt(argc,argv,options)) != -1) {
+
+    switch(opt) {
+
+      case 'i':
+        eprintf(info_format,G->progname,G->progver,G->progdate);
+        return false;
+
+      case 'h':
+        eprintf(help_format,G->progname);
+        return false;
+
+      case ':':
+        eprintf(missing_format,optopt);
+        return false;
+
+      case '?':
+        eprintf(invalid_format,optopt);
+        return false;
+
+    }
+
+  }
+
+  return true;
+}
_______________________________________________
Frugalware-git mailing list
Frugalware-git@frugalware.org
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to