home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 50 / af050.adf / Rexx / CmdShell.dmcs next >
Text File  |  1993-07-05  |  2KB  |  86 lines

  1.  
  2. /** $VER: CmdShell.dmcs 1.1 (10.11.91)
  3.  **
  4.  ** Deluxe Music's command shell
  5.  **
  6.  ** Original by David N. Junod
  7.  ** Modified by Bill Hawes
  8.  ** Modified by Martin Taillefer
  9.  ** Modified by Talin
  10.  **/
  11.  
  12. OPTIONS RESULTS
  13. OPTIONS FAILAT 100
  14. OPTIONS PROMPT "Cmd> "
  15.  
  16.  
  17.   /* Display instructions */
  18.   SAY 'Enter commands, or press CTRL-\ to exit.'
  19.  
  20.   /* Get input until the user closes the Command Shell */
  21.   DO FOREVER
  22.  
  23.     /* Wait until the user types a command followed by RETURN */
  24.     PARSE PULL cmdString
  25.  
  26.     SELECT
  27.       WHEN (cmdString = "") | (UPPER(cmdString) = "Q") | (UPPER(cmdString) = "QUIT") THEN DO
  28.         LEAVE
  29.       END
  30.  
  31.       WHEN (cmdString = "?") | (UPPER(cmdString) = "HELP") THEN DO
  32.         SAY 'Enter "HELP <command>" to obtain a command''s template.'
  33.         SAY 'Enter CTRL-\ to close this window.'
  34.       END;
  35.  
  36.       OTHERWISE DO
  37.         CALL HandleCmd(cmdString)
  38.       END;
  39.  
  40.     END
  41.   END
  42.  
  43.   RETURN
  44.  
  45.  
  46. HandleCmd: PROCEDURE
  47. PARSE ARG cmdString
  48.  
  49.   /* Execute the command */
  50.   cmdString
  51.  
  52.   /* See if the command succeeded */
  53.   IF RC = 0 THEN DO
  54.     IF symbol('RESULT') == "VAR" THEN DO
  55.       SAY RESULT
  56.     END
  57.     RETURN
  58.   END
  59.  
  60.   /* Wasn't a host command, try running it as an ARexx script */
  61.   IF DMUSIC.LastError = 515 THEN DO
  62.     ADDRESS REXX cmdString
  63.  
  64.     /* Wasn't an ARexx script, try running it as a CLI command */
  65.     IF RC > 0 THEN DO
  66.       ADDRESS COMMAND cmdString
  67.     END
  68.  
  69.   END; ELSE DO
  70.     IF RC > 0 THEN DO
  71.       last    = DMUSIC.LastError
  72.  
  73.       GetErrorInfo DMUSIC.LastError
  74.       IF RC = 0 THEN
  75.         msg = RESULT
  76.       ELSE DO
  77.         msg = ""
  78.       END
  79.  
  80.       SAY '*** Error #'last': 'msg
  81.     END
  82.   END
  83.  
  84.   RETURN
  85. /* end of HandleCmd() */
  86.