Readline interface: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: fixed help abbreviation for ''quit''. -- ~~~~) |
(→{{header|REXX}}: re-worked the entire program, added a sample session (for '''out0ut'''). -- ~~~~) |
||
Line 144: | Line 144: | ||
<br>The HELP (?), REDO, error checking, and abbreviations took up most of the program. |
<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. |
<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" |
<lang rexx>/*REXX program to implement a simple "readline" *hell. */ |
||
trace off /*suppress echoing of non-zero RC*/ |
trace off /*suppress echoing of non-zero RC*/ |
||
signal on syntax; signal on novalue /*handle REXX program errors. */ |
signal on syntax; signal on novalue /*handle REXX program errors. */ |
||
cmdX='ATTRIB CAL CHDIR COPY DEL DIR ECHO EDIT FC FIND KEDIT LLL', |
|||
'MEM MKDIR MORE REM REXX RMDIR SET TYPE VER XCOPY' |
|||
cmdX='CAL DIR ECHO FC FIND KEDIT LLL MEM MORE REM REXX TYPE VER' |
|||
cls='CLS' /*define the pgm to clear screen.*/ |
cls='CLS' /*define the pgm to clear screen.*/ |
||
@hist.='*** command not defined. ***' /*initialize the history database*/ |
@hist.='*** command not defined. ***' /*initialize the history database*/ |
||
Line 158: | Line 157: | ||
redoing=0 /*flag for executing naked ReDO.*/ |
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=='EXIT' | xxxF="QUIT" then leave /*the fat lady sung.*/ |
|||
when xxxF=='HISTORY' then call .history |
|||
when xxxF=='HELP' then call .help |
|||
when xxxF=='PROMPT' then call .prompt |
|||
when xxxF=='REDO' then call .redo |
|||
otherwise call er 'unknown command:' xxx yyy |
|||
end /*select*/ |
|||
end /*forever*/ |
|||
say ' |
say xxxF'ting...' /*say goodbye, 'cause it's polite*/ |
||
exit /*stick a fork in it, we're done.*/ |
exit /*stick a fork in it, we're done.*/ |
||
/*───────────────────────────────error handling subroutines and others.─*/ |
/*───────────────────────────────error handling subroutines and others.─*/ |
||
Line 184: | Line 183: | ||
.cmdX: xxxF yyy; return |
.cmdX: xxxF yyy; return |
||
/*──────────────────────────────────.HELP subroutine────────────────────*/ |
/*──────────────────────────────────.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 |
|||
'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. = ' No help is available for the' yyy "command." |
||
help.cal = 'shows a calendar for the current month or specified month.' |
help.cal = 'shows a calendar for the current month or specified month.' |
||
Line 191: | Line 199: | ||
help.lll = 'shows a formatted listing of files in the current directory.' |
help.lll = 'shows a formatted listing of files in the current directory.' |
||
help.prompt= 'sets the PROMPT message to the specified text.' |
help.prompt= 'sets the PROMPT message to the specified text.' |
||
help.quit = 'exits this program.' |
help.quit = 'quits (exits) this program.' |
||
help.redo = 're-does the |
help.redo = 're-does the command # specified (or the last command).' |
||
help.rexx = 'executes the REXX program specified.' |
help.rexx = 'executes the REXX program specified.' |
||
yyyF=unabbrev(yyy) |
|||
if yyy=='' then do j=1 while cmds_\=='' |
if yyy=='' then do j=1 while cmds_\=='' |
||
parse var cmds_ x cmds_ |
parse var cmds_ x cmds_ |
||
say left('',sw%2) changestr('|',x," | ") |
say left('',sw%2) changestr('|',x," | ") |
||
end |
end /*j*/ |
||
else select |
else select |
||
when wordpos(yyyF,cmdsH)\==0 then yyyF '/?' |
when wordpos(yyyF,cmdsH)\==0 then yyyF '/?' |
||
Line 204: | Line 212: | ||
if left(help.yyyF,1)\==' ' then say yyyF ' ' help.yyyF |
if left(help.yyyF,1)\==' ' then say yyyF ' ' help.yyyF |
||
else say help.yyyF |
else say help.yyyF |
||
end |
end /*select*/ |
||
return |
return |
||
/*──────────────────────────────────.HISTORY subroutine─────────────────*/ |
/*──────────────────────────────────.HISTORY subroutine─────────────────*/ |
||
Line 210: | Line 218: | ||
do j=1 for hist# |
do j=1 for hist# |
||
say right(j,w) '===>' @hist.j |
say right(j,w) '===>' @hist.j |
||
end |
end /*j*/ |
||
return |
return |
||
/*──────────────────────────────────.PROMPT subroutine──────────────────*/ |
/*──────────────────────────────────.PROMPT subroutine──────────────────*/ |
||
Line 223: | Line 231: | ||
parse pull xxx yyy |
parse pull xxx yyy |
||
end |
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) |
yyyU=yyy; upper yyyU; yyyU=strip(yyyU) |
||
hist#=hist#+1; /*bump the history counter. */ |
hist#=hist#+1; /*bump the history counter. */ |
||
@hist.hist#=strip(xxx yyy) /*assign to history. */ |
@hist.hist#=strip(xxx yyy) /*assign to history. */ |
||
xxxF=unAbbrev(xxx) /*expand the abbreviation (maybe)*/ |
xxxF=unAbbrev(xxx) /*expand the abbreviation (maybe)*/ |
||
return |
return 0 |
||
/*──────────────────────────────────.redo subroutine────────────────────*/ |
/*──────────────────────────────────.redo subroutine────────────────────*/ |
||
.redo: |
.redo: |
||
Line 236: | Line 245: | ||
when \datatype(yyy,'W') then call er "2nd arg isn't numeric for" xxx |
when \datatype(yyy,'W') then call er "2nd arg isn't numeric for" xxx |
||
otherwise nop |
otherwise nop |
||
end |
end /*select*/ |
||
if redoing then return /*handle with kid gloves. */ |
if redoing then return /*handle with kid gloves. */ |
||
yyy=yyy/1 /*normalize it: +7 7. 1e1 007 7.0*/ |
yyy=yyy/1 /*normalize it: +7 7. 1e1 007 7.0*/ |
||
Line 245: | Line 254: | ||
unabbrev: procedure; arg ccc |
unabbrev: procedure; arg ccc |
||
select |
select |
||
when abbrev('ATTRIBUTES',ccc,6) then return 'ATTRIB' |
|||
when abbrev('CALENDAR',ccc,3) then return 'CAL' |
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('CLEARSCREEN',ccc,5) then return 'CLS' |
||
when abbrev('FILECOMPARE',ccc,9) then return 'FC' |
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('HISTORY',ccc,4) then return 'HISTORY' |
||
when abbrev('HELP',ccc,1) |, |
when abbrev('HELP',ccc,1) |, |
||
abbrev('MANUAL',ccc,3) |, |
abbrev('MANUAL',ccc,3) |, |
||
ccc=='?' then return 'HELP' |
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('KEDIT',ccc,1) then return 'KEDIT' |
||
when abbrev('QUIT',ccc,1) then return 'QUIT' |
when abbrev('QUIT',ccc,1) then return 'QUIT' |
||
when abbrev('REMARK',ccc,3) then return 'REM' |
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('REXX',ccc,1) then return 'REXX' |
||
when abbrev('TYPE',ccc,1) then return 'TYPE' |
when abbrev('TYPE',ccc,1) then return 'TYPE' |
||
otherwise nop |
otherwise nop |
||
end |
end /*select*/ |
||
return ccc</lang> |
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> |