fixed build with bundled OpenSSL
[public/netxms.git] / tools / gen_param_doc.pl
CommitLineData
9f4f3da3
AK
1#!/usr/bin/perl -w
2## This script scans the source files of NetXMS agent and platform
3## subagents and generates wiki-style parameter compatibility matrix
4## Copyright (C) 2013 Raden Solutions
5##
6## This program is free software; you can redistribute it and/or modify
7## it under the terms of the GNU General Public License version 2
8## as published by the Free Software Foundation.
9##
10## This program is distributed in the hope that it will be useful,
11## but WITHOUT ANY WARRANTY; without even the implied warranty of
12## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13## GNU General Public License for more details.
14##
15## You should have received a copy of the GNU General Public License
16## along with this program; if not, write to the Free Software
17## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19use strict;
20
21# NetXMS source tree
22my $NXBASE = ".";
23
24# process command line
25L1:
26while ($#ARGV >= 0) {
27 if ($ARGV[0] eq "-b") {
28 shift @ARGV;
29 $NXBASE = $ARGV[0];
30 shift @ARGV;
31 next L1;
32 }
33 print STDERR "Incorrect input parameter(s)\n";
34 exit;
35}
36
37# list of sources
38my %paths = (
39 "common" => { "path" => "$NXBASE/src/agent/core/getparam.cpp" },
40 "win" => { "path" => "$NXBASE/src/agent/subagents/winnt/main.cpp" },
41 "linux" => { "path" => "$NXBASE/src/agent/subagents/linux/linux.cpp" },
42 "macos" => { "path" => "$NXBASE/src/agent/subagents/darwin/darwin.cpp" },
43 "freebsd" => { "path" => "$NXBASE/src/agent/subagents/freebsd/freebsd.cpp" },
44 "openbsd" => { "path" => "$NXBASE/src/agent/subagents/openbsd/openbsd.cpp" },
45 "netbsd" => { "path" => "$NXBASE/src/agent/subagents/netbsd/netbsd.cpp" },
46 "hpux" => { "path" => "$NXBASE/src/agent/subagents/hpux/main.cpp" },
47 "aix" => { "path" => "$NXBASE/src/agent/subagents/aix/main.cpp" },
48 "sunos" => { "path" => "$NXBASE/src/agent/subagents/sunos/main.cpp" },
49 "ipso" => { "path" => "$NXBASE/src/agent/subagents/ipso/ipso.cpp" },
50);
51
52# all parameters across all subagents
53my @params;
54
55# create empty arrays and add references to them
56for my $os (keys %paths) {
57 $paths{$os}->{params} = [];
58}
59
60# process sources
61for my $os (keys %paths) {
62 my $str = do {
63 local $/ = undef;
64 open my $fh, "<", $paths{$os}->{path} or die "Cannot open file ".$paths{$os}->{path}." $!";
65 <$fh>;
66 };
67 $str =~ s!/\*.*?\*/!!sg;
68 # common is a special case since it contains params available for
69 # all platforms, win32 is an unpleasant exception though
70 if ($os eq "common") {
71 while ($str =~ /(?:m_parameters|m_stdParams)\[\]\s*?=\s*?\{
72 \s*?\#ifdef\s*?_WIN32(.*?)\#endif(.*?)\}\s*?;/sgix) {
73 my $cont_w32 = $1;
74 my $cont = $2;
75 while ($cont =~ /\{\s*?(?:_T\()?\"(.+?)\"/sgix) {
76 push @params, $1;
77 for ("win", "linux", "macos", "freebsd", "openbsd",
78 "netbsd", "hpux", "aix", "sunos", "ipso") {
79 push @{$paths{$_}->{params}}, $1;
80 }
81 }
82 while ($cont_w32 =~ /\{\s*?(?:_T\()?\"(.+?)\"/sgix) {
83 push @params, $1;
84 push @{$paths{"win"}->{params}}, $1;
85 }
86 }
87 }
88 else { # there subagents go
89 while ($str =~ /(?:m_parameters|m_stdParams)\[\]\s*?=\s*?\{(.*?)\}\s*?;/sgix) {
90 # print "$os: Matched!\n";
91 my $cont = $1;
92 while ($cont =~ /\{\s*?(?:_T\()?\"(.+?)\"/sgix) {
93 push @params, $1;
94 push @{$paths{$os}->{params}}, $1;
95 }
96 }
97 }
98}
99
100my %tmp = map { $_ => 1 } @params;
101my @params_sorted = sort keys %tmp;
102
103print_header(1);
104
105for (my $i = 0; $i <= $#params_sorted; $i++) {
106 my $p = $params_sorted[$i];
107 print "|-\n| $p ||";
108 for ("win", "linux", "macos", "freebsd", "openbsd",
109 "netbsd", "aix", "hpux", "sunos", "ipso") {
110 if (match_array($p, @{$paths{$_}->{params}})) { print_yes(); } else { print_no(); }
111 }
112 print "\n";
113 print_header(0) if ($i > 0 && $i % 32 == 0);
114}
115
116print_footer();
117
118sub match_array
119{
120 my $val = shift;
121 my @arr = @_;
122 for (@arr) { return 1 if $_ eq $val; }
123 return 0;
124}
125
126sub print_header
127{
128 my $begin = shift;
129 print "{| class=\"wikitable\"\n" if ($begin);
130 print <<EOF
131|-
132! Parameter !! Windows !! Linux !! MacOS !! FreeBSD !! OpenBSD !! NetBSD !! AIX !! HP-UX !! Solaris !! IPSO !! Notes
133EOF
134;
135}
136
137sub print_footer
138{
139 print "|}\n";
140}
141
142sub print_yes
143{
144 print 'bgcolor="ltgreen"| Yes ||';
145}
146
147sub print_no
148{
149 print 'bgcolor="red"| No ||';
150}