Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

TCL(Tool Command Language) Scripting

Adding a Safe Interactive Intrepreter to an Application.


Good People,

I have been considering adding an interactive shell to one of our
stand alone applicaions.

Any ideas on how to do this?

Dave

No takers on this?

Dave

davidhbige@simplifiedlogic.com wrote:
> No takers on this?

> Dave

Never done anything with save interps but:

#!/usr/bin/tclsh

set saveinterp [ interp create -safe ]
puts stderr "saveinterp created : $saveinterp"

set prompt      "\n>> "
set ::run 1
set ::ifd stdin
set ::ofd stdout

# I guess here you would insert some aliases and stuff
# for commands not present in the save interp to work
# ( in a save way, puts, exit, ... comes to mind )

# end of prelude

while {$::run} {
         puts -nonewline $::ofd \n$prompt ; flush $::ofd
         append script " "
         append script [ gets $::ifd ]
         if {[info complete $script]} {
                 catch { interp eval $saveinterp $script } cerr
                 puts -nonewline $::ofd $cerr ; flush $::ofd
                 unset script
                 set ::prompt "\n>> "
         } else {
                 set ::prompt "\n > "
         }

}

uwe
On May 18, 11:52 am, Uwe Klein <uwe_klein_habertw@t-online.de>
wrote:

Not sure how this works -- the idea I was hoping for was more along
the lines of a text editor that I would be able to embed in my Tcl/Tk
application for the user to perofrm tcl functions, string
manipulations, evaluations, etc.  from within the text widget.

Got any ideas on that?

Dave

davidhbige@simplifiedlogic.com wrote:
> ...
> Not sure how this works -- the idea I was hoping for was more along
> the lines of a text editor that I would be able to embed in my Tcl/Tk
> application for the user to perofrm tcl functions, string
> manipulations, evaluations, etc.  from within the text widget.

> Got any ideas on that?

If your Tcl/Tk application simply embedded tkcon (= sourceing tkcon.tcl)
, would that provide the sort of functionality that that you're after?
You probably need to make some modifications to make the interactive
interpreter safe.

References:
  http://tkcon.sourceforge.net/
  http://mini.net/tcl/tkcon

Erik
--
   leunissen@       nl | Merge the left part of these two lines into one,
e.          hccnet.   | respecting a character's position in a line.

davidhbige@simplifiedlogic.com schrieb:

> Good People,

> I have been considering adding an interactive shell to one of our
> stand alone applicaions.

> Any ideas on how to do this?

What are you actually trying to achieve?

One fast way is embedding the tkcon megawidget as a command shell.
(http://wiki.tcl.tk/17616)

Depending on your requirements (aka should users be able to block/kill
the app from the shell or not) you might want put the console into a
separate thread and in a safe interpreter there or just in a safe
interpreter.

If you put tkcon into a child interpreter (safe or not) you can then
export your application API with some interp aliases. I usually put my
external interface in one namespace and then use something like this to
init the aliases in the console interpreter:

foreach cmd [info commands ::external::*] {
    interp alias $consoleInterp $cmd {} $cmd

}

If you think about user written plugins, the pluginmgr module in tcllib
might be useful for you, it provides a safe interpreter sandbox with
definable APIs for plugins.
http://tcllib.sourceforge.net/doc/pluginmgr.html

Especially [exit] should be remapped in the child interpreter, to do
something sane for your app.

Michael

On May 19, 6:46 am, Erik Leunissen <l@the.footer.invalid> wrote:

YES - that is about PEREFCT - but Too MUCH!  Anyway to get rid of the
menus and all of that..?

Dave

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc