diff options
Diffstat (limited to 'generic/tclScan.c')
| -rw-r--r-- | generic/tclScan.c | 91 |
1 files changed, 39 insertions, 52 deletions
diff --git a/generic/tclScan.c b/generic/tclScan.c index d21bfaf..229f3fa 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 const char * BuildCharSet(CharSet *cset, const char *format); +static char * BuildCharSet(CharSet *cset, char *format); static int CharInSet(CharSet *cset, int ch); static void ReleaseCharSet(CharSet *cset); -static int ValidateFormat(Tcl_Interp *interp, const char *format, +static int ValidateFormat(Tcl_Interp *interp, char *format, int numVars, int *totalVars); /* @@ -67,14 +67,14 @@ static int ValidateFormat(Tcl_Interp *interp, const char *format, *---------------------------------------------------------------------- */ -static const char * +static char * BuildCharSet( CharSet *cset, - const char *format) /* Points to first char of set. */ + char *format) /* Points to first char of set. */ { Tcl_UniChar ch, start; int offset, nranges; - const char *end; + char *end; memset(cset, 0, sizeof(CharSet)); @@ -101,9 +101,10 @@ BuildCharSet( end += Tcl_UtfToUniChar(end, &ch); } - cset->chars = ckalloc(sizeof(Tcl_UniChar) * (end - format - 1)); + cset->chars = (Tcl_UniChar *) + ckalloc(sizeof(Tcl_UniChar) * (end - format - 1)); if (nranges > 0) { - cset->ranges = ckalloc(sizeof(struct Range) * nranges); + cset->ranges = (struct Range *) ckalloc(sizeof(struct Range)*nranges); } else { cset->ranges = NULL; } @@ -223,9 +224,9 @@ static void ReleaseCharSet( CharSet *cset) { - ckfree(cset->chars); + ckfree((char *)cset->chars); if (cset->ranges) { - ckfree(cset->ranges); + ckfree((char *)cset->ranges); } } @@ -249,7 +250,7 @@ ReleaseCharSet( static int ValidateFormat( Tcl_Interp *interp, /* Current interpreter. */ - const char *format, /* The format string. */ + 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 @@ -259,7 +260,7 @@ ValidateFormat( char *end; Tcl_UniChar ch; int objIndex, xpgSize, nspace = numVars; - int *nassign = TclStackAlloc(interp, nspace * sizeof(int)); + int *nassign = (int *) TclStackAlloc(interp, nspace * sizeof(int)); char buf[TCL_UTF_MAX+1]; /* @@ -331,7 +332,6 @@ ValidateFormat( Tcl_SetResult(interp, "cannot mix \"%\" and \"%n$\" conversion specifiers", TCL_STATIC); - Tcl_SetErrorCode(interp, "TCL", "FORMAT", "MIXEDSPECTYPES", NULL); goto error; } @@ -341,7 +341,7 @@ ValidateFormat( */ if ((ch < 0x80) && isdigit(UCHAR(ch))) { /* INTL: "C" locale. */ - value = strtoul(format-1, (char **) &format, 10); /* INTL: "C" locale. */ + value = strtoul(format-1, &format, 10); /* INTL: "C" locale. */ flags |= SCAN_WIDTH; format += Tcl_UtfToUniChar(format, &ch); } @@ -378,7 +378,6 @@ ValidateFormat( Tcl_SetResult(interp, "field width may not be specified in %c conversion", TCL_STATIC); - Tcl_SetErrorCode(interp, "TCL", "FORMAT", "BADWIDTH", NULL); goto error; } /* @@ -392,7 +391,6 @@ ValidateFormat( Tcl_AppendResult(interp, "field size modifier may not be specified in %", buf, " conversion", NULL); - Tcl_SetErrorCode(interp, "TCL", "FORMAT", "BADSIZE", NULL); goto error; } /* @@ -400,18 +398,19 @@ ValidateFormat( */ case 'd': case 'e': + case 'E': case 'f': case 'g': + case 'G': case 'i': case 'o': case 'x': - case 'b': + case 'X': break; case 'u': if (flags & SCAN_BIG) { Tcl_SetResult(interp, "unsigned bignum scans are invalid", TCL_STATIC); - Tcl_SetErrorCode(interp, "TCL", "FORMAT", "BADUNSIGNED",NULL); goto error; } break; @@ -448,14 +447,16 @@ ValidateFormat( badSet: Tcl_SetResult(interp, "unmatched [ in format string", TCL_STATIC); - Tcl_SetErrorCode(interp, "TCL", "FORMAT", "BRACKET", NULL); goto error; default: - buf[Tcl_UniCharToUtf(ch, buf)] = '\0'; - Tcl_AppendResult(interp, "bad scan conversion character \"", buf, - "\"", NULL); - Tcl_SetErrorCode(interp, "TCL", "FORMAT", "BADTYPE", NULL); - goto error; + { + char buf[TCL_UTF_MAX+1]; + + buf[Tcl_UniCharToUtf(ch, buf)] = '\0'; + Tcl_AppendResult(interp, "bad scan conversion character \"", + buf, "\"", NULL); + goto error; + } } if (!(flags & SCAN_SUPPRESS)) { if (objIndex >= nspace) { @@ -471,7 +472,7 @@ ValidateFormat( } else { nspace += 16; /* formerly STATIC_LIST_SIZE */ } - nassign = TclStackRealloc(interp, nassign, + nassign = (int *) TclStackRealloc(interp, nassign, nspace * sizeof(int)); for (i = value; i < nspace; i++) { nassign[i] = 0; @@ -501,7 +502,6 @@ ValidateFormat( Tcl_SetResult(interp, "variable is assigned by multiple \"%n$\" conversion specifiers", TCL_STATIC); - Tcl_SetErrorCode(interp, "TCL", "FORMAT", "POLYASSIGNED", NULL); goto error; } else if (!xpgSize && (nassign[i] == 0)) { /* @@ -512,7 +512,6 @@ ValidateFormat( Tcl_SetResult(interp, "variable is not assigned by any conversion specifiers", TCL_STATIC); - Tcl_SetErrorCode(interp, "TCL", "FORMAT", "UNASSIGNED", NULL); goto error; } } @@ -524,12 +523,10 @@ ValidateFormat( if (gotXpg) { Tcl_SetResult(interp, "\"%n$\" argument index out of range", TCL_STATIC); - Tcl_SetErrorCode(interp, "TCL", "FORMAT", "INDEXRANGE", NULL); } else { Tcl_SetResult(interp, "different numbers of variable names and field specifiers", TCL_STATIC); - Tcl_SetErrorCode(interp, "TCL", "FORMAT", "FIELDVARMISMATCH", NULL); } error: @@ -557,16 +554,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. */ { - const char *format; + 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; @@ -579,7 +576,7 @@ Tcl_ScanObjCmd( if (objc < 3) { Tcl_WrongNumArgs(interp, 1, objv, - "string format ?varName ...?"); + "string format ?varName varName ...?"); return TCL_ERROR; } @@ -599,7 +596,7 @@ Tcl_ScanObjCmd( */ if (totalVars > 0) { - objs = ckalloc(sizeof(Tcl_Obj *) * totalVars); + objs = (Tcl_Obj **) ckalloc(sizeof(Tcl_Obj*) * totalVars); for (i = 0; i < totalVars; i++) { objs[i] = NULL; } @@ -679,7 +676,7 @@ Tcl_ScanObjCmd( */ if ((ch < 0x80) && isdigit(UCHAR(ch))) { /* INTL: "C" locale. */ - width = (int) strtoul(format-1, (char **) &format, 10);/* INTL: "C" locale. */ + width = (int) strtoul(format-1, &format, 10);/* INTL: "C" locale. */ format += Tcl_UtfToUniChar(format, &ch); } else { width = 0; @@ -715,7 +712,6 @@ Tcl_ScanObjCmd( if (!(flags & SCAN_SUPPRESS)) { objPtr = Tcl_NewIntObj(string - baseString); Tcl_IncrRefCount(objPtr); - CLANG_ASSERT(objs); objs[objIndex++] = objPtr; } nconversions++; @@ -734,13 +730,10 @@ Tcl_ScanObjCmd( parseFlag |= TCL_PARSE_OCTAL_ONLY | TCL_PARSE_SCAN_PREFIXES; break; case 'x': + case 'X': 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; @@ -749,7 +742,9 @@ Tcl_ScanObjCmd( case 'f': case 'e': + case 'E': case 'g': + case 'G': op = 'f'; break; @@ -823,7 +818,6 @@ Tcl_ScanObjCmd( if (!(flags & SCAN_SUPPRESS)) { objPtr = Tcl_NewStringObj(string, end-string); Tcl_IncrRefCount(objPtr); - CLANG_ASSERT(objs); objs[objIndex++] = objPtr; } string = end; @@ -874,7 +868,6 @@ Tcl_ScanObjCmd( if (!(flags & SCAN_SUPPRESS)) { objPtr = Tcl_NewIntObj((int)sch); Tcl_IncrRefCount(objPtr); - CLANG_ASSERT(objs); objs[objIndex++] = objPtr; } break; @@ -979,7 +972,6 @@ Tcl_ScanObjCmd( } } Tcl_SetDoubleObj(objPtr, dvalue); - CLANG_ASSERT(objs); objs[objIndex++] = objPtr; string = end; } @@ -1001,14 +993,9 @@ Tcl_ScanObjCmd( continue; } result++; - - /* - * In case of multiple errors in setting variables, just report - * the first one. - */ - - if (Tcl_ObjSetVar2(interp, objv[i+3], NULL, objs[i], - (code == TCL_OK) ? TCL_LEAVE_ERR_MSG : 0) == NULL) { + if (Tcl_ObjSetVar2(interp, objv[i+3], NULL, objs[i], 0) == NULL) { + Tcl_AppendResult(interp, "couldn't set variable \"", + TclGetString(objv[i+3]), "\"", NULL); code = TCL_ERROR; } Tcl_DecrRefCount(objs[i]); @@ -1034,7 +1021,7 @@ Tcl_ScanObjCmd( } } if (objs != NULL) { - ckfree(objs); + ckfree((char*) objs); } if (code == TCL_OK) { if (underflow && (nconversions == 0)) { |
