make_debug 1.3 KB
Newer Older
1
#!/usr/bin/perl
Alexandre Julliard's avatar
Alexandre Julliard committed
2
#
3
# Update the list of debug channels of a given spec file
Alexandre Julliard's avatar
Alexandre Julliard committed
4
#
5 6 7
# Copyright 2000 Alexandre Julliard
#
# Usage: make_debug spec_file [source_files...]
Alexandre Julliard's avatar
Alexandre Julliard committed
8
#
Alexandre Julliard's avatar
Alexandre Julliard committed
9

10
die "Usage: make_debug spec_file [source]\n" unless @ARGV;
11

12
$SPEC = shift @ARGV;
13

14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
# read in all the source files
if (@ARGV)
{
    while (<>)
    {
        if (/DECLARE_DEBUG_CHANNEL\s*\(\s*([A-Za-z0-9_]+)\s*\)/) { $channels{$1} = 1; }
        if (/DEFAULT_DEBUG_CHANNEL\s*\(\s*([A-Za-z0-9_]+)\s*\)/) { $channels{$1} = 1; }
    }
}
@dbg_channels = sort keys %channels;

# read the whole spec file
undef $/;
open SPEC or die "Cannot open $SPEC\n";
$spec = <SPEC>;
close SPEC;

# build the new channel list
$channel_str = "debug_channels (";
$pos = length($channel_str);
for ($i = 0; $i <= $#dbg_channels; $i++)
{
   $channel_str .= $dbg_channels[$i];
   $pos += length($dbg_channels[$i]);
   if ($i < $#dbg_channels)
   {
       if ($pos >= 75) { $pos = 16; $channel_str .= "\n" . (" " x $pos); }
       else { $channel_str .= " "; $pos++; }
   }
}
$channel_str .= ")";
45

46 47
# replace the list in the spec file
if (!($spec =~ s/debug_channels\s*\(([^)]*)\)/$channel_str/))
48
{
49 50
    die "Could not replace debug_channels\n" if @dbg_channels;
    exit 0;
51
}
52 53 54 55 56

# output the modified spec file
open OUTPUT, ">$SPEC" or die "Cannot modify $SPEC\n";
print OUTPUT $spec;
close OUTPUT;