diff options
Diffstat (limited to 'generic/tclScan.c')
-rw-r--r-- | generic/tclScan.c | 57 |
1 files changed, 31 insertions, 26 deletions
diff --git a/generic/tclScan.c b/generic/tclScan.c index d83c8c9..0051415 100644 --- a/generic/tclScan.c +++ b/generic/tclScan.c @@ -43,10 +43,10 @@ typedef struct CharSet { * Declarations for functions used only in this file. */ -static char * BuildCharSet(CharSet *cset, char *format); +static const char * BuildCharSet(CharSet *cset, const char *format); static int CharInSet(CharSet *cset, int ch); static void ReleaseCharSet(CharSet *cset); -static int ValidateFormat(Tcl_Interp *interp, char *format, +static int ValidateFormat(Tcl_Interp *interp, const char *format, int numVars, int *totalVars); /* @@ -67,14 +67,14 @@ static int ValidateFormat(Tcl_Interp *interp, char *format, *---------------------------------------------------------------------- */ -static char * +static const char * BuildCharSet( CharSet *cset, - char *format) /* Points to first char of set. */ + const char *format) /* Points to first char of set. */ { Tcl_UniChar ch, start; int offset, nranges; - char *end; + const char *end; memset(cset, 0, sizeof(CharSet)); @@ -250,7 +250,7 @@ ReleaseCharSet( static int ValidateFormat( Tcl_Interp *interp, /* Current interpreter. */ - char *format, /* The format string. */ + const char *format, /* The format string. */ int numVars, /* The number of variables passed to the scan * command. */ int *totalSubs) /* The number of variables that will be @@ -260,7 +260,7 @@ ValidateFormat( char *end; Tcl_UniChar ch; int objIndex, xpgSize, nspace = numVars; - int *nassign = (int *) TclStackAlloc(interp, nspace * sizeof(int)); + int *nassign = TclStackAlloc(interp, nspace * sizeof(int)); char buf[TCL_UTF_MAX+1]; /* @@ -341,7 +341,7 @@ ValidateFormat( */ if ((ch < 0x80) && isdigit(UCHAR(ch))) { /* INTL: "C" locale. */ - value = strtoul(format-1, &format, 10); /* INTL: "C" locale. */ + value = strtoul(format-1, (char **) &format, 10); /* INTL: "C" locale. */ flags |= SCAN_WIDTH; format += Tcl_UtfToUniChar(format, &ch); } @@ -403,6 +403,7 @@ ValidateFormat( case 'i': case 'o': case 'x': + case 'b': break; case 'u': if (flags & SCAN_BIG) { @@ -446,14 +447,10 @@ ValidateFormat( TCL_STATIC); goto error; default: - { - char buf[TCL_UTF_MAX+1]; - - buf[Tcl_UniCharToUtf(ch, buf)] = '\0'; - Tcl_AppendResult(interp, "bad scan conversion character \"", - buf, "\"", NULL); - goto error; - } + buf[Tcl_UniCharToUtf(ch, buf)] = '\0'; + Tcl_AppendResult(interp, "bad scan conversion character \"", buf, + "\"", NULL); + goto error; } if (!(flags & SCAN_SUPPRESS)) { if (objIndex >= nspace) { @@ -469,7 +466,7 @@ ValidateFormat( } else { nspace += 16; /* formerly STATIC_LIST_SIZE */ } - nassign = (int *) TclStackRealloc(interp, nassign, + nassign = TclStackRealloc(interp, nassign, nspace * sizeof(int)); for (i = value; i < nspace; i++) { nassign[i] = 0; @@ -551,16 +548,16 @@ ValidateFormat( /* ARGSUSED */ int Tcl_ScanObjCmd( - ClientData dummy, /* Not used. */ + ClientData dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ - Tcl_Obj *CONST objv[]) /* Argument objects. */ + Tcl_Obj *const objv[]) /* Argument objects. */ { - char *format; + const char *format; int numVars, nconversions, totalVars = -1; int objIndex, offset, i, result, code; long value; - CONST char *string, *end, *baseString; + const char *string, *end, *baseString; char op = 0; int width, underflow = 0; Tcl_WideInt wideValue; @@ -573,7 +570,7 @@ Tcl_ScanObjCmd( if (objc < 3) { Tcl_WrongNumArgs(interp, 1, objv, - "string format ?varName varName ...?"); + "string format ?varName ...?"); return TCL_ERROR; } @@ -593,7 +590,7 @@ Tcl_ScanObjCmd( */ if (totalVars > 0) { - objs = (Tcl_Obj **) ckalloc(sizeof(Tcl_Obj*) * totalVars); + objs = (Tcl_Obj **) ckalloc(sizeof(Tcl_Obj *) * totalVars); for (i = 0; i < totalVars; i++) { objs[i] = NULL; } @@ -673,7 +670,7 @@ Tcl_ScanObjCmd( */ if ((ch < 0x80) && isdigit(UCHAR(ch))) { /* INTL: "C" locale. */ - width = (int) strtoul(format-1, &format, 10);/* INTL: "C" locale. */ + width = (int) strtoul(format-1, (char **) &format, 10);/* INTL: "C" locale. */ format += Tcl_UtfToUniChar(format, &ch); } else { width = 0; @@ -709,6 +706,7 @@ Tcl_ScanObjCmd( if (!(flags & SCAN_SUPPRESS)) { objPtr = Tcl_NewIntObj(string - baseString); Tcl_IncrRefCount(objPtr); + CLANG_ASSERT(objs); objs[objIndex++] = objPtr; } nconversions++; @@ -730,6 +728,10 @@ Tcl_ScanObjCmd( op = 'i'; parseFlag |= TCL_PARSE_HEXADECIMAL_ONLY; break; + case 'b': + op = 'i'; + parseFlag |= TCL_PARSE_BINARY_ONLY; + break; case 'u': op = 'i'; parseFlag |= TCL_PARSE_DECIMAL_ONLY; @@ -812,6 +814,7 @@ Tcl_ScanObjCmd( if (!(flags & SCAN_SUPPRESS)) { objPtr = Tcl_NewStringObj(string, end-string); Tcl_IncrRefCount(objPtr); + CLANG_ASSERT(objs); objs[objIndex++] = objPtr; } string = end; @@ -862,6 +865,7 @@ Tcl_ScanObjCmd( if (!(flags & SCAN_SUPPRESS)) { objPtr = Tcl_NewIntObj((int)sch); Tcl_IncrRefCount(objPtr); + CLANG_ASSERT(objs); objs[objIndex++] = objPtr; } break; @@ -966,6 +970,7 @@ Tcl_ScanObjCmd( } } Tcl_SetDoubleObj(objPtr, dvalue); + CLANG_ASSERT(objs); objs[objIndex++] = objPtr; string = end; } @@ -1015,7 +1020,7 @@ Tcl_ScanObjCmd( } } if (objs != NULL) { - ckfree((char*) objs); + ckfree((char *) objs); } if (code == TCL_OK) { if (underflow && (nconversions == 0)) { @@ -1035,7 +1040,7 @@ Tcl_ScanObjCmd( } return code; } - + /* * Local Variables: * mode: c |