#!/opt/bin/perl # this script walks '.' recursively and will find all archetypes # that can be found and will look for face and state info in them # and return a json hash to stdout with the following key/value format: # # "":"" # # see also json_conv_old_faces for instructions on how to convert the facenames # use strict; use File::Find; *name = *File::Find::name; *dir = *File::Find::dir; my $first = 1; # marks the first key/value (don't print too many ','s) sub getarch { my ($file, $lines, $outarchs) = @_; my $inarch = 0; my $at_end = 0; my $archlines = []; do { my $line = shift @$lines; if ($line =~ m/^arch\s*(\S+)\s*$/) { if ($inarch) { unshift @$lines, $line; getarch ($file, $lines, $outarchs); } else { $inarch = 1; push @$archlines, $line; } } elsif ($line =~ m/^end\s*$/) { push @$archlines, $line; push @$outarchs, $archlines; $archlines = []; $at_end = 1; } else { push @$archlines, $line if $inarch; } } while (not ($at_end) && @$lines); if ($inarch and not $at_end) { die "mismatched archetype in $file!"; } } sub wanted { my $file = $_; -f $file or return; next if $file =~ /\.pst$/; open my $fh, "<$file" or return; my $map = do { local $/; <$fh> }; my $found_magic_ear; my $found_npc; my @lines = split /\r?\n/, $map; my $archs = []; getarch ($file, \@lines, $archs) while @lines; for my $archlines (@$archs) { my $arch; my $uuid; my $face; my $state; for (@$archlines) { if (/^arch\s*(\S+)\s*$/) { $arch = $1; } if (/^state\s*(\S+)\s*$/) { $state = $1; } if (/^uuid\s*(\S+)\s*$/) { $uuid = $1; } if (/^face\s*(\S+)\s*$/) { $face = $1; } } next if $arch eq 'map'; if ($uuid && $face) { $state *= 1; print "," unless $first; $first = 0; print "\n\"$uuid$state\":\"$face\""; } } } print "{"; find { no_chdir => 1, wanted => \&wanted }, "."; print "\n}\n";