home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / forth / compiler / fpc / source / sedsort.seq < prev    next >
Text File  |  1989-03-29  |  2KB  |  59 lines

  1. \ SEDSORT.SEQ   Sort the lines of a paragraph           by Tom Zimmer
  2.  
  3. editor definitions
  4.  
  5. 0 value colsave
  6.  
  7. variable sortto
  8. variable sortfrm
  9.  
  10. create sort1.buf 142 allot
  11. create sort2.buf 142 allot
  12.  
  13. headerless
  14.  
  15. : sortline      ( --- )
  16.                 linebuf 1+ sort1.buf 1+ 132 cmove
  17.                 linelen sort1.buf c! ldel
  18.                 @> sortfrm dup @> sortto
  19.                 do      sort2.buf colsave + 15 blank
  20.                         i #lineseginfo 2- ?cs: sort2.buf rot
  21.                         colsave 15 + min
  22.                         cmovel sort2.buf colsave +
  23.                         sort1.buf 1+ colsave + 8 compare 0>
  24.                         if drop i leave then
  25.                 loop    backto.line <nln>
  26.                 sort1.buf dup linebuf 132 cmove
  27.                 c@ =: linelen  @> rmargin linebuf c!
  28.                 modified putline getline
  29.                 sortfrm incr   @> sortfrm to.line ;
  30.  
  31. : ssort         ( --- )         \ sort lines of a paragraph
  32.                 ?browse ?exit
  33.                 linelen 0= ?lastline or if sdln exit then
  34.                 screenchar =: colsave
  35.                 ?shiftkey save!> caps
  36.                      true save!> imode
  37.                            save> screenline
  38.                         0 save!> screenchar
  39.                 curline =: sortto
  40.                 sdln
  41.                 curline =: sortfrm
  42.                 begin   modified
  43.                         putline getline
  44.                         linelen 0> ?lastline 0= and
  45.                 while   sortline
  46.                 repeat  sortto @ backto.line
  47.                 restore> screenchar
  48.                 restore> screenline
  49.                 restore> imode
  50.                 restore> caps
  51.                 scrshow ;
  52.  
  53. ' ssort is sortlin
  54.  
  55. headers
  56.  
  57. forth definitions
  58.  
  59.