home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / epmmac.zip / MARKFILT.E < prev    next >
Text File  |  1989-08-16  |  3KB  |  81 lines

  1. /*
  2.   This file provides procedures for filtering a block,line or character mark
  3.  
  4.  pinit_extract() initializes the extraction
  5.  
  6.  pextract_string(var string)
  7.    OUTPUT
  8.      sets string to the next line in marked text and returns
  9.      code 0 if ok ,1 if last line, -1 if blank line
  10.  
  11.  pput_string_back(string)
  12.      put string back into marked text
  13.  
  14. */
  15. defproc pinit_extract()
  16.    universal zzline_ptr,zzline,zzfirstline,zzlastline,zzfirstcol,zzlastcol,zzfileid,zzleftchr,zzrightchr
  17.  
  18.    getmark zzfirstline,zzlastline,zzfirstcol,zzlastcol,zzfileid
  19.    zzline_ptr = zzfirstline - 1
  20.  
  21. defproc pextract_string(var string)
  22.    universal zzline_ptr,zzline,zzfirstline,zzlastline,zzfirstcol,zzlastcol, zzfileid,zzleftchr,zzrightchr
  23.  
  24.    /* return value: 0 if ok ,1 if last line, -1 if blank line */
  25. compile if EPM
  26.    if zzline_ptr = zzlastline | (zzline_ptr=(zzlastline-1) & not zzlastcol) then
  27.       return 1
  28.    endif
  29. compile else
  30.    if zzline_ptr = zzlastline then return 1; endif
  31. compile endif
  32.    zzline_ptr = zzline_ptr + 1
  33.    getline zzline,zzline_ptr,zzfileid
  34.    if marktype() = 'LINE' then
  35.       string = zzline           /* for a line mark it's easy */
  36.    else
  37.       if marktype() = 'BLOCK' then
  38.          zzleftchr = zzfirstcol; zzrightchr = zzlastcol
  39.       else
  40.          zzline_ptr
  41.          zzlastchr = length(zzline)
  42.          if zzline_ptr = zzfirstline then
  43.             zzleftchr = zzfirstcol
  44.             if zzline_ptr = zzlastline then
  45.                zzrightchr = zzlastcol
  46.             else
  47.                if zzlastchr then
  48.                   zzrightchr = zzlastchr
  49.                else
  50.                   zzrightchr = zzfirstcol
  51.                endif
  52.             endif
  53.          else
  54.             if zzline_ptr = zzlastline then
  55.                zzleftchr = 1; zzrightchr = zzlastcol
  56.             else
  57.                if not zzlastchr then return -1; endif
  58.                zzleftchr = 1
  59.                zzrightchr = zzlastchr
  60.             endif
  61.          endif
  62.       endif
  63.       string = substr(zzline,zzleftchr,zzrightchr-zzleftchr+1)
  64.    endif
  65. ;; if string='' then            -- Following saves 9 bytes.
  66. ;;    return -1
  67. ;; endif
  68. ;; return 0
  69.    return (string<>'') - 1
  70.  
  71.  
  72. defproc pput_string_back(string)
  73.    universal zzline_ptr,zzline,zzfirstline,zzlastline,zzfirstcol,zzlastcol,zzfileid,zzleftchr,zzrightchr
  74.  
  75.    if marktype() = 'LINE' then
  76.       zzline = string
  77.    else
  78.       zzline = substr(zzline,1,zzleftchr-1)||string||substr(zzline,zzrightchr+1)
  79.    endif
  80.    replaceline zzline,zzline_ptr,zzfileid
  81.