unzip: use printable_string() for printing filenames
authorDenys Vlasenko <vda.linux@googlemail.com>
Sun, 30 Sep 2018 14:56:56 +0000 (16:56 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Sun, 30 Sep 2018 14:56:56 +0000 (16:56 +0200)
function                                             old     new   delta
unzip_main                                          2726    2792     +66
printable_string2                                      -      57     +57
identify                                            4329    4336      +7
expmeta                                              659     663      +4
add_interface                                         99     103      +4
beep_main                                            286     289      +3
changepath                                           192     194      +2
builtin_type                                         115     117      +2
devmem_main                                          469     470      +1
input_tab                                           1076    1074      -2
create_J                                            1821    1819      -2
poplocalvars                                         314     311      -3
doCommands                                          2222    2214      -8
do_load                                              918     902     -16
printable_string                                      57       9     -48
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 8/6 up/down: 146/-79)            Total: 67 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
archival/unzip.c
coreutils/ls.c
include/libbb.h
libbb/lineedit.c
libbb/printable_string.c
libbb/unicode.c
util-linux/fdisk_gpt.c

index 96b7ab69b403b2a543879ea5673d8a5cb217b7a1..c406d53c422373ec59c1c5dcb726f28bfc335a78 100644 (file)
@@ -153,15 +153,15 @@ typedef union {
 #define FIX_ENDIANNESS_CDF(cdf) \
 do { if (BB_BIG_ENDIAN) { \
        (cdf).fmt.version_made_by = SWAP_LE16((cdf).fmt.version_made_by); \
-       (cdf).fmt.version_needed = SWAP_LE16((cdf).fmt.version_needed); \
-       (cdf).fmt.method        = SWAP_LE16((cdf).fmt.method      ); \
-       (cdf).fmt.modtime       = SWAP_LE16((cdf).fmt.modtime     ); \
-       (cdf).fmt.moddate       = SWAP_LE16((cdf).fmt.moddate     ); \
-       (cdf).fmt.crc32         = SWAP_LE32((cdf).fmt.crc32       ); \
-       (cdf).fmt.cmpsize       = SWAP_LE32((cdf).fmt.cmpsize     ); \
-       (cdf).fmt.ucmpsize      = SWAP_LE32((cdf).fmt.ucmpsize    ); \
-       (cdf).fmt.filename_len  = SWAP_LE16((cdf).fmt.filename_len); \
-       (cdf).fmt.extra_len     = SWAP_LE16((cdf).fmt.extra_len   ); \
+       (cdf).fmt.version_needed  = SWAP_LE16((cdf).fmt.version_needed ); \
+       (cdf).fmt.method          = SWAP_LE16((cdf).fmt.method         ); \
+       (cdf).fmt.modtime         = SWAP_LE16((cdf).fmt.modtime        ); \
+       (cdf).fmt.moddate         = SWAP_LE16((cdf).fmt.moddate        ); \
+       (cdf).fmt.crc32           = SWAP_LE32((cdf).fmt.crc32          ); \
+       (cdf).fmt.cmpsize         = SWAP_LE32((cdf).fmt.cmpsize        ); \
+       (cdf).fmt.ucmpsize        = SWAP_LE32((cdf).fmt.ucmpsize       ); \
+       (cdf).fmt.filename_len    = SWAP_LE16((cdf).fmt.filename_len   ); \
+       (cdf).fmt.extra_len       = SWAP_LE16((cdf).fmt.extra_len      ); \
        (cdf).fmt.file_comment_length = SWAP_LE16((cdf).fmt.file_comment_length); \
        (cdf).fmt.external_attributes = SWAP_LE32((cdf).fmt.external_attributes); \
 }} while (0)
@@ -456,7 +456,9 @@ static int get_lstat_mode(const char *dst_fn)
        struct stat stat_buf;
        if (lstat(dst_fn, &stat_buf) == -1) {
                if (errno != ENOENT) {
-                       bb_perror_msg_and_die("can't stat '%s'", dst_fn);
+                       bb_perror_msg_and_die("can't stat '%s'",
+                               dst_fn
+                       );
                }
                /* File does not exist */
                return -1;
@@ -634,7 +636,9 @@ int unzip_main(int argc, char **argv)
                                break;
                        if (++i > 2) {
                                *ext = '\0';
-                               bb_error_msg_and_die("can't open %s[.zip]", src_fn);
+                               bb_error_msg_and_die("can't open %s[.zip]",
+                                       src_fn
+                               );
                        }
                        strcpy(ext, extn[i - 1]);
                }
@@ -646,8 +650,11 @@ int unzip_main(int argc, char **argv)
                xchdir(base_dir);
 
        if (quiet <= 1) { /* not -qq */
-               if (quiet == 0)
-                       printf("Archive:  %s\n", src_fn);
+               if (quiet == 0) {
+                       printf("Archive:  %s\n",
+                               printable_string(src_fn)
+                       );
+               }
                if (opts & OPT_l) {
                        puts(verbose ?
                                " Length   Method    Size  Cmpr    Date    Time   CRC-32   Name\n"
@@ -831,7 +838,8 @@ int unzip_main(int argc, char **argv)
                                printf(       "%9u  " "%s   "         "%s\n",
                                        (unsigned)zip.fmt.ucmpsize,
                                        dtbuf,
-                                       dst_fn);
+                                       printable_string(dst_fn)
+                               );
                        } else {
                                char method6[7];
                                unsigned long percents;
@@ -860,7 +868,8 @@ int unzip_main(int argc, char **argv)
                                        (unsigned)percents,
                                        dtbuf,
                                        zip.fmt.crc32,
-                                       dst_fn);
+                                       printable_string(dst_fn)
+                               );
                                total_size += zip.fmt.cmpsize;
                        }
                        total_usize += zip.fmt.ucmpsize;
