home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
EPMATR.ZIP
/
HIDEIT.E
< prev
next >
Wrap
Text File
|
1989-07-06
|
15KB
|
440 lines
/*
This file contains code that implements the hiding and restoring of
hidden text. It works in conjuction with the attribute routines provided in
attr.e. Support for loading and saving files with hidden text can be found
in AttrLod.e.
*/
-------------------------------------------------------------------------------
defproc StashPhrase(ThePhrase)
universal HIDEIT_Next_Index
compile if 0
getfileid thisfileid
getfileid HiddenFileID, "hidnstuf.xxx"
if HiddenFileID=='' then
compile if EVERSION < 5
"e /n /h /q hidnstuf.xxx"
compile else
"e /n /q hidnstuf.xxx"
.visible = 0
compile endif
else
activatefile HiddenFileID
endif
FirstOne = "["HIDEIT_Next_Index"]"ThePhrase
insertline FirstOne, HiddenFileID.last+1
activatefile thisfileid
compile else
OldRc = RC; RC = 0
display -2
do_array 6, ArrayID, "associated_strings"
display 2
if RC then
RC = OldRC
do_array 1, ArrayID, "associated_strings"
else
RC = OldRC
endif
do_array 2, ArrayID, HIDEIT_Next_Index, ThePhrase
compile endif
HIDEIT_Next_Index = HIDEIT_Next_Index+1
return HIDEIT_Next_Index - 1
-------------------------------------------------------------------------------
defproc HideCharRegion(BLine, ELine, BCol, ECol)
universal HIDEIT_Next_Index
oldmarktype = marktype()
getmark firstmline, lastmline,firstmcol,lastmcol,mkfileid
getfileid thisfileid
if (thisfileid==mkfileid) and
(((firstmline<=ELine) and (firstmline>=BLine)) or
((lastmline<=ELine) and (lastmline>=BLine))) then
/* Our region interferes with a marked region. */
/*call prestore_pos(old_position);*/
call showmessage("No Action: Existing Marked region interferes with ",
" region to be hidden. ")
return 0
else
unmark
--OldCommandState = commandstate()
if BCol then
BLine; .col=BCol; markchar
else
BLine-1; endline; markchar
endif
if ECol then
ELine; .col=ECol; markchar
else
-- this is how one marks column 0...
ELine-1; endline; markchar
endif
-- deal with hidden buffer
getfileid HiddenFileID, "hidnstuf.xxx"
if HiddenFileID=='' then
compile if EVERSION < 5
"e /n /h /q hidnstuf.xxx"
compile else
"e /n /q hidnstuf.xxx"
.visible = 0
compile endif
else
activatefile HiddenFileID
endif
compile if EVERSION < 5
cursordata
compile endif
FirstOne = "["HIDEIT_Next_Index"]"
insertline FirstOne, HiddenFileID.last+1
OldInsertState = insertstate()
if not InsertState() then
inserttoggle
endif
.last; .col=length(FirstOne)+1
call pmove_mark()
unmark
--if ECol==0 then
-- /* insert that EOL that we postponed earlier */
-- insertline '', .last
--endif
xxxline = .line
-- the next few lines avoid a bug in E that deletes spaces at the
-- end of line. [editorial...This bug may have been intentional, but
-- it is nonetheless a bug!!!!] Putting a dumb character at the
-- end of the line keeps the spaces there, but now we must be
-- sure not to copy it back later.
.last; .col = ECol+1; keyin 'x'
xxxline
if BLine<ELine then
'+1'; markline; .line=.last; markline; shiftright
endif
if InsertState()<>OldInsertState then
inserttoggle
endif
activatefile thisfileid
--if OldCommandState<>commandstate() then
-- compile if EVERSION < 5
-- commandtoggle
-- compile endif
--endif
HIDEIT_Next_Index = HIDEIT_Next_Index+1
if thisfileid==mkfileid then
difference = ELine - BLine
if firstmline > BLine then
firstmline = firstmline - difference
lastmline = lastmline - difference
elseif lastmline > BLine then
lastmline = lastmline - difference
endif
endif
unmark;
if oldmarktype then
call pset_mark(firstmline, lastmline, firstmcol, lastmcol, oldmarktype, mkfileid)
endif
return HIDEIT_Next_Index-1
endif
-------------------------------------------------------------------------------
defproc CrudelyExpandCharTag(TheColm, TheLine, TheFileId, TheTagNum,
var EndOfInsertionCol,
var EndOfInsertionLn)
-- EndOfInsertion is a string with the position of the last character inserted.
compile if EVERSION < 5
cursordata
compile endif
getfileid StartingFileId
call psave_pos(old_position)
oldmarktype = marktype()
getmark firstmline, lastmline,firstmcol,lastmcol,mkfileid
if (TheFileId==mkfileid) and
((firstmline=TheLine) or (lastmline=TheLine)) then
/* Our region interferes with a marked region. */
call showmessage("No Action: Existing Marked region interferes with",
" the lexical block. ")
return 1
endif
unmark
/* assert: .line = oldlinenum; .col = oldcolnum; */
getfileid HiddenFileID, "hidnstuf.xxx"
if HiddenFileID=='' then
compile if EVERSION < 5
"e /n /h /q hidnstuf.xxx"
compile else
"e /n /q hidnstuf.xxx"
.visible = 0
compile endif
else
activatefile HiddenFileID
endif
TheTagString = "["TheTagNum"]"
1; .col = 1
"xcom l /"TheTagString"/"
while (.col/==1) and not RC do
;; right
;; "l /"TheTagString"/"
repeat_find
endwhile
if RC then
activatefile StartingFileId
call prestore_pos(old_position)
call showmessage("No Action: The tag could not be resolved.")
call pset_mark(firstmline, lastmline, firstmcol, lastmcol, oldmarktype, mkfileid)
RC = 0
return 1
endif
unmark
/* start marking replacement text */
"xcom l /]/"
right
markchar
FirstLineOfRepText = .line
sayerror 1; -- hide error messages.
/* now find end of that text */
"xcom l /\[[0-9]+\]/g"
while (.col/==1) and not RC do
; right
; "l /\[[0-9]+\]/g"
repeat_find
endwhile
if RC then
.last
rc = 0
else
'-1'
endif
sayerror 0
endline; left; left; markchar
-- the second left in the above line is to skip the dumb character placed
-- and the end of the last line of each entry into the hidden text buffer
-- to prevent spaces from being lost.
NumberOfLines = .line - FirstLineOfRepText
EndOfInsertionLn = NumberOfLines+TheLine
if NumberOfLines then
EndOfInsertionCol = .col-1
else
EndOfInsertionCol = .col-length(TheTagString) + TheColm - 1
endif
activatefile TheFileId
/* remember Insert state and set it to Insert active. */
OldInsertState = InsertState()
if not InsertState() then
inserttoggle
endif
TheLine; .col = TheColm
call pcopy_mark()
unmark
TheLine; .col = TheColm
/* Now remove the column of indent that was inserted into the ref text. */
if NumberOfLines>0 then
down; markline
TheLine+NumberOfLines
markline
shiftleft
activatefile StartingFileId; -- this was added untested by (JLC,1/28/89) while reading code.
call prestore_pos(old_position)
endif
/* restore old insert state */
if InsertState()<>OldInsertState then
inserttoggle
endif
compile if EVERSION < 5
-- let's see what happens if I don't do this... (jlc experiment 3/6/89)
-- display 1
compile else
-- let's see what happens if I don't do anything. (jlc experiment 3/6/89)
compile endif
/* restore old mark. */
if TheFileId==mkfileid then
difference = NumberOfLines
if firstmline > TheLine then
firstmline = firstmline + difference
lastmline = lastmline + difference
elseif lastmline > TheLine then
lastmline = lastmline + difference
endif
endif
unmark
if oldmarktype then
call pset_mark(firstmline, lastmline, firstmcol, lastmcol, oldmarktype, mkfileid)
endif
-------------------------------------------------------------------------------
defproc ExpandCharTag(TheOffs, TheColm, TheLine, TheFileId, TheTagNum)
universal FIND_NEXT_ATTR_SUBOP
universal FIND_PREV_ATTR_SUBOP
universal DELETE_ATTR_SUBOP
universal ANY_CLASS
getfileid StartingFileId
call psave_pos(old_position)
oldmarktype = marktype()
getmark firstmline, lastmline,firstmcol,lastmcol,mkfileid
if (TheFileId==mkfileid) and
((firstmline=TheLine) or (lastmline=TheLine)) then
/* Our region interferes with a marked region. */
call showmessage("No Action: Existing Marked region interferes with",
" the lexical block. ")
return 1
endif
unmark
/* assert: .line = oldlinenum; .col = oldcolnum; */
TheClass = ANY_CLASS
TheColumn = TheColm
TheLn = TheLine
if TheOffs<0 then
TheOffset = -300
attribute_action FIND_NEXT_ATTR_SUBOP, TheClass,
TheOffset, TheColumn, TheLn, TheFileId
--TheOffset = signit(TheOffset)
call CrudelyExpandCharTag(TheColm, TheLine, TheFileId, TheTagNum,
EndOfInsertionCol,
EndOfInsertionLn)
if (TheClass==0) or (TheOffs<TheOffset) or (TheColumn<>TheColm) or (TheLine<>TheLn) then
-- We will not have to split the character from some of its attributes.
-- Just do a crude insertion.
return
endif
TheSLn = EndOfInsertionLn
TheSColumn = EndOfInsertionCol+1
TheSOffset = TheOffs
TheDLn = TheLine
TheDColumn = TheColm
TheDOffset = -300
while TheOffset<=TheOffs do
-- TheSLn = EndOfInsertionLn
-- TheSColumn = EndOfInsertionCol+1
-- TheSOffset = TheOffs
-- TheDLn = TheLine
-- TheDColumn = TheColm
-- TheDOffset = -300
query_attribute TheClass, TheValue, IsPush, TheSOffset, TheSColumn, TheSLn
insert_attribute TheClass, TheValue, IsPush, TheDOffset, TheDColumn, TheDLn
attribute_action DELETE_ATTR_SUBOP, TheClass,
TheSOffset, TheSColumn, TheSLn
TheOffset = TheOffset+1
endwhile
else
TheOffset = 300
attribute_action FIND_PREV_ATTR_SUBOP, TheClass,
TheOffset, TheColumn, TheLn, TheFileId
--TheOffset = signit(TheOffset)
call CrudelyExpandCharTag(TheColm+1, TheLine, TheFileId, TheTagNum,
EndOfInsertionCol,
EndOfInsertionLn)
if (TheClass==0) or (TheOffs>TheOffset) or (TheColumn<>TheColm) or (TheLine<>TheLn) then
-- We will not have to split the character from some of its attributes.
-- Just do a crude insertion.
return
endif
TheDLn = EndOfInsertionLn
TheDColumn = EndOfInsertionCol
TheDOffset = 300
TheSLn = TheLine
TheSColumn = TheColm
TheSOffset = TheOffs
while TheOffset>=TheOffs do
-- TheDLn = EndOfInsertionLn
-- TheDColumn = EndOfInsertionCol
-- TheDOffset = 300
-- TheSLn = TheLine
-- TheSColumn = TheColm
-- TheSOffset = TheOffs
query_attribute TheClass, TheValue, IsPush, TheSOffset, TheSColumn, TheSLn
insert_attribute TheClass, TheValue, IsPush, TheDOffset, TheDColumn, TheDLn
attribute_action DELETE_ATTR_SUBOP, TheClass,
TheSOffset, TheSColumn, TheSLn
TheOffset = TheOffset-1
endwhile
endif
-------------------------------------------------------------------------------
defproc GetPhraseTagged(TheTagNum, var ThePhrase)
getfileid StartingFileId
call psave_pos(old_position)
/* assert: .line = oldlinenum; .col = oldcolnum; */
oldRC = RC; RC= 0
display -2
do_array 6, ArrayID, "associated_strings"
display 2
if RC then
RC = OldRC
do_array 1, ArrayID, "associated_strings"
ThePhrase = ''
return 1
else
RC = OldRC
--activatefile HiddenFileID
endif
compile if 0
TheTag = "["TheTagNum"]"
1; .col = 1
"xcom l /"TheTag"/"
while (.col/==1) and not RC do
repeat_find
endwhile
if RC then
activatefile StartingFileId
call prestore_pos(old_position)
ThePhrase = ''
return 1
endif
unmark
/* start marking replacement text */
"l /]/"
getline TempLine, .line, HiddenFileID
ThePhrase = substr(TempLine, .col+1)
compile else
do_array 3, ArrayID, TheTagNum, ThePhrase
compile endif
activatefile StartingFileId
call prestore_pos(old_position)
return 0
definit
universal HIDEIT_initialized
universal HIDEIT_Next_Index
universal ATTR_initialized
if ""==HIDEIT_initialized then
OldRC = rc; rc = 0
getfileid oldfileid
compile if EVERSION < 5
"xcom e /n /h /q hidnstuf.xxx"
compile else
"xcom e /n /q hidnstuf.xxx"
.visible = 0
compile endif
if (rc==-282 /* New File */) or not rc then
RC = OldRc
endif
activatefile oldfileid
HIDEIT_initialized = 1
HIDEIT_Next_Index = 1
endif
if ""==ATTR_initialized then
"link ATTR"
sayerror 0
endif