diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2019-06-09 09:16:03 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2019-06-09 09:16:03 +0200 |
| commit | 48eebc8d5c43c204941abb467d412bd58d845e72 (patch) | |
| tree | 8c0591486400115c27f0fd80fd9c871ef17c9749 /coreutils | |
| parent | 92549250f36f91f4492c296bb227cfca83d5c4fe (diff) | |
| download | busybox-w32-48eebc8d5c43c204941abb467d412bd58d845e72.tar.gz busybox-w32-48eebc8d5c43c204941abb467d412bd58d845e72.tar.bz2 busybox-w32-48eebc8d5c43c204941abb467d412bd58d845e72.zip | |
expand: add commented-out code to handle NULs
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
| -rw-r--r-- | coreutils/expand.c | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/coreutils/expand.c b/coreutils/expand.c index 8d064db5e..20e4c4b23 100644 --- a/coreutils/expand.c +++ b/coreutils/expand.c | |||
| @@ -64,34 +64,61 @@ enum { | |||
| 64 | }; | 64 | }; |
| 65 | 65 | ||
| 66 | //FIXME: does not work properly with input containing NULs | 66 | //FIXME: does not work properly with input containing NULs |
| 67 | //coreutils 8.30 preserves NULs but treats them as chars of width zero: | ||
| 68 | //AB<nul><tab>C will expand <tab> to 6 spaces, not 5. | ||
| 67 | 69 | ||
| 68 | #if ENABLE_EXPAND | 70 | #if ENABLE_EXPAND |
| 69 | static void expand(FILE *file, unsigned tab_size, unsigned opt) | 71 | static void expand(FILE *file, unsigned tab_size, unsigned opt) |
| 70 | { | 72 | { |
| 71 | char *line; | ||
| 72 | 73 | ||
| 73 | while ((line = xmalloc_fgets(file)) != NULL) { | 74 | for (;;) { |
| 74 | unsigned char c; | 75 | char *line; |
| 75 | char *ptr; | 76 | char *ptr; |
| 76 | char *ptr_strbeg; | 77 | char *ptr_strbeg; |
| 77 | 78 | //commented-out code handles NULs, +90 bytes of code, not tested much | |
| 79 | // size_t linelen; | ||
| 80 | // unsigned len = 0; | ||
| 81 | |||
| 82 | // linelen = 1024 * 1024; | ||
| 83 | // line = xmalloc_fgets_str_len(file, "\n", &linelen); | ||
| 84 | line = xmalloc_fgets(file); // | ||
| 85 | if (!line) | ||
| 86 | break; | ||
| 78 | ptr = ptr_strbeg = line; | 87 | ptr = ptr_strbeg = line; |
| 79 | while ((c = *ptr) != '\0') { | 88 | for (;;) { |
| 89 | unsigned char c = *ptr; | ||
| 90 | if (c == '\0') { | ||
| 91 | // size_t rem = line + linelen - ptr; | ||
| 92 | // if (rem > 0) { | ||
| 93 | //# if ENABLE_UNICODE_SUPPORT | ||
| 94 | // len += unicode_strwidth(ptr_strbeg); | ||
| 95 | //# else | ||
| 96 | // len += ptr - ptr_strbeg; | ||
| 97 | //# endif | ||
| 98 | // printf("%s%c", ptr_strbeg, '\0'); | ||
| 99 | // memmove(ptr, ptr + 1, rem + 1); | ||
| 100 | // ptr_strbeg = ptr; | ||
| 101 | // linelen--; | ||
| 102 | // continue; | ||
| 103 | // } | ||
| 104 | break; | ||
| 105 | } | ||
| 80 | if ((opt & OPT_INITIAL) && !isblank(c)) { | 106 | if ((opt & OPT_INITIAL) && !isblank(c)) { |
| 81 | /* not space or tab */ | 107 | /* not space or tab */ |
| 82 | break; | 108 | break; |
| 83 | } | 109 | } |
| 84 | if (c == '\t') { | 110 | if (c == '\t') { |
| 85 | unsigned len; | 111 | unsigned len = 0; // |
| 86 | *ptr = '\0'; | 112 | *ptr = '\0'; |
| 87 | # if ENABLE_UNICODE_SUPPORT | 113 | # if ENABLE_UNICODE_SUPPORT |
| 88 | len = unicode_strwidth(ptr_strbeg); | 114 | len += unicode_strwidth(ptr_strbeg); |
| 89 | # else | 115 | # else |
| 90 | len = ptr - ptr_strbeg; | 116 | len += ptr - ptr_strbeg; |
| 91 | # endif | 117 | # endif |
| 92 | len = tab_size - (len % tab_size); | 118 | len = tab_size - (len % tab_size); |
| 93 | /*while (ptr[1] == '\t') { ptr++; len += tab_size; } - can handle many tabs at once */ | 119 | /*while (ptr[1] == '\t') { ptr++; len += tab_size; } - can handle many tabs at once */ |
| 94 | printf("%s%*s", ptr_strbeg, len, ""); | 120 | printf("%s%*s", ptr_strbeg, len, ""); |
| 121 | // len = 0; | ||
| 95 | ptr_strbeg = ptr + 1; | 122 | ptr_strbeg = ptr + 1; |
| 96 | } | 123 | } |
| 97 | ptr++; | 124 | ptr++; |
