home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / EDGE1_704.DMS / in.adf / Edge_Rexx.lha / CmdShell.edge < prev    next >
Encoding:
Text File  |  1993-10-27  |  2.8 KB  |  151 lines

  1.  
  2. /*
  3. ** $VER: CmdShell.edge 1.6 (Saturday 23-Oct-93 13:30:46)
  4. **
  5. ** Edge's command shell
  6. **
  7. ** Written by Thomas liljetoft
  8. */
  9.  
  10.  
  11. options results
  12. options failat 100
  13.  
  14. /* are we already running, (using F31 in _GE_UserFlags as a semaphore) */
  15. 'flag _ge_userflags f31 set'
  16. if result = 'Set' then
  17.     do
  18.     'requestchoice' '"It appears that you already have a command-shell running.\010Do you wish to start this one anyway?"'
  19.     if RC ~= 0 then exit(0)
  20.     end
  21.  
  22. call open("stdin","console:",'R')
  23. call open("stdout","console:",'W')
  24. call writech('stdout',' ')
  25.  
  26. /* get users prefered text font */
  27. 'getenvvar' _ge_realtextfontname
  28. fontname = result
  29. 'getenvvar' _ge_realtextfontsize
  30. fontsize = result
  31. address command setfont fontname fontsize
  32.  
  33. say 'Enter commands, "Q" to exit, "?" for help.'
  34.  
  35. /*    loop until user exits */
  36.  
  37. mainloop:
  38.  
  39. signal on break_f
  40.  
  41. /*
  42. ** NOTE: ctrl f will break the command shell without trying to reset F31.
  43. */
  44.  
  45. signal on break_c
  46. signal on break_d
  47. signal on break_e
  48. signal on halt
  49. signal on ioerr
  50. signal on syntax
  51.  
  52. do forever
  53.  
  54.     call writech('stdout',''address()'> ')
  55.     cmd = readch('stdin',5000)
  56.  
  57.     select
  58.  
  59.         /* time to quit? */
  60.         when (length(cmd) = 2 & upper(left(cmd,1)) = "Q")    then do
  61.             leave
  62.       end
  63.  
  64.         /* need some help? */
  65.         when (length(cmd) = 2 & left(cmd,1) = "?") then do
  66.             say 'Enter "<command> ?" to obtain a command''s template.'
  67.             say 'Enter "HELP <command>" to obtain more help on a command.'
  68.             say 'Enter "Q" to exit command shell.'
  69.             say 'Enter "REXX <command>" to execute rexx commands.'
  70.       end
  71.  
  72.         /* do nothing on empty lines, e.g. only one character == 'return key' */
  73.         when (length(cmd) = 1) then do
  74.             'Nop'
  75.         end
  76.  
  77.         /* ctrl \ or closegadget return a null command */
  78.         when (cmd = "") then do
  79.             'closerexxio'
  80.             leave
  81.         end
  82.  
  83.         /* whatsinaline */
  84.         otherwise do
  85.  
  86.             /* if the commandstring starts with "rexx " interpret it as a rexx
  87.                 instruction instead of as an Edge command */
  88.             if upper(left(cmd,5)) = "REXX " then do
  89.                 interpret right(cmd,length(cmd) - 5)
  90.             end
  91.  
  92.             else do
  93.                 /* execute the command string, but first remove the NL character */
  94.                 left(cmd,length(cmd) - 1)
  95.             
  96.                 /* if ok show the result, if any */
  97.                 if RC == 0 then do
  98.                     if result ~= "RESULT" then say result
  99.                 end
  100.  
  101.                 else do
  102.                     /* ERROR!!!!   get fault string */
  103.                     'Fault' raw
  104.                     say "*** Edge Error ***"
  105.                     say result
  106.                 end
  107.             end
  108.             
  109.       end
  110.  
  111.     end
  112. end
  113.  
  114. 'flag _ge_userflags f31 clear'
  115. exit(0)
  116.  
  117. /* here comes the signal handler routines */
  118.  
  119. syntax:
  120.     say 'Oups....   'errortext(RC) 
  121.     signal mainloop
  122.  
  123. halt:
  124.     say 'Halted.'
  125.     'flag _ge_userflags f31 clear'
  126.     exit(0)
  127.  
  128. ioerr:
  129.     say 'IO error.'
  130.     signal mainloop
  131.  
  132. break_c:
  133.     say 'Break...'
  134.     'flag _ge_userflags f31 clear'
  135.     exit(0)
  136.  
  137. break_d:
  138.     say 'Break...'
  139.     'flag _ge_userflags f31 clear'
  140.     exit(0)
  141.  
  142. break_e:
  143.     say 'Break...'
  144.     'flag _ge_userflags f31 clear'
  145.     exit(0)
  146.  
  147. break_f:
  148.     say 'Break...'
  149.     exit(0)
  150.  
  151.