]> granicus.if.org Git - zziplib/commitdiff
allow for -l/-v in unzzip list
authorGuido Draheim <guidod@gmx.de>
Mon, 24 Apr 2017 21:04:51 +0000 (23:04 +0200)
committerGuido Draheim <guidod@gmx.de>
Mon, 24 Apr 2017 21:04:51 +0000 (23:04 +0200)
bins/unzzip.c
bins/unzzipdir-big.c
bins/unzzipdir-mem.c
bins/unzzipdir-mix.c
bins/unzzipdir-zip.c
bins/unzzipdir-zip.h
test/zziptests.py

index 73f9ecf956320d24bb6bbef6818be8d7c8f69272..6c74bcf05d93b33f9366becef0e8d18b77c48935 100644 (file)
 #include "unzzipcat-zip.h"
 #include "unzzipdir-zip.h"
 
-extern int unzzip_list(int argc, char** argv);
-extern int unzzip_print(int argc, char** argv);
-extern int unzzip_extract(int argc, char** argv);
-
 static const char usage[] = 
 {
     "unzzip <dir>.. \n"
@@ -53,14 +49,14 @@ main (int argc, char ** argv)
     if (! strcmp (argv[1], "-l") || ! strcmp(argv[1], "--list"))
     {
         argc -= 1; argv += 1;
-        return unzzip_list(argc, argv);
+        return unzzip_show_list(argc, argv);
     }
     if (! strcmp (argv[1], "-v") || ! strcmp(argv[1], "--versions"))
     {
         if (argc == 2)
             return unzzip_version(); /* compatible with info-zip */
         argc -= 1; argv += 1;
-        return unzzip_list(argc, argv); /* short format here */
+        return unzzip_long_list(argc, argv);
     }
     if (! strcmp (argv[1], "-p") || ! strcmp(argv[1], "--pipe"))
     {
index 916f0965c24e0138ff9431b36bbe3e8ffdd85bae..e2a4c59651759705b1952ecc7a9ae26f212bd72e 100644 (file)
@@ -37,7 +37,8 @@ static const char* comprlevel[] = {
     "stored",   "shrunk",   "redu:1",   "redu:2",   "redu:3",   "redu:4",
     "impl:N",   "toknze",   "defl:N",   "defl:B",   "impl:B" };
 
-int unzzip_list (int argc, char ** argv)
+static int 
+unzzip_list (int argc, char ** argv, int verbose)
 {
     int argn;
     FILE* disk;
@@ -77,6 +78,18 @@ int unzzip_list (int argc, char ** argv)
     return 0;
 } 
 
+int 
+unzzip_long_list (int argc, char ** argv)
+{
+    return unzzip_list(argc, argv, 1);
+}
+
+int 
+unzzip_show_list (int argc, char ** argv)
+{
+    return unzzip_list(argc, argv, 0);
+}
+
 /* 
  * Local variables:
  * c-file-style: "stroustrup"
index f74e44ea701cc57f29f079b108052451523f5b47..629dbd7e012b978f604adfd0343bb326b7e02c95 100644 (file)
@@ -32,8 +32,8 @@ static const char* comprlevel[] = {
     "stored",   "shrunk",   "redu:1",   "redu:2",   "redu:3",   "redu:4",
     "impl:N",   "toknze",   "defl:N",   "defl:B",   "impl:B" };
 
-int 
-unzzip_list (int argc, char ** argv)
+static int 
+unzzip_list (int argc, char ** argv, int verbose)
 {
     int argn;
     ZZIP_MEM_DISK* disk;
@@ -57,10 +57,16 @@ unzzip_list (int argc, char ** argv)
        {
            char* name = zzip_mem_entry_to_name (entry);
            long long usize = entry->zz_usize;
-           long long csize = entry->zz_csize;
-           unsigned compr = entry->zz_compr;
-            const char* defl = (compr < sizeof(comprlevel)) ? comprlevel[compr] : "(redu)";
-           printf ("%lli/%lli %s %s\n", csize, usize, defl, name);
+           if (!verbose)
+           {
+               printf ("%22lli %s\n", usize, name);
+           } else 
+           {
+               long long csize = entry->zz_csize;
+               unsigned compr = entry->zz_compr;
+               const char* defl = (compr < sizeof(comprlevel)) ? comprlevel[compr] : "(redu)";
+               printf ("%lli/%lli %s %s\n", csize, usize, defl, name);
+           }
        }
        return 0;
     }
@@ -72,10 +78,16 @@ unzzip_list (int argc, char ** argv)
        {
            char* name = zzip_mem_entry_to_name (entry);
            long long usize = entry->zz_usize;
-           long long csize = entry->zz_csize;
-           unsigned compr = entry->zz_compr;
-            const char* defl = (compr < sizeof(comprlevel)) ? comprlevel[compr] : "(redu)";
-           printf ("%lli/%lli %s %s\n", csize, usize, defl, name);
+           if (!verbose)
+           {
+               printf ("%22lli %s\n", usize, name);
+           } else 
+           {
+               long long csize = entry->zz_csize;
+               unsigned compr = entry->zz_compr;
+               const char* defl = (compr < sizeof(comprlevel)) ? comprlevel[compr] : "(redu)";
+               printf ("%lli/%lli %s %s\n", csize, usize, defl, name);
+           }
        }
        return 0;
     }
@@ -90,11 +102,18 @@ unzzip_list (int argc, char ** argv)
                if (! fnmatch (argv[argn], name, 
                               FNM_NOESCAPE|FNM_PATHNAME|FNM_PERIOD))
                {
+                   char* name = zzip_mem_entry_to_name (entry);
                    long long usize = entry->zz_usize;
-                   long long csize = entry->zz_csize;
-                   unsigned compr = entry->zz_compr;
-                   const char* defl = (compr < sizeof(comprlevel)) ? comprlevel[compr] : "(redu)";
-                   printf ("%lli/%lli %s %s\n", csize, usize, defl, name);
+                   if (!verbose)
+                   {
+                       printf ("%22lli %s\n", usize, name);
+                   } else 
+                   {
+                       long long csize = entry->zz_csize;
+                       unsigned compr = entry->zz_compr;
+                       const char* defl = (compr < sizeof(comprlevel)) ? comprlevel[compr] : "(redu)";
+                       printf ("%lli/%lli %s %s\n", csize, usize, defl, name);
+                   }
                    break; /* match loop */
                }
            }
