Index: trunk/extensions/Wikidata/OmegaWiki/small/ra3.pl |
— | — | @@ -0,0 +1,85 @@ |
| 2 | +#!/usr/bin/perl |
| 3 | +use strict; |
| 4 | +use Data::Dumper; |
| 5 | +#Replace attribs 2 ( |
| 6 | + |
| 7 | +# seeks out the attributes globals and replaces them with rather more sane code |
| 8 | +# still leaves a small amount of mess at times |
| 9 | +# I should still watch out for scope |
| 10 | + |
| 11 | +sub joinpairs { |
| 12 | + my @a=@_; |
| 13 | + my @b; |
| 14 | + for(my $pointer=0;$pointer<$#a;$pointer+=2) { |
| 15 | + push (@b, $a[$pointer].$a[$pointer+1]); |
| 16 | + } |
| 17 | + return \@b; |
| 18 | +} |
| 19 | + |
| 20 | +my $global=0; # state variable: are we inside a (multiline?) php 'global' statement |
| 21 | +my $statement=""; |
| 22 | +my $block_num=0; # the next number we shall assign to a block |
| 23 | +my @block_stack=0; # your actual current block number is $block_stack[0] (ie, peek the stack) |
| 24 | +my %globals; |
| 25 | +while(<>) { |
| 26 | + if (/global/) { |
| 27 | + $global=1; #start of global statement |
| 28 | + print $statement; |
| 29 | + $statement=""; |
| 30 | + } |
| 31 | + |
| 32 | + #if ($global) { |
| 33 | + # s/\$(\w+)(Attributes?|Structure)\;/;/g; |
| 34 | + # s/\$(\w+)(Attributes?|Structure)\W//g; |
| 35 | + # s/^\s*$//; # remove empty lines |
| 36 | + #} |
| 37 | + $statement.=$_; |
| 38 | + |
| 39 | + |
| 40 | + # This makes some evil assumptions, but we're just |
| 41 | + # trying to _cut down_ on the number of errors, we don't |
| 42 | + # eliminate them entirely, since we're just running this |
| 43 | + # script once, after all |
| 44 | + if (/\{/) { |
| 45 | + $block_num++; |
| 46 | + unshift(@block_stack, $block_num); |
| 47 | + } |
| 48 | + |
| 49 | + if (/\}/) { |
| 50 | + my $end=shift(@block_stack); |
| 51 | + } |
| 52 | + |
| 53 | + if (/\;/) { |
| 54 | + my @matches=[]; |
| 55 | + $statement=~/^(\s*).*/; |
| 56 | + my $indent=$1; |
| 57 | + if ($global) { |
| 58 | + @matches=($statement=~/\$(\w+)(Attributes?|Structure)/g); |
| 59 | + if (@matches) { |
| 60 | + $globals{$block_stack[0]}=joinpairs(@matches); |
| 61 | + $statement=~s/\$(\w+)(Attributes?|Structure)\;/;/g; |
| 62 | + $statement=~s/\$(\w+)(Attributes?|Structure)\W//gm; |
| 63 | + #$statement=~s/;/ ,;/ if $statement=~/global.*\$\w*(.*);/gs; # if there are still params left, we need a comma |
| 64 | + $statement=~s/;/;\n$indent\$o=OmegaWikiAttributes::getInstance();/g; |
| 65 | + } |
| 66 | + $statement=~s/,\s*;/;/gm; # remove redundant trailing commas |
| 67 | + $statement=~s/.*global\s*;\s*//gs; # perhaps the global statement is entirely redundant? |
| 68 | + $statement=~s/^\s*$//gm; # remove empty lines (redundant now?) |
| 69 | + $global=0; # end of global statement |
| 70 | + } |
| 71 | + #$statement=~s/\$o\s*=\s*\$omegaWikiAttributes;/\$o=OmegaWikiAttributes::getInstance();/g; |
| 72 | + $statement=~s/\$(\w+)Attribute(\W)/\$o\-\>$1$2/g; |
| 73 | + $statement=~s/\$(\w+)Attributes(\W)/\$o\-\>$1Attributes$2/g; |
| 74 | + $statement=~s/\$(\w+)Structure(\W)/\$o\-\>$1Structure$2/g; |
| 75 | + $statement=~s/->getAttributeValue\(\s*\$o->(\$\w+)\s*\);/->$1;/g; |
| 76 | + $statement=~s/->setAttributeValue\(\s*\$o->(\$\w+)\s*,\s*(.*)\s*\);/->$1 = $2;/g; |
| 77 | + #print $block_stack[0].": ".$statement; # and peek too |
| 78 | + #print "[".join(", ",@block_stack)."]\n"; |
| 79 | + $statement=""; |
| 80 | + |
| 81 | + } |
| 82 | + print $block_stack[0].": ".$_; |
| 83 | +} |
| 84 | +print $statement; # flush out any remaining lines |
| 85 | + |
| 86 | +print Dumper(%globals); |
Property changes on: trunk/extensions/Wikidata/OmegaWiki/small/ra3.pl |
___________________________________________________________________ |
Added: svn:executable |
1 | 87 | + * |
Index: trunk/extensions/Wikidata/OmegaWiki/small/listmatch.pl |
— | — | @@ -0,0 +1,12 @@ |
| 2 | +#!/usr/bin/perl |
| 3 | +# Can we get a list of matches? |
| 4 | +# |
| 5 | + |
| 6 | +$alist="bla bat cat hat mat ra gosh mosh tosh socks rocks docks batty"; |
| 7 | + |
| 8 | +@rhymes_with_bat = ($alist=~/\b(\w*at)\b/g); |
| 9 | +@rhymes_with_rocks = ($alist=~/\b(\w*ocks)\b/g); |
| 10 | +print join(", ",@rhymes_with_bat).".\n"; |
| 11 | +print join(", ",@rhymes_with_rocks).".\n"; |
| 12 | +print $alist."\n"; |
| 13 | + |
Property changes on: trunk/extensions/Wikidata/OmegaWiki/small/listmatch.pl |
___________________________________________________________________ |
Added: svn:executable |
1 | 14 | + * |
Index: trunk/extensions/Wikidata/OmegaWiki/small/check.sh |
— | — | @@ -1,6 +1,6 @@ |
2 | 2 | #!/bin/bash |
3 | 3 | export myfile=$1; |
4 | 4 | |
5 | | -small/raO.pl $myfile | |
6 | | - diff -d $myfile - | |
| 5 | +small/ra3.pl $myfile | |
| 6 | + diff -dy $myfile - | |
7 | 7 | less |