diff options
Diffstat (limited to 'generic/tkGet.c')
-rw-r--r-- | generic/tkGet.c | 152 |
1 files changed, 84 insertions, 68 deletions
diff --git a/generic/tkGet.c b/generic/tkGet.c index 65a16ae..f109582 100644 --- a/generic/tkGet.c +++ b/generic/tkGet.c @@ -6,8 +6,8 @@ * functions, like Tk_GetDirection and Tk_GetUid. The more complex * functions like Tk_GetColor are in separate files. * - * Copyright (c) 1991-1994 The Regents of the University of California. - * Copyright (c) 1994-1997 Sun Microsystems, Inc. + * Copyright © 1991-1994 The Regents of the University of California. + * Copyright © 1994-1997 Sun Microsystems, Inc. * * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -28,17 +28,17 @@ typedef struct { } ThreadSpecificData; static Tcl_ThreadDataKey dataKey; -static void FreeUidThreadExitProc(ClientData clientData); +static void FreeUidThreadExitProc(void *clientData); /* * The following tables defines the string values for reliefs, which are * used by Tk_GetAnchorFromObj and Tk_GetJustifyFromObj. */ -static const char *const anchorStrings[] = { +const char *const tkAnchorStrings[] = { "n", "ne", "e", "se", "s", "sw", "w", "nw", "center", NULL }; -static const char *const justifyStrings[] = { +const char *const tkJustifyStrings[] = { "left", "right", "center", NULL }; @@ -71,7 +71,7 @@ Tk_GetAnchorFromObj( { int index, code; - code = Tcl_GetIndexFromObj(interp, objPtr, anchorStrings, "anchor", 0, + code = Tcl_GetIndexFromObj(interp, objPtr, tkAnchorStrings, "anchor", 0, &index); if (code == TCL_OK) { *anchorPtr = (Tk_Anchor) index; @@ -155,7 +155,7 @@ Tk_GetAnchor( Tcl_SetObjResult(interp, Tcl_ObjPrintf( "bad anchor position \"%s\": must be" " n, ne, e, se, s, sw, w, nw, or center", string)); - Tcl_SetErrorCode(interp, "TK", "VALUE", "ANCHOR", NULL); + Tcl_SetErrorCode(interp, "TK", "VALUE", "ANCHOR", (char *)NULL); return TCL_ERROR; } @@ -190,6 +190,7 @@ Tk_NameOfAnchor( case TK_ANCHOR_W: return "w"; case TK_ANCHOR_NW: return "nw"; case TK_ANCHOR_CENTER: return "center"; + case TK_ANCHOR_NULL: return ""; } return "unknown anchor position"; } @@ -242,7 +243,7 @@ Tk_GetJoinStyle( Tcl_SetObjResult(interp, Tcl_ObjPrintf( "bad join style \"%s\": must be bevel, miter, or round", string)); - Tcl_SetErrorCode(interp, "TK", "VALUE", "JOIN", NULL); + Tcl_SetErrorCode(interp, "TK", "VALUE", "JOIN", (char *)NULL); return TCL_ERROR; } @@ -323,7 +324,7 @@ Tk_GetCapStyle( Tcl_SetObjResult(interp, Tcl_ObjPrintf( "bad cap style \"%s\": must be butt, projecting, or round", string)); - Tcl_SetErrorCode(interp, "TK", "VALUE", "CAP", NULL); + Tcl_SetErrorCode(interp, "TK", "VALUE", "CAP", (char *)NULL); return TCL_ERROR; } @@ -385,7 +386,7 @@ Tk_GetJustifyFromObj( { int index, code; - code = Tcl_GetIndexFromObj(interp, objPtr, justifyStrings, + code = Tcl_GetIndexFromObj(interp, objPtr, tkJustifyStrings, "justification", 0, &index); if (code == TCL_OK) { *justifyPtr = (Tk_Justify) index; @@ -441,7 +442,7 @@ Tk_GetJustify( Tcl_SetObjResult(interp, Tcl_ObjPrintf( "bad justification \"%s\": must be left, right, or center", string)); - Tcl_SetErrorCode(interp, "TK", "VALUE", "JUSTIFY", NULL); + Tcl_SetErrorCode(interp, "TK", "VALUE", "JUSTIFY", (char *)NULL); return TCL_ERROR; } @@ -471,7 +472,7 @@ Tk_NameOfJustify( case TK_JUSTIFY_LEFT: return "left"; case TK_JUSTIFY_RIGHT: return "right"; case TK_JUSTIFY_CENTER: return "center"; - default: break; + case TK_JUSTIFY_NULL: return ""; } return "unknown justification style"; } @@ -531,7 +532,7 @@ Tk_GetUid( { int dummy; ThreadSpecificData *tsdPtr = (ThreadSpecificData *) - Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); + Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); Tcl_HashTable *tablePtr = &tsdPtr->uidTable; if (!tsdPtr->initialized) { @@ -572,53 +573,63 @@ Tk_GetScreenMM( const char *string, /* String describing a screen distance. */ double *doublePtr) /* Place to store converted result. */ { - char *end; + const char *rest; double d; - - d = strtod(string, &end); - if (end == string) { - goto error; - } - while ((*end != '\0') && isspace(UCHAR(*end))) { - end++; - } - switch (*end) { - case 0: + Tcl_DString ds; + + if (Tcl_GetDouble(NULL, string, &d) == TCL_OK) { + if (!tkwin) { + if (interp != NULL) { + Tcl_SetObjResult(interp, Tcl_NewStringObj("bad screen", -1)); + Tcl_SetErrorCode(interp, "TK", "VALUE", "SCREEN_DISTANCE", (char *)NULL); + } + return TCL_ERROR; + } d /= WidthOfScreen(Tk_Screen(tkwin)); d *= WidthMMOfScreen(Tk_Screen(tkwin)); - break; + *doublePtr = d; + return TCL_OK; + } + rest = string + strlen(string); + while ((rest > string) && isspace(UCHAR(rest[-1]))) { + --rest; /* skip all spaces at the end */ + } + if (rest > string) { + --rest; /* point to the character just before the last space */ + } + if (rest == string) { + error: + if (interp != NULL) { + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "expected screen distance or \"\" but got \"%.50s\"", string)); + Tcl_SetErrorCode(interp, "TK", "VALUE", "PIXELS", (char *)NULL); + } + return TCL_ERROR; + } + Tcl_DStringInit(&ds); + Tcl_DStringAppend(&ds, string, rest-string); + if (Tcl_GetDouble(NULL, Tcl_DStringValue(&ds), &d) != TCL_OK) { + Tcl_DStringFree(&ds); + goto error; + } + Tcl_DStringFree(&ds); + switch (*rest) { case 'c': d *= 10; - end++; break; case 'i': d *= 25.4; - end++; break; case 'm': - end++; break; case 'p': d *= 25.4/72.0; - end++; break; default: goto error; } - while ((*end != '\0') && isspace(UCHAR(*end))) { - end++; - } - if (*end != 0) { - goto error; - } *doublePtr = d; return TCL_OK; - - error: - Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "bad screen distance \"%s\"", string)); - Tcl_SetErrorCode(interp, "TK", "VALUE", "SCREEN_DISTANCE", NULL); - return TCL_ERROR; } /* @@ -692,61 +703,66 @@ TkGetDoublePixels( const char *string, /* String describing a number of pixels. */ double *doublePtr) /* Place to store converted result. */ { - char *end; + const char *rest; double d; + Tcl_DString ds; + if (Tcl_GetDouble(NULL, string, &d) == TCL_OK) { + *doublePtr = d; + return TCL_OK; + } if (!tkwin) { - Tcl_SetObjResult(interp, Tcl_ObjPrintf("bad screen")); - Tcl_SetErrorCode(interp, "TK", "VALUE", "FRACTIONAL_PIXELS", NULL); + if (interp != NULL) { + Tcl_SetObjResult(interp, Tcl_NewStringObj("bad screen", -1)); + Tcl_SetErrorCode(interp, "TK", "VALUE", "FRACTIONAL_PIXELS", (char *)NULL); + } return TCL_ERROR; } - d = strtod((char *) string, &end); - if (end == string) { - goto error; + rest = string + strlen(string); + while ((rest > string) && isspace(UCHAR(rest[-1]))) { + --rest; /* skip all spaces at the end */ } - while ((*end != '\0') && isspace(UCHAR(*end))) { - end++; + if (rest > string) { + --rest; /* point to the character just before the last space */ } - switch (*end) { - case 0: - break; + if (rest == string) { + error: + if (interp != NULL) { + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "expected screen distance but got \"%.50s\"", string)); + Tcl_SetErrorCode(interp, "TK", "VALUE", "PIXELS", (char *)NULL); + } + return TCL_ERROR; + } + Tcl_DStringInit(&ds); + Tcl_DStringAppend(&ds, string, rest-string); + if (Tcl_GetDouble(NULL, Tcl_DStringValue(&ds), &d) != TCL_OK) { + Tcl_DStringFree(&ds); + goto error; + } + Tcl_DStringFree(&ds); + switch (*rest) { case 'c': d *= 10*WidthOfScreen(Tk_Screen(tkwin)); d /= WidthMMOfScreen(Tk_Screen(tkwin)); - end++; break; case 'i': d *= 25.4*WidthOfScreen(Tk_Screen(tkwin)); d /= WidthMMOfScreen(Tk_Screen(tkwin)); - end++; break; case 'm': d *= WidthOfScreen(Tk_Screen(tkwin)); d /= WidthMMOfScreen(Tk_Screen(tkwin)); - end++; break; case 'p': d *= (25.4/72.0)*WidthOfScreen(Tk_Screen(tkwin)); d /= WidthMMOfScreen(Tk_Screen(tkwin)); - end++; break; default: goto error; } - while ((*end != '\0') && isspace(UCHAR(*end))) { - end++; - } - if (*end != 0) { - goto error; - } *doublePtr = d; return TCL_OK; - - error: - Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "bad screen distance \"%s\"", string)); - Tcl_SetErrorCode(interp, "TK", "VALUE", "FRACTIONAL_PIXELS", NULL); - return TCL_ERROR; } /* |