1 |
578 |
markom |
'\"
|
2 |
|
|
'\" Copyright (c) 1989-1993 The Regents of the University of California.
|
3 |
|
|
'\" Copyright (c) 1994-1997 Sun Microsystems, Inc.
|
4 |
|
|
'\"
|
5 |
|
|
'\" See the file "license.terms" for information on usage and redistribution
|
6 |
|
|
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
7 |
|
|
'\"
|
8 |
|
|
'\" RCS: @(#) $Id: ExprLong.3,v 1.1.1.1 2002-01-16 10:25:23 markom Exp $
|
9 |
|
|
'\"
|
10 |
|
|
.so man.macros
|
11 |
|
|
.TH Tcl_ExprLong 3 7.0 Tcl "Tcl Library Procedures"
|
12 |
|
|
.BS
|
13 |
|
|
.SH NAME
|
14 |
|
|
Tcl_ExprLong, Tcl_ExprDouble, Tcl_ExprBoolean, Tcl_ExprString \- evaluate an expression
|
15 |
|
|
.SH SYNOPSIS
|
16 |
|
|
.nf
|
17 |
|
|
\fB#include \fR
|
18 |
|
|
.sp
|
19 |
|
|
int
|
20 |
|
|
\fBTcl_ExprLong\fR(\fIinterp, string, longPtr\fR)
|
21 |
|
|
.sp
|
22 |
|
|
int
|
23 |
|
|
\fBTcl_ExprDouble\fR(\fIinterp, string, doublePtr\fR)
|
24 |
|
|
.sp
|
25 |
|
|
int
|
26 |
|
|
\fBTcl_ExprBoolean\fR(\fIinterp, string, booleanPtr\fR)
|
27 |
|
|
.sp
|
28 |
|
|
int
|
29 |
|
|
\fBTcl_ExprString\fR(\fIinterp, string\fR)
|
30 |
|
|
.SH ARGUMENTS
|
31 |
|
|
.AS Tcl_Interp *booleanPtr
|
32 |
|
|
.AP Tcl_Interp *interp in
|
33 |
|
|
Interpreter in whose context to evaluate \fIstring\fR or \fIobjPtr\fR.
|
34 |
|
|
.AP char *string in
|
35 |
|
|
Expression to be evaluated. Must be in writable memory (the expression
|
36 |
|
|
parser makes temporary modifications to the string during parsing, which
|
37 |
|
|
it undoes before returning).
|
38 |
|
|
.AP long *longPtr out
|
39 |
|
|
Pointer to location in which to store the integer value of the
|
40 |
|
|
expression.
|
41 |
|
|
.AP int *doublePtr out
|
42 |
|
|
Pointer to location in which to store the floating-point value of the
|
43 |
|
|
expression.
|
44 |
|
|
.AP int *booleanPtr out
|
45 |
|
|
Pointer to location in which to store the 0/1 boolean value of the
|
46 |
|
|
expression.
|
47 |
|
|
.BE
|
48 |
|
|
|
49 |
|
|
.SH DESCRIPTION
|
50 |
|
|
.PP
|
51 |
|
|
These four procedures all evaluate the expression
|
52 |
|
|
given by the \fIstring\fR argument
|
53 |
|
|
and return the result in one of four different forms.
|
54 |
|
|
The expression can have any of the forms accepted by the \fBexpr\fR command.
|
55 |
|
|
Note that these procedures have been largely replaced by the
|
56 |
|
|
object-based procedures \fBTcl_ExprLongObj\fR, \fBTcl_ExprDoubleObj\fR,
|
57 |
|
|
\fBTcl_ExprBooleanObj\fR, and \fBTcl_ExprStringObj\fR.
|
58 |
|
|
Those object-based procedures evaluate an expression held in a Tcl object
|
59 |
|
|
instead of a string.
|
60 |
|
|
The object argument can retain an internal representation
|
61 |
|
|
that is more efficient to execute.
|
62 |
|
|
.PP
|
63 |
|
|
The \fIinterp\fR argument refers to an interpreter used to
|
64 |
|
|
evaluate the expression (e.g. for variables and nested Tcl
|
65 |
|
|
commands) and to return error information.
|
66 |
|
|
\fIinterp->result\fR is assumed to be initialized
|
67 |
|
|
in the standard fashion when they are invoked.
|
68 |
|
|
.PP
|
69 |
|
|
For all of these procedures the return value is a standard
|
70 |
|
|
Tcl result: \fBTCL_OK\fR means the expression was successfully
|
71 |
|
|
evaluated, and \fBTCL_ERROR\fR means that an error occurred while
|
72 |
|
|
evaluating the expression.
|
73 |
|
|
If \fBTCL_ERROR\fR is returned then
|
74 |
|
|
\fIinterp->result\fR will hold a message describing the error.
|
75 |
|
|
If an error occurs while executing a Tcl command embedded in
|
76 |
|
|
the expression then that error will be returned.
|
77 |
|
|
.PP
|
78 |
|
|
If the expression is successfully evaluated, then its value is
|
79 |
|
|
returned in one of four forms, depending on which procedure
|
80 |
|
|
is invoked.
|
81 |
|
|
\fBTcl_ExprLong\fR stores an integer value at \fI*longPtr\fR.
|
82 |
|
|
If the expression's actual value is a floating-point number,
|
83 |
|
|
then it is truncated to an integer.
|
84 |
|
|
If the expression's actual value is a non-numeric string then
|
85 |
|
|
an error is returned.
|
86 |
|
|
.PP
|
87 |
|
|
\fBTcl_ExprDouble\fR stores a floating-point value at \fI*doublePtr\fR.
|
88 |
|
|
If the expression's actual value is an integer, it is converted to
|
89 |
|
|
floating-point.
|
90 |
|
|
If the expression's actual value is a non-numeric string then
|
91 |
|
|
an error is returned.
|
92 |
|
|
.PP
|
93 |
|
|
\fBTcl_ExprBoolean\fR stores a 0/1 integer value at \fI*booleanPtr\fR.
|
94 |
|
|
If the expression's actual value is an integer or floating-point
|
95 |
|
|
number, then they store 0 at \fI*booleanPtr\fR if
|
96 |
|
|
the value was zero and 1 otherwise.
|
97 |
|
|
If the expression's actual value is a non-numeric string then
|
98 |
|
|
it must be one of the values accepted by \fBTcl_GetBoolean\fR
|
99 |
|
|
such as ``yes'' or ``no'', or else an error occurs.
|
100 |
|
|
.PP
|
101 |
|
|
\fBTcl_ExprString\fR returns the value of the expression as a
|
102 |
|
|
string stored in \fIinterp->result\fR.
|
103 |
|
|
If the expression's actual value is an integer
|
104 |
|
|
then \fBTcl_ExprString\fR converts it to a string using \fBsprintf\fR
|
105 |
|
|
with a ``%d'' converter.
|
106 |
|
|
If the expression's actual value is a floating-point
|
107 |
|
|
number, then \fBTcl_ExprString\fR calls \fBTcl_PrintDouble\fR
|
108 |
|
|
to convert it to a string.
|
109 |
|
|
|
110 |
|
|
.SH "SEE ALSO"
|
111 |
|
|
Tcl_ExprLongObj, Tcl_ExprDoubleObj, Tcl_ExprBooleanObj, Tcl_ExprObj
|
112 |
|
|
|
113 |
|
|
.SH KEYWORDS
|
114 |
|
|
boolean, double, evaluate, expression, integer, object, string
|