home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / run.zip / run.RXX < prev    next >
Text File  |  2000-01-26  |  18KB  |  624 lines

  1. /*-----------------------------------------------------------------------------+
  2. |                                                                              |
  3. |  REXX source code listing for DrRexx application:                            |
  4. |    J:\drdi\projects\run\run.RES                                              |
  5. |                                                                              |
  6. |  File last modified on: 01/23/00 at: 03:16pm                                 |
  7. |  Listing produced on:   01/26/00 at: 02:45pm                                 |
  8. |                                                                              |
  9. +-----------------------------------------------------------------------------*/
  10.  
  11. SIGNAL ON SYNTAX
  12. SIGNAL ON HALT
  13. SIGNAL INIT
  14.  
  15. RETURN:
  16.   SIGNAL VALUE DrRexxEvent()
  17.  
  18. L1:
  19.   EXIT -1
  20.  
  21. L2:
  22.   INTERPRET DrRexxInterpret()
  23.   SIGNAL RETURN
  24.  
  25. /*-----------------------------------------------------------------------------+
  26. |                                                                              |
  27. |  Event handlers for dialog: D100                                             |
  28. |                                                                              |
  29. +-----------------------------------------------------------------------------*/
  30.  
  31. /* Event handlers for: D100 (DIALOG) */
  32.  
  33. D100_Init:
  34.   /* author= J. Pedone (jpedone@flash.net) */
  35.   /* Load REXX UTIL functions */
  36.   Call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  37.   Call sysloadfuncs
  38.   
  39.   /* Get current working directory */
  40.       parse arg pworkdir
  41.       If pworkdir = '' Then Do
  42.           pworkdir=Directory()
  43.       End
  44.   
  45.   /* check for root */
  46.       If LastPos('\',pworkdir) <> Length(pworkdir) Then Do
  47.           pworkdir=pworkdir||'\'
  48.       End
  49.   
  50.   /* get current work directory */
  51.       cworkdir=directory()
  52.       If LastPos('\',cworkdir) <> Length(cworkdir) Then Do
  53.           cworkdir=cworkdir||'\'
  54.       End
  55.   
  56.   /* set up some defaults */
  57.         file_found = ''
  58.         history=''
  59.       internetProg=''
  60.       oldD100=1
  61.   
  62.   /* get vars for ftp and web browser */
  63.       call iniFunctions 'read,'||pworkdir||'run.ini , browsers; WEB Browser;, browsers; FTP Browser;'
  64.       internetProg.0=iniValues.0
  65.       Do n = 1 to 2
  66.             internetProg.n = iniValues.n
  67.       End
  68.       call check_internet
  69.   
  70.   /* get history from run.ini */
  71.         Call get_data
  72.   
  73.   /* display the last command */
  74.       rc = D100.prog_list.Select(1,'Select')
  75.   
  76.   SIGNAL RETURN
  77.  
  78. /* Event handlers for: Browse_push (PUSHBUTTON) */
  79.  
  80. D100_Browse_push_Click:
  81.   /* Get file */
  82.         browse = FilePrompt('*.*','Browse',ok,'Open')
  83.   /* Put it in the run box */
  84.       rc = D100.prog_list.Text(browse)
  85.   SIGNAL RETURN
  86.  
  87. /* Event handlers for: ok_push (PUSHBUTTON) */
  88.  
  89. D100_ok_push_Click:
  90.   /* reorder history and run prog */
  91.   call run_prog
  92.   SIGNAL RETURN
  93.  
  94. /* Event handlers for: prog_list (COMBOBOX) */
  95.  
  96. D100_prog_list_Enter:
  97.   call run_prog
  98.   SIGNAL RETURN
  99.  
  100. /*-----------------------------------------------------------------------------+
  101. |                                                                              |
  102. |  Menu handlers for dialog: D100                                              |
  103. |                                                                              |
  104. +-----------------------------------------------------------------------------*/
  105.  
  106. /* Browsers */
  107. /* - Label: Internet */
  108. /* - Action: */
  109.      call internet
  110.      SIGNAL RETURN
  111.  
  112. /*-----------------------------------------------------------------------------+
  113. |                                                                              |
  114. |  Event handlers for dialog: error_dialog                                     |
  115. |                                                                              |
  116. +-----------------------------------------------------------------------------*/
  117.  
  118. /* Event handlers for: error_ok (PUSHBUTTON) */
  119.  
  120. error_dialog_error_ok_Click:
  121.   /* close error dialog */
  122.   rc=error_dialog.close()
  123.   SIGNAL RETURN
  124.  
  125. /*-----------------------------------------------------------------------------+
  126. |                                                                              |
  127. |  Event handlers for dialog: browser_setup                                    |
  128. |                                                                              |
  129. +-----------------------------------------------------------------------------*/
  130.  
  131. /* Event handlers for: browser_setup (DIALOG) */
  132.  
  133. browser_setup_Init:
  134.   /* fill in the boxes */
  135.       rc  = browser_setup.web_browser.Text(internetProg.1)
  136.       rc  = browser_setup.ftp_browser.Text(internetProg.2)
  137.   /* give the ok button the focus */
  138.       CALL browser_setup.browser_ok_push.Focus
  139.   SIGNAL RETURN
  140.  
  141. /* Event handlers for: browser_cancel_push (PUSHBUTTON) */
  142.  
  143. browser_setup_browser_cancel_push_Click:
  144.   /* close error dialog */
  145.       rc=browser_setup.close()
  146.   SIGNAL RETURN
  147.  
  148. /* Event handlers for: browser_ok_push (PUSHBUTTON) */
  149.  
  150. browser_setup_browser_ok_push_Click:
  151.   /* save browser data */
  152.       internetProg.1 = browser_setup.web_browser.Text()
  153.       internetProg.2 = browser_setup.ftp_browser.Text()
  154.   /* write out the browser info */
  155.       call iniFunctions 'set,'||pworkdir||'run.ini , browsers;WEB Browser;'||internetprog.1||',browsers; FTP Browser;'||internetprog.2
  156.       rc = browser_setup.close()
  157.       call check_internet
  158.   
  159.   SIGNAL RETURN
  160.  
  161. /* Event handlers for: prog2_push (PUSHBUTTON) */
  162.  
  163. browser_setup_prog2_push_Click:
  164.   /* get the ftp browser */
  165.       internetProgTemp2 = FilePrompt('*.exe','FTP Browser',ok,'Open')
  166.   /* put it in the box */
  167.       rc  = browser_setup.ftp_browser.Text(internetProgTemp2)
  168.   SIGNAL RETURN
  169.  
  170. /* Event handlers for: Prog1_push (PUSHBUTTON) */
  171.  
  172. browser_setup_Prog1_push_Click:
  173.   /* get the web browser */
  174.       internetProgTemp1 = FilePrompt('*.exe','Web Browser',ok,'Open')
  175.   /* put it in the box */
  176.       rc  = browser_setup.web_browser.Text(internetProgTemp1)
  177.   
  178.   
  179.   
  180.   SIGNAL RETURN
  181.  
  182. /*-----------------------------------------------------------------------------+
  183. |                                                                              |
  184. |  Global procedures:                                                          |
  185. |                                                                              |
  186. +-----------------------------------------------------------------------------*/
  187.  
  188. iniFunctions:
  189.   /* INI File functions */
  190.   /* Called as:
  191.       iniFunctions file [,application name; key name; value]
  192.   
  193.       Examples:
  194.       iniFunctions set, test.ini , paths; download; f:\temp, paths; upload; f:\dragen\download, paths; program root; f:\dragen
  195.   
  196.       iniFunctions get apps, test.ini
  197.           The values will be stored in appNames stem variable
  198.   
  199.       iniFunctions get keys, test.ini , paths
  200.           The values will be stored in keyNames stem variable
  201.   
  202.       iniFunctions read, test.ini , paths; download;, paths; upload;, paths; program root;
  203.           The values will be stored in iniValues stem variable
  204.   
  205.       iniFunctions delete app,test.ini , paths;;
  206.   
  207.       iniFunctions delete,test.ini , paths; download;
  208.   */
  209.   parse arg function ',' file ',' appAndKeysAndData
  210.   Parse upper var function function
  211.   function = Strip(function)
  212.   file = Strip(file)
  213.   appAndKeysAndData = Strip(appAndKeysAndData)
  214.   x=0
  215.   Do while appAndKeysAndData > ''
  216.       x=x+1
  217.       parse var appAndKeysAndData app ';' key ';' data ',' .
  218.       app.0 = x
  219.       app.x = Strip(app)
  220.       key.0 = x
  221.       key.x = Strip(key)
  222.       data.0 = x
  223.       data.x = Strip(data)
  224.       parse var appAndKeysAndData . ',' appAndKeysAndData
  225.   End
  226.   
  227.   
  228.   Select
  229.       When function = 'SET' Then Do
  230.           Do x = 1 to app.0
  231.                 rc=sysini(file,app.x,key.x,data.x)
  232.           End
  233.       End /* when do */
  234.   
  235.       When function = 'READ' Then Do
  236.           Drop iniValues
  237.           Do x = 1 to app.0
  238.               iniValues.0=x
  239.               iniValues.x=sysini(file,app.x,key.x)
  240.               If iniValues.x = 'ERROR:' Then Do
  241.                   iniValues.x = ''
  242.               End
  243.           End
  244.       End /* when do */
  245.   
  246.       When function = 'DELETE' Then Do
  247.           Do x = 1 to app.0
  248.                 rc=sysini(file,app.x,key.x,'DELETE:')
  249.           End
  250.       End /* when do */
  251.   
  252.       When function = 'DELETE APP' Then Do
  253.           Do x = 1 to app.0
  254.                 rc=sysini(file,app.x,'DELETE:')
  255.           End
  256.       End /* when do */
  257.   
  258.       When function = 'GET KEYS' Then Do
  259.           Drop keyNames
  260.           Do x = 1 to app.0
  261.                 rc=sysini(file,app.x,'ALL:',keyNames)
  262.           End
  263.       End /* when do */
  264.   
  265.       When function = 'GET APPS' Then Do
  266.           Drop appNames
  267.           rc=sysini(file,'ALL:',appNames)
  268.       End /* when do */
  269.   
  270.       Otherwise Do
  271.           Return 1
  272.       end /* Otherwise */
  273.   
  274.   end /* select */
  275.   
  276.   RETURN
  277.  
  278. check_internet:
  279.   /* check for existance of internet programs */
  280.       internetProg.1=strip(internetProg.1,B)
  281.       internetProg.2=strip(internetProg.2,B)
  282.   
  283.   Do n = 1 to 2
  284.       parse upper var internetProg.n prog .
  285.       drive_part=FileSpec('Drive',prog)
  286.   
  287.       Select 
  288.           When prog = '' Then Do
  289.               call not_found
  290.               call internet
  291.               Return
  292.           End
  293.   
  294.           When drive_part='' Then Do
  295.               prog=SysSearchPath('Path',prog)
  296.               if prog='' Then Do
  297.                   Call not_found
  298.                   Call internet
  299.                   Return
  300.               End
  301.           End /* when */
  302.   
  303.           Otherwise Do
  304.               Call SysFileTree prog, 'file', 'F'
  305.               If file.0 = 0 Then Do
  306.                   Call not_found
  307.                   call internet
  308.                   Return
  309.               End
  310.           End /* otherwise */
  311.       End /* select */
  312.       parse caseless var internetProg.n . parm
  313.       internetProg.n = prog||' '||parm
  314.   End
  315.   /* write out the browser info */
  316.       call iniFunctions 'set,'||pworkdir||'run.ini ,' ||,
  317.           'browsers ; WEB Browser ; '||internetprog.1||',' ||,
  318.           'browsers ; FTP Browser ; '||internetprog.2
  319.   RETURN
  320.  
  321. internet:
  322.   /* open the browser setup dialog */
  323.       rc=browser_setup.open()
  324.       call browser_setup.show
  325.   RETURN
  326.  
  327. not_found:
  328.   /* the requested prog was not found */
  329.       rc = D100.Visible(oldD100)
  330.       rc=error_dialog.open()
  331.       call error_dialog.show
  332.   RETURN
  333.  
  334. save_history:
  335.   /* save the history list */
  336.       Call iniFunctions 'set,'||pworkdir||'run.ini, ' ||,
  337.           'history ; history1 ; '||history.1||', '||,
  338.           'history ; history2 ; '||history.2||', '||,
  339.           'history ; history3 ; '||history.3||', '||,
  340.           'history ; history4 ; '||history.4||', '||,
  341.           'history ; history5 ; '||history.5||', '||,
  342.           'history ; history6 ; '||history.6||', '||,
  343.           'history ; history7 ; '||history.7||', '||,
  344.           'history ; history8 ; '||history.8||', '||,
  345.           'history ; history9 ; '||history.9||', '||,
  346.           'history ; history10 ; '||history.10
  347.   RETURN
  348.  
  349. history:
  350.   /* strip blanks */
  351.       do n = 1 to 10
  352.           history.n = strip(history.n,'B')
  353.       end
  354.   
  355.   /* rebuild history list */
  356.   Select
  357.       When D100.prog_list.Text()=history.10 Then Do
  358.           historytemp=history.1
  359.           history.1=history.10
  360.           history.10=history.9
  361.           history.9=history.8
  362.           history.8=history.7
  363.           history.7=history.6
  364.           history.6=history.5
  365.           history.5=history.4
  366.           history.4=history.3
  367.           history.3=history.2
  368.           history.2=historytemp
  369.           return
  370.       End
  371.       When D100.prog_list.Text()=history.9 Then Do
  372.           historytemp=history.1
  373.           history.1=history.9
  374.           history.9=history.8
  375.           history.8=history.7
  376.           history.7=history.6
  377.           history.6=history.5
  378.           history.5=history.4
  379.           history.4=history.3
  380.           history.3=history.2
  381.           history.2=historytemp
  382.           return
  383.       End
  384.       When D100.prog_list.Text()=history.8 Then Do
  385.           historytemp=history.1
  386.           history.1=history.8
  387.           history.8=history.7
  388.           history.7=history.6
  389.           history.6=history.5
  390.           history.5=history.4
  391.           history.4=history.3
  392.           history.3=history.2
  393.           history.2=historytemp
  394.           return
  395.       End
  396.       When D100.prog_list.Text()=history.7 Then Do
  397.           historytemp=history.1
  398.           history.1=history.7
  399.           history.7=history.6
  400.           history.6=history.5
  401.           history.5=history.4
  402.           history.4=history.3
  403.           history.3=history.2
  404.           history.2=historytemp
  405.           return
  406.       End
  407.       When D100.prog_list.Text()=history.6 Then Do
  408.           historytemp=history.1
  409.           history.1=history.6
  410.           history.6=history.5
  411.           history.5=history.4
  412.           history.4=history.3
  413.           history.3=history.2
  414.           history.2=historytemp
  415.           return
  416.       End
  417.       When D100.prog_list.Text()=history.5 Then Do
  418.           historytemp=history.1
  419.           history.1=history.5
  420.           history.5=history.4
  421.           history.4=history.3
  422.           history.3=history.2
  423.           history.2=historytemp
  424.           return
  425.       End
  426.       When D100.prog_list.Text()=history.4 Then Do
  427.           historytemp=history.1
  428.           history.1=history.4
  429.           history.4=history.3
  430.           history.3=history.2
  431.           history.2=historytemp
  432.           return
  433.       End
  434.       When D100.prog_list.Text()=history.3 Then Do
  435.           historytemp=history.1
  436.           history.1=history.3
  437.           history.3=history.2
  438.           history.2=historytemp
  439.           return
  440.       End
  441.       When D100.prog_list.Text()=history.2 Then Do
  442.           historytemp=history.1
  443.           history.1=history.2
  444.           history.2=historytemp
  445.           return
  446.       End
  447.       When D100.prog_list.Text()=history.1 Then Do
  448.           return
  449.       End
  450.       Otherwise Do
  451.             history.10=history.9
  452.             history.9=history.8
  453.             history.8=history.7
  454.             history.7=history.6
  455.             history.6=history.5
  456.             history.5=history.4
  457.             history.4=history.3
  458.             history.3=history.2
  459.             history.2=history.1
  460.             history.1=D100.prog_list.Text()
  461.       End
  462.   End
  463.   RETURN
  464.  
  465. run_prog:
  466.   /* hide the dialog */
  467.       oldD100 = D100.Visible(0)
  468.   
  469.   /* reorder the history */
  470.       call history
  471.   
  472.   /* run the program */
  473.   /* check for internet stuff */
  474.       firstFour = SubStr(D100.prog_list.text(),1,4)
  475.       parse upper var firstFour firstFour .
  476.       if firstFour = 'HTTP' | firstFour = 'WWW.' | firstFour = 'FTP:' | firstFour = 'FTP.' then do
  477.           objectID = '<JWP_RUN_TEMP>'
  478.           title = 'Browser'
  479.           class = 'WPProgram'
  480.           location = '<WP_NOWHERE>'
  481.           If firstFour='HTTP' | firstFour = 'WWW.' Then Do
  482.               parse caseless var internetProg.1 prog parm
  483.               setup = 'EXENAME='prog';' || ,
  484.               'PARAMETERS='parm||' '||D100.prog_list.text()';' || ,
  485.               'OBJECTID=' || objectID || ';' || ,
  486.               'CONCURRENTVIEW=YES' || ';'
  487.           End
  488.           If firstFour='FTP:' | firstFour = 'FTP.' Then Do
  489.               parse caseless var internetProg.2 prog parm
  490.               setup = 'EXENAME='prog';' || ,
  491.               'PARAMETERS='parm||' '||D100.prog_list.text()';' || ,
  492.               'OBJECTID=' || objectID || ';'|| ,
  493.               'CONCURRENTVIEW=YES' || ';'
  494.           End
  495.           rc = D100.close()
  496.            rc = SysCreateObject( class, title, location, setup, 'U' )
  497.           rc = SysOpenObject(objectID,0,1)
  498.           call save_history
  499.           exit 0
  500.       End
  501.   
  502.   /* check for a blank entry */
  503.       fileToRun=D100.prog_list.text()
  504.       fileToRun = strip(fileToRun,'B')
  505.       if fileToRun = '' Then Do
  506.           Exit 1
  507.       End
  508.   
  509.   /* set up for exe, com, cmd or bat (in order) */
  510.       run.0 = 6
  511.        parse var fileToRun run.1 . 
  512.       run.2 = run.1||'.exe'
  513.       run.3 = run.1||'.com'
  514.       run.4 = run.1||'.cmd'
  515.       run.5 = run.1||'.bat'
  516.       run.6 = fileToRun
  517.   
  518.   /* Change relative to absolute */
  519.       parse upper var fileToRun drive_part .
  520.       drive_part=FileSpec('Drive',drive_part)
  521.       Do i = 1 to 5
  522.           If drive_part=' ' Then Do
  523.               fileToRun=SysSearchPath('Path',run.i)
  524.           End
  525.       If fileToRun \= '' then leave
  526.       End
  527.   
  528.   /* check to see if it exists */
  529.       Call SysFileTree fileToRun, 'file', 'F'
  530.       If file.0 = 0 Then Do
  531.           Call not_found
  532.           Return
  533.       End
  534.   
  535.   /* set up the extension */
  536.       parse upper var fileToRun '.' test
  537.   
  538.   /* run it */
  539.       Select 
  540.   
  541.   /* non-executable */
  542.           When test \= 'EXE' & test \= 'COM' & test \= 'CMD' & test \= 'BAT' & test \= '' Then Do
  543.               call sysOpenObject fileToRun,'Default','True'
  544.               call sysOpenObject fileToRun,'Default','True'
  545.               call save_history
  546.               exit 0
  547.           End
  548.   
  549.   /* Executable */
  550.           When test = 'EXE' | test = 'COM' | test = 'CMD' | test = 'BAT' Then Do
  551.               parse var run.6 . parms
  552.               parse var fileToRun fileToRun .
  553.               objectID = '<JWP_RUN_TEMP>'
  554.               title = 'Run - '||fileToRun
  555.               class = 'WPProgram'
  556.               location = '<WP_NOWHERE>'
  557.               setup = 'EXENAME='fileToRun';' || ,
  558.               'PARAMETERS='||parms';' || ,
  559.               'OBJECTID=' || objectID || ';'|| ,
  560.               'CONCURRENTVIEW=YES' || ';' ,
  561.               'WORKDIR='||cworkdir||';'
  562.               rc = D100.close()
  563.                rc = SysCreateObject( class, title, location, setup, 'R' )
  564.               rc = SysOpenObject(objectID,0,1)
  565.               rc = SysOpenObject(objectID,0,1)
  566.               call save_history
  567.               exit 0
  568.           End
  569.   
  570.   /* File not found */
  571.           Otherwise Do
  572.               call not_found 
  573.           End
  574.       End
  575.   
  576.   RETURN
  577.  
  578. get_data:
  579.   /* read it in and add the contents to the combo box */
  580.       Call iniFunctions 'read,'||pworkdir||'run.ini,' ||,
  581.           'history ; history1 ; ,' ||,
  582.           'history ; history2 ; ,' ||,
  583.           'history ; history3 ; ,' ||,
  584.           'history ; history4 ; ,' ||,
  585.           'history ; history5 ; ,' ||,
  586.           'history ; history6 ; ,' ||,
  587.           'history ; history7 ; ,' ||,
  588.           'history ; history8 ; ,' ||,
  589.           'history ; history9 ; ,' ||,
  590.           'history ; history10 ; '
  591.       Do n = 1 to 10
  592.             history.n = iniValues.n
  593.           rc = D100.prog_list.Add(history.n,n)
  594.       End
  595.   
  596.   RETURN
  597.  
  598. /*-----------------------------------------------------------------------------+
  599. |                                                                              |
  600. |  Default initialization:                                                     |
  601. |                                                                              |
  602. +-----------------------------------------------------------------------------*/
  603.  
  604. INIT:
  605.   SIGNAL RETURN
  606.  
  607. /*-----------------------------------------------------------------------------+
  608. |                                                                              |
  609. |  Default error handlers:                                                     |
  610. |                                                                              |
  611. +-----------------------------------------------------------------------------*/
  612.  
  613. SYNTAX:
  614.   SAY 'SYNTAX ERROR:' errortext( rc ) 'in:'
  615.   SAY sourceline( sigl )
  616.   SIGNAL ON SYNTAX
  617.   SIGNAL RETURN
  618.  
  619. HALT:
  620.   SAY 'HALT occurred in:'
  621.   SAY sourceline( sigl )
  622.   SIGNAL ON HALT
  623.   SIGNAL RETURN
  624.