#!/usr/bin/perl # Script by David B. Nagle # Version 0.2 # http://randomfrequency.net/misc-code/scrape-php-globals/ # Usage information $usage = "Usage: $0 filename [columns]\n"; $usage = < 1) ? $ARGV[1] : 79; # Get file contents open(QDIG, $file); @lines = ; close(QDIG); # Convert file to a single string $file = join('', @lines); @lines = undef; # Remove /* ... */ $file =~ s/\057\052.*?\052\057//sg; # Remove // ... $file =~ s/\/\/.*?$//mg; # Find all global statements @globals = ($file =~ m/global .*?;/sg); foreach $g (@globals) { # Get rid of the non-variable parts $g =~ s/^global //s; $g =~ s/;$//s; # Convert all series of space characters to single spaces $g =~ s/\s+/ /sg; # Extract all variables @temp = split/, /, $g; push @vars, @temp; } # Figure out minimum length required for output line $minlen = length("global"); # Populate a hash with all the variable names foreach $v (@vars) { $hash{$v} = 1; # Add 1 for the comma/semicolon $minlen = length($v)+1 if(length($v)+1 > $minlen); } # Coerce cols up to minlen if necessary $cols = $minlen if($cols < $minlen && $cols >= 0); # Create a new global command with all the variables $disp = join(', ', sort keys %hash); $disp = "global $disp;"; if($cols >= 0) { # Print the command, restrained by column width $comma = $cols-1; while($disp) { $disp =~ m"(^.{1,$cols}$|^.{1,$comma},)"; $line = $1; substr($disp, 0, length($line)) = ''; $disp =~ s/^ //; print "$line\n"; } } else { print "$disp\n"; }