4 #use vars qw(\$version \$help \$verbose \$lang \@includes \%ents);
7 sub print_revision
($$);
12 my $PROGNAME = "tango";
13 my $REVISION = '$Revision$ ';
14 $REVISION =~ s/^\$Revision: //;
15 $REVISION =~ s/ \$ $//;
17 my $PACKAGE = 'Nagios Plugins';
19 my $WARRANTY = "The nagios plugins come with ABSOLUTELY NO WARRANTY. You may redistribute\ncopies of the plugins under the terms of the GNU General Public License.\nFor more information about these matters, see the file named COPYING.\n";
28 Getopt
::Long
::Configure
('bundling');
30 ("V" => \
$version, "version" => \
$version,
31 "h" => \
$help, "help" => \
$help,
32 "v" => \
$verbose, "verbose" => \
$verbose,
33 "f" => \
$follow, "follow!" => \
$follow,
34 "l=s" => \
$lang, "language=s" => \
$lang,
38 print_help
($PROGNAME,$REVISION);
43 print_revision
($PROGNAME,$REVISION);
47 if (!defined($lang)) {
48 print_usage
($PROGNAME,$REVISION);
60 # first step is to get a set of defines in effect
61 # we do this with gcc preprocessor
63 # first, assemble the command
64 my $cmd = "/usr/bin/gcc -E -dM";
65 foreach $dir (@INCLUDE) {
66 $cmd .= " -I $dir" if ($dir) ;
69 # add the file(s) to process
70 while ($file = shift) {
75 # then execute the command, storing defines in %main::ents
78 next if (m
|\#define\s
+[^\s\
(]+\
(|);
79 if (m
|\#define\s
+(\S
+)\s
+(\"?
)(.*?
)\
2$|) {
82 $ent =~ s
|\\n
\\n
|</para
>\n\n<para
>|msg
;
84 $main::ents
{$key} = $ent;
88 # then we slurp the file to fetch the XML
90 foreach $file (@files) {
91 $xml .= slurp
($lang, $follow, $file, @INCLUDE);
94 # finally substitute the defines as XML entities
95 foreach $key (keys %main::ents
) {
96 $xml =~ s/\&$key\;/$main::ents{$key}/msg;
99 # and print the result
104 sub print_revision
($$) {
105 my $PROGNAME = shift;
106 my $REVISION = shift;
107 print "$PROGNAME ($PACKAGE $RELEASE) $REVISION\n";
111 sub print_usage
($$) {
112 my $PROGNAME = shift;
113 my $REVISION = shift;
114 print qq"\n$PROGNAME -l <language> [options] file [...]\n"
117 sub print_help
($$) {
118 my $PROGNAME = shift;
119 my $REVISION = shift;
120 print_usage
($PROGNAME, $REVISION);
123 -l, --language=STRING
124 Currently supported languages are C and perl
130 my ($lang, $follow, $file, @INCLUDE) = @_;
135 my $descriptor = 'T' . int(rand 100000000);
137 if ($file !~ m
|^[\
.\
/\\]|) {
138 foreach $dir (@INCLUDE) {
139 if ($ostat = open $descriptor, "<$dir/$file") {
140 push @main::includes
, $file;
145 $ostat = open $descriptor, "<$file";
146 push @main::includes
, $file if $ostat;
148 return "" unless $ostat;
151 while (<$descriptor>) {
153 if ($follow && m
|^\s
*\#\s
*include\s
+[<"]([^\">]+)[">]|) {
154 $xml .= slurp
($lang, $follow, $1, @INCLUDE) unless (in (@main::includes
, $1));
156 if ($block =~ m
|(\S
+)\s
+(\S
+)\s
*(\
([^\
)]*\
));|) {
157 $main::ents
{"PROTO_$2"} = "$1 $2 $3";
159 if ($block =~ m
|//|) { # C++ style one-line comment
160 if (m
|//\@\@
-(.*)-\@\@
|) {
164 if ($block =~ m
|/\
*|) { # normal C comments
165 while ($block !~ m
|/\*(.*)\*/|ms
) {
166 $block .= <$descriptor>;
168 if ($block =~ m
|\@\@
-(.*)-\@\@
|ms
) {
170 } elsif ($block =~ m
|\
@s*-(.*)\s
*-\@
|ms
) {
172 while ($block !~ m
|\
*/\s
*([^\
;]+);|ms
) {
173 $block .= <$descriptor>;
175 if ($block =~ m
|\
*/\s
*([^\
;]+);|ms
) {
176 $main::ents
{$key} = $1;
189 return 1 if ($key eq $el);
194 sub CommentStart
($) {
198 } elsif ($lang == 'perl') {
205 # if ($_ =~ m/^\s*\#\s*define\s+([-_a-zA-Z0-9]+)\s+(.*)\s*$/) {
207 # $main::ents{$key} = "$2";
208 # while (($main::ents{$key} =~ s/\\\s*$//s) && ($block = <$descriptor>)) {
209 # $main::ents{$key} .= $block;
211 # $main::ents{$key} =~ s/"(.*)"$/$1/s;
212 # $main::ents{$key} =~ s/\s+\/[\/\*].*$//s;
215 ### Local Variables: ;;;
217 ### perl-indent-level: 2 ;;;