#!/usr/local/bin/perl
# uumerge for mew
#   modified by kazu@is.aist-nara.ac.jp 06/17/94
require 'getopt.pl';
&Getopt('d:');

if ($opt_d) {
	chdir($opt_d) || die "$opt_d: $!\n";
}

while (<>) {
        $sawbegin++, last if ($mode,$file) = /^begin\s*(\d*)\s*(\S*)/;
}
die "uumerge: missing begin\n" unless $sawbegin;
open(OUT,"> $file") if $file ne "";
while (<>) {
        $sawend++, last if /^end/;
        s/[a-z]+$//; # handle stupid trailing lowercase letters
        next if /[a-z]/;
        next unless int((((ord() - 32) & 077) + 2) / 3) == int(length() / 4);
        print OUT unpack("u", $_);
}
close(OUT);
chmod oct($mode), $file;
die "uumerge: missing end\n" unless $sawend;

print $file, "\n";
exit 0;
