#!/usr/bin/perl -w # # Copyright (C) 2008 Andreas Baumann # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . use strict; # configuration my %gettext_lang = ( "German" => "../po/de.po" ); # header declaring the langages print < ;// This program is free software: you can redistribute it and/or modify ;// it under the terms of the GNU General Public License as published by ;// the Free Software Foundation, either version 3 of the License, or ;// (at your option) any later version. ;// This program is distributed in the hope that it will be useful, ;// but WITHOUT ANY WARRANTY; without even the implied warranty of ;// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;// GNU General Public License for more details. ;// You should have received a copy of the GNU General Public License ;// along with this program. If not, see . ;// messages file for wolf messages ;// language codes for translated messages ;// (409 ist the windows locale for en-US) ;// (see http://msdn.microsoft.com/en-us/library/ms776260.aspx) LanguageNames = ( English = 0x0409 : MSG00409 German = 0x0407 : MSG00407 ) ;// Category names come first, the 'CategoryCount' registry entry ;// for the event source must match the number of entries here. ;// Also the numbering must be strictly starting by one and increase ;// by one. Careful: categories MUST be defined here, the message ;// compiler is a little bit flag and context infected. Also make ;// sure they are not longer than 10 characters, the event viewer ;// field is quite small. EOF # remember already mapped message ids my %message_ids = (); # read all gettext translations my $lang; my %gettext = (); foreach $lang ( keys %gettext_lang ) { my $pofile = $gettext_lang{$lang}; open PO, "<$pofile"; my $line; my $msgid; my $msgstr; foreach $line ( ) { if( $line =~ /^msgid\s+"(.*)"/ ) { $msgid = $1; } elsif( $line =~ /^msgstr\s+"(.*)"/ ) { $msgstr = $1; $gettext{"${lang}_${msgid}"} = $msgstr; } } close PO; } print <; close CONTENT; open CONTENT, "find .. -name '*.c' -exec cat {} \\; | cpp -I../../include/wolf |"; my $expanded_code = ; close CONTENT; for( ;; ) { if( !( $code =~ /wolf_log\s*\(([^\;]*)/s ) ) { last; } my $func = $1; $code = $'; AGAIN: if( !( $expanded_code =~ /wolf_log\s*\(([^\;]*)/s ) ) { exit 1; } my $expanded_func = $1; $expanded_code = $'; if( $func =~ /\s*(WOLF_LOG_[^\, ]+)\s*\,\s*(WOLF_CATEGORY_[^\, ]+)\s*\,\s*(WOLF_MSG_[^\, ]+)\s*\,\s*_\(\s*"([^"]*)/ ) { my $level = $1; my $category = $2; my $messageid = $3; my $formatstr_c = $4; # map C snprintf format to positional format my $formatstr_win = $formatstr_c; my $pos = 1; while( $formatstr_win =~ s/%[sd]/%${pos}/ ) { $pos++ }; # map the Wolf levels to windows event log severity levels my $severity; if( $level =~ /WOLF_LOG_((EMERG)|(ALERT)|(CRIT)|(ERR))/ ) { $severity = "Error"; } elsif( $level eq " WOLF_LOG_WARNING" ) { $severity = "Warning"; } else { $severity = "Informational"; } # fetch expanded message id from the CPP output my $messageid_number = 9999999; if( $expanded_func =~ /\s*(WOLF_LOG_[^\, ]+)\,\s*([\d\s\+]+)\,\s*([^\,]+)/ ) { my $expanded_messageid = $3; $messageid_number = eval $expanded_messageid; } else { goto AGAIN; } if( defined( $message_ids{$messageid} ) ) { next; } $message_ids{$messageid} = ""; print <