summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2009-10-26 18:54:09 -0400
committerTavian Barnes <tavianator@gmail.com>2009-10-26 19:08:43 -0400
commitbc16db8ce1e990dbfadcf6c08f68bd4cb2c445a5 (patch)
tree2eb0b6525d4da941803e3ed3b3d5830e5e6cf823
parent296cafcb79bfb8d40071efe937e7e270c404ca8b (diff)
downloaddimension-bc16db8ce1e990dbfadcf6c08f68bd4cb2c445a5.tar.xz
Add some command-line options to `dimension' program.
-rw-r--r--dimension/main.c65
1 files changed, 64 insertions, 1 deletions
diff --git a/dimension/main.c b/dimension/main.c
index 46cb798..8f5aa9f 100644
--- a/dimension/main.c
+++ b/dimension/main.c
@@ -19,8 +19,71 @@
#include "../libdimension/dimension.h"
#include <stdlib.h>
+#include <getopt.h>
+
+const char *output = NULL, *input = NULL;
+int tokenize = 0;
int
-main() {
+main(int argc, char **argv) {
+ /* Parse the command-line options */
+
+ static struct option long_options[] = {
+ { "output", required_argument, NULL, 'o' },
+ { "input", required_argument, NULL, 'i' },
+ { "tokenize", no_argument, &tokenize, 1 },
+ { 0, 0, 0, 0 }
+ };
+ int opt, opt_index;
+
+ while (1) {
+ opt = getopt_long(argc, argv, "o:i:", long_options, &opt_index);
+
+ if (opt == -1)
+ break;
+
+ switch (opt) {
+ case 0:
+ /* Option set a flag - do nothing here */
+ break;
+
+ case 'o':
+ if (output) {
+ dmnsn_error(DMNSN_SEVERITY_HIGH, "--output specified more than once.");
+ } else {
+ output = optarg;
+ }
+ break;
+
+ case 'i':
+ if (input) {
+ dmnsn_error(DMNSN_SEVERITY_HIGH, "--input specified more than once.");
+ } else {
+ input = optarg;
+ }
+ break;
+
+ default:
+ dmnsn_error(DMNSN_SEVERITY_HIGH, "Error parsing command line.");
+ };
+ }
+
+ if (optind == argc - 1) {
+ if (input) {
+ dmnsn_error(DMNSN_SEVERITY_HIGH, "Multiple input files specified.");
+ } else {
+ input = argv[optind];
+ }
+ } else if (optind < argc) {
+ dmnsn_error(DMNSN_SEVERITY_HIGH, "Invalid extranious command line options.");
+ }
+
+ if (!output) {
+ dmnsn_error(DMNSN_SEVERITY_HIGH, "No output file specified.");
+ }
+ if (!input) {
+ dmnsn_error(DMNSN_SEVERITY_HIGH, "No input file specified.");
+ }
+
return EXIT_SUCCESS;
}