Update parser flags to allow "checking" with "-t"
All checks were successful
Run Unit Tests / build-and-run-unit-tests (push) Successful in 3s
All checks were successful
Run Unit Tests / build-and-run-unit-tests (push) Successful in 3s
This commit is contained in:
parent
875e4bb2a4
commit
58daa1130d
3 changed files with 17 additions and 8 deletions
|
@ -39,7 +39,7 @@ int main(int argc, const char **argv) {
|
||||||
|
|
||||||
simple_archiver_parse_args(argc, argv, &parsed);
|
simple_archiver_parse_args(argc, argv, &parsed);
|
||||||
|
|
||||||
if ((parsed.flags & 0x2) == 0) {
|
if ((parsed.flags & 0x4) == 0) {
|
||||||
FILE *file = fopen(parsed.filename, "r");
|
FILE *file = fopen(parsed.filename, "r");
|
||||||
if (file != NULL) {
|
if (file != NULL) {
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
14
src/parser.c
14
src/parser.c
|
@ -137,6 +137,7 @@ void simple_archiver_print_usage(void) {
|
||||||
fprintf(stderr, "Usage flags:\n");
|
fprintf(stderr, "Usage flags:\n");
|
||||||
fprintf(stderr, "-c : create archive file\n");
|
fprintf(stderr, "-c : create archive file\n");
|
||||||
fprintf(stderr, "-x : extract archive file\n");
|
fprintf(stderr, "-x : extract archive file\n");
|
||||||
|
fprintf(stderr, "-t : examine archive file\n");
|
||||||
fprintf(stderr, "-f <filename> : filename to work on\n");
|
fprintf(stderr, "-f <filename> : filename to work on\n");
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"--compressor <full_compress_cmd> : requires --decompressor\n");
|
"--compressor <full_compress_cmd> : requires --decompressor\n");
|
||||||
|
@ -192,11 +193,18 @@ int simple_archiver_parse_args(int argc, const char **argv,
|
||||||
simple_archiver_print_usage();
|
simple_archiver_print_usage();
|
||||||
exit(0);
|
exit(0);
|
||||||
} else if (strcmp(argv[0], "-c") == 0) {
|
} else if (strcmp(argv[0], "-c") == 0) {
|
||||||
// unset first bit.
|
// unset first two bits.
|
||||||
out->flags &= 0xFFFFFFFE;
|
out->flags &= 0xFFFFFFFC;
|
||||||
} else if (strcmp(argv[0], "-x") == 0) {
|
} else if (strcmp(argv[0], "-x") == 0) {
|
||||||
|
// unset first two bits.
|
||||||
|
out->flags &= 0xFFFFFFFC;
|
||||||
// set first bit.
|
// set first bit.
|
||||||
out->flags |= 0x1;
|
out->flags |= 0x1;
|
||||||
|
} else if (strcmp(argv[0], "-t") == 0) {
|
||||||
|
// unset first two bits.
|
||||||
|
out->flags &= 0xFFFFFFFC;
|
||||||
|
// set second bit.
|
||||||
|
out->flags |= 0x2;
|
||||||
} else if (strcmp(argv[0], "-f") == 0 && argc > 1) {
|
} else if (strcmp(argv[0], "-f") == 0 && argc > 1) {
|
||||||
int size = strlen(argv[1]) + 1;
|
int size = strlen(argv[1]) + 1;
|
||||||
out->filename = malloc(size);
|
out->filename = malloc(size);
|
||||||
|
@ -216,7 +224,7 @@ int simple_archiver_parse_args(int argc, const char **argv,
|
||||||
--argc;
|
--argc;
|
||||||
++argv;
|
++argv;
|
||||||
} else if (strcmp(argv[0], "--overwrite-create") == 0) {
|
} else if (strcmp(argv[0], "--overwrite-create") == 0) {
|
||||||
out->flags |= 0x2;
|
out->flags |= 0x4;
|
||||||
} else if (argv[0][0] == '-' && argv[0][1] == '-' && argv[0][2] == 0) {
|
} else if (argv[0][0] == '-' && argv[0][1] == '-' && argv[0][2] == 0) {
|
||||||
is_remaining_args = 1;
|
is_remaining_args = 1;
|
||||||
} else if (argv[0][0] != '-') {
|
} else if (argv[0][0] != '-') {
|
||||||
|
|
|
@ -23,10 +23,11 @@
|
||||||
|
|
||||||
typedef struct SDArchiverParsed {
|
typedef struct SDArchiverParsed {
|
||||||
/// Each bit is a flag.
|
/// Each bit is a flag.
|
||||||
/// 0b0 - is creating.
|
/// 0b xxxx xx00 - is creating.
|
||||||
/// 0b1 - is extracting.
|
/// 0b xxxx xx01 - is extracting.
|
||||||
/// 0b0x - Do NOT allow create archive overwrite.
|
/// 0b xxxx xx10 - is checking/examining.
|
||||||
/// 0b1x - Allow create archive overwrite.
|
/// 0b xxxx x0xx - Do NOT allow create archive overwrite.
|
||||||
|
/// 0b xxxx x1xx - Allow create archive overwrite.
|
||||||
unsigned int flags;
|
unsigned int flags;
|
||||||
/// Null-terminated string.
|
/// Null-terminated string.
|
||||||
char *filename;
|
char *filename;
|
||||||
|
|
Loading…
Reference in a new issue