@@ -103,6 +122,18 @@ unzzip_list (int argc, char ** argv)
     }
 } 
 
+int 
+unzzip_long_list (int argc, char ** argv)
+{
+    return unzzip_list(argc, argv, 1);
+}
+
+int 
+unzzip_show_list (int argc, char ** argv)
+{
+    return unzzip_list(argc, argv, 0);
+}
+
 /* 
  * Local variables:
  * c-file-style: "stroustrup"
index 84927918b4f779b235746c410e3ac14bfc7fed12..30535c5ec59de8ebfff2401d1947d0486b23abe6 100644 (file)
@@ -32,8 +32,10 @@ static const char* comprlevel[] = {
     "stored",   "shrunk",   "redu:1",   "redu:2",   "redu:3",   "redu:4",
     "impl:N",   "toknze",   "defl:N",   "defl:B",   "impl:B" };
 
-int 
-unzzip_list (int argc, char ** argv)
+
+
+static int 
+unzzip_list (int argc, char ** argv, int verbose)
 {
     int argn;
     ZZIP_DIR* disk;
@@ -56,11 +58,17 @@ unzzip_list (int argc, char ** argv)
        while((entry = zzip_readdir(disk)))
        {
            char* name = entry->d_name;
-           long long csize = entry->d_csize;
            long long usize = entry->st_size;
-           unsigned compr = entry->d_compr;
-           const char* defl = (compr < sizeof(comprlevel)) ? comprlevel[compr] : "(redu)";
-            printf ("%lli/%lli %s %s\n", usize, csize, defl, name);
+           if (!verbose)
+           {
+               printf ("%22lli %s\n", usize, name);
+           } else
+           {
+               long long csize = entry->d_csize;
+               unsigned compr = entry->d_compr;
+               const char* defl = (compr < sizeof(comprlevel)) ? comprlevel[compr] : "(redu)";
+               printf ("%lli/%lli %s %s\n", usize, csize, defl, name);
+           }
        }
     }
     else
@@ -74,11 +82,17 @@ unzzip_list (int argc, char ** argv)
                if (! fnmatch (argv[argn], name, 
                               FNM_NOESCAPE|FNM_PATHNAME|FNM_PERIOD))
                {
-                   long long csize = entry->d_csize;
                    long long usize = entry->st_size;
-                   unsigned compr = entry->d_compr;
-                   const char* defl = (compr < sizeof(comprlevel)) ? comprlevel[compr] : "(redu)";
-                   printf ("%lli/%lli %s %s\n", usize, csize, defl, name);
+                   if (!verbose)
+                   {
+                       printf ("%22lli %s\n", usize, name);
+                   } else
+                   {
+                       long long csize = entry->d_csize;
+                       unsigned compr = entry->d_compr;
+                       const char* defl = (compr < sizeof(comprlevel)) ? comprlevel[compr] : "(redu)";
+                       printf ("%lli/%lli %s %s\n", usize, csize, defl, name);
+                   }
                    break; /* match loop */
                }
            }
