Jump to content

Readline interface: Difference between revisions

→‎{{header|REXX}}: re-worked the entire program, added a sample session (for '''out0ut'''). -- ~~~~
m (→‎{{header|REXX}}: fixed help abbreviation for ''quit''. -- ~~~~)
(→‎{{header|REXX}}: re-worked the entire program, added a sample session (for '''out0ut'''). -- ~~~~)
Line 144:
<br>The HELP (?), REDO, error checking, and abbreviations took up most of the program.
<br>"User" commands (subroutines) are identified with a leading period (.) to make it easier to understand what's what.
<lang rexx>/*REXX program to implement a simple "readline" shell*hell. */
trace off /*suppress echoing of non-zero RC*/
signal on syntax; signal on novalue /*handle REXX program errors. */
cmdscmdX='?|Help|MANualATTRIB CALendarCAL CHDIR COPY DEL DIR ECHO EDIT FC|FILECOMPAre FIND HISToryKEDIT KeditLLL',
'LLL MEM MKDIR MORE PROMPTREM QuitREXX REMarkRMDIR RexxSET REDOTYPE TypeVER VERXCOPY'
cmdX='CAL DIR ECHO FC FIND KEDIT LLL MEM MORE REM REXX TYPE VER'
cls='CLS' /*define the pgm to clear screen.*/
@hist.='*** command not defined. ***' /*initialize the history database*/
Line 158 ⟶ 157:
redoing=0 /*flag for executing naked ReDO.*/
 
do forever /*do it until the fat lady sings.*/
do forever
if prompter() then iterate /*Nothing entered? So try again.*/
call prompter; if xxx=='' then iterate
select /*now then, let's rock & roll. */
when wordpos(xxxF,cmdX)\==0 then call .cmdX
when xxxF=='HISTORYEXIT' | xxxF="QUIT" then callleave /*the fat lady sung.history*/
when xxxF=='HELPHISTORY' then call .helphistory
when xxxF=='PROMPTHELP' then call .prompthelp
when xxxF=='QUITPROMPT' then leavecall .prompt
when xxxF=='REDO' then call .redo
otherwise call er 'unknown command:' xxx yyy
end /*select*/
end /*forever*/
 
say xxxF'Quittingting...' /*say goodbye, 'cause it's polite*/
exit /*stick a fork in it, we're done.*/
/*───────────────────────────────error handling subroutines and others.─*/
Line 184 ⟶ 183:
.cmdX: xxxF yyy; return
/*──────────────────────────────────.HELP subroutine────────────────────*/
.help: cmdsH='ATTRIB CHDIR CLS COPY DEL DIR ECHO EDIT FC FIND MEM',
.help: say center(strip(xxx yyy),sw-1,'═'); cmds_=cmds
cmdsH='CLS DIR ECHO FC FIND MEM 'MKDIR MORE PRINT REM RMDIR SET TREE TYPE VER XCOPY'
/*the above commands have their own help via /? */
 
cmds='?|Help|MANual ATTRIButes CALendar CD|CHDIR|CHANGEDir COPY DELete|ERASE',
'DELete|ERASE DIR ECHO EDIT FC|FILECOMPAre FIND HISTory Kedit LLL',
'MEM MD|MKDIR|MAKEDir MORE PRINT PROMPT Quit|EXIT',
'R4 RD|RMDIR|REMOVEDir REGINA REMark Rexx REDO SET TREE Type VER'
 
say center(strip(xxx yyy),sw-1,'═'); cmds_=cmds; yyyF=unabbrev(yyy)
 
help. = ' No help is available for the' yyy "command."
help.cal = 'shows a calendar for the current month or specified month.'
Line 191 ⟶ 199:
help.lll = 'shows a formatted listing of files in the current directory.'
help.prompt= 'sets the PROMPT message to the specified text.'
help.quit = 'quits (exits) this program.'
help.redo = 're-does the a command # specified (or the last command).'
help.rexx = 'executes the REXX program specified.'
 
