Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program new;
- function String.StartsWith(Prefix:String): Boolean;
- var
- i: Int32;
- begin
- if Length(Prefix) > Length(Self) then
- Exit(False);
- Result := True;
- for i:=1 to Length(Prefix) do
- if (Prefix[i] <> Self[i]) then
- Exit(False);
- end;
- var
- EndTokens:TStringArray = ['OVERLOAD','OVERRIDE','EXTERNAL','CDECL','STDCALL','SAFECALL','INLINE']; //ADD WHAT EVER
- function ParseFunctionHeads(Data:String): TStringArray;
- //Skip newlines, space, and other junk chars..
- procedure SkipJunk(Data:String; var p:Int32);
- begin
- while (Data[p] in [#0,#9,#10,#11,#13,#32]) and (p <= length(Data)) do Inc(p);
- end;
- //Increse position until we reach "C"
- function SkipTo(Data:String; var p:Int32; C:Char): Boolean;
- begin
- Result := True;
- while (Data[p] <> C) and (p <= length(Data)) do Inc(p);
- if (p > length(Data)) then Exit(False);
- end;
- //Parse from pos till the end of the method, returns false if it's not a method.
- function ParseMathod(Data:String; var pos:Int32; var funcDef:String; Decl:String): Boolean;
- var i,j:Int32; inString:Boolean=False; pcount:Int32;
- begin
- i := 1+Length(Decl);
- SkipJunk(Data,i);
- //methods should alsawys start with given chars:
- if not(Data[i] in ['a'..'z','A'..'Z', '_']) then begin Inc(pos, i); Exit(False); end;
- Inc(i);
- //Now they can be numeric as well, and have dots
- while (Data[i] in ['a'..'z','A'..'Z', '_', '.', '0'..'9']) and (i < length(Data)) do Inc(i);
- SkipJunk(Data,i);
- //Does it have parameters?
- if Data[i] = '(' then begin Inc(pcount); Inc(i); end;
- //While inside param-expressions do:
- while (pcount > 0) do begin
- if Data[i] = #39 then InString := Not(InString)
- else if (Data[i] = '(') and Not(InString) then inc(pcount)
- else if (Data[i] = ')') and Not(InString) then dec(pcount);
- inc(i);
- if i > length(Data) then begin Inc(pos, i); Exit(False); end;
- end;
- if not(SkipTo(Data, i, ';')) then begin Inc(pos, i); Exit(False); end;
- Inc(i);
- //Check for all possible endtokens:
- j := 0;
- while j < Length(EndTokens) do begin
- SkipJunk(data,i);
- //if (UpperCase(Data[i]) = EndTokens[j][1]) then //uncomment for speedup.. lape fails.
- if UpperCase(Copy(Data,i,Length(EndTokens[j]))) = EndTokens[j] then begin
- Inc(i,length(EndTokens[j]));
- if not(SkipTo(Data, i, ';')) then Break;
- Inc(i);
- j := 0;
- continue;
- end;
- Inc(j);
- end;
- funcDef := Copy(Data,0,i-1);
- Inc(pos, i-1);
- Exit(True);
- end;
- var
- i,j,tm:Int32;
- tmp,funcDef:String;
- DTypes:TStringArray = ['FUNCTION', 'PROCEDURE'];
- begin
- i := 1;
- while i < Length(Data) do
- begin
- tmp := Copy(Data,i,255);
- for j:=0 to High(DTypes) do
- //is procedure?
- if uppercase(tmp).startswith(DTypes[0]) then begin
- if ParseMathod(tmp, i, funcDef, DTypes[0]) then begin
- j := Length(Result);
- SetLength(Result, j+1);
- Result[j] := FuncDef;
- end else Inc(i);
- end else
- //is function?
- if uppercase(tmp).startswith(DTypes[1]) then begin
- if ParseMathod(tmp, i, funcDef,DTypes[1]) then begin
- j := Length(Result);
- SetLength(Result, j+1);
- Result[j] := FuncDef;
- end else Inc(i);
- //junk...
- end else begin
- Inc(i);
- Continue;
- end;
- end;
- end;
- var
- heads:TStringArray;
- s:String;
- i:Int32;
- begin
- s := getPage('http://paste.villavu.com/raw/6115/');
- heads := ParseFunctionHeads(s);
- for i:=0 to High(heads) do
- WriteLn(heads[i] +#13#10);
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement