blob: cc83b29846db2d25ca19fab44037c8d20f590ad5 [file] [log] [blame]
Alexandre Julliard94613ab2000-11-05 04:51:34 +00001#!/usr/bin/perl
Alexandre Julliardaca05781994-10-17 18:12:41 +00002#
Alexandre Julliard94613ab2000-11-05 04:51:34 +00003# Update the list of debug channels of a given spec file
Alexandre Julliardaca05781994-10-17 18:12:41 +00004#
Alexandre Julliard94613ab2000-11-05 04:51:34 +00005# Copyright 2000 Alexandre Julliard
6#
Alexandre Julliard0799c1a2002-03-09 23:29:33 +00007# This library is free software; you can redistribute it and/or
8# modify it under the terms of the GNU Lesser General Public
9# License as published by the Free Software Foundation; either
10# version 2.1 of the License, or (at your option) any later version.
11#
12# This library is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15# Lesser General Public License for more details.
16#
17# You should have received a copy of the GNU Lesser General Public
18# License along with this library; if not, write to the Free Software
19# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20#
Alexandre Julliard94613ab2000-11-05 04:51:34 +000021# Usage: make_debug spec_file [source_files...]
Alexandre Julliardaca05781994-10-17 18:12:41 +000022#
Alexandre Julliardecc37121994-11-22 16:31:29 +000023
Alexandre Julliard94613ab2000-11-05 04:51:34 +000024die "Usage: make_debug spec_file [source]\n" unless @ARGV;
Alexandre Julliardecc37121994-11-22 16:31:29 +000025
Alexandre Julliard94613ab2000-11-05 04:51:34 +000026$SPEC = shift @ARGV;
Patrik Stridvallb4b9fae1999-04-19 14:56:29 +000027
Alexandre Julliard94613ab2000-11-05 04:51:34 +000028# read in all the source files
29if (@ARGV)
Alexandre Julliard383da682000-02-10 22:15:21 +000030{
Alexandre Julliard94613ab2000-11-05 04:51:34 +000031 while (<>)
32 {
33 if (/DECLARE_DEBUG_CHANNEL\s*\(\s*([A-Za-z0-9_]+)\s*\)/) { $channels{$1} = 1; }
34 if (/DEFAULT_DEBUG_CHANNEL\s*\(\s*([A-Za-z0-9_]+)\s*\)/) { $channels{$1} = 1; }
35 }
Alexandre Julliard383da682000-02-10 22:15:21 +000036}
Alexandre Julliard94613ab2000-11-05 04:51:34 +000037@dbg_channels = sort keys %channels;
38
39# read the whole spec file
40undef $/;
41open SPEC or die "Cannot open $SPEC\n";
42$spec = <SPEC>;
43close SPEC;
44
45# build the new channel list
46$channel_str = "debug_channels (";
47$pos = length($channel_str);
48for ($i = 0; $i <= $#dbg_channels; $i++)
49{
50 $channel_str .= $dbg_channels[$i];
51 $pos += length($dbg_channels[$i]);
52 if ($i < $#dbg_channels)
53 {
54 if ($pos >= 75) { $pos = 16; $channel_str .= "\n" . (" " x $pos); }
55 else { $channel_str .= " "; $pos++; }
56 }
57}
58$channel_str .= ")";
59
60# replace the list in the spec file
61if (!($spec =~ s/debug_channels\s*\(([^)]*)\)/$channel_str/))
62{
63 die "Could not replace debug_channels\n" if @dbg_channels;
64 exit 0;
65}
66
67# output the modified spec file
68open OUTPUT, ">$SPEC" or die "Cannot modify $SPEC\n";
69print OUTPUT $spec;
70close OUTPUT;