yyyF=unabbrev(yyy)
if yyy=='' then do j=1 while cmds_\==''
parse var cmds_ x cmds_
say left('',sw%2) changestr('|',x," | ")
end /*j*/
else select
when wordpos(yyyF,cmdsH)\==0 then yyyF '/?'
Line 204 ⟶ 212:
if left(help.yyyF,1)\==' ' then say yyyF ' ' help.yyyF
else say help.yyyF
end /*select*/
return
/*──────────────────────────────────.HISTORY subroutine─────────────────*/
Line 210 ⟶ 218:
do j=1 for hist#
say right(j,w) '===>' @hist.j
end /*j*/
return
/*──────────────────────────────────.PROMPT subroutine──────────────────*/
Line 223 ⟶ 231:
parse pull xxx yyy
end
 
xxxU=xxx; upper xxxU; if xxx=='' then return
xxxU=xxx; upper xxxU; if xxx=='' then return 1 /*No input? Try again*/
yyyU=yyy; upper yyyU; yyyU=strip(yyyU)
hist#=hist#+1; /*bump the history counter. */
@hist.hist#=strip(xxx yyy) /*assign to history. */
xxxF=unAbbrev(xxx) /*expand the abbreviation (maybe)*/
return 0
/*──────────────────────────────────.redo subroutine────────────────────*/
.redo:
Line 236 ⟶ 245:
when \datatype(yyy,'W') then call er "2nd arg isn't numeric for" xxx
otherwise nop
end /*select*/
if redoing then return /*handle with kid gloves. */
yyy=yyy/1 /*normalize it: +7 7. 1e1 007 7.0*/
Line 245 ⟶ 254:
unabbrev: procedure; arg ccc
select
when abbrev('ATTRIBUTES',ccc,6) then return 'ATTRIB'
when abbrev('CALENDAR',ccc,3) then return 'CAL'
when abbrev('CHANGEDIR',ccc,7) |,
ccc=='CHDIR' |,
ccc=='CD' then return 'CHDIR'
when abbrev('CLEARSCREEN',ccc,5) then return 'CLS'
when abbrev('FILECOMPARE',ccc,9) then return 'FC'
when abbrev('DELETE',ccc,3) |,
ccc=='ERASE' then return 'DEL'
when abbrev('HISTORY',ccc,4) then return 'HISTORY'
when abbrev('HELP',ccc,1) |,
abbrev('MANUAL',ccc,3) |,
ccc=='?' then return 'HELP'
when abbrev('MAKEDIR',ccc,5) |,
ccc=='MKDIR' |,
ccc=='MD' then return 'MKDIR'
when abbrev('KEDIT',ccc,1) then return 'KEDIT'
when abbrev('QUIT',ccc,1) then return 'QUIT'
when abbrev('REMARK',ccc,3) then return 'REM'
when abbrev('REMOVEDIR',ccc,7) |,
ccc=='RMDIR' |,
ccc=='RD' then return 'RMDIR'
when abbrev('REXX',ccc,1) then return 'REXX'
when abbrev('TYPE',ccc,1) then return 'TYPE'
otherwise nop
end /*select*/
return ccc</lang>
'''output''' showing a sample session
<pre style="height:120ex;overflow:scroll">
Enter command ──or── ? ──or── Quit
hel
═══════════════════════════════════════════hel══════════════════════════════════
? | Help | MANual
ATTRIButes
CALendar
CD | CHDIR | CHANGEDir
COPY
DELete | ERASE
DELete | ERASE
DIR
ECHO
EDIT
FC | FILECOMPAre
FIND
HISTory
Kedit
LLL
MEM
MD | MKDIR | MAKEDir
MORE
PRINT
PROMPT
Quit | EXIT
R4
RD | RMDIR | REMOVEDir
REGINA
REMark
Rexx
REDO
SET
TREE
Type
VER
 
