tadd %lB for lower case - plan9port - [fork] Plan 9 from user space
 (HTM) git clone git://src.adamsgaard.dk/plan9port
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 039b8c9af0866a5a6607cbdd992b586896d48cdc
 (DIR) parent 52e5e85b025b9f520324997ea1410e0e6a9aa84c
 (HTM) Author: rsc <devnull@localhost>
       Date:   Sun, 13 Feb 2005 18:34:57 +0000
       
       add %lB for lower case
       
       Diffstat:
         M src/libmp/port/mpfmt.c              |      67 ++++++++++++++++++-------------
       
       1 file changed, 39 insertions(+), 28 deletions(-)
       ---
 (DIR) diff --git a/src/libmp/port/mpfmt.c b/src/libmp/port/mpfmt.c
       t@@ -40,10 +40,10 @@ to32(mpint *b, char *buf, int len)
                return rv;
        }
        
       -static char set16[] = "0123456789ABCDEF";
       -
       +static char upper16[] = "0123456789ABCDEF";
       +static char lower16[] = "0123456789abcdef";
        static int
       -to16(mpint *b, char *buf, int len)
       +to16(mpint *b, char *buf, int len, char *set16)
        {
                mpdigit *p, x;
                int i, j;
       t@@ -123,30 +123,8 @@ to10(mpint *b, char *buf, int len)
                return 0;
        }
        
       -int
       -mpfmt(Fmt *fmt)
       -{
       -        mpint *b;
       -        char *p;
       -
       -        b = va_arg(fmt->args, mpint*);
       -        if(b == nil)
       -                return fmtstrcpy(fmt, "*");
       -        
       -        p = mptoa(b, fmt->prec, nil, 0);
       -        fmt->flags &= ~FmtPrec;
       -
       -        if(p == nil)
       -                return fmtstrcpy(fmt, "*");
       -        else{
       -                fmtstrcpy(fmt, p);
       -                free(p);
       -                return 0;
       -        }
       -}
       -
       -char*
       -mptoa(mpint *b, int base, char *buf, int len)
       +static char*
       +_mptoa(mpint *b, int base, char *buf, int len, char *set16)
        {
                char *out;
                int rv, alloced;
       t@@ -177,7 +155,7 @@ mptoa(mpint *b, int base, char *buf, int len)
                        break;
                default:
                case 16:
       -                rv = to16(b, out, len);
       +                rv = to16(b, out, len, set16);
                        break;
                case 10:
                        rv = to10(b, out, len);
       t@@ -190,3 +168,36 @@ mptoa(mpint *b, int base, char *buf, int len)
                }
                return buf;
        }
       +
       +char*
       +mptoa(mpint *b, int base, char *buf, int len)
       +{
       +        return _mptoa(b, base, buf, len, upper16);
       +}
       +
       +int
       +mpfmt(Fmt *fmt)
       +{
       +        mpint *b;
       +        char *p;
       +        char *set16;
       +
       +        b = va_arg(fmt->args, mpint*);
       +        if(b == nil)
       +                return fmtstrcpy(fmt, "*");
       +
       +        set16 = upper16;
       +        if(fmt->flags & FmtLong)
       +                set16 = lower16;
       +        p = _mptoa(b, fmt->prec, nil, 0, set16);
       +        fmt->flags &= ~FmtPrec;
       +
       +        if(p == nil)
       +                return fmtstrcpy(fmt, "*");
       +        else{
       +                fmtstrcpy(fmt, p);
       +                free(p);
       +                return 0;
       +        }
       +}
       +