Maxlength

Pipelines v2.0

 

/* Example by TenFiftyTwo(c). */

Home

 
/* The following pipeline handles one input argument:
 
   arg 1. The maximum output record length.
 
   The pipeline reads its input and formats each paragraph so that, where possible, each
   record is no longer than (arg 1) characters in length. If an input record comprises a single
   word which is longer than (arg 1) characters in length, the record remains unchanged.
 
   Note. leading, embedded and trailing whitespace is discarded during the process. */
 
Address Rxpipe
 
Parse Arg length
 
‘pipe (stagesep ~)’,
     ‘in’,                    /* Read from input. */
     ‘~ strip trailing’,      /* Trim off trailing whitespace, so we can find blank records. */
     ‘~ split’,               /* Split into individual words. */
     ‘~ join * x20’ length ,  /* Join records up to a maximum length of &arg1. */
     ‘~ out’                  /* Write to output. */
 
Exit 0