#include #include #include #include #include #include #include #include "unalf.h" #ifndef VERSION #define VERSION "0.0.0" #endif FILE *in_file, *out_file; char *in_filename, *self; opts_t opts; const char *exclude_globs[MAX_EXCLUDES]; int exclude_count; char * const *include_globs; static void create_outdir(void); static void set_self(char *argv0) { char *p; self = argv0; p = strrchr(self, '/'); if(p) self = p + 1; } /* like "mkdir -p" (no error if dir already exists), followed by "cd" (which will error if the existing "directory" turns out to be a file or broken symlink */ static void create_outdir(void) { int r; r = mkdir(opts.outdir, 0777); if(r < 0 && errno != EEXIST) { fprintf(stderr, "%s: ", self); perror(opts.outdir); exit(1); } if(chdir(opts.outdir) < 0) { fprintf(stderr, "%s: ", self); perror(opts.outdir); exit(1); } } void usage(void) { extern char *usage_msg[]; char **line; puts("unalf (ALF extractor) v" VERSION " by B. Watson. WTFPL."); printf("Usage: %s -[options] [wildcard ...]\n", self); puts("Options:"); puts(" wildcards: extract only matching files."); for(line = usage_msg; *line; line++) puts(*line); exit(0); } int main(int argc, char **argv) { set_self(argv[0]); if(argc < 2) usage(); parse_opts(argc, argv); if(!(in_file = fopen(in_filename, "rb"))) { fprintf(stderr, "%s: ", self); perror(in_filename); exit(1); } if(opts.outdir) create_outdir(); if(opts.listonly) list_alf(); else extract_alf(); exit(0); }