Implemented the Preprocessor interface.
[aesalon.git] / newsource.pl
blob3c91bc605cbd3f0a76c73251f819f84781b16766
1 #!/usr/bin/env perl
3 sub openNamespace {
4 print FILE "namespace @_[1] {\n";
7 sub closeNamespace {
8 print FILE "} // namespace @_[1]\n";
11 sub classDefinition {
12 print FILE "class @_[1] {\n";
13 print FILE "public:\n";
14 print FILE "\t@_[1]();\n";
15 print FILE "\t~@_[1]();\n";
16 print FILE "};\n";
19 sub printCopyright {
20 # Copyright notice . . .
21 print FILE <<EOF;
22 /**
23 Aesalon, a tool to visualize a program's behaviour at run-time.
24 Copyright (C) 2010, Aesalon Development Team.
26 Aesalon is distributed under the terms of the GNU GPLv3. For more
27 licensing information, see the file LICENSE included with the distribution.
29 \@file @_[0]
32 EOF
35 sub createHeader {
36 if(@_[1] ne "") {
37 $filename = @_[0] . (lc @_[1]) . "/" . @_[2] . ".h\n";
39 else {
40 $filename = @_[0] . "/" . @_[2] . ".h\n";
43 open(FILE, ">$filename") or die("Can't open $filename . . .");
45 printCopyright($filename);
47 # Inclusion guard . . .
48 #$guard = "Aesalon" . @_[3] . "_" . @_[1] . "_" . @_[2] . "_H";
49 if(@_[1] ne "") {
50 $guard = "Aesalon@_[3]_@_[1]_@_[2]_H";
52 else {
53 $guard = "Aesalon@_[3]_@_[2]_H";
56 # Remove duplicate . . .
57 #$guard =~ s/@_[1]@_[1]/@_[1]/e;
59 print FILE "#ifndef $guard\n";
60 print FILE "#define $guard\n\n";
62 openNamespace(FILE, @_[3]);
63 openNamespace(FILE, @_[1]) if @_[1] ne "";
65 print FILE "\n";
67 classDefinition(FILE, @_[2]);
69 print FILE "\n";
71 closeNamespace(FILE, @_[1]) if @_[1] ne "";
72 closeNamespace(FILE, @_[3]);
74 print FILE "\n#endif\n";
76 close(FILE);
79 sub createSource {
80 $filename = @_[0] . (lc @_[1]) . "/" . @_[2] . ".cpp\n";
82 open(FILE, ">$filename") or die("Can't open $filename . . .");
84 printCopyright($filename);
86 if(@_[1] ne "") {
87 print FILE "#include \"" . (lc @_[1]) . "/@_[2].h\"\n\n";
89 else {
90 print FILE "#include \"@_[2].h\"\n\n";
93 openNamespace(FILE, @_[3]);
94 openNamespace(FILE, @_[1]) if @_[1] ne "";
96 print FILE "\n\n\n";
98 closeNamespace(FILE, @_[1]) if @_[1] ne "";
99 closeNamespace(FILE, @_[3]);
101 close(FILE);
104 sub extractNamespace {
105 if(!(@_[0] =~ m/(.+)\:\:(.+)/)) { return "", @_[0]; }
107 # print "1: $1, 2: $2\n";
109 if($2 eq "") { return "", $1; }
110 return $1, $2
113 $argumentCount = $#ARGV + 1;
115 if($argumentCount < 1) {
116 die("Not enough arguments given");
119 $mode = "";
121 # Parse mode . . .
122 if($argumentCount == 1) {
123 $mode = "common";
125 else {
126 if(lc $ARGV[0] eq "monitor") { $mode = "monitor"; }
127 elsif(lc $ARGV[0] eq "visualizer") { $mode = "visualizer"; }
128 elsif(lc $ARGV[0] eq "common") { $mode = "common"; }
129 else {
130 die "Unknown mode";
134 if($mode eq "monitor") {
135 createHeader("include/monitor/", extractNamespace($ARGV[1]), "Monitor");
136 createSource("monitor/src/", extractNamespace($ARGV[1]), "Monitor");
138 elsif($mode eq "visualizer") {
141 elsif($mode eq "common") {
142 createHeader("include/common", extractNamespace($ARGV[1]), "Common");