1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
|
unit PasPrep;
interface
uses
Comments;
const
PasNesting:longbool=true;
procedure do_pascal(__buf:pointer;size:longint;proc:pointer);
implementation
type
at=array[1..1]of char;
pat=^at;
str255=string[255];
procedure do_pascal(__buf:pointer;size:longint;proc:pointer);
var
old,i:longint;
buf:pat absolute __buf;
const
GetWord_Pos:longint=0;
LastWord:str255='';
StringBody:longbool=false;
procedure GetWord;
begin
LastWord:='';
if GetWord_Pos>size then
exit;
while buf^[GetWord_Pos]<=#32 do
begin
if GetWord_Pos>size then
exit;
inc(GetWord_Pos);
end;
repeat
if buf^[GetWord_Pos]=''''then
StringBody:=not StringBody;
LastWord:=LastWord+upcase(buf^[GetWord_Pos]);
inc(GetWord_Pos);
if GetWord_Pos>size then
break;
if(buf^[GetWord_Pos]in[#0..#32,';'])and not StringBody then
break;
until false;
while(length(LastWord)>1)and(lastWord[1]=';')do
begin
inc(GetWord_Pos);
delete(LastWord,1,1);
end;
end;
function IsTypeDef(pos:longint):longbool;
var
i:longint;
begin
IsTypeDef:=false;
for i:=pos downto 1 do
if buf^[i]>=#32 then
begin
IsTypeDef:=buf^[i]in['=',':'];
exit;
end;
end;
procedure JumpToNext;
var iLastword: Longint;
begin
repeat
iLastword:=GetWord_Pos;
if GetWord_Pos>size then
exit;
GetWord;
i:=GetWord_Pos;
if(LastWord='EXTERNAL')or(LastWord='FORWARD')or(LastWord='INLINE')then
break
else if (LastWord='CONST')then begin
GetWord_Pos:=iLastword;
break;
end;
until false;
end;
procedure JumpToEnd;
var
mainBegin:str255;
procedure do_body;
var
level:longint;
begin
level:=1;
while level>0 do
begin
if GetWord_Pos>size then
exit;
GetWord;
if (LastWord='BEGIN')or(LastWord='ASM')or(LastWord='CASE')then
inc(level)
else if (LastWord='END')then
dec(level);
end;
end;
begin
mainBegin:='BEGIN';
repeat
if GetWord_Pos>size then
exit;
GetWord;
i:=GetWord_Pos;
if((LastWord='PROCEDURE')or(lastword='FUNCTION')or(lastword='OPERATOR'))and not isTypedef(old)then
JumpToEnd
else if(LastWord='EXTERNAL')or(LastWord='FORWARD')or(LastWord='INLINE')then
exit
else if (LastWord='ASSEMBLER')then
mainBegin:='ASM';
until LastWord=mainBegin;
do_body;
end;
procedure do_consts(savefunc:pointer);
type
Tpushfunc=procedure(const key,value:str255;CaseSent:longbool);
var
old,k,kk:longint;
s:str255;
ss:array[1..2]of str255;
pushfunc:Tpushfunc absolute SaveFunc;
begin
repeat
if GetWord_Pos>size then
exit;
old:=GetWord_Pos;
GetWord;
if(((LastWord='PROCEDURE')or(lastword='FUNCTION')or(lastword='OPERATOR'))and not isTypedef(old))
or(lastword='TYPE')
or(lastword='CONST')
or(lastword='VAR')then
begin
GetWord_Pos:=old;
exit;
end
else
begin
s:=LastWord;
while LastWord<>';'do
begin
GetWord;
if GetWord_Pos>size then
exit;
s:=s+LastWord;
end;
if s[length(s)]=';'then
dec(s[0]);
if s<>''then
if pos(':',s)=0 then
if pos('=',s)>0 then
begin
ss[1]:='';
ss[2]:='';
kk:=1;
for k:=1 to length(s)do
begin
if s[k]>#32 then
begin
if(s[k]='=')and(kk=1)then
inc(kk)
else
ss[kk]:=ss[kk]+s[k];
end;
end;
TpushFunc(PushFunc)(ss[1],ss[2],false);
end;
end;
until false;
end;
begin
ClearComments(PasNesting,buf,size);
i:=1;
GetWord_Pos:=0;
while i<=size do
begin
old:=GetWord_Pos;
GetWord;
i:=GetWord_Pos;
if (lastword='OPERATOR')and not isTypedef(old)then
JumpToEnd
else if ((LastWord='PROCEDURE')or(lastword='FUNCTION')) and not isTypedef(old) then
JumpToNext
else if LastWord='CONST'then
Do_Consts(proc)
else if LastWord='IMPLEMENTATION'then
exit;
end;
end;
end.
|