#!/usr/local/bin/livecode-server ## array for storing the options passed to this program local sOpts ## load options repeat with x = 0 to ($# - 1) do "put $" & x && "into tReadOpt" if char 1 of tReadOpt is "-" then repeat with y = 2 to the number of chars in tReadOpt put char y of tReadOpt into sOpts[(the number of lines in the keys of sOpts + 1)] end repeat else put tReadOpt into sOpts[(the number of lines in the keys of sOpts + 1)] end if end repeat ## read from pipe if optEnabled("p") then read from stdin until EOF put it into input end if ## get command from last command line option and execute it, then quit if optEnabled("e") then do sOpts[(the number of lines in the keys of sOpts)] put return quit end if ## otherwise assume interactive mode repeat put "lcsh[" & the folder & "]# " read from stdin for 1 line put it into tCommand if isCommand(tCommand) then put shell(tCommand) else try do tCommand catch pError put "Error:" & return put pError end try end if put return end repeat ## checks to see if the first word is a command in $PATH function isCommand pCommand set the itemDel to ":" put the folder into tFolder put false into tIsCommand repeat for each item tDir in $PATH set the folder to tDir if word 1 of pCommand is among the lines of the files then put true into tIsCommand end repeat set the folder to tFolder return tIsCommand end isCommand function optEnabled pOpt repeat for each key tKey in sOpts if sOpts[tKey] is pOpt then return true end repeat return false end optEnabled