diff --git a/regress/file_comment_encmismatch.test b/regress/file_comment_encmismatch.test index fb026eb3e..a5c6c221f 100644 --- a/regress/file_comment_encmismatch.test +++ b/regress/file_comment_encmismatch.test @@ -1,4 +1,7 @@ # set file comment to UTF-8 for CP437 encoded filename (adds InfoZIP extra field) return 0 -arguments testfile.zip set_file_comment 0 ÄÖÜßäöü +arguments -i testfile.zip dummy +stdin +set_file_comment 0 ÄÖÜßäöü +end-of-inline-data file testfile.zip test-cp437.zip test-cp437-comment-utf-8.zip diff --git a/regress/name_locate-utf8.test b/regress/name_locate-utf8.test index ae205206f..bbd638416 100644 --- a/regress/name_locate-utf8.test +++ b/regress/name_locate-utf8.test @@ -1,5 +1,8 @@ description tests for various encoding flags for zip_name_locate -arguments test.zip name_locate "æÆôöòûùÿÖÜ¢£¥₧ƒá" 0 name_locate "æÆôöòûùÿÖÜ¢£¥₧ƒá" 4 name_locate "æÆôöòûùÿÖÜ¢£¥₧ƒá" 8 name_locate "æÆôöòûùÿÖÜ¢£¥₧ƒá" r name_locate "æÆôöòûùÿÖÜ¢£¥₧ƒá" s +arguments -i test.zip dummy +stdin +name_locate æÆôöòûùÿÖÜ¢£¥₧ƒá 0 name_locate æÆôöòûùÿÖÜ¢£¥₧ƒá 4 name_locate æÆôöòûùÿÖÜ¢£¥₧ƒá 8 name_locate æÆôöòûùÿÖÜ¢£¥₧ƒá r name_locate æÆôöòûùÿÖÜ¢£¥₧ƒá s +end-of-inline-data return 0 file test.zip test-cp437.zip stdout diff --git a/regress/rename_utf8.test b/regress/rename_utf8.test index 452661ca7..d4b13a56b 100644 --- a/regress/rename_utf8.test +++ b/regress/rename_utf8.test @@ -1,4 +1,7 @@ # rename file to UTF-8 name in zip archive return 0 -arguments testfile rename 0 ÄÖÜßäöü +arguments -i testfile dummy +stdin +rename 0 ÄÖÜßäöü +end-of-inline-data file testfile testfile.zip testfile-UTF8.zip diff --git a/regress/rename_utf8_encmismatch.test b/regress/rename_utf8_encmismatch.test index cf8b21948..e20dbc926 100644 --- a/regress/rename_utf8_encmismatch.test +++ b/regress/rename_utf8_encmismatch.test @@ -1,4 +1,7 @@ # rename file to UTF-8 name in zip archive with CP437 comment (sets InfoZIP UTF-8 Name Extension) return 0 -arguments testfile rename 0 ÄÖÜßäöü +arguments -i testfile dummy +stdin +rename 0 ÄÖÜßäöü +end-of-inline-data file testfile test-cp437-fc.zip test-cp437-fc-utf-8-filename.zip diff --git a/regress/ziptool_regress.c b/regress/ziptool_regress.c index a653de3a0..562897b11 100644 --- a/regress/ziptool_regress.c +++ b/regress/ziptool_regress.c @@ -12,6 +12,7 @@ source_type_t source_type = SOURCE_TYPE_NONE; zip_uint64_t fragment_size = 0; zip_file_t *z_files[16]; unsigned int z_files_count; +int commands_from_stdin = 0; static int add_nul(char *argv[]); static int cancel(char *argv[]); @@ -24,14 +25,17 @@ static int unchange_one(char *argv[]); static int unchange_all(char *argv[]); static int zin_close(char *argv[]); -#define OPTIONS_REGRESS "F:Hmx" +#define OPTIONS_REGRESS "F:Himx" -#define USAGE_REGRESS " [-Hmx] [-F fragment-size]" +#define USAGE_REGRESS " [-Himx] [-F fragment-size]" #define GETOPT_REGRESS \ case 'H': \ source_type = SOURCE_TYPE_HOLE; \ break; \ + case 'i': \ + commands_from_stdin = 1; \ + break; \ case 'm': \ source_type = SOURCE_TYPE_IN_MEMORY; \ break; \ @@ -69,12 +73,43 @@ static int zin_close(char *argv[]); /* clang-format on */ +#define MAX_STDIN_ARGC 128 +#define MAX_STDIN_LENGTH 8192 + +char* stdin_argv[MAX_STDIN_ARGC]; +static char stdin_line[MAX_STDIN_LENGTH]; + +int get_stdin_commands(void); + +#define REGRESS_PREPARE_ARGS \ + if (commands_from_stdin) { \ + argc = get_stdin_commands(); \ + arg = 0; \ + argv = stdin_argv; \ + } zip_t *ziptool_open(const char *archive, int flags, zip_error_t *error, zip_uint64_t offset, zip_uint64_t len); #include "ziptool.c" +int get_stdin_commands(void) { + int argc = 0; + char *p, *word; + fgets(stdin_line, sizeof(stdin_line), stdin); + p = stdin_line; + while ((word = strsep(&p, " \n")) != NULL) { + if (word[0] == '\0') { + continue; + } + stdin_argv[argc] = word; + argc++; + if (argc >= MAX_STDIN_ARGC) { + break; + } + } + return argc; +} zip_source_t *memory_src = NULL; diff --git a/src/ziptool.c b/src/ziptool.c index e9b8da70c..281bfbbb7 100644 --- a/src/ziptool.c +++ b/src/ziptool.c @@ -1060,6 +1060,10 @@ main(int argc, char *argv[]) { } zip_error_fini(&error); +#ifdef REGRESS_PREPARE_ARGS + REGRESS_PREPARE_ARGS +#endif + err = 0; while (arg < argc) { int ret;