Comment 8 for bug 519126

Revision history for this message
Dan MacNeil (omacneil) wrote :

#!/usr/bin/perl

use strict;
use warnings;

{ # main

    # see man perlvar for @ARGV
    my $filename = $ARGV[0]
      or die "need to supply a filename argument\n";
    my $type = get_type_from($filename);
    my %file = make_type_table();

    if ( !$file{$type} ) {
        print "can't handle file type: \n\t'$type' \nin file: \n\t'$filename'\n";
    }
    else {
       print "ok\n";
    }

}

sub get_type_from {
    my $filename = shift;
    my $type = `file -b $filename`;
    chomp $type;
    $type =~ s/^\s+//;

    return $type;
}

sub make_type_table {
    my %f = (
        'ASCII English text' => {
            start => '#',
            stop => '',
        },
        'ASCII HTML document text' => {
            start => '<!-- ',
            stop => '-->',
        },
    );

    return %f;
}

# make_success_output($filename,$type,
# $file{$type}{start},
# $file{$type}{stop});

sub make_success_output {
my ($filename,$type,$start,$end)=@_;
my $result = << "HERE_DOC";
File: '$filename'";
print "Type: '$type'";
   comment line starts with: is '$start';
   comment line ends with: is '$end';
HERE_DOC

}