home *** CD-ROM | disk | FTP | other *** search
/ c't freeware shareware 1999 February / CT_SW9902.ISO / pc / software / wissen / daten / gnuplot.hqx / gnuplot.2.0b4 / gnuplotMode.tcl < prev    next >
Text File  |  1997-04-27  |  82KB  |  2,841 lines

  1. #  
  2. # "gnuplotMode.tcl"  
  3. #                                    created: 08/03/95 {16:53:59} 
  4. #                                last update: 12/23/96 {10:41:56 AM} 
  5. #  Author: Jeff Schindall
  6. #  E-mail: <mailto:schindall@nrl.navy.mil>
  7. #    mail: Naval Research Laboratory 
  8. #          Acoustics Division --- Code 7120
  9. #          4555 Overlook Ave SW
  10. #          Washington, DC, 20375 USA ]
  11. #    
  12. # gnuplotMode.tcl, Version 1.7?       For  gnuplot 3.6
  13. #
  14. # This is a set of TCL proc's that allow the shareware Macintosh 
  15. # text editor Alpha to serve as a front end for GNUPLOT for 
  16. # Macintosh version 3.6. This script requires Alpha 6.1 or later.
  17. #
  18. #############################################################################
  19. #    
  20.   
  21. proc donothinghereiamadummyprocedure16 {} {
  22.     insertText {#
  23.     
  24.  "Installation instructions:"
  25.   --------------------------- 
  26.  
  27.    First, "PRESS HERE"    
  28.    Now, save your preferences file.  Thats it!  
  29.  
  30.    Type "<control-shift-g>" to launch gnuplot mode.
  31.  
  32.  
  33.   
  34.  More Explicit Instructions:
  35.  ===========================
  36.  
  37.   ALPHA 6.2 or later:
  38.   -------------------
  39.     Drop this file in the Alpha:TCL:Modes folder.
  40.     Thats it!
  41.  
  42.   ALPHA (prior to version 6.2)
  43.   ----------------------------
  44.    For older versions of Alpha, drop this file into the
  45.    Alpha:TCL:usercode folder then add the following line to your
  46.    Prefs.tcl file:
  47.  
  48.      source "$HOME:tcl:usercode:gnuplotMode.tcl"
  49.  
  50.    Or wherever you choose to install the file.  I suppose you could 
  51.    install this in your Prefs folder instead...thats where I used to
  52.    keep it :)
  53.  
  54.  
  55.  Once sourced, you can launch the "console" by hitting the key
  56.  sequence:   "<shift-ctrl-g>"
  57.  
  58.  That's it!  Now all .gnu, .gnup, .gp, .GPLT, or .gnp files 
  59.  will automatically open into gnuplot mode.  
  60.  
  61.  Mac_gnuplot is available at: 
  62.    
  63.    "ftp://ftp.ee.gatech.edu/pub/mac/gnuplot" 
  64.  
  65.  Alpha is available at 
  66.  
  67.    "ftp://www.cs.umd.edu/pub/faculty/keleher/Alpha"
  68.  
  69.  More recent versions of this script are available at:
  70.     
  71.    "ftp://wave1m.nrl.navy.mil/pub/mac/gnuplotMode.tcl.sit.hqx"
  72.    
  73.  If you use latex/bibtex/c/c++ on the mac, then check out 
  74.  the VinceAdditions package in the Alpha/contrib directory.  
  75.  It is quite usefull...
  76.  
  77.  E-mail "me" if you have any questions/suggestions about gnuplotMode.tcl
  78.  
  79. }
  80.  
  81. }
  82.  
  83. ########################################################################
  84. #
  85. #  This mode was written by Jeff Schindall.  Some code was pinched from 
  86. #  other TCL files distributed with Alpha and matlab.tcl.
  87. #   
  88. #  Comments, suggestions, and bug reports should be sent to Jeff at
  89. #     mailto:schindall@nrl.navy.mil
  90. #
  91. #  You should be able to find the most recent current version of this
  92. #  gnuplotMode.tcl and the server app script at 
  93. #      
  94. #      ftp://ftp.ee.gatech.edu/pub/mac/gnuplot
  95. #
  96. #   and the most recent bleeding edge version at 
  97. #
  98. #      ftp://wave1m.nrl.navy.mil/pub/gnuplotMode.tcl.gz
  99. #
  100. #######################################################################
  101. #                                                                        
  102. #     Version History:                                                
  103. #                                                                        
  104. #         1.6    12/23/96                                                   
  105. #         -----------------------------------------------
  106. #         Floating palatte now very usefull.  User can run a script
  107. #         by selecting a script menu item, or edit the script by
  108. #         selecting the script menu item with the option key held down
  109. #
  110. #         1.5.9b    12/10/96                                                   
  111. #         -----------------------------------------------
  112. #         repaired broken scripts menu
  113. #         added a "edit scripts" menu----eventually, this one
  114. #         will go away, but the functionality will be retained
  115. #
  116. #         1.5.9    12/05/96                                                   
  117. #         -----------------------------------------------
  118. #         repaired broken pwd display
  119. #
  120. #         1.5.8    12/05/96                                                   
  121. #         -----------------------------------------------
  122. #         plot '-' now works
  123. #         pause in demo-mode works better
  124. #         added option to rebuild scripts menu
  125. #
  126. #         1.5.7    11/13/96                                                   
  127. #         -----------------------------------------------
  128. #         Check OUTP event for "Sorry, " string
  129. #         so that help for unknown item will be sent to console
  130. #         rather than a new output terminal page
  131. #
  132. #         1.5.6    11/07/96                                                   
  133. #         -----------------------------------------------
  134. #          Fixed a few floating menu buggers
  135. #
  136. #         1.5.5    11/06/96                                                   
  137. #         -----------------------------------------------
  138. #          Added a "Scripts" menu which auto loads any script
  139. #         in gnuplots "Scripts" folder (or subfolder)
  140. #         Made terminal output window creation faster
  141. #                                                                        
  142. #         1.5.4    11/05/96                                                   
  143. #         -----------------------------------------------
  144. #          Added terminal output windows for PS/TeX/MIF/etc.
  145. #                                                                        
  146. #         1.5.3    11/02/96                                                   
  147. #         -----------------------------------------------
  148. #          See 1.5.2
  149. #                                                                        
  150. #         1.5.2    11/02/96                                                   
  151. #         -----------------------------------------------
  152. #          Attempt to fix ome context switching weirdness
  153. #                                                                        
  154. #         1.5.1    10/23/96                                                   
  155. #         -----------------------------------------------
  156. #          Added some more apple event and floating palatte 
  157. #           options.
  158. #
  159. #         1.5    10/22/96                                                   
  160. #         -----------------------------------------------
  161. #          Slight bug fixes
  162. #
  163. #         1.5b3    07/18/96                                                   
  164. #         -----------------------------------------------
  165. #          Now works with Alpha 6.1 and higher.
  166. #         Added Floating menu...
  167. #
  168. #         1.5b2    07/16/96                                                   
  169. #         -----------------------------------------------
  170. #          Now works with Alpha 6.1 and higher.
  171. #
  172. #         1.5b1    07/02/96                                                   
  173. #         -----------------------------------------------
  174. #          Modify code so that it is compliant with the new
  175. #            mode conventions Pete added to 6.2 (see changes file).
  176. #         This script should still work for Alpha pre 6.2!
  177. #          Nifty self-installer!
  178. #                                                                          
  179. #                                                                          
  180. #         1.4.4    04/26/96                                                   
  181. #         -----------------------------------------------
  182. #          Modify trap for broken eventhandler on 68k                 
  183. #              so that pause works correctly and so that        
  184. #              gnuplot can bring itself to the front            
  185. #                                                                          
  186. #                                                                          
  187. #         1.4.3    04/24/96                                                  
  188. #         -----------------------------------------------
  189. #          Add trap for broken eventhandler on 68k                     
  190. #                                                                          
  191. #         1.4.2    04/17/96                                                
  192. #         -----------------------------------------------
  193. #          Let alpha do bookkeeping on globals                         
  194. #                                                                          
  195. #         1.4.1    04/15/96                                                       
  196. #         -----------------------------------------------
  197. #          Repaired broken quit and switchto menu options         
  198. #                                                                          
  199. #                                                                          
  200. #         1.4.0    04/14/96                                                       
  201. #         -----------------------------------------------
  202. #          GPLT mode preferences accessable from                  
  203. #            config:currentmode:flags... menu            
  204. #          Keyword coloring now works and is auto-sourced
  205. #            whenever GPTLPrefs.tcl is closed                          
  206. #          Reorganized and added to gnuplot menu            
  207. #          Reorganized all mode specifice procedures and 
  208. #             variable names                                        
  209. #                                                                          
  210. #                                                                          
  211. #         1.3.9    04/10/96                                                       
  212. #         -----------------------------------------------
  213. #          Keyword coloring editable from gnuplot pref menu.        
  214. #          gnuplot pref menu re-arranged                                  
  215. #          this package should display the path                       
  216. #             on the message bar                                              
  217. #                                                                          
  218. #                                                                          
  219. #         1.3.8    03/13/96                                                       
  220. #         -----------------------------------------------
  221. #          Re-arranged some code.                                  
  222. #                                                                                   
  223. #                                                                          
  224. #         1.3.7    03/13/96                                                       
  225. #         -----------------------------------------------
  226. #          Added support for cwd display on message bar    
  227. #                                                                                   
  228. #                                                                          
  229. #         1.3.6    02/26/96                                                       
  230. #         -----------------------------------------------
  231. #          Added graph button preference and repaired        
  232. #        my broken closeHook procedure                         
  233. #                                                                          
  234. #         1.3.5    02/01/96                                                       
  235. #         -----------------------------------------------
  236. #          Some minor fixes to console routines                
  237. #                                                                          
  238. #                                                                        
  239. #         1.3.4    02/01/96                                                       
  240. #         -----------------------------------------------
  241. #       Added "iconic" graph window which switches to             
  242. #               the gnuplot application                            
  243. #          Added a "gnuplot prefs" submenu                    
  244. #                                                                        
  245. #         1.3.3    12/20/95                                                       
  246. #         -----------------------------------------------
  247. #       Added Live History window                                       
  248. #          Added a function sub-menu                            
  249. #                                                                         
  250. #                                                                        
  251. #         1.3.2    12/15/95                                                       
  252. #         -----------------------------------------------
  253. #       History dump Really working this time.......           
  254. #          Included a kludge eventHander: GPIC EXEC        
  255. #             for Dave (temporary)                                
  256. #                                                                        
  257. #         1.3.1    12/14/95                                                       
  258. #         -----------------------------------------------
  259. #          Consolidated console and script editor modes.    
  260. #          Supports server once again.                           
  261. #       History dump working.......                            
  262. #                                                                        
  263. #                                                                        
  264. #         1.3    12/09/95                                                           
  265. #         -----------------------------------------------
  266. #          Should work with gnuplot app and              
  267. #          Fixed an "unknown" bug---thanks Vince            
  268. #          Files with gnuplot creator open in gnuplot mode
  269. #          Added several eventHandler's to work with the          
  270. #         gnuplot's new personality module                     
  271. #       NOTE:  No longer supports the gnuplot server app,      
  272. #              but I might add it back in later...             
  273. #                                                                        
  274. #         1.2.5    8/29/95                                            
  275. #         -----------------------------------------------
  276. #           File type as well as creator settings in place
  277. #                                                                        
  278. #                                                                        
  279. #         1.2.4    8/28/95                                            
  280. #         -----------------------------------------------
  281. #            I honestly don't recall                                
  282. #                                                                        
  283. #         1.2.3    8/27/95                                            
  284. #         -----------------------------------------------
  285. #           Fixed a few prompt related items.                
  286. #            I need to clean up the code a bit                
  287. #            especially in the console output routines        
  288. #                                                                        
  289. #         1.2.2    8/23/95                                            
  290. #         -----------------------------------------------
  291. #           Repaired help/prompting/etc which broke in    
  292. #                1.2.1                                                    
  293. #            DoSelection works for multiple lines            
  294. #                                                                        
  295. #                                                                        
  296. #         1.2.1    8/23/95                                            
  297. #         -----------------------------------------------
  298. #           Now works with unthreaded 68k systems                       
  299. #                                                                        
  300. #                                                                        
  301. #         1.2    8/23/95                                                
  302. #         -----------------------------------------------
  303. #           Deal w/"pause -1"     properly                                   
  304. #            cmd-dbl-click now works for all prompts         
  305. #            Cleaned up set output creator                        
  306. #                                                                          
  307. #                                                                        
  308. #         1.1    8/22/95                                                
  309. #         -----------------------------------------------
  310. #           Set output creators from gnuplot menu            
  311. #            Quit Working properly once again                    
  312. #            Added ERRP eventHandler for those w/o the             
  313. #          Thread Manager                                        
  314. #                                                                        
  315. #         1.0    8/21/95  (these release numbers are backwards)        
  316. #         -----------------------------------------------
  317. #           First working release                                 
  318. #                                                                        
  319. #    ============= Below were really beta's ==================== 
  320. #                                                                        
  321. #         1.0.6    8/17/95                                            
  322. #         -----------------------------------------------
  323. #           Cleaned up several procs                            
  324. #            Quit now works properly                                
  325. #                                                                        
  326. #                                                                        
  327. #         1.0.5    8/16/95                                            
  328. #         -----------------------------------------------
  329. #             replaced 'dosc' w/AEBuild                            
  330. #             added eventHandler  (thanks Dave)                    
  331. #             dumped "clean" window since Pete will            
  332. #                add this functionality to "new" in 6.0.2    
  333. #                                                                        
  334. #                                                                        
  335. #         1.0.4    8/12/95                                            
  336. #         -----------------------------------------------
  337. #             new modeVar to keep console "clean"             
  338. #                                                                        
  339. #                                                                        
  340. #         1.0.3    8/12/95                                            
  341. #         -----------------------------------------------
  342. #             Fixed bugs in closing console window            
  343. #             Added wristwatch cursor while waiting for gnuplot        
  344. #                                                                        
  345. #         1.0.2    8/11/95                                            
  346. #         -----------------------------------------------
  347. #         When console window is closed the gnuplot    
  348. #              app is quit and user is prompted to save    
  349. #          the Alpha/gnuplot history                        
  350. #                                                                        
  351. #         Command-Dbl-Click anywhere between gnuplot     
  352. #              prompts to select gnuplot output.  Nice        
  353. #          if you send term output to the console.        
  354. #                                                                        
  355. #         1.0.1    8/8/95                                            
  356. #         -----------------------------------------------
  357. #            Handles multiplot mode                                
  358. #             set output file CREATOR modeVar    (not yet)    
  359. #                                                                         
  360. #                                                                        
  361. #         1.0    8/7/95                                                
  362. #         -----------------------------------------------
  363. #            Now works with 3.6 (but not with 3.5)            
  364. #                                                                         
  365. #    =======================================================        
  366. #                                                                         
  367. #         0.4    8/3/95                                                
  368. #         -----------------------------------------------
  369. #           user specified colorizing through check pop-up       
  370. #             menu in GNUc console.  You must quit alpha and       
  371. #             restart to see the effects.  Also, you must          
  372. #         make sure that keywords and colors don't overlap.    # 
  373. #                                                              
  374. #                                                                        
  375. #         0.3    8/3/95                                                
  376. #         -----------------------------------------------
  377. #             Console position remembered between sessions
  378. #                                                                        
  379. #              Enabled command history to be dumped to a window        
  380. #                                                                  
  381. #                                                                        
  382. #         0.2    8/2/95                                                
  383. #         -----------------------------------------------
  384. #             Added a    Switch to gnuplot    menu option            
  385. #                                                                        
  386. #             Added Console modeVar                                        
  387. #                                                                        
  388. #         Added run in background modeVar                           
  389. #                                                                        
  390. #             Command History mostly working in console.    
  391. #                                                                        
  392. #             Cleaned    things up a    bit.                            
  393. #                                                                        
  394. #                                                                        
  395. #         0.1    8/1/95                                                
  396. #         -----------------------------------------------
  397. #             converted matlab.tcl to gnuplot.tcl            
  398. #                                                                        
  399. #                                                                        
  400. ###############################################################
  401.  
  402.  
  403. #############################################################################
  404. #
  405. # Autoload procedures
  406. #
  407. #
  408.  
  409. if { [info exists  startingUp] } {
  410. if {[string match {[6-9].[2-9]*}   [lindex [version] 2] ]} {
  411.   if {$startingUp} {
  412.     addMode GPLT dummyGPLT {*.gp *.gnu *.gnp *.gplt *.GP *.GNU *.GNP *.GPLT }  \
  413.          GPLTMenu 
  414.     addMenu GPLTMenu
  415.    #return
  416.   } else {
  417.     
  418.     lappend modes GPLT
  419.      lappend modeSuffixes     {*.gnu *.gnp *.gnup *.gplt *.gp}   \
  420.      { set winMode GPLT }
  421.     lappend modeSuffixes     {*.GNU *.GNP *.GNUP *.GPLT *.GP}   \
  422.      { set winMode GPLT }
  423.  }
  424. }
  425.  
  426. } else {
  427.     
  428.     lappend modes GPLT
  429.      lappend modeSuffixes     {*.gnu *.gnp *.gnup *.gplt *.gp}   \
  430.      { set winMode GPLT }
  431.     lappend modeSuffixes     {*.GNU *.GNP *.GNUP *.GPLT *.GP}   \
  432.      { set winMode GPLT }
  433.  }
  434.  
  435.  
  436.  
  437. proc dummyGPLT  {} {}
  438. proc GPLTMenu {} {}
  439.  
  440. # use the gnuplot icon if its available
  441. if {( [string trim [lindex [version] 2] {,}]< "6.01")} {
  442.     set GPLTMenu  "gnuplot"
  443. } else {
  444.     set GPLTMenu  "•415"
  445. }
  446.  
  447. # Set GLOBAL mode binding to bring up gnuplot Console
  448. bind 'g' <sz> { GP_Console  }
  449. bind 'n' <sc> { GP_NewWindow  }
  450.  
  451. newModeVar GPLT elecRBrace        {0} 1
  452. newModeVar GPLT prefixString      {# } 0
  453. newModeVar GPLT electricSemi      {0} 1
  454. newModeVar GPLT wordBreak         {[a-zA-Z0-9_]+} 0
  455. newModeVar GPLT elecLBrace        {0} 1
  456. newModeVar GPLT wordWrap          {0} 1
  457. newModeVar GPLT wordBreakPreface  {[^a-zA-Z0-9_]} 0
  458. newModeVar GPLT tabSize           {3} 0
  459. newModeVar GPLT prefixString          {# } 0
  460. newModeVar GPLT NevrSavHist       {0} 1
  461. newModeVar GPLT LiveHist              {1} 1
  462. newModeVar GPLT GraphButton          {1} 1
  463. newModeVar GPLT EventHandler          {1} 1
  464. newModeVar GPLT bracesColor blue 0
  465. newModeVar GPLT bracesColor blue 0
  466. newModeVar GPLT stringColor green 0
  467. newModeVar GPLT commentColor red 0
  468. #newModeVar GPLT 
  469. set gpTermCt 0
  470.  
  471. ###BGK
  472.    # (DO NOT ERASE Previous line)
  473.    # 
  474.    # NOTE:  Some coloring is controlled via 
  475.    #        Config:current mode:flags... menu
  476.    #
  477.  
  478.       ### BLUE words ###
  479.  
  480. set gpBlueWords { 
  481.     console  set show plot splot \\
  482.     autoscale      binary         boxxyerrorbars bugs
  483.     call           cd             clear          co-ordinates
  484.     comments             environment    exit
  485.     expressions    fit                       if
  486.     introduction   line-editing   load           pause
  487.     plot           print          pwd            quit
  488.     replot         reread         reset          save
  489.     seeking-assistance set            shell          show
  490.     splot          startup        style          substitution
  491.     test           update         userdefined    xyerrorbars
  492.     xerrorbars yerrorbars
  493.     "Copyright(C) 1986 - 1995" "Copyright(C) 1986 - 1996"
  494.  
  495.  
  496.  
  497.       ### RED words ###
  498.  
  499. set gpRedWords { 
  500.     topics available: Subtopics available  
  501.     server macintosh Press return for more: Help topic: 
  502.     Subtopic of {G N U P L O T} {(pre 3.6)}  3.5 3.6 
  503.     version for 68k ppc Power Macintosh patchlevel 
  504.     last modified first second
  505.  
  506.  
  507.      ### GREEN WORDS ###
  508.  
  509. set gpGreenWords {  
  510.     ranges         smooth         data-file      datafile          
  511.     parametric     locale         nosquare       errorbars
  512.     gnuplot        gnuplot>       term           square         
  513.     angles         arrow          autoscale      bar
  514.     bmargin        border         boxwidth       clabel
  515.     clip           cntrparam      contour        data
  516.     dgrid3d        dummy          encoding       format
  517.     function       grid           hidden3d       isosamples
  518.     key            keytitle       label          lmargin
  519.     logscale       mapping        margin         missing
  520.     multiplot      mx2tics        mxtics         my2tics
  521.     mytics         mztics         noarrow        noautoscale
  522.     noborder       noclabel       noclip         nodgrid3d
  523.     nokey          nolabel        nologscale     nomultiplot
  524.     nomx2tics      nomxtics       nomy2tics      nomytics
  525.     nomztics       noparametric   nopolar        nosurface
  526.     nox2dtics      nox2mtics      nox2tics       nox2zeroaxis
  527.     noxdtics       noxmtics       noxtics        noxzeroaxis
  528.     noy2dtics      noy2mtics      noy2tics       noy2zeroaxis
  529.     noydtics       noymtics       noytics        noyzeroaxis
  530.     nozdtics       nozeroaxis     nozmtics       noztics
  531.     offsets        origin         output         parametric
  532.     pointsize      polar          punctuation    rmargin
  533.     rrange         samples        size           specify
  534.     style          surface        syntax         terminal
  535.     tics           ticscale       ticslevel      time
  536.     timefmt        title          tmargin        trange
  537.     urange         view           vrange         x2dtics
  538.     x2label        x2mtics        x2range        x2tics
  539.     x2zeroaxis     xdata          xdtics         xlabel
  540.     xmtics         xrange         xtics          xzeroaxis
  541.     y2dtics        y2label        y2mtics        y2range
  542.     y2tics         y2zeroaxis     ydtics         ylabel
  543.     ymtics         yrange         ytics          yzeroaxis
  544.     zdtics         zero           zeroaxis       zlabel
  545.     zmtics         zrange         ztics
  546.     threaded  
  547.  
  548.  
  549.  
  550.     ### MAGENTA WORDS ###
  551.  
  552. set gpMageWords  { 
  553.     with lines using  points  multiplot> mac gx eps enh
  554.     info-gnuplot dartmouth edu bug-gnuplot { \@ }
  555.     Send comments and requests for help to
  556.     Send bugs, suggestions and mods to
  557.                    
  558.  
  559.  
  560.     ### CYAN WORDS ###
  561.  
  562. set gpCyanWords  {   post mac     macintosh      texdraw
  563.     aifm           atari          dumb           enhpost
  564.     epson          epson180       epson60        fig
  565.     gpic           hpljii         imagen         iris4d
  566.     latex          linux          mf             mif
  567.     mtos           nec-cp6        pbm            pcl5
  568.     postscript     pslatex        regis          starc
  569.     table          tandy60        tgif           uniplex
  570.     vdi            windows        unknown        pstricks
  571.     png            dxf            cgm            gif
  572.     emtex          pstex          eepic          tpic
  573.     pstricks       texdraw
  574.     Thomas Williams, Colin Kelley and many others 
  575.     Russell Lang, Dave Kotz, John Campbell. Gershon Elber
  576.  
  577. #
  578. # Color keywords for GPLT mode
  579. #
  580. regModeKeywords  -i "\}" -i "\{"  -i ">" -i "<" -i ")" -i "("  -i "/" -i "\\"  \
  581.     -i "\]" -i "\[" -i "\$" -i "\'" -i "\`" -i ">" -i "<" -i "^" -i "_" \
  582.     -I $GPLTmodeVars(bracesColor) \
  583.      -e {#} -c $GPLTmodeVars(commentColor) \
  584.     -s $GPLTmodeVars(stringColor)  \
  585.     -k red GPLT $gpRedWords
  586. regModeKeywords -a -k blue GPLT $gpBlueWords
  587. regModeKeywords -a -k green GPLT $gpGreenWords
  588. regModeKeywords -a -k magenta GPLT $gpMageWords
  589. regModeKeywords -a -k cyan GPLT $gpCyanWords
  590.  
  591. #  (DO NOT ERASE NEXT TWO LINES)
  592. ###EGK
  593.  
  594.  
  595.  
  596. #define saved globals
  597. if { ![info exists gp_FSIG]}  { set gp_FSIG                  {GPLT} } 
  598. if { ![info exists gp_CREA]}  { set gp_CREA                  {ALFA} } 
  599. if { ![info exists gp_TYPE]}  { set gp_TYPE                  {TEXT} } 
  600. if { ![info exists gp_CreatorList]}  { set gp_CreatorList [list] }
  601. if { ![info exists gp_TypeList]}  { set gp_TypeList [list] }
  602. if { ![info exists gp_CreatorNames]} { set gp_CreatorNames [list] }
  603. if { ![info exists gp_GEOM] } {set gp_GEOM [list]}
  604. if { ![info exists gp_HistGEOM] } {set gp_HistGEOM [list ]}
  605. if { ![info exists headerSuffices] } {set headerSuffices {$GPLTmodeSuffixes}}
  606. if { ![info exists sourceSuffices] } {set sourceSuffices {$GPLTmodeSuffixes}}
  607.  
  608. if {[llength $gp_CreatorList] == 0 \
  609.  || [llength $gp_CreatorList] != [llength $gp_CreatorNames] \
  610.  || [llength $gp_CreatorList] != [llength $gp_TypeList]} {
  611.     set gp_CreatorList [list ALFA GPLT]
  612.     set gp_TypeList [list  TEXT TEXT]
  613.     set gp_CreatorNames [list  alpha gnuplot]
  614.     set gp_CREA {ALFA} 
  615.     set gp_TYPE {TEXT}
  616. }
  617.  
  618. #remove unused, previously saved globals
  619. if { [info exists GPLTmodeVars(FSIG)]}  { removeArrDef  GPLTmodeVars FSIG
  620.                                                         unset GPLTmodeVars(FSIG)
  621.                                                      } 
  622. if { [info exists GPLTmodeVars(CREA)]}  { removeArrDef  GPLTmodeVars  CREA
  623.                                                         unset GPLTmodeVars(CREA)
  624.                                                      } 
  625. if { [info exists GPLTmodeVars(TYPE)]}  { removeArrDef  GPLTmodeVars TYPE
  626.                                                         unset GPLTmodeVars(TYPE)
  627.                                                      } 
  628.  
  629.  
  630. #############################################################################
  631. #
  632. #  global variables
  633. #
  634.  
  635. set gp_CommandHist [list]
  636. set gp_CommandNum 0
  637.  
  638. set gp_Prompt       "gnuplot> "
  639. set gp_MultiPrompt  "multiplot> "
  640. set gp_ContPrompt   "> "
  641. set gp_HelpPrompt   ": "
  642.  
  643. set gp_Prompts [list $gp_Prompt $gp_ContPrompt $gp_MultiPrompt ]
  644.  
  645. set gp_Console  "* gnuplot *"
  646. set gp_Hist     "* history *"
  647. set gp_Graph     "* graph *"
  648. set gp_sl [list]
  649.  
  650. #############################################################################
  651. #
  652. #  Bind some keys
  653. #
  654.  
  655. # Editing .gnu files
  656.  
  657. bind '\r' <z>  GP_DoLine             "GPLT"
  658.  
  659. # Command Window
  660.  
  661. bind '\r'      GP_CarriageReturn     "GPLT"
  662. bind up        GP_PrevCommand        "GPLT"
  663. bind down      GP_NextCommand        "GPLT"
  664. bind '1'  <c>  GP_Console            "GPLT"
  665. bind '2'  <c>  GP_Activate           "GPLT"
  666. bind '3'  <c>  GP_DumpHistory        "GPLT"
  667. bind 'f'  <sc>  GP_SaveAndExecute    "GPLT"
  668.  
  669.  
  670. # Repeat menu keys for command window
  671.  
  672.  
  673. set gp_Launched {0}
  674.  
  675.  
  676.  
  677.  
  678. set pathComments(GPLTPath)    "gnuplot"
  679.  
  680. #############################################################################
  681. #
  682. #  gnuplot Menu stuff
  683. #
  684.  
  685.  menu -n    $GPLTMenu -p GPLTMenuItem    {                         
  686.      "/1console"                                                     
  687.      "/2graph"                                                     
  688.      "/3history"                                                     
  689.     "(-"    
  690.      "setWorkingFolder..."
  691.      "/P<UchoosePlotFile..."
  692.       "/L<Uload..."                                         
  693.      {menu -n "saveSettings" -p GPLTMenuItem  {
  694.                   "/S<Uall"                  
  695.                  "(-"
  696.                  "setCmds" 
  697.                  "functions"         
  698.                 "variables"    
  699.             }
  700.      }
  701.      "(-"                                                                                                                                  
  702.      "/N<UnewScriptWin"                                                 
  703.       "/F<UsaveAndExecute"                                         
  704.     "(-"    
  705.      {menu  -s -m -n mathFunctions -p GPLTMenuItem  {
  706.          {menu  -s -m -n Trigonometric -p GPLTMenuItem  {
  707.         "cos"
  708.         "tan"
  709.         "sin"
  710.          }}
  711.          {menu  -s -m -n InverseTrig -p GPLTMenuItem  {
  712.          "acos"
  713.          "asin"
  714.         "atan"         
  715.         }}
  716.          {menu  -s -m -n Hyperbolic -p GPLTMenuItem  {
  717.         "cosh"
  718.         "sinh"
  719.         "tanh"
  720.         }}
  721.          {menu  -s -m -n special -p GPLTMenuItem  {
  722.         "erf"            
  723.         "erfc"           
  724.         "inverf"                                  
  725.         "(-"
  726.         "gamma"                                       
  727.         "igamma"                        
  728.         "lgamma"                                      
  729.         "(-"
  730.         "ibeta"                                        
  731.          }}
  732.          {menu  -s -m -n bessel -p GPLTMenuItem  {
  733.         "besj0"
  734.         "besj1"
  735.         "besy0"
  736.         "besy1"         
  737.         }}
  738.         "(-"
  739.         "abs"  
  740.         "arg"               
  741.         "sgn"     
  742.         "sqrt"
  743.         "(-"
  744.         "exp"
  745.         "log"
  746.         "log10"                                  
  747.         "(-"
  748.         "ceil"           
  749.         "floor" 
  750.         "rand"
  751.         "norm"
  752.         "invnorm"
  753.         "(-"
  754.         "real" 
  755.         "imag"
  756.         "int"
  757.             }
  758.         }
  759.      "(-"    
  760.      "/M<UdoSelection"                                             
  761.      "doLine"                                                         
  762.      "(-"
  763.      {menu -n gnuplotOptions -p GPLTMenuItem     {         
  764.         "setPointSize..."
  765.          "(-"    
  766.         "/H<UclearHistory"
  767.          "(-"    
  768.           {menu -n setOutputCreator -p GPLTMenuItem     {         
  769.             "select..."                                                 
  770.             "add..."                                                     
  771.              "delete..."                                                 
  772.             }                                                                 
  773.         }    
  774.         "keywordColoring..."                
  775.          }
  776.     }                
  777.     "readme..."
  778.      "/2switchTo gnuplot"                                         
  779.      "/Q<Uquit gnuplot"                                             
  780.  }                                                                         
  781.                                                                              
  782.  
  783.      # Attempt to overload the following command keys:
  784.      #
  785.        #  Command-1  :  Console
  786.         #  Command-2  :  Graph
  787.         #  Command-3  :  History
  788.                         
  789.                         
  790.                         
  791.  proc    GPLTMenuItem {menu item} {                                 
  792.  #global GPLTMenu                                                     
  793.      switch $item {                                                 
  794.             "console"                GP_Console                     
  795.             "graph"                     GP_Activate                     
  796.             "gnuplot"                     GP_Activate                     
  797.             "history"                GP_DumpHistory                     
  798.             "newScriptWin"            GP_NewWindow         
  799.             "choosePlotFile..."        GP_ChoosePlotFile         
  800.             "saveAndExecute"         GP_SaveAndExecute         
  801.             "load..."                 GP_LoadScript             
  802.             "all"                     { GP_SaveSettings "" }             
  803.             "setCmds"                 { GP_SaveSettings "set" }             
  804.             "functions"                 { GP_SaveSettings "fun" }             
  805.             "variables"                 { GP_SaveSettings "var" }             
  806.             "doSelection"             GP_DoSelection             
  807.             "doLine"                    GP_DoLine                          
  808.             "switchTognuplot"        GP_Activate                 
  809.             "select..."                 GP_SelectCreator         
  810.             "add..."                     GP_AddCreator             
  811.             "delete..."                 GP_DeleteCreator         
  812.             "clearHistory"            GP_ClearHistory             
  813.             "quitgnuplot"             GP_Quit                     
  814.             "keywordColoring..."        editCurrentModePrefs
  815.             "setWorkingFolder..."   GP_SetCWD
  816.             "setPointSize..."       GP_SetPTSZ
  817.             "readme..."                 GP_Readme
  818.             "labels..."                { GP_Dialog "labl" }
  819.             "linestyles..."            { GP_Dialog "line" }
  820.             "textformat..."            { GP_Dialog "text" }
  821.              "labels..."                { GP_Dialog "labl" }
  822.              "gxText"                { GP_Dialog "gxtx" }
  823.              "offsets..."             { GP_Dialog "oset" }
  824.             default                    { insertText [string tolower $item ] () 
  825.                                           backwardChar    
  826.                                      }
  827.             }                                                                 
  828.  }                                                                         
  829.                                                                              
  830. #############################################################################
  831. #
  832. #  setup the event handler for Alpha/gnuplot interapp communication
  833. #   Currently only works in the Alpha 6.01 PPC 
  834. #
  835.  
  836. if { (   [string match {[6-9].[2-9]*}  [lindex [version] 2] ] ) | \
  837.      ( (   0 != [string first {(68k)}  [lindex [version] 1] ] ) & \
  838.        ( [string match {[6-9].?[1-0]*} [lindex [version] 2] ] ) ) } {
  839.    # Setup event Handler for STDOUT
  840.       eventHandler GPSE OUTP "GP_STDOUThandler"  
  841.     
  842.     # Setup event Handler for systems w/o ThreadManager
  843.       eventHandler GPSE ERRP "GP_STDERRhandler"
  844.     
  845.     # *ICInitializeCommand // This initializes the console.  
  846.     # Alpha eventhandler is needed.
  847.     # 'GPIC init'
  848.      eventHandler GPIC init "GP_ConsoleH"
  849.     # 
  850.     # *ICInitializePath // sends the working directory as 
  851.    # stored in preferences.
  852.     # Since you aren't displaying the working directory anywhere, 
  853.    # we can ignore
  854.     # this for now.
  855.     # 'GPIC path', contains a string in the direct object.
  856.      eventHandler GPIC path "GP_SendPath"
  857.     # 
  858.     # ICExecute // Tells the console to execute a gnuplot command.  
  859.    # I can't think
  860.     # of a reason for this one in Alpha.  The menuing system uses 
  861.    # this one in the current console.  We could define an event however.
  862.     # 
  863.     # 
  864.     # ICInsertCommand // Might be slick.  An example of what this 
  865.    # does is where
  866.     # functions get pasted into the command line.  Not absolutely necessary
  867.     # though.
  868.    # 'GPIC' 'inse'
  869.     eventHandler GPIC inse "GP_INSEhandler"
  870.     # 
  871.     # ICComeToFront  // The function will bring Alpha to the front.  
  872.    # No handler needed.
  873.     # 
  874.     # *ICBringGnuplotToFront // Handler needed.  When you get this one, bring
  875.     # gnuplot to the front.
  876.     # 'GPIC tofr'
  877.      eventHandler GPIC tofr "GP_ActivateH"
  878.     # 
  879.     # *ICHandleAEReply // You'll get this one if somebody used a 
  880.    # gnuplot menu to
  881.     # do something which necessitated a reply from gnuplot. The 
  882.    # gnuplot interface
  883.     # will pass the reply to you for display.
  884.     # 'GPIC repl', handle this one just like the reply from your exec event.
  885.      eventHandler GPIC repl "GP_STDERRhandler"
  886.     # 
  887.     # *ICMakeNewDocument  // It sounds like this one is working already.
  888.     # 'core crel'
  889.      eventHandler core crel "GP_NewWindowH"
  890.     # 
  891.     # *ICOpenDocument // Alpha already knows about this one.
  892.     # --already defined in alpha---
  893.  
  894.     # The event 'GPIC' 'cbye' is now sent whenever gnuplot quits.
  895.    # This will let you close the console if somebody quits 
  896.    # gnuplot some other way. You could
  897.     # use this to eliminate your 'quit' trapping if you want.
  898.      eventHandler GPIC cbye "GP_CloseH"
  899.     # I also defined a new event: 'GPIC' 'EXEC'.  All you need to 
  900.    # do is take the
  901.     # data and send it back to gnuplot as a 'GPSE' 'exec' event. 
  902.    # This is a kludge
  903.     # to make the commands in the gnuplot app menus work. 
  904.    # It will eventually go away.
  905.      eventHandler GPIC EXEC "GP_Kludge"
  906.     
  907.     proc GP_Kludge {it} {
  908.        set outit  [GP_filtercurlyq $it]
  909.       GP_STDERR $outit
  910.       if { $it == "Unable to find process" } GP_Quit
  911.       return 0
  912.      }    
  913.      
  914.     proc GP_STDERRhandler {it} {
  915.         global gp_cwd
  916.         set outit  [GP_filtercurlyq $it]
  917.         GP_ExtractPath $it
  918.         GP_Results $outit
  919.         if { $it == "Unable to find process" } GP_Quit
  920.        return 0
  921.     }
  922.     
  923.     proc GP_STDOUThandler {it} {
  924.         global gp_cwd gp_Out gpTermCt
  925.         global winModes gp_Console gp_Graph winModes 
  926.         global GPLTmodeVars gp_Launched gp_GEOM
  927.         global gp_Prompt  gp_cwd GPLTMenu 
  928.     
  929.         set outit  [GP_filtercurlyq $it]
  930.         GP_ExtractPath $it
  931.         set wins [winNames]    
  932.         
  933.         set itLen [ string length "$it" ]
  934.         set termID [ string range "$outit" 0 20 ]
  935.         set termType [ string range "$it" [expr $itLen -25] [expr $itLen -1] ] 
  936.         
  937.         if { [ string first "Sorry," "$termID" ] == 0 } {
  938.             insertText -w  $gp_Console "\n$outit"
  939.             return
  940.             
  941.         } elseif { [ string first "% GNUPLOT: LaTeX" "$termID" ] == 0 } {           
  942.             incr gpTermCt 1
  943. #            set gp_Out [getline "Enter name of output console?" "* TeX output $gpTermCt *" ]
  944.             set gp_Out "* TeX output $gpTermCt *"
  945.             set theMode "TeX"
  946.             
  947.         } elseif { [string first "%!PS-Adobe" "$termID" ] == 0 } {
  948.             incr gpTermCt 1
  949. #            set gp_Out [getline "Enter name of output console?" "* PS output $gpTermCt *" ]
  950.             set gp_Out "* PS output $gpTermCt *"
  951.             set theMode "PS"
  952.             
  953.         } elseif { [string first "<MIFFile 3.00>" "$termID" ] == 0 } {
  954.             incr gpTermCt 1
  955. #            set gp_Out [getline "Enter name of output console?" "* MIF output $gpTermCt *" ]
  956.             set gp_Out "* MIF output $gpTermCt *"
  957.             set theMode "PS"
  958.             
  959.         } elseif { [string first "% GNUPLOT: dxf" "$termID" ] >= 0 } {
  960.             incr gpTermCt 1
  961. #            set gp_Out [getline "Enter name of output console?" "* misc output $gpTermCt *" ]
  962.             set gp_Out "* misc output $gpTermCt *"
  963.             set theMode "TEXT"
  964.             
  965.         } elseif { [string first "if unknown cmbase" "$termID" ] == 0 } {
  966.             incr gpTermCt 1
  967. #            set gp_Out [getline "Enter name of output console?" "* MF output $gpTermCt *" ]
  968.             set gp_Out "* MF output $gpTermCt *"
  969.             set theMode "TeX"
  970.             
  971.         } elseif { [string first "#Curve" "$termID" ] == 0 } {
  972.             incr gpTermCt 1
  973. #            set gp_Out [getline "Enter name of output console?" "* misc output $gpTermCt *" ]
  974.             set gp_Out"* misc output $gpTermCt *"
  975.             set theMode "TEXT"
  976.             
  977.         } elseif { [ string index "$termID" 0  ] == " " && [ string first "TERM:“dumb”" "$termType" ] > 0 } {
  978.             set ns "\n"
  979.             append ns $outit
  980.             set outit "$ns"
  981.             set gp_Out $gp_Console
  982.             #set theMode "TEXT"
  983.  
  984.         } elseif { ![info exists gp_Out ] || [lsearch $wins $gp_Out ] < 0 } {
  985.             incr gpTermCt 1
  986. #            set gp_Out [getline "Enter name of output console?" "* misc output $gpTermCt *" ]
  987.             set gp_Out "* misc output $gpTermCt *"
  988.             set theMode "TEXT"
  989.         }
  990.  
  991.         if { $gp_Out == "" } {set gp_Out $gp_Console }
  992.         
  993.         if {  [lsearch $wins $gp_Out ]  < 0 } { 
  994.             new  -n $gp_Out
  995.             #set wins [winNames]
  996.             set gp_Out [lindex [winNames] 0]
  997.             changeMode [set winModes([lindex [winNames] 0]) $theMode ]
  998.         } else {
  999.             #catch [ bringToFront $gp_Out ] ans
  1000.             #if { ![info exists ans] } { return }
  1001.         }
  1002.         
  1003.         insertText -w $gp_Out $outit
  1004.         GP_Console
  1005.         if { $it == "Unable to find process" } GP_Quit
  1006.        return 0
  1007.     }
  1008.     
  1009.     proc GP_INSEhandler {it} {
  1010.     global gp_Console gp_TYPE gp_CREA gp_FSIG
  1011.         set res [GP_filtercurlyq $it]
  1012.         set wins [winNames]
  1013.         if { ( "$res" != "\n" ) & ( "$res" != "" ) & ( "$res" != "\r" ) } {
  1014.             if { [ lsearch $wins $gp_Console  ] >= 0} {
  1015.                 bringToFront $gp_Console    
  1016.             }        
  1017.         }        
  1018.         
  1019.         goto [maxPos]        
  1020.         insertText -w $gp_Console $res
  1021.         
  1022.        
  1023.        set paren  [string first "()" $res ]
  1024.  
  1025.        if { $paren >= 1 } {
  1026.            goto [expr [maxPos] - $paren + 2]
  1027.        }
  1028.               
  1029.        if { "$res" == "\r" }  {
  1030.           GP_SendCommand "" 3600
  1031.        } elseif { "$res" == "\n" }  {
  1032.           GP_SendCommand "" 3600 
  1033.        } elseif { "$res" == "" }  {
  1034.           GP_SendCommand "" 3600
  1035.        } else {
  1036.             return 0
  1037.        }
  1038.           
  1039.           
  1040.     }
  1041.  
  1042.  
  1043.    proc GP_SendPath { dummyVar } {
  1044.        global gp_cwd
  1045.       # display current path on status bar
  1046.          set gp_cwd [ GP_filtercurlyq $dummyVar ]
  1047.          message "Current gnuplot Path ==> $gp_cwd"
  1048.     }
  1049.  
  1050.     proc GP_ConsoleH { dummyVar } { 
  1051.        GP_Console   
  1052.        # this is a dummy routine
  1053.     }  
  1054.  
  1055.     proc GP_NewWindowH { dummyVar } { 
  1056.         switchTo 'ALFA'
  1057.         GP_NewWindow   
  1058.        # this is a dummy routine
  1059.     }  
  1060.  
  1061.     proc GP_ActivateH { dummyVar } { 
  1062.        GP_Activate   
  1063.        # this is a dummy routine
  1064.     }  
  1065.  
  1066.     proc GP_CloseH { dummyVar } { 
  1067.        GP_Quit   
  1068.        # this is a dummy routine
  1069.     }  
  1070.  
  1071.  } else { set GPLTmodeVars(EventHandler) 0 }
  1072.  
  1073.  
  1074. #############################################################################
  1075. #
  1076. #  Find and launch gnuplot
  1077. #
  1078. #
  1079.  
  1080. proc GP_Check {} {
  1081.     global GPLTMenu  gp_Launched appName GPLTPath  GPLTmodeVars gp_FSIG
  1082.     global modifiedVars
  1083.                    
  1084.     # Check if gnuplot app is running.  If not, open the app named in 
  1085.     # $ (if defined) or have the user select an app via a
  1086.     # standard file dialog.  Leave the gnuplot app in the background.
  1087.    
  1088.       set appName [checkRunning gnuplot {GPSE GPLT}  GPLTPath 1]
  1089.     if { $appName != {} } {
  1090.         foreach proc [processes] {
  1091.                 # if a running app has the correct sig, ...
  1092.                 if {[lsearch -exact {GPSE GPLT} [lindex $proc 1] ] >= 0} {
  1093.                 # ...then return its name.
  1094.                         set gp_FSIG  [lindex $proc 1]
  1095.                       set gp_Launched 1
  1096.                       enableMenuItem $GPLTMenu "quit gnuplot" on
  1097.                       enableMenuItem $GPLTMenu "graph" on
  1098.                       enableMenuItem $GPLTMenu "history" on
  1099.                       lappend modifiedVars  GPLTPath          
  1100.                       lappend modifiedVars  gp_FSIG          
  1101.                       enableMenuItem $GPLTMenu "saveSettings" on  
  1102.                       enableMenuItem gnuplotOptions "setPointSize..." on  
  1103.                       enableMenuItem $GPLTMenu "setWorkingFolder..." on
  1104.                       enableMenuItem $GPLTMenu "choosePlotFile..."     on
  1105.                }
  1106.             }
  1107.         #switchTo 'ALFA'
  1108.         return {0}
  1109.     } 
  1110.     #gnuplotClear
  1111.    return {-1}
  1112. }
  1113.  
  1114. #############################################################################
  1115. #
  1116. #  Goto command window
  1117. #
  1118. proc GP_Console {  } {
  1119. global gp_Console winModes  GPLTmodeVars 
  1120. global gp_Launched gp_Prompt 
  1121.    
  1122.     # Check if gnuplot app is running.  If not, open the app named in 
  1123.     # $ (if defined) or have the user select an app via a
  1124.     # standard file dialog.  Leave the gnuplot app in the background.
  1125.    
  1126.     set wins [winNames]
  1127.     if { [lsearch $wins $gp_Console ]  >= 0} {
  1128.         bringToFront $gp_Console
  1129.         goto [maxPos]
  1130.     } else   {
  1131.         GP_NewConsole
  1132.     }  
  1133. }
  1134.  
  1135.  
  1136. #############################################################################
  1137. #
  1138. #  Create  command window
  1139. #
  1140. proc GP_NewConsole { } {
  1141.     global winModes gp_Console gp_Graph winModes gp_Path
  1142.     global  GPLTmodeVars gp_Launched gp_GEOM GP_GraphMenu
  1143.     global gp_Prompt  gp_cwd GPLTMenu  gp_home gp_scriptItems
  1144.  
  1145.     if {[llength $gp_GEOM] != "4" } {            
  1146.         GP_Readme
  1147.         new -n $gp_Console
  1148.         changeMode GPLT
  1149.         set gp_GEOM [ getGeometry $gp_Console ] 
  1150.     }   
  1151.     set wd [lindex $gp_GEOM 2]
  1152.     set ht [lindex $gp_GEOM 3]
  1153.     set top [lindex $gp_GEOM 1]
  1154.     set left [lindex $gp_GEOM 0]
  1155.     set gY [expr $top - 15]
  1156.     set gX [expr $left + $wd + 5]
  1157.     set gW [expr 72 ]
  1158.     set gH [expr 50 ]
  1159.  
  1160.     set wins [winNames]    
  1161.     if {  [lsearch $wins $gp_Console ]  < 0 } { 
  1162.             new -g $left $top $wd $ht -n $gp_Console
  1163.             newMode GPLT
  1164.     }
  1165.     catch { setWinInfo -w $gp_Console shell 1 } jjj
  1166.     GP_GraphButton
  1167.     if { $GPLTmodeVars(LiveHist) } GP_DumpHistory
  1168.     insertText -w $gp_Console  "\nWelcome to Alpha's gnuplot 3.6 shell.\n" 
  1169.     GP_Check
  1170.     bringToFront $gp_Console
  1171.     
  1172.      set res [ GP_STDERR ""  3600 ]
  1173.      insertText -w $gp_Console "$res"
  1174.      
  1175.      # The following is a huge kludge...to deal with accidentally
  1176.      # closing the gnuplot window
  1177.      if    { $res == "" }    {
  1178.              GP_Results "gnuplot> "
  1179.      }
  1180.      # end kludge
  1181.           
  1182.      # Now setup the CLIE
  1183.      if {[string first "Using threaded console."  $res ] != {-1} \
  1184.        | [string first "ppc" [string tolower $res ] ] != {-1}  } { 
  1185.            set ress [GP_STDERR "" 3600 ]
  1186.     }
  1187.  
  1188.     set gp_home "$gp_cwd"
  1189.     append gp_home "Scripts:*" 
  1190.  
  1191.  
  1192.      set cdir [pwd]
  1193.      set gp_Path "$gp_home"
  1194.    
  1195.     GP_RebuildScriptMenu
  1196.     cd "$cdir"
  1197.     
  1198.      set gp_home [string range "$gp_home" 0 [expr [string length "$gp_home" ] -2 ] ]
  1199.      message "Current gnuplot Path ==> $gp_cwd"
  1200.      
  1201. }
  1202.  
  1203.  
  1204. ################################################################################
  1205. #
  1206. #  Rebuild the script menu 
  1207. #      
  1208. #
  1209.  
  1210. proc GP_RebuildScriptMenu {  }   {
  1211. global gp_cwd GP_GraphMenu gp_scriptItems gp_openItems gp_Path
  1212.  
  1213.     set gp_scriptItems [list]
  1214.     set gp_openItems [list]
  1215.     set gp_home "$gp_Path"
  1216.  
  1217.     set gp_sl [ GP_ScriptList "$gp_home" "Scripts" ]
  1218.     set gp_sm [concat menu -m -n "Scripts" -p GP_ScriptMenuItems [list "$gp_sl"]  ]
  1219.     
  1220.     # kill the current floating menu (if any)
  1221.     GP_KillGraphButton
  1222.     
  1223.     menu  -n "$GP_GraphMenu" -p GPLTMenuItem [list \
  1224.       "gnuplot" \
  1225.       "(-" \
  1226.       {menu -m -s -n "Settings" -p GPLTMenuItem  {\
  1227.           "line styles...&" \
  1228.         "text format...&" \
  1229.           "labels...&" \
  1230.           "offsets...&" \
  1231.       }}\
  1232.        "(-" \
  1233.        "$gp_sm" \
  1234.     ]
  1235.      
  1236.     GP_GraphButton
  1237. }
  1238.    
  1239.     
  1240. ################################################################################
  1241. #
  1242. #  Generate a new script window 
  1243. #      
  1244. #
  1245.  
  1246. proc GP_NewWindow {  } {
  1247. global winModes
  1248.     set wname "Untitled.gp"
  1249.     new -n $wname
  1250.     GP_uFD
  1251.     insertText "#\r"
  1252.     changeMode [set winModes([lindex [winNames] 0]) GPLT]        
  1253.     setWinInfo -w $wname dirty 0
  1254.    #
  1255. }
  1256.  
  1257.  
  1258.  
  1259.  
  1260. #############################################################################
  1261. #
  1262. #  Tell gnuplot to quit
  1263. #
  1264.  
  1265. proc GP_Quit {} {
  1266.     global gp_Console  
  1267.  
  1268.     switchTo 'ALFA'
  1269.     set wins [winNames]
  1270.     if { [set winThere [lsearch $wins $gp_Console ] ] >= 0} {
  1271.         set name [lindex $wins $winThere]
  1272.         bringToFront $name
  1273.         killWindow
  1274.     } 
  1275.  
  1276. }
  1277.  
  1278.  
  1279. #############################################################################
  1280. #
  1281. #  Switch to gnuplot
  1282. #
  1283.  
  1284. proc GP_Activate {  } {
  1285.     global   gp_FSIG 
  1286.     
  1287.     if { ![GP_Check] } { 
  1288.         switchTo \'$gp_FSIG\' 
  1289.     }    
  1290. }
  1291.  
  1292.  
  1293. #############################################################################
  1294. #
  1295. #  Carriage return for command window
  1296. #
  1297.  
  1298. proc GP_CarriageReturn {} {
  1299.     global gp_CommandHist gp_CommandNum  gp_Console gp_Hist gp_Graph 
  1300.  
  1301.     #enter only if cr in console window...
  1302.     set wins [winNames]
  1303.     if { [lsearch $wins $gp_Console ]  == 0  } {
  1304.         setWinInfo -w $gp_Console dirty 0            
  1305.         set pos [getPos]
  1306.     
  1307.         # I look for > and : instead of the proper prompts... Hmmm...
  1308.         # if -1 then we are not on an input line...
  1309.         # or we could be waiting for a pause...
  1310.         # which should be on the last line...        
  1311.         set ind [string first ">" [getText [lineStart $pos] $pos] ]
  1312.         if {$ind < 0} {
  1313.             set ind [string first ":" [getText [lineStart $pos] $pos] ]
  1314.             if {$ind < 0} {
  1315.                  endOfBuffer
  1316.                  # just send a cr to the server
  1317.                  insertText "\r"
  1318.                  GP_SendCommand [getText [lineStart $pos] $pos] 0
  1319.                  return 
  1320.             }
  1321.         }
  1322.         set lStart [expr [lineStart $pos]+$ind+2]
  1323.         endOfLine
  1324.         set lEnd  [getPos]  
  1325.         set scriptName [getText $lStart $lEnd]
  1326.         insertText "\r"
  1327.         # if not on last line, then replace text on last line...
  1328.         GP_SendCommand "$scriptName"  0
  1329.     } elseif {[lsearch $wins $gp_Hist ] == 0} {
  1330.         # execute the current command in the history window...
  1331.         GP_HistgotoMatch
  1332.     } else {
  1333.         insertText "\r"
  1334.     }
  1335. }
  1336.  
  1337.  
  1338.  
  1339. #############################################################################
  1340. #
  1341. #  Filter curlyq's out of sting...We may need to be smarter 
  1342. #    about this later
  1343. #
  1344. proc GP_filtercurlyq { it } {
  1345.  
  1346.   set from [string first "“" $it]
  1347.   set to [string first "”" $it]
  1348.   set ans [string range $it [expr $from + 1] [expr $to - 1] ]
  1349.   if { ![expr [string length $ans] -1 ] } { 
  1350.       regexp -nocase {[a-z0-9]} $ans nans
  1351.       if {[info exists nans]} {
  1352.           set ans $nans
  1353.       } else {
  1354.           set ans ""
  1355.       }
  1356.       
  1357.       
  1358.   }
  1359.   
  1360.   return $ans
  1361. }
  1362.  
  1363. #############################################################################
  1364. #
  1365. #  Extract current gnuplot path from event reply
  1366. #
  1367.  
  1368. proc GP_ExtractPath { ans } {
  1369.     global gp_cwd 
  1370.     
  1371.     # We need to be tricky since I'm not sure if Dave is sending the
  1372.     # path in an alis, or as a string
  1373. #    regexp {“(.*)(”.*“)(.*)”} "$ans" dummy spec1 spec2 spec3   
  1374.     
  1375.     set frst [ string first "PSTR:" "$ans" ]
  1376.     set lst [ string first "TERM:" "$ans" ]
  1377.     
  1378.     if { ($frst > 0) } {
  1379.         if { $lst <= 0 } { set lst [string length $ans ] }
  1380.         set ans [string range "$ans" $frst $lst ]
  1381.         regexp {“(.*)”} "$ans" dummy  spec3   spec1 
  1382.         if {[info exists spec3]} {
  1383.            set ngp_cwd $spec3
  1384.            if {$ngp_cwd != "" } {
  1385.                set gp_cwd "$ngp_cwd"
  1386.             return 0
  1387.            }         
  1388.        }
  1389.    }
  1390.       
  1391.    regexp {«(.*)»} "$ans" dummy spec
  1392.    if {[info exists spec]} {
  1393.    set ngp_cwd [specToPathName $spec]
  1394.    if {$ngp_cwd != "" } {
  1395.            set gp_cwd "$ngp_cwd"
  1396.         return 0
  1397.        }         
  1398.    }
  1399. }    
  1400.   
  1401.     
  1402.  
  1403. #############################################################################
  1404. #
  1405. #  Send a command to gnuplot and return stderr!
  1406. #
  1407.  
  1408. proc GP_STDERR { mycommand tmout } {
  1409. global  gp_cwd  GPLTmodeVars gp_FSIG gp_TYPE gp_CREA
  1410.  
  1411.     if { ! $GPLTmodeVars(EventHandler) } {
  1412.         catch { AEBuild -t $tmout -r \'$gp_FSIG\' GPSE  "exec" ---- \
  1413.                [curlyq $mycommand] {CREA:} "$gp_CREA" \
  1414.                {TYPE:} "$gp_TYPE" } ans 
  1415.     } else {
  1416.         catch { AEBuild -t $tmout -r \'$gp_FSIG\' GPSE  "exec" ---- \
  1417.                [curlyq $mycommand] {CLIE:} "ALFA" {CREA:} "$gp_CREA" \
  1418.                {TYPE:} "$gp_TYPE" } ans 
  1419.     } 
  1420.     if { $ans == "Unable to find process"  }  GP_Quit        
  1421.     GP_ExtractPath $ans
  1422.     return [GP_filtercurlyq $ans]
  1423. }
  1424.  
  1425.  
  1426. #############################################################################
  1427. #
  1428. #  Send a command to gnuplot  
  1429. #
  1430.  
  1431. proc GP_SendCommand { mycommand tmout} {
  1432. global GPLTmodeVars GPLTMenu  gp_CommandHist gp_Rsp  gp_CommandNum  
  1433. global gp_Prompts gp_Launched 
  1434.     
  1435.     watchCursor
  1436.     GP_Console
  1437.       
  1438.     if { $tmout == 0 } { set tmout 3600 }
  1439.     #display command on the last line of the console if its not already there
  1440.    GP_DispCommand "$mycommand"
  1441.       if { [string trim $mycommand '\r'] != {} } {
  1442.         GP_AddToHist $mycommand
  1443.     }
  1444.  
  1445.    # send gnuplot a command
  1446.    # display the stderr results on the screen
  1447.    # The eventHandler above will display the stdout results first
  1448.    set stderr [GP_STDERR "$mycommand\r"  $tmout ]
  1449.    
  1450.    # Null stderr can mean two things.  
  1451.    #   (1) a pause 
  1452.    #   (2) if no thread manager available, it could mean go back 
  1453.    #       and retrieve the stderr which will help 68k systems 
  1454.    #       work since eventHandler is broken in 6.01
  1455.    
  1456.    # This can probably be cleaned up with a little effort
  1457.    # What I'm doing in the next line is taking care of the 
  1458.    # non-threaded macs...
  1459.    # which always return "".  Its harmless otherwise.
  1460.    if {$stderr == ""  & $mycommand != "" } { set stderr [GP_STDERR "" $tmout ] }
  1461.     #if { $GPLTmodeVars(EventHandler) == "0" &  $stderr == "" } { set stderr "gnuplot> " }
  1462.    if { $stderr != "" } { 
  1463.           GP_Results     "$stderr" 
  1464.    } else {
  1465.           #GP_Results ""
  1466.    }
  1467.          
  1468.     blink [getPos]
  1469. }
  1470.   
  1471.  
  1472. #############################################################################
  1473. #
  1474. #  Save current window and execute it in GNUPLOT, just like GNUPLOT 
  1475. #  command ;)
  1476. #
  1477.  
  1478. proc GP_SaveAndExecute {} {
  1479.  
  1480.     if {[winDirty]} {save}
  1481.  
  1482. # Get the path of the current window and it's name
  1483.     
  1484.    # Set the working directory to the current window's
  1485.    # current dir.
  1486.     set GPLTFilePath "cd \'\:"
  1487.     set GPLTFile [lindex [winNames -f] 0]
  1488.     set GPLTFP [file dirname $GPLTFile]
  1489.     append  GPLTFilePath  $GPLTFP ":\'"
  1490.  
  1491.     # use unix style file paths 
  1492.     regsub -all ":" $GPLTFilePath {/} GPLTFilePath
  1493.  
  1494.    # get the load command ready...
  1495.     set scriptName  "load \'"
  1496.     append scriptName [file tail $GPLTFile] "\'"
  1497.  
  1498.    # Change current working directory to window's
  1499.    GP_SendCommand $GPLTFilePath 0
  1500.     
  1501.    # Do the script
  1502.    GP_SendCommand $scriptName 0
  1503. }
  1504.   
  1505.  
  1506. #############################################################################
  1507. #
  1508. #  Write results to command window  
  1509.  
  1510. proc GP_Results { res } {
  1511. global gp_Console gp_cwd
  1512.         insertText -w $gp_Console  "\n" $res
  1513.         setWinInfo -w $gp_Console dirty 0
  1514.     message "Current gnuplot Path ==> $gp_cwd"
  1515. }
  1516.  
  1517.  
  1518. #############################################################################
  1519. #
  1520. #  Display or rewrite "command" to command window  
  1521.  
  1522. proc GP_DispCommand {command} {
  1523.     global   gp_Prompts gp_cwd 
  1524.     
  1525.     # This is ugly and probably not very efficient.
  1526.     
  1527.    set lst [maxPos]
  1528.    set boll [lineStart $lst]
  1529.  set curr [getPos]
  1530.    
  1531.    if { $curr >= $boll } {       
  1532.         set bol [lineStart $curr]
  1533.         set eol [nextLineStart $curr] 
  1534.          set text [getText $bol $eol]
  1535.        set ltext [getText $boll $lst]
  1536.        foreach gp $gp_Prompts {
  1537.            set c1 [string first $gp $ltext]
  1538.            set c2 [expr $lst - $boll]
  1539.            set c3 [string length $gp]
  1540.            set c4 [expr $lst - $curr] 
  1541.            set c5 [string length $command]
  1542.            if { $c1 == 0 & [expr $c2 >= $c3 | $c4 >= $c5 ] } {
  1543.                     if {[string first $command $text] == -1} {
  1544.                         set a [expr $boll + [string length $gp] ]
  1545.                         set b [string trim $command "\r"]
  1546.                         replaceText $lst  $a $b
  1547.                 } 
  1548.            } 
  1549.         }    
  1550.     }
  1551. }
  1552.  
  1553.  
  1554.  
  1555.  
  1556. #############################################################################
  1557. #
  1558. #  Send line to GNUPLOT
  1559. #
  1560.  
  1561. proc GP_DoLine {} {
  1562.     
  1563.     beginningOfLine
  1564.     set bol [getPos]
  1565.     endOfLine
  1566.     set eol [getPos]
  1567.  
  1568.     set scriptName [getText $bol $eol]
  1569.    GP_SendCommand $scriptName     0
  1570. }
  1571.  
  1572.  
  1573. #############################################################################
  1574. #
  1575. #  Send selection to GNUPLOT
  1576. #
  1577.  
  1578. proc GP_DoSelection {} {
  1579.     # Break lines into separate commands.
  1580.     foreach sN [split [getSelect] "\r"] { 
  1581.         GP_SendCommand $sN 0
  1582.     }
  1583.     
  1584. }
  1585.  
  1586.  
  1587.  
  1588.  
  1589. #############################################################################
  1590. #
  1591. #  Command History 
  1592. #
  1593.  
  1594. proc GP_PrevCommand {} {
  1595. global  gp_CommandHist gp_CommandNum gp_Hist gp_Prompt gp_MultiPrompt 
  1596. global  gp_ContPrompt gp_Console gp_Hist
  1597.     
  1598.     #enter only if cr in console window...
  1599.     set wins [winNames]
  1600.     if { [lsearch $wins $gp_Console ] == 0} {
  1601.  
  1602.         set text [getText [lineStart [getPos] ] [nextLineStart [getPos] ] ]
  1603.         if {[set ind [string first $gp_Prompt $text] ] == 0} {
  1604.             goto [expr [lineStart [getPos] ] + $ind + [string length $gp_Prompt] ]
  1605.         } elseif {[set ind [string first $gp_MultiPrompt $text] ] == 0} {
  1606.             goto [expr [lineStart [getPos] ] + $ind + 
  1607.               [string length $gp_Multiprompt] ]
  1608.         } elseif {[set ind [string first $gp_ContPrompt $text] ] == 0} {
  1609.             goto [expr [lineStart [getPos] ] + $ind + [string length $gp_Contprompt] ]
  1610.         } elseif { return }
  1611.     
  1612.         incr gp_CommandNum -1
  1613.         if {$gp_CommandNum < 0} {
  1614.             incr gp_CommandNum
  1615.             endOfLine
  1616.             return
  1617.         } 
  1618.         set text [lindex $gp_CommandHist $gp_CommandNum]
  1619.         set to [nextLineStart [getPos] ]
  1620.         if {[lookAt [expr $to-1] ] == "\r"} {incr to -1}
  1621.  
  1622.         replaceText [getPos] $to $text
  1623.     } elseif { [lsearch $wins $gp_Hist ]  == 0} {
  1624.         
  1625.         set limit [nextLineStart [nextLineStart 0] ]
  1626.         if {[getPos] > $limit} {
  1627.             set limit [expr [getPos] - 1]
  1628.         }
  1629.         select [lineStart $limit] [nextLineStart $limit]
  1630.     } else {
  1631.         previousLine
  1632.     }
  1633.     
  1634. }
  1635.  
  1636. proc GP_NextCommand {} {
  1637.     global  gp_CommandHist gp_CommandNum gp_Prompt gp_MultiPrompt 
  1638.    global gp_ContPrompt gp_Console gp_Hist
  1639.     
  1640.     #enter only if cr in console window...
  1641.     set wins [winNames]
  1642.     if { [lsearch $wins $gp_Console  ]  == 0} {
  1643.  
  1644.         set text [getText [lineStart [getPos] ] [nextLineStart [getPos] ]]
  1645.         if {[set ind [string first $gp_Prompt $text] ] == 0} {
  1646.             goto [expr [lineStart [getPos] ] + $ind + 9]
  1647.         } elseif {[set ind [string first $gp_MultiPrompt $text] ] == 0} {
  1648.                 goto [expr [lineStart [getPos] ] + $ind + 11]
  1649.         } elseif {[set ind [string first $gp_ContPrompt $text] ] == 0} {
  1650.                 goto [expr [lineStart [getPos] ] + $ind + 3]
  1651.         } else  { 
  1652.             endOfBuffer
  1653.             return 
  1654.         }
  1655.     
  1656.         incr gp_CommandNum
  1657.         if {$gp_CommandNum >= [llength $gp_CommandHist]} {
  1658.             incr gp_CommandNum -1
  1659.             return
  1660.         }
  1661.         set text [lindex $gp_CommandHist $gp_CommandNum]
  1662.         set to [nextLineStart [getPos] ]
  1663.         if {[lookAt [expr $to-1] ] == "\r"} {incr to -1}
  1664.         replaceText [getPos] $to $text
  1665.     } elseif { [lsearch $wins $gp_Hist  ]  == 0} {
  1666.             set pos [getPos]
  1667.             if {$pos < [nextLineStart 0]} {
  1668.                 set pos [nextLineStart 0]
  1669.             }
  1670.             if {[nextLineStart $pos] != [maxPos]} {
  1671.                 select [nextLineStart $pos] [nextLineStart [nextLineStart $pos] ]
  1672.             }
  1673.         } else {
  1674.       # mv cusor down...
  1675.             nextLine
  1676.     }    
  1677. }
  1678.  
  1679.  
  1680.  
  1681. #############################################################################
  1682. #
  1683. #  Edit current window in GNUPLOT
  1684. #
  1685.  
  1686. proc GP_EditFile {} {
  1687. global gp_FSIG 
  1688.  
  1689.     if { ![GP_Check] } {
  1690.         set thisWin  [lindex [winNames] 0]
  1691.         if {[winDirty]} {
  1692.             if {[askyesno "Save '$thisWin'?"] == "yes"} {
  1693.                 save
  1694.             } else { return }     }
  1695.         set thisWin  [lindex [winNames -f ] 0]
  1696.         fileMenuProc File close
  1697.         if {[catch {sendOpenEvent -n \'$gp_FSIG\' $thisWin }] } {
  1698.         } else { switchTo \'$gp_FSIG\'     }
  1699.    }
  1700. }
  1701.  
  1702.  
  1703. #############################################################################
  1704. #
  1705. #  change behavior of modifyModeFlags
  1706. #
  1707.  
  1708. if    {![string length [info commands GP_modifyModeFlags] ]} {    
  1709.     global mode GPLTmodeVars gp_modflag PREFS gp_HistGEOM gp_GEOM
  1710.     global GPLTMenu  gp_Graph gp_Console  gp_Hist 
  1711.         
  1712.     rename modifyModeFlags GP_modifyModeFlags
  1713.     
  1714.     proc modifyModeFlags {} {
  1715.         global mode GPLTmodeVars gp_modflag PREFS gp_HistGEOM gp_GEOM
  1716.         global GPLTMenu  gp_Graph gp_Console  gp_Hist gp_floatmenu
  1717.         
  1718.         set wins [winNames]
  1719.         if { [lsearch $wins $gp_Console ]  >= 0}  {
  1720.             set gp_GEOM [ getGeometry $gp_Console ]
  1721.         }
  1722.         
  1723.         if { [lsearch $wins $gp_Hist] >= 0 } {
  1724.             set gp_HistGEOM [ getGeometry $gp_Hist ]
  1725.         }
  1726.         
  1727.         set ans [ GP_modifyModeFlags ]    
  1728.        if { $mode == "GPLT" } {
  1729.        # make any changes to GPLT environment
  1730.             set gp_modflag 1
  1731.            
  1732.             if { $GPLTmodeVars(LiveHist) } { 
  1733.                 set wins [winNames]
  1734.                 if { [lsearch $wins $gp_Console  ]  >= 0} {
  1735.                     GP_DumpHistory
  1736.                 } 
  1737.             } else {
  1738.                   set wins [winNames]
  1739.                 if {[lsearch $wins $gp_Hist  ]  >= 0} {
  1740.                     bringToFront $gp_Hist
  1741.                     killWindow 
  1742.                 } 
  1743.             }
  1744.             if { $GPLTmodeVars(EventHandler) } { 
  1745.             } else {
  1746.                 set jj1 "The event handler is broken in Alpha (68k).
  1747.                 set jj2 "You may need to disable event handling until it is fixed."
  1748.                alertnote $jj1 $jj2
  1749.             }
  1750.             if { $GPLTmodeVars(GraphButton) } { 
  1751.                 GP_GraphButton
  1752.             } else {
  1753.                 GP_KillGraphButton
  1754.             }
  1755.             catch {  source $PREFS:GPLTPrefs.tcl } jjj
  1756.             catch {    bringToFront $gp_Console } jjj
  1757.        }
  1758.        return $ans
  1759.     }
  1760. }
  1761.  
  1762.  
  1763.  
  1764. #############################################################################
  1765. #
  1766. #  Redefine the closeHook procedure so that gnuplot is quit 
  1767. #  whenever the user closes the console window.  Also ask about 
  1768. #  saving the history list when the console is closed.
  1769. #
  1770. #
  1771.     
  1772. if    {![string length [info commands GP_CloseHook] ]} {
  1773. global GPLTMenu GPLTPath GPLTmodeVars PREFS modifiedModeVars
  1774. global gp_CreatorList gp_TypeList gp_Console gp_Graph  gp_Hist 
  1775. global gp_CreatorNames gp_CommandNum gp_Launched gp_FSIG modifiedVars
  1776. global gp_GEOM gp_HistGEOM modifiedVars
  1777.           
  1778.     
  1779.     rename closeHook GP_CloseHook
  1780.     
  1781.     proc closeHook    {name} {
  1782.         global GPLTMenu GPLTPath GPLTmodeVars PREFS modifiedModeVars
  1783.         global gp_CreatorList gp_TypeList gp_Console gp_Graph gp_Hist 
  1784.         global gp_CreatorNames gp_CommandNum gp_Launched gp_FSIG modifiedVars
  1785.         global gp_GEOM gp_HistGEOM modifiedVars
  1786.         
  1787.         # Always call the original closeHook.
  1788.         set result [eval GP_CloseHook    {$name}]
  1789.  
  1790.         # We need to make    sure that we launched gnuplot    in    the first place
  1791.         # and    that we are    in    gp_ulot mode....    
  1792.         if    { [string first "$PREFS:GPLTPrefs.tcl" $name] == 0    } {
  1793.             if { [ catch { source "$PREFS:GPLTPrefs.tcl" } hmmm ] } {
  1794.                 alertnote "Error sourcing GPLTPrefs.tcl\n\n$hmmm"
  1795.             }
  1796.         } elseif { [string first $gp_Console $name] == 0    } {
  1797.  #    
  1798.                if    {$gp_CommandNum != 0 && ! $GPLTmodeVars(NevrSavHist) } {
  1799.                     GP_DumpHistory
  1800.                    set ans [askyesno -c "Save    gnuplot command History?" ]
  1801.                 } else {    set ans "yes" }
  1802.  #                
  1803.                 GP_OffSet
  1804.                 switch -exact [string tolower $ans] {
  1805.                     "cancel"   { GP_Console; return $result }
  1806.                     "no"       { GP_ClearHistory }
  1807.                     "yes"       {     
  1808.                                     catch { setWinInfo -w $gp_Hist read-only 0 } jj                                        
  1809.                                     catch { setWinInfo -w $gp_Hist dirty 1 } jj
  1810.                                     catch { bringToFront $gp_Hist } jj
  1811.                                     if { $jj == 0 } { 
  1812.                                         catch { saveAs "history.gp" } jj
  1813.                                     }
  1814.                                     catch { setWinInfo -w $gp_Hist dirty 0 } jj                                        
  1815.                                     catch { setWinInfo -w $gp_Hist read-only 1 } jj
  1816.                                     GP_ClearHistory
  1817.                                 }
  1818.                   } 
  1819.             #end case
  1820.             if {$gp_Launched    !=    0 } { 
  1821.                 catch { sendQuitEvent \'$gp_FSIG\' } hhh  
  1822.                 lappend modifiedVars  gp_FSIG 
  1823.             } 
  1824.                set gp_Launched 0
  1825.              set wins [winNames]
  1826.             if { [lsearch $wins $gp_Hist  ]  >= 0} {
  1827.                 bringToFront $gp_Hist
  1828.                 killWindow 
  1829.             } 
  1830.             lappend modifiedVars   gp_GEOM 
  1831.             lappend modifiedVars   gp_HistGEOM 
  1832.             if { [info exists GPLTPath] } { lappend modifiedVars GPLTPath }            
  1833.  
  1834.         } elseif {[string first $gp_Hist    $name] == 0} {
  1835.                 set wins [winNames]
  1836.                 if { [lsearch $wins $gp_Console ]  >= 0} {
  1837.                    set GPLTmodeVars(LiveHist) 0
  1838.                 } 
  1839.         }
  1840.          #end if
  1841.          return $result
  1842.  ##
  1843.     } 
  1844.     #endproc    closeHook
  1845. # end if
  1846.     
  1847.  
  1848. #############################################################################
  1849. #
  1850. #  Redefine the deactivateHook procedure so that gnuplot is quit 
  1851. #  whenever the user closes the console window.  Also ask about 
  1852. #  saving the history list when the console is closed.
  1853. #
  1854. #
  1855.     
  1856. if    {![string length [info commands GP_DeactivateHook] ]} {
  1857.     global gp_Hist GPLTmodeVars gp_Console
  1858.     global  gp_GEOM gp_HistGEOM
  1859.     
  1860.     rename deactivateHook GP_DeactivateHook
  1861.     proc deactivateHook    {name} {
  1862.         global  gp_Hist GPLTmodeVars gp_Console gp_Graph
  1863.         global  gp_GEOM gp_HistGEOM
  1864.         # Always call the original deactivateHook.
  1865.         set result [eval GP_DeactivateHook    {$name}]
  1866.         
  1867.         if    { [string first $gp_Hist $name] == 0    } {
  1868.             set gp_HistGEOM [ getGeometry $gp_Hist ]
  1869.           endOfBuffer
  1870.         } elseif {[string first $gp_Console $name] == 0} {
  1871.             set gp_GEOM [getGeometry $gp_Console ]
  1872.         } 
  1873.          #end if
  1874.          return $result
  1875.  ##
  1876.     } 
  1877.     #endproc    deactivateHook
  1878. # end if
  1879.  
  1880. #############################################################################
  1881. #
  1882. #  Redefine the activateHook procedure so that gnuplot is quit 
  1883. #  whenever the user closes the console window.  Also ask about 
  1884. #  saving the history list when the console is closed.
  1885. #
  1886. #
  1887.     
  1888. if    {![string length [info commands GP_ActivateHook] ]} {
  1889.         global  gp_Hist gp_Graph gp_Console modifiedModeVars
  1890.         global  mode gp_cwd GPLTmodeVars mode gp_modflag gp_GEOM
  1891.     
  1892.     rename activateHook GP_ActivateHook
  1893.     #    set lastStack {}
  1894.     proc activateHook    {name} {
  1895.         global  gp_Hist gp_Graph gp_Console modifiedModeVars
  1896.         global  mode gp_cwd GPLTmodeVars mode gp_modflag gp_GEOM
  1897.     
  1898.         # Always call the original activateHook.
  1899.         set result [eval GP_ActivateHook    {$name}]
  1900.         
  1901.         if    { [string first $gp_Console $name] == 0} {
  1902.             set gp_GEOM [ getGeometry $gp_Console ]
  1903.         } elseif    { [string first $gp_Hist $name] == 0} {
  1904.             set gp_HistGEOM [ getGeometry $gp_Hist ]
  1905.         }
  1906.         
  1907.          #end if
  1908.         if { $mode == "GPLT"} {
  1909.             message "Current gnuplot Path ==> $gp_cwd"
  1910.         }
  1911.         #set gp_modflag 0
  1912.          return $result
  1913.     } 
  1914.     #endproc    activateHook
  1915. # end if
  1916.  
  1917.  
  1918.  
  1919. ###########################################################################
  1920. #
  1921. # In GNUc mode, cmd-double-click highlights area btween consecutive 
  1922. # gnuplot prompts
  1923. #
  1924.  
  1925. proc GPLTDblClick {from to} {
  1926.    
  1927.     global gp_Prompts
  1928.     
  1929.     # First find "gnuplot> " prompt above and below cursor entry...
  1930.     # don't forget to deal with "multiplot> " and "> "
  1931.  
  1932.     set gp1 [list]
  1933.     foreach gp $gp_Prompts {lappend gp1 [search -n -f 0 -r 1   $gp $from] }
  1934.     set firstmatch [lindex [lindex $gp1 0 ] 0]
  1935.     foreach el $gp1 { if {[lindex $el 1] > $firstmatch } { 
  1936.          set firstmatch [lindex $el 0] } }    
  1937.  
  1938.     if {$firstmatch == {}} {
  1939.         message "You are not between prompts" 
  1940.         return 
  1941.     } else {
  1942.         
  1943.         set firstmatch [nextLineStart $firstmatch]
  1944.         endOfBuffer
  1945.         set lastmatch [getPos ]
  1946.         set gp1 [list]
  1947.         foreach gp $gp_Prompts {lappend gp1 [search -n -f 1 -r 1   $gp $from] }
  1948.         foreach el $gp1 {if {[lindex $el 1]!={} & [lindex $el 0]< $lastmatch } { 
  1949.                set lastmatch $el } 
  1950.        }
  1951.          if {$lastmatch == {}} {
  1952.             message "You are not between prompts" 
  1953.             return 
  1954.         } else { 
  1955.         
  1956.         goto $lastmatch
  1957.         beginningOfLine
  1958.         select $firstmatch [getPos] }
  1959.     }
  1960. }
  1961.  
  1962.  
  1963.  
  1964. #########################################################################
  1965. #
  1966. # Modify openHook to set gp_plot mode for files of type/creator GPLT
  1967. #
  1968.  
  1969. if    {![string length [info commands GP_OpenHook] ]} {
  1970.         global GPLTMenu gp_Console   
  1971.         global  GPLTmodeVars gp_CommandNum gp_Launched 
  1972.     
  1973.     rename openHook GP_OpenHook
  1974.     
  1975.     #set lastStack {}
  1976.     proc openHook    {name} {
  1977.         global GPLTMenu gp_Console   
  1978.         global  GPLTmodeVars gp_CommandNum gp_Launched 
  1979.     
  1980.         # Always call the original closeHook.
  1981.         set result [eval GP_OpenHook    {$name} ]
  1982.  
  1983.         # check to see if file type is GPLT if so, then set gp_plot mode.
  1984.         # of course this gets over-ridden if the file suffix is supported
  1985.         # by some other mode.
  1986.          if { [string first "GPLT" [getFileSig  "$name"] ] >= 0 } {
  1987.            changeMode [ set winModes([lindex [winNames] 0]) GPLT ] 
  1988.          } elseif { [string first "GPSE" [getFileSig  "$name"] ] >= 0 } {
  1989.            changeMode [ set winModes([lindex [winNames] 0]) GPLT ] 
  1990.          }
  1991.          #
  1992.         return $result
  1993.     }
  1994. }
  1995.  
  1996.  
  1997.  
  1998. #############################################################################
  1999. #
  2000. #  Select creator from list
  2001. #
  2002.  
  2003. proc GP_SelectCreator {} {
  2004. global gp_CreatorNames  gp_CreatorList   gp_TypeList GPLTmodeVars  
  2005. global setOutputCreator modifiedModeVars modifiedVars
  2006. global gp_CREA gp_TYPE
  2007.  
  2008.     set crea [listpick -p "Select output file creator:" $gp_CreatorNames  ]
  2009.    set creator [lindex $gp_CreatorList [lsearch  $gp_CreatorNames $crea] ]
  2010.    set type [lindex $gp_TypeList [lsearch  $gp_CreatorNames $crea] ]
  2011.    if {$creator == {} } {
  2012.          set gp_CREA 'ALFA'
  2013.          set gp_TYPE 'TEXT' 
  2014.    } else { 
  2015.        set gp_CREA $creator
  2016.        set gp_TYPE $type
  2017.    }
  2018.     lappend modifiedVars  gp_TYPE
  2019.     lappend modifiedVars  gp_CREA
  2020.     lappend modifiedVars  gp_CreatorList 
  2021.     lappend modifiedVars  gp_TypeList
  2022.     lappend modifiedVars  gp_CreatorNames 
  2023. }
  2024.  
  2025.  
  2026. #############################################################################
  2027. #
  2028. #  Add creator to list from file dialog
  2029. #
  2030.  
  2031. proc GP_AddCreator {} {
  2032. global gp_CreatorNames  gp_CreatorList  GPLTMenu gp_TypeList 
  2033. global GPLTmodeVars modifiedVars modifiedModeVars
  2034. global gp_CREA gp_TYPE
  2035.    
  2036.    set fname [getfile "Select file type for creator"] 
  2037. #  add to creator list
  2038.    if {[getFileType $fname]=="APPL"} {
  2039.        alertnote "Sorry, but that was an application. \rTry again."
  2040.        return
  2041.    }
  2042.    
  2043.    if {$fname != {}} {
  2044.        set nm [getline "What do you wish to call it?" [file tail $fname ] ]
  2045.         if {$nm != {} } {   
  2046.                 set gp_CREA  [getFileSig $fname]
  2047.                 set gp_TYPE  [getFileType $fname]
  2048.                 lappend gp_CreatorList  $gp_CREA
  2049.                 lappend gp_TypeList     $gp_TYPE
  2050.                 lappend gp_CreatorNames $nm
  2051.                 enableMenuItem  setOutputCreator "Select..." on
  2052.                 enableMenuItem  setOutputCreator "Delete..." on
  2053.                 lappend modifiedVars  gp_TYPE
  2054.                 lappend modifiedVars  gp_CREA
  2055.                 lappend modifiedVars  gp_CreatorList 
  2056.                 lappend modifiedVars  gp_TypeList 
  2057.                 lappend modifiedVars  gp_CreatorNames 
  2058.             }
  2059.    }
  2060.      
  2061.  
  2062. }
  2063.  
  2064. #############################################################################
  2065. #
  2066. #  Remove creator from list
  2067. #
  2068.  
  2069. proc GP_DeleteCreator {} {
  2070. global gp_CreatorNames GPLTMenu gp_CreatorList  gp_TypeList 
  2071. global GPLTmodeVars modifiedVars modifiedModeVars
  2072. global gp_CREA gp_TYPE
  2073.  
  2074.     set crea [listpick -p "Select creator to be deleted:"  $gp_CreatorNames ]
  2075.  
  2076.       if {$crea != {}} {
  2077.     #  now remove this creator from both lists....
  2078.         set creatorInd [lsearch  $gp_CreatorNames $crea]
  2079.         set crea [ lindex $gp_CreatorList $creatorInd]
  2080.         set gp_CreatorNames [ lreplace $gp_CreatorNames $creatorInd $creatorInd ]
  2081.         set gp_CreatorList  [ lreplace $gp_CreatorList  $creatorInd $creatorInd ]
  2082.         set gp_TypeList     [ lreplace $gp_TypeList     $creatorInd $creatorInd ]
  2083.     
  2084.         if {$gp_CREA == $crea } {
  2085.             set gp_CREA 'ALFA'
  2086.             set gp_TYPE 'TEXT'
  2087.         } 
  2088.         lappend modifiedVars  gp_TYPE
  2089.         lappend modifiedVars  gp_CREA
  2090.         lappend modifiedVars  gp_CreatorList 
  2091.         lappend modifiedVars  gp_TypeList 
  2092.         lappend modifiedVars  gp_CreatorNames 
  2093.     }
  2094.     
  2095.     if {[llength $gp_CreatorList] == 0} {
  2096.         enableMenuItem  setOutputCreator "Select..." off
  2097.         enableMenuItem setOutputCreator "Delete..." off
  2098.     }
  2099. }
  2100.  
  2101.  
  2102. #############################################################################
  2103. #
  2104. #  Add command to history list
  2105. #
  2106.  
  2107. proc GP_AddToHist  { cmmd } {
  2108. global gp_CommandHist gp_CommandNum GPLTMenu 
  2109. global GP_Console gp_Hist GPLTmodeVars
  2110.     
  2111.     enableMenuItem gnuplotOptions "clearHistory" on
  2112.     lappend gp_CommandHist $cmmd
  2113.     set gp_CommandNum [llength $gp_CommandHist]
  2114.     
  2115.     if { $GPLTmodeVars(LiveHist) } {
  2116.         # if history list active then append $cmmd on last line
  2117.         set wins [winNames]
  2118.         if { [lsearch $wins $gp_Hist ]  >= 0} {
  2119.              setWinInfo -w $gp_Hist dirty 1
  2120.              setWinInfo -w $gp_Hist  read-only 0
  2121.             insertText -w $gp_Hist "$cmmd\r"
  2122.              setWinInfo -w $gp_Hist  dirty 0
  2123.              setWinInfo    -w $gp_Hist  read-only 1
  2124.         } else {
  2125.             GP_DumpHistory
  2126.             bringToFront $GP_Console
  2127.         }
  2128.         
  2129.     }
  2130. }
  2131.  
  2132.  
  2133. #############################################################################
  2134. #
  2135. #  Clear History list 
  2136. #
  2137.  
  2138. proc GP_ClearHistory {} {
  2139.     global  GPLTMenu gp_CommandHist gp_CommandNum  gp_Hist
  2140.  
  2141.     set gp_CommandHist [list]
  2142.     set gp_CommandNum "0"
  2143.     enableMenuItem gnuplotOptions "clearHistory" off    
  2144.     set wins [winNames]
  2145.     if { [lsearch $wins $gp_Hist ] >= 0} {
  2146.         bringToFront $gp_Hist
  2147.         killWindow 
  2148.     }
  2149. }
  2150.  
  2151.  
  2152. #############################################################################
  2153. #
  2154. #  Write History list into a window of its own.
  2155. #
  2156.  
  2157. proc GP_DumpHistory {} {
  2158.     global gp_CommandHist gp_CommandNum gp_Console 
  2159.     global winModes GPLTmodeVars gp_Console gp_Hist  
  2160.    global gp_GEOM modifiedModeVars
  2161.    
  2162.     set wins [winNames]
  2163.     set nw [ llength $wins ]
  2164.  
  2165.     if { [lsearch $wins $gp_Hist ]  == -1} {
  2166.         
  2167.         set l [ expr [lindex $gp_GEOM 0] + 5 + [lindex $gp_GEOM 2] ]
  2168.         set t [ expr [lindex $gp_GEOM 1] + 20 ]
  2169.         set w 96
  2170.         set h [ expr [lindex $gp_GEOM 3] - 20 ]
  2171.         new -n $gp_Hist -g $l $t $w $h
  2172.         
  2173.        set gp_HistGEOM [getGeometry]        
  2174.         set fileName [lindex [winNames] 0]
  2175.         changeMode [set winModes([lindex [winNames] 0]) GPLT ]
  2176.         GP_uFD
  2177.         set scriptName "# (<cr> to send to gnuplot)\r#-----\r"
  2178.       foreach word $gp_CommandHist  {append  scriptName  $word "\r" }
  2179.         insertText  -w $fileName $scriptName
  2180.          setWinInfo dirty 0
  2181.          setWinInfo read-only 1
  2182.     } else {
  2183.         bringToFront $gp_Hist
  2184.     }
  2185. }
  2186.  
  2187.     
  2188.  
  2189. ################################################################################
  2190. #
  2191. #  Insert File Description---use Vince's if possible.  
  2192. #      this used in creating new window and in dumping history list
  2193. #
  2194.  
  2195. proc GP_uFD { } {
  2196.     #catch {userFileDescription } ans 
  2197.     #if {     $ans != ""    }  {
  2198.          insertText "#\r#\r#     " [join [mtime [now] long] ] "\r"
  2199.          nextLine
  2200.     #}
  2201.    endOfBuffer
  2202. }
  2203.  
  2204.  
  2205. ################################################################################
  2206. #
  2207. #  Clear a few globals...
  2208. #
  2209. #
  2210. #
  2211. proc GP_Clear {} {
  2212.     global PREFS GPLTPath  GPLTmodeVars
  2213.     global  gp_CreatorList gp_CreatorNames  
  2214.     global gp_GEOM gp_HistGEOM modifiedVars
  2215.     global gp_CREA gp_TYPE
  2216.  
  2217.     if { [info exists GPLTPath] } { unset GPLTPath }
  2218.     if { [info exists gp_GEOM] } { set gp_GEOM [list] }      
  2219.     if { [info exists gp_CreatorList] } { unset gp_CreatorList }      
  2220.     if { [info exists gp_TypeList] } { unset gp_TypeList }      
  2221.     if { [info exists gp_CreatorNames] } { unset gp_CreatorNames }      
  2222.     if { [info exists gp_HistGEOM] } { unset gp_HistGEOM  }      
  2223.     if { [info exists gp_CREA] } { unset gp_CREA  }      
  2224.     if { [info exists gp_TYPE] } { unset gp_TYPE  }      
  2225.     
  2226.     if { ![info exists gp_CreatorList]}  { set gp_CreatorList [list ALFA GPLT ] }
  2227.     if { ![info exists gp_TypeList]}  { set gp_TypeList [list TEXT TEXT ] }
  2228.     if { ![info exists gp_CreatorNames]} { set gp_CreatorNames [list alpha gnuplot] }
  2229.     if { ![info exists gp_CREA] } {set gp_CREA ALFA}
  2230.     if { ![info exists gp_TYPE ] } {set gp_TYPE TEXT}
  2231.     if { ![info exists gp_GEOM] } {set gp_GEOM [list]}
  2232.     if { ![info exists gp_HistGEOM] } {set gp_HistGEOM [list ]}
  2233.     
  2234.     if { [llength $gp_CreatorList] == 0 \
  2235.       || [llength $gp_CreatorList] != [llength $gp_CreatorNames] \
  2236.       || [llength $gp_CreatorList] != [llength $gp_TypeList]} {
  2237.             set gp_CreatorList [list]
  2238.             set gp_TypeList [list]
  2239.             set gp_CreatorNames [list]
  2240.     }
  2241.  
  2242.     lappend modifiedVars gp_CreatorNames gp_TypeList gp_CreatorList 
  2243.     lappend modifiedVars gp_HistGEOM gp_GEOM GPLTPath
  2244.     lappend modifiedVars gp_TYPE gp_CREA
  2245.     catch { source $PREFS:gnuplotMode.tcl } blah
  2246.     catch { source $HOME:tcl:modes:gnuplotMode.tcl } blah
  2247. }
  2248.  
  2249.  
  2250. ################################################################################
  2251. #
  2252. #  History goto match...
  2253. #
  2254. #
  2255. #
  2256.  
  2257. proc GP_HistgotoMatch {} {
  2258.    set frst [lineStart [getPos] ]
  2259.    endOfLine
  2260.    set lst  [getPos]
  2261.     endOfBuffer
  2262.     beginningOfLine
  2263.    GP_SendCommand [getText $frst $lst ] 0
  2264. }
  2265.  
  2266.  
  2267.  
  2268.  
  2269.  
  2270. ################################################################################
  2271. #
  2272. #  Create floating menu
  2273. #
  2274. #
  2275. #
  2276.  
  2277. set GP_GraphMenu "gnuplotGraph"
  2278.  
  2279. set gp_grmen [list "menu  -n $GP_GraphMenu -p GPLTMenuItem" ]
  2280. lappend gp_grmen "gnuplot" "(-" 
  2281.  
  2282. menu  -n $GP_GraphMenu -p GPLTMenuItem   [ concat \
  2283.       "gnuplot" \
  2284.       ]
  2285.       
  2286.      
  2287.  
  2288.  
  2289.  
  2290.  
  2291.  
  2292. ################################################################################
  2293. #
  2294. #  run load scripts from scripts menu
  2295. #
  2296. #
  2297. #
  2298.  
  2299. proc GP_ScriptMenuItems {menu item} {
  2300. global gp_sl gp_home gp_scriptItems gp_Path  gp_openItems
  2301.  
  2302.    set men [string tolower $menu]
  2303.    set ite [string tolower $item]
  2304.    
  2305.    if { "$item" == "Rebuild Menu" } {
  2306.         set cdir [pwd]
  2307.         set sl [expr [string length $gp_Path ] - 2] 
  2308.         cd [string range $gp_Path 0 $sl ]
  2309.      GP_RebuildScriptMenu
  2310.      cd "$cdir"
  2311.      return 0
  2312.    }
  2313.    
  2314.    foreach it $gp_scriptItems {
  2315.         if { [string match "cd \'*$men:\'; load \'*$men:$ite\'" [string tolower $it] ] } {
  2316.           GP_SendCommand "$it" 0
  2317.           return 0
  2318.      }      
  2319.     }
  2320.  
  2321.    #set men [string tolower [string range $menu 5 [string length $menu] ] ]
  2322.    
  2323.    # filter out the "• edit "  from the selected $menu $item
  2324.    set ite [string tolower [string range $item 7 [string length $item] ] ]
  2325.  
  2326.    foreach it $gp_openItems {
  2327.         if { [string match "*$men:$ite" [string tolower $it] ] } {
  2328.           edit "$it" 
  2329.           newMode  GPLT 
  2330.           return 0
  2331.      }      
  2332.     }
  2333. }
  2334.  
  2335.  
  2336.  
  2337. ################################################################################
  2338. #
  2339. #  Create a floating gnuplot graph button (Alpha 6.2 or higher)
  2340. #
  2341. #
  2342. #
  2343. proc GP_GraphButton {} {    
  2344. global gp_floatmenu GP_GraphMenu GPLTmodeVars gp_sl gp_Path
  2345.  
  2346.   
  2347.  if {$GPLTmodeVars(GraphButton) } { 
  2348.     if { (![info exists  gp_floatmenu] )} {
  2349.      set gp_floatmenu [float -m $GP_GraphMenu -n "" -M -1 -z GPLT]
  2350.     } 
  2351.  } 
  2352.     
  2353. }
  2354.  
  2355.  
  2356.  
  2357. ################################################################################
  2358. #
  2359. #  Generate the script menu 
  2360. #      
  2361. #
  2362.  
  2363. proc GP_ScriptList { sdir men } {
  2364. global gp_scriptItems  gp_openItems
  2365.    
  2366.     if {"$men" == "Scripts" } {
  2367.         set sl [list "Rebuild Menu"]
  2368.     } else {
  2369.         set sl [list]
  2370.     }
  2371.     
  2372.     # get the list of text files in $sdir
  2373.     set gp_fl [ glob -nocomplain -t TEXT "$sdir"] 
  2374.     set mdir [string range "$sdir" 0 [expr [string length "$sdir"] - 2 ] ] 
  2375.     set rdir [string range "$mdir" 0 [expr [string length "$mdir"] -1 ] ]
  2376.     foreach f $gp_fl {
  2377.       set mitem [string range $f [expr 1 + [string last ":" "$f" ] ] [ string length "$f" ] ]
  2378.       #append mitem "&"
  2379.       if { $mitem != "" } { 
  2380.           lappend sl "<E<S$mitem" 
  2381.           lappend sl "<S<I• edit $mitem" 
  2382.           lappend sl "<S<B• edit $mitem" 
  2383.           lappend sl "<S<U• edit $mitem" 
  2384.           lappend sl "<S<O• edit $mitem" 
  2385.         lappend gp_scriptItems "cd \'$rdir\'; load \'$f\'"
  2386.         lappend gp_openItems "$f"
  2387.       }
  2388.     }
  2389.     
  2390.     # get the list of aliased directories in $sdir and
  2391.     # perform this operation again on subdirectories
  2392.     set dlist [ glob   -t fdrp -nocomplain "$sdir"]
  2393.     foreach d $dlist {
  2394.        set dn [string range $d [expr [string last ":" "$d" ] +1 ] [string length $d]   ]
  2395.        #set dn [string range $dn [expr 1 + [string last ":" "$dn" ] ] [ string length "$dn" ] ]
  2396.        set sl [concat "$sl"  [concat " \{menu -m -n" "\"$dn\"" -p GP_ScriptMenuItems  " \{  "  ] ]
  2397.        set dnam $d
  2398.        append dnam "*" 
  2399.        #set gp_ssl [ GP_ScriptList "$dnam" $dn ]
  2400.        set gp_ssl [list "(ALIASED FOLDERS NOT WORKING YET"]
  2401.        set sl [ concat "$sl "  $gp_ssl " \}  \} " ]
  2402.     }
  2403.     
  2404.     # get the list of directories in $sdir and
  2405.     # perform this operation again on subdirectories
  2406.     set dlist [ glob -nocomplain  "$sdir:"]
  2407.     foreach d $dlist {
  2408.        set dn [string range $d 0 [expr [string last ":" "$d" ] - 1 ]  ]
  2409.        set dn [string range $dn [expr 1 + [string last ":" "$dn" ] ] [ string length "$dn" ] ]
  2410.        set sl [concat "$sl"  [concat " \{menu -m -n" "\"$dn\"" -p GP_ScriptMenuItems  " \{  "  ] ]
  2411.        set dnam $d
  2412.        append dnam "*" 
  2413.        set gp_ssl [ GP_ScriptList "$dnam" $dn ]
  2414.        set sl [ concat "$sl "  $gp_ssl " \}  \} " ]
  2415.     }
  2416.     
  2417.     return  $sl 
  2418. }
  2419.    
  2420.  
  2421. ################################################################################
  2422. #
  2423. #  Kill a floating gnuplot menu (Alpha 6.2 or higher)
  2424. #
  2425. #
  2426. #
  2427. proc GP_KillGraphButton {} {    
  2428. global gp_floatmenu GPLTMenu GPLTmodeVars 
  2429.  
  2430. if { [info exists  gp_floatmenu] }  { #
  2431.      catch {unfloat $gp_floatmenu } ans
  2432.      unset gp_floatmenu
  2433.     }
  2434. }
  2435.  
  2436.  
  2437.  
  2438.  
  2439.  
  2440. ################################################################################
  2441. #
  2442. #  Load a script into gnuplot 
  2443. #      
  2444. #
  2445.  
  2446. proc GP_LoadScript {} {
  2447.     global gp_cwd
  2448.     catch { cd "$gp_cwd" } hmm
  2449.     set GPLTFile [ getfile "Choose a script to load:" ]
  2450.    if { $GPLTFile != "" } {    
  2451.        GP_SendCommand  "load \'$GPLTFile\'" 0
  2452.     }
  2453. }
  2454.  
  2455.  
  2456.  
  2457. ################################################################################
  2458. #
  2459. #  Tell gnuplot to save settings...
  2460. #
  2461. #
  2462. #
  2463.  
  2464. proc GP_SaveSettings { what } {
  2465. global  GPLTmodeVars gp_cwd gp_TYPE gp_CREA
  2466.  
  2467.    catch { cd "$gp_cwd" } hmm
  2468.    set tCREA $gp_CREA
  2469.    set tTYPE $gp_TYPE
  2470.    set gp_CREA {ALFA}
  2471.    set gp_TYPE {TEXT}
  2472.     set where [ putfile "Save current gnuplot settings" \
  2473.       [format "gnuplot%src.gp" [string toupper $what ] ] ]
  2474.     if { $where != "" } { 
  2475.       GP_SendCommand "save $what \'$where\'" 0
  2476.     }
  2477.     set gp_CREA  $tCREA
  2478.     set gp_TYPE  $tTYPE
  2479. }
  2480.  
  2481.  
  2482.  
  2483. ################################################################################
  2484. #
  2485. #  Tell gnuplot where the current dir is...
  2486. #
  2487. #
  2488. #
  2489.  
  2490. proc GP_SetCWD {} {
  2491.     set gp_cwd [ get_directory -p "Select gnuplot working folder"]
  2492.     if { $gp_cwd != "" } {
  2493.         GP_SendCommand "cd \'$gp_cwd\'" 0
  2494.     }
  2495. }
  2496.  
  2497.  
  2498.  
  2499. ################################################################################
  2500. #
  2501. #  Tell gnuplot to change the point size
  2502. #
  2503. #
  2504. #
  2505.  
  2506. proc GP_SetPTSZ {} {
  2507.     GP_SendCommand " set pointsize [ getline "Enter point size" 1 ] " 0
  2508. }
  2509.  
  2510. ################################################################################
  2511. #
  2512. #  Choose a file to plot and write "plot 'filename'" on command line
  2513. #
  2514. #
  2515. #
  2516.  
  2517. proc GP_ChoosePlotFile { } {
  2518.     global gp_Console gp_cwd
  2519.     catch { cd "$gp_cwd" } hmm
  2520.     set plotfile [ getPathName "Choose a file to plot" 1 ] 
  2521.    if { $plotfile != "" } {
  2522.         insertText -w $gp_Console "plot \'$plotfile\' "
  2523.     }
  2524. }
  2525.  
  2526.  
  2527. ################################################################################
  2528. #
  2529. #  Setup menu flags, etc ... assuming gnuplot is off
  2530. #
  2531. #
  2532. #
  2533. proc GP_OffSet {} {
  2534. global GPLTMenu gp_CreatorList
  2535.     
  2536.     enableMenuItem gnuplotOptions "clearHistory" off                 
  2537.     enableMenuItem $GPLTMenu "quit gnuplot" off                 
  2538.     enableMenuItem $GPLTMenu "graph" off                 
  2539.     enableMenuItem $GPLTMenu "history" off                 
  2540.     enableMenuItem $GPLTMenu "saveSettings" off  
  2541.     enableMenuItem gnuplotOptions "setPointSize..." off  
  2542.     enableMenuItem $GPLTMenu "setWorkingFolder..." off
  2543.     enableMenuItem $GPLTMenu "choosePlotFile..."     off
  2544.     
  2545.     if {[llength $gp_CreatorList] == 0} {
  2546.         enableMenuItem  setOutputCreator "Select..." off
  2547.         enableMenuItem  setOutputCreator "Delete..." off
  2548.     }
  2549.     
  2550. }
  2551.  
  2552. ################################################################################
  2553. #
  2554. #  TEMPORARY JUNK
  2555. #
  2556. #
  2557. #
  2558. set gp_cwd "???"
  2559.  
  2560. proc aevt { hmm } { #dummy procedure too fool 68k into semi-working w/eventHandler....
  2561.    if { $hmm == "'GP_A'()" } {
  2562.         GP_Activate
  2563.    } elseif {$hmm=="'GP_C'()" } {
  2564.        GP_Results "gnuplot> "
  2565.       
  2566.    }    
  2567. }
  2568.      
  2569.  
  2570. ################################################################################
  2571. #
  2572. #  Things to do in order to properly setup gnuplot mode menu
  2573. #
  2574. #
  2575. #
  2576. lappend allModeMenus  GPLTMenu
  2577. set modeMenus(GPLT)    { GPLTMenu }
  2578. set gp_modflag 0
  2579. GP_OffSet
  2580.  
  2581.  
  2582. ################################################################################
  2583. #
  2584. #  A simple user message
  2585. #
  2586. #
  2587. #
  2588. proc GP_Readme {} {    
  2589.   set wname "message"
  2590.   new -n $wname
  2591.   GP_uFD
  2592.   
  2593.   catch [ newMode [set winModes([lindex [winNames] 0]) GPLT] ]
  2594.   
  2595.   insertText { 
  2596. #
  2597.    gnuplotMode.tcl Version 1.6
  2598.  
  2599. #   NEWSTUFF:
  2600. #   ---------
  2601.  
  2602.    This version has a simple floating menu with a button that lists
  2603.    all texts files in the scripts directory of gnuplot home dir.
  2604.    To run a script, just select it from the scripts menu.  To edit
  2605.    a script in Alpha, select a script menu item while holding down a 
  2606.    modifier key (shift, option, command, OR ctrl).
  2607.  
  2608.  
  2609.    Modify some of the GPLT mode behaviour by choosing the menu item:
  2610.  
  2611. #     Config:Current Mode:Flags...
  2612.  
  2613.  
  2614.    Edit keyword coloring by choosing the menu item:
  2615.  
  2616. #     Config:Current Mode:Edit Prefs
  2617.  
  2618.  
  2619.  
  2620. #   GNUPLOT works best with Alpha 6.2 or later
  2621. #   ------------------------------------------
  2622.  
  2623. #   FOR 68K USERS ONLY
  2624. #   ------------------
  2625.  
  2626.    Recent versions of Alpha (<6.2) do not have a fully working      
  2627.    eventHandler procedure.  Thus, you might notice strange behavior  
  2628.    in the gnuplot console.  The symptoms of the problem are that     
  2629.    a new gnuplot prompt may not be displayed on the screen after     
  2630.    pressing a carriage return;  or, longer messages may be garbled. 
  2631.   
  2632.    Try the following: 
  2633.  
  2634. #      set term post
  2635. #      plot sin(x)
  2636.  
  2637.    If you see pages of postscript output, then the eventHandler is 
  2638.    apparently working.
  2639.  
  2640.    If not, then to make effective use of the console you may need   
  2641.    to open the Config:Current Mode:flags... menu in Alpha (when in  
  2642.    
  2643.    Keep an eye out at ftp://www.cs.umd.edu/pub/faculty/keleher/Alpha
  2644.    for the latest versions of Alpha which will eventually solve      
  2645.    this problem.
  2646.  
  2647. #   jeff@wave.nrl.navy.mil 
  2648. }    
  2649.    
  2650.   setWinInfo -w $wname dirty 0
  2651.      
  2652. }
  2653.  
  2654.  
  2655. #############################################################################
  2656. #
  2657. #  change behavior of editCurrentModePrefs
  2658. #
  2659. # I need to "source $HOME:tcl:systemcode:prefs.tcl" before renaming
  2660. # the procedure "editCurrentPrefs" so I call "buildRecentFiles"
  2661.  
  2662. buildRecentFiles
  2663.  
  2664. #
  2665. #
  2666.  
  2667. if    {![string length [info commands GP_editCurrentModePrefs] ]} {    
  2668.     global mode GPLTmodeVars gp_modflag PREFS gp_HistGEOM gp_GEOM
  2669.     global GPLTMenu  gp_Graph gp_Console  gp_Hist 
  2670.     global PREFS HOME 
  2671.         
  2672.      rename editCurrentModePrefs GP_editCurrentModePrefs
  2673.      
  2674.      proc editCurrentModePrefs { } {
  2675.        global mode GPLTmodeVars gp_modflag PREFS gp_HistGEOM gp_GEOM
  2676.        global GPLTMenu  gp_Graph gp_Console  gp_Hist 
  2677.        global PREFS HOME 
  2678.  
  2679.        set ans [GP_editCurrentModePrefs]
  2680.        set wins  [winNames]
  2681.        set jjwinThere [lsearch $wins "GPLTPrefs.tcl"]
  2682.        set searchString1 {[\n\r]###BGK[\n\r](.*)[\n\r]###EGK[\n\r]}
  2683.       
  2684.        if { $jjwinThere >= 0} {
  2685.            set ss [searchInFile "$PREFS:GPLTPrefs.tcl"  "$searchString1" ]
  2686.            if { $ss == "" } {
  2687.                    goto [maxPos]
  2688.                if {$ss == ""} {
  2689.                    set ss [searchInFile "$HOME:tcl:usercode:gnuplotMode.tcl" \
  2690.                      "$searchString1" ]
  2691.                 }
  2692.                if {$ss == ""} {
  2693.                    set ss [searchInFile "$HOME:tcl:systemcode:gnuplotMode.tcl" \
  2694.                      "$searchString1" ]
  2695.                 }
  2696.                if {$ss == ""} {                                                   
  2697.                    set ss [searchInFile "$PREFS:gnuplotMode.tcl" "$searchString1" ]
  2698.                 } 
  2699.                if {$ss == ""} {                                                   
  2700.                    set ss [searchInFile "$HOME:tcl:Modes:gnuplotMode.tcl" \
  2701.                      "$searchString1" ]
  2702.                 } 
  2703.                if {$ss == ""} {                                                   
  2704.                    alertnote "Sorry, you'll have to edit gnuplotMode.tcl on your own."
  2705.                 } else {
  2706.                   insertText  -w "GPLTPrefs.tcl" "\n\n$ss\n\n"
  2707.                   goto 1
  2708.                }
  2709.            }
  2710.       }
  2711.       return $ans
  2712.      }
  2713.  }
  2714.  
  2715.  
  2716. #############################################################################
  2717. #
  2718. #  Use hyperlinks in the comments at the beginning of this file to 
  2719. #  auto-install this mode.
  2720. #
  2721.  
  2722. proc GP_INSTALLER1.6 {}  {
  2723. global HOME PREFS startingUp
  2724.  
  2725.  set fname [lindex [winNames -f] 0]
  2726.  catch [GP_Readme]
  2727.  if { [string match {*gnuplotMode.tcl} $fname ] } {
  2728.      edit   "$PREFS:prefs.tcl"
  2729.      
  2730.     set searchString {gnuplot}
  2731.     
  2732.     set pos [search -n $searchString 1]
  2733.     while { $pos != "" } {
  2734.        commentLine    
  2735.        set pos [search -n $searchString [lindex $pos 1]]
  2736.     }
  2737.     
  2738.     set gp_ver "1.6"
  2739.  
  2740.     # Rename old versions of gnuplot.tcl and gnuplotMode.tcl
  2741.     catch {removeFile "$PREFS:gnuplotMode.tcl-pre-$gp_ver" } ans
  2742.     catch {moveFile "$PREFS:gnuplotMode.tcl" \
  2743.                     "$PREFS:gnuplotMode.tcl-pre-$gp_ver" } ans
  2744.     catch {removeFile "$PREFS:gnuplot.tcl-pre-$gp_ver" } ans
  2745.     catch {moveFile "$PREFS:gnuplot.tcl" \
  2746.                     "$PREFS:gnuplot.tcl-pre-$gp_ver" } ans
  2747.  
  2748.     catch {removeFile "$HOME:gnuplotMode.tcl-pre-$gp_ver" } ans
  2749.     catch {moveFile "$HOME:gnuplotMode.tcl" \
  2750.                     "$HOME:gnuplotMode.tcl-pre-$gp_ver" } ans
  2751.     catch {removeFile "$HOME:gnuplot.tcl-pre-$gp_ver" } ans
  2752.     catch {moveFile "$HOME:gnuplot.tcl" \
  2753.                     "$HOME:gnuplot.tcl-pre-$gp_ver" } ans
  2754.  
  2755.     catch {removeFile "$HOME:tcl:usercode:gnuplotMode.tcl-pre-$gp_ver" } ans
  2756.     catch {moveFile "$HOME:tcl:usercode:gnuplotMode.tcl" \
  2757.                     "$HOME:tcl:usercode:gnuplotMode.tcl-pre-$gp_ver" } ans
  2758.     catch {removeFile "$HOME:tcl:usercode:gnuplot.tcl-pre-$gp_ver" } ans
  2759.     catch {moveFile "$HOME:tcl:usercode:gnuplot.tcl" \
  2760.                     "$HOME:tcl:usercode:gnuplot.tcl-pre-$gp_ver" } ans
  2761.  
  2762.     catch {removeFile "$HOME:tcl:systemcode:gnuplotMode.tcl-pre-$gp_ver" } ans
  2763.     catch {moveFile "$HOME:tcl:systemcode:gnuplotMode.tcl" \
  2764.                     "$HOME:tcl:systemcode:gnuplotMode.tcl-pre-$gp_ver" } ans
  2765.     catch {removeFile "$HOME:tcl:systemcode:gnuplot.tcl-pre-$gp_ver" } ans
  2766.     catch {moveFile "$HOME:tcl:systemcode:gnuplot.tcl" \
  2767.                     "$HOME:tcl:systemcode:gnuplot.tcl-pre-$gp_ver" } ans
  2768.  
  2769.     catch {removeFile "$HOME:tcl:modes:gnuplotMode.tcl-pre-$gp_ver" } ans
  2770.     catch {moveFile "$HOME:tcl:modes:gnuplotMode.tcl" \
  2771.                     "$HOME:tcl:modes:gnuplotMode.tcl-pre-$gp_ver" } ans
  2772.     catch {removeFile "$HOME:tcl:modes:gnuplot.tcl-pre-$gp_ver" } ans
  2773.     catch {moveFile "$HOME:tcl:modes:gnuplot.tcl" \
  2774.                     "$HOME:tcl:modes:gnuplot.tcl-pre-$gp_ver" } ans
  2775.  
  2776.     
  2777.     if { [info exists  startingUp] } {
  2778.         catch {cp "$fname" "$HOME:tcl:modes:gnuplotMode.tcl" } ans
  2779.         alertnote "Save your prefs.tcl file, quit and restart Alpha, and gnuplotMode.tcl is ready to go!"
  2780.     } else {
  2781.         catch {cp "$fname" "$PREFS:gnuplotMode.tcl" } ans
  2782.         goto [maxPos]
  2783.         insertText "\r\r#source gnuplotMode.tcl\rsource \$HOME:tcl:systemcode::gnuplotMode.tcl\r"
  2784.         alertnote {Remove any extra SOURCE GNUPLOT.TCL  or 
  2785.                   SOURCE GNUPLOT.TCL lines from your HOME.TCL file.  
  2786.                   Save your prefs.tcl file, and restart Alpha}
  2787.         
  2788.         
  2789.     }
  2790.               
  2791.  } else {
  2792.      alertnote "Sorry, gnuplotMode did ***NOT*** install!"
  2793.  }
  2794. }
  2795.  
  2796.  
  2797.  
  2798. #
  2799.  
  2800. set gp_fm_first 1
  2801.  
  2802. if { [info commands GP_ChangeMode] == "" } {
  2803.     rename changeMode GP_ChangeMode
  2804.  
  2805. # This is called for all open, saveas, and activate events:
  2806. proc changeMode { newmode } {    
  2807.     global gp_fm_first
  2808.     if { ($newmode == "GPLT") && ($gp_fm_first) } {
  2809.         set gp_fm_first 0
  2810.         GP_GraphButton
  2811.     }
  2812.     GP_ChangeMode $newmode
  2813. }
  2814. }
  2815.  
  2816.  
  2817.  
  2818. #############################################################################
  2819. #
  2820. #  Called from menu to handle dialogs in the server app
  2821. #  
  2822. #
  2823. proc GP_Dialog { ans } {
  2824. global  gp_FSIG
  2825.     switchTo  \'$gp_FSIG\'
  2826.     AEBuild -t 36000 -r 'GPSE' GPLT "DIAG" ---- $ans
  2827.     switchTo 'ALFA'
  2828. }
  2829.