Enter command ──or── ? ──or── Quit
rexx $mayan 123,456,787,654,321
╔════╗ ╔════╗ ╔════╗ ╔════╗ ╔════╗ ╔════╗ ╔════╗ ╔════╗ ╔════╗ ╔════╗ ╔════╗
║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ∙ ║ ║ ║ ║ ∙ ║ ║ ║
║ ∙∙ ║ ║ ║ ║ ║ ║ ║ ║ ∙∙ ║ ║ ║ ║ ║ ║────║ ║────║ ║────║ ║ ║
║────║ ║ ║ ║ ║ ║────║ ║────║ ║ ∙ ║ ║ ║ ║────║ ║────║ ║────║ ║ ║
║────║ ║ ∙ ║ ║ ∙∙ ║ ║────║ ║────║ ║────║ ║ ∙∙ ║ ║────║ ║────║ ║────║ ║ ∙ ║
╚════╝ ╚════╝ ╚════╝ ╚════╝ ╚════╝ ╚════╝ ╚════╝ ╚════╝ ╚════╝ ╚════╝ ╚════╝
 
Enter command ──or── ? ──or── Quit
cal
┌────────────────────────────────────────────────────────────────────────────┐
│ │
│ │
│ June 2012 │
│ │
│ │
│ Sunday Monday Tuesday Wednesday Thursday Friday Saturday │
├──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────┤
│ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │
│ │ │ │ │ │ ─ 1 ─ │ 2 │
│ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │
├──────────┼──────────┼──────────┼──────────┼──────────┼──────────┼──────────┤
│ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │
│ 3 │ 4 │ 5 │ 6 │ 7 │ 8 │ 9 │
│ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │
├──────────┼──────────┼──────────┼──────────┼──────────┼──────────┼──────────┤
│ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │
│ 10 │ 11 │ 12 │ 13 │ 14 │ 15 │ 16 │
│ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │
├──────────┼──────────┼──────────┼──────────┼──────────┼──────────┼──────────┤
│ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │
│ 17 │ 18 │ 19 │ 20 │ 21 │ 22 │ 23 │
│ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │
├──────────┼──────────┼──────────┼──────────┼──────────┼──────────┼──────────┤
│ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │
│ 24 │ 25 │ 26 │ 27 │ 28 │ 29 │ 30 │
│ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │
└──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┘
 
 
Enter command ──or── ? ──or── Quit
LLL
mm/dd/yyyy hh:mm ──filesize── ─────────────────filename D:\*.*─────────────────
06/01/2012 10:36 2,322 DIV_GRID.TXT
05/13/2012 20:39 1,044 MOD_EXP.REX
05/13/2012 19:39 694 MOD_EXP.TXT
06/01/2012 02:32 1,439 RCOMBN.RX_
06/01/2012 02:24 7,181 READLINT.REX
05/29/2012 22:48 60 sub00.REX
──────────────────────12,740 <──────────────total bytes [6 files]
 
Enter command ──or── ? ──or── Quit
dir
Volume in drive D is -----D-----
Volume Serial Number is 68D0-6356
 
Directory of D:\
 
05/09/2012 12:40 <DIR> Config.Msi
12/16/2005 19:54 <DIR> Documents and Settings
01/15/2006 10:33 <DIR> Program Files
04/14/2010 19:58 <DIR> Recycled
12/16/2005 20:29 <DIR> System Volume Information
01/26/2011 00:21 <DIR> temp
12/16/2005 19:42 <DIR> WINDOWS
01/06/2006 14:43 211 boot.ini
06/01/2012 10:36 2,322 DIV_GRID.TXT
12/16/2005 20:18 0 IO.SYS
05/13/2012 20:39 1,044 MOD_EXP.REX
05/13/2012 19:39 694 MOD_EXP.TXT
12/16/2005 20:18 0 MSDOS.SYS
08/04/2004 12:00 47,564 NTDETECT.COM
08/04/2004 12:00 250,032 ntldr
06/01/2012 02:32 1,439 RCOMBN.RX_
06/01/2012 02:24 7,181 READLINT.REX
05/29/2012 22:48 60 sub00.REX
11 File(s) 310,547 bytes
7 Dir(s) 6,793,314,304 bytes free
 
Enter command ──or── ? ──or── Quit
help ver
════════════════════════════════════════help ver═════════════════════════════════════════
Displays the Windows XP version.
 
VER
 
Enter command ──or── ? ──or── Quit
q
QUITting...
</pre>
Cookies help us deliver our services. By using our services, you agree to our use of cookies.