BRL-CAD
tclcad_eval.c
Go to the documentation of this file.
1 /* T C L C A D _ E V A L . C
2  * BRL-CAD
3  *
4  * Copyright (c) 2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 /** @file tclcad_eval.c
21  *
22  * Functions for escaping and evaluating TCL commands.
23  *
24  */
25 
26 
27 #include "common.h"
28 
29 #include <tcl.h>
30 
31 
32 int
33 tclcad_eval(Tcl_Interp *interp, const char *command, size_t num_args,
34  const char * const *args)
35 {
36  int ret;
37  size_t i;
38 
39  Tcl_DString script;
40  Tcl_DStringInit(&script);
41  Tcl_DStringAppend(&script, command, -1);
42 
43  for (i = 0; i < num_args; ++i)
44  Tcl_DStringAppendElement(&script, args[i]);
45 
46  ret = Tcl_Eval(interp, Tcl_DStringValue(&script));
47  Tcl_DStringFree(&script);
48 
49  return ret;
50 }
51 
52 
53 int
54 tclcad_eval_noresult(Tcl_Interp *interp, const char *command, size_t num_args,
55  const char * const *args)
56 {
57  int ret;
58 
59  Tcl_Obj *saved_result = Tcl_GetObjResult(interp);
60  Tcl_IncrRefCount(saved_result);
61  ret = tclcad_eval(interp, command, num_args, args);
62  Tcl_SetObjResult(interp, saved_result);
63  Tcl_DecrRefCount(saved_result);
64 
65  return ret;
66 }
67 
68 
69 /*
70  * Local Variables:
71  * tab-width: 8
72  * mode: C
73  * indent-tabs-mode: t
74  * c-file-style: "stroustrup"
75  * End:
76  * ex: shiftwidth=4 tabstop=8
77  */
ustring interp
Header file for the BRL-CAD common definitions.
int tclcad_eval_noresult(Tcl_Interp *interp, const char *command, size_t num_args, const char *const *args)
Definition: tclcad_eval.c:54
int tclcad_eval(Tcl_Interp *interp, const char *command, size_t num_args, const char *const *args)
Definition: tclcad_eval.c:33