r25031 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25030‎ | r25031 | r25032 >
Date:04:17, 22 August 2007
Author:kim
Status:old
Tags:
Comment:
Some extra grep functions to dig my way through the Editor and idstacks.
Doing:
small/bodygrep.pl save Editor.php

Is not as enlightening as I'd hoped. (possibly because I'm sleepy)
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/small/bodygrep.pl (added) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/small/funcgrep.pl (added) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/small/funcgrep.pl
@@ -0,0 +1,70 @@
 2+#!/usr/bin/perl
 3+use strict;
 4+use Data::Dumper;
 5+# simple variant on grep, reports class and function names that match.
 6+
 7+
 8+my $search_term=shift;
 9+
 10+my $global=0; # state variable: are we inside a (multiline?) php 'global' statement
 11+my $statement="";
 12+my $block_num=0; # the next number we shall assign to a block
 13+my @block_stack=0; # your actual current block number is $block_stack[0] (ie, peek the stack)
 14+my @function_stack;
 15+my @class_stack;
 16+my %globals;
 17+my $line=0;
 18+my $pretty_newline=0;
 19+while(<>) {
 20+
 21+ $line++;
 22+ # This makes some evil assumptions, but we're just
 23+ # trying to _cut down_ on the number of errors, we don't
 24+ # eliminate them entirely, since we're just running this
 25+ # script once, after all
 26+ if (/\{/) { # Block start
 27+ $block_num++;
 28+ unshift(@block_stack, $block_num);
 29+ if (/class/) {
 30+ unshift (@class_stack, [$block_num,"$line: $_",1]); # [block num, match, flag already shown]
 31+ }
 32+ if (/function/) {
 33+ unshift (@function_stack,[$block_num,"$line: $_",1]);
 34+ }
 35+ $pretty_newline=0;
 36+ }
 37+
 38+ if (/\}/) { #Block end
 39+ my $end=shift(@block_stack);
 40+ if ($end==$function_stack[0][0]) {
 41+ shift (@function_stack);
 42+ print "\n" if $pretty_newline;
 43+ $pretty_newline=0;
 44+ }
 45+ if ($end==$class_stack[0][0]) {
 46+ shift (@class_stack);
 47+ print "\n" if $pretty_newline;
 48+ $pretty_newline=0;
 49+ }
 50+ }
 51+
 52+ if (/$search_term/) {
 53+ my $function=$function_stack[0][1]; #1 : line string. (0 is used for identifying the correct block)
 54+ my $class=$class_stack[0][1];
 55+ if ($class_stack[0][2]) { #2 already shown?
 56+ print "$class";
 57+ $class_stack[0][2]=0;
 58+ }
 59+ if ($function_stack[0][2]) {
 60+ print " $function";
 61+ $function_stack[0][2]=0;
 62+ }
 63+ my $match;
 64+ $match="$line: $_";
 65+ if ($match ne $function && $match ne $class) { # prevent reporting matching function or class names twice
 66+ print " $match";
 67+ }
 68+ $pretty_newline=1;
 69+ }
 70+}
 71+
Property changes on: trunk/extensions/Wikidata/OmegaWiki/small/funcgrep.pl
___________________________________________________________________
Added: svn:executable
172 + *
Index: trunk/extensions/Wikidata/OmegaWiki/small/bodygrep.pl
@@ -0,0 +1,70 @@
 2+#!/usr/bin/perl
 3+use strict;
 4+use Data::Dumper;
 5+# func_grep that returns entire function bodies.
 6+
 7+
 8+my $search_term=shift;
 9+
 10+my $function=0; # state variable: are we inside a function?
 11+my $statement="";
 12+my $block_num=0; # the next number we shall assign to a block
 13+my @block_stack=0; # your actual current block number is $block_stack[0] (ie, peek the stack)
 14+my @function_stack;
 15+my @class_stack;
 16+my %globals;
 17+my $pretty_newline=0;
 18+my $body="";
 19+my $line=0;
 20+while(<>) {
 21+
 22+ $line++;
 23+ # This makes some evil assumptions, but we're just
 24+ # trying to _cut down_ on the number of errors, we don't
 25+ # eliminate them entirely, since we're just running this
 26+ # script once, after all
 27+ if (/\{/) { # Block start
 28+ $block_num++;
 29+ unshift(@block_stack, $block_num);
 30+ if (/class/) {
 31+ unshift (@class_stack, [$block_num,"$line: $_",1]); # [block num, match, flag already shown]
 32+ }
 33+ if (/function/ && /$search_term/) {
 34+ unshift (@function_stack,[$block_num,$line,1]);
 35+ $function=1;
 36+ }
 37+ $pretty_newline=0;
 38+ }
 39+
 40+ $body.=$_ if $function;
 41+
 42+ if (/\}/) { #Block end
 43+ my $end=shift(@block_stack);
 44+ if ($end==$function_stack[0][0]) {
 45+ my $fn_data=shift (@function_stack);
 46+ my $fn_line=@$fn_data[1];
 47+ print "\n" if $pretty_newline;
 48+ $pretty_newline=0;
 49+ if ($function) {
 50+ my $class=$class_stack[0][1];
 51+ if ($class_stack[0][2]) { #2 already shown?
 52+ print "$class";
 53+ $class_stack[0][2]=0;
 54+ }
 55+ print "$fn_line:$body";
 56+ $body="";
 57+ $function=0;
 58+ }
 59+
 60+ $pretty_newline=1;
 61+ }
 62+
 63+ if ($end==$class_stack[0][0]) {
 64+ shift (@class_stack);
 65+ print "\n" if $pretty_newline;
 66+ $pretty_newline=0;
 67+ }
 68+ }
 69+
 70+}
 71+
Property changes on: trunk/extensions/Wikidata/OmegaWiki/small/bodygrep.pl
___________________________________________________________________
Added: svn:executable
172 + *

Status & tagging log