]>
cvs.zerfleddert.de Git - micropolis/blob - src/tcl/tclget.c
4 * This file contains procedures to convert strings into
5 * other forms, like integers or floating-point numbers or
6 * booleans, doing syntax checking along the way.
8 * Copyright 1990-1991 Regents of the University of California
9 * Permission to use, copy, modify, and distribute this
10 * software and its documentation for any purpose and without
11 * fee is hereby granted, provided that the above copyright
12 * notice appear in all copies. The University of California
13 * makes no representations about the suitability of this
14 * software for any purpose. It is provided "as is" without
15 * express or implied warranty.
19 static char rcsid
[] = "$Header: /user6/ouster/tcl/RCS/tclGet.c,v 1.11 92/02/29 16:13:14 ouster Exp $ SPRITE (Berkeley)";
25 *----------------------------------------------------------------------
29 * Given a string, produce the corresponding integer value.
32 * The return value is normally TCL_OK; in this case *intPtr
33 * will be set to the integer value equivalent to string. If
34 * string is improperly formed then TCL_ERROR is returned and
35 * an error message will be left in interp->result.
40 *----------------------------------------------------------------------
45 Tcl_Interp
*interp
, /* Interpreter to use for error reporting. */
46 char *string
, /* String containing a (possibly signed)
47 * integer in a form acceptable to strtol. */
48 int *intPtr
/* Place to store converted result. */
54 i
= strtol(string
, &end
, 0);
55 while ((*end
!= '\0') && isspace(*end
)) {
58 if ((end
== string
) || (*end
!= 0)) {
59 Tcl_AppendResult(interp
, "expected integer but got \"", string
,
68 *----------------------------------------------------------------------
72 * Given a string, produce the corresponding double-precision
73 * floating-point value.
76 * The return value is normally TCL_OK; in this case *doublePtr
77 * will be set to the double-precision value equivalent to string.
78 * If string is improperly formed then TCL_ERROR is returned and
79 * an error message will be left in interp->result.
84 *----------------------------------------------------------------------
89 Tcl_Interp
*interp
, /* Interpreter to use for error reporting. */
90 char *string
, /* String containing a floating-point number
91 * in a form acceptable to strtod. */
92 double *doublePtr
/* Place to store converted result. */
98 d
= strtod(string
, &end
);
99 while ((*end
!= '\0') && isspace(*end
)) {
102 if ((end
== string
) || (*end
!= 0)) {
103 Tcl_AppendResult(interp
, "expected floating-point number but got \"",
104 string
, "\"", (char *) NULL
);
112 *----------------------------------------------------------------------
116 * Given a string, return a 0/1 boolean value corresponding
120 * The return value is normally TCL_OK; in this case *boolPtr
121 * will be set to the 0/1 value equivalent to string. If
122 * string is improperly formed then TCL_ERROR is returned and
123 * an error message will be left in interp->result.
128 *----------------------------------------------------------------------
133 Tcl_Interp
*interp
, /* Interpreter to use for error reporting. */
134 char *string
, /* String containing a boolean number
135 * specified either as 1/0 or true/false or
137 int *boolPtr
/* Place to store converted result, which
146 * Convert the input string to all lower-case.
149 for (i
= 0; i
< 9; i
++) {
154 if ((c
>= 'A') && (c
<= 'Z')) {
161 length
= strlen(lowerCase
);
163 if ((c
== '0') && (lowerCase
[1] == '\0')) {
165 } else if ((c
== '1') && (lowerCase
[1] == '\0')) {
167 } else if ((c
== 'y') && (strncmp(lowerCase
, "yes", length
) == 0)) {
169 } else if ((c
== 'n') && (strncmp(lowerCase
, "no", length
) == 0)) {
171 } else if ((c
== 't') && (strncmp(lowerCase
, "true", length
) == 0)) {
173 } else if ((c
== 'f') && (strncmp(lowerCase
, "false", length
) == 0)) {
175 } else if ((c
== 'o') && (length
>= 2)) {
176 if (strncmp(lowerCase
, "on", length
) == 0) {
178 } else if (strncmp(lowerCase
, "off", length
) == 0) {
182 Tcl_AppendResult(interp
, "expected boolean value but got \"",
183 string
, "\"", (char *) NULL
);