|
/* $Header: /cvsroot/esrg/sfesrg/esrgpcpj/shared/tcl_base/tclhistory.c,v 1.1.1.1 2001/06/13 04:39:28 dtashley Exp $ */ |
|
|
|
|
|
/* |
|
|
* tclHistory.c -- |
|
|
* |
|
|
* This module and the Tcl library file history.tcl together implement |
|
|
* Tcl command history. Tcl_RecordAndEval(Obj) can be called to record |
|
|
* commands ("events") before they are executed. Commands defined in |
|
|
* history.tcl may be used to perform history substitutions. |
|
|
* |
|
|
* 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. |
|
|
* |
|
|
* RCS: @(#) $Id: tclhistory.c,v 1.1.1.1 2001/06/13 04:39:28 dtashley Exp $ |
|
|
*/ |
|
|
|
|
|
#include "tclInt.h" |
|
|
#include "tclPort.h" |
|
|
|
|
|
|
|
|
/* |
|
|
*---------------------------------------------------------------------- |
|
|
* |
|
|
* Tcl_RecordAndEval -- |
|
|
* |
|
|
* This procedure adds its command argument to the current list of |
|
|
* recorded events and then executes the command by calling |
|
|
* Tcl_Eval. |
|
|
* |
|
|
* Results: |
|
|
* The return value is a standard Tcl return value, the result of |
|
|
* executing cmd. |
|
|
* |
|
|
* Side effects: |
|
|
* The command is recorded and executed. |
|
|
* |
|
|
*---------------------------------------------------------------------- |
|
|
*/ |
|
|
|
|
|
int |
|
|
Tcl_RecordAndEval(interp, cmd, flags) |
|
|
Tcl_Interp *interp; /* Token for interpreter in which command |
|
|
* will be executed. */ |
|
|
char *cmd; /* Command to record. */ |
|
|
int flags; /* Additional flags. TCL_NO_EVAL means |
|
|
* only record: don't execute command. |
|
|
* TCL_EVAL_GLOBAL means use Tcl_GlobalEval |
|
|
* instead of Tcl_Eval. */ |
|
|
{ |
|
|
register Tcl_Obj *cmdPtr; |
|
|
int length = strlen(cmd); |
|
|
int result; |
|
|
|
|
|
if (length > 0) { |
|
|
/* |
|
|
* Call Tcl_RecordAndEvalObj to do the actual work. |
|
|
*/ |
|
|
|
|
|
cmdPtr = Tcl_NewStringObj(cmd, length); |
|
|
Tcl_IncrRefCount(cmdPtr); |
|
|
result = Tcl_RecordAndEvalObj(interp, cmdPtr, flags); |
|
|
|
|
|
/* |
|
|
* Move the interpreter's object result to the string result, |
|
|
* then reset the object result. |
|
|
*/ |
|
|
|
|
|
Tcl_SetResult(interp, TclGetString(Tcl_GetObjResult(interp)), |
|
|
TCL_VOLATILE); |
|
|
|
|
|
/* |
|
|
* Discard the Tcl object created to hold the command. |
|
|
*/ |
|
|
|
|
|
Tcl_DecrRefCount(cmdPtr); |
|
|
} else { |
|
|
/* |
|
|
* An empty string. Just reset the interpreter's result. |
|
|
*/ |
|
|
|
|
|
Tcl_ResetResult(interp); |
|
|
result = TCL_OK; |
|
|
} |
|
|
return result; |
|
|
} |
|
|
|
|
|
/* |
|
|
*---------------------------------------------------------------------- |
|
|
* |
|
|
* Tcl_RecordAndEvalObj -- |
|
|
* |
|
|
* This procedure adds the command held in its argument object to the |
|
|
* current list of recorded events and then executes the command by |
|
|
* calling Tcl_EvalObj. |
|
|
* |
|
|
* Results: |
|
|
* The return value is a standard Tcl return value, the result of |
|
|
* executing the command. |
|
|
* |
|
|
* Side effects: |
|
|
* The command is recorded and executed. |
|
|
* |
|
|
*---------------------------------------------------------------------- |
|
|
*/ |
|
|
|
|
|
int |
|
|
Tcl_RecordAndEvalObj(interp, cmdPtr, flags) |
|
|
Tcl_Interp *interp; /* Token for interpreter in which command |
|
|
* will be executed. */ |
|
|
Tcl_Obj *cmdPtr; /* Points to object holding the command to |
|
|
* record and execute. */ |
|
|
int flags; /* Additional flags. TCL_NO_EVAL means |
|
|
* record only: don't execute the command. |
|
|
* TCL_EVAL_GLOBAL means evaluate the |
|
|
* script in global variable context instead |
|
|
* of the current procedure. */ |
|
|
{ |
|
|
int result; |
|
|
Tcl_Obj *list[3]; |
|
|
register Tcl_Obj *objPtr; |
|
|
|
|
|
/* |
|
|
* Do recording by eval'ing a tcl history command: history add $cmd. |
|
|
*/ |
|
|
|
|
|
list[0] = Tcl_NewStringObj("history", -1); |
|
|
list[1] = Tcl_NewStringObj("add", -1); |
|
|
list[2] = cmdPtr; |
|
|
|
|
|
objPtr = Tcl_NewListObj(3, list); |
|
|
Tcl_IncrRefCount(objPtr); |
|
|
(void) Tcl_EvalObjEx(interp, objPtr, TCL_EVAL_GLOBAL); |
|
|
Tcl_DecrRefCount(objPtr); |
|
|
|
|
|
/* |
|
|
* Execute the command. |
|
|
*/ |
|
|
|
|
|
result = TCL_OK; |
|
|
if (!(flags & TCL_NO_EVAL)) { |
|
|
result = Tcl_EvalObjEx(interp, cmdPtr, flags & TCL_EVAL_GLOBAL); |
|
|
} |
|
|
return result; |
|
|
} |
|
|
|
|
|
|
|
|
/* $History: tclhistory.c $ |
|
|
* |
|
|
* ***************** Version 1 ***************** |
|
|
* User: Dtashley Date: 1/02/01 Time: 1:30a |
|
|
* Created in $/IjuScripter, IjuConsole/Source/Tcl Base |
|
|
* Initial check-in. |
|
|
*/ |
|
|
|
|
|
/* End of TCLHISTORY.C */ |
|
1 |
|
/* $Header$ */ |
2 |
|
/* |
3 |
|
* tclHistory.c -- |
4 |
|
* |
5 |
|
* This module and the Tcl library file history.tcl together implement |
6 |
|
* Tcl command history. Tcl_RecordAndEval(Obj) can be called to record |
7 |
|
* commands ("events") before they are executed. Commands defined in |
8 |
|
* history.tcl may be used to perform history substitutions. |
9 |
|
* |
10 |
|
* Copyright (c) 1990-1993 The Regents of the University of California. |
11 |
|
* Copyright (c) 1994-1997 Sun Microsystems, Inc. |
12 |
|
* |
13 |
|
* See the file "license.terms" for information on usage and redistribution |
14 |
|
* of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
15 |
|
* |
16 |
|
* RCS: @(#) $Id: tclhistory.c,v 1.1.1.1 2001/06/13 04:39:28 dtashley Exp $ |
17 |
|
*/ |
18 |
|
|
19 |
|
#include "tclInt.h" |
20 |
|
#include "tclPort.h" |
21 |
|
|
22 |
|
|
23 |
|
/* |
24 |
|
*---------------------------------------------------------------------- |
25 |
|
* |
26 |
|
* Tcl_RecordAndEval -- |
27 |
|
* |
28 |
|
* This procedure adds its command argument to the current list of |
29 |
|
* recorded events and then executes the command by calling |
30 |
|
* Tcl_Eval. |
31 |
|
* |
32 |
|
* Results: |
33 |
|
* The return value is a standard Tcl return value, the result of |
34 |
|
* executing cmd. |
35 |
|
* |
36 |
|
* Side effects: |
37 |
|
* The command is recorded and executed. |
38 |
|
* |
39 |
|
*---------------------------------------------------------------------- |
40 |
|
*/ |
41 |
|
|
42 |
|
int |
43 |
|
Tcl_RecordAndEval(interp, cmd, flags) |
44 |
|
Tcl_Interp *interp; /* Token for interpreter in which command |
45 |
|
* will be executed. */ |
46 |
|
char *cmd; /* Command to record. */ |
47 |
|
int flags; /* Additional flags. TCL_NO_EVAL means |
48 |
|
* only record: don't execute command. |
49 |
|
* TCL_EVAL_GLOBAL means use Tcl_GlobalEval |
50 |
|
* instead of Tcl_Eval. */ |
51 |
|
{ |
52 |
|
register Tcl_Obj *cmdPtr; |
53 |
|
int length = strlen(cmd); |
54 |
|
int result; |
55 |
|
|
56 |
|
if (length > 0) { |
57 |
|
/* |
58 |
|
* Call Tcl_RecordAndEvalObj to do the actual work. |
59 |
|
*/ |
60 |
|
|
61 |
|
cmdPtr = Tcl_NewStringObj(cmd, length); |
62 |
|
Tcl_IncrRefCount(cmdPtr); |
63 |
|
result = Tcl_RecordAndEvalObj(interp, cmdPtr, flags); |
64 |
|
|
65 |
|
/* |
66 |
|
* Move the interpreter's object result to the string result, |
67 |
|
* then reset the object result. |
68 |
|
*/ |
69 |
|
|
70 |
|
Tcl_SetResult(interp, TclGetString(Tcl_GetObjResult(interp)), |
71 |
|
TCL_VOLATILE); |
72 |
|
|
73 |
|
/* |
74 |
|
* Discard the Tcl object created to hold the command. |
75 |
|
*/ |
76 |
|
|
77 |
|
Tcl_DecrRefCount(cmdPtr); |
78 |
|
} else { |
79 |
|
/* |
80 |
|
* An empty string. Just reset the interpreter's result. |
81 |
|
*/ |
82 |
|
|
83 |
|
Tcl_ResetResult(interp); |
84 |
|
result = TCL_OK; |
85 |
|
} |
86 |
|
return result; |
87 |
|
} |
88 |
|
|
89 |
|
/* |
90 |
|
*---------------------------------------------------------------------- |
91 |
|
* |
92 |
|
* Tcl_RecordAndEvalObj -- |
93 |
|
* |
94 |
|
* This procedure adds the command held in its argument object to the |
95 |
|
* current list of recorded events and then executes the command by |
96 |
|
* calling Tcl_EvalObj. |
97 |
|
* |
98 |
|
* Results: |
99 |
|
* The return value is a standard Tcl return value, the result of |
100 |
|
* executing the command. |
101 |
|
* |
102 |
|
* Side effects: |
103 |
|
* The command is recorded and executed. |
104 |
|
* |
105 |
|
*---------------------------------------------------------------------- |
106 |
|
*/ |
107 |
|
|
108 |
|
int |
109 |
|
Tcl_RecordAndEvalObj(interp, cmdPtr, flags) |
110 |
|
Tcl_Interp *interp; /* Token for interpreter in which command |
111 |
|
* will be executed. */ |
112 |
|
Tcl_Obj *cmdPtr; /* Points to object holding the command to |
113 |
|
* record and execute. */ |
114 |
|
int flags; /* Additional flags. TCL_NO_EVAL means |
115 |
|
* record only: don't execute the command. |
116 |
|
* TCL_EVAL_GLOBAL means evaluate the |
117 |
|
* script in global variable context instead |
118 |
|
* of the current procedure. */ |
119 |
|
{ |
120 |
|
int result; |
121 |
|
Tcl_Obj *list[3]; |
122 |
|
register Tcl_Obj *objPtr; |
123 |
|
|
124 |
|
/* |
125 |
|
* Do recording by eval'ing a tcl history command: history add $cmd. |
126 |
|
*/ |
127 |
|
|
128 |
|
list[0] = Tcl_NewStringObj("history", -1); |
129 |
|
list[1] = Tcl_NewStringObj("add", -1); |
130 |
|
list[2] = cmdPtr; |
131 |
|
|
132 |
|
objPtr = Tcl_NewListObj(3, list); |
133 |
|
Tcl_IncrRefCount(objPtr); |
134 |
|
(void) Tcl_EvalObjEx(interp, objPtr, TCL_EVAL_GLOBAL); |
135 |
|
Tcl_DecrRefCount(objPtr); |
136 |
|
|
137 |
|
/* |
138 |
|
* Execute the command. |
139 |
|
*/ |
140 |
|
|
141 |
|
result = TCL_OK; |
142 |
|
if (!(flags & TCL_NO_EVAL)) { |
143 |
|
result = Tcl_EvalObjEx(interp, cmdPtr, flags & TCL_EVAL_GLOBAL); |
144 |
|
} |
145 |
|
return result; |
146 |
|
} |
147 |
|
|
148 |
|
/* End of tclhistory.c */ |