aboutsummaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2024-01-01 22:22:15 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2024-01-01 22:24:42 +0100
commit1cac2585217f830d29f7e9d2a1226d55c80886b6 (patch)
treefb40d7a0720871587ab806cb9b36c2da6626777f /miscutils
parent01e80ff9ebaf42f2fb9b4ddddc75d37bc9a403aa (diff)
downloadbusybox-w32-1cac2585217f830d29f7e9d2a1226d55c80886b6.tar.gz
busybox-w32-1cac2585217f830d29f7e9d2a1226d55c80886b6.tar.bz2
busybox-w32-1cac2585217f830d29f7e9d2a1226d55c80886b6.zip
time: implement %% and \escapes in -f FMT
function old new delta time_main 1217 1316 +99 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
-rw-r--r--miscutils/time.c39
1 files changed, 18 insertions, 21 deletions
diff --git a/miscutils/time.c b/miscutils/time.c
index 4b1b043c3..77d35a832 100644
--- a/miscutils/time.c
+++ b/miscutils/time.c
@@ -226,28 +226,19 @@ static void summarize(const char *fmt, char **command, resource_t *resp)
226 } 226 }
227 227
228 switch (*fmt) { 228 switch (*fmt) {
229#ifdef NOT_NEEDED
230 /* Handle literal char */
231 /* Usually we optimize for size, but there is a limit
232 * for everything. With this we do a lot of 1-byte writes */
233 default:
234 bb_putchar(*fmt);
235 break;
236#endif
237
238 case '%': 229 case '%':
239 switch (*++fmt) { 230 switch (*++fmt) {
240#ifdef NOT_NEEDED_YET
241 /* Our format strings do not have these */
242 /* and we do not take format str from user */
243 default: 231 default:
244 bb_putchar('%'); 232 /* Unknown %<char> is printed as "?<char>" */
233 bb_putchar('?');
234 if (!*fmt) {
235 /* Trailing -f '...%' prints "...?" but NOT newline */
236 goto ret;
237 }
245 /*FALLTHROUGH*/ 238 /*FALLTHROUGH*/
246 case '%': 239 case '%':
247 if (!*fmt) goto ret;
248 bb_putchar(*fmt); 240 bb_putchar(*fmt);
249 break; 241 break;
250#endif
251 case 'C': /* The command that got timed. */ 242 case 'C': /* The command that got timed. */
252 printargv(command); 243 printargv(command);
253 break; 244 break;
@@ -381,14 +372,21 @@ static void summarize(const char *fmt, char **command, resource_t *resp)
381 } 372 }
382 break; 373 break;
383 374
384#ifdef NOT_NEEDED_YET 375 default: /* *fmt is '\': format escape */
385 case '\\': /* Format escape. */
386 switch (*++fmt) { 376 switch (*++fmt) {
387 default: 377 default:
378 /* Unknown \<char> is printed as "?\<char>" */
379 bb_putchar('?');
388 bb_putchar('\\'); 380 bb_putchar('\\');
381 if (!*fmt) {
382 /* Trailing -f '...\': GNU time 1.9 prints
383 * "...?\COMMAND" (it's probably a bug).
384 */
385 puts(command[0]);
386 goto ret;
387 }
389 /*FALLTHROUGH*/ 388 /*FALLTHROUGH*/
390 case '\\': 389 case '\\':
391 if (!*fmt) goto ret;
392 bb_putchar(*fmt); 390 bb_putchar(*fmt);
393 break; 391 break;
394 case 't': 392 case 't':
@@ -399,12 +397,11 @@ static void summarize(const char *fmt, char **command, resource_t *resp)
399 break; 397 break;
400 } 398 }
401 break; 399 break;
402#endif
403 } 400 }
404 ++fmt; 401 ++fmt;
405 } 402 }
406 /* ret: */
407 bb_putchar('\n'); 403 bb_putchar('\n');
404 ret: ;
408} 405}
409 406
410/* Run command CMD and return statistics on it. 407/* Run command CMD and return statistics on it.
@@ -438,7 +435,7 @@ int time_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
438int time_main(int argc UNUSED_PARAM, char **argv) 435int time_main(int argc UNUSED_PARAM, char **argv)
439{ 436{
440 resource_t res; 437 resource_t res;
441 /* $TIME has lowest prio (-v,-p,-f FMT overrride it) */ 438 /* $TIME has lowest prio (-v,-p,-f FMT override it) */
442 const char *output_format = getenv("TIME") ? : default_format; 439 const char *output_format = getenv("TIME") ? : default_format;
443 char *output_filename; 440 char *output_filename;
444 int output_fd; 441 int output_fd;