static int PkguaEqObjCmd( ClientData dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { int result; const char *str1, *str2; int len1, len2; if (objc != 3) { Tcl_WrongNumArgs(interp, 1, objv, "string1 string2"); return TCL_ERROR; } str1 = Tcl_GetStringFromObj(objv[1], &len1); str2 = Tcl_GetStringFromObj(objv[2], &len2); if (len1 == len2) { result = (Tcl_UtfNcmp(str1, str2, len1) == 0); } else { result = 0; } Tcl_SetObjResult(interp, Tcl_NewIntObj(result)); return TCL_OK; }
/* compare a Tcl_DString to a const string. use negative length to find first null in string2 */ int TSP_Util_string_compare_const(Tcl_DString* s1, char* string2, int length2) { char* string1; int length1; int length; int match; string1 = Tcl_DStringValue(s1); length1 = Tcl_DStringLength(s1); length1 = Tcl_NumUtfChars(string1, length1); length2 = Tcl_NumUtfChars(string2, length2); length = (length1 < length2) ? length1 : length2; match = Tcl_UtfNcmp(string1, string2, (unsigned) length); if (match == 0) { match = length1 - length2; } return match; }