| 1 | #!/usr/bin/perl |
|---|
| 2 | if ($#ARGV != 0) |
|---|
| 3 | { |
|---|
| 4 | die "Argument must contain filename $#ARGV" |
|---|
| 5 | } |
|---|
| 6 | else |
|---|
| 7 | { |
|---|
| 8 | $fname=$ARGV[0]; |
|---|
| 9 | } |
|---|
| 10 | open(my $in, $fname); |
|---|
| 11 | |
|---|
| 12 | $declTypeDef="typedef void * in; \n"; |
|---|
| 13 | $output = ""; |
|---|
| 14 | $inClass = 0; |
|---|
| 15 | |
|---|
| 16 | $inStaticMethods = ""; |
|---|
| 17 | |
|---|
| 18 | while (<$in>) |
|---|
| 19 | { |
|---|
| 20 | if (/(^\s*)(%>)(.*)/) |
|---|
| 21 | { |
|---|
| 22 | $output=$output."$1///$3"; |
|---|
| 23 | } |
|---|
| 24 | if (($listeProperties == 1) && (/(^\s*end\s*)/)) |
|---|
| 25 | { |
|---|
| 26 | $listeProperties = 0; |
|---|
| 27 | } |
|---|
| 28 | if (($listeProperties == 1) && (/^\s*([\w\d]*)\s*[=]?.*(%>.*)?/)) |
|---|
| 29 | { |
|---|
| 30 | if (!($1 =~ /^$/)) |
|---|
| 31 | { |
|---|
| 32 | $properties = "$1;$2"; |
|---|
| 33 | $properties =~ s/%>/\/\/\//g; |
|---|
| 34 | $properties =~ s/%/\/\//g; |
|---|
| 35 | $output=$output.$properties; |
|---|
| 36 | } |
|---|
| 37 | } |
|---|
| 38 | if (/(^\s*function)\s*([\] \w\d,_\[]+=)?\s*([.\w\d_-]*)\s*\(?([\w\d\s,]*)\)?(%?.*)/) |
|---|
| 39 | { |
|---|
| 40 | $functionKeyWord = $1; |
|---|
| 41 | $functionName = $3; |
|---|
| 42 | $arguments = $4; |
|---|
| 43 | if ($inClass == 0) |
|---|
| 44 | { |
|---|
| 45 | $output = $declTypeDef.$output; |
|---|
| 46 | $declTypeDef = ""; |
|---|
| 47 | } |
|---|
| 48 | $arguments =~ s/,/,in /g; |
|---|
| 49 | $arguments = "in $arguments"; |
|---|
| 50 | if ($arguments =~ /^in $/) |
|---|
| 51 | { |
|---|
| 52 | $arguments = ""; |
|---|
| 53 | } |
|---|
| 54 | $ligne = "$inStaticMethods $functionKeyWord $functionName($arguments);"; |
|---|
| 55 | $output=$output.$ligne; |
|---|
| 56 | } |
|---|
| 57 | # inheritance for classes |
|---|
| 58 | if (/(^\s*classdef)\s*([\w\d_]+)\s*<?\s*([\w\d_]+)?(.*)/) |
|---|
| 59 | { |
|---|
| 60 | if (!($3 =~ /^$/)) |
|---|
| 61 | { |
|---|
| 62 | $classDef = "class $2:public $3"; |
|---|
| 63 | } |
|---|
| 64 | elsif (/(^\s*classdef)\s*([\w\d_]+)(.*)/) |
|---|
| 65 | { |
|---|
| 66 | $classDef = "class $2"; |
|---|
| 67 | } |
|---|
| 68 | $output=$output.$classDef; |
|---|
| 69 | $output=$output."{"; |
|---|
| 70 | $output=$output.$declTypeDef; |
|---|
| 71 | $output=$output."public:\n"; |
|---|
| 72 | $inClass = 1; |
|---|
| 73 | } |
|---|
| 74 | if (/(^\s*properties)\s*(.*)/) |
|---|
| 75 | { |
|---|
| 76 | $listeProperties = 1; |
|---|
| 77 | } |
|---|
| 78 | if (/^\s*methods\s*\(\s*Static(\s*=\s*true\s*)?\)(.*)/) |
|---|
| 79 | { |
|---|
| 80 | $inStaticMethods = "static"; |
|---|
| 81 | } |
|---|
| 82 | elsif (/^\s*methods\s*\.*/) |
|---|
| 83 | { |
|---|
| 84 | $inStaticMethods = ""; |
|---|
| 85 | } |
|---|
| 86 | $output=$output."\n"; |
|---|
| 87 | } |
|---|
| 88 | $output=$output."};\n"; |
|---|
| 89 | print $output; |
|---|
| 90 | close $in; |
|---|