feat: add -h/--help with full option descriptions to fpack/funpack
This commit is contained in:
+21
-1
@@ -34,6 +34,7 @@ static struct option long_opts[] = {
|
|||||||
{"progress", no_argument, NULL, 'p'},
|
{"progress", no_argument, NULL, 'p'},
|
||||||
{"quiet", no_argument, NULL, 'q'},
|
{"quiet", no_argument, NULL, 'q'},
|
||||||
{"verbose", no_argument, NULL, 'v'},
|
{"verbose", no_argument, NULL, 'v'},
|
||||||
|
{"help", no_argument, NULL, 'h'},
|
||||||
{NULL, 0, NULL, 0}
|
{NULL, 0, NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -230,9 +231,25 @@ static int add_dir(struct fpk_writer *w, const char *dir, size_t base_len)
|
|||||||
static void usage(void)
|
static void usage(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "usage: %s [-o output.fpk] [-p] [-q] [-v] input_dir\n", PROGRAM_NAME);
|
fprintf(stderr, "usage: %s [-o output.fpk] [-p] [-q] [-v] input_dir\n", PROGRAM_NAME);
|
||||||
|
fprintf(stderr, "try '%s --help' for more information\n", PROGRAM_NAME);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void help(void)
|
||||||
|
{
|
||||||
|
printf("usage: %s [options] input_dir\n", PROGRAM_NAME);
|
||||||
|
printf("\n");
|
||||||
|
printf("Pack a directory tree into an fpk archive.\n");
|
||||||
|
printf("\n");
|
||||||
|
printf("options:\n");
|
||||||
|
printf(" -o, --output=FILE write the archive to FILE instead of the derived name\n");
|
||||||
|
printf(" -p, --progress print packing progress\n");
|
||||||
|
printf(" -q, --quiet suppress the final summary line\n");
|
||||||
|
printf(" -v, --verbose print each packed entry\n");
|
||||||
|
printf(" -h, --help show this help and exit\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
const char *output_arg = NULL;
|
const char *output_arg = NULL;
|
||||||
@@ -242,7 +259,7 @@ int main(int argc, char **argv)
|
|||||||
struct fpk_writer *w;
|
struct fpk_writer *w;
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
while ((c = getopt_long(argc, argv, "o:pqv", long_opts, NULL)) != -1) {
|
while ((c = getopt_long(argc, argv, "o:pqvh", long_opts, NULL)) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'o':
|
case 'o':
|
||||||
output_arg = optarg;
|
output_arg = optarg;
|
||||||
@@ -256,6 +273,9 @@ int main(int argc, char **argv)
|
|||||||
case 'v':
|
case 'v':
|
||||||
flags |= FPACK_VERBOSE;
|
flags |= FPACK_VERBOSE;
|
||||||
break;
|
break;
|
||||||
|
case 'h':
|
||||||
|
help();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
|
|||||||
+30
-3
@@ -32,6 +32,7 @@ static struct option long_opts[] = {
|
|||||||
{"progress", no_argument, NULL, 'p'},
|
{"progress", no_argument, NULL, 'p'},
|
||||||
{"quiet", no_argument, NULL, 'q'},
|
{"quiet", no_argument, NULL, 'q'},
|
||||||
{"verbose", no_argument, NULL, 'v'},
|
{"verbose", no_argument, NULL, 'v'},
|
||||||
|
{"help", no_argument, NULL, 'h'},
|
||||||
{NULL, 0, NULL, 0}
|
{NULL, 0, NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -57,17 +58,23 @@ static char *join_path(const char *dir, const char *name)
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define IS_PATH_SEP(c) ((c) == '/' || (c) == '\\')
|
||||||
|
#else
|
||||||
|
#define IS_PATH_SEP(c) ((c) == '/')
|
||||||
|
#endif
|
||||||
|
|
||||||
static char *basename_dup(const char *path)
|
static char *basename_dup(const char *path)
|
||||||
{
|
{
|
||||||
size_t end = strlen(path);
|
size_t end = strlen(path);
|
||||||
size_t start;
|
size_t start;
|
||||||
char *out;
|
char *out;
|
||||||
|
|
||||||
while (end > 0 && path[end - 1] == '/')
|
while (end > 0 && IS_PATH_SEP(path[end - 1]))
|
||||||
end--;
|
end--;
|
||||||
|
|
||||||
start = end;
|
start = end;
|
||||||
while (start > 0 && path[start - 1] != '/')
|
while (start > 0 && !IS_PATH_SEP(path[start - 1]))
|
||||||
start--;
|
start--;
|
||||||
|
|
||||||
out = malloc(end - start + 1);
|
out = malloc(end - start + 1);
|
||||||
@@ -155,9 +162,26 @@ static int extract_entry(const char *out_dir, const fpk_entry_t *entry,
|
|||||||
static void usage(void)
|
static void usage(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "usage: %s [-d output_dir] [-l] [-p] [-q] [-v] input.fpk\n", PROGRAM_NAME);
|
fprintf(stderr, "usage: %s [-d output_dir] [-l] [-p] [-q] [-v] input.fpk\n", PROGRAM_NAME);
|
||||||
|
fprintf(stderr, "try '%s --help' for more information\n", PROGRAM_NAME);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void help(void)
|
||||||
|
{
|
||||||
|
printf("usage: %s [options] input.fpk\n", PROGRAM_NAME);
|
||||||
|
printf("\n");
|
||||||
|
printf("Extract files from an fpk archive.\n");
|
||||||
|
printf("\n");
|
||||||
|
printf("options:\n");
|
||||||
|
printf(" -d, --dir=DIR extract into DIR instead of the archive's derived name\n");
|
||||||
|
printf(" -l, --list list archive entries and exit, without extracting\n");
|
||||||
|
printf(" -p, --progress print extraction progress\n");
|
||||||
|
printf(" -q, --quiet suppress the final summary line\n");
|
||||||
|
printf(" -v, --verbose print each extracted entry\n");
|
||||||
|
printf(" -h, --help show this help and exit\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
const char *dir_arg = NULL;
|
const char *dir_arg = NULL;
|
||||||
@@ -168,7 +192,7 @@ int main(int argc, char **argv)
|
|||||||
uint64_t i;
|
uint64_t i;
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
while ((c = getopt_long(argc, argv, "d:lpqv", long_opts, NULL)) != -1) {
|
while ((c = getopt_long(argc, argv, "d:lpqvh", long_opts, NULL)) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'd':
|
case 'd':
|
||||||
dir_arg = optarg;
|
dir_arg = optarg;
|
||||||
@@ -185,6 +209,9 @@ int main(int argc, char **argv)
|
|||||||
case 'v':
|
case 'v':
|
||||||
flags |= FUNPACK_VERBOSE;
|
flags |= FUNPACK_VERBOSE;
|
||||||
break;
|
break;
|
||||||
|
case 'h':
|
||||||
|
help();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user