home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / tcl / 2465 < prev    next >
Encoding:
Text File  |  1993-01-23  |  4.7 KB  |  132 lines

  1. Newsgroups: comp.lang.tcl
  2. Path: sparky!uunet!eco.twg.com!twg.com!news
  3. From: "David Herron" <david@twg.com>
  4. Subject: Re: How difficult is a restricted tcl shell ?
  5. Message-ID: <1993Jan23.030504.3434@twg.com>
  6. Sensitivity: Personal
  7. Encoding:  112 TEXT , 4 TEXT 
  8. Sender: news@twg.com (USENET News System)
  9. Conversion: Prohibited
  10. Organization: The Wollongong Group, Inc., Palo Alto, CA
  11. Conversion-With-Loss: Prohibited
  12. Date: Sat, 23 Jan 1993 03:10:04 GMT
  13. Lines: 117
  14.  
  15. The last time this issue was brought up someone mentioned my work with
  16. adding multiple interpretor manipulation to TCL.  But back then I was
  17. on vacation, or for some other reason was too busy to respond then.
  18.  
  19. As Bruce suggested, different interpretors can very easily have different
  20. sets of commands.  One interpretor can have access to the full TCL while
  21. others have access to some small set of commands.
  22.  
  23. I have an extension to TCL I'm working on (slowly) which can do this
  24. from TCL.  It is nearing a releasable state.  Since there seems to be
  25. more demand for this feature than I have time to satisfy we might have
  26. to set up some kind of committee to further develop this module/extension.
  27. If you agree, send me mail to my home address (david@davids.mmdf.com) since
  28. this may take some time to develop and arrange, and it has no bearing
  29. on what I do here at twg.com.
  30.  
  31. What I have now is rather different from what was posted before.  It
  32. has been tweaked to improve the notation, and to provide support for
  33. object oriented programming -- an object being an interpretor.  So I
  34. had to first learn some fundamentals of OO programming before implementing
  35. TCL extensions for that purpose.
  36.  
  37. The facilities are:
  38.  
  39. interpretor create: The command is "interp new interp-name".  This creates
  40. an interpretor; puts an entry into a hashed table of interpretors; creates
  41. a command in one (or more) other interpretors which will execute commands
  42. in that other interpretor; creates a few needed commands in this new
  43. interpretor.
  44.  
  45. interpretor delete: The exit command in the interpretor is changed to
  46. call an interp destruction function.  There's also "interp delete interp-name".
  47.  
  48. accessing variables: Some of the commands given to the interpretor are
  49.  
  50.     -getVar name1 name1
  51.     -setVar name1 name2 value
  52.     -unsetVar name1 name2
  53.  
  54. So that you can access like: interp-name -getVar name1 name2
  55. or: $interp -getVar name1 name2
  56. or: set var [$interp -getVar name1 name2]
  57.  
  58. calling functions in other interpretor: interp-name command line
  59. or: interp-name {
  60.     complex; command; sequence; including;
  61.     proc definition{} {code }
  62.     }
  63.  
  64. The facilities go on and on.  There's also a C API to the module to
  65. use it in other ways.  For instance, the interp's are created knowing
  66. nothing but the basic TCL commands.  None of the TCLX or TK commands
  67. are known.  If you want a customized interp, you've gotta use the
  68. C API to create it.
  69.  
  70. I've written a file browser "object" which I'll post next week (or
  71. maybe over the weekend).  It shows lots of the interp facilities.
  72. The programming interface to the file browser object is like:
  73.  
  74.     wm minsize . 1 1
  75.     # Tell the interp module which is the "main interpretor" so
  76.     # it knows where to send unknown commands.
  77.     interp MainInterp
  78.  
  79.     # Load in the object definition.  Create the object and
  80.     # its visual look.
  81.     source $ooLibrary/FileBrowserC.tcl
  82.     set fb [FileBrowserClass new]
  83.     $fb MakeWidgets .fb
  84.     pack append . .fb {top fill expand}
  85.  
  86.     # Customize this particular instance.
  87.     $fb {
  88.         # Set beginning directory, filter.  Make the contents
  89.         # of it appear.
  90.         setDirectory "/tmp"
  91.         setPattern   "*"
  92.         changeDirectory
  93.  
  94.     # These are called when the OK and CANCEL buttons are pressed
  95.     proc okCommand {} {
  96.         set dir [getDirectory]
  97.         set file [getFile]
  98.         if {$dir != "" && $file != ""} {
  99.             puts stdout "$dir/$file"
  100.         }
  101.         MainInterp exit
  102.     }
  103.  
  104.     proc cancelCommand {} { MainInterp exit }
  105.     }
  106.  
  107. This program is pretty much what the test script for the filebrowser
  108. object is.  If you slap a "#! /usr/local/bin/wish -f" in front
  109. and named "queryFile", it could be used from a shell script like:
  110.  
  111.     FILE="`queryFile`"
  112.  
  113.  
  114.  
  115. This gets away from the original query of a way to have limited
  116. interpretors.  Sorry, this is what I've been working on and this
  117. is pretty cool by itself.  The limited interp's idea is very doable
  118. and requires some tweaking of my interp module.  I'm very interested
  119. in seeing that happen.
  120.  
  121. I offer to host a mailing list on my home system for this purpose.
  122. (Which means setting ServiceMail back up and making sure it
  123. can manipulate MMDF style mailing lists....!)
  124.  
  125. Again, send me mail at david@davids.mmdf.com about this!
  126.  
  127.  
  128. <- David Herron <david@twg.com> (work) <david@davids.mmdf.com> (home)
  129. <-
  130. <- "That's our advantage at Microsoft; we set the standards and we can change them."
  131. <- Karen Hargrove of Microsoft quoted in the Feb 1993 Unix Review editorial.
  132.