Fix a couple of warnings and a typo.
[wine] / tools / make_debug
1 #!/usr/bin/perl
2 #
3 # Update the list of debug channels of a given spec file
4 #
5 # Copyright 2000 Alexandre Julliard
6 #
7 # Usage: make_debug spec_file [source_files...]
8 #
9
10 die "Usage: make_debug spec_file [source]\n" unless @ARGV;
11
12 $SPEC = shift @ARGV;
13
14 # read in all the source files
15 if (@ARGV)
16 {
17     while (<>)
18     {
19         if (/DECLARE_DEBUG_CHANNEL\s*\(\s*([A-Za-z0-9_]+)\s*\)/) { $channels{$1} = 1; }
20         if (/DEFAULT_DEBUG_CHANNEL\s*\(\s*([A-Za-z0-9_]+)\s*\)/) { $channels{$1} = 1; }
21     }
22 }
23 @dbg_channels = sort keys %channels;
24
25 # read the whole spec file
26 undef $/;
27 open SPEC or die "Cannot open $SPEC\n";
28 $spec = <SPEC>;
29 close SPEC;
30
31 # build the new channel list
32 $channel_str = "debug_channels (";
33 $pos = length($channel_str);
34 for ($i = 0; $i <= $#dbg_channels; $i++)
35 {
36    $channel_str .= $dbg_channels[$i];
37    $pos += length($dbg_channels[$i]);
38    if ($i < $#dbg_channels)
39    {
40        if ($pos >= 75) { $pos = 16; $channel_str .= "\n" . (" " x $pos); }
41        else { $channel_str .= " "; $pos++; }
42    }
43 }
44 $channel_str .= ")";
45
46 # replace the list in the spec file
47 if (!($spec =~ s/debug_channels\s*\(([^)]*)\)/$channel_str/))
48 {
49     die "Could not replace debug_channels\n" if @dbg_channels;
50     exit 0;
51 }
52
53 # output the modified spec file
54 open OUTPUT, ">$SPEC" or die "Cannot modify $SPEC\n";
55 print OUTPUT $spec;
56 close OUTPUT;