00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include "common.h"
00041
00042
00043 #include "tcl.h"
00044 #ifdef HAVE_STRING_H
00045 #include <string.h>
00046 #endif
00047 #include "machine.h"
00048 #include "cmd.h"
00049
00050
00051 extern int bu_cmdhist_history(ClientData clientData, Tcl_Interp *interp, int argc, char **argv);
00052 extern int bu_cmdhist_add(ClientData clientData, Tcl_Interp *interp, int argc, char **argv);
00053 extern int bu_cmdhist_curr(ClientData clientData, Tcl_Interp *interp, int argc, char **argv);
00054 extern int bu_cmdhist_next(ClientData clientData, Tcl_Interp *interp, int argc, char **argv);
00055 extern int bu_cmdhist_prev(ClientData clientData, Tcl_Interp *interp, int argc, char **argv);
00056
00057 int cho_open_tcl(ClientData clientData, Tcl_Interp *interp, int argc, char **argv);
00058
00059 static struct bu_cmdhist_obj HeadCmdHistObj;
00060
00061 static struct bu_cmdtab ch_cmds[] =
00062 {
00063 {"add", bu_cmdhist_add},
00064 {"curr", bu_cmdhist_curr},
00065 {"next", bu_cmdhist_next},
00066 {"prev", bu_cmdhist_prev},
00067 {(char *)NULL, CMD_NULL}
00068 };
00069
00070
00071
00072
00073 int
00074 cho_hist(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
00075 {
00076 return bu_cmd(clientData, interp, argc, argv, ch_cmds, 1);
00077 }
00078
00079
00080
00081
00082
00083 static struct bu_cmdtab cho_cmds[] =
00084 {
00085 {"add", bu_cmdhist_add},
00086 {"curr", bu_cmdhist_curr},
00087 {"history", bu_cmdhist_history},
00088 {"next", bu_cmdhist_next},
00089 {"prev", bu_cmdhist_prev},
00090 {(char *)NULL, CMD_NULL}
00091 };
00092
00093
00094
00095
00096
00097 static int
00098 cho_cmd(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
00099 {
00100 return bu_cmd(clientData, interp, argc, argv, cho_cmds, 1);
00101 }
00102
00103
00104
00105
00106
00107 int
00108 Cho_Init(Tcl_Interp *interp)
00109 {
00110 BU_LIST_INIT(&HeadCmdHistObj.l);
00111 (void)Tcl_CreateCommand(interp, "ch_open", (Tcl_CmdProc *)cho_open_tcl,
00112 (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
00113
00114 return TCL_OK;
00115 }
00116
00117
00118
00119
00120
00121 static void
00122 cho_deleteProc(ClientData clientData)
00123 {
00124 struct bu_cmdhist_obj *chop = (struct bu_cmdhist_obj *)clientData;
00125 struct bu_cmdhist *curr, *next;
00126
00127
00128 curr = BU_LIST_NEXT(bu_cmdhist, &chop->cho_head.l);
00129 while(BU_LIST_NOT_HEAD(curr,&chop->cho_head.l)) {
00130 curr = BU_LIST_NEXT(bu_cmdhist, &chop->cho_head.l);
00131 next = BU_LIST_PNEXT(bu_cmdhist, curr);
00132
00133 bu_vls_free(&curr->h_command);
00134
00135 BU_LIST_DEQUEUE(&curr->l);
00136 bu_free((genptr_t)curr, "cho_deleteProc: curr");
00137 curr = next;
00138 }
00139
00140 bu_vls_free(&chop->cho_name);
00141 bu_vls_free(&chop->cho_head.h_command);
00142
00143 BU_LIST_DEQUEUE(&chop->l);
00144 bu_free((genptr_t)chop, "cho_deleteProc: chop");
00145 }
00146
00147 #if 0
00148
00149
00150
00151
00152
00153
00154 static int
00155 cho_close_tcl(clientData, interp, argc, argv)
00156 ClientData clientData;
00157 Tcl_Interp *interp;
00158 int argc;
00159 char **argv;
00160 {
00161 struct bu_cmdhist_obj *chop = (struct bu_cmdhist_obj *)clientData;
00162 struct bu_vls vls;
00163
00164 if (argc != 2) {
00165 bu_vls_init(&vls);
00166 bu_vls_printf(&vls, "helplib cho_close");
00167 Tcl_Eval(interp, bu_vls_addr(&vls));
00168 bu_vls_free(&vls);
00169 return TCL_ERROR;
00170 }
00171
00172
00173 Tcl_DeleteCommand(interp, bu_vls_addr(&chop->cho_name));
00174
00175 return TCL_OK;
00176 }
00177 #endif
00178
00179
00180
00181
00182
00183 static struct bu_cmdhist_obj *
00184 cho_open(ClientData clientData, Tcl_Interp *interp, char *name)
00185 {
00186 struct bu_cmdhist_obj *chop;
00187
00188
00189 for (BU_LIST_FOR(chop, bu_cmdhist_obj, &HeadCmdHistObj.l)) {
00190 if (strcmp(name,bu_vls_addr(&chop->cho_name)) == 0) {
00191 Tcl_AppendResult(interp, "ch_open: ", name,
00192 " exists.\n", (char *)NULL);
00193 return CMDHIST_OBJ_NULL;
00194 }
00195 }
00196
00197 BU_GETSTRUCT(chop, bu_cmdhist_obj);
00198 bu_vls_init(&chop->cho_name);
00199 bu_vls_strcpy(&chop->cho_name, name);
00200 BU_LIST_INIT(&chop->cho_head.l);
00201 bu_vls_init(&chop->cho_head.h_command);
00202 chop->cho_head.h_start.tv_sec = chop->cho_head.h_start.tv_usec =
00203 chop->cho_head.h_finish.tv_sec = chop->cho_head.h_finish.tv_usec = 0L;
00204 chop->cho_head.h_status = TCL_OK;
00205 chop->cho_curr = &chop->cho_head;
00206
00207 BU_LIST_APPEND(&HeadCmdHistObj.l, &chop->l);
00208 return chop;
00209 }
00210
00211
00212
00213
00214
00215
00216
00217
00218 int
00219 cho_open_tcl(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
00220 {
00221 struct bu_cmdhist_obj *chop;
00222 struct bu_vls vls;
00223
00224 if (argc == 1) {
00225
00226 for (BU_LIST_FOR(chop, bu_cmdhist_obj, &HeadCmdHistObj.l))
00227 Tcl_AppendResult(interp, bu_vls_addr(&chop->cho_name), " ", (char *)NULL);
00228
00229 return TCL_OK;
00230 }
00231
00232 if (argc == 2) {
00233 if ((chop = cho_open(clientData, interp, argv[1])) == CMDHIST_OBJ_NULL)
00234 return TCL_ERROR;
00235
00236 (void)Tcl_CreateCommand(interp,
00237 bu_vls_addr(&chop->cho_name),
00238 (Tcl_CmdProc *)cho_cmd,
00239 (ClientData)chop,
00240 cho_deleteProc);
00241
00242
00243 Tcl_ResetResult(interp);
00244 Tcl_AppendResult(interp, bu_vls_addr(&chop->cho_name), (char *)NULL);
00245 return TCL_OK;
00246 }
00247
00248 bu_vls_init(&vls);
00249 bu_vls_printf(&vls, "helplib ch_open");
00250 Tcl_Eval(interp, bu_vls_addr(&vls));
00251 bu_vls_free(&vls);
00252 return TCL_ERROR;
00253 }
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263