Minor syntactical changes for readability.
[xuni.git] / src / staticgen.pl
blob57c5811c8be61d0c252deadc16f9c00248b95276
1 #!/usr/bin/perl
3 my $firstfunc = 1;
4 my $path = '';
5 my @funclist = ();
7 print_header();
9 foreach my $file (@ARGV) {
10 $path = '';
11 get_list(get_path($file), read_file($file));
14 print_funclist();
16 print_footer();
18 sub get_path {
19 my $file = shift;
20 $file =~ /(.*)\// && return $1;
22 return '';
25 sub get_filename {
26 my $file = shift;
27 $file =~ /\/([^\/]+)/;
29 return $1;
32 sub read_file {
33 my $file = shift;
35 #print "--- $file\n";
37 open(FILE, "$file");
38 my @data = <FILE>;
39 close FILE;
41 return @data;
44 sub get_list {
45 my $path = shift;
46 my @data = @_;
47 my $in = 0;
48 my @list = ();
50 foreach my $line (@data) {
51 if($in) {
52 if($line =~ /<\/handler/) {
53 $in = 0;
55 else {
56 if($line =~ /<[\w\d_]+>([\w\d_]+)<\/[\w\d_]+>/) {
57 push(@funclist, $1);
61 else {
62 if($line =~ /<include>(.*)<\/include>/) {
63 my $file = $1;
64 my $addpath = get_path($file);
65 my $temppath = $path;
67 if($addpath ne '') {
68 $temppath .= "/$addpath";
71 get_list($temppath,
72 read_file("$temppath/" . get_filename($file)));
75 if($line =~ /<handler/) {
76 $in = 1;
77 next;
81 if($in) {
82 push(@list, $_);
86 return @list;
89 sub print_header {
90 print <<EOF;
91 #ifdef LOADSO_STATIC_VERSION
92 func_point_t xuni_loadso_load_function(loadso_t object, const char *func) {
93 struct string_function_t data[] = {
94 EOF
97 sub print_funclist {
98 my $prev = '';
100 foreach my $func (sort @funclist) {
101 if($func ne $prev) {
102 print_func($func);
105 $prev = $func;
109 sub print_func {
110 my $func = shift;
112 if(!$firstfunc) {
113 print ",\n";
116 print " {\"$func\", (func_point_t)$func}";
118 $firstfunc = 0;
121 sub print_footer {
122 print <<EOF;
125 func_point_t funcp
126 = string_to_function(data, sizeof(data) / sizeof(*data), func);
128 if(!funcp) {
129 log_message(ERROR_TYPE_RESOURCE, 0, __FILE__, __LINE__,
130 "Unknown function: \\"%s\\"", func);
133 return funcp;
135 #endif