8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / auditrecord / mkmsg.pl
blob7fd3983158cfbf77e42d0a4ca04a51440cf973c7
1 #!/usr/perl5/bin/perl -w
3 # CDDL HEADER START
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
20 # CDDL HEADER END
23 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
27 # mkmsg.pl -- generate message file content for strings that
28 # originate in audit_record_attr and audit_event
30 # mkmsg.pl domain po_file_name
32 require 5.005;
33 use strict;
35 use vars qw(
36 $parse %translateText
37 $debug
38 %attr %event %class %skipClass %token %noteAlias);
40 use locale;
41 use POSIX qw(locale_h);
42 use Sun::Solaris::Utils qw(gettext textdomain);
43 use Sun::Solaris::BSM::_BSMparse;
45 unless ($#ARGV == 1) {
46 print STDERR "usage: $0 domain_name file_name\n";
47 exit (1);
49 my $textDomain = $ARGV[0];
50 my $poFile = $ARGV[1];
52 # Set message locale
53 setlocale(LC_ALL, "");
54 textdomain($textDomain);
56 my %options;
57 $options{'classFilter'} = ''; # don''t filter
58 $debug = 0; # debug mode on
59 $options{'eventFilter'} = ''; # don''t filter
60 $options{'idFilter'} = ''; # don''t filter
62 $parse = new Sun::Solaris::BSM::_BSMparse($debug, \%options, './',
63 '../../lib/libbsm', '.txt');
65 my ($attr, $token, $skipClass, $noteAlias) = $parse->readAttr();
66 %class = %{$parse->readClass()};
67 %event = %{$parse->readEvent()};
69 %attr = %$attr;
70 %token = %$token;
71 %noteAlias = %$noteAlias;
72 %skipClass = %$skipClass;
74 my $label;
76 my $errString;
78 foreach $label (sort keys %event) {
80 my ($id, $class, $eventDescription) = ('', '', '');
81 if (defined($event{$label})) {
82 ($id, $class, $eventDescription) = @{$event{$label}};
83 $eventDescription =~ s/\(\w+\)//;
86 my ($name, $description, $title, $skip, @case) = ('', '', '', '', ());
87 if (defined($attr{$label})) {
88 ($name, $description, $title, $skip, @case) = @{$attr{$label}};
89 $description = '' if ($description eq 'none');
90 $name = '' if ($name eq 'none');
91 $title = $name if (($title eq 'none') || (!defined($title)));
94 # in auditrecord.pl, _either_ $description _or_ $eventDescription
95 # is used. Both are put into the message file so that this script
96 # doesn't have logic dependent on auditrecord.pl
98 addToMsgFile($title);
99 addToMsgFile($eventDescription);
100 addToMsgFile($description);
102 my $case;
104 foreach $case (@case) {
105 addToMsgFile(${$case}[0]); # description
106 # [1] # token id (a name list)
107 my @comment = split(/\s*:\s*/, ${$case}[2]);
108 my $note = ${$case}[3];
110 my $comment;
111 foreach $comment (@comment) {
112 addToMsgFile($comment);
114 if ($noteAlias{$note}) {
115 addToMsgFile($noteAlias{$note});
116 } else {
117 addToMsgFile($note);
122 writeMsgFile($textDomain, $poFile);
124 exit (0);
126 sub addToMsgFile {
127 my @text = @_;
129 my $text;
130 foreach $text (@text) {
131 next if ($text =~ /^$/);
132 $text =~ s/:/:/g;
133 $translateText{$text} = 1;
137 # ids in the .po file must be quoted; since the messages themselves
138 # contain quotes, quotes must be escaped
140 sub writeMsgFile {
141 my $domain = shift;
142 my $file = shift;
144 my $text;
146 open(Message, ">$file") or
147 die "Failed to open $file: $!\n";
149 print Message "# File:audit_record_attr: textdomain(\"$domain\")\n";
150 foreach $text (sort keys %translateText) {
151 $text =~ s/"/\\"/g;
152 print Message "msgid \"$text\"\nmsgstr\n";
154 close Message;