@@ -88,6 +102,18 @@ unzzip_list (int argc, char ** argv)
     return 0;
 } 
 
+int 
+unzzip_long_list (int argc, char ** argv)
+{
+    return unzzip_list(argc, argv, 1);
+}
+
+int 
+unzzip_show_list (int argc, char ** argv)
+{
+    return unzzip_list(argc, argv, 0);
+}
+
 /* 
  * Local variables:
  * c-file-style: "stroustrup"
index 9d175b4e3f60e1bd4d2f66ee4f396304cc876074..0be917c38ef6c07e886ca09e4b2ec777298d4912 100644 (file)
@@ -32,8 +32,9 @@ static const char* comprlevel[] = {
     "stored",   "shrunk",   "redu:1",   "redu:2",   "redu:3",   "redu:4",
     "impl:N",   "toknze",   "defl:N",   "defl:B",   "impl:B" };
 
-int 
-unzzip_list (int argc, char ** argv)
+
+static int 
+unzzip_list (int argc, char ** argv, int verbose)
 {
     int argn;
     ZZIP_DIR* disk;
@@ -57,11 +58,17 @@ unzzip_list (int argc, char ** argv)
        while(zzip_dir_read(disk, &entry))
        {
            char* name = entry.d_name;
-           long long csize = entry.d_csize;
            long long usize = entry.st_size;
-           unsigned compr = entry.d_compr;
-           const char* defl = (compr < sizeof(comprlevel)) ? comprlevel[compr] : "(redu)";
-           printf ("%lli/%lli %s %s\n", usize, csize, defl, name);
+           if (!verbose)
+           {
+               printf ("%22lli %s\n", usize, name);
+           } else
+           {
+               long long csize = entry.d_csize;
+               unsigned compr = entry.d_compr;
+               const char* defl = (compr < sizeof(comprlevel)) ? comprlevel[compr] : "(redu)";
+               printf ("%lli/%lli %s %s\n", usize, csize, defl, name);
+           }
        }
     }
     else
@@ -75,11 +82,17 @@ unzzip_list (int argc, char ** argv)
                if (! fnmatch (argv[argn], name, 
                               FNM_NOESCAPE|FNM_PATHNAME|FNM_PERIOD))
                {
-                   long long csize = entry.d_csize;
                    long long usize = entry.st_size;
-                   unsigned compr = entry.d_compr;
-                   const char* defl = (compr < sizeof(comprlevel)) ? comprlevel[compr] : "(redu)";
-                   printf ("%lli/%lli %s %s\n", usize, csize, defl, name);
+                   if (!verbose)
+                   {
+                       printf ("%22lli %s\n", usize, name);
+                   } else
+                   {
+                       long long csize = entry.d_csize;
+                       unsigned compr = entry.d_compr;
+                       const char* defl = (compr < sizeof(comprlevel)) ? comprlevel[compr] : "(redu)";
+                       printf ("%lli/%lli %s %s\n", usize, csize, defl, name);
+                   }
                    break; /* match loop */
                }
            }
