vfmg (DEVEL): vfmg - unified Name and GenericName decoding - put g...

sparky sparky at pld-linux.org
Sat Dec 31 19:27:48 CET 2005


Author: sparky                       Date: Sat Dec 31 18:27:48 2005 GMT
Module: vfmg                          Tag: DEVEL
---- Log message:
- unified Name and GenericName decoding
- put generic name in ASCII mode

---- Files affected:
vfmg:
   vfmg (1.73.2.47 -> 1.73.2.48) 

---- Diffs:

================================================================
Index: vfmg/vfmg
diff -u vfmg/vfmg:1.73.2.47 vfmg/vfmg:1.73.2.48
--- vfmg/vfmg:1.73.2.47	Sat Dec 31 19:16:04 2005
+++ vfmg/vfmg	Sat Dec 31 19:27:43 2005
@@ -327,10 +327,8 @@
 	return unless -f && /^[^.].*\.desktop$/;
 	my $file = $_;
 
-	open F_IN, "$file" or warn "$File::Find::name: $!\n" and return;
+	open F_IN, $file or warn "$File::Find::name: $!\n" and return;
 	my %tags = (
-		Name		=> '',
-		GenericName	=> '',
 		Icon		=> '',
 		Categories	=> '',
 		Type		=> '',
@@ -357,15 +355,9 @@
 		}
 		return unless $found;
 	}
-	$tags{_name} = findfirstlang( grep /^Name/, keys %tags);
-	$tags{name} = $tags{ $tags{_name} };
-	$tags{_genericname} = findfirstlang( grep /^GenericName/, keys %tags);
-	$tags{genericname} = $tags{ $tags{_genericname} };
 	  
-	$tags{enc}  = exists $tags{Encoding} ? $tags{Encoding} : 'iso-8859-1';
 	$tags{term} =
 	  ($tags{Terminal} && $tags{Terminal} =~ /^(?:1|true)$/i) ? 1 : 0;
-
 	return if $tags{term} and not $opt{xterm};
 
 	my($bin) = ($tags{Exec} =~ /(\S+)/);    #v---------v
@@ -380,7 +372,7 @@
 		}
 		return unless $exists;
 	}
-	if ($tags{term}) {
+	if ( $tags{term} ) {
 		$bin =~ s|.*/||;
 		$_ = $opt{xterm};
 		s/%1/$bin/;
@@ -402,87 +394,67 @@
 		}
 		$tags{Icon} = '' unless $exists;
 	}
