Changeset 860 for trunk/dll/commafmt.c
- Timestamp:
- Nov 10, 2007, 11:58:43 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dll/commafmt.c
r859 r860 13 13 25 May 05 SHL Add CommaFmtULL, CommaFmtUL 14 14 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat 15 05 Nov 07 GKY Use commafmtULL to display file sizes for large file support 16 10 Nov 07 GKY Get thousands separator from country info for file sizes. 15 17 16 18 ***********************************************************************/ 17 19 18 20 /* 19 ** COMMAFMT.C 20 ** Public domain by Bob Stout 21 ** 22 ** Notes: 1. Use static buffer to eliminate error checks on buffer overflow 23 ** and reduce code size. 24 ** 2. By making the numeric argument a long and prototyping it before 25 ** use, passed numeric arguments will be implicitly cast to longs 26 ** thereby avoiding int overflow. 27 ** 3. Use the thousands grouping and thousands separator from the 28 ** ANSI locale to make this more robust. 21 * COMMAFMT.C 22 * Adapted from public domain code by Bob Stout 23 * 24 * 2. By making the numeric argument a long and prototyping it before 25 * use, passed numeric arguments will be implicitly cast to longs 26 * thereby avoiding int overflow. 27 * 3. Use the thousands grouping and thousands separator from the 28 * ANSI locale to make this more robust. 29 29 */ 30 30 31 #define INCL_WIN 31 32 #define INCL_LONGLONG 32 33 #include <os2.h> … … 35 36 #include <stdio.h> 36 37 #include <string.h> 38 #include "fm3dll.h" 37 39 38 40 size_t commafmt(char *pszBuf, // Output buffer … … 57 59 58 60 for (; cChars <= cBufSize; ++cChars, ++cDigits) { 59 *pch-- = (CHAR) 61 *pch-- = (CHAR)(lNumber % 10 + '0'); 60 62 lNumber /= 10; 61 63 if (!lNumber) 62 64 break; 63 65 if (cDigits % 3 == 0) { 64 *pch-- = ',';66 *pch-- = *ThousandsSeparator; 65 67 ++cChars; 66 68 } … … 85 87 } 86 88 87 //=== CommaFmtULL: format long long number with commas and SI unit suffix === 89 /** 90 * Format long long number with commas and SI unit suffix 91 * @param pszBuf Points to output buffer 92 * @param cBufSize Buffer size including space for terminating nul 93 * @param ullNumber Number to convert 94 * @param chPreferred Preferred suffix, blank, K, M 95 * @return size of formatting string excluding terminating nul 96 */ 88 97 89 98 size_t CommaFmtULL(char *pszBuf, // Output buffer … … 109 118 } 110 119 111 c = commafmt(pszBuf, cBufSize, (LONG) 120 c = commafmt(pszBuf, cBufSize, (LONG)ullNumber); 112 121 113 122 if (chSuffix != ' ') {
Note:
See TracChangeset
for help on using the changeset viewer.