"Fossies" - the Fresh Open Source Software Archive

Member "links-1.03/mailcap.pl" (31 Dec 2000, 1215 Bytes) of archive /linux/www/links-1.03.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/usr/bin/perl -w
    2 # mailcap to links.cfg converter (aka quick hack)
    3 # version 1.00 by <grin@tolna.net>
    4 # Released under GPLv2 or later
    5 #
    6 # Usage: mailcap-convert.pl /etc/mailcap >> ~/.links/links.cfg
    7 #
    8 
    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;
   16     
   17     my @out = ( "External association", $fields[0], $fields[1] );
   18     
   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]);
   28         }
   29     }
   30     &new_assoc( \@out );
   31 }
   32 print "association \"-=END DEBIAN CONVERT=-\" \"\" \"\" 23 1\n";
   33 
   34 sub new_assoc {
   35     my $aref = shift;
   36     print "association ";
   37     for my $i (0..2) {
   38         print "\"$aref->[$i]\" ";
   39     }
   40     print "23 1\n";
   41 }
   42 
   43 sub new_ext {
   44     print "extension";
   45     for my $i (0..1) {
   46         print " \"$_[$i]\"";
   47     }
   48     print "\n";
   49 }
   50 
   51