vfmg (DEVEL): vfmg - %desktop changed from hash to array - killed ...

sparky sparky at pld-linux.org
Thu Nov 10 14:26:14 CET 2005


Author: sparky                       Date: Thu Nov 10 13:26:08 2005 GMT
Module: vfmg                          Tag: DEVEL
---- Log message:
- %desktop changed from hash to array
- killed @happs array

---- Files affected:
vfmg:
   vfmg (1.73.2.36 -> 1.73.2.37) 

---- Diffs:

================================================================
Index: vfmg/vfmg
diff -u vfmg/vfmg:1.73.2.36 vfmg/vfmg:1.73.2.37
--- vfmg/vfmg:1.73.2.36	Mon Nov  7 02:05:17 2005
+++ vfmg/vfmg	Thu Nov 10 14:26:02 2005
@@ -294,8 +294,7 @@
 # what is $DESKTOP_FILE_PATH?
 
 my @apps;	# $apps{name}{category}=[icon,exec]
-my @happs;
-my %desktop;
+my @desktop;
 find(\&wanted, grep -d, map {"$_/applications"} @xdg_data_dirs);
 
 sub wanted { # {{{
@@ -410,13 +409,13 @@
 	warn "Unknown Exec parameter variable: $1 in $File::Find::name, removing\n"
 	  if ($tags{Exec} =~ s/(%[^%\s])// and $o_verbose);
 	$tags{Exec} =~ s/%%/%/g;
-	push @happs, $File::Find::name;
-
-	$apps[$#happs]{$_} = 1    # two apps can have same names now:)
+	
+	$file =~ s/\.desktop$//;
+	push @desktop, [$file, $utfname, $tags{Icon}, $tags{Exec}];
+	
+	$apps[$#desktop]{$_} = 1    # two apps can have same names now:)
 	  foreach grep length, split /;+/, $tags{Categories};
 
-	$file =~ s/\.desktop$//;
-	$desktop{$File::Find::name} = [$file, $utfname, $tags{Icon}, $tags{Exec}];
 } # }}}
 
 # read XDG menu specification
@@ -447,6 +446,7 @@
 
 my @menu;	# $menu[parent]{name}=[x=menu number,icon]
 		# $menu[parent]{name}=[-1=entry,icon,exec]
+my $desknum = $#desktop;
 
 # logic {{{
 sub cand { # {{{
@@ -457,7 +457,7 @@
 		if($tag eq 'Category') {
 			my $dir=getname();
 			if($firstrun) {
-				foreach $name(0..$#happs) {
+				foreach $name(0..$desknum) {
 					$iapps[$name]=$apps[$name] if exists $apps[$name]{$dir};
 				}
 				$firstrun=0;
@@ -501,7 +501,7 @@
 	while ( (my $tag = gettag()) ne '/Or') {
 		if($tag eq 'Category') {
 			my $dir=getname();
-			foreach $name(0..$#happs) {
+			foreach $name(0..$desknum) {
 				$iapps[$name]=1 if exists $apps[$name]{$dir};
 			}
 			gettag();	# must be </category> else GIGO and we don't care
@@ -567,8 +567,8 @@
 	while ( (my $tag = gettag()) ne "/Include" ) {
 		if($tag eq 'Category') {
 			my $dir=getname();
-			foreach my $name(0..$#happs) {
-				$menu[$mno]{$happs[$name]}=-1
+			foreach my $name(0..$desknum) {
+				$menu[$mno]{$name}=-1
 					if exists $apps[$name]{$dir};
 			}
 			gettag();	# must be </category> else GIGO and we don't care
@@ -586,7 +586,7 @@
 			foreach my $name(0..$#$tmpapps) {
 				next unless defined $tmpapps->[$name];
 				foreach my $dir (keys %{$apps[$name]}) {
-					$menu[$mno]{$happs[$name]}=-1;
+					$menu[$mno]{$name}=-1;
 				}
 			}
 			next;
@@ -599,15 +599,15 @@
 	}
 } # }}}
 
-sub menu($$);
-sub menu($$) { # {{{
-	my ($parent_name, $parent_number) = @_;
-	# just in case, will fail if more <menu>'s have no <name> tag
-	my $this_name = $parent_name . ":new";
+sub menu($);
+sub menu($) { # {{{
+	my ($parent_number) = @_;
 	my $name;
+	$#desktop++;
+	my $dirnum = $#desktop;
 	$#menu++;
 	my $mno = $#menu;
-	my $dirfile;
+	# $dirnum = $desknum + $mno;
 
 	while ( (my $tag = gettag()) ne "/Menu" ) {
 		if($tag eq 'Include') {
@@ -615,24 +615,16 @@
 			next;
 		}
 		if($tag eq 'Menu') {
-			menu($this_name, $mno);
+			menu($mno);
 			next;
 		}
 		if($tag eq 'Name') {
 			$name = getname();
-			$this_name = $parent_name .":". $name;
-			$menu[$parent_number]{$this_name} = $mno;
-			if ( defined $dirfile ) {
-				# $desktop created, but without name
-				my $old_name = $parent_name . ":new";
-				$desktop{$this_name}=$desktop{$old_name};
-				delete $desktop{$old_name . ":new"};
-			}
 			gettag();	# must be </name> else GIGO and we don't care
 			next;
 		}
 		if($tag eq 'Directory') {
-			$dirfile=getname();
+			my $dirfile = getname();
 			my $lang=0;
 			my $dname="";
 			my $icon="";
@@ -686,7 +678,7 @@
 					$utfname=$name;
 				}
 				$dirfile =~ s/\..*?$//;
-				$desktop{$this_name} = [$dirfile, $utfname, $icon];
+				$desktop[$dirnum] = [$dirfile, $utfname, $icon];
 			} else {
 				local $" = "\n- ";
 				warn "No readable $dirfile in:\n- @tmp\n";
@@ -723,14 +715,16 @@
 	}
 	
 	# if there was no <Directory>
-	$desktop{$this_name}=[$name,$name,""] unless defined $desktop{$this_name};
+	$desktop[$dirnum]=[$name,$name,""] unless defined $desktop[$dirnum];
+	
+	$menu[$parent_number]{$dirnum} = $mno;
 } # }}}
 
 $#menu++;
 while( (my $tag = gettag()) ne "Menu" ) {
 	warn "Omitted tag: $tag\n" if $o_tags;
 }
-menu("", 0);
+menu(0);
 
 warn "Omitted ending: $file\n" if(($file ne "")&& $o_end);
 # parse menu file }}}
@@ -819,9 +813,9 @@
 sub cmpdname {
 	use locale;
 	return 
-			encode($opt{encoding}, $desktop{$a}[1] )
+			encode($opt{encoding}, $desktop[$a][1] )
 		cmp
-			encode($opt{encoding}, $desktop{$b}[1] )
+			encode($opt{encoding}, $desktop[$b][1] )
 		;
 }
 
@@ -833,7 +827,7 @@
 	my $all = ($#tmp + 1) / 2;
 	my $num = 0;
 	foreach my $entry (sort cmpdname keys %{$menu[$no]}) {
-		my $d = $desktop{$entry};
+		my $d = $desktop[$entry];
 		$num++;
 		if($menu[$no]{$entry} < 0) {
 			push @apps, $$d[LOCALENAME];
@@ -865,7 +859,7 @@
 	my $apps = "";
 	my @edje = qw(edje_cc -id . -fd . icon.edc);
 	foreach my $entry (sort cmpdname keys %{$menu[$no]}) {
-		my $d = $desktop{$entry};
+		my $d = $desktop[$entry];
 		my $name = $$d[LOCALENAME];
 		print $tab.$name."..";
 		
@@ -913,7 +907,7 @@
 	my ($no, $level)=@_;
 	my $apps="";
 	foreach my $entry (sort cmpdname keys %{$menu[$no]}) {
-		my $d = $desktop{$entry};
+		my $d = $desktop[$entry];
 		( my $name = $$d[LOCALENAME] ) =~ s/\"/\\\"/g;
 		if($menu[$no]{$entry} < 0) {
 			( my $exec = $$d[EXEC] ) =~ s/\"/\\\"/g;
@@ -931,7 +925,7 @@
 	my ($no, $dir)=@_;
 	
 	foreach my $entry(keys %{$menu[$no]}) {
-		my $d = $desktop{$entry};
+		my $d = $desktop[$entry];
 		my $name = encode($opt{encoding},$$d[LOCALENAME]);
 		if($menu[$no]{$entry} < 0) {
 			$name=~s/\"/\\\"/g;
@@ -954,7 +948,7 @@
 	my ($no, $level)=@_;
 	my $apps="";
 	foreach my $entry (sort cmpdname keys %{$menu[$no]}) {
-		my $d = $desktop{$entry};
+		my $d = $desktop[$entry];
 		if($menu[$no]{$entry} < 0) {
 			$apps .= "$level"."[exec] ($$d[LOCALENAME]) {$$d[EXEC]}\n";
 		} else {
@@ -973,7 +967,7 @@
 	print $F_OUT qq("$title"\n);
 	my $apps="";
 	foreach my $entry (sort cmpdname keys %{$menu[$no]}) {
-		my $d = $desktop{$entry};
+		my $d = $desktop[$entry];
 		my $name = encode($opt{encoding},$$d[LOCALENAME]);
 		$name=~s/\"/\'/g;
 		my $icon="";
@@ -993,7 +987,7 @@
 	my ($no, $level)=@_;
 	my $apps="";
 	foreach my $entry (sort cmpdname keys %{$menu[$no]}) {
-		my $d = $desktop{$entry};
+		my $d = $desktop[$entry];
 		my $icon = "";
 		$icon = scale_icon($$d[ICON]) if $opt{icons};
 		if($menu[$no]{$entry}<0) {
@@ -1022,7 +1016,7 @@
 	my $this_menu = "";
 	$this_menu .= qq(Popup "$file"\n\tTitle "$basename"\n);
 	foreach my $entry (sort cmpdname keys %{$menu[$no]}) {
-		my $d = $desktop{$entry};
+		my $d = $desktop[$entry];
 		if($menu[$no]{$entry} < 0) {
 			my $name = $$d[LOCALENAME];
 			$name =~ s/\"/\\\"/g;
@@ -1041,7 +1035,7 @@
 	my ($no, $level)=@_;
 	my $apps="";
 	foreach my $entry (sort cmpdname keys %{$menu[$no]}) {
-		my $d = $desktop{$entry};
+		my $d = $desktop[$entry];
 		( my $name = $$d[LOCALENAME] ) =~ s/\"/\\\"/g;
 		my $icon = "";
 		$icon = scale_icon($$d[ICON]) if $opt{icons};
@@ -1064,7 +1058,7 @@
 	my ($no, $level)=@_;
 	my $apps="";
 	foreach my $entry (sort cmpdname keys %{$menu[$no]}) {
-		my $d = $desktop{$entry};
+		my $d = $desktop[$entry];
 		my $name = $$d[LOCALENAME];
 		$name =~ s/\"/\\\"/g;
 		my $icon = "";
@@ -1089,7 +1083,7 @@
 	my $this_menu = "";
 	$this_menu .= qq(DestroyMenu $file\nAddToMenu $file "$basename" Title\n);
 	foreach my $entry (sort cmpdname keys %{$menu[$no]}) {
-		my $d = $desktop{$entry};
+		my $d = $desktop[$entry];
 		my $icon = "";
 		$icon = scale_icon($$d[ICON]) if $opt{icons};
 		$icon = "\%$icon\%" if length $icon;
@@ -1110,7 +1104,7 @@
 	my ($no, $level)=@_;
 	my $apps="";
 	foreach my $entry (sort cmpdname keys %{$menu[$no]}) {
-		my $d = $desktop{$entry};
+		my $d = $desktop[$entry];
 		( my $name = $$d[LOCALENAME] ) =~ s/\"/\\\"/g;
 		if($menu[$no]{$entry}<0) {
 			$apps .= qq($level"$name"	exec $$d[EXEC]\n);
@@ -1127,7 +1121,7 @@
 	my ($no, $level)=@_;
 	my $apps="";
 	foreach my $entry (sort cmpdname keys %{$menu[$no]}) {
-		my $d = $desktop{$entry};
+		my $d = $desktop[$entry];
 		if($menu[$no]{$entry}<0) {
 			$apps .=
 				qq($level<item label="$$d[LOCALENAME]">\n).
@@ -1148,7 +1142,7 @@
 	my ($no, $level)=@_;
 	my $apps="";
 	foreach my $entry (sort cmpdname keys %{$menu[$no]}) {
-		my $d = $desktop{$entry};
+		my $d = $desktop[$entry];
 		( my $name = $$d[LOCALENAME] ) =~ s/\"/\\\"/g;
 		my $icon = "";
 		$icon = scale_icon($$d[ICON]) if $opt{icons};
@@ -1169,7 +1163,7 @@
 	my ($no, $coma, $level)=@_;
 	my $apps="";
 	foreach my $entry (sort cmpdname keys %{$menu[$no]}) {
-		my $d = $desktop{$entry};
+		my $d = $desktop[$entry];
 		my $name = $$d[LOCALENAME];
 		$name =~ s/\"/\\\"/g;
 		if($menu[$no]{$entry} < 0) {
@@ -1190,7 +1184,7 @@
 	my ($no, $level)=@_;
 	my $apps="";
 	foreach my $entry (sort cmpdname keys %{$menu[$no]}) {
-		my $d = $desktop{$entry};
+		my $d = $desktop[$entry];
 		my $name = $$d[LOCALENAME];
 		$name =~ s/\"/\\\"/g;
 		if($menu[$no]{$entry} < 0) {
@@ -1217,7 +1211,7 @@
 	my ($no, $level)=@_;
 	my $apps="";
 	foreach my $entry (sort cmpdname keys %{$menu[$no]}) {
-		my $d = $desktop{$entry};
+		my $d = $desktop[$entry];
 		my $name = ($$d[LOCALENAME] =~ /["&<>]/) ?
 			xmlname($$d[LOCALENAME]) : $$d[LOCALENAME];
 		my $icon = "";
@@ -1238,7 +1232,7 @@
 sub xpde { # {{{
 	my ($no, $dir)=@_;
 	foreach my $entry (keys %{$menu[$no]}) {
-		my $d = $desktop{$entry};
+		my $d = $desktop[$entry];
 		my $name = encode($opt{encoding},$$d[LOCALENAME]);
 		if($menu[$no]{$entry} < 0) {
 			$name =~ s/\"/\\\"/g;
================================================================

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




More information about the pld-cvs-commit mailing list