#!/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;