Changeset 98 for trunk/dll


Ignore:
Timestamp:
May 21, 2004, 5:22:09 PM (21 years ago)
Author:
root
Message:

Drop hundfmt, clean commafmt

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/commafmt.c

    r2 r98  
     1
     2/***********************************************************************
     3
     4  $Id$
     5
     6  Command formatting tools
     7
     8  Copyright (c) 1993-98 M. Kimes
     9  Copyright (c) 2004 Steven H.Levine
     10
     11  Revisions     06 Jan 04 SHL - Drop hundfmt, clean commafmt
     12
     13***********************************************************************/
     14
    115/*
    216**  COMMAFMT.C
    3 **
    417**  Public domain by Bob Stout
    518**
     
    2033
    2134size_t commafmt(char   *buf,            /* Buffer for formatted string  */
    22                 int     bufsize,        /* Size of buffer               */
    23                 long    N)              /* Number to convert            */
     35                int     bufsize,        /* Size of buffer               */
     36                long    N)              /* Number to convert            */
    2437{
    25         int len = 1, posn = 1, sign = 1;
    26         char *ptr = buf + bufsize - 1;
     38        int len = 1;
     39        int posn = 1;
     40        int sign = 1;
    2741
    28         if (2 > bufsize)
    29         {
     42        char *ptr = buf + bufsize - 1;
     43
     44        if (bufsize < 2)
     45        {
    3046ABORT:          *buf = 0;
    31                 return 0;
    32         }
     47                return 0;
     48        }
    3349
    34         *ptr-- = 0;
    35         --bufsize;
    36         if (0L > N)
    37         {
    38                 sign = -1;
    39                 N = -N;
    40         }
     50        *ptr-- = 0;
     51        --bufsize;
     52        if (N < 0)
     53        {
     54                sign = -1;
     55                N = -N;
     56        }
    4157
    42         for ( ; len <= bufsize; ++len, ++posn)
    43         {
    44                 *ptr-- = (char)((N % 10L) + '0');
    45                 if (0L == (N /= 10L))
    46                         break;
    47                 if (0 == (posn % 3))
    48                 {
    49                         *ptr-- = ',';
    50                         ++len;
    51                 }
    52                 if (len >= bufsize)
    53                         goto ABORT;
    54         }
     58        for ( ; len <= bufsize; ++len, ++posn)
     59        {
     60                *ptr-- = (char)((N % 10L) + '0');
     61                N /= 10;
     62                if (!N)
     63                        break;
     64                if (posn % 3 == 0)
     65                {
     66                        *ptr-- = ',';
     67                        ++len;
     68                }
     69                if (len >= bufsize)
     70                        goto ABORT;
     71        }
    5572
    56         if (0 > sign)
    57         {
    58                 if (0 == bufsize)
    59                         goto ABORT;
    60                 *ptr-- = '-';
    61                 ++len;
    62         }
     73        if (sign < 0)
     74        {
     75                if (bufsize == 0)
     76                        goto ABORT;
     77                *ptr-- = '-';
     78                ++len;
     79        }
    6380
    64         strcpy(buf, ++ptr);
    65         return (size_t)len;
     81        strcpy(buf, ++ptr);             // Left align
     82        return len;
    6683}
    6784
     85
     86#if 0 // fixme
    6887
    6988size_t hundfmt (char *buf,int bufsize,unsigned long N) {
     
    91110  return p - buf;
    92111}
     112
     113#endif 0 // fixme
Note: See TracChangeset for help on using the changeset viewer.