diff options
-rw-r--r-- | coreutils/printf.c | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/coreutils/printf.c b/coreutils/printf.c index a20fc3301..45d761d1c 100644 --- a/coreutils/printf.c +++ b/coreutils/printf.c | |||
@@ -155,6 +155,12 @@ static double my_xstrtod(const char *arg) | |||
155 | static int print_esc_string(const char *str) | 155 | static int print_esc_string(const char *str) |
156 | { | 156 | { |
157 | char c; | 157 | char c; |
158 | #if ENABLE_PLATFORM_MINGW32 | ||
159 | char *s, *t; | ||
160 | int ret = 0; | ||
161 | |||
162 | s = t = xstrdup(str); | ||
163 | #endif | ||
158 | while ((c = *str) != '\0') { | 164 | while ((c = *str) != '\0') { |
159 | str++; | 165 | str++; |
160 | if (c == '\\') { | 166 | if (c == '\\') { |
@@ -166,7 +172,12 @@ static int print_esc_string(const char *str) | |||
166 | } | 172 | } |
167 | } | 173 | } |
168 | else if (*str == 'c') { | 174 | else if (*str == 'c') { |
175 | #if ENABLE_PLATFORM_MINGW32 | ||
176 | ret = 1; | ||
177 | goto finish; | ||
178 | #else | ||
169 | return 1; | 179 | return 1; |
180 | #endif | ||
170 | } | 181 | } |
171 | { | 182 | { |
172 | /* optimization: don't force arg to be on-stack, | 183 | /* optimization: don't force arg to be on-stack, |
@@ -176,10 +187,21 @@ static int print_esc_string(const char *str) | |||
176 | str = z; | 187 | str = z; |
177 | } | 188 | } |
178 | } | 189 | } |
190 | #if ENABLE_PLATFORM_MINGW32 | ||
191 | *t++ = c; | ||
192 | #else | ||
179 | putchar(c); | 193 | putchar(c); |
194 | #endif | ||
180 | } | 195 | } |
181 | 196 | #if ENABLE_PLATFORM_MINGW32 | |
197 | finish: | ||
198 | *t = '\0'; | ||
199 | printf(s); | ||
200 | free(s); | ||
201 | return ret; | ||
202 | #else | ||
182 | return 0; | 203 | return 0; |
204 | #endif | ||
183 | } | 205 | } |
184 | 206 | ||
185 | static void print_direc(char *format, unsigned fmt_length, | 207 | static void print_direc(char *format, unsigned fmt_length, |
@@ -293,10 +315,19 @@ static char **print_formatted(char *f, char **argv, int *conv_err) | |||
293 | int field_width; /* Arg to first '*' */ | 315 | int field_width; /* Arg to first '*' */ |
294 | int precision; /* Arg to second '*' */ | 316 | int precision; /* Arg to second '*' */ |
295 | char **saved_argv = argv; | 317 | char **saved_argv = argv; |
318 | #if ENABLE_PLATFORM_MINGW32 | ||
319 | char *s, *t; | ||
320 | s = t = auto_string(xstrdup(f)); | ||
321 | #endif | ||
296 | 322 | ||
297 | for (; *f; ++f) { | 323 | for (; *f; ++f) { |
298 | switch (*f) { | 324 | switch (*f) { |
299 | case '%': | 325 | case '%': |
326 | #if ENABLE_PLATFORM_MINGW32 | ||
327 | *t = '\0'; | ||
328 | printf(s); | ||
329 | t = s; | ||
330 | #endif | ||
300 | direc_start = f++; | 331 | direc_start = f++; |
301 | direc_length = 1; | 332 | direc_length = 1; |
302 | field_width = precision = 0; | 333 | field_width = precision = 0; |
@@ -385,6 +416,19 @@ static char **print_formatted(char *f, char **argv, int *conv_err) | |||
385 | free(p); | 416 | free(p); |
386 | } | 417 | } |
387 | break; | 418 | break; |
419 | #if ENABLE_PLATFORM_MINGW32 | ||
420 | case '\\': | ||
421 | if (*++f == 'c') { | ||
422 | *t = '\0'; | ||
423 | printf(s); | ||
424 | return saved_argv; /* causes main() to exit */ | ||
425 | } | ||
426 | *t++ = bb_process_escape_sequence((const char **)&f); | ||
427 | f--; | ||
428 | break; | ||
429 | default: | ||
430 | *t++ = *f; | ||
431 | #else | ||
388 | case '\\': | 432 | case '\\': |
389 | if (*++f == 'c') { | 433 | if (*++f == 'c') { |
390 | return saved_argv; /* causes main() to exit */ | 434 | return saved_argv; /* causes main() to exit */ |
@@ -394,8 +438,13 @@ static char **print_formatted(char *f, char **argv, int *conv_err) | |||
394 | break; | 438 | break; |
395 | default: | 439 | default: |
396 | putchar(*f); | 440 | putchar(*f); |
441 | #endif | ||
397 | } | 442 | } |
398 | } | 443 | } |
444 | #if ENABLE_PLATFORM_MINGW32 | ||
445 | *t = '\0'; | ||
446 | printf(s); | ||
447 | #endif | ||
399 | 448 | ||
400 | return argv; | 449 | return argv; |
401 | } | 450 | } |