home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / GFX / Misc / PWP522.DMS / in.adf / Rexx / CmdShell.pwx next >
Encoding:
Text File  |  1994-10-27  |  3.0 KB  |  138 lines

  1. /** $VER: CmdShell.pwx 1.3 (13.1.94)
  2.  **
  3.  ** PhotoworX command shell
  4.  **
  5.  ** Original by David N. Junod
  6.  ** Modified by Bill Hawes
  7.  ** Modified by Martin Taillefer
  8.  ** Modified by Olaf Barthel
  9.  **/
  10.  
  11. /* Try to open locale.library in order to provide
  12.  * properly localized response strings.
  13.  */
  14.  
  15. IF ~SHOW(LIBRARIES,"locale.library") THEN DO
  16.   CALL ADDLIB("locale.library",0,-30)
  17. END
  18.  
  19. /* Let's see if we can find a proper catalog for this file. */
  20.  
  21. IF SHOW(LIBRARIES,"locale.library") THEN DO
  22.   catalog = OpenCatalog("rexx/cmdshell.catalog","english",0)
  23. END
  24.  
  25. OPTIONS RESULTS
  26. OPTIONS FAILAT 100
  27. OPTIONS PROMPT GetString(0,"Cmd>")||" "
  28.  
  29. /* Display instructions */
  30. SAY GetString(1,'Enter commands, or press CTRL-\ to exit.');
  31.  
  32. /* Get input until the user closes the Command Shell */
  33. DO FOREVER
  34.  
  35.   /* Enable window activation for all PhotoworX commands. */
  36.  
  37.   SETATTR APPLICATION FIELD ACTIVATE VAL ON
  38.  
  39.   /* Wait until the user types a command followed by RETURN */
  40.   PARSE PULL cmdString
  41.  
  42.   SELECT
  43.     WHEN (cmdString = "") THEN DO
  44.       LEAVE
  45.     END
  46.  
  47.     WHEN (cmdString = "?") | (UPPER(cmdString) = "HELP") THEN DO
  48.       SAY GetString(2,'Enter "HELP <command>" to obtain a command''s template.' || '0A'X || 'Enter CTRL-\ to close this window.');
  49.     END;
  50.  
  51.     OTHERWISE DO
  52.       CALL HandleCmd(cmdString)
  53.     END;
  54.  
  55.   END
  56. END
  57.  
  58. IF SHOW(LIBRARIES,"locale.library") THEN DO
  59.   CloseCatalog(catalog)
  60. END
  61.  
  62. RETURN
  63.  
  64.  
  65. HandleCmd: PROCEDURE EXPOSE catalog
  66. PARSE ARG cmdString
  67.  
  68.   /* Turn off window activation for most PhotoworX commands
  69.    * so the command shell window will stay active.
  70.    */
  71.  
  72.   SETATTR APPLICATION FIELD ACTIVATE VAL OFF
  73.  
  74.   /* Execute the command */
  75.   cmdString
  76.  
  77.   /* See if the command succeeded */
  78.   IF RC = 0 THEN DO
  79.     IF symbol('RESULT') == "VAR" THEN DO
  80.       PARSE UPPER VAR cmdString Request Command .
  81.       IF Request = "HELP" THEN DO
  82.         IF RESULT = "" THEN DO
  83.           RESULT = GetString(3,"« This command requires no arguments »");
  84.         END
  85.         SAY GetString(4," Command:") || " " || Command || '0A'X || GetString(5,"Template:") || " " || RESULT
  86.       END; ELSE DO
  87.         SAY RESULT
  88.       END
  89.     END
  90.     RETURN
  91.   END
  92.  
  93.   /* Wasn't a PhotoworX command, try running it as an ARexx script */
  94.   IF PHOTOWORX.LASTERROR = 1062 THEN DO
  95.     ADDRESS REXX cmdString
  96.  
  97.     /* Wasn't an ARexx script, try running it as a CLI command */
  98.     IF RC > 0 THEN DO
  99.       ADDRESS COMMAND cmdString
  100.     END
  101.  
  102.   END; ELSE DO
  103.     IF RC > 0 THEN DO
  104.       last = PHOTOWORX.LASTERROR
  105.  
  106.       FAULT last
  107.  
  108.       IF RC = 0 THEN
  109.         msg = RESULT
  110.       ELSE DO
  111.         msg = ""
  112.       END
  113.  
  114.       IF RC = 5 THEN
  115.         SAY GetString(6,'*** Warning')
  116.       ELSE DO
  117.         SAY GetString(7,'*** Error #') last': 'msg
  118.       END
  119.     END
  120.   END
  121.  
  122.   RETURN
  123. /* end of HandleCmd() */
  124.  
  125.  
  126. GetString: PROCEDURE EXPOSE catalog
  127. PARSE ARG number,default
  128.  
  129.   IF SHOW(LIBRARIES,"locale.library") THEN DO
  130.     string = GetCatalogStr(catalog,number,default)
  131.   END; ELSE DO
  132.     string = default;
  133.   END
  134.  
  135.   IF string = "" THEN RETURN default
  136.                  ELSE RETURN string
  137. /* end of GetString() */
  138.