@@ -89,6 +102,18 @@ unzzip_list (int argc, char ** argv)
     return 0;
 } 
 
+int 
+unzzip_long_list (int argc, char ** argv)
+{
+    return unzzip_list(argc, argv, 1);
+}
+
+int 
+unzzip_show_list (int argc, char ** argv)
+{
+    return unzzip_list(argc, argv, 0);
+}
+
 /* 
  * Local variables:
  * c-file-style: "stroustrup"
index 51d57e86d21b8afbfa80bc6d77a61c69dc5cc677..683c1387858cb0f4f7d77c8a005233de75726c19 100644 (file)
@@ -5,5 +5,6 @@
  *      This file is used as an example to clarify zzip api usage.
  */
 
-extern int unzzip_list(int argc, char** argv);
+extern int unzzip_show_list(int argc, char** argv);
+extern int unzzip_long_list(int argc, char** argv);
 
index d19a4a2f8679ee1439834393741747a5286abb3d..0e8981cb70931bcf061a0dcda2a8a3baac17d04c 100644 (file)
@@ -851,7 +851,7 @@ class ZZipTest(unittest.TestCase):
     zipfile = "test0.zip"
     getfile = "test0.zip"
     exe = self.bins("unzzip-mem")
-    run = shell("{exe} -l {getfile} ".format(**locals()))
+    run = shell("{exe} -v {getfile} ".format(**locals()))
     self.assertIn(' README\n', run.output)
     self.assertIn(' defl:N ', run.output)
     self.assertLess(len(run.output), 30)
@@ -860,7 +860,7 @@ class ZZipTest(unittest.TestCase):
     zipfile = "test1.zip"
     getfile = "test1.zip"
     exe = self.bins("unzzip-mem")
-    run = shell("{exe} -l {getfile} ".format(**locals()))
+    run = shell("{exe} -v {getfile} ".format(**locals()))
     self.assertIn(' file.1\n', run.output)
     self.assertIn(' file.2\n', run.output)
     self.assertIn(' file.9\n', run.output)
@@ -872,7 +872,7 @@ class ZZipTest(unittest.TestCase):
     zipfile = "test2.zip"
     getfile = "test2.zip"
     exe = self.bins("unzzip-mem")
-    run = shell("{exe} -l {getfile} ".format(**locals()))
+    run = shell("{exe} -v {getfile} ".format(**locals()))
     self.assertIn(' file.01\n', run.output)
     self.assertIn(' file.22\n', run.output)
     self.assertIn(' file.99\n', run.output)
@@ -883,7 +883,7 @@ class ZZipTest(unittest.TestCase):
     zipfile = "test3.zip"
     getfile = "test3.zip"
     exe = self.bins("unzzip-mem")
-    run = shell("{exe} -l {getfile} ".format(**locals()))
+    run = shell("{exe} -v {getfile} ".format(**locals()))
     self.assertIn(' file.001\n', run.output)
     self.assertIn(' file.222\n', run.output)
     self.assertIn(' file.999\n', run.output)
@@ -894,7 +894,7 @@ class ZZipTest(unittest.TestCase):
     zipfile = "test4.zip"
     getfile = "test4.zip"
     exe = self.bins("unzzip-mem")
-    run = shell("{exe} -l {getfile} ".format(**locals()))
+    run = shell("{exe} -v {getfile} ".format(**locals()))
     self.assertIn(' file.001\n', run.output)
     self.assertIn(' file.222\n', run.output)
     self.assertIn(' file.999\n', run.output)
@@ -906,7 +906,7 @@ class ZZipTest(unittest.TestCase):
     zipfile = "test0.zip"
     getfile = "test0.zip"
     exe = self.bins("unzzip-mix")
-    run = shell("{exe} -l {getfile} ".format(**locals()))
+    run = shell("{exe} -v {getfile} ".format(**locals()))
     self.assertIn(' README\n', run.output)
     self.assertIn(' defl:N ', run.output)
     self.assertLess(len(run.output), 30)
@@ -915,7 +915,7 @@ class ZZipTest(unittest.TestCase):
     zipfile = "test1.zip"
     getfile = "test1.zip"
     exe = self.bins("unzzip-mix")
