diff options
Diffstat (limited to 'generic/tclRegexp.c')
-rw-r--r-- | generic/tclRegexp.c | 62 |
1 files changed, 29 insertions, 33 deletions
diff --git a/generic/tclRegexp.c b/generic/tclRegexp.c index 5bc3aa2..dac6aba 100644 --- a/generic/tclRegexp.c +++ b/generic/tclRegexp.c @@ -53,8 +53,8 @@ * * *** NOTE: this code has been altered slightly for use in Tcl: *** * *** 1. Names have been changed, e.g. from re_comp to *** - * *** TclRegComp, to avoid clashes with other *** - * *** regexp implementations used by applications. *** + * *** TclRegComp, to avoid clashes with other *** + * *** regexp implementations used by applications. *** */ /* @@ -100,7 +100,7 @@ static int SetRegexpFromAny(Tcl_Interp *interp, Tcl_Obj *objPtr); * compiled form of the regular expression. */ -const Tcl_ObjType tclRegexpType = { +Tcl_ObjType tclRegexpType = { "regexp", /* name */ FreeRegexpInternalRep, /* freeIntRepProc */ DupRegexpInternalRep, /* dupIntRepProc */ @@ -173,7 +173,7 @@ Tcl_RegExpExec( * that "^" won't match. */ { int flags, result, numChars; - TclRegexp *regexp = (TclRegexp *) re; + TclRegexp *regexp = (TclRegexp *)re; Tcl_DString ds; const Tcl_UniChar *ustr; @@ -391,8 +391,9 @@ Tcl_RegExpMatch( const char *text, /* Text to search for pattern matches. */ const char *pattern) /* Regular expression to match against text. */ { - Tcl_RegExp re = Tcl_RegExpCompile(interp, pattern); + Tcl_RegExp re; + re = Tcl_RegExpCompile(interp, pattern); if (re == NULL) { return -1; } @@ -435,8 +436,7 @@ Tcl_RegExpExecObj( Tcl_UniChar *udata; int length; int reflags = regexpPtr->flags; -#define TCL_REG_GLOBOK_FLAGS \ - (TCL_REG_ADVANCED | TCL_REG_NOSUB | TCL_REG_NOCASE) +#define TCL_REG_GLOBOK_FLAGS (TCL_REG_ADVANCED | TCL_REG_NOSUB | TCL_REG_NOCASE) /* * Take advantage of the equivalent glob pattern, if one exists. @@ -571,14 +571,14 @@ Tcl_GetRegExpFromObj( { int length; TclRegexp *regexpPtr; - const char *pattern; + char *pattern; /* * This is OK because we only actually interpret this value properly as a * TclRegexp* when the type is tclRegexpType. */ - regexpPtr = objPtr->internalRep.twoPtrValue.ptr1; + regexpPtr = (TclRegexp *) objPtr->internalRep.twoPtrValue.ptr1; if ((objPtr->typePtr != &tclRegexpType) || (regexpPtr->flags != flags)) { pattern = TclGetStringFromObj(objPtr, &length); @@ -601,7 +601,7 @@ Tcl_GetRegExpFromObj( */ TclFreeIntRep(objPtr); - objPtr->internalRep.twoPtrValue.ptr1 = regexpPtr; + objPtr->internalRep.twoPtrValue.ptr1 = (void *) regexpPtr; objPtr->typePtr = &tclRegexpType; } return (Tcl_RegExp) regexpPtr; @@ -654,7 +654,7 @@ TclRegAbout( {0, NULL} }; const struct infoname *inf; - Tcl_Obj *infoObj, *resultObj; + Tcl_Obj *infoObj; /* * The reset here guarantees that the interpreter result is empty and @@ -670,8 +670,7 @@ TclRegAbout( * well and Tcl has other limits that constrain things as well... */ - resultObj = Tcl_NewObj(); - Tcl_ListObjAppendElement(NULL, resultObj, + Tcl_ListObjAppendElement(NULL, Tcl_GetObjResult(interp), Tcl_NewIntObj((int) regexpPtr->re.re_nsub)); /* @@ -685,8 +684,7 @@ TclRegAbout( Tcl_NewStringObj(inf->text, -1)); } } - Tcl_ListObjAppendElement(NULL, resultObj, infoObj); - Tcl_SetObjResult(interp, resultObj); + Tcl_ListObjAppendElement(NULL, Tcl_GetObjResult(interp), infoObj); return 0; } @@ -714,14 +712,14 @@ TclRegError( int status) /* Status code to report. */ { char buf[100]; /* ample in practice */ - char cbuf[TCL_INTEGER_SPACE]; + char cbuf[100]; /* lots in practice */ size_t n; const char *p; Tcl_ResetResult(interp); n = TclReError(status, NULL, buf, sizeof(buf)); p = (n > sizeof(buf)) ? "..." : ""; - Tcl_SetObjResult(interp, Tcl_ObjPrintf("%s%s%s", msg, buf, p)); + Tcl_AppendResult(interp, msg, buf, p, NULL); sprintf(cbuf, "%d", status); (void) TclReError(REG_ITOA, NULL, cbuf, sizeof(cbuf)); @@ -749,7 +747,7 @@ static void FreeRegexpInternalRep( Tcl_Obj *objPtr) /* Regexp object with internal rep to free. */ { - TclRegexp *regexpRepPtr = objPtr->internalRep.twoPtrValue.ptr1; + TclRegexp *regexpRepPtr = (TclRegexp *) objPtr->internalRep.twoPtrValue.ptr1; /* * If this is the last reference to the regexp, free it. @@ -783,7 +781,7 @@ DupRegexpInternalRep( Tcl_Obj *srcPtr, /* Object with internal rep to copy. */ Tcl_Obj *copyPtr) /* Object with internal rep to set. */ { - TclRegexp *regexpPtr = srcPtr->internalRep.twoPtrValue.ptr1; + TclRegexp *regexpPtr = (TclRegexp *) srcPtr->internalRep.twoPtrValue.ptr1; regexpPtr->refCount++; copyPtr->internalRep.twoPtrValue.ptr1 = srcPtr->internalRep.twoPtrValue.ptr1; @@ -905,7 +903,7 @@ CompileRegexp( * This is a new expression, so compile it and add it to the cache. */ - regexpPtr = ckalloc(sizeof(TclRegexp)); + regexpPtr = (TclRegexp *) ckalloc(sizeof(TclRegexp)); regexpPtr->objPtr = NULL; regexpPtr->string = NULL; regexpPtr->details.rm_extend.rm_so = -1; @@ -932,7 +930,7 @@ CompileRegexp( * Clean up and report errors in the interpreter, if possible. */ - ckfree(regexpPtr); + ckfree((char *)regexpPtr); if (interp) { TclRegError(interp, "couldn't compile regular expression pattern: ", status); @@ -946,10 +944,11 @@ CompileRegexp( * Tcl_RegExpExecObj to optionally do a fast match (avoids RE engine). */ - if (TclReToGlob(NULL, string, length, &stringBuf, &exact, - NULL) == TCL_OK) { - regexpPtr->globObjPtr = TclDStringToObj(&stringBuf); + if (TclReToGlob(NULL, string, length, &stringBuf, &exact) == TCL_OK) { + regexpPtr->globObjPtr = Tcl_NewStringObj(Tcl_DStringValue(&stringBuf), + Tcl_DStringLength(&stringBuf)); Tcl_IncrRefCount(regexpPtr->globObjPtr); + Tcl_DStringFree(&stringBuf); } else { regexpPtr->globObjPtr = NULL; } @@ -959,8 +958,8 @@ CompileRegexp( * the entire pattern. */ - regexpPtr->matches = - ckalloc(sizeof(regmatch_t) * (regexpPtr->re.re_nsub + 1)); + regexpPtr->matches = (regmatch_t *) ckalloc( + sizeof(regmatch_t) * (regexpPtr->re.re_nsub + 1)); /* * Initialize the refcount to one initially, since it is in the cache. @@ -975,7 +974,6 @@ CompileRegexp( if (tsdPtr->patterns[NUM_REGEXPS-1] != NULL) { TclRegexp *oldRegexpPtr = tsdPtr->regexps[NUM_REGEXPS-1]; - if (--(oldRegexpPtr->refCount) <= 0) { FreeRegexp(oldRegexpPtr); } @@ -986,8 +984,8 @@ CompileRegexp( tsdPtr->patLengths[i+1] = tsdPtr->patLengths[i]; tsdPtr->regexps[i+1] = tsdPtr->regexps[i]; } - tsdPtr->patterns[0] = ckalloc(length + 1); - memcpy(tsdPtr->patterns[0], string, (unsigned) length + 1); + tsdPtr->patterns[0] = (char *) ckalloc((unsigned) (length+1)); + strcpy(tsdPtr->patterns[0], string); tsdPtr->patLengths[0] = length; tsdPtr->regexps[0] = regexpPtr; @@ -1019,9 +1017,9 @@ FreeRegexp( TclDecrRefCount(regexpPtr->globObjPtr); } if (regexpPtr->matches) { - ckfree(regexpPtr->matches); + ckfree((char *) regexpPtr->matches); } - ckfree(regexpPtr); + ckfree((char *) regexpPtr); } /* @@ -1056,12 +1054,10 @@ FinalizeRegexp( ckfree(tsdPtr->patterns[i]); tsdPtr->patterns[i] = NULL; } - /* * We may find ourselves reinitialized if another finalization routine * invokes regexps. */ - tsdPtr->initialized = 0; } |