Alexandre Julliard | 94613ab | 2000-11-05 04:51:34 +0000 | [diff] [blame] | 1 | #!/usr/bin/perl |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 2 | # |
Alexandre Julliard | 94613ab | 2000-11-05 04:51:34 +0000 | [diff] [blame] | 3 | # Update the list of debug channels of a given spec file |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 4 | # |
Alexandre Julliard | 94613ab | 2000-11-05 04:51:34 +0000 | [diff] [blame] | 5 | # Copyright 2000 Alexandre Julliard |
| 6 | # |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 7 | # 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 Julliard | 94613ab | 2000-11-05 04:51:34 +0000 | [diff] [blame] | 21 | # Usage: make_debug spec_file [source_files...] |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 22 | # |
Alexandre Julliard | ecc3712 | 1994-11-22 16:31:29 +0000 | [diff] [blame] | 23 | |
Alexandre Julliard | 94613ab | 2000-11-05 04:51:34 +0000 | [diff] [blame] | 24 | die "Usage: make_debug spec_file [source]\n" unless @ARGV; |
Alexandre Julliard | ecc3712 | 1994-11-22 16:31:29 +0000 | [diff] [blame] | 25 | |
Alexandre Julliard | 94613ab | 2000-11-05 04:51:34 +0000 | [diff] [blame] | 26 | $SPEC = shift @ARGV; |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 27 | |
Alexandre Julliard | 94613ab | 2000-11-05 04:51:34 +0000 | [diff] [blame] | 28 | # read in all the source files |
| 29 | if (@ARGV) |
Alexandre Julliard | 383da68 | 2000-02-10 22:15:21 +0000 | [diff] [blame] | 30 | { |
Alexandre Julliard | 94613ab | 2000-11-05 04:51:34 +0000 | [diff] [blame] | 31 | 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 Julliard | 383da68 | 2000-02-10 22:15:21 +0000 | [diff] [blame] | 36 | } |
Alexandre Julliard | 94613ab | 2000-11-05 04:51:34 +0000 | [diff] [blame] | 37 | @dbg_channels = sort keys %channels; |
| 38 | |
| 39 | # read the whole spec file |
| 40 | undef $/; |
| 41 | open SPEC or die "Cannot open $SPEC\n"; |
| 42 | $spec = <SPEC>; |
| 43 | close SPEC; |
| 44 | |
| 45 | # build the new channel list |
| 46 | $channel_str = "debug_channels ("; |
| 47 | $pos = length($channel_str); |
| 48 | for ($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 |
| 61 | if (!($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 |
| 68 | open OUTPUT, ">$SPEC" or die "Cannot modify $SPEC\n"; |
| 69 | print OUTPUT $spec; |
| 70 | close OUTPUT; |