diff options
Diffstat (limited to 'generic/tclGet.c')
| -rw-r--r-- | generic/tclGet.c | 92 |
1 files changed, 60 insertions, 32 deletions
diff --git a/generic/tclGet.c b/generic/tclGet.c index bb3f8f1..28734d1 100644 --- a/generic/tclGet.c +++ b/generic/tclGet.c @@ -5,8 +5,8 @@ * integers or floating-point numbers or booleans, doing syntax checking * along the way. * - * Copyright © 1990-1993 The Regents of the University of California. - * Copyright © 1994-1997 Sun Microsystems, Inc. + * Copyright (c) 1990-1993 The Regents of the University of California. + * Copyright (c) 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. @@ -36,7 +36,7 @@ int Tcl_GetInt( Tcl_Interp *interp, /* Interpreter to use for error reporting. */ - const char *src, /* String containing a (possibly signed) + CONST char *src, /* String containing a (possibly signed) * integer in a form acceptable to * Tcl_GetIntFromObj(). */ int *intPtr) /* Place to store converted result. */ @@ -53,7 +53,53 @@ Tcl_GetInt( if (obj.refCount > 1) { Tcl_Panic("invalid sharing of Tcl_Obj on C stack"); } - TclFreeInternalRep(&obj); + TclFreeIntRep(&obj); + return code; +} + +/* + *---------------------------------------------------------------------- + * + * TclGetLong -- + * + * Given a string, produce the corresponding long integer value. This + * routine is a version of Tcl_GetInt but returns a "long" instead of an + * "int" (a difference that matters on 64-bit architectures). + * + * Results: + * The return value is normally TCL_OK; in this case *longPtr will be set + * to the long integer value equivalent to src. If src is improperly + * formed then TCL_ERROR is returned and an error message will be left in + * the interp's result if interp is non-NULL. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +int +TclGetLong( + Tcl_Interp *interp, /* Interpreter used for error reporting if not + * NULL. */ + CONST char *src, /* String containing a (possibly signed) long + * integer in a form acceptable to + * Tcl_GetLongFromObj(). */ + long *longPtr) /* Place to store converted long result. */ +{ + Tcl_Obj obj; + int code; + + obj.refCount = 1; + obj.bytes = (char *) src; + obj.length = strlen(src); + obj.typePtr = NULL; + + code = Tcl_GetLongFromObj(interp, &obj, longPtr); + if (obj.refCount > 1) { + Tcl_Panic("invalid sharing of Tcl_Obj on C stack"); + } + TclFreeIntRep(&obj); return code; } @@ -80,8 +126,8 @@ Tcl_GetInt( int Tcl_GetDouble( Tcl_Interp *interp, /* Interpreter used for error reporting. */ - const char *src, /* String containing a floating-point number - * in a form acceptable to + CONST char *src, /* String containing a floating-point number + * in a form acceptable to * Tcl_GetDoubleFromObj(). */ double *doublePtr) /* Place to store converted result. */ { @@ -97,7 +143,7 @@ Tcl_GetDouble( if (obj.refCount > 1) { Tcl_Panic("invalid sharing of Tcl_Obj on C stack"); } - TclFreeInternalRep(&obj); + TclFreeIntRep(&obj); return code; } @@ -110,7 +156,7 @@ Tcl_GetDouble( * string. * * Results: - * The return value is normally TCL_OK; in this case *charPtr will be set + * The return value is normally TCL_OK; in this case *boolPtr will be set * to the 0/1 value equivalent to src. If src is improperly formed then * TCL_ERROR is returned and an error message will be left in the * interp's result. @@ -121,49 +167,31 @@ Tcl_GetDouble( *---------------------------------------------------------------------- */ -#undef Tcl_GetBool -#undef Tcl_GetBoolFromObj int -Tcl_GetBool( +Tcl_GetBoolean( Tcl_Interp *interp, /* Interpreter used for error reporting. */ - const char *src, /* String containing one of the boolean values - * 1, 0, true, false, yes, no, on, off. */ - int flags, - char *charPtr) /* Place to store converted result, which will + CONST char *src, /* String containing one of the boolean values + * 1, 0, true, false, yes, no, on off. */ + int *boolPtr) /* Place to store converted result, which will * be 0 or 1. */ { Tcl_Obj obj; int code; - if ((src == NULL) || (*src == '\0')) { - return Tcl_GetBoolFromObj(interp, NULL, flags, charPtr); - } obj.refCount = 1; obj.bytes = (char *) src; obj.length = strlen(src); obj.typePtr = NULL; - code = TclSetBooleanFromAny(interp, &obj); + code = Tcl_ConvertToType(interp, &obj, &tclBooleanType); if (obj.refCount > 1) { Tcl_Panic("invalid sharing of Tcl_Obj on C stack"); } if (code == TCL_OK) { - Tcl_GetBoolFromObj(NULL, &obj, flags, charPtr); + *boolPtr = obj.internalRep.longValue; } return code; } - -#undef Tcl_GetBoolean -int -Tcl_GetBoolean( - Tcl_Interp *interp, /* Interpreter used for error reporting. */ - const char *src, /* String containing one of the boolean values - * 1, 0, true, false, yes, no, on, off. */ - int *intPtr) /* Place to store converted result, which will - * be 0 or 1. */ -{ - return Tcl_GetBool(interp, src, (TCL_NULL_OK-2)&(int)sizeof(int), (char *)(void *)intPtr); -} /* * Local Variables: |
