Just in time processing on a character stream: Difference between revisions

→‎{{header|REXX}}: added/deleted/changed statements, comments, and whitespace, used templates for INPUT and OUTPUT.
(Added D)
(→‎{{header|REXX}}: added/deleted/changed statements, comments, and whitespace, used templates for INPUT and OUTPUT.)
Line 210:
 
=={{header|REXX}}==
The input file used by this REXX program only contains one page;   (it has no   ''FF'' or  (''formfeed'')   characters in it),
<br>and the injection of &nbsp; ''FF'' &nbsp; characters into the file would be like putting pencil marks into a holy book. &nbsp; <big><big><big> ☺ </big></big></big>
<lang rexx>/*REXX pgmprogram extracts characters by using a book cipher from a text file. */
parse arg iFID /*obtain optional name of file (book). */
if iFID=='' | iFID=="," then iFID="JIT.TXT" /*Not specified? Then use the default.*/
$= 'abcdefghijklmnopqrstuvwxyz'; _=$; upper _; $= '0123456789'$ || _
errTxt= ' is missing or not a positive integer: ' /*error text string.*/
askprompt= '──────────enter four parameters (all positive integers) or QUIT'
$='abcdefghijklmnopqrstuvwxyz'; _=$; upper _; $= '0123456789'$ || _
?pag=1; lin=1; FF='c'x /*assume start of page 1, /*defineline the1. phrase to be null.*/
ask='──────────enter four parameters (all positive integers) or QUIT'
pag@.=1; lin=1; @.= /*assumeread startthe ofentire pagebook 1,from linethe 1file. */
do while lines(iFID)\==0 /*readprocess thelines entirefrom book frominput stream(file.)*/
do while_=translate( lineslinein(iFID)\==0, , '9'x) /*processobtain a single linesline from input streamfile.*/
if pos(FF, _)\==0 then do; pag=pag+1; lin=1 /*bump page counter; reset line counter*/
_=translate(linein(iFID),,'9'x) /*obtain a single line from input*/
end /*stick a[↑] fork inhandle it,finding we'reof done.FF (formfeed)*/</lang>
if pos('c'x,_)\==0 then do /*was a ff (form-feed) detected? */
@.pag.lin=_ pag=pag+1 /*bumpobtain a pagesingle counterline forfrom nextinput pagefile.*/
lin=lin+1 lin=1 /*resetbump the line counter. to one. */
end /*while lines···*/ end /* [↑] handle findingread the entire input stream. of formfeed*/
?= @.pag.lin=_ /*obtaindefine the phrase ato singlebe linenull from(so inputfar)*/
lin=lin+1 do ask=0; bad=1; say prompt; pull y /*bumpget thejust─in─time linepositional counternumbers. */
end /*whileif y='QUIT' then exit 0 lines···*/ /*the user [↑]wants out readof entirethis inputloop, stream.exit*/
y=space( translate(y, $, $ || xrange() )) /*allow any separator the user wants. */
?= /*define the phrase to be null.*/
doparse prompt=0;var bad= y a.1 a.2 a.3 a.4 /*getparse J.I.T.the positionalpertinent numbersparameters. */
if words(y)>4 then do; say 'too many parameters entered.'
say ask; pull y /*obtain the numbers from console*/
if y='QUIT' then exit 0 /*the user wants out of this loop*/ iterate ask
y=space(translate(y,$,$||xrange())) end /*allowgo and try again anyto sepobtain userthe wantsparms.*/
parse var do y a.k=1 a.2 a.3for a.4 /*parsevalidate parms the pertinent{positive parametersintegers}.*/
if datatype(a.1==k,'QUITW') & a.k>0 then exititerate 0 /*the user wants out of this loop/*found a bad parameter. */
if words(y)>4 say 'parameter then' do k " is /*didmissing theor usernot havea fingeritispositive ?integer: */" a.k
iterate ask say 'too many parameters entered /*go and ask for another set of parms.' */
a.k=a.k / 1 iterate prompt /*normalize the user's parm (number). */
end /*k*/ end /*go and[↑] try againdone towith getthe parmsvalidations. */
parse value do k=a.1 a.2 fora.3 a.4 with p l w c /*validateparse parmsparameters {positivefor ints}specific names. */
x=substr( if datatypeword(a @.kp.l,'W' w), c, 1) & a.k>0 then iterate /*foundextract a badcharacter parmfrom the book. */
if x=='!' then leave /*if the stop char was found, done. */
say 'parameter ' k errTxt a.k /*issue an error message to term.*/
say right(x iterate prompt '◄─── a letter',46) /*gomight &as askwell forecho anotherchar setto ofterminal. #s.*/
?=? || x a.k=a.k/1 /*normalizeappend the user'scharacter number.to the phrase. */
end /*kj*/ /* [↑] donedisplay letters found within thebook. validations*/
say '═════►' ? parse var y p l w c /*parsestick parametersa forfork names.in it, we're all done. */</lang>
'''{{out|input''' |text=&nbsp; supplied to the console (terminal) by the user in response to the prompts, &nbsp; (the commas are optional):}}
x=substr(word(@.p.l,w),c,1) /*extract the character from book*/
if x=='!' then leave /*if the stop char found, done.*/
say right(x '◄─── a letter',46) /*might as well echo char to term*/
?=? || x /*append the character to phrase.*/
end /*j*/ /* [↑] go & keep building phrase*/
say '═════►' ? /*display letters found from book*/
/*stick a fork in it, we're done.*/</lang>
'''input''' &nbsp; supplied to the console (terminal) by the user &nbsp; (the commas are optional):
<pre>
1, 133, 4, 5
Line 266 ⟶ 259:
1, 571, 4, 12
</pre>
'''output''' {{out|input|text=&nbsp; (abbridged)}}
<pre>
──────────enter four parameters (all positive integers) or QUIT
1, 133, 4, 5 ◄■■■■■■■■■ user input (first reponse).
1, 133, 4, 5
s ◄─── a letter
──────────enter four parameters (all positive integers) or QUIT
 
·
∙ (some prompts and reponses elided.)
·
·
 
──────────enter four parameters (all positive integers) or QUIT
1, 571, 4, 12 ◄■■■■■■■■■ user input (ninth reponse).
═════► so─true.
</pre>