aboutsummaryrefslogtreecommitdiff
path: root/src/opts.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/opts.c')
-rw-r--r--src/opts.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/opts.c b/src/opts.c
new file mode 100644
index 0000000..2a5628e
--- /dev/null
+++ b/src/opts.c
@@ -0,0 +1,65 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include "unalf.h"
+
+#define OPTIONS "aeklLopqtvd:x:"
+
+/* uncomment to test exclude/include glob lists */
+// #define DEBUG_GLOBS
+
+static void add_exclude(const char *glob) {
+ if(exclude_count == MAX_EXCLUDES)
+ return;
+ exclude_globs[exclude_count++] = glob;
+}
+
+#ifdef DEBUG_GLOBS
+static void show_globs(void) {
+ int i;
+
+ printf("Include globs:\n");
+ while(*include_globs)
+ printf(" + %s\n", *include_globs++);
+ printf("Exclude globs:\n");
+ for(i = 0; i < exclude_count; i++)
+ printf(" - %s\n", exclude_globs[i]);
+ exit(0);
+}
+#endif
+
+void parse_opts(int argc, char * const *argv) {
+ int opt;
+
+ while((opt = getopt(argc, argv, OPTIONS)) != -1) {
+ switch(opt) {
+ case 'a': opts.txtconv++; break;
+ case 'e': opts.listonly = opts.testonly = 0; break;
+ case 'k': opts.keepdot++; break;
+ case 'l': opts.listonly++; opts.testonly = 0; break;
+ case 'L': opts.lowercase++; break;
+ case 'o': opts.overwrite++; break;
+ case 'p': opts.extract_to_stdout++; opts.quiet++; break;
+ case 'q': opts.quiet++; break;
+ case 't': opts.testonly++; opts.listonly = 0; break;
+ case 'v': opts.listonly = 1; opts.testonly = 0; opts.verbose_list++; break;
+ case 'd': opts.outdir = optarg; break;
+ case 'x': add_exclude(optarg); break;
+ default:
+ fprintf(stderr, "%s: invalid option (try -h or --help)\n", self);
+ exit(1);
+ }
+ }
+
+ if(optind >= argc) {
+ fprintf(stderr, "%s: missing alf file argument (try -h or --help)\n", self);
+ exit(1);
+ }
+
+ in_filename = argv[optind];
+ include_globs = &argv[optind + 1]; /* might be null, that's OK */
+
+#ifdef DEBUG_GLOBS
+ show_globs();
+#endif
+}