sort-paragraph.rex

Pipelines v2.1

 

.....|...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8....+....9....+....10...

Home

     **** Top of file ****
   1
   2 /* arg 1. The number of the paragraph to sort.
   3    arg 2. The sort type (a)scending or (d)escending.
   4
   5    The pipeline reads its input and selects the specified paragraph and sorts
   6    it, writing the result back to its caller.
   7
   8    Note. that if any input record contains the hexadecimal characters x'fc'
   9    through x'ff'; you will need to substitute the character for another character
  10    not present in the record. */
  11
  12 Address Rxpipe
  13
  14 Parse Arg pnumber type
  15
  16 'pipe (endchar ?)',
  17      'in',                                  /* Input. */
  18      '| literal xfdfe',                     /* Ensure paragraph is marked. */
  19      '| strip',                             /* Trim off whitespace. */
  20      '| a: locate',                         /* Route out blank records. */
  21         ,
  22         /* Concatenate groups of records that make up a paragraph. */,
  23         ,
  24      '| specs xfc 1 1-* n',                 /* Insert start of line flag. */
  25      '| split after str xfc',               /* Split into individual records. */
  26      '| b: faninany',                       /* Feed blank records back into pipeline. */
  27      '| join until str xfc',                /* Join records in current paragraph. */
  28      '| c: nlocate xfd',                    /* Go and mark start of paragraph. */
  29      '| d: faninany',                       /* Feed paragraph marker back into pipeline. */
  30      '| split before str xfd',              /* Separate records back into paragraph format. */
  31         ,
  32         /* Select the paragraph that we want to sort. */,
  33         ,
  34      '| e: fromlab pat /Para#'pnumber'1*/', /* Select records between the start of the.. */
  35      '| f: tolabel pat xfd2a',              /* ..paragraph and the start of the next. */
  36      '| sort anycase' type ,                /* Sort the paragraph. */
  37      '| nlocate /Para#/',                   /* Discard the paragraph marker. */
  38      '| specs recno 1 1-* nw',              /* Insert leading record number. */
  39      '| g: fanin 1 0 2',                    /* Merge all the streams. */
  40      '| nlocate /Para#/',                   /* Discard all paragraph markers. */
  41      '| nlocate xfdfe',                     /* Discard start of file marker. */
  42      '| change xfd //',                     /* Discard blank record marker. */
  43      '| out',                               /* Output. */
  44      '?',
  45      'a:',
  46      '| specs xfd 1',                       /* Indicate blank records with a marker. */
  47      '| b:',
  48      '?',
  49      'c:',
  50      '| specs 1-* 1 write',                 /* Mark the start of a paragraph. */
  51              '/Para#/ n',
  52              'recno strip n',
  53      '| d:',
  54      '?',
  55      'e:',
  56      '| elastic',                           /* Handle records that come before start.. */
  57      '| g:',                                /* ..of a paragraph. */
  58      '?',
  59      'f:',
  60      '| elastic',                           /* Handle records that come after the end of.. */
  61      '| g:'                                 /* ..a paragraph. */
  62
  63 Exit 0
     **** End of file ****
 

 

 
Validate the arguments!