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
|
#!/usr/bin/perl
use FileHandle;
use IPC::Open2;
if ($ARGV[0] =~ /^--command\=(.+)/) {
$command = $1;
} else {
$command = "g++ -E -I /usr/include/mysql";
}
if (-e 'lib/mysql++.h') {
$command .= " -I lib";
}
else {
$command .= " -I /usr/include/mysql++/";
}
$/ = undef;
$orgcode = <STDIN>;
($macro) = $orgcode =~ /(sql_create_.+? *\(.+?\))/s;
$out = << "---";
#include <ssqls.h>
$macro
---
$/ = "\n";
$temp_dir = -d '/tmp' ? '/tmp' : $ENV{TMP} || $ENV{TEMP};
#print $out;
open OUT, ">$temp_dir/${$}.cc";
print OUT $out;
close OUT;
system "$command $temp_dir/${$}.cc > $temp_dir/${$}.ii";
open IN, "$temp_dir/${$}.ii";
while (<IN>) {
next if /^\#/;
$code .= $_;
}
close IN;
unlink "$temp_dir/${$}.cc","$temp_dir/${$}.ii";
$_ = $code;
s/\s+/ /g;
s/ *public: */public:\n/g;
s/ *private: */public:\n/g;
s/ *\; */\;\n/g;
s/ *\{ */ \{\n/g;
s/ *\} */ \}\n\n/g;
s/ *\n */\n/g;
s/\{\s+}/\{\}/g;
s/\}\s+\;/\}\;\n/g;
$code = "";
foreach (split /\n/) {
if (/\}/ && !/\{\}/ ) {
$indent -= 2;
$ind = ' 'x$indent;
}
$code .= "$ind$_\n" unless /\:$/;
$code .= "$_\n" if /\:$/;
if (/\{/ && !/\{\}/ ) {
$indent += 2;
$ind = ' 'x$indent;
}
}
$orgcode =~ s/(sql_create_.+? *\(.+?\))/\n$code\n/s;
print $orgcode;
|