/** $VER: CmdShell.pwx 1.3 (13.1.94) ** ** PhotoworX command shell ** ** Original by David N. Junod ** Modified by Bill Hawes ** Modified by Martin Taillefer ** Modified by Olaf Barthel **/ /* Try to open locale.library in order to provide * properly localized response strings. */ IF ~SHOW(LIBRARIES,"locale.library") THEN DO CALL ADDLIB("locale.library",0,-30) END /* Let's see if we can find a proper catalog for this file. */ IF SHOW(LIBRARIES,"locale.library") THEN DO catalog = OpenCatalog("rexx/cmdshell.catalog","english",0) END OPTIONS RESULTS OPTIONS FAILAT 100 OPTIONS PROMPT GetString(0,"Cmd>")||" " /* Display instructions */ SAY GetString(1,'Enter commands, or press CTRL-\ to exit.'); /* Get input until the user closes the Command Shell */ DO FOREVER /* Enable window activation for all PhotoworX commands. */ SETATTR APPLICATION FIELD ACTIVATE VAL ON /* Wait until the user types a command followed by RETURN */ PARSE PULL cmdString SELECT WHEN (cmdString = "") THEN DO LEAVE END WHEN (cmdString = "?") | (UPPER(cmdString) = "HELP") THEN DO SAY GetString(2,'Enter "HELP " to obtain a command''s template.' || '0A'X || 'Enter CTRL-\ to close this window.'); END; OTHERWISE DO CALL HandleCmd(cmdString) END; END END IF SHOW(LIBRARIES,"locale.library") THEN DO CloseCatalog(catalog) END RETURN HandleCmd: PROCEDURE EXPOSE catalog PARSE ARG cmdString /* Turn off window activation for most PhotoworX commands * so the command shell window will stay active. */ SETATTR APPLICATION FIELD ACTIVATE VAL OFF /* Execute the command */ cmdString /* See if the command succeeded */ IF RC = 0 THEN DO IF symbol('RESULT') == "VAR" THEN DO PARSE UPPER VAR cmdString Request Command . IF Request = "HELP" THEN DO IF RESULT = "" THEN DO RESULT = GetString(3,"« This command requires no arguments »"); END SAY GetString(4," Command:") || " " || Command || '0A'X || GetString(5,"Template:") || " " || RESULT END; ELSE DO SAY RESULT END END RETURN END /* Wasn't a PhotoworX command, try running it as an ARexx script */ IF PHOTOWORX.LASTERROR = 1062 THEN DO ADDRESS REXX cmdString /* Wasn't an ARexx script, try running it as a CLI command */ IF RC > 0 THEN DO ADDRESS COMMAND cmdString END END; ELSE DO IF RC > 0 THEN DO last = PHOTOWORX.LASTERROR FAULT last IF RC = 0 THEN msg = RESULT ELSE DO msg = "" END IF RC = 5 THEN SAY GetString(6,'*** Warning') ELSE DO SAY GetString(7,'*** Error #') last': 'msg END END END RETURN /* end of HandleCmd() */ GetString: PROCEDURE EXPOSE catalog PARSE ARG number,default IF SHOW(LIBRARIES,"locale.library") THEN DO string = GetCatalogStr(catalog,number,default) END; ELSE DO string = default; END IF string = "" THEN RETURN default ELSE RETURN string /* end of GetString() */