summaryrefslogtreecommitdiff
path: root/src/cli.c
diff options
context:
space:
mode:
authorjakob <jakob@memeware.net>2017-01-19 18:54:37 -0500
committerjakob <jakob@memeware.net>2017-01-19 18:54:37 -0500
commita17c7e61ba8953301c28e94890e459e76f532687 (patch)
treeafa7e44ebce49c4b85792ab043f9a68e930c5cf5 /src/cli.c
parent7604aed47d67a6c0114983b42a26b4c5745c4f0e (diff)
Implemented the ability to specify an output path,.
Diffstat (limited to 'src/cli.c')
-rw-r--r--src/cli.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/cli.c b/src/cli.c
index 0025141..7d00434 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -36,6 +36,7 @@
" -l, --list\t\tList the contents of the archive.\n\n" \
" -a, --archive\tAlternate way of specifying archive" \
"to extract.\n" \
+ " -o, --output\t\tPath to extract files to.\n" \
" -g, --game\t\tGame the archive is from. Required for " \
"file decryption\n" \
" -q, --quiet\t\tDon't display information about " \
@@ -68,12 +69,13 @@ struct configuration parse_args(int argc, char *argv[]) {
{"extract", no_argument, NULL, 'e'},
{"list", no_argument, NULL, 'l'},
{"archive", required_argument, NULL, 'a'},
+ {"output", required_argument, NULL, 'o'},
{"game", required_argument, NULL, 'g'},
{NULL, 0, NULL, 0}
};
do {
- current = getopt_long(argc, argv, "hvelqa:g:", long_options,
+ current = getopt_long(argc, argv, "hvelqa:o:g:", long_options,
&option_index);
switch (current) {
case 'h':
@@ -92,6 +94,14 @@ struct configuration parse_args(int argc, char *argv[]) {
count++;
parsed.archive = optarg;
break;
+ case 'o':
+ count++;
+ size_t path_size = strlen(optarg);
+ parsed.output = malloc(path_size + 1);
+ strcpy(parsed.output, optarg);
+ if (parsed.output[path_size - 1] != PATH_DELIMITER)
+ parsed.output[path_size] = PATH_DELIMITER;
+ break;
case 'g':
count++;
/* Out of concern for efficiency, string comparisons are
@@ -128,5 +138,13 @@ struct configuration parse_args(int argc, char *argv[]) {
parsed.archive = argv[count];
}
+ /* The output path is allocated on the heap to simplify freeing. */
+ if (parsed.output == NULL) {
+ if ((parsed.output = strdup(".")) == NULL) {
+ fprintf(stderr, "Insufficient memory.\n");
+ exit(EXIT_FAILURE);
+ }
+ }
+
return parsed;
}