@@ -886,7 +895,7 @@ int unzip_main(int argc, char **argv)
                        mode = get_lstat_mode(dst_fn);
                        if (mode == -1) { /* ENOENT */
                                if (!quiet) {
-                                       printf("   creating: %s\n", dst_fn);
+                                       printf("   creating: %s\n", printable_string(dst_fn));
                                }
                                unzip_create_leading_dirs(dst_fn);
                                if (bb_make_directory(dst_fn, dir_mode, FILEUTILS_IGNORE_CHMOD_ERR)) {
@@ -895,7 +904,9 @@ int unzip_main(int argc, char **argv)
                        } else {
                                if (!S_ISDIR(mode)) {
                                        bb_error_msg_and_die("'%s' exists but is not a %s",
-                                               dst_fn, "directory");
+                                               printable_string(dst_fn),
+                                               "directory"
+                                       );
                                }
                        }
                        goto skip_cmpsize;
@@ -914,12 +925,16 @@ int unzip_main(int argc, char **argv)
                        if (!S_ISREG(mode)) {
  fishy:
                                bb_error_msg_and_die("'%s' exists but is not a %s",
-                                       dst_fn, "regular file");
+                                       printable_string(dst_fn),
+                                       "regular file"
+                               );
                        }
                        if (overwrite == O_ALWAYS) {
                                goto do_open_and_extract;
                        }
-                       printf("replace %s? [y]es, [n]o, [A]ll, [N]one, [r]ename: ", dst_fn);
+                       printf("replace %s? [y]es, [n]o, [A]ll, [N]one, [r]ename: ",
+                               printable_string(dst_fn)
+                       );
                        my_fgets80(key_buf);
                        /* User input could take a long time. Is it still a regular file? */
                        mode = get_lstat_mode(dst_fn);
