aboutsummaryrefslogtreecommitdiff
path: root/src/unalf.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/unalf.c')
-rw-r--r--src/unalf.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/unalf.c b/src/unalf.c
new file mode 100644
index 0000000..ba6405e
--- /dev/null
+++ b/src/unalf.c
@@ -0,0 +1,66 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <f65.h>
+#include "unalf.h"
+
+FILE *in_file, *out_file;
+char *in_filename, *self;
+
+static void usage(void) {
+ printf("usage: %s [-l] file.alf\n", self);
+ exit(1);
+}
+
+static void set_self(char *argv0) {
+ char *p;
+
+ self = argv0;
+ p = strrchr(self, '/');
+ if(p) self = p + 1;
+}
+
+int main(int argc, char **argv) {
+ char opt = 0;
+ int listonly = 0;
+
+ set_self(argv[0]);
+
+ if(argc == 1) {
+ fprintf(stderr, "%s: missing required argument(s)\n", self);
+ usage();
+ } else if(argc > 3) {
+ fprintf(stderr, "%s: too many arguments\n", self);
+ usage();
+ } else if(argc == 2) {
+ in_filename = argv[1];
+ } else { /* argc == 3 */
+ in_filename = argv[2];
+ if(argv[1][0] == '-')
+ opt = argv[1][1];
+ else
+ opt = argv[1][0];
+ if(opt == 'l' || opt == 'v') {
+ listonly = 1;
+ } else if(opt == 'x' || opt == 'e') {
+ /* NOP */
+ } else {
+ fprintf(stderr, "%s: unknown option '-%c'\n", self, opt);
+ usage();
+ }
+ }
+
+ if(!(in_file = fopen(in_filename, "rb"))) {
+ fprintf(stderr, "%s: ", self);
+ perror(in_filename);
+ exit(1);
+ }
+
+ if(listonly)
+ list_alf();
+ else
+ extract_alf();
+
+ exit(0);
+}