home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / EPMATR.ZIP / HIDEIT.E < prev    next >
Text File  |  1989-07-06  |  15KB  |  440 lines

  1. /*
  2.  
  3.   This file contains code that implements the hiding and restoring of
  4. hidden text. It works in conjuction with the attribute routines provided in
  5. attr.e. Support for loading and saving files with hidden text can be found
  6. in AttrLod.e.
  7.  
  8.  
  9. */
  10.  
  11.  
  12.  
  13. -------------------------------------------------------------------------------
  14. defproc StashPhrase(ThePhrase)
  15.    universal HIDEIT_Next_Index
  16.    compile if 0
  17.       getfileid thisfileid
  18.       getfileid HiddenFileID, "hidnstuf.xxx"
  19.  
  20.       if HiddenFileID=='' then
  21.      compile if EVERSION < 5
  22.         "e /n /h /q hidnstuf.xxx"
  23.      compile else
  24.         "e /n /q hidnstuf.xxx"
  25.         .visible = 0
  26.      compile endif
  27.       else
  28.         activatefile HiddenFileID
  29.       endif
  30.       FirstOne = "["HIDEIT_Next_Index"]"ThePhrase
  31.       insertline FirstOne, HiddenFileID.last+1
  32.       activatefile thisfileid
  33.  
  34.    compile else
  35.       OldRc = RC; RC = 0
  36.       display -2
  37.       do_array 6, ArrayID, "associated_strings"
  38.       display 2
  39.       if RC then
  40.          RC = OldRC
  41.          do_array 1, ArrayID, "associated_strings"
  42.       else
  43.          RC = OldRC
  44.       endif
  45.       do_array 2, ArrayID, HIDEIT_Next_Index, ThePhrase
  46.    compile endif
  47.    HIDEIT_Next_Index = HIDEIT_Next_Index+1
  48.    return HIDEIT_Next_Index - 1
  49.  
  50. -------------------------------------------------------------------------------
  51. defproc HideCharRegion(BLine, ELine, BCol, ECol)
  52.      universal HIDEIT_Next_Index
  53.      oldmarktype = marktype()
  54.      getmark firstmline, lastmline,firstmcol,lastmcol,mkfileid
  55.      getfileid thisfileid
  56.      if (thisfileid==mkfileid) and
  57.         (((firstmline<=ELine) and (firstmline>=BLine)) or
  58.          ((lastmline<=ELine)  and (lastmline>=BLine))) then
  59.        /* Our region interferes with a marked region. */
  60.        /*call prestore_pos(old_position);*/
  61.        call showmessage("No Action: Existing Marked region interferes with  ",
  62.                    "           region to be hidden.                    ")
  63.        return 0
  64.      else
  65.        unmark
  66.        --OldCommandState = commandstate()
  67.        if BCol then
  68.           BLine; .col=BCol; markchar
  69.        else
  70.           BLine-1; endline; markchar
  71.        endif
  72.        if ECol then
  73.           ELine; .col=ECol; markchar
  74.        else
  75.          -- this is how one marks column 0...
  76.           ELine-1; endline; markchar
  77.        endif
  78.        -- deal with hidden buffer
  79.        getfileid HiddenFileID, "hidnstuf.xxx"
  80.        if HiddenFileID=='' then
  81. compile if EVERSION < 5
  82.          "e /n /h /q hidnstuf.xxx"
  83. compile else
  84.          "e /n /q hidnstuf.xxx"
  85.          .visible = 0
  86. compile endif
  87.        else
  88.           activatefile HiddenFileID
  89.        endif
  90.        compile if EVERSION < 5
  91.           cursordata
  92.        compile endif
  93.        FirstOne = "["HIDEIT_Next_Index"]"
  94.        insertline FirstOne, HiddenFileID.last+1
  95.  
  96.        OldInsertState = insertstate()
  97.        if not InsertState() then
  98.          inserttoggle
  99.        endif
  100.  
  101.        .last; .col=length(FirstOne)+1
  102.        call pmove_mark()
  103.        unmark
  104.        --if ECol==0 then
  105.        --  /* insert that EOL that we postponed earlier */
  106.        --  insertline '', .last
  107.        --endif
  108.        xxxline = .line
  109.        -- the next few lines avoid a bug in E that deletes spaces at the
  110.        --   end of line. [editorial...This bug may have been intentional, but
  111.        --   it is nonetheless a bug!!!!] Putting a dumb character at the
  112.        --   end of the line keeps the spaces there, but now we must be
  113.        --   sure not to copy it back later.
  114.        .last; .col = ECol+1; keyin 'x'
  115.        xxxline
  116.        if BLine<ELine then
  117.          '+1'; markline;  .line=.last; markline; shiftright
  118.        endif
  119.        if InsertState()<>OldInsertState then
  120.          inserttoggle
  121.        endif
  122.  
  123.        activatefile thisfileid
  124.        --if OldCommandState<>commandstate() then
  125.        --   compile if EVERSION < 5
  126.        --      commandtoggle
  127.        --   compile endif
  128.        --endif
  129.        HIDEIT_Next_Index = HIDEIT_Next_Index+1
  130.        if  thisfileid==mkfileid then
  131.            difference = ELine - BLine
  132.            if firstmline > BLine  then
  133.              firstmline = firstmline - difference
  134.              lastmline  = lastmline - difference
  135.            elseif lastmline > BLine  then
  136.              lastmline = lastmline - difference
  137.            endif
  138.        endif
  139.        unmark;
  140.        if oldmarktype then
  141.           call pset_mark(firstmline, lastmline, firstmcol, lastmcol, oldmarktype, mkfileid)
  142.        endif
  143.        return HIDEIT_Next_Index-1
  144.      endif
  145.  
  146.  
  147.  
  148. -------------------------------------------------------------------------------
  149. defproc CrudelyExpandCharTag(TheColm, TheLine, TheFileId, TheTagNum,
  150.                              var EndOfInsertionCol,
  151.                              var EndOfInsertionLn)
  152. -- EndOfInsertion is a string with the position of the last character inserted.
  153.      compile if EVERSION < 5
  154.         cursordata
  155.      compile endif
  156.      getfileid StartingFileId
  157.      call psave_pos(old_position)
  158.      oldmarktype = marktype()
  159.      getmark firstmline, lastmline,firstmcol,lastmcol,mkfileid
  160.      if (TheFileId==mkfileid) and
  161.                  ((firstmline=TheLine) or (lastmline=TheLine)) then
  162.         /* Our region interferes with a marked region. */
  163.         call showmessage("No Action: Existing Marked region interferes with",
  164.                     "           the lexical block.                    ")
  165.         return 1
  166.      endif
  167.      unmark
  168.      /* assert: .line = oldlinenum;  .col = oldcolnum; */
  169.  
  170.      getfileid HiddenFileID, "hidnstuf.xxx"
  171.      if HiddenFileID=='' then
  172. compile if EVERSION < 5
  173.          "e /n /h /q hidnstuf.xxx"
  174. compile else
  175.          "e /n /q hidnstuf.xxx"
  176.          .visible = 0
  177. compile endif
  178.      else
  179.        activatefile HiddenFileID
  180.      endif
  181.  
  182.      TheTagString = "["TheTagNum"]"
  183.      1; .col = 1
  184.      "xcom l /"TheTagString"/"
  185.      while (.col/==1) and not RC do
  186. ;;     right
  187. ;;     "l /"TheTagString"/"
  188.         repeat_find
  189.      endwhile
  190.      if RC then
  191.        activatefile StartingFileId
  192.        call prestore_pos(old_position)
  193.        call showmessage("No Action: The tag could not be resolved.")
  194.        call pset_mark(firstmline, lastmline, firstmcol, lastmcol, oldmarktype, mkfileid)
  195.        RC = 0
  196.        return 1
  197.      endif
  198.      unmark
  199.      /* start marking replacement text */
  200.      "xcom l /]/"
  201.      right
  202.      markchar
  203.      FirstLineOfRepText = .line
  204.      sayerror 1;  -- hide error messages.
  205.      /* now find end of that text */
  206.      "xcom l /\[[0-9]+\]/g"
  207.      while (.col/==1) and not RC do
  208. ;      right
  209. ;      "l /\[[0-9]+\]/g"
  210.        repeat_find
  211.      endwhile
  212.      if RC then
  213.        .last
  214.        rc = 0
  215.      else
  216.        '-1'
  217.      endif
  218.      sayerror 0
  219.      endline; left; left; markchar
  220.      -- the second left in the above line is to skip the dumb character placed
  221.      --   and the end of the last line of each entry into the hidden text buffer
  222.      --   to prevent spaces from being lost.
  223.      NumberOfLines = .line - FirstLineOfRepText
  224.      EndOfInsertionLn = NumberOfLines+TheLine
  225.      if NumberOfLines then
  226.        EndOfInsertionCol = .col-1
  227.      else
  228.        EndOfInsertionCol = .col-length(TheTagString) + TheColm - 1
  229.      endif
  230.  
  231.      activatefile TheFileId
  232.      /* remember Insert state and set it to Insert active. */
  233.      OldInsertState = InsertState()
  234.      if not InsertState() then
  235.        inserttoggle
  236.      endif
  237.      TheLine;   .col   = TheColm
  238.      call pcopy_mark()
  239.      unmark
  240.      TheLine;   .col   = TheColm
  241.      /* Now remove the column of indent that was inserted into the ref text. */
  242.      if NumberOfLines>0 then
  243.       down; markline
  244.       TheLine+NumberOfLines
  245.       markline
  246.       shiftleft
  247.       activatefile StartingFileId; -- this was added untested by (JLC,1/28/89) while reading code.
  248.       call prestore_pos(old_position)
  249.      endif
  250.      /* restore old insert state */
  251.      if InsertState()<>OldInsertState then
  252.        inserttoggle
  253.      endif
  254.      compile if EVERSION < 5
  255.         -- let's see what happens if I don't do this...  (jlc experiment 3/6/89)
  256.         -- display 1
  257.      compile else
  258.         -- let's see what happens if I don't do anything. (jlc experiment 3/6/89)
  259.      compile endif
  260.      /* restore old mark. */
  261.      if  TheFileId==mkfileid then
  262.          difference = NumberOfLines
  263.          if firstmline > TheLine  then
  264.            firstmline = firstmline + difference
  265.            lastmline  = lastmline + difference
  266.          elseif lastmline > TheLine  then
  267.            lastmline = lastmline + difference
  268.          endif
  269.      endif
  270.      unmark
  271.      if oldmarktype then
  272.         call pset_mark(firstmline, lastmline, firstmcol, lastmcol, oldmarktype, mkfileid)
  273.      endif
  274.  
  275. -------------------------------------------------------------------------------
  276. defproc ExpandCharTag(TheOffs, TheColm, TheLine, TheFileId, TheTagNum)
  277.   universal FIND_NEXT_ATTR_SUBOP
  278.   universal FIND_PREV_ATTR_SUBOP
  279.   universal DELETE_ATTR_SUBOP
  280.   universal ANY_CLASS
  281.      getfileid StartingFileId
  282.      call psave_pos(old_position)
  283.      oldmarktype = marktype()
  284.      getmark firstmline, lastmline,firstmcol,lastmcol,mkfileid
  285.      if (TheFileId==mkfileid) and
  286.                  ((firstmline=TheLine) or (lastmline=TheLine)) then
  287.         /* Our region interferes with a marked region. */
  288.         call showmessage("No Action: Existing Marked region interferes with",
  289.                     "           the lexical block.                    ")
  290.         return 1
  291.      endif
  292.      unmark
  293.      /* assert: .line = oldlinenum;  .col = oldcolnum; */
  294.  
  295.      TheClass  = ANY_CLASS
  296.      TheColumn = TheColm
  297.      TheLn     = TheLine
  298.      if TheOffs<0 then
  299.        TheOffset = -300
  300.        attribute_action FIND_NEXT_ATTR_SUBOP, TheClass,
  301.                                      TheOffset, TheColumn, TheLn, TheFileId
  302.        --TheOffset = signit(TheOffset)
  303.        call CrudelyExpandCharTag(TheColm, TheLine, TheFileId, TheTagNum,
  304.                             EndOfInsertionCol,
  305.                             EndOfInsertionLn)
  306.        if (TheClass==0) or (TheOffs<TheOffset) or (TheColumn<>TheColm) or (TheLine<>TheLn) then
  307.          -- We will not have to split the character from some of its attributes.
  308.          -- Just do a crude insertion.
  309.          return
  310.        endif
  311.        TheSLn     = EndOfInsertionLn
  312.        TheSColumn = EndOfInsertionCol+1
  313.        TheSOffset = TheOffs
  314.        TheDLn     = TheLine
  315.        TheDColumn = TheColm
  316.        TheDOffset = -300
  317.        while TheOffset<=TheOffs do
  318.          -- TheSLn     = EndOfInsertionLn
  319.          -- TheSColumn = EndOfInsertionCol+1
  320.          -- TheSOffset = TheOffs
  321.          -- TheDLn     = TheLine
  322.          -- TheDColumn = TheColm
  323.          -- TheDOffset = -300
  324.          query_attribute  TheClass, TheValue, IsPush, TheSOffset, TheSColumn, TheSLn
  325.          insert_attribute  TheClass, TheValue, IsPush, TheDOffset, TheDColumn, TheDLn
  326.          attribute_action DELETE_ATTR_SUBOP, TheClass,
  327.                                        TheSOffset, TheSColumn, TheSLn
  328.          TheOffset = TheOffset+1
  329.        endwhile
  330.      else
  331.        TheOffset = 300
  332.        attribute_action FIND_PREV_ATTR_SUBOP, TheClass,
  333.                                      TheOffset, TheColumn, TheLn, TheFileId
  334.        --TheOffset = signit(TheOffset)
  335.        call CrudelyExpandCharTag(TheColm+1, TheLine, TheFileId, TheTagNum,
  336.                             EndOfInsertionCol,
  337.                             EndOfInsertionLn)
  338.        if (TheClass==0) or (TheOffs>TheOffset)  or (TheColumn<>TheColm) or (TheLine<>TheLn) then
  339.          -- We will not have to split the character from some of its attributes.
  340.          -- Just do a crude insertion.
  341.          return
  342.        endif
  343.        TheDLn     = EndOfInsertionLn
  344.        TheDColumn = EndOfInsertionCol
  345.        TheDOffset = 300
  346.        TheSLn     = TheLine
  347.        TheSColumn = TheColm
  348.        TheSOffset = TheOffs
  349.        while TheOffset>=TheOffs do
  350.          -- TheDLn     = EndOfInsertionLn
  351.          -- TheDColumn = EndOfInsertionCol
  352.          -- TheDOffset = 300
  353.          -- TheSLn     = TheLine
  354.          -- TheSColumn = TheColm
  355.          -- TheSOffset = TheOffs
  356.          query_attribute  TheClass, TheValue, IsPush, TheSOffset, TheSColumn, TheSLn
  357.          insert_attribute  TheClass, TheValue, IsPush, TheDOffset, TheDColumn, TheDLn
  358.          attribute_action DELETE_ATTR_SUBOP, TheClass,
  359.                                        TheSOffset, TheSColumn, TheSLn
  360.          TheOffset = TheOffset-1
  361.        endwhile
  362.      endif
  363.  
  364.  
  365.  
  366.  
  367.  
  368. -------------------------------------------------------------------------------
  369. defproc GetPhraseTagged(TheTagNum, var ThePhrase)
  370.      getfileid StartingFileId
  371.      call psave_pos(old_position)
  372.  
  373.      /* assert: .line = oldlinenum;  .col = oldcolnum; */
  374.      oldRC = RC; RC= 0
  375.      display -2
  376.      do_array 6, ArrayID, "associated_strings"
  377.      display 2
  378.      if RC then
  379.        RC = OldRC
  380.        do_array 1, ArrayID, "associated_strings"
  381.        ThePhrase = ''
  382.        return 1
  383.      else
  384.        RC = OldRC
  385.        --activatefile HiddenFileID
  386.      endif
  387.  
  388.      compile if 0
  389.         TheTag = "["TheTagNum"]"
  390.         1; .col = 1
  391.         "xcom l /"TheTag"/"
  392.         while (.col/==1) and not RC do
  393.            repeat_find
  394.         endwhile
  395.         if RC then
  396.           activatefile StartingFileId
  397.           call prestore_pos(old_position)
  398.           ThePhrase = ''
  399.           return 1
  400.         endif
  401.         unmark
  402.         /* start marking replacement text */
  403.         "l /]/"
  404.         getline TempLine, .line, HiddenFileID
  405.         ThePhrase = substr(TempLine, .col+1)
  406.      compile else
  407.         do_array 3, ArrayID, TheTagNum, ThePhrase
  408.      compile endif
  409.      activatefile StartingFileId
  410.      call prestore_pos(old_position)
  411.      return 0
  412.  
  413.  
  414.  
  415.  
  416. definit
  417.   universal HIDEIT_initialized
  418.   universal HIDEIT_Next_Index
  419.   universal ATTR_initialized
  420.   if ""==HIDEIT_initialized then
  421.      OldRC = rc; rc = 0
  422.      getfileid oldfileid
  423.      compile if EVERSION < 5
  424.         "xcom e /n /h /q hidnstuf.xxx"
  425.      compile else
  426.         "xcom e /n /q hidnstuf.xxx"
  427.         .visible = 0
  428.      compile endif
  429.      if (rc==-282 /* New File */) or not rc then
  430.         RC = OldRc
  431.      endif
  432.      activatefile oldfileid
  433.      HIDEIT_initialized = 1
  434.      HIDEIT_Next_Index  = 1
  435.   endif
  436.   if ""==ATTR_initialized then
  437.     "link ATTR"
  438.     sayerror 0
  439.   endif
  440.