-
Notifications
You must be signed in to change notification settings - Fork 1
/
.hpp2h
executable file
·105 lines (91 loc) · 1.65 KB
/
.hpp2h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/perl
#GENERATE HEADER FILE FROM A PROGRAM FILE AND A TEMPLATE OF THE HEADER
$USAGE="Usage:
$0 <filename>
Extract the prototypes from <filename>.cpp append it to <filename>.hpp and generate <filename>.h
Routines prototypes in <filename>.cpp should be enclosed by /*P-*/ and /*-P*/
Example:
/*P-*/
real MaxMin(real x,real y)
/*-P*/
{
return x>y?x:y;
}
";
$file=shift @ARGV;
print "Generating $file.h...\n";
if(!-e "$file.cpp")
{
print "Error: source file $file.cpp does not exists...\n";
print $USAGE;
exit(1);
}
if(!-e "$file.hpp")
{
print "Error: template file $file.hpp does not exists...\n";
print $USAGE;
exit(1);
}
open(fl,"<$file.cpp");
@lines=<fl>;chomp @lines;
close(fl);
$prot="";
$decl="";
$ini=$end=0;
$inid=$endd=0;
for $line (@lines){
# if($line=~/\/\*P-\*\//){
# $ini=1;
# $end=0;
# $prot.="\n";
# next;
# }
# elsif($line=~/\/\*-P\*\//){
# $ini=0;
# $end=1;
# $prot.=";\n";
# next;
# }
if($line=~/\/\*P\*\//){
$ini=1;
$end=0;
$prot.="\n";
next;
}
elsif($line=~/^{/){
$ini=0;
$end=1;
$prot.=";\n";
next;
}
elsif($line=~/\/\*D\*\// and !$inid){
$inid=1;
$endd=0;
$decl.="\n";
next;
}
elsif($line=~/\/\*D\*\// and $inid){
$ini=0;
$inid=0;
$endd=1;
$decl.="\n";
next;
}
if($ini){
next if($line!~/\w/);
$line=~s/^\s+//;
$line=~s/\/\*=([^=]+)=\*\//=$1/;
$prot.="$line";
}
elsif($inid){
next if($line!~/\w/);
$line=~s/^\s+//;
$decl.="extern $line\n";
}
}
system("cat $file.hpp > $file.h");
open(fl,">>$file.h");
print fl $decl;
print fl $prot;
print fl "\n#endif";
close(fl);