fixed build with bundled OpenSSL
[public/netxms.git] / tools / mc.pl
CommitLineData
6dde64eb
AK
1#!c:/apps/perl/bin/pelr -w
2
8e76f8aa 3# $Id$
6dde64eb
AK
4
5###############################################################################
6#
7# VC++ message compiler alternative.
8# read .mc files and generate corresponding source & include
9#
10###############################################################################
11
3da83dc7
AK
12# disabled; broke build on HP-UX (perl 5.005_02)
13#use strict;
14#use Data::Dumper;
6dde64eb
AK
15
16# file names
17my $inFile = shift || die "Usage : mc.pl <input_file>";
18my $outHeader = $inFile;
19$outHeader =~ s/\.[a-z]+$//;
20my $outSource = $outHeader . ".c";
21$outHeader .= ".h";
22
23my $type = "DWORD";
24my $messageId = 0;
25my $comment;
26my $symbolicName = "";
27my %structData;
28
29open(IN, "<$inFile") || die "input file: $!";
30open(OUTH, ">$outHeader") || die "out header: $!";
31open(OUTS, ">$outSource") || die "out source: $!";
32
33while(<IN>) {
34 chomp;
35 my $in = $_;
36 my $text = "";
37
38 if ($in eq "") {
39 next;
40 }
41
42 if ($in =~ /^[;#]+.*$/) {
43 print OUTH substr($in, 1) . "\n";
44 next; # comment -> skip
45 }
46
47 if ($in =~ /^MessageIdTypedef=([A-Z]+)$/i) {
48 # typedef
49 $type = $1;
50
51 next;
52 }
53
54 if ($in =~ /^MessageId=([0-9]*)$/i) {
55 if ($1 eq "") {
56 $messageId++;
57 } else {
58 $messageId = $1 + 0;
59 }
60
61 next;
62 }
63 if ($in =~ /^SymbolicName=(.+)$/i) {
64 $symbolicName = $1;
65
66 next;
67 }
68 if ($in =~ /^Language=(.*)$/i) {
69 # ignore language
70 next;
71 }
72
73 # multiline text
74 $text = $in;
75 while(<IN>) {
76 chomp;
77 if ($_ ne ".") {
78 $text .= "$_\n";
79 # end
80 } else {
81 if ($symbolicName eq "") {
82 last;
83 }
84 print OUTH "//\n// MessageId: $symbolicName\n//\n";
85 print OUTH "// MessageText:\n//\n// ";
86 $structData{$messageId} = $text;
87 $text =~ s/\n/\n\/\//gm;
88 print OUTH $text . "\n//\n";
89
90 my $size = 8;
91 if ($type =~ /^(WORD|short)$/i) {
92 $size = 4;
93 }
eeb5e39c 94 printf OUTH ("#define %-30s (($type)0x%0" . $size . "x)\n\n", $symbolicName, $messageId);
6dde64eb
AK
95 last;
96 }
97 }
98}
99
100print OUTS "/* autogenerated from $inFile */\n\n";
76b1d3d8 101print OUTS "#include <nms_common.h>\n\n";
d49d7500
VK
102print OUTS "#include <unicode.h>\n\n";
103print OUTS "const TCHAR *g_szMessages[] = {\n";
6dde64eb 104
2bdde1f8 105my @keys = sort { $a <=> $b } (keys %structData);
6dde64eb 106
2bdde1f8
AK
107my $i;
108for ($i = 0; $i < $keys[$#keys] + 1; $i++) {
6dde64eb
AK
109 if (defined $structData{$i}) {
110 $structData{$i} =~ s/\"/\\\"/g;
d49d7500 111 print OUTS "\t_T(\"" . $structData{$i} . "\")";
6dde64eb 112 } else {
d49d7500 113 print OUTS "\t_T(\"\")";
6dde64eb
AK
114 }
115
2bdde1f8 116 if ($i == $keys[$#keys]) {
6dde64eb
AK
117 print OUTS "\n";
118 } else {
119 print OUTS ",\n";
120 }
121}
122
3662e9d3 123print OUTS "};\n";
779ce551 124print OUTS "\nunsigned int g_dwNumMessages = $i;\n";
6dde64eb
AK
125
126close IN;
127close OUTH;
128close OUTS;