diff options
Diffstat (limited to 'rt/tools')
| -rw-r--r-- | rt/tools/genbuild.pl | 48 | ||||
| -rw-r--r-- | rt/tools/genintf.pl | 42 |
2 files changed, 90 insertions, 0 deletions
diff --git a/rt/tools/genbuild.pl b/rt/tools/genbuild.pl new file mode 100644 index 0000000..1acabc0 --- /dev/null +++ b/rt/tools/genbuild.pl @@ -0,0 +1,48 @@ +#!/usr/bin/env perl + +$comment=""; + +print "#include <stdio.h>\n"; +print "#include <dlfcn.h>\n"; +print "#include <pthread.h>\n"; +print "#include <string.h>\n"; +print "#include \"plugin.h\"\n\n"; + +print "int load_plugin_from_dl_(dlhandle_t dl, plugin_t* plug)\n"; +print "{\n"; +print " void* ptr;\n"; +print " int ret = 0;\n"; +print "\n"; +print " const char** name = dlsym(dl, \"plugin_name\");\n"; +print " memset(plug, 0, sizeof(*plug));\n"; +print " if (name) {\n"; +print " plug->plugin_name = *name;\n"; +print " } else {\n"; +print " plug->plugin_name = NULL;\n"; +print " }\n"; +print " plug->state = NULL;\n"; +print " plug->library_handle = dl;\n"; +print "\n"; +while (<>) { + if (/^\s*EXPORT/) { + my $line = "$_"; + while (not ($line =~ /;$/)) { + my $nextline = <STDIN>; + last unless defined $nextline; + + $line="$line$nextline"; + } + if ($line =~ /^\s*EXPORT\(\s*((?:\w|\s*\*\s*)+)\s*\(\*(\w+)\)\s*\((.*)\)\);/s) { + print "\n"; + print " ptr = dlsym(dl, \"$2\");\n"; + print " if (!ptr) {\n"; + print " fprintf(stderr, \"Plugin missing %s\\n\", \"$2\");\n"; + print " ret |= 1;\n"; + print " }\n"; + print " plug->$2 = ptr;\n"; + $comment=""; + } + } +} +print "\n return ret;\n"; +print "}\n"; diff --git a/rt/tools/genintf.pl b/rt/tools/genintf.pl new file mode 100644 index 0000000..794f966 --- /dev/null +++ b/rt/tools/genintf.pl @@ -0,0 +1,42 @@ +#!/usr/bin/env perl + +$comment=""; + +print "#ifndef _PLUG_INTF\n"; +print "#define _PLUG_INTF\n"; +print "\n#include <stdint.h>\n"; +print "\n#include <plugin_types.h>\n"; + +while (<STDIN>) { + if (/^\s*\/\*/) { + $_ =~ s/^\s*//; + $comment="$_"; + next; + } + + if (/^\s*\*/) { + $_ =~ s/^\s*/ /; + $comment="$comment$_"; + next; + } + + if (/^\s*EXPORT_INCLUDE\((.*)\)/) { + print "#include $1\n"; + } elsif (/^\s*EXPORT/) { + my $line = "$_"; + while (not ($line =~ /;$/)) { + my $nextline = <STDIN>; + last unless defined $nextline; + + $line="$line$nextline"; + } + if ($line =~ /^\s*EXPORT\(\s*((?:\w|\s*\*\s*)+)\s*\(\*(\w+)\)\s*\((.*)\)\);/s) { + print "$comment"; + print "$1 $2($3);\n\n"; + $comment=""; + } elsif ($line =~ /^\s*EXPORT\((.*)\);/s) { + print "$1\n"; + } + } +} +print "#endif /* _PLUG_INTF */\n"; |