Word wrap: Difference between revisions

Content added Content deleted
(→‎{{header|REXX}}: added original version.)
(→‎version 0: found an older version. -- ~~~~)
Line 1,472: Line 1,472:
=={{header|REXX}}==
=={{header|REXX}}==
===version 0===
===version 0===
This version was the original and it has no error checking and only does left-margin justification.
This version was the original (of version 1) and has no error checking and only does left-margin justification.
<lang rexx>/*REXX pgm reads a file and displays it (with word wrap to the screen). */
<lang rexx>/*REXX pgm reads a file and displays it (with word wrap to the screen). */
parse arg iFID width . /*get optional arguments from CL.*/
parse arg iFID width /*get optional arguments from CL.*/
@= /*nullify the text (so far). */
@= /*nullify the text (so far). */
do j=0 while lines(iFID)\==0 /*read from the file until E-O-F.*/
do j=0 while lines(iFID)\==0 /*read from the file until E-O-F.*/
@=@ linein(iFID) /*append the file's text to @ */
@=@ linein(iFID) /*append the file's text to @ */
end /*j*/
end /*j*/
$=
$=
do k=1 for words(@); x=word(@,k) /*parse until text (@) exhausted.*/
do k=1 for words(@); x=word(@,k) /*parse until text (@) exhausted.*/
_=$ x /*append it to the money and see.*/
_=$ x /*append it to the money and see.*/
if length(_)>width then call tell /*word(s) exceeded the width? */
if length(_)>width then do /*words exceeded the width? */
$=_ /*the new words are OK so far. */
say $ /*display what we got so far. */
_=x /*overflow for the next line. */
end /*k*/
call tell /*handle any residual words. */
end
exit /*stick a fork in it, we're done.*/
$=_ /*append this word to the output.*/
end /*k*/
/*──────────────────────────────────TELL subroutine─────────────────────*/
tell: if $=='' then return /*first word may be too long. */
if $\=='' then say $ /*handle any residual words. */
say $ /*show and tell, or write──►file?*/
/*stick a fork in it, we're done.*/</lang>
'''output''' is the same as version 1 using the &nbsp; '''L'''eft &nbsp; option (the default).
_=x /*handle any word overflow. */
return /*go back and keep truckin'. */</lang>
'''output''' is the same as version 1 using the &nbsp; '''L'''eft &nbsp; option (the default).


===version 1===
===version 1===