home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
epm603b.zip
/
EPMATR.ZIP
/
CBLOCK.E
< prev
next >
Wrap
Text File
|
1989-07-06
|
10KB
|
312 lines
defproc FindEndOfCBlock(var EndOfBlockLine, var EndOfBlockCol)
/* This procedure begins looking for the '}' character after the present
cursor position. It will skip it if it finds it within comments or
quotation marks.
Assert: The cursor is presently on the { character.
*/
StartLine = .line; StartCol = .col+1;
BestSoFar = "none";
loop
.line = StartLine; .col = StartCol;
"l /}/+f"
if RC then
call showmessage(" No Action: This block is not terminated!!!");
return 1; /* zero indicates success */
else
FirstTerminatorLine = .line;
FirstTerminatorCol = .col;
endif
.line = StartLine; .col = StartCol;
"l %/*%+f"
if RC then
FirstCommentLine = .last+1;
else
FirstCommentLine = .line;
FirstCommentCol = .col;
endif
.line = StartLine; .col = StartCol;
"l %'%+f"
if RC then
FirstCharLine = .last+1;
else
FirstCharLine = .line;
FirstCharCol = .col;
endif
.line = StartLine; .col = StartCol;
'l %"%+f'
if RC then
FirstStringLine = .last+1;
else
FirstStringLine = .line;
FirstStringCol = .col;
endif
.line = StartLine; .col = StartCol;
'l %{%+f'
if RC then
FirstDeeperLine = .last+1;
else
FirstDeeperLine = .line;
FirstDeeperCol = .col;
endif
if (((FirstTerminatorLine<FirstCommentLine)) or
((FirstTerminatorLine=FirstCommentLine)and
(FirstTerminatorCol<=FirstCommentCol))) then
if (((FirstTerminatorLine<FirstCharLine)) or
((FirstTerminatorLine=FirstCharLine)and
(FirstTerminatorCol<=FirstCharCol))) then
if (((FirstTerminatorLine<FirstStringLine)) or
((FirstTerminatorLine=FirstStringLine)and
(FirstTerminatorCol<=FirstStringCol))) then
if (((FirstTerminatorLine<FirstDeeperLine)) or
((FirstTerminatorLine=FirstDeeperLine)and
(FirstTerminatorCol<=FirstDeeperCol))) then
BestSoFar = "TheTerminator";
else
BestSoFar = "TheDeeper";
endif
else
BestSoFar = "TheString";
endif
else
BestSoFar = "TheChar";
endif
else
if (((FirstCommentLine<FirstCharLine)) or
((FirstCommentLine=FirstCharLine)and
(FirstCommentCol<=FirstCharCol))) then
if (((FirstCommentLine<FirstStringLine)) or
((FirstCommentLine=FirstStringLine)and
(FirstCommentCol<=FirstStringCol))) then
if (((FirstCommentLine<FirstDeeperLine)) or
((FirstCommentLine=FirstDeeperLine)and
(FirstCommentCol<=FirstDeeperCol))) then
BestSoFar = "TheComment";
else
BestSoFar = "TheDeeper";
endif
else
BestSoFar = "TheString";
endif
else
BestSoFar = "TheChar";
endif
endif
if BestSoFar=="TheChar" then
if (((FirstCharLine<FirstStringLine)) or
((FirstCharLine=FirstStringLine)and
(FirstCharCol<=FirstStringCol))) then
if (((FirstCharLine<FirstDeeperLine)) or
((FirstCharLine=FirstDeeperLine)and
(FirstCharCol<=FirstDeeperCol))) then
BestSoFar = "TheChar";
else
BestSoFar = "TheDeeper";
endif
else
BestSoFar = "TheString";
endif
endif
if BestSoFar=="TheString" then
if (((FirstStringLine<FirstDeeperLine)) or
((FirstStringLine=FirstDeeperLine)and
(FirstStringCol<=FirstDeeperCol))) then
BestSoFar = "TheString";
else
BestSoFar = "TheDeeper";
endif
endif
if BestSoFar=="TheTerminator" then
/* Mission accomplished. */
EndOfBlockLine = FirstTerminatorLine;
EndOfBlockCol = FirstTerminatorCol;
return;
else
if BestSoFar=="TheComment" then
.line = FirstCommentLine;
.col = FirstCommentCol;
result = FindEndOfCComment(StartLine, StartCol);
if result then
return 1;
endif
StartCol = StartCol+2; /* jump the comment terminator */
else
if BestSoFar=="TheDeeper" then
.line = FirstDeeperLine;
.col = FirstDeeperCol;
result = FindEndOfCBlock(StartLine, StartCol);
if result then
return 1;
endif
StartCol = StartCol+1; /* jump the } character */
else
if BestSoFar=="TheString" then
.line = FirstStringLine;
.col = FirstStringCol;
result = FindEndOfCString(StartLine, StartCol);
if result then
return 1;
endif
StartCol = StartCol+1; /* jump the " character */
else
.line = FirstCharLine;
.col = FirstCharCol;
result = FindEndOfCChar(StartLine, StartCol);
if result then
return 1;
endif
StartCol = StartCol+1; /* jump the ' character */
endif
endif
endif
endif
endloop
defproc FindEndOfCComment(var EndOfCommentLine, var EndOfCommentCol)
/* This procedure begins looking for a * followed by a / character after the
present cursor position.
*/
right; right;
"l %*/%+f"
if RC then
call showmessage(" No Action: Unterminated Comment at line" .line);
return 1;
else
EndOfCommentLine = .line;
EndOfCommentCol = .col;
endif
defproc FindEndOfCString(var EndOfStringLine, var EndOfStringCol)
/* This procedure begins looking for the final " in a C string that begins at
the present cursor position.
*/
StartLine = .line; StartCol = .col;
Done = "false";
while Done=="false" do
right;
'l /"/+f'
if RC then
call showmessage(" No Action: String Unterminated at line" StartLine);
return 1;
else
EndOfStringLine = .line;
EndOfStringCol = .col;
endif
getline ALine;
Done = "true";
while (.col>1) and (substr(ALine,.col-1,1)=='\\') do
left;
if Done=="false" then
Done="true"
else
Done="false"
endif
endwhile
.col = EndOfStringCol;
endwhile
defproc FindEndOfCChar(var EndOfCharLine, var EndOfCharCol)
/* This procedure begins looking for the end of a C character literal. The
search begins at the present cursor position which is assumed to be on the
first ' of the character literal.
*/
getline ALine;
if substr(ALine, .col+1, 1)== '\\' then
EndOfCharCol = .col+3;
else
EndOfCharCol = .col+2;
endif
if substr(ALine, EndOfCharCol, 1)/=="'" then
call showmessage("No Action: Unterminated character literal @ line" .line);
return 1;
endif
EndOfCharLine = .line;
-------------------------------------------------------------------------------
defc blkexpansion_Compress_Blk
universal COLORCLASS;
universal HIDNCLASS;
/*
The following procedure returns an error message if the cursor is not on
a { character. If it is on a { character, it stores the content of that
block in a seperate file in a manner in which it can be restored. A
flashing asterix appears on the screen where the block previously was.
*/
"MH_gotoposition"
oldlinenum = .line;
oldcolnum = .col;
psave_pos(old_position);
getline topline, .line;
if substr(topline, .col, 1) == '{' then
result = FindEndOfCBlock(EndOfBlockLine, EndOfBlockCol);
if result then
/* There was an error. I assume the user was already informed. */
prestore_pos(old_position);
return;
endif
TheTag = HideCharRegion(oldlinenum, EndOfBlockLine, oldcolnum+1, EndOfBlockCol-1)
OldInsertState = InsertState();
if insertstate()=='0' then
inserttoggle;
endif
/* should delete unneeded tag here, but will do it after demo. */
keyin '*'
.col = .col-1;
insert_attribute COLORCLASS, 165, 1, -1, .col, .line;
insert_attribute COLORCLASS, 165, 0, 1, .col, .line;
insert_attribute HIDNCLASS, TheTag, 2, -1, .col, .line;
else
call showmessage("No Action: Cursor was not on a block initiator '{'");
endif
prestore_pos(old_position);
sayerror 0;
------------------------------------------------------------------------------
defc blkexpansion_Expand_Blk;
/*
The following procedure returns an error message if the cursor is not on
a { character. If it is on a { character, but it is not expandable, it also
returns an error message. If the block is expandable, the expansion text will
be found in a separate file and replace the tagged block that the cursor was
on when this function was called.
*/
"MH_gotoposition"
oldlinenum = .line;
oldcolnum = .col;
call psave_pos(old_position);
.col = .col-1;
"l /{*}/"
if (.line==oldlinenum) and (.col==oldcolnum-1) and (RC==0) then
/* assert: There is a tag here, but we are not
certain that we can resolve it. */
query_attribute TheClass, TheValue, IsPush, -1, oldcolnum, .line;
.col = oldcolnum; deletechar;
/* some stuff */
/**************/
getfileid TheFile;
call ExpandCharTag(-300, .col, .line, TheFile, TheValue);
else
call showmessage("No Action: Cursor was not on a tagged block initiator.");
endif
sayerror 0;
definit
"link HIDEIT" ;
sayerror 0; -- refresh the screen to hide any messages.
"enable_attr_keys"