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