source: tol/toltcl/generic/tclutils.cpp @ 6d7779d

1941-docker-image-to-testdevel
Last change on this file since 6d7779d was 6d7779d, checked in by Jorge Pérez <josp.jorge@…>, 18 years ago

initial import

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@1 be4846ae-f051-483a-831f-b64e7d08527f

  • Property mode set to 100644
File size: 2.4 KB
Line 
1/* tclutils.cpp: This file define a set of utils functions.
2                 GNU/tolTcl Library
3
4   Copyright (C) 2001, 2002, 2003 - Bayes Decisión, SL
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   This program is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with this program; if not, write to the Free Software
18   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19   USA.
20 */
21
22
23#include <tt_tclutils.h>
24
25/*!
26 *  EvalScript::EvalScript --
27 *
28 *    class constructor. Setup the script and the arguments
29 *    to be used in next evaluations.
30 *
31 */
32EvalScript::EvalScript( Tcl_Interp * interp,
33                        Tcl_Obj * script, int objc, Tcl_Obj * objv[] )
34{
35  int itemc;
36  Tcl_Obj ** itemv;
37  int i;
38
39  m_interp = interp;
40  m_status = Tcl_ListObjGetElements( interp, script, &itemc, &itemv );
41  if ( m_status != TCL_OK ) {
42    m_objc = 0;
43    m_objv = NULL;
44  }
45  else {
46    m_xobjc = objc;
47    m_xobjv = objv;
48    m_objc = itemc + objc;
49    m_objv = (Tcl_Obj**)Tcl_Alloc( sizeof(Tcl_Obj*) * m_objc );
50    for ( i = 0; i < itemc; i++ ) {
51      m_objv[i] = itemv[i];
52      Tcl_IncrRefCount( m_objv[i] );
53    }
54    m_status = TCL_OK;
55  }
56}
57
58/*!
59 *  EvalScript::~EvalScript --
60 *
61 */
62EvalScript::~EvalScript()
63{
64  int i;
65
66  if ( m_objv ) {
67    for ( i = 0; i < m_objc - m_xobjc; i++ )
68      Tcl_DecrRefCount( m_objv[i] );
69    Tcl_Free( (char*)m_objv );
70    m_objc = 0;
71    m_objv = NULL;
72  }
73}
74
75/*!
76 *  EvalScript::Eval --
77 *
78 *    Eval the script and arguments.
79 *
80 */
81int EvalScript::Eval()
82{
83  if ( m_objc ) {
84    /* Refresh the extra arguments value */
85    for ( int j = 0, i = m_objc-m_xobjc; i < m_objc; i++, j++ )
86      m_objv[i] = m_xobjv[j];
87    m_status = Tcl_EvalObjv( m_interp, m_objc, m_objv, TCL_EVAL_GLOBAL);
88  }
89  return m_status;
90}
91
92Tcl_Obj * NewExternalStringObj( char * str )
93{
94  Tcl_DString dstr;
95  Tcl_Obj * obj;
96
97  Tcl_DStringInit(&dstr);
98  Tcl_ExternalToUtfDString(NULL, str, -1, &dstr);
99  obj = Tcl_NewStringObj(Tcl_DStringValue(&dstr), -1);
100  Tcl_DStringFree(&dstr);
101  return obj;
102}
Note: See TracBrowser for help on using the repository browser.