Readline interface: Difference between revisions
Content added Content deleted
(→{{header|REXX}}: added the '''changestr''' bif. -- ~~~~) |
m (→{{header|REXX}}: corrected a typo. -- ~~~~) |
||
Line 145: | Line 145: | ||
<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. |
||
<br><br>Some older REXXes don't have a '''changestr'' bif, so one is included here. |
<br><br>Some older REXXes don't have a '''changestr'' bif, so one is included here. |
||
<lang rexx>/*REXX program to implement a simple "readline" |
<lang rexx>/*REXX program to implement a simple "readline" shell. */ |
||
trace off /*suppress echoing of non-zero RC*/ |
trace off /*suppress echoing of non-zero RC*/ |
||
signal on syntax; signal on novalue |
signal on syntax; signal on novalue /*handle REXX program errors. */ |
||
cmdX='ATTRIB CAL CHDIR COPY DEL DIR ECHO EDIT FC FIND KEDIT LLL', |
cmdX='ATTRIB CAL CHDIR COPY DEL DIR ECHO EDIT FC FIND KEDIT LLL', |
||
'MEM MKDIR MORE REM REXX RMDIR SET TYPE VER XCOPY' |
'MEM MKDIR MORE REM REXX RMDIR SET TYPE VER XCOPY' |
||
Line 159: | Line 159: | ||
do forever /*do it until the fat lady sings.*/ |
do forever /*do it until the fat lady sings.*/ |
||
if prompter() then iterate |
if prompter() then iterate /*Nothing entered? So try again.*/ |
||
select /*now then, let's rock & roll. */ |
select /*now then, let's rock & roll. */ |
||
when wordpos(xxxF,cmdX)\==0 then call .cmdX |
when wordpos(xxxF,cmdX)\==0 then call .cmdX |
||
Line 176: | Line 176: | ||
er: say; say; say '****error!****'; say; say arg(1); say; say; return |
er: say; say; say '****error!****'; say; say arg(1); say; say; return |
||
err: say; say; say center(' error! ',max(40,linesize()%2),"*"); say |
err: say; say; say center(' error! ',max(40,linesize()%2),"*"); say |
||
do j=1 for arg(); say arg(j); say; end; say; exit 13 |
do j=1 for arg(); say arg(j); say; end; say; exit 13 |
||
novalue: syntax: call err 'REXX program' condition('C') "error",, |
novalue: syntax: call err 'REXX program' condition('C') "error",, |
||
condition('D'),'REXX source statement (line' sigl"):",, |
condition('D'),'REXX source statement (line' sigl"):",, |
||
sourceline(sigl) |
sourceline(sigl) |
||
/*───────────────────────────CHANGESTR subroutine───────────────────────*/ |
|||
changestr: procedure; parse arg o,h,n; r=; w=length(o); if w==0 then return n||h |
|||
do forever; parse var h y (o) _ +(w) h; if _=='' then return r||y; r=r||y||n; end |
|||
/*──────────────────────────────────.CMDX subroutine────────────────────*/ |
/*──────────────────────────────────.CMDX subroutine────────────────────*/ |
||
.cmdX: xxxF yyy; return |
.cmdX: xxxF yyy; return |