iconv: Bail out of the loop when an illegal sequence of bytes occurs.
[elinks/elinks-j605.git] / contrib / conv / mailcap.pl
blobfc05d651708dd68ba24506eb3167f2e6e18c5711
1 #!/usr/bin/perl -w
2 # mailcap to elinks.conf converter (aka quick hack)
3 # version 1.00 by <grin@tolna.net>
4 # Released under GPLv2 or later
6 # Usage: mailcap-convert.pl /etc/mailcap >> ~/.elinks/elinks.conf
9 print "association \"-=BEGIN DEBIAN CONVERT=-\" \"\" \"\" 23 1\n";
10 while( <> ) {
11 chomp;
12 next if /^\s*(#|$)/;
13 @fields = split /;\s*/;
14 # change %s to % in the command
15 $fields[1] =~ s/%s/%/g;
17 my @out = ( "External association", $fields[0], $fields[1] );
19 for( my $i=2; $i<=$#fields; $i++ ) {
20 if( $fields[$i] =~ m/description="?([^"]+)"?/ ) {
21 # description
22 $out[0] = $1;
23 } elsif( $fields[$i] =~ m/nametemplate=(.+)/ ) {
24 # extension for the mime type
25 my $ext = $1;
26 $ext =~ s/%s\.(.+)$/$1/;
27 &new_ext($ext,$fields[0]);
30 &new_assoc( \@out );
32 print "association \"-=END DEBIAN CONVERT=-\" \"\" \"\" 23 1\n";
34 sub new_assoc {
35 my $aref = shift;
36 print "association ";
37 for my $i (0..2) {
38 print "\"$aref->[$i]\" ";
40 print "23 1\n";
43 sub new_ext {
44 print "extension";
45 for my $i (0..1) {
46 print " \"$_[$i]\"";
48 print "\n";