On Thu, May 05, 2011 at 02:08:35AM +0200, Adam Borowski wrote: > On Wed, May 04, 2011 at 10:40:22AM -0700, Jeff Johnson wrote: > > It sounds o.k. to me, but my perl knowledge is not that great. Is > > there a volunteer to start the perl script? If someone can read the > > enum.h file into data structures, I can output the correct stuff. > > If not, I can muddle through it. :) > > Is this good enough? > > ===================================================================== > #!/usr/bin/perl -w > use Cwd; > > my $src = Cwd::realpath(__FILE__ . "/../../enum.h"); > -r $src or die "Can't find enum.h\n"; > open IN, "cpp \"$src\"|" or die "Can't run cpp\n"; > { undef local $/; $_ = <IN>; } > /enum monster_type\s*{\s*((?:\w+\s*(?:\s*=\s*\w+)?,\s*)+)}/ > or die "Can't find enum monster_type in enum.h\n"; > print "$_ => \"\L$_\"\n" for ($1 =~ /(\w+)\s*(?:\s*=\s*\w+)?,/g) > =====================================================================
Sigh. How about we write perl as though it was written sometime in the past decade? ===================================================================== #!/usr/bin/env perl use strict; use warnings; use Cwd; use File::Spec; my $filename = File::Spec->catfile(__FILE__, '..', '..', 'enum.h'); $filename = Cwd::realpath($filename); die "Can't find enum.h" unless -r $filename; my $source = do { open STDIN, '<', $filename or die "Can't reopen stdin: $!"; open my $fh, '-|', 'cpp' or die "Can't run cpp: $!"; local $/; <$fh> }; die "Can't find enum monster_type in enum.h" unless $source =~ /enum monster_type/; $source =~ s/.*enum monster_type.*?\n//s; for my $line (split /\n/, $source) { last if $line =~ /}/; my ($enum) = $line =~ /(\w+).*?,/; next unless $enum; my $lc_enum = lc($enum); print qq{$enum => "$lc_enum"\n}; } ===================================================================== Perl doesn't have to be unreadable, you know d: -doy ------------------------------------------------------------------------------ WhatsUp Gold - Download Free Network Management Software The most intuitive, comprehensive, and cost-effective network management toolset available today. Delivers lowest initial acquisition cost and overall TCO of any competing solution. http://p.sf.net/sfu/whatsupgold-sd _______________________________________________ Crawl-ref-discuss mailing list Crawl-ref-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/crawl-ref-discuss