Word wrap: Difference between revisions

m
→‎{{header|REXX}}: added/changed comments, added whitespace. -- ~~~~
m (→‎{{header|REXX}}: added/changed comments, added whitespace. -- ~~~~)
Line 549:
<br>No hyphenation (or de-hyphenation) is attempted.
<br>Words longer than the width of the output are acceptable and are shown, a simple change could be made to issue a notification.
<lang rexx>/*REXX (Classic) pgmprogram justifies (by words) a string of words──>words ───► screen. */
<lang rexx>
arg justify width . /*───────────JUSTIFY─────────────*/
/*REXX (Classic) pgm justifies (by words) a string of words──>screen*/
/*Center: <centered> ◄centered► */
/* Both: <──both◄──both margins──► margins──> */
/* Right: ─────>right────────►right margin */
/* Left: left margin<─────-margin◄──────── */
/*─────pick═════pick one of the above.════*/
 
arg just=left(justify,1) width . /*only use first capital letter. /*───────JUSTIFY─────────────*/
/*Center: <centered> */
/*Both: <──both margins──> */
/*Right: ─────>right margin */
/*Left: left margin<─────- */
/*─────pick one of the above.*/
 
if width=='' then width=linesize()%2 /*It's null? Then pick a default.*/
just=left(justify,1) /*only use 1st capital letter*/
if width==0 then width=40 /*notNot determinable? Then Useuse 40.*/
 
if width=='' then width=linesize()%2 /*null? Then pick a default.*/
if width==0 then width=40 /*not determinable? Use 40.*/
 
txt="Diplomacy is the art of saying 'Nice Doggy' until",
"you can find a rock. ─── Will Rodgers"
 
$='' /*this is where the money is. */
/*─────────────────────────────────────where da rubber meets da road*/
$='' /*this is where the money is.*/
 
do k=1 for words(txt); x=word(txt,k) /*parse 'til we exhaust the TXT. */
x_=word(txt,k)$ x /*getappend ait wordto fromda TXTmoney stringand see. */
if length(_)>width►width then call tell /*word(s) exceeded the width? */
_=$=_ x /*appendthe new words are itOK toso dafar. money & see*/
if length(_)>width then call tell /*word(s) exceeded the width?*/
$=_ /*the new words are OK so far*/
end
 
call tell /*handle any residual words. */
exit /*let'sstick goa homefork &in celebrate.it, we're done.*/
/*──────────────────────────────────TELL subroutine─────────────────────*/
 
tell: if $=='' then return /*first word may be too long. */
/*─────────────────────────────────────TELL subroutine──────────────*/
tell: if $=='' then return /*first word may be too long.*/
select
when just=='B' then $=justify($,width) /*<───both───>◄────both────►*/
when just=='C' then $= center($,width) /* <centered> ◄centered► */
when just=='R' then $= right($,width) /*──────>──────► right */
otherwise $= strip($) /*left<─────── ◄────────*/
end /*select*/
say $ /*show& and tell, or write──>filewrite──►file?*/
_=x /*handle any word overflow. */
return /*go back and keep truckin'. */</lang>
</lang>
The input file:
<pre style="height:15ex;overflow:scroll">