-	my $utfname;
-	if (length $tags{name}) {
-		if ($tags{enc} eq 'Legacy-Mixed') {
+	
+	$tags{Encoding} = exists $tags{Encoding} ? $tags{Encoding} : 'iso-8859-1';
+	
+	my @to_decode = qw(Name);
+	push @to_decode, "GenericName"
+		if $o_output eq "DR17" or $o_output eq "ASCII";
+	foreach my $tag_name (@to_decode) {
+		my @all = (grep /^$tag_name/, keys %tags);
+		next if ($#all < 0);
+		my $first = findfirstlang(@all);
+		my $enc = $tags{Encoding};
+	
+		if ($enc eq 'Legacy-Mixed') {
 			warn "$File::Find::name: Legacy-Mixed encoding is depreciated.\n";
 
 			# this code is untested
 			#    --radek
-			($tags{lang}) = ($tags{_name} =~ /^Name\[([^\]]+)/);
-			if ($tags{lang} !~ /\./) {
+			my ($lang) = ($first =~ /^$tag_name\[([^\]]+)/);
+			if ($lang !~ /\./) {
 				warn "$File::Find::name: cannot get encoding name for"
-				  . " `$tags{lang}'. Assuming iso-8859-1\n";
-				$tags{enc} = "iso-8859-1";
+				  . " `$lang'. Assuming iso-8859-1\n";
+				$enc = "iso-8859-1";
 			} else {
 				require POSIX;
 				my $old_locale = setlocale(POSIX::LC_ALL());
 				eval {
-					setlocale(POSIX::LC_ALL(), $tags{lang});
+					setlocale(POSIX::LC_ALL(), $lang);
 					require I18N::Langinfo;
-					$tags{enc} =
-					  I18N::Langinfo::langinfo(I18N::Langinfo::CODESET());
+					$enc = I18N::Langinfo::langinfo(I18N::Langinfo::CODESET());
 				};
 				warn "something went wrong: $@" if $@;
 				setlocale(POSIX::LC_ALL(), $old_locale);
 			}
 		}
-		$utfname = decode($tags{enc}, $tags{name});
-		unless ($utfname) {
-			warn "$File::Find::name: wrong encoding!\n";
-			$utfname = $tags{name};
+		$tags{$tag_name} = decode($enc, $tags{$first});
+		unless ($tags{$tag_name}) {
+			warn "$File::Find::name: $first: wrong encoding!\n";
+			$tags{$tag_name} = $tags{$first};
 		}
 	}
-	else {
-		($utfname = $file) =~ s/\.desktop$//;
-		warn "$File::Find::name: missing Name tag! using $utfname\n";
-	}
-	my $genname = "";
-	if ($o_output eq "DR17" and length $tags{genericname}) {
-		if ($tags{enc} eq 'Legacy-Mixed') {
-			warn "$File::Find::name: Legacy-Mixed encoding is depreciated.\n";
-
-			# this code is untested
-			#    --radek
-			($tags{lang}) = ($tags{_genericname} =~ /^GenericName\[([^\]]+)/);
-			if ($tags{lang} !~ /\./) {
-				warn "$File::Find::name: cannot get encoding name for"
-				  . " `$tags{lang}'. Assuming iso-8859-1\n";
-				$tags{enc} = "iso-8859-1";
-			} else {
-				require POSIX;
-				my $old_locale = setlocale(POSIX::LC_ALL());
-				eval {
-					setlocale(POSIX::LC_ALL(), $tags{lang});
-					require I18N::Langinfo;
-					$tags{enc} =
-					  I18N::Langinfo::langinfo(I18N::Langinfo::CODESET());
-				};
-				warn "something went wrong: $@" if $@;
-				setlocale(POSIX::LC_ALL(), $old_locale);
-			}
-		}
-		$genname = decode($tags{enc}, $tags{genericname});
-		unless ($genname) {
-			warn "$File::Find::name: wrong encoding!\n";
-			$genname = $tags{name};
-		}
-		
+	unless ($tags{Name}) {
+		( $tags{Name} = $file ) =~ s/\.desktop$//;
+		warn "$File::Find::name: missing Name tag! using $tags{Name}\n";
+	}
+	
+	if ( $tags{Exec} =~ /%\S/ ) {
+		$tags{Exec} =~ s/([^%])%v/$1/g;
+		$tags{Exec} =~ s/([^%])%k/$1$file/g;
+		$tags{Exec} =~ s/([^%])%c/$1$tags{Name}/g;
+		my $iicon = '';
+		$iicon = "--icon $tags{Icon}" if $tags{Icon};
+		$tags{Exec} =~ s/([^%])%i/$1$iicon/g;
+		$tags{Exec} =~ s/%(?i:[fudn])//g;
+		warn "Unknown Exec parameter variable: $1 "
+			."in $File::Find::name, removing\n"
+		  if ($tags{Exec} =~ s/(%[^%\s])// and $o_verbose);
+		$tags{Exec} =~ s/%%/%/g;
 	}
-
-	$tags{Exec} =~ s/([^%])%v/$1/g;
-	$tags{Exec} =~ s/([^%])%k/$1$file/g;
-	$tags{Exec} =~ s/([^%])%c/$1$utfname/g;
-	my $iicon = '';
-	$iicon = "--icon $tags{Icon}" if $tags{Icon};
-	$tags{Exec} =~ s/([^%])%i/$1$iicon/g;
-	$tags{Exec} =~ s/%(?i:[fudn])//g;
-	warn "Unknown Exec parameter variable: $1 in $File::Find::name, removing\n"
-	  if ($tags{Exec} =~ s/(%[^%\s])// and $o_verbose);
-	$tags{Exec} =~ s/%%/%/g;
 	
 	$file =~ s/\.desktop$//;
-	push @desktop, [$file, $utfname, $tags{Icon}, $tags{Exec}, $genname, $tags{term}, $bin];
+	push @desktop, [$file, $tags{Name}, $tags{Icon}, $tags{Exec}, $tags{GenericName}, $tags{term}, $bin];
 	
 	$apps[$#desktop]{$_} = 1    # two apps can have same names now:)
 	  foreach grep length, split /;+/, $tags{Categories};
@@ -908,25 +880,29 @@
 		my $d = $desktop[$entry];
 		$num++;
 		if($menu[$no]{$entry} < 0) {
-			push @apps, $$d[LOCALENAME];
+			push @apps, $d;
 		} else {
 			my $step = " \033[${cnum}m\033(0\017x\033(B\033[0m ";
 			if ($num >= $all and ( $#apps < 0 )) {
 				$step = "   ";
-				print "$level \033[${cnum}m\033(0mq\033(B\033[${cnext}m\033[1m[$$d[LOCALENAME]]\033[0m\n";
+				print "$level \033[${cnum}m\033(0mq\033(B\033[${cnext}m\033[1m[$$d[LOCALENAME]]";
 			} else {
-				print "$level \033[${cnum}m\033(0tq\033(B\033[${cnext}m\033[1m[$$d[LOCALENAME]]\033[0m\n";
+				print "$level \033[${cnum}m\033(0tq\033(B\033[${cnext}m\033[1m[$$d[LOCALENAME]]";
 			}
+			print " ($$d[GENNAME])" if $$d[GENNAME];
+			print "\033[0m\n";
 			ASCII($menu[$no]{$entry},$level.$step, $cnext);
 		}
 	}
 	$num = 0;
-	foreach my $app (@apps) {
+	foreach my $d (@apps) {
 		if ($num >= $#apps) {
-			print "$level \033[${cnum}m\033(0\017mq\033(B\033[${cnext}m$app\033[0m\n";
+			print "$level \033[${cnum}m\033(0\017mq\033(B\033[${cnext}m$$d[LOCALENAME]";
 		} else {
-			print "$level \033[${cnum}m\033(0\017tq\033(B\033[${cnext}m$app\033[0m\n";
+			print "$level \033[${cnum}m\033(0\017tq\033(B\033[${cnext}m$$d[LOCALENAME]";
 		}
+		print " ($$d[GENNAME])" if $$d[GENNAME];
+		print "\033[0m\n";
 		$num++;
 	}
 } # }}}
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/vfmg/vfmg?r1=1.73.2.47&r2=1.73.2.48&f=u



More information about the pld-cvs-commit mailing list