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

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