home *** CD-ROM | disk | FTP | other *** search
-
-
-
- TTTTccccllll____IIIInnnntttteeeerrrrpppp((((3333)))) TTTTccccllll (((( )))) TTTTccccllll____IIIInnnntttteeeerrrrpppp((((3333))))
-
-
-
- _________________________________________________________________
-
- NNNNAAAAMMMMEEEE
- Tcl_Interp - client-visible fields of interpreter structures
-
- SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
- ####iiiinnnncccclllluuuuddddeeee <<<<ttttccccllll....hhhh>>>>
-
- typedef struct {
- char *_r_e_s_u_l_t;
- Tcl_FreeProc *_f_r_e_e_P_r_o_c;
- int _e_r_r_o_r_L_i_n_e;
- } Tcl_Interp;
-
- typedef void Tcl_FreeProc(char *_b_l_o_c_k_P_t_r);
- _________________________________________________________________
-
-
- DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
- The TTTTccccllll____CCCCrrrreeeeaaaatttteeeeIIIInnnntttteeeerrrrpppp procedure returns a pointer to a
- Tcl_Interp structure. This pointer is then passed into
- other Tcl procedures to process commands in the interpreter
- and perform other operations on the interpreter.
- Interpreter structures contain many many fields that are
- used by Tcl, but only three that may be accessed by clients:
- _r_e_s_u_l_t, _f_r_e_e_P_r_o_c, and _e_r_r_o_r_L_i_n_e.
-
- The _r_e_s_u_l_t and _f_r_e_e_P_r_o_c fields are used to return results or
- error messages from commands. This information is returned
- by command procedures back to TTTTccccllll____EEEEvvvvaaaallll, and by TTTTccccllll____EEEEvvvvaaaallll back
- to its callers. The _r_e_s_u_l_t field points to the string that
- represents the result or error message, and the _f_r_e_e_P_r_o_c
- field tells how to dispose of the storage for the string
- when it isn't needed anymore. The easiest way for command
- procedures to manipulate these fields is to call procedures
- like TTTTccccllll____SSSSeeeettttRRRReeeessssuuuulllltttt or TTTTccccllll____AAAAppppppppeeeennnnddddRRRReeeessssuuuulllltttt; they will hide all
- the details of managing the fields. The description below
- is for those procedures that manipulate the fields directly.
-
- Whenever a command procedure returns, it must ensure that
- the _r_e_s_u_l_t field of its interpreter points to the string
- being returned by the command. The _r_e_s_u_l_t field must always
- point to a valid string. If a command wishes to return no
- result then _i_n_t_e_r_p->_r_e_s_u_l_t should point to an empty string.
- Normally, results are assumed to be statically allocated,
- which means that the contents will not change before the
- next time TTTTccccllll____EEEEvvvvaaaallll is called or some other command procedure
- is invoked. In this case, the _f_r_e_e_P_r_o_c field must be zero.
- Alternatively, a command procedure may dynamically allocate
- its return value (e.g. using mmmmaaaalllllllloooocccc) and store a pointer to
- it in _i_n_t_e_r_p->_r_e_s_u_l_t. In this case, the command procedure
- must also set _i_n_t_e_r_p->_f_r_e_e_P_r_o_c to the address of a procedure
-
-
-
- Page 1 (printed 7/10/95)
-
-
-
-
-
-
- TTTTccccllll____IIIInnnntttteeeerrrrpppp((((3333)))) TTTTccccllll (((( )))) TTTTccccllll____IIIInnnntttteeeerrrrpppp((((3333))))
-
-
-
- that can free the value (usually ffffrrrreeeeeeee). If _i_n_t_e_r_p->_f_r_e_e_P_r_o_c
- is non-zero, then Tcl will call _f_r_e_e_P_r_o_c to free the space
- pointed to by _i_n_t_e_r_p->_r_e_s_u_l_t before it invokes the next
- command. If a client procedure overwrites _i_n_t_e_r_p->_r_e_s_u_l_t
- when _i_n_t_e_r_p->_f_r_e_e_P_r_o_c is non-zero, then it is responsible
- for calling _f_r_e_e_P_r_o_c to free the old _i_n_t_e_r_p->_r_e_s_u_l_t (the
- TTTTccccllll____FFFFrrrreeeeeeeeRRRReeeessssuuuulllltttt macro should be used for this purpose).
-
- _F_r_e_e_P_r_o_c should have arguments and result that match the
- TTTTccccllll____FFFFrrrreeeeeeeePPPPrrrroooocccc declaration above: it receives a single
- argument which is a pointer to the result value to free. In
- most applications ffffrrrreeeeeeee is the only non-zero value ever used
- for _f_r_e_e_P_r_o_c. However, an application may store a different
- procedure address in _f_r_e_e_P_r_o_c in order to use an alternate
- memory allocator or in order to do other cleanup when the
- result memory is freed.
-
- As part of processing each command, TTTTccccllll____EEEEvvvvaaaallll initializes
- _i_n_t_e_r_p->_r_e_s_u_l_t and _i_n_t_e_r_p->_f_r_e_e_P_r_o_c just before calling the
- command procedure for the command. The _f_r_e_e_P_r_o_c field will
- be initialized to zero, and _i_n_t_e_r_p->_r_e_s_u_l_t will point to an
- empty string. Commands that do not return any value can
- simply leave the fields alone. Furthermore, the empty
- string pointed to by _r_e_s_u_l_t is actually part of an array of
- TTTTCCCCLLLL____RRRREEEESSSSUUUULLLLTTTT____SSSSIIIIZZZZEEEE characters (approximately 200). If a
- command wishes to return a short string, it can simply copy
- it to the area pointed to by _i_n_t_e_r_p->_r_e_s_u_l_t. Or, it can use
- the sprintf procedure to generate a short result string at
- the location pointed to by _i_n_t_e_r_p->_r_e_s_u_l_t.
-
- It is a general convention in Tcl-based applications that
- the result of an interpreter is normally in the initialized
- state described in the previous paragraph. Procedures that
- manipulate an interpreter's result (e.g. by returning an
- error) will generally assume that the result has been
- initialized when the procedure is called. If such a
- procedure is to be called after the result has been changed,
- then TTTTccccllll____RRRReeeesssseeeettttRRRReeeessssuuuulllltttt should be called first to reset the
- result to its initialized state.
-
- The _e_r_r_o_r_L_i_n_e field is valid only after TTTTccccllll____EEEEvvvvaaaallll returns a
- TTTTCCCCLLLL____EEEERRRRRRRROOOORRRR return code. In this situation the _e_r_r_o_r_L_i_n_e
- field identifies the line number of the command being
- executed when the error occurred. The line numbers are
- relative to the command being executed: 1 means the first
- line of the command passed to TTTTccccllll____EEEEvvvvaaaallll, 2 means the second
- line, and so on. The _e_r_r_o_r_L_i_n_e field is typically used in
- conjunction with TTTTccccllll____AAAAddddddddEEEErrrrrrrroooorrrrIIIInnnnffffoooo to report information
- about where an error occurred. _E_r_r_o_r_L_i_n_e should not
- normally be modified except by TTTTccccllll____EEEEvvvvaaaallll.
-
-
-
-
-
- Page 2 (printed 7/10/95)
-
-
-
-
-
-
- TTTTccccllll____IIIInnnntttteeeerrrrpppp((((3333)))) TTTTccccllll (((( )))) TTTTccccllll____IIIInnnntttteeeerrrrpppp((((3333))))
-
-
-
- KKKKEEEEYYYYWWWWOOOORRRRDDDDSSSS
- free, initialized, interpreter, malloc, result
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Page 3 (printed 7/10/95)
-
-
-
-