vfmg (DEVEL): vfmg - moved some options to %opt hash, for future r...
sparky
sparky at pld-linux.org
Mon Oct 31 19:42:43 CET 2005
Author: sparky Date: Mon Oct 31 18:42:43 2005 GMT
Module: vfmg Tag: DEVEL
---- Log message:
- moved some options to %opt hash, for future rc file support
---- Files affected:
vfmg:
vfmg (1.73.2.13 -> 1.73.2.14)
---- Diffs:
================================================================
Index: vfmg/vfmg
diff -u vfmg/vfmg:1.73.2.13 vfmg/vfmg:1.73.2.14
--- vfmg/vfmg:1.73.2.13 Mon Oct 31 17:35:19 2005
+++ vfmg/vfmg Mon Oct 31 19:42:38 2005
@@ -10,39 +10,42 @@
my $o_help=0;
my $o_tags=0;
my $o_end=0;
-my $o_icons=0;
-my $o_exec=0;
-my $o_clear=0;
-my $o_promote=0;
my $o_verbose=0;
-my $o_full=0;
-my $o_strip=0;
+my %opt = (
+ icons => 0,
+ exec => 0,
+ clear => 0,
+ promote => 0,
+ full => 0,
+ strip => 0,
+ utf => 0,
+ enc => "",
+ nomenu => 0,
+ xterm => "xterm -name xterm-%1 -e %2",
+);
my $o_output="";
-my $o_utf=0;
-my $o_enc="";
-my $o_xterm="xterm -name xterm-%1 -e %2";
-my $o_nomenu=0;
-$o_xterm="$ENV{'VFMG_TERM'}" if $ENV{'VFMG_TERM'};
+$opt{xterm}="$ENV{'VFMG_TERM'}" if $ENV{'VFMG_TERM'};
GetOptions('help'=>\$o_help,
'tags'=>\$o_tags,
'end|e'=>\$o_end,
- 'icons'=>\$o_icons,
- 'exec|x'=>\$o_exec,
- 'clear'=>\$o_clear,
- 'promote'=>\$o_promote,
+ 'icons'=>\$opt{icons},
+ 'exec|x'=>\$opt{exec},
+ 'clear'=>\$opt{clear},
+ 'promote'=>\$opt{promote},
'verbose'=>\$o_verbose,
- 'full'=>\$o_full,
- 'strip'=>\$o_strip,
- 'utf8'=>\$o_utf,
- 'nomenu|m'=>\$o_nomenu,
- 'output=s'=>\$o_enc,
- 'xterm|r=s'=>\$o_xterm
+ 'full'=>\$opt{full},
+ 'strip'=>\$opt{strip},
+ 'utf8'=>\$opt{utf},
+ 'nomenu|m'=>\$opt{nomenu},
+ 'output=s'=>\$opt{enc},
+ 'xterm|r=s'=>\$opt{xterm}
);
if($o_help) {
- print "Usage: $0 [options] {aewm, afterstep, blackbox, enlightenment, fbpanel, fluxbox, fvwm, fvwm2, icewm, metisse, openbox, olvwm, qvwm, wmaker, wmaker-old, xfce4, xpde}
+ print<<EOF;
+Usage: $0 [options] {aewm, afterstep, blackbox, enlightenment, fbpanel, fluxbox, fvwm, fvwm2, icewm, metisse, openbox, olvwm, qvwm, wmaker, wmaker-old, xfce4, xpde}
-h, --help - print this help
-t, --tags - echo omitted tags to stderr
-e, --end - echo omitted XDG file ending to stderr
@@ -54,10 +57,11 @@
-p, --promote - promote submenus with single entry
-s, --strip - strip 1st level menu
-u, --utf8 - output in utf8 (default is locale setting)
- -m, --nomenu - don't add additional menu info (valid for blackbox, fluxbox, openbox, xfce4)
-o, --output= - output in given encoding (e.g. iso-8859-2)
- -r, --xterm= - set x terminal application (default \"xterm -name xterm-%1 -e %2\")
- example \"gnome-terminal -t Terminal.%1 -x %2\"\n";
+ -m, --nomenu - don't add additional menu info (valid for blackbox, fluxbox, openbox, xfce4)
+ -r, --xterm= - set x terminal application (default "xterm -name xterm-%1 -e %2")
+ example "gnome-terminal -t Terminal.%1 -x %2"
+EOF
exit;
}
@@ -67,7 +71,7 @@
die "Unrecognized argument: $o_output\n"
unless $o_output=~/^(aewm|afterstep|blackbox|enlightenment|fbpanel|fluxbox|fvwm|fvwm2|icewm|metisse|openbox|olvwm|qvwm|wmaker|wmaker-old|xfce4|xpde)$/;
-$o_full=1 if $o_icons and $o_output=~/^(enlightenment|metisse)$/;
+$opt{full}=1 if $opt{icons} and $o_output=~/^(enlightenment|metisse)$/;
# header }}}
# search dirs {{{
@@ -103,20 +107,20 @@
);
my @path;
-if($o_exec) {
+if($opt{exec}) {
@path=(grep (-d, split(/:+/,$ENV{'PATH'})), "");
- if($o_xterm) {
+ if($opt{xterm}) {
my $exists=0;
- my $bin=$o_xterm;
+ my $bin=$opt{xterm};
$bin=~s/(\S+).*/$1/; #v---------v
foreach my $dir(@path) { # would be "//dir/.../file" correct?
if(-x "$dir/$bin") {#----^
$exists=1;
- $o_xterm="$dir/$o_xterm" if $o_full;
+ $opt{xterm}="$dir/$opt{xterm}" if $opt{full};
last;
}
}
- $o_xterm="" unless $exists;
+ $opt{xterm}="" unless $exists;
}
}
# search dirs }}}
@@ -187,15 +191,15 @@
$tags{term} =
($tags{Terminal} && $tags{Terminal} =~ /^(?:1|true)$/i) ? 1 : 0;
- return if $tags{term} and not $o_xterm;
+ return if $tags{term} and not $opt{xterm};
my($bin) = ($tags{Exec} =~ /(\S+)/); #v---------v
- if ($o_exec) {
+ if ($opt{exec}) {
my $exists;
foreach my $dir (@path) { # would be "//dir/.../file" correct?
if (-x "$dir/$bin") { #----^
$exists++;
- $tags{Exec} = "$dir/$tags{Exec}" if $o_full;
+ $tags{Exec} = "$dir/$tags{Exec}" if $opt{full};
last;
}
}
@@ -203,12 +207,12 @@
}
if ($tags{term}) {
$bin =~ s|.*/||;
- $_ = $o_xterm;
+ $_ = $opt{xterm};
s/%1/$bin/;
s/%2/$tags{Exec}/;
$tags{Exec} = $_;
}
- if ($o_icons) {
+ if ($opt{icons}) {
my $exists=0;
my @idirs;
push @idirs, '' if $tags{Icon} =~ m|^/|;
@@ -222,7 +226,7 @@
}
}
if ($exists) {
- $tags{Icon} = "$dir$tags{Icon}" if $o_full;
+ $tags{Icon} = "$dir$tags{Icon}" if $opt{full};
last;
}
}
@@ -536,7 +540,7 @@
last;
}
if ($ok) {
- if($o_icons) {
+ if($opt{icons}) {
my $exists=0;
foreach my $dir(@icondirs) {
if(-f "$dir$icon") {
@@ -550,7 +554,7 @@
next;
}
$exists=1;
- $icon="$dir$icon" if $o_full;
+ $icon="$dir$icon" if $opt{full};
last;
}
$icon="" unless $exists;
@@ -604,7 +608,7 @@
warn "Omitted ending: $file\n" if(($file ne "")&& $o_end);
# parse menu file }}}
-if(($o_clear)&&(!$o_promote)) { # {{{
+if(($opt{clear})&&(!$opt{promote})) { # {{{
my @empty;
for(my $i=$#menu; $i>=0; $i--) {
$empty[$i]=1;
@@ -623,7 +627,7 @@
}
} #}}}
-if($o_promote) { # {{{
+if($opt{promote}) { # {{{
my @count;
for(my $i=$#menu; $i>=0; $i--) {
$count[$i]=0;
@@ -792,7 +796,7 @@
foreach my $entry(keys %{$menu[$no]}) {
my $d = $desktop{$entry};
- $name = encode($o_enc,$$d[1]);
+ $name = encode($opt{enc},$$d[1]);
if($menu[$no]{$entry} < 0) {
$name=~s/\"/\\\"/g;
my $F_OUT;
@@ -864,7 +868,7 @@
foreach my $entry (sort {$desktop{$a}[1] cmp $desktop{$b}[1]} keys %{$menu[$no]}) {
my $d = $desktop{$entry};
my $icon = "";
- $icon = $$d[2] if $o_icons;
+ $icon = $$d[2] if $opt{icons};
$icon = scale_icon($$d[2],"png","-geometry","21x18") if $icon;
$icon = "\%$icon\%" if $icon;
@@ -949,10 +953,10 @@
my $apps="";
foreach my $entry (sort {$desktop{$a}[1] cmp $desktop{$b}[1]} keys %{$menu[$no]}) {
my $d = $desktop{$entry};
- $name=encode($o_enc,$$d[1]);
+ $name=encode($opt{enc},$$d[1]);
$name=~s/\"/\'/g;
my $icon="";
- $icon=$$d[2] if $o_icons;
+ $icon=$$d[2] if $opt{icons};
$icon=scale_icon($icon,"png","-geometry","18x18") if length $icon;
if($menu[$no]{$entry}<0) {
$apps .= qq("$name" "$icon" exec "$$d[3]"\n);
@@ -969,7 +973,7 @@
my ($no, $dir)=@_;
foreach my $entry (keys %{$menu[$no]}) {
my $d = $desktop{$entry};
- $name = encode($o_enc,$$d[1]);
+ $name = encode($opt{enc},$$d[1]);
if($menu[$no]{$entry} < 0) {
$name =~ s/\"/\\\"/g;
open F_OUT, ">> $dir/$$d[0].lnk" or warn "$dir/$$d[0].lnk: $!\n";
@@ -1035,33 +1039,33 @@
} # }}}
# WM functions }}}
-$o_enc||="utf-8" if $o_utf;
+$opt{enc}||="utf-8" if $opt{utf};
#use open OUT => ':utf8';
-#eval "use open OUT => ':locale'" unless $o_enc; # $o_enc always set
-unless ($o_enc) {
+#eval "use open OUT => ':locale'" unless $opt{enc}; # $o_enc always set
+unless (length $opt{enc}) {
require I18N::Langinfo;
I18N::Langinfo->import(qw(langinfo CODESET));
- $o_enc=langinfo(CODESET()) unless $o_enc;
+ $opt{enc}=langinfo(CODESET());
}
-binmode STDOUT, ":encoding($o_enc)";
+binmode STDOUT, ":encoding($opt{enc})";
# WM case {{{
if($o_output eq "icewm") {
- icewm($o_strip);
+ icewm($opt{strip});
exit;
}
if($o_output eq "blackbox") {
- print "[begin] (Blackbox)\n" unless $o_nomenu;
- blackbox($o_strip);
- print "[end]\n" unless $o_nomenu;
+ print "[begin] (Blackbox)\n" unless $opt{nomenu};
+ blackbox($opt{strip});
+ print "[end]\n" unless $opt{nomenu};
exit;
}
if($o_output eq "wmaker-old") {
- wmakerold($o_strip);
+ wmakerold($opt{strip});
exit;
}
if($o_output eq "wmaker") {
- if($o_strip) {
+ if($opt{strip}) {
wmaker(1,",");
} else {
wmaker(0,"");
@@ -1071,9 +1075,9 @@
}
if($o_output eq "xfce4") {
print "<xfdesktop-menu>\n";
- print "<title name=\"Desktop Menu\" visible=\"yes\"/>\n" unless $o_nomenu;
+ print "<title name=\"Desktop Menu\" visible=\"yes\"/>\n" unless $opt{nomenu};
$level.=" ";
- xfce4($o_strip);
+ xfce4($opt{strip});
print "</xfdesktop-menu>\n";
exit;
}
@@ -1090,22 +1094,22 @@
} else {
mkpath("$dir",0,0700);
}
- afterstep($o_strip,$dir);
+ afterstep($opt{strip},$dir);
exit;
} # }}}
if($o_output eq "fvwm") {
- fvwm($o_strip,"", "fvwm");
+ fvwm($opt{strip},"", "fvwm");
exit;
}
if($o_output eq "fluxbox") { # This is the same as blackbox (I hope so)
- print "[begin] (Fluxbox)\n" unless $o_nomenu;
- blackbox($o_strip);
- print "[end]\n" unless $o_nomenu;
+ print "[begin] (Fluxbox)\n" unless $opt{nomenu};
+ blackbox($opt{strip});
+ print "[end]\n" unless $opt{nomenu};
exit;
}
if($o_output eq "fvwm2") {
$level="fvwm2";
- fvwm2($o_strip);
+ fvwm2($opt{strip});
exit;
}
@@ -1117,21 +1121,21 @@
}
mkpath("$icon_dir",0,0700);
}
- metisse($o_strip,"", "metisse");
+ metisse($opt{strip},"", "metisse");
exit;
}
if($o_output eq "olvwm") {
- olvwm($o_strip);
+ olvwm($opt{strip});
exit;
}
if($o_output eq "qvwm") {
print "[StartMenu]\n";
- qvwm($o_strip);
+ qvwm($opt{strip});
exit;
}
if($o_output eq "aewm") {
- aewm($o_strip);
+ aewm($opt{strip});
exit;
}
if($o_output eq "enlightenment") { # {{{
@@ -1149,7 +1153,7 @@
}
mkpath("$icon_dir",0,0700);
}
- enlightenment($o_strip,"index","Enlightenment");
+ enlightenment($opt{strip},"index","Enlightenment");
exit;
} # }}}
if($o_output eq "xpde") { # {{{
@@ -1160,19 +1164,19 @@
rename("$dir","$dir.old");
}
mkpath("$dir",0,0700);
- xpde($o_strip,$dir);
+ xpde($opt{strip},$dir);
exit;
} # }}}
if($o_output eq "fbpanel") {
- fbpanel($o_strip);
+ fbpanel($opt{strip});
exit;
}
if($o_output eq "openbox") { # {{{
- print "<openbox_menu>\n" unless $o_nomenu;
- print "<menu id=\"root-menu\" label=\"PLD Linux\">\n" unless $o_nomenu;
- openbox($o_strip);
- print "</menu>\n" unless $o_nomenu;
- print "</openbox_menu>\n" unless $o_nomenu;
+ print "<openbox_menu>\n" unless $opt{nomenu};
+ print "<menu id=\"root-menu\" label=\"PLD Linux\">\n" unless $opt{nomenu};
+ openbox($opt{strip});
+ print "</menu>\n" unless $opt{nomenu};
+ print "</openbox_menu>\n" unless $opt{nomenu};
exit;
} # }}}
# WM case }}}
================================================================
---- CVS-web:
http://cvs.pld-linux.org/vfmg/vfmg?r1=1.73.2.13&r2=1.73.2.14&f=u
More information about the pld-cvs-commit
mailing list