@@ -949,7 +964,9 @@ int unzip_main(int argc, char **argv)
                        if (!quiet) {
                                printf(/* zip.fmt.method == 0
                                        ? " extracting: %s\n"
-                                       : */ "  inflating: %s\n", dst_fn);
+                                       : */ "  inflating: %s\n",
+                                       printable_string(dst_fn)
+                               );
                        }
 #if ENABLE_FEATURE_UNZIP_CDF
                        if (S_ISLNK(file_mode)) {
index b1c306809af7c033facad0f198e24bd63ae0aabc..db3ddb9446d521d7df6b2f4dd19da6de63a59166 100644 (file)
@@ -421,7 +421,7 @@ static unsigned calc_name_len(const char *name)
        uni_stat_t uni_stat;
 
        // TODO: quote tab as \t, etc, if -Q
-       name = printable_string(&uni_stat, name);
+       name = printable_string2(&uni_stat, name);
 
        if (!(option_mask32 & OPT_Q)) {
                return uni_stat.unicode_width;
@@ -450,7 +450,7 @@ static unsigned print_name(const char *name)
        uni_stat_t uni_stat;
 
        // TODO: quote tab as \t, etc, if -Q
-       name = printable_string(&uni_stat, name);
+       name = printable_string2(&uni_stat, name);
 
        if (!(option_mask32 & OPT_Q)) {
                fputs(name, stdout);
index 61fa1e03e62c45fe66318cb8afa9e90fc7ba29c6..140404ff5c40d34553669c01d5ebc71389543bf2 100644 (file)
@@ -833,7 +833,8 @@ typedef struct uni_stat_t {
 } uni_stat_t;
 /* Returns a string with unprintable chars replaced by '?' or
  * SUBST_WCHAR. This function is unicode-aware. */
-const char* FAST_FUNC printable_string(uni_stat_t *stats, const char *str);
+const char* FAST_FUNC printable_string(const char *str);
+const char* FAST_FUNC printable_string2(uni_stat_t *stats, const char *str);
 /* Prints unprintable char ch as ^C or M-c to file
  * (M-c is used only if ch is ORed with PRINTABLE_META),
  * else it is printed as-is (except for ch = 0x9b) */
index d5e92e84c364a9129bebfe44a2575dfcc24fbe7b..b1e971f88da7d64f51947141c946a4bf43f9465e 100644 (file)
@@ -1086,7 +1086,7 @@ static void showfiles(void)
                        );
                }
                if (ENABLE_UNICODE_SUPPORT)
-                       puts(printable_string(NULL, matches[n]));
+                       puts(printable_string(matches[n]));
                else
                        puts(matches[n]);
        }
index 077d58d32fd6f03f4ad8f8b3d73e3d6559c58f8d..a814fd03c08ae185e22411499a9b8b20d5e989fb 100644 (file)
@@ -9,7 +9,7 @@
 #include "libbb.h"
 #include "unicode.h"
 
-const char* FAST_FUNC printable_string(uni_stat_t *stats, const char *str)
+const char* FAST_FUNC printable_string2(uni_stat_t *stats, const char *str)
 {
        char *dst;
        const char *s;
@@ -55,3 +55,8 @@ const char* FAST_FUNC printable_string(uni_stat_t *stats, const char *str)
 #endif
        return auto_string(dst);
 }
+
+const char* FAST_FUNC printable_string(const char *str)
+{
+       return printable_string2(NULL, str);
+}
index d378175a4f0ca381f9a2e1054be30e71dcc85c4f..89d42179b48c280900739904b976bc925c73e18d 100644 (file)
@@ -996,7 +996,7 @@ size_t FAST_FUNC unicode_strlen(const char *string)
 size_t FAST_FUNC unicode_strwidth(const char *string)
 {
        uni_stat_t uni_stat;
-       printable_string(&uni_stat, string);
+       printable_string2(&uni_stat, string);
        return uni_stat.unicode_width;
 }
 
index cdb90627daec785f9c2e13836bc5583a275bf5cd..dbe889f7c32681ef5efa7de0cf342df637661d17 100644 (file)
@@ -87,7 +87,7 @@ gpt_print_wide36(uint16_t *s)
        }
        wc[i] = 0;
        if (wcstombs(buf, wc, sizeof(buf)) <= sizeof(buf)-1)
-               fputs(printable_string(NULL, buf), stdout);
+               fputs(printable_string(buf), stdout);
 #else
        char buf[37];
        int i = 0;