| Rhea, Matthew wrote:
| Here's what I used for 72 positions.
|
| /*---------------------------REXX-------------------------------------*/
| /*--------------------------------------------------------------------*/
| /* TAKES AN INPUT STATEMENT AND SPLITS IT UP SO THAT EACH */
| /* LINE IS NO LONGER THAN 72 POSITIONS */
| /*--------------------------------------------------------------------*/
| TRACE O
| INPUT. = ''
| OUTPUT. = ''
| I = 0
| J = 0
| N = 0
| /*--------------------------------------------------------------------*/
| "EXECIO * DISKR INDD (FINIS STEM INPUT."
| IF RC <> 0 THEN
| DO
| SAY 'ERROR OPENING INDD FILE'
| EXIT RC
| END /* DO */
| ELSE
| NOP
| /* END IF */
| /*--------------------------------------------------------------------*/
| DO I = 1 TO INPUT.0
| INPUT.I = STRIP(INPUT.I)
| IF LENGTH(INPUT.I) > 72 THEN
| DO WHILE LENGTH(INPUT.I) > 72
| CALL SPLIT_LINE
| END /* DO */
| ELSE
| NOP
| /* END IF */
| N = N + 1
| OUTPUT.N = INPUT.I
| END /* DO */
| /*--------------------------------------------------------------------*/
| "EXECIO * DISKW OUTDD (FINIS STEM OUTPUT."
| IF RC > 1 THEN
| DO
| SAY 'ERROR WRITING OUTDD FILE'
| EXIT RC
| END /* DO */
| ELSE
| EXIT
| /* END IF */
| /*--------------------------------------------------------------------*/
| SPLIT_LINE:
| DO J = 72 TO 1 BY -1
| IF SUBSTR(INPUT.I,J,1) = ' ' THEN
| DO
| N = N + 1
| OUTPUT.N = SUBSTR(INPUT.I,1,J -1)
| INPUT.I = SUBSTR(INPUT.I,J+1)
| LEAVE
| END /* DO */
| ELSE
| NOP
| /* END IF */
| END /*DO */
| RETURN
| /*--------------------------------------------------------------------*/
A few things...
The above code doesn't handle an input line of all blanks (or a single
blank).
The other thing is that if the input line is > 72 characters, and hasn't
any blanks in it, the DO WHILE LENGTH(INPUT.I)>72 loops.
Also, I so no need to add dead code (ELSE NOP), and non-unique comments
on END /* DO */ phrases.
So, I rewrote the above code just a wee bit and made the issuing of
error messages so that they stand out more. The code also handles a
blank input line.
I also eliminated the DO loop to find the last blank on long lines.
==========================================================================
/*REXX*/ trace o
/*--------------------------------------------------------------------+
| reads input lines & splits them so each line is less than 73 chars |
+--------------------------------------------------------------------*/
@.='' /*stem for input records. */
$.='' /*stem for output records. */
maxlen=72 /*maximum length of each line.*/
nr=0 /*number of lines written. */
"EXECIO * DISKR INDD (FINIS STEM @."
if rc\==0 then call sayer 'error opening INDD file.'
do j=1 to @.0
@.j=space(@.j)
if @.j=='' then @.j=' '
if length(@.j)>maxlen then do while length(@.j)>maxlen
_=lastpos(' ',@.j)
if _==0 then _=length(@.j)
nr=nr+1
$.nr=strip(substr(@.j,1,_-1))
@.j =strip(substr(@.j,_+1))
end
nr=nr+1
if @.j\=='' then $.nr=@.j
end
"EXECIO * DISKW OUTDD (FINIS STEM $."
if rc>1 then call sayer 'error writing OUTDD file.'
exit
sayer: say; say '***error!***' arg(1); say; say 'RC='rc; say; exit rc
=========================================================================
I feel that if you can get the whole shebang on one screen, it is easier
to comprehend (and thus, easier to modify and/or debug).
______________________________________________________________Gerard S.
| -----Original Message-----
| From: TSO REXX Discussion List [mailto:TSO-***@VM.MARIST.EDU]On Behalf
| Of Lindy Mayfield
| Sent: Wednesday, July 06, 2005 9:46 AM
| To: TSO-***@VM.MARIST.EDU
| Subject: [TSO-REXX] How to word wrap in Rexx?
|
|
| I've been thinking about this problem for a few days now and I cannot seem to get it in my head the best way to approach it. I
have a variable length text string that I want to wrap at word boundaries with a specific maximum length.
|
| For example, if I have a 50 byte fields and I have a string of 80 bytes of text, I want to split up the lines so they fit into the
50 byte fields.
|
| I have a nagging suspicion that I can do this easily in Rexx, but I'm having brain block. Anyone ever done this before? Any
specific Rexx functions that were helpful that you used or could suggest?
|
| Many thanks,
| Lindy