CoCalc Public Fileswww / cgi-bin / openwebmail / misc / test / debugadd.plOpen with one click!
Author: William A. Stein
1
#!/usr/bin/perl
2
#
3
# this uty adds debug log line at the begining of all subroutine,
4
# so calling of each routine will be logged into /tmp/openwebmail.debug
5
#
6
7
use strict;
8
if ($#ARGV<0) {
9
print "debugadd file1 file2 ...\n";
10
exit;
11
}
12
13
my $updatedfile=0;
14
my $totalinsertion=0;
15
foreach my $script (@ARGV) {
16
my $content='';
17
my $insertion=0;
18
my $package=0;
19
print "add debug code to $script ...";
20
open (F, $script);
21
while (<F>) {
22
my $line=$_;
23
if ($line=~/^sub .*{\s*/ && $line!~/sub log_time/) {
24
$content.=$line;
25
my $debugline=$line;
26
$debugline=~s/^sub //;
27
$debugline=~s/\s*{.*$//g;
28
chomp($debugline);
29
$debugline=qq|log_time('$debugline :', \@_);\n|;
30
$content.=$debugline;
31
$insertion++;
32
} elsif ($line=~/^package openwebmail::/) {
33
$package=1;
34
$content.=$line;
35
} else {
36
$content.=$line;
37
}
38
}
39
close(F);
40
41
if ($package) {
42
print "package skipped\n";
43
} elsif ($insertion) {
44
if (open (F, ">$script")) {
45
print F $content;
46
close(F);
47
print "$insertion line added\n";
48
$updatedfile++;
49
$totalinsertion+=$insertion;
50
} else {
51
print "update err!\n";
52
}
53
} else {
54
print "\n";
55
}
56
}
57
58
print "$updatedfile file updated (total $totalinsertion line added)\n";
59