Integrate get_comment.c into modify.c and adapt tests.
diff --git a/.hgignore b/.hgignore index 52b48ea..08e4a0f 100644 --- a/.hgignore +++ b/.hgignore
@@ -24,7 +24,6 @@ ^regress/encoding$ ^regress/fopen_unchanged$ ^regress/fread$ -^regress/get_comment$ ^regress/modify$ ^regress/name_locate$ ^regress/rename$
diff --git a/regress/CMakeLists.txt b/regress/CMakeLists.txt index e7069ba..4498f57 100644 --- a/regress/CMakeLists.txt +++ b/regress/CMakeLists.txt
@@ -6,7 +6,6 @@ add_from_zip fopen_unchanged fread - get_comment name_locate set_comment_all set_comment_localonly
diff --git a/regress/Makefile.am b/regress/Makefile.am index ecbc4d5..08019c4 100644 --- a/regress/Makefile.am +++ b/regress/Makefile.am
@@ -4,7 +4,6 @@ add_from_zip \ fopen_unchanged \ fread \ - get_comment \ modify \ name_locate \ rename \
diff --git a/regress/file_comment_encmismatch.test b/regress/file_comment_encmismatch.test index 845851e..8685cdb 100644 --- a/regress/file_comment_encmismatch.test +++ b/regress/file_comment_encmismatch.test
@@ -1,6 +1,6 @@ # set file comment to UTF-8 for CP437 encoded filename (fails) program modify return 1 -args testfile file_comment 0 ÄÖÜßäöü +args testfile set_file_comment 0 ÄÖÜßäöü file testfile test-cp437.zip test-cp437.zip stderr can't set file comment at index `0' to `ÄÖÜßäöü': Encoding of name and comment do not match
diff --git a/regress/get_comment.c b/regress/get_comment.c deleted file mode 100644 index 2446f5a..0000000 --- a/regress/get_comment.c +++ /dev/null
@@ -1,89 +0,0 @@ -/* - comment.c -- test cases for file and archive comments - Copyright (C) 2006 Dieter Baron and Thomas Klausner - - This file is part of libzip, a library to manipulate ZIP archives. - The authors can be contacted at <libzip@nih.at> - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. - 3. The names of the authors may not be used to endorse or promote - products derived from this software without specific prior - written permission. - - THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS - OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER - IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - - - -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include "zip.h" - -const char *prg; - -int -main(int argc, char *argv[]) -{ - const char *archive; - struct zip *za; - char buf[100]; - int err; - const char *com; - int i, len; - - prg = argv[0]; - - if (argc != 2) { - fprintf(stderr, "usage: %s archive\n", prg); - return 1; - } - - archive = argv[1]; - - if ((za=zip_open(archive, 0, &err)) == NULL) { - zip_error_to_str(buf, sizeof(buf), err, errno); - fprintf(stderr, "%s: can't open zip archive `%s': %s\n", prg, - archive, buf); - return 1; - } - - if ((com=zip_get_archive_comment(za, &len, 0)) == NULL) - printf("No archive comment\n"); - else - printf("Archive comment: %.*s\n", len, com); - - for (i=0; i<zip_get_num_files(za); i++) { - if ((com=zip_get_file_comment(za, i, &len, 0)) == NULL) - printf("No comment for `%s'\n", zip_get_name(za, i, 0)); - else - printf("File comment for `%s': %.*s\n", zip_get_name(za, i, 0), len, com); - } - - if (zip_close(za) == -1) { - fprintf(stderr, "%s: can't close zip archive `%s': %s\n", prg, archive, zip_strerror(za)); - return 1; - } - - return 0; -}
diff --git a/regress/get_comment.test b/regress/get_comment.test index a7b22ea..09a8cbb 100644 --- a/regress/get_comment.test +++ b/regress/get_comment.test
@@ -1,7 +1,7 @@ # show comments of a zip archive -program get_comment +program modify return 0 -args testcomment.zip +args testcomment.zip get_archive_comment get_file_comment 0 get_file_comment 1 get_file_comment 2 get_file_comment 3 file testcomment.zip testcomment.zip testcomment.zip stdout Archive comment: This is the archive comment for the file. stdout
diff --git a/regress/modify.c b/regress/modify.c index dc2bdf2..6ebf867 100644 --- a/regress/modify.c +++ b/regress/modify.c
@@ -56,7 +56,17 @@ prg = argv[arg++]; if (argc < 2) { - fprintf(stderr, "usage: %s archive [add name content|add_dir name|add_file name filename offset len|delete index|file_comment index comment|rename index name]\n", prg); + fprintf(stderr, "usage: %s archive command1 [args] command2 [args] ...]\n\n" + "Supported commands and arguments are:\n" + "\tadd name content\n" + "\tadd_dir name\n" + "\tadd_file name filename offset len\n" + "\tdelete index\n" + "\tget_archive_comment\n" + "\tget_file_comment index\n" + "\trename index name\n" + "\tset_file_comment index comment\n" + "\nThe index is zero-based.\n", prg); return 1; } @@ -117,15 +127,25 @@ break; } arg += 2; - } else if (strcmp(argv[arg], "file_comment") == 0 && arg+2 < argc) { - /* set file comment */ + } else if (strcmp(argv[arg], "get_archive_comment") == 0) { + const char *comment; + int len; + /* get archive comment */ + if ((comment=zip_get_archive_comment(za, &len, 0)) == NULL) + printf("No archive comment\n"); + else + printf("Archive comment: %.*s\n", len, comment); + arg += 1; + } else if (strcmp(argv[arg], "get_file_comment") == 0 && arg+1 < argc) { + const char *comment; + int len; + /* get file comment */ idx = atoi(argv[arg+1]); - if (zip_set_file_comment(za, idx, argv[arg+2], strlen(argv[arg+2])) < 0) { - fprintf(stderr, "can't set file comment at index `%d' to `%s': %s\n", idx, argv[arg+2], zip_strerror(za)); - err = 1; - break; - } - arg += 3; + if ((comment=zip_get_file_comment(za, idx, &len, 0)) == NULL) + printf("No comment for `%s'\n", zip_get_name(za, idx, 0)); + else + printf("File comment for `%s': %.*s\n", zip_get_name(za, idx, 0), len, comment); + arg += 2; } else if (strcmp(argv[arg], "rename") == 0 && arg+2 < argc) { /* rename */ idx = atoi(argv[arg+1]); @@ -135,6 +155,15 @@ break; } arg += 3; + } else if (strcmp(argv[arg], "set_file_comment") == 0 && arg+2 < argc) { + /* set file comment */ + idx = atoi(argv[arg+1]); + if (zip_set_file_comment(za, idx, argv[arg+2], strlen(argv[arg+2])) < 0) { + fprintf(stderr, "can't set file comment at index `%d' to `%s': %s\n", idx, argv[arg+2], zip_strerror(za)); + err = 1; + break; + } + arg += 3; } else { fprintf(stderr, "unrecognized command `%s', or not enough arguments\n", argv[arg]); err = 1;