1#!/usr/bin/env perl 2 3use warnings; 4 5use strict; 6 7unless (@ARGV == 1) 8{ 9 die("usage: grep-mon.pl <pattern>\n"); 10} 11 12my $data_file; 13 14if (-e "mon-data.h") 15{ 16 $data_file = "mon-data.h"; 17} 18elsif (-e "../mon-data.h") 19{ 20 $data_file = "../mon-data.h"; 21} 22else 23{ 24 die("Can't find 'mon-data.h'\n"); 25} 26 27unless (open(FILE, "<$data_file")) 28{ 29 die("Couldn't open '$data_file' for reading: $!\n"); 30} 31 32my $line; 33 34while (<FILE>) 35{ 36 $line = $_; 37 last if ($line =~ /static monsterentry mondata/); 38} 39 40unless ($line =~ /static monsterentry mondata/) 41{ 42 die("Couldn't find mondata array.\n"); 43} 44 45# Slurp in the rest of it. 46undef($/); 47my $content = <FILE>; 48close(FILE); 49 50my @mons = split(/^},/m, $content); 51 52my @matches = grep(/$ARGV[0]/s, @mons); 53 54print join("},", @matches) . "\n"; 55