summaryrefslogtreecommitdiff
path: root/src/cli.c
diff options
context:
space:
mode:
authorjakob <jakob@memeware.net>2017-01-08 20:22:46 -0500
committerjakob <jakob@memeware.net>2017-01-08 20:22:46 -0500
commit7d141c7e79bb9688a475b88722f6101ad01ef782 (patch)
treec6afc8951270e57461ce25d32a32665ab52d7d6c /src/cli.c
parentb3560b1005d3bc78a4f00a2279eb791209801a98 (diff)
Large commit. Filenames are now converted from UTF-16LE and placed into a linked list. Parsers also exist for every entry in the XP3 format.
Diffstat (limited to 'src/cli.c')
-rw-r--r--src/cli.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/cli.c b/src/cli.c
index dd3c263..481aaea 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -22,6 +22,7 @@
#include <getopt.h>
#include "cli.h"
+#include "defs.h"
#define VERSION "0.1.0"
#define HELP_TEXT "A tool for decompressing the XP3 archives used by " \
@@ -35,8 +36,8 @@
/* General subroutine for parsing command-line arguments. Returns a
"configuration" structure containing everything parsed from argv. */
struct configuration parse_args(int argc, char *argv[]) {
- if (argc != 2) {
- fprintf(stderr, "Usage: %s [OPTIONS] (ARCHIVE PATH)\n", argv[0]);
+ if (argc < 2) {
+ fprintf(stderr, "Usage: %s (ARCHIVE PATH) [OPTIONS]\n", argv[0]);
exit(1);
}
@@ -45,25 +46,39 @@ struct configuration parse_args(int argc, char *argv[]) {
struct configuration parsed;
memset(&parsed, 0, sizeof(parsed));
- int current = 0, option_index = 0;
+ /* count represents the number of options parsed, regardless of
+ whether or not they were "long." This is kept track of so that
+ the user can supply an archive path as a positional argument. */
+ int current = 0, option_index = 0, count = 0;
static struct option long_options[] = {
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'v'},
{NULL, 0, NULL, 0}
};
- while (current >= 0) {
+ do {
current = getopt_long(argc, argv, "hv", long_options, &option_index);
switch (current) {
case 'h':
printf("Usage: %s [OPTIONS] (ARCHIVE PATH)\n\n", argv[0]);
printf("%s\n", HELP_TEXT);
- exit(0);
+ exit(EXIT_SUCCESS);
case 'v':
printf("Nekopack, version %s\nProgrammed by "
"Jakob. <http://tsar-fox.com/>\n", VERSION);
- exit(0);
+ exit(EXIT_SUCCESS);
}
+ count++;
+ } while (current >= 0);
+
+ /* getopt "sorts" the argument array such that all of the flags come
+ first. argv[count] is the first positional argument encountered. */
+ if (parsed.archive_path == NULL) {
+ if (argv[count] == NULL) {
+ fprintf(stderr, "No archive path given.\n");
+ exit(EXIT_FAILURE);
+ }
+ parsed.archive_path = argv[count];
}
return parsed;