3 # Take a C header file and remove all preprocessor commands.
4 # Wrap all typedefs with a preprocessor guard,
5 # add all possible typedefs in firm at the beginning of the file, also
6 # wrapped with a preprocessor guard
9 # perl remove_cpp_comands.perl <file>
10 # for a file with name <file>.h.
20 open(OUT, ">$outfile");
22 $typedeffile = "firm_typedefs.h";
23 open(TDF, ">>$typedeffile");
26 print OUT "\n#include \"firm_typedefs.h\"\n\n";
29 #Unresolved preprocessor commands
30 print TDF "#define INLINE\n";
31 print TDF "#define FILE int *\n";
32 print TDF "#ifndef MYTYPEDEFS\n#define MYTYPEDEFS\n";
33 print TDF "typedef unsigned long size_t;\n";
34 #print TDF "typedef enum { false = 0, true = 1 } bool;\n"; geht nicht, false und true JAVA Schluesselwoerter
35 print TDF "typedef int bool;\n";
45 foreach $line (@lines) {
47 if (($line =~ /^\#/) ) {
49 $scndlastline = $lastline;
51 } elsif ($openbracket == 1) {
53 if ((index($line, "}") > -1)) {
55 if (($guardedtypedef == 1)) {
61 } elsif ($line =~ /typedef/) {
62 # move the full typedef to firm_typedefs.h
64 if (($lastline =~ /^\#/) ) {
66 print TDF "$scndlastline"; $scndlastline = "";
67 print TDF "$lastline"; $lastline = "";
70 if ((index($line, "{") > -1)) {
72 } elsif (($guardedtypedef == 1)) {
76 if ((index($line, "}") > -1)) {
78 if (($guardedtypedef == 1)) {
85 $scndlastline = $lastline;