[+] vc++ message compiler replacement
authorAlex Kirhenshtein <alk@netxms.org>
Thu, 9 Oct 2003 16:03:43 +0000 (16:03 +0000)
committerAlex Kirhenshtein <alk@netxms.org>
Thu, 9 Oct 2003 16:03:43 +0000 (16:03 +0000)
.gitattributes
tools/mc.pl [new file with mode: 0644]

index 96367d3..1c0ed9d 100644 (file)
@@ -32,3 +32,4 @@ src/server/dbdrv/pgsql/pgsql.dsw -text
 src/server/dbdrv/pgsql/pgsqldrv.h -text
 src/server/include/dbdrv.h -text
 src/server/include/nms_threads.h -text
+tools/mc.pl -text
diff --git a/tools/mc.pl b/tools/mc.pl
new file mode 100644 (file)
index 0000000..15100ad
--- /dev/null
@@ -0,0 +1,122 @@
+#!c:/apps/perl/bin/pelr -w
+
+# $Id: mc.pl,v 1.1 2003-10-09 16:03:43 alk Exp $
+
+###############################################################################
+#
+# VC++ message compiler alternative.
+# read .mc files and generate corresponding source & include
+#
+###############################################################################
+
+use strict;
+
+# file names
+my $inFile = shift || die "Usage : mc.pl <input_file>";
+my $outHeader = $inFile;
+$outHeader =~ s/\.[a-z]+$//;
+my $outSource = $outHeader . ".c";
+$outHeader .= ".h";
+
+my $type = "DWORD";
+my $messageId = 0;
+my $comment;
+my $symbolicName = "";
+my %structData;
+
+open(IN, "<$inFile") || die "input file: $!";
+open(OUTH, ">$outHeader") || die "out header: $!";
+open(OUTS, ">$outSource") || die "out source: $!";
+
+while(<IN>) {
+       chomp;
+       my $in = $_;
+       my $text = "";
+
+       if ($in eq "") {
+               next;
+       }
+
+       if ($in =~ /^[;#]+.*$/) {
+               print OUTH substr($in, 1) . "\n";
+               next; # comment -> skip
+       }
+
+       if ($in =~ /^MessageIdTypedef=([A-Z]+)$/i) {
+               # typedef
+               $type = $1;
+
+               next;
+       }
+
+       if ($in =~ /^MessageId=([0-9]*)$/i) {
+               if ($1 eq "") {
+                       $messageId++;
+               } else {
+                       $messageId = $1 + 0;
+               }
+
+               next;
+       }
+       if ($in =~ /^SymbolicName=(.+)$/i) {
+               $symbolicName = $1;
+
+               next;
+       }
+       if ($in =~ /^Language=(.*)$/i) {
+               # ignore language
+               next;
+       }
+
+       # multiline text
+       $text = $in;
+       while(<IN>) {
+               chomp;
+               if ($_ ne ".") {
+                       $text .= "$_\n";
+                       # end
+               } else {
+                       if ($symbolicName eq "") {
+                               last;
+                       }
+                       print OUTH "//\n// MessageId: $symbolicName\n//\n";
+                       print OUTH "// MessageText:\n//\n// ";
+                       $structData{$messageId} = $text;
+                       $text =~ s/\n/\n\/\//gm;
+                       print OUTH $text . "\n//\n";
+
+                       my $size = 8;
+                       if ($type =~ /^(WORD|short)$/i) {
+                               $size = 4;
+                       }
+                       printf OUTH ("#define %-30s (($type)%0" . $size . "x)\n\n", $symbolicName, $messageId);
+                       last;
+               }
+       }
+}
+
+print OUTS "/* autogenerated from $inFile */\n\n";
+print OUTS "char *g_szMessages[] = {\n";
+
+my @keys = sort {$b <=> $a} (keys %structData);
+
+for (my $i = 0; $i < $keys[0]; $i++) {
+       if (defined $structData{$i}) {
+               $structData{$i} =~ s/\"/\\\"/g;
+               print OUTS "\t\"" . $structData{$i} . "\"";
+       } else {
+               print OUTS "\t\"\"";
+       }
+
+       if ($i+1 == $keys[0]) {
+               print OUTS "\n";
+       } else {
+               print OUTS ",\n";
+       }
+}
+
+print OUTS "}\n";
+
+close IN;
+close OUTH;
+close OUTS;