wrapping-records.rex |
Pipelines v2.1 |
.....|...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8....+....9....+....10... |
**** Top of file ****
1
2 /* The following pipeline handles two input arguments:
3
4 arg 1. The name of a file to read.
5 arg 2. The maximum record length+1.
6
7 The pipeline reads the input file: (arg 1), and formats each paragraph so that, where possible,
8 each record is no longer than (arg 2)-1 characters and displays the result on the console. If a
9 record comprises a single word which is longer than (arg 2)-1 characters in length, the record
10 remains unchanged.
11
12 Note. leading and embedded whitespace is maintained. */
13
14 Address Rxpipe
15
16 Parse Arg file length
17
18 'pipe (endchar ?)',
19 '<' file , /* Read input file. */
20 '| strip trailing', /* Trim off trailing whitespace, to find blank records. */
21 '| xlate x20 xfe', /* Change spaces to x'fe'. */
22 '| a: locate', /* Route out blank records. */
23 '| specs 1-* 1 xfe n', /* Append a x'fe' to the end of each record. */
24 '| b: faninany', /* Merge in the modified blank records. */
25 '| split after str xfe', /* Split into separate records. */
26 '| join *' length , /* Join records up to a maximum length of 'length'. */
27 '| xlate xfe x20', /* Change x'fe' to spaces. */
28 '| change xff ..', /* Delete blank record fillers. */
29 '| cons', /* Display on the console. */
30 '?',
31 'a:',
32 '| specs pad xff xff 1.'length , /* Fill blank records with the filler char: x'ff'. */
33 '| b:' /* Route back to main pipeline. */
34
35 Exit 0
**** End of file ****
|
Validate the arguments!