#!/usr/bin/env perl use strict; use warnings; sub usage { return "Usage: perl arch2xml \n\n" ." arches the root directory of the arch files you want to put into XML\n"; } die usage unless @ARGV; my $root = $ARGV[0]; opendir TMP, $root or die "$root: $!\n"; closedir TMP; #-------------------------------------------------- # use File::Find; # # my @arches = (); # # sub recurse { # my ($top_level_dir) = @_; # finddepth(\&isarc, $top_level_dir); # } # # sub isarc { # if (-f && /\.arc$/) { # push @arches, $File::Find::name, chomp $/; # } # } #-------------------------------------------------- sub arch2xml { # recurse '.'; my ($root) = @_; my @arches = split /\n/, `find $root -type f -name \*.arc`; my $xml = ""; for my $file (@arches) { my @arch = do { open my $fh, "<$file" or die "$file: $!"; <$fh> }; my $msg = ""; my $ismsg = 0; my $anim = ""; my $isanim = 0; for my $line (@arch) { chomp $line; next if ($line =~ /^#/ or $line =~ /^(\s+)?$/); if ($line eq "endmsg") { $xml .= "\t\t$msg\n"; $msg = ""; $ismsg = 0; } if ($ismsg) { $msg .= "$line "; next; } if ($line eq "mina") { $xml .= "\t\t\n\t\t$anim\n"; $anim = ""; $isanim = 0; } if ($isanim) { $anim .= "\t$line\n\t\t"; next; } if ($line =~ /[Oo]bject/) { $line =~ s/^[Oo]bject //; $xml .= "\t\n"; $xml .= "\t\t$line\n"; } elsif ($line =~ /^end$/) { $xml .= "\t\n"; } elsif ($line eq "msg") { $ismsg = 1; } elsif ($line eq "anim") { $isanim = 1; } elsif ($line eq "More") { # handle "More" } elsif ($line eq "mina") { # handled above } elsif ($line eq "endmsg") { # handled above } else { my ($tag, $data) = split / /, $line, 2; $xml .= "\t\t<$tag>$data\n"; } } } return $xml; } print "\n"; print "\n"; print "\n"; print arch2xml $root; print "\n";