]> git.seodisparate.com - SimpleArchiver/commitdiff
Update parser flags to allow "checking" with "-t"
authorStephen Seo <seo.disparate@gmail.com>
Wed, 17 Jul 2024 03:13:33 +0000 (12:13 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Wed, 17 Jul 2024 03:13:33 +0000 (12:13 +0900)
src/main.c
src/parser.c
src/parser.h

index 1492fa3fbf012f21fa2fe29e601c4966a0319d2d..8582f527897e740b011abdf063cf932104fa4265 100644 (file)
@@ -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);
index c59131ef862baa65007f2a2a96124c745011436a..82eea638f95455bf56154a9cf9e5b220a2d476d7 100644 (file)
@@ -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> : filename to work on\n");
   fprintf(stderr,
           "--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();
         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] != '-') {
index 7e582e4d108822bb01a3c64f6426774e23536581..c9ebc34bc10c96b768696aac2634e747b09a9775 100644 (file)
 
 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;