#!/usr/bin/perl

$index = "Index";
$msg = ".message";

if ( open ( F, "$msg" ) ) {
	while (<F>) { print; }
	close F;
}

open ( F, "$index" ) || system("/bin/ls -1");

$_ = <F>;	#  
$_ = <F>;

while ( <F> ) {
ST:
	#    ^Name Size|<dir> Date Comments
	if ( /^(\S+)\s+(\S+)\s+(\S+)\s+(.*)/ ) {
		#  
		if ( $2 eq "<dir>" ) {
			while ( <F> ) {
				if ( ! /^\s+(.*)/ ) {
					goto ST;
				}
			}
		}
		#   ^\s+Comments
		else {
			print "$1 $4";
			while ( <F> ) {
				if ( /^\s+(.*)/ ) {
					print " $1";
				} else {
					print "\n";
					goto ST;
				}
			}
		}
	}
	#     
	# ^Name$
	#   Size|<dir> Date Comments
	if ( /^(\S+)$/ ) {
		print "$1 ";
		$_ = <F>;
		if ( /^\s*(\S+)\s+(\S+)\s+(.*)/ ) {
			#  
			if ( $1 eq "<dir>" ) {
				while ( <F> ) {
					if ( ! /^\s+(.*)/ ) {
						goto ST;
					}
				}
			}
			#   ^\s+Comments
			else {
				print "$3";
				while ( <F> ) {
					if ( /^\s+(.*)/ ) {
						print " $1";
					} else {
						print "\n";
						goto ST;
					}
				}
			}
		}
	}
}

close F;

