#!/bin/sh
# -*- perl -*-
# This code allows us to start perl from our path or an environment variable
# rather than hardcoding a path into the #! line.  It works from sh or csh.
(exit $?0) && eval 'exec ${QPERLQ-perl} -x $0 ${1+"$@"}'
if (! $?QPERLQ) setenv QPERLQ perl
exec $QPERLQ -x $0 $argv:q

#!/usr/local/bin/perl -w
#
# $Id: longname-to-dos,v 1.1 1997/10/13 00:40:29 ejb Exp $
# $Source: /home/ejb/scripts/RCS/longname-to-dos,v $
# $Author: ejb $
#

require 5.002;
use strict;

my $whoami = ($0 =~ m,([^/\\]*)$,) ? $1 : $0;
#my $dirname = ($0 =~ m,(.*)[/\\][^/\\]+$,) ? $1 : ".";

my %files = ();
while (<>)
{
    chop;
    my $old = $_;
    my $dir = "";
    my $lastcomp = $_;
    if (m,^(.*)/([^/]+)$,)
    {
	$dir = $1;
	$lastcomp = $2;
    }
    my $root = $lastcomp;
    my $ext = "";
    if ($lastcomp =~ m/\./)
    {
	$root = $`;
	$ext = $';
    }
    if (length($root) > 8)
    {
	$root = substr($root, 0, 8);
    }
    if (length($ext) > 3)
    {
	$ext = substr($ext, 0, 3);
    }
    my $new = $root;
    ($new .= ".$ext") if $ext ne "";
    if ($dir ne "")
    {
	$new = "$dir/$new";
    }
    if (exists $files{$new})
    {
	warn "=====> $new is duplicated\n";
    }
    $files{$new} = 1;
    if ($new ne $old)
    {
	print "mv $_ $new\n";
    }
}