-    run = shell("{exe} -l {getfile} ".format(**locals()))
+    run = shell("{exe} -v {getfile} ".format(**locals()))
     self.assertIn(' file.1\n', run.output)
     self.assertIn(' file.2\n', run.output)
     self.assertIn(' file.9\n', run.output)
@@ -927,7 +927,7 @@ class ZZipTest(unittest.TestCase):
     zipfile = "test2.zip"
     getfile = "test2.zip"
     exe = self.bins("unzzip-mix")
-    run = shell("{exe} -l {getfile} ".format(**locals()))
+    run = shell("{exe} -v {getfile} ".format(**locals()))
     self.assertIn(' file.01\n', run.output)
     self.assertIn(' file.22\n', run.output)
     self.assertIn(' file.99\n', run.output)
@@ -938,7 +938,7 @@ class ZZipTest(unittest.TestCase):
     zipfile = "test3.zip"
     getfile = "test3.zip"
     exe = self.bins("unzzip-mix")
-    run = shell("{exe} -l {getfile} ".format(**locals()))
+    run = shell("{exe} -v {getfile} ".format(**locals()))
     self.assertIn(' file.001\n', run.output)
     self.assertIn(' file.222\n', run.output)
     self.assertIn(' file.999\n', run.output)
@@ -949,7 +949,7 @@ class ZZipTest(unittest.TestCase):
     zipfile = "test4.zip"
     getfile = "test4.zip"
     exe = self.bins("unzzip-mix")
-    run = shell("{exe} -l {getfile} ".format(**locals()))
+    run = shell("{exe} -v {getfile} ".format(**locals()))
     self.assertIn(' file.001\n', run.output)
     self.assertIn(' file.222\n', run.output)
     self.assertIn(' file.999\n', run.output)
@@ -960,7 +960,7 @@ class ZZipTest(unittest.TestCase):
     zipfile = "test0.zip"
     getfile = "test0.zip"
     exe = self.bins("unzzip")
-    run = shell("{exe} -l {getfile} ".format(**locals()))
+    run = shell("{exe} -v {getfile} ".format(**locals()))
     self.assertIn(' README\n', run.output)
     self.assertIn(' defl:N ', run.output)
     self.assertLess(len(run.output), 30)
@@ -969,7 +969,7 @@ class ZZipTest(unittest.TestCase):
     zipfile = "test1.zip"
     getfile = "test1.zip"
     exe = self.bins("unzzip")
-    run = shell("{exe} -l {getfile} ".format(**locals()))
+    run = shell("{exe} -v {getfile} ".format(**locals()))
     self.assertIn(' file.1\n', run.output)
     self.assertIn(' file.2\n', run.output)
     self.assertIn(' file.9\n', run.output)
@@ -981,7 +981,7 @@ class ZZipTest(unittest.TestCase):
     zipfile = "test2.zip"
     getfile = "test2.zip"
     exe = self.bins("unzzip")
-    run = shell("{exe} -l {getfile} ".format(**locals()))
+    run = shell("{exe} -v {getfile} ".format(**locals()))
     self.assertIn(' file.01\n', run.output)
     self.assertIn(' file.22\n', run.output)
     self.assertIn(' file.99\n', run.output)
@@ -992,7 +992,7 @@ class ZZipTest(unittest.TestCase):
     zipfile = "test3.zip"
     getfile = "test3.zip"
     exe = self.bins("unzzip")
-    run = shell("{exe} -l {getfile} ".format(**locals()))
+    run = shell("{exe} -v {getfile} ".format(**locals()))
     self.assertIn(' file.001\n', run.output)
     self.assertIn(' file.222\n', run.output)
     self.assertIn(' file.999\n', run.output)
@@ -1003,7 +1003,7 @@ class ZZipTest(unittest.TestCase):
     zipfile = "test4.zip"
     getfile = "test4.zip"
     exe = self.bins("unzzip")
-    run = shell("{exe} -l {getfile} ".format(**locals()))
+    run = shell("{exe} -v {getfile} ".format(**locals()))
     self.assertIn(' file.001\n', run.output)
     self.assertIn(' file.222\n', run.output)
     self.assertIn(' file.999\n', run.output)