summaryrefslogtreecommitdiffstats
path: root/generic/tclStringObj.c
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2007-11-18 22:30:10 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2007-11-18 22:30:10 (GMT)
commit238ad5bc9e7a3a174084646bd915e2392030cfdd (patch)
treea168b4a14a7f4bf466ffa4d2ea1903339cbd0221 /generic/tclStringObj.c
parent2b41844782e22787bbd8b88ba36bf09ee9f09be0 (diff)
downloadtcl-238ad5bc9e7a3a174084646bd915e2392030cfdd.zip
tcl-238ad5bc9e7a3a174084646bd915e2392030cfdd.tar.gz
tcl-238ad5bc9e7a3a174084646bd915e2392030cfdd.tar.bz2
More minor cleanup
Diffstat (limited to 'generic/tclStringObj.c')
-rw-r--r--generic/tclStringObj.c143
1 files changed, 69 insertions, 74 deletions
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c
index bdfe6f2..c21c22b 100644
--- a/generic/tclStringObj.c
+++ b/generic/tclStringObj.c
@@ -33,7 +33,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclStringObj.c,v 1.66 2007/11/11 19:32:17 msofer Exp $ */
+ * RCS: @(#) $Id: tclStringObj.c,v 1.67 2007/11/18 22:30:10 dkf Exp $ */
#include "tclInt.h"
#include "tommath.h"
@@ -43,16 +43,16 @@
*/
static void AppendUnicodeToUnicodeRep(Tcl_Obj *objPtr,
- CONST Tcl_UniChar *unicode, int appendNumChars);
+ const Tcl_UniChar *unicode, int appendNumChars);
static void AppendUnicodeToUtfRep(Tcl_Obj *objPtr,
- CONST Tcl_UniChar *unicode, int numChars);
+ const Tcl_UniChar *unicode, int numChars);
static void AppendUtfToUnicodeRep(Tcl_Obj *objPtr,
- CONST char *bytes, int numBytes);
+ const char *bytes, int numBytes);
static void AppendUtfToUtfRep(Tcl_Obj *objPtr,
- CONST char *bytes, int numBytes);
+ const char *bytes, int numBytes);
static void FillUnicodeRep(Tcl_Obj *objPtr);
static void AppendPrintfToObjVA(Tcl_Obj *objPtr,
- CONST char *format, va_list argList);
+ const char *format, va_list argList);
static void FreeStringInternalRep(Tcl_Obj *objPtr);
static void DupStringInternalRep(Tcl_Obj *objPtr,
Tcl_Obj *copyPtr);
@@ -183,7 +183,7 @@ typedef struct String {
#undef Tcl_NewStringObj
Tcl_Obj *
Tcl_NewStringObj(
- CONST char *bytes, /* Points to the first of the length bytes
+ const char *bytes, /* Points to the first of the length bytes
* used to initialize the new object. */
int length) /* The number of bytes to copy from "bytes"
* when initializing the new object. If
@@ -195,7 +195,7 @@ Tcl_NewStringObj(
#else /* if not TCL_MEM_DEBUG */
Tcl_Obj *
Tcl_NewStringObj(
- CONST char *bytes, /* Points to the first of the length bytes
+ const char *bytes, /* Points to the first of the length bytes
* used to initialize the new object. */
int length) /* The number of bytes to copy from "bytes"
* when initializing the new object. If
@@ -244,13 +244,13 @@ Tcl_NewStringObj(
#ifdef TCL_MEM_DEBUG
Tcl_Obj *
Tcl_DbNewStringObj(
- CONST char *bytes, /* Points to the first of the length bytes
+ const char *bytes, /* Points to the first of the length bytes
* used to initialize the new object. */
int length, /* The number of bytes to copy from "bytes"
* when initializing the new object. If
* negative, use bytes up to the first NUL
* byte. */
- CONST char *file, /* The name of the source file calling this
+ const char *file, /* The name of the source file calling this
* function; used for debugging. */
int line) /* Line number in the source file; used for
* debugging. */
@@ -267,13 +267,13 @@ Tcl_DbNewStringObj(
#else /* if not TCL_MEM_DEBUG */
Tcl_Obj *
Tcl_DbNewStringObj(
- CONST char *bytes, /* Points to the first of the length bytes
+ const char *bytes, /* Points to the first of the length bytes
* used to initialize the new object. */
register int length, /* The number of bytes to copy from "bytes"
* when initializing the new object. If
* negative, use bytes up to the first NUL
* byte. */
- CONST char *file, /* The name of the source file calling this
+ const char *file, /* The name of the source file calling this
* function; used for debugging. */
int line) /* Line number in the source file; used for
* debugging. */
@@ -303,7 +303,7 @@ Tcl_DbNewStringObj(
Tcl_Obj *
Tcl_NewUnicodeObj(
- CONST Tcl_UniChar *unicode, /* The unicode string used to initialize the
+ const Tcl_UniChar *unicode, /* The unicode string used to initialize the
* new object. */
int numChars) /* Number of characters in the unicode
* string. */
@@ -335,7 +335,7 @@ Tcl_NewUnicodeObj(
stringPtr->uallocated = uallocated;
stringPtr->hasUnicode = (numChars > 0);
stringPtr->allocated = 0;
- memcpy((void *) stringPtr->unicode, (void *) unicode, uallocated);
+ memcpy(stringPtr->unicode, unicode, uallocated);
stringPtr->unicode[numChars] = 0;
SET_STRING(objPtr, stringPtr);
return objPtr;
@@ -686,7 +686,7 @@ Tcl_GetRange(
void
Tcl_SetStringObj(
register Tcl_Obj *objPtr, /* Object whose internal rep to init. */
- CONST char *bytes, /* Points to the first of the length bytes
+ const char *bytes, /* Points to the first of the length bytes
* used to initialize the object. */
register int length) /* The number of bytes to copy from "bytes"
* when initializing the object. If negative,
@@ -761,23 +761,22 @@ Tcl_SetObjLength(
if (length > (int) stringPtr->allocated &&
(objPtr->bytes != NULL || stringPtr->hasUnicode == 0)) {
-
/*
* Not enough space in current string. Reallocate the string space and
* free the old string.
*/
if (objPtr->bytes != tclEmptyStringRep) {
- objPtr->bytes = ckrealloc((char *)objPtr->bytes,
- (unsigned)(length+1));
+ objPtr->bytes = ckrealloc((char *) objPtr->bytes,
+ (unsigned) (length + 1));
} else {
- char *new = ckalloc((unsigned) (length+1));
+ char *newBytes = ckalloc((unsigned) (length+1));
+
if (objPtr->bytes != NULL && objPtr->length != 0) {
- memcpy((void *) new, (void *) objPtr->bytes,
- (size_t) objPtr->length);
+ memcpy(newBytes, objPtr->bytes, (size_t) objPtr->length);
Tcl_InvalidateStringRep(objPtr);
}
- objPtr->bytes = new;
+ objPtr->bytes = newBytes;
}
stringPtr->allocated = length;
@@ -876,7 +875,7 @@ Tcl_AttemptSetObjLength(
if (length > (int) stringPtr->allocated &&
(objPtr->bytes != NULL || stringPtr->hasUnicode == 0)) {
- char *new;
+ char *newBytes;
/*
* Not enough space in current string. Reallocate the string space and
@@ -884,22 +883,22 @@ Tcl_AttemptSetObjLength(
*/
if (objPtr->bytes != tclEmptyStringRep) {
- new = attemptckrealloc(objPtr->bytes, (unsigned)(length+1));
- if (new == NULL) {
+ newBytes = attemptckrealloc(objPtr->bytes,
+ (unsigned)(length + 1));
+ if (newBytes == NULL) {
return 0;
}
} else {
- new = attemptckalloc((unsigned) (length+1));
- if (new == NULL) {
+ newBytes = attemptckalloc((unsigned) (length + 1));
+ if (newBytes == NULL) {
return 0;
}
if (objPtr->bytes != NULL && objPtr->length != 0) {
- memcpy((void *) new, (void *) objPtr->bytes,
- (size_t) objPtr->length);
+ memcpy(newBytes, objPtr->bytes, (size_t) objPtr->length);
Tcl_InvalidateStringRep(objPtr);
}
}
- objPtr->bytes = new;
+ objPtr->bytes = newBytes;
stringPtr->allocated = length;
/*
@@ -974,7 +973,7 @@ Tcl_AttemptSetObjLength(
void
Tcl_SetUnicodeObj(
Tcl_Obj *objPtr, /* The object to set the string of. */
- CONST Tcl_UniChar *unicode, /* The unicode string used to initialize the
+ const Tcl_UniChar *unicode, /* The unicode string used to initialize the
* object. */
int numChars) /* Number of characters in the unicode
* string. */
@@ -1008,7 +1007,7 @@ Tcl_SetUnicodeObj(
stringPtr->uallocated = uallocated;
stringPtr->hasUnicode = (numChars > 0);
stringPtr->allocated = 0;
- memcpy((void *) stringPtr->unicode, (void *) unicode, uallocated);
+ memcpy(stringPtr->unicode, unicode, uallocated);
stringPtr->unicode[numChars] = 0;
SET_STRING(objPtr, stringPtr);
@@ -1037,14 +1036,14 @@ Tcl_SetUnicodeObj(
void
Tcl_AppendLimitedToObj(
register Tcl_Obj *objPtr, /* Points to the object to append to. */
- CONST char *bytes, /* Points to the bytes to append to the
+ const char *bytes, /* Points to the bytes to append to the
* object. */
register int length, /* The number of bytes available to be
* appended from "bytes". If < 0, then all
* bytes up to a NUL byte are available. */
register int limit, /* The maximum number of bytes to append to
* the object. */
- CONST char *ellipsis) /* Ellipsis marker string, appended to the
+ const char *ellipsis) /* Ellipsis marker string, appended to the
* object to indicate not all available bytes
* at "bytes" were appended. */
{
@@ -1118,7 +1117,7 @@ Tcl_AppendLimitedToObj(
void
Tcl_AppendToObj(
register Tcl_Obj *objPtr, /* Points to the object to append to. */
- CONST char *bytes, /* Points to the bytes to append to the
+ const char *bytes, /* Points to the bytes to append to the
* object. */
register int length) /* The number of bytes to append from "bytes".
* If < 0, then append all bytes up to NUL
@@ -1147,7 +1146,7 @@ Tcl_AppendToObj(
void
Tcl_AppendUnicodeToObj(
register Tcl_Obj *objPtr, /* Points to the object to append to. */
- CONST Tcl_UniChar *unicode, /* The unicode string to append to the
+ const Tcl_UniChar *unicode, /* The unicode string to append to the
* object. */
int length) /* Number of chars in "unicode". */
{
@@ -1283,7 +1282,7 @@ Tcl_AppendObjToObj(
static void
AppendUnicodeToUnicodeRep(
Tcl_Obj *objPtr, /* Points to the object to append to. */
- CONST Tcl_UniChar *unicode, /* String to append. */
+ const Tcl_UniChar *unicode, /* String to append. */
int appendNumChars) /* Number of chars of "unicode" to append. */
{
String *stringPtr, *tmpString;
@@ -1334,7 +1333,7 @@ AppendUnicodeToUnicodeRep(
* trailing null.
*/
- memcpy((void*) (stringPtr->unicode + stringPtr->numChars), unicode,
+ memcpy(stringPtr->unicode + stringPtr->numChars, unicode,
appendNumChars * sizeof(Tcl_UniChar));
stringPtr->unicode[numChars] = 0;
stringPtr->numChars = numChars;
@@ -1362,11 +1361,11 @@ AppendUnicodeToUnicodeRep(
static void
AppendUnicodeToUtfRep(
Tcl_Obj *objPtr, /* Points to the object to append to. */
- CONST Tcl_UniChar *unicode, /* String to convert to UTF. */
+ const Tcl_UniChar *unicode, /* String to convert to UTF. */
int numChars) /* Number of chars of "unicode" to convert. */
{
Tcl_DString dsPtr;
- CONST char *bytes;
+ const char *bytes;
if (numChars < 0) {
numChars = 0;
@@ -1407,7 +1406,7 @@ AppendUnicodeToUtfRep(
static void
AppendUtfToUnicodeRep(
Tcl_Obj *objPtr, /* Points to the object to append to. */
- CONST char *bytes, /* String to convert to Unicode. */
+ const char *bytes, /* String to convert to Unicode. */
int numBytes) /* Number of bytes of "bytes" to convert. */
{
Tcl_DString dsPtr;
@@ -1448,7 +1447,7 @@ AppendUtfToUnicodeRep(
static void
AppendUtfToUtfRep(
Tcl_Obj *objPtr, /* Points to the object to append to. */
- CONST char *bytes, /* String to append. */
+ const char *bytes, /* String to append. */
int numBytes) /* Number of bytes of "bytes" to append. */
{
String *stringPtr;
@@ -1492,8 +1491,7 @@ AppendUtfToUtfRep(
stringPtr->numChars = -1;
stringPtr->hasUnicode = 0;
- memcpy((void *) (objPtr->bytes + oldLength), (void *) bytes,
- (size_t) numBytes);
+ memcpy(objPtr->bytes + oldLength, bytes, (size_t) numBytes);
objPtr->bytes[newLength] = 0;
objPtr->length = newLength;
}
@@ -1636,7 +1634,7 @@ Tcl_AppendStringsToObjVA(
*/
if (args != static_list) {
- ckfree((void *)args);
+ ckfree((void *) args);
}
#undef STATIC_LIST_SIZE
}
@@ -1695,19 +1693,16 @@ int
Tcl_AppendFormatToObj(
Tcl_Interp *interp,
Tcl_Obj *appendObj,
- CONST char *format,
+ const char *format,
int objc,
- Tcl_Obj *CONST objv[])
+ Tcl_Obj *const objv[])
{
- CONST char *span = format;
- int numBytes = 0;
- int objIndex = 0;
- int gotXpg = 0, gotSequential = 0;
+ const char *span = format, *msg;
+ int numBytes = 0, objIndex = 0, gotXpg = 0, gotSequential = 0;
int originalLength;
- CONST char *msg;
- CONST char *mixedXPG =
+ static const char *mixedXPG =
"cannot mix \"%\" and \"%n$\" conversion specifiers";
- CONST char *badIndex[2] = {
+ static const char *badIndex[2] = {
"not enough arguments for all format specifiers",
"\"%n$\" argument index out of range"
};
@@ -1930,6 +1925,7 @@ Tcl_AppendFormatToObj(
case 'c': {
char buf[TCL_UTF_MAX];
int code, length;
+
if (TclGetIntFromObj(interp, segment, &code) != TCL_OK) {
goto error;
}
@@ -2028,7 +2024,7 @@ Tcl_AppendFormatToObj(
case 'd': {
int length;
Tcl_Obj *pure;
- CONST char *bytes;
+ const char *bytes;
if (useShort) {
pure = Tcl_NewIntObj((int)(s));
@@ -2143,8 +2139,9 @@ Tcl_AppendFormatToObj(
int digitOffset;
if (useBig) {
- if ((size_t)shift<CHAR_BIT*sizeof(Tcl_WideUInt)-DIGIT_BIT) {
- bits |= (((Tcl_WideUInt)big.dp[index++]) << shift);
+ if ((size_t) shift <
+ CHAR_BIT*sizeof(Tcl_WideUInt) - DIGIT_BIT) {
+ bits |= (((Tcl_WideUInt)big.dp[index++]) <<shift);
shift += DIGIT_BIT;
}
shift -= numBits;
@@ -2303,9 +2300,9 @@ Tcl_AppendFormatToObj(
Tcl_Obj *
Tcl_Format(
Tcl_Interp *interp,
- CONST char *format,
+ const char *format,
int objc,
- Tcl_Obj *CONST objv[])
+ Tcl_Obj *const objv[])
{
int result;
Tcl_Obj *objPtr = Tcl_NewObj();
@@ -2332,12 +2329,12 @@ Tcl_Format(
static void
AppendPrintfToObjVA(
Tcl_Obj *objPtr,
- CONST char *format,
+ const char *format,
va_list argList)
{
int code, objc;
Tcl_Obj **objv, *list = Tcl_NewObj();
- CONST char *p;
+ const char *p;
char *end;
p = format;
@@ -2360,13 +2357,13 @@ AppendPrintfToObjVA(
seekingConversion = 0;
break;
case 's': {
- CONST char *q, *end, *bytes = va_arg(argList, char *);
+ const char *q, *end, *bytes = va_arg(argList, char *);
seekingConversion = 0;
/*
- * The buffer to copy characters from starts at bytes
- * and ends at either the first NUL byte, or after
- * lastNum bytes, when caller has indicated a limit.
+ * The buffer to copy characters from starts at bytes and ends
+ * at either the first NUL byte, or after lastNum bytes, when
+ * caller has indicated a limit.
*/
end = bytes;
@@ -2375,9 +2372,9 @@ AppendPrintfToObjVA(
}
/*
- * Within that buffer, we trim both ends if needed so that
- * we copy only whole characters, and avoid copying any
- * partial multi-byte characters.
+ * Within that buffer, we trim both ends if needed so that we
+ * copy only whole characters, and avoid copying any partial
+ * multi-byte characters.
*/
q = Tcl_UtfPrev(end, bytes);
@@ -2478,7 +2475,7 @@ AppendPrintfToObjVA(
void
Tcl_AppendPrintfToObj(
Tcl_Obj *objPtr,
- CONST char *format,
+ const char *format,
...)
{
va_list argList;
@@ -2504,7 +2501,7 @@ Tcl_AppendPrintfToObj(
Tcl_Obj *
Tcl_ObjPrintf(
- CONST char *format,
+ const char *format,
...)
{
va_list argList;
@@ -2622,9 +2619,8 @@ FillUnicodeRep(
{
String *stringPtr;
size_t uallocated;
- char *src, *srcEnd;
+ char *srcEnd, *src = objPtr->bytes;
Tcl_UniChar *dst;
- src = objPtr->bytes;
stringPtr = GET_STRING(objPtr);
if (stringPtr->numChars == -1) {
@@ -2709,8 +2705,7 @@ DupStringInternalRep(
STRING_SIZE(srcStringPtr->uallocated));
copyStringPtr->uallocated = srcStringPtr->uallocated;
- memcpy((void *) copyStringPtr->unicode,
- (void *) srcStringPtr->unicode,
+ memcpy(copyStringPtr->unicode, srcStringPtr->unicode,
(size_t) srcStringPtr->numChars * sizeof(Tcl_UniChar));
copyStringPtr->unicode[srcStringPtr->numChars] = 0;
}