#!/usr/bin/perl # 9/17/2004 - Erik Jacobson - erik@underhanded.org use warnings; use strict; use File::Find; # Change these if you want my $recurse = 1; # Recurse into subdirectories? my $followsymlinks = 0; # Follow Symlinks? Wouldn't recommend this die "Please provide one or more pathnames as arguments!\n" unless $#ARGV >= 0; my %options = ( wanted => \&wanted, follow => $followsymlinks, dangling_symlinks => 0, no_chdir => 1, ); my %styles; if($recurse) { find(\%options, @ARGV); } else { foreach my $path (@ARGV) { if(opendir(DIR, $path)) { foreach my $file (readdir(DIR)) { &wanted($file); } closedir(DIR); } else { &wanted($path); } } } open(FILE, ">/home/azhrarn/cssout.txt") or die "Unable to open output file: $!\n"; my %globclasses; foreach my $file (sort keys %styles) { print FILE "$file -\n"; if(exists $styles{$file}{class}) { print FILE "-CLASSES:\n"; foreach my $class (sort keys %{$styles{$file}{class}}) { $globclasses{class}{$class}++; print FILE "\t$class\n"; } } if(exists $styles{$file}{id}) { print FILE "-IDS:\n"; foreach my $id (sort keys %{$styles{$file}{id}}) { $globclasses{id}{$id}++; print FILE "\t$id\n"; } } print FILE "\n\n"; } print FILE "CLASS LISTING -\n"; print FILE "-CLASSES:\n"; foreach my $class (sort keys %{$globclasses{class}}) { print FILE "\t$class\n"; } print FILE "-IDS:\n"; foreach my $id (sort keys %{$globclasses{id}}) { print FILE "\t$id\n"; } close FILE; sub wanted { my $file = (defined $_[0]) ? $_[0] : (-l $File::Find::name) ? $File::Find::fullname : $File::Find::name; return unless defined $file; if(-f $file && $file =~ /(?:htm|html|php|inc)$/i) { open(FILE, "$file") or die "Unable to open $file: $!\n"; local $/; my $buffer = ; close FILE; while($buffer =~ /\b(class|id)\s*=\s*(\\?["'])(.+?)\2/img) { $styles{$file}{lc($1)}{$3}++; } } }