Category : Pascal Source Code
Archive   : LEX_YACC.ZIP
Filename : FINDPROC.L

 
Output of file : FINDPROC.L contained in archive : LEX_YACC.ZIP

%{
(* Sample Lex program to search for function and procedure headers in
Pascal source files. *)

(* Name: findproc - search procedures and functions in Pascal source files
Synopsis: findproc [>]
Description: looks for lines starting with a procedure or function header
in the specified files (wildcards allowed; extension .pas must be given
explicitly); prints numbers and contents of the lines found; output may
also be redirected to
Bugs: "function" and "procedure" keywords must either be in lower- or
uppercase (no mixed upper/lowercase); cannot handle nested comments
in Turbo Pascal style
*)

(* to compile this Lex program, issue the command `lex findproc' and then
`tpc findproc' *)

uses LexLib, DOS;
function yywrap : boolean; forward;
(* redefined for wrap around at endoffile *)
procedure scan_comment; forward;
(* skips a comment *)
%}

function function|FUNCTION
procedure procedure|PROCEDURE

%%

^[ \t]*({function}|{procedure})[ \t].*$
begin
writeln(yylineno:4, ': ', yytext);
reject
{ reject is needed to reprocess
any comments on the line }
end;

"(*" |
"{" scan_comment;
. |
\n ;

%%

var
search_rec : SearchRec; (* used to process wildcards *)

function path(filename : string) : string;
(* returns path contained in filename *)
var
i : integer;
begin
for i := length(filename) downto 1 do
if (filename[i]=':') or (filename[i]='\') then
begin
path := copy(filename, 1, i);
exit
end;
path := ''
end(*path*);
procedure openfile(name : string);
begin
writeln(name, ':');
assign(yyin, name);
reset(yyin);
yylineno := 1;
end(*openfile*);
function yywrap;
begin
close(yyin);
findNext(search_rec);
if DosError=0 then openfile(path(paramStr(1))+search_rec.name);
yywrap := DosError<>0
end(*yywrap*);
procedure scan_comment;
var c : char;
begin
repeat
case input of
'*': begin
c := input;
if c=')' then
exit
else
unput(c)
end;
'}': exit;
end
until false
end(*scan_comment*);

begin
findFirst(paramStr(1), 0, search_rec);
if DosError=0 then
begin
openfile(path(paramStr(1))+search_rec.name);
if yylex=0 then (* done *)
end
else
writeln('no files found')
end(*findproc*).


  3 Responses to “Category : Pascal Source Code
Archive   : LEX_YACC.ZIP
Filename : FINDPROC.L

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/