diff --git a/src/main.c b/src/main.c index 1492fa3..8582f52 100644 --- a/src/main.c +++ b/src/main.c @@ -39,7 +39,7 @@ int main(int argc, const char **argv) { simple_archiver_parse_args(argc, argv, &parsed); - if ((parsed.flags & 0x2) == 0) { + if ((parsed.flags & 0x4) == 0) { FILE *file = fopen(parsed.filename, "r"); if (file != NULL) { fclose(file); diff --git a/src/parser.c b/src/parser.c index c59131e..82eea63 100644 --- a/src/parser.c +++ b/src/parser.c @@ -137,6 +137,7 @@ void simple_archiver_print_usage(void) { fprintf(stderr, "Usage flags:\n"); fprintf(stderr, "-c : create archive file\n"); fprintf(stderr, "-x : extract archive file\n"); + fprintf(stderr, "-t : examine archive file\n"); fprintf(stderr, "-f : filename to work on\n"); fprintf(stderr, "--compressor : requires --decompressor\n"); @@ -192,11 +193,18 @@ int simple_archiver_parse_args(int argc, const char **argv, simple_archiver_print_usage(); exit(0); } else if (strcmp(argv[0], "-c") == 0) { - // unset first bit. - out->flags &= 0xFFFFFFFE; + // unset first two bits. + out->flags &= 0xFFFFFFFC; } else if (strcmp(argv[0], "-x") == 0) { + // unset first two bits. + out->flags &= 0xFFFFFFFC; // set first bit. 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) { int size = strlen(argv[1]) + 1; out->filename = malloc(size); @@ -216,7 +224,7 @@ int simple_archiver_parse_args(int argc, const char **argv, --argc; ++argv; } 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) { is_remaining_args = 1; } else if (argv[0][0] != '-') { diff --git a/src/parser.h b/src/parser.h index 7e582e4..c9ebc34 100644 --- a/src/parser.h +++ b/src/parser.h @@ -23,10 +23,11 @@ typedef struct SDArchiverParsed { /// Each bit is a flag. - /// 0b0 - is creating. - /// 0b1 - is extracting. - /// 0b0x - Do NOT allow create archive overwrite. - /// 0b1x - Allow create archive overwrite. + /// 0b xxxx xx00 - is creating. + /// 0b xxxx xx01 - is extracting. + /// 0b xxxx xx10 - is checking/examining. + /// 0b xxxx x0xx - Do NOT allow create archive overwrite. + /// 0b xxxx x1xx - Allow create archive overwrite. unsigned int flags; /// Null-terminated string. char *filename;