Bugfix -> un chomp de merde et 1 heure de perdue :( Le fichier de conf
[old-projects.git] / deptrack / deptrack.pl
CommitLineData
14d630dd
JL
1#!/usr/bin/perl -w
2#
3# $Id$
4
5# return program syntax
6sub syntax {
7 print "Syntax:\n\tdeptrack directory\n";
8 die;
9}
10
11# worker function called by tagextract and tagstrip
12sub tagcrunch {
13 my($tag1,$tag2,$intag,@lines) = @_;
14 my $line;
15 my $pos;
16 my $out;
17 my $add;
18
19 while ($line = shift(@lines)) {
20 if ($intag) {
21 # we are inside the block
22 if (($pos=index($line, $tag2)) > -1) {
23 $add = substr($line,0,$pos);
24 $line = substr($line,$pos+length($tag2));
25 $intag = 0;
26 } else {
27 $add = $line;
28 $line = "";
29 }
30 $add =~ s/^\s*//;
31 $add =~ s/\s*$//;
32 if (length($add)>0) { $out .= "$add\n"; }
33 }
34
35 if (!$intag) {
36 # we are outside the block
37 while(($pos = index($line, $tag1)) > -1) {
38 $line = substr($line,$pos+length($tag1));
39 if (($pos=index($line, $tag2)) > -1) {
40 $add = substr($line,0,$pos);
41 $line = substr($line,$pos+length($tag2));
42 } else {
43 $add = $line;
44 $line="";
45 $intag=1;
46 }
47 $add =~ s/^\s*//;
48 $add =~ s/\s*$//;
49 if (length($add)>0) { $out .= "$add\n"; }
50 }
51 }
52 }
53 return $out;
54}
55
56# return only blocks of @lines between tag1 and tag2
57sub tagextract {
58 my($tag1,$tag2,@lines) = @_;
59 return tagcrunch($tag1,$tag2,0,@lines);
60}
61
62# return @lines minus blocks between tag1 and tag2
63sub tagstrip {
64 my($tag1,$tag2,@lines) = @_;
65 return tagcrunch($tag2,$tag1,1,@lines);
66}
67
68# parse a directory
69sub parsedir {
70 my $dirhandle;
71 my $dir = $_[0];
72 my $file;
73
74 opendir($dirhandle,$dir);
75 my @files=grep /.*.(php|inc)/,readdir($dirhandle);
76 closedir($dirhandle);
77 foreach $file (@files) {
78 parsefile($file);
79 }
80}
81
82# parse a file
83sub parsefile {
84 my $fhandle;
85 my $file = $_[0];
86
87 open($fhandle,$file);
88 @lines = <$fhandle>;
89 close($fhandle);
90 @lines = tagstrip("<!--","-->",@lines);
91 @lines = tagextract("<?php","?>",@lines);
92 @lines = tagstrip("/*","*/",@lines);
93 print @lines;
94}
95
96my $dir;
97my $nargs = @ARGV;
98$nargs || syntax();
99
100foreach $dir (@ARGV) {
101 parsedir($dir);
102}