diff options
author | dgp <dgp@users.sourceforge.net> | 2005-07-05 18:15:41 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2005-07-05 18:15:41 (GMT) |
commit | 54bafc704cf48ffee9929b86352c127bfc9c024d (patch) | |
tree | 7ee4e1ed918eafe78497e6a04d4a32ed2c90a911 /generic/tclUtil.c | |
parent | 1f35b60c45319b66403716359b926d67f7d9b328 (diff) | |
download | tcl-54bafc704cf48ffee9929b86352c127bfc9c024d.zip tcl-54bafc704cf48ffee9929b86352c127bfc9c024d.tar.gz tcl-54bafc704cf48ffee9929b86352c127bfc9c024d.tar.bz2 |
* generic/tclUtil.c: Converted TclFormatInt() into a macro.
* generic/tclInt.decls: [RFE 1194015]
* generic/tclInt.h:
* generic/tclIntDecls.h: make genstubs
* generic/tclStubInit.c:
Diffstat (limited to 'generic/tclUtil.c')
-rw-r--r-- | generic/tclUtil.c | 87 |
1 files changed, 1 insertions, 86 deletions
diff --git a/generic/tclUtil.c b/generic/tclUtil.c index 2c787c2..248a38d 100644 --- a/generic/tclUtil.c +++ b/generic/tclUtil.c @@ -11,7 +11,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclUtil.c,v 1.60 2005/05/14 20:46:46 das Exp $ + * RCS: @(#) $Id: tclUtil.c,v 1.61 2005/07/05 18:15:59 dgp Exp $ */ #include "tclInt.h" @@ -2196,91 +2196,6 @@ TclNeedSpace(start, end) /* *---------------------------------------------------------------------- * - * TclFormatInt -- - * - * This procedure formats an integer into a sequence of decimal digit - * characters in a buffer. If the integer is negative, a minus sign is - * inserted at the start of the buffer. A null character is inserted at - * the end of the formatted characters. It is the caller's - * responsibility to ensure that enough storage is available. This - * procedure has the effect of sprintf(buffer, "%d", n) but is faster. - * - * Results: - * An integer representing the number of characters formatted, not - * including the terminating \0. - * - * Side effects: - * The formatted characters are written into the storage pointer to - * by the "buffer" argument. - * - *---------------------------------------------------------------------- - */ - -int -TclFormatInt(buffer, n) - char *buffer; /* Points to the storage into which the - * formatted characters are written. */ - long n; /* The integer to format. */ -{ - long intVal; - int i; - int numFormatted, j; - char *digits = "0123456789"; - - /* - * Check first whether "n" is zero. - */ - - if (n == 0) { - buffer[0] = '0'; - buffer[1] = 0; - return 1; - } - - /* - * Check whether "n" is the maximum negative value. This is - * -2^(m-1) for an m-bit word, and has no positive equivalent; - * negating it produces the same value. - */ - - if (n == -n) { - sprintf(buffer, "%ld", n); - return strlen(buffer); - } - - /* - * Generate the characters of the result backwards in the buffer. - */ - - intVal = (n < 0? -n : n); - i = 0; - buffer[0] = '\0'; - do { - i++; - buffer[i] = digits[intVal % 10]; - intVal = intVal/10; - } while (intVal > 0); - if (n < 0) { - i++; - buffer[i] = '-'; - } - numFormatted = i; - - /* - * Now reverse the characters. - */ - - for (j = 0; j < i; j++, i--) { - char tmp = buffer[i]; - buffer[i] = buffer[j]; - buffer[j] = tmp; - } - return numFormatted; -} - -/* - *---------------------------------------------------------------------- - * * TclLooksLikeInt -- * * This procedure decides whether the leading characters of a |