Anonymous user
Word wrap: Difference between revisions
→version 1: used a stemmed array instead of a long character string, faster, but more complex and harder to follow than version 0. -- ~~~~
Walterpachl (talk | contribs) m (→{{header|Python}}=: fix tag) |
(→version 1: used a stemmed array instead of a long character string, faster, but more complex and harder to follow than version 0. -- ~~~~) |
||
Line 1,558:
</pre>
('''L'''eft is the default.)
<br><br>This version was modified (for speed at the expense of simplicity) to accommodate faster processing of large files.
<lang rexx>/*REXX pgm reads a file and displays it (with word wrap to the screen). */▼
<br>Instead of appending lines of a file to a character string, the words are picked off and stored in a stemmed array.
<br>This decreases the amount of work that REXX has to do to retrieve (get) the next word in the (possibly) ginormous string.
parse arg iFID width justify _ . /*get optional CL args.*/
if iFID='' |iFID==',' then iFID ='LAWS.TXT' /*default input file ID*/
Line 1,573 ⟶ 1,576:
if _\=='' then call err "too many arguments specified." _
if \datatype(width,'W') then call err "WIDTH (2nd arg) isn't an integer:" width
do j=0 while lines(iFID)\==0 /*read from the file until E-O-F.*/
do words(_) /*extract some words (maybe not).*/
end /*j*/▼
n=n+1; parse var _ @.n _ /*get & assign next word in text.*/
end /*DO words(_)*/
▲ end /*j*/
call time 'R'
if j==0 then call err 'file' iFID "not found."
if
$=@.1 /*init da money bag with 1st word*/
do
_=$ x /*append it to the money and see.*/
if length(_)>width then call tell /*this word
$=_ /*the new words are OK so far. */
end /*
call tell /*handle any residual words. */
exit /*stick a fork in it, we're done.*/
Line 1,593 ⟶ 1,598:
/*──────────────────────────────────TELL subroutine─────────────────────*/
tell: if $=='' then return /*first word may be too long. */
if just=='L' then $= strip($) /*left ◄────────*/
else
when just=='
when just=='
end /*select*/
end
say $ /*show and tell, or write──►file?*/
_=x /*handle any word overflow. */
|