Mercurial > hg > toybox
changeset 1651:114fb916e04e draft
One more bugfix for printf.c, with test suite entry. (Make %-3d etc work.)
author | Rob Landley <rob@landley.net> |
---|---|
date | Sun, 11 Jan 2015 10:16:38 -0600 |
parents | a740a876c76c |
children | 971df24b458b |
files | tests/printf.test toys/pending/printf.c |
diffstat | 2 files changed, 8 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/tests/printf.test Sun Jan 11 01:22:36 2015 -0600 +++ b/tests/printf.test Sun Jan 11 10:16:38 2015 -0600 @@ -37,7 +37,10 @@ testing "printf extra args" "$PRINTF 'abc%s!%ddef\n' X 42 ARG 36" \ "abcX!42def\nabcARG!36def\n" "" "" -testing "printf '%3c'" "printf '%3c' x" " x" "" "" +testing "printf '%3c'" "$PRINTF '%3c' x" " x" "" "" +testing "printf '%-3c'" "$PRINTF '%-3c' x" "x " "" "" +testing "printf '%+d'" "$PRINTF '%+d' 5" "+5" "" "" + testing "printf '%5d%4d' 1 21 321 4321 54321" \ "$PRINTF '%5d%4d' 1 21 321 4321 54321" " 1 21 321432154321 0" "" ""
--- a/toys/pending/printf.c Sun Jan 11 01:22:36 2015 -0600 +++ b/toys/pending/printf.c Sun Jan 11 10:16:38 2015 -0600 @@ -4,6 +4,8 @@ * Copyright 2014 Kyungwan Han <asura321@gmail.com> * * See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/printf.html + * + * todo: *m$ ala printf("%1$d:%2$.*3$d:%4$.*3$d\n", hour, min, precision, sec); USE_PRINTF(NEWTOY(printf, "<1", TOYFLAG_USR|TOYFLAG_BIN)) @@ -93,7 +95,7 @@ // Parse width.precision between % and type indicator. *to++ = '%'; - while (strchr("-+# '0", *f) && (to-toybuf)<10) *to = *f++; + while (strchr("-+# '0", *f) && (to-toybuf)<10) *to++ = *f++; for (i=0; i<2; i++) { if (eat(&f, '*')) { if (*arg) wp[i] = atolx(*arg++); @@ -118,10 +120,10 @@ else if (strchr("diouxX", c)) { long ll; - sprintf(to, "*.*ll%c", c); if (*aa == '\'' || *aa == '"') ll = aa[1]; else ll = strtoll(aa, &end, 0); + sprintf(to, "*.*ll%c", c); printf(toybuf, wp[0], wp[1], ll); } else if (strchr("feEgG", c)) { long double ld = strtold(aa, &end);