Sophie

Sophie

distrib > Mandriva > 2006.0 > i586 > media > main-src > by-pkgid > a6bc312ce50b5c8d0c51736e58ac32bc > files > 70

kdebase-3.4.2-55mdk.src.rpm

#!/usr/bin/perl -w
use strict;

# This scripts saves the kde mimetype associations that the
# user set up in ~/.kde/share/applnk into a file
# (/tmp/update-menu-<uid>-kdemimetypes)
# This is used by restorekdemimetypes.sh to restore the
# associations after update-menu has run.

# 06/09/2000: Initial Version. David Faure <david@mandrakesoft.com>
# 05/04/2001: Ported to perl, path on the command line (DF)

if ( $#ARGV != 0 ) {
  print STDERR "Usage : savekdemimetypes.pl ....../share/applnk (either user or global)\n";
  exit 1;
}

## This is the perl equivalent of:
##  find . -type f -exec egrep -H 'ServiceTypes|MimeType' {} \;> /tmp/update-menu-$UID-kdemimetypes

my $basepath=$ARGV[0];
open (FILEDEST, ">$ENV{HOME}/tmp/update-menu-$<-kdemimetypes") or die;

use File::Find;
sub process_file {
  if ( -f )
    {
      my $file = $File::Find::name;
      my $data = "";
      #print STDERR "Processing $file\n";
      
      open (FILEIN, "<$file") or die;
      seek(FILEIN, 0, 2);
      my $fsize = tell(FILEIN);
      seek(FILEIN, 0, 0);
      read FILEIN, $data, $fsize;
      close(FILEIN);
      # Copy the MimeType and ServiceTypes line from that file
      print FILEDEST $file. "::$1\n" if ($data =~ /\n(ServiceTypes[ \t]*=[ \t]*[^\n]*)\n/);
      print FILEDEST $file. "::$1\n" if ($data =~ /\n(MimeType[ \t]*=[ \t]*[^\n]*)\n/);
    }
}

find(\&process_file, $ARGV[0]);

close FILEDEST;