home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / epmmac.zip / CHAROPS.E < prev    next >
Text File  |  1993-03-01  |  17KB  |  482 lines

  1. /*
  2. ┌──────────────────────────────────────────────────────────────────────────────┐
  3. │PCOMMON_ADJUST_OVERLAY:  provide the adjust mark and overlay mark function    │
  4. │for the character and line marks.                                             │
  5. └──────────────────────────────────────────────────────────────────────────────┘
  6. */
  7. compile if WANT_CHAR_OPS
  8. defproc pcommon_adjust_overlay(letter)
  9.    call checkmark()
  10.    mt=marktype()
  11. compile if EVERSION >= '5.50'
  12.    if leftstr(mt,1)<>'B' then             -- Change to block mark
  13. compile else
  14.    if mt<>'BLOCK' then             -- Change to block mark
  15. compile endif
  16.       getmark firstline,lastline,firstcol,lastcol,mkfileid
  17. compile if EVERSION >= '5.50'
  18.       if leftstr(mt,1)='C' & firstline<>lastline then
  19. compile else
  20.       if mt='CHAR' & firstline<>lastline then
  21. compile endif
  22.          sayerror CHAR_ONE_LINE__MSG
  23.          stop
  24.       endif
  25.       call pset_mark(firstline,lastline,firstcol,lastcol,'BLOCK',mkfileid)
  26.    endif
  27.    if letter='A' then adjustblock
  28.    elseif letter='O' then overlay_block
  29.    endif
  30.    if mt<>'BLOCK' then             -- Restore mark type
  31.       getmark firstline,lastline,firstcol,lastcol,mkfileid
  32.       call pset_mark(firstline,lastline,firstcol,lastcol,mt,mkfileid)
  33. compile if EVERSION >= '5.50'  -- We now retain trailing blanks...
  34.       if leftstr(mt, 1)='L' then 'strip' firstline lastline; endif
  35. compile endif
  36.    endif
  37. compile endif
  38.  
  39. /*
  40. ┌──────────────────────────────────────────────────────────────────────────────┐
  41. │PCOPY_MARK: this procedure provide the copy mark function for the character   │
  42. │marks.                                                                        │
  43. └──────────────────────────────────────────────────────────────────────────────┘
  44. */
  45. defproc pcopy_mark
  46. compile if WANT_CHAR_OPS & EVERSION < '5.50'
  47.    if marktype()='CHAR' then
  48.       if not .line then insert; top; .col=1; endif /* Corrected HURLEYJ */
  49.  
  50.       getmark firstline,lastline,firstcol,lastcol,mkfileid
  51.       getfileid thisfileid
  52.       samefile=(thisfileid=mkfileid)
  53.  
  54.       /* compute the overlay condition */
  55.       if samefile then         -- Don't bother if different files.
  56.          if (.line=lastline & .line=firstline & firstcol<=.col & .col<=lastcol) |
  57.             (.line=firstline & .line<>lastline & firstcol<=.col ) |
  58.             (.line=lastline & .line<>firstline & .col<=lastcol) |
  59.             (firstline<.line & .line<lastline)
  60.          then
  61.             sayerror -281  -- Source Destination conflict
  62.             stop
  63.          endif
  64.       endif
  65.  
  66.       /* First case:  lastline=firstline */
  67.       if lastline = firstline then
  68.          pset_mark(firstline, lastline, firstcol, lastcol, 'BLOCK', mkfileid)
  69.          copymark
  70.          len = lastcol+1-firstcol
  71.  
  72.          /* compute new position of source marked area and destination (for pmove) */
  73.          if samefile and .line=firstline then
  74.             if .col < firstcol then
  75.                firstcol = firstcol+len
  76.                lastcol  = lastcol+len
  77.             endif
  78.          endif
  79.       else
  80.          /* the other cases */
  81.  compile if EVERSION >= '4.2'     -- The new way, handles attribute bytes.
  82.          -- split destination
  83.          destcol =  .col
  84.          destline = .line
  85.          split
  86.          if (firstline>=.line) and samefile then
  87.             if firstline=.line then
  88.                firstcol  = firstcol - .col + 1
  89.                /* last col unchanged */
  90.             endif
  91.             firstline = firstline+1
  92.             lastline  = lastline+1
  93.          endif
  94.  
  95.          -- split out marked text.
  96.          activatefile mkfileid
  97. ;        if not samefile then
  98.            FinalSrcCol = .col
  99.            FinalSrcLine = .line
  100. ;        endif
  101.          firstline
  102.          .col  = firstcol
  103.          split
  104.          firstline = firstline+1
  105.          lastline  = lastline+1
  106.          if samefile and (destline>=firstline) then
  107.            destline = destline+1
  108.          endif
  109.          .col  = lastcol+1
  110.          src_at_eof = lastline>.last
  111.          if src_at_eof then
  112.             insertline "", .last+1
  113.          else
  114.             lastline
  115.             split
  116.          endif
  117.          if samefile and (destline>=lastline) then
  118.            -- the following lines are commented out because they
  119.            -- cause trouble if dest is just behind end of source.
  120.            --if destline=lastline then
  121.            --  destcol = destcol - .col + 1
  122.            --endif
  123.            destline = destline+1
  124.          endif
  125.  
  126.          -- copy marked region
  127.          numlines = lastline - firstline + 1
  128.          pset_mark(firstline, lastline,  1, 1, 'LINE', mkfileid)
  129.          activatefile thisfileid
  130.          destline
  131.          copymark
  132.  
  133.          -- adjust source region.
  134.          if samefile and (destline<firstline) then
  135.            firstline = firstline + numlines - 2
  136.            lastline  = lastline  + numlines - 2
  137.          endif
  138.  
  139.          -- close up destination
  140.            -- ??? need this ???? .col  = destcol
  141.          join
  142.           -- may need to remove a space character here.
  143.          .line + numlines - 1
  144.           -- ??? need this ???   .col  = .lastcol+1
  145.          join
  146.           -- may need to remove a space character here.
  147.  
  148.          -- close up source
  149.          activatefile mkfileid
  150.          firstline - 1
  151.          endline; firstcol = .col
  152.          --endline; we may not need this line. Try it.
  153.          join
  154.           -- may need to remove a space character here.
  155.          .line + numlines - 1
  156.          -- may not need this line .col = lastcol+1
  157.  
  158.          if src_at_eof then
  159.             deleteline .last
  160.          else
  161.             join
  162.          endif
  163.  
  164.          -- adjust source
  165.          firstline = firstline-1
  166.          lastline  = lastline -1
  167.          if not samefile then
  168.             FinalSrcLine
  169.             .col  = FinalSrcCol
  170.          endif
  171.  
  172.          -- adjust destination
  173.          if samefile and destline>firstline then
  174.            destline = destline - 2
  175.          endif
  176.  
  177.          -- return to origin
  178.          activatefile thisfileid
  179.          destline
  180.          .col  = destcol
  181.  
  182.  compile else                        -- The old way is 170 bytes shorter
  183.          split
  184.          if (firstline>=.line) and samefile then
  185.             if firstline=.line then
  186.                firstcol  = firstcol - .col + 1
  187.                /* last col unchanged */
  188.             endif
  189.             firstline = firstline+1
  190.             lastline  = lastline+1
  191.          endif
  192.  
  193.          getline firstmarkedline,firstline,mkfileid
  194.  
  195.          pset_mark(firstline, firstline,  firstcol, length(firstmarkedline), 'BLOCK', mkfileid)
  196.          copymark
  197.  
  198.          pset_mark(lastline, lastline, 1, lastcol, 'BLOCK', mkfileid)
  199.          '+1'; oldcolumn = .col; beginline  -- go to beginning of next (split) line
  200.          copymark
  201.          '-1'; .col = oldcolumn
  202.  
  203.          if lastline - firstline > 1 then
  204.             pset_mark(firstline+1, lastline-1, 1,1, 'LINE', mkfileid)
  205.             copymark
  206.          endif
  207.  
  208.          if samefile and (firstline>.line)  then
  209.            if firstline=.line+1 then
  210.              /* if the marked text was on the line in which it was to be
  211.               *  inserted, then shift the final position of the mark.
  212.               */
  213.              firstcol = lastcol + firstcol
  214.            endif
  215.            numlines = lastline - firstline-1
  216.            firstline = firstline+numlines
  217.            lastline  = lastline +numlines
  218.          endif
  219.  compile endif
  220.       endif
  221.       pset_mark(firstline, lastline, firstcol, lastcol, 'CHAR', mkfileid)
  222.       rc=0
  223.    else
  224. compile elseif EVERSION < '5.50'
  225.    call no_char_mark()
  226. compile endif
  227.       rc=0    /* Watch for memory-full, return its rc. */
  228.       copy_mark
  229. compile if WANT_CHAR_OPS & EVERSION < '5.50'
  230.    endif
  231. compile endif
  232.    return rc
  233.  
  234. /*
  235. ┌──────────────────────────────────────────────────────────────────────────────┐
  236. │PDELETE_MARK: provide delete mark function for character mark                 │
  237. └──────────────────────────────────────────────────────────────────────────────┘
  238. */
  239. defproc pdelete_mark
  240. compile if EVERSION < '5.50'
  241. /* this procedure must also keep track of the cursor position. */
  242. compile if EVERSION >= '5.50'
  243.    if .levelofattributesupport then
  244.       themarktype=marktype()
  245.       if themarktype then  -- If not, later DELETEMARK will give an error message
  246.          getmark firstline, lastline, firstcol, lastcol, mkfileid
  247.          DestinationCol=lastcol+1
  248.          findoffset=0
  249.          findline=lastline
  250.          findcolumn=lastcol
  251.  
  252.          do forever
  253.             FINDCLASS=0
  254.             Attribute_action FIND_PREV_ATTR_SUBOP, findclass, findoffset, findcolumn, findline
  255.             if not findclass then leave; endif
  256.             if themarktype=="LINE" then
  257.                if (findline<firstline) then
  258.                   leave
  259.                endif
  260.                DestinationLine=lastLine+1   /* error if lastline=.last */
  261.                DestinationCol=1
  262.             elseif (themarktype=="CHAR") then
  263.                if findline<firstline or findcolumn<firstcol then
  264.                   leave
  265.                endif
  266.                DestinationLine=lastLine
  267.             elseif (themarktype=="BLOCK") then
  268.                if findline>firstline and findcolumn<firstcol then
  269.                   iterate                   /* case 1:  to the left of the block */
  270.                elseif findline>=firstline and findcolumn>lastcol then
  271.                   iterate                   /* case 2:  to the right of the block */
  272.                elseif findline>=firstline and findcolumn>=firstcol and findcolumn<=lastcol then
  273.                   DestinationLine=findline  /* case 3:  in the block */
  274.                else
  275.                   leave                     /* case 4:  before the block (or to the left on firstline) */
  276.                endif    /* end case like if stmt */
  277.             endif     /* marktype if stmt */
  278.  
  279.              /* Move Attribute */
  280.             query_attribute theclass, thevalue, thepush, findoffset, findcolumn, findline
  281.             -- only move push/pop type attributes (tags are just deleted)
  282.             if thepush==0 or thepush==1 then
  283.                -- move attribute to destination, if cancellation delete both attributes
  284.                FastMoveAttrToBeg(theclass, thevalue,thepush, DestinationCol, DestinationLine,findcolumn,findline,findoffset)
  285.                findoffset=findoffset+1  -- since the attr rec was deleted and all attr rec were shifted to fill the vacancy
  286.             endif
  287.          enddo
  288.       endif      -- marks required if stmt
  289.    endif  -- .levelofattributesupport set
  290. compile endif  -- EVERSION >= '5.50'
  291. compile if WANT_CHAR_OPS
  292.    if marktype()='CHAR' then
  293.       getmark firstline,lastline,firstcol,lastcol,mkfileid
  294.  compile if EPM
  295.       if not lastcol then
  296.          lastline=lastline-1
  297.          getline lastlineText, lastline, mkfileid
  298.          lastcol=length(lastlineText)
  299.       endif
  300.  compile endif
  301.       getline lastlineText, lastline, mkfileid
  302.       unmark
  303.       getfileid Oldfileid
  304.       activatefile mkfileid
  305.       OldLine = .line; OldCol = .col
  306.  
  307.       if firstline == lastline then
  308.          pset_mark(firstline, firstline, firstcol, lastcol, "BLOCK", mkfileid)
  309.          deletemark
  310.          if (OldLine=firstline) and (OldCol>firstcol) then
  311.             if OldCol>lastcol  then
  312.                .col = OldCol - (lastcol-firstcol+1)
  313.             else  -- the mark enclosed the cursor
  314.                .col = firstcol
  315.             endif
  316.          endif
  317.       else
  318.          firstline; .col = firstcol
  319.          eraseendline
  320.          if length(lastlineText)>lastcol then
  321.             pset_mark(lastline, lastline, lastcol+1, length(lastlineText), "BLOCK", mkfileid)
  322.             copy_mark
  323.             unmark
  324.          endif
  325.          pset_mark(firstline+1, lastline, 1, 1, "LINE", mkfileid)
  326.          deletemark
  327.          if (OldLine>firstline) then
  328.             if (OldLine>lastline) then
  329.                OldLine - (lastline-firstline)
  330.                .col  = OldCol
  331.             else
  332.                if (OldLine<lastline) then
  333.                   .col = firstcol
  334.                   firstline
  335.                else  -- Oldline == lastline
  336.                   if OldCol>lastcol then
  337.                      .col = firstcol + (OldCol-lastcol-1)
  338.                   else
  339.                      .col = firstcol
  340.                   endif
  341.                   firstline
  342.                endif
  343.             endif
  344.          else
  345.             if (OldLine=firstline) and (OldCol>.col) then
  346.                .col = firstcol
  347.             else
  348.                .col = OldCol; OldLine
  349.             endif
  350.          endif
  351.       endif
  352.       activatefile Oldfileid
  353.    else
  354. compile else  -- WANT_CHAR_OPS
  355.    call no_char_mark()
  356. compile endif  -- WANT_CHAR_OPS
  357. compile endif  -- EVERSION < '5.50'
  358.       delete_mark
  359. compile if WANT_CHAR_OPS & EVERSION < '5.50'
  360.    endif
  361. compile endif
  362.  
  363. /*
  364. ┌──────────────────────────────────────────────────────────────────────────────┐
  365. │PFILL_MARK: provide fill mark function for character mark                     │
  366. └──────────────────────────────────────────────────────────────────────────────┘
  367. */
  368. defproc pfill_mark
  369. compile if EVERSION >= 5  -- EPM doesn't have GETKEY()
  370.    if arg(1)=='' then
  371.  compile if EVERSION >= 5.21
  372.       parse value entrybox(FILL__MSG, '', '', 0, 1,
  373.              atoi(1) || atoi(0) || gethwndc(APP_HANDLE) ||
  374.              ENTER_FILL_CHAR__MSG) with button 2 k \0
  375.       if button<>\1 | k=='' then return; endif
  376.  compile else
  377.       k=entrybox(ENTER_FILL_CHAR__MSG, '', '', 0, 1)
  378.       if k=='' then return; endif
  379.  compile endif
  380.    else
  381.        k=substr(arg(1),1,1)
  382.    endif
  383. compile endif
  384. compile if WANT_CHAR_OPS
  385.    if marktype() = 'CHAR' then
  386.  compile if EVERSION < 5
  387.       if not arg() then
  388.          sayerror TYPE_A_CHAR__MSG; k = getkey()
  389.          /* Display error message - HURLEYJ */
  390.          if length(k) > 1 then sayerror PFILL_ERROR__MSG; stop endif
  391.       else
  392.          k=substr(arg(1),1,1)
  393.       endif
  394.  compile endif
  395.       call psave_pos(save_pos)
  396.       call pinit_extract()
  397.       do forever
  398.          code = pextract_string(string)
  399.          if code = 1 then leave endif
  400.          if code = 0 then
  401.             string = substr('',1,length(string),k)
  402.             call pput_string_back(string)
  403.          endif
  404.       end
  405.       call prestore_pos(save_pos)
  406.       sayerror 0
  407.    else
  408. compile else
  409.    call no_char_mark()
  410. compile endif
  411. compile if EVERSION < 5
  412.       if arg() then
  413.          fill_mark arg(1)
  414.       else
  415.          fill_mark
  416.       endif
  417. compile else
  418.       fill_mark k
  419. compile endif
  420. compile if WANT_CHAR_OPS
  421.    endif
  422. compile endif
  423.  
  424. /*
  425. ┌──────────────────────────────────────────────────────────────────────────────┐
  426. │PMOVE_MARK: provide move mark function for the character marks.               │
  427. └──────────────────────────────────────────────────────────────────────────────┘
  428. */
  429. defproc pmove_mark
  430. compile if WANT_CHAR_OPS & EVERSION < '5.50'
  431.    if marktype()='CHAR' then
  432.        getfileid thisfileid
  433.        getmark firstline,lastline,firstcol,lastcol,mkfileid
  434.        call pcopy_mark()
  435.        call pdelete_mark()
  436.        /* now calculate where the (dest) mark is. */
  437.        if firstline=lastline then
  438.           call pset_mark(.line, .line, .col, .col + lastcol - firstcol,'CHAR',thisfileid)
  439.        else
  440.           call pset_mark(.line, .line+lastline-firstline,.col,lastcol ,'CHAR',thisfileid)
  441.        endif
  442.    else
  443. compile elseif EVERSION < '5.50'
  444.    call no_char_mark()
  445. compile endif
  446.       move_mark
  447. compile if WANT_CHAR_OPS & EVERSION < '5.50'
  448.    endif
  449. compile endif
  450.  
  451. compile if WANT_CHAR_OPS = 0
  452. defproc no_char_mark
  453.    if marktype()='CHAR' then
  454.       sayerror NO_CHAR_SUPPORT__MSG
  455.       stop
  456.    endif
  457. compile endif
  458.  
  459. compile if EVERSION >= '5.50'
  460. defproc FastMoveATTRtoBeg(theclass, thevalue, thepush, DestinationCol, DestinationLine, scol, slin, soff)
  461.    if thepush<>1 then      -- an end attribute cannot cancel any attribute
  462.                            -- when placed at the beginning (most negative) so it must be
  463.                            -- inserted...
  464.       insert_attribute theclass, thevalue, thepush, -300, DestinationCol, DestinationLine
  465.       Attribute_action DELETE_ATTR_SUBOP, theclass, soff, scol, slin
  466.    else                    -- this begin attribute must be checked for cancellation
  467.       findclass=theclass
  468.       findoffset=soff
  469.       findcolumn=scol
  470.       findline=slin
  471.       Attribute_Action FIND_MATCH_ATTR_SUBOP, findclass, findoffset, findcolumn, findline
  472.       if ((findcolumn==DestinationCol) and (findline==DestinationLine)) then
  473.          /* then the attribute is canceled out */
  474.          Attribute_action DELETE_ATTR_SUBOP, theclass, soff, scol, slin
  475.          Attribute_action DELETE_ATTR_SUBOP, theclass, findoffset, findcolumn, findline
  476.       else
  477.          insert_attribute theclass, thevalue, thepush, -300, DestinationCol, DestinationLine
  478.          Attribute_action DELETE_ATTR_SUBOP, theclass, soff, scol, slin
  479.       endif
  480.    endif
  481. compile endif
  482.