#! /usr/bin/perl -W
#
-# (c) 2009 Technische Universität Dresden
+# (c) 2009-2011 Technische Universität Dresden
# This file is part of TUD:OS and distributed under the terms of the
# GNU General Public License 2.
# Please see the COPYING-GPL-2 file for details.
use L4::ModList;
-unless (defined $ARGV[0]) {
- print "ERROR: Need to give modules file!\n";
+unless (defined $ARGV[1]) {
+ print "ERROR: Need to give command and modules file!\n";
exit 1;
}
-my @e = L4::ModList::get_entries($ARGV[0]);
+my @e = L4::ModList::get_entries($ARGV[1]);
-print join("\n", @e), "\n";
-
-my ($tmpfd, $tmpfilename) = tempfile();
-
-my $backtitle = '';
-if (defined $ENV{BACKTITLE})
+if ($ARGV[0] eq 'menu')
{
- $backtitle = $ENV{BACKTITLE};
- $backtitle =~ s/"/\\"/g;
- $backtitle = "--backtitle \"$backtitle\"";
- }
+ my ($tmpfd, $tmpfilename) = tempfile();
-system("dialog $backtitle --title 'Entry selection' "
- ." --menu 'Select entry to launch' 18 65 18 ".
- join(' ', map { "$_ '$e[$_]'" } (0 .. $#e) )." 2> $tmpfilename");
+ my $backtitle = '';
+ if (defined $ENV{BACKTITLE})
+ {
+ $backtitle = $ENV{BACKTITLE};
+ $backtitle =~ s/"/\\"/g;
+ $backtitle = "--backtitle \"$backtitle\"";
+ }
-if ($?) {
- print "ERROR: dialog aborted!\n";
- exit 1;
-}
+ system("dialog $backtitle --title 'Entry selection' "
+ ." --menu 'Select entry to launch' 18 65 18 ".
+ join(' ', map { "$_ '$e[$_]'" } (0 .. $#e) )." 2> $tmpfilename");
-my $o;
-read $tmpfd, $o, 100;
-close $tmpfd;
-unlink $tmpfilename;
+ if ($?)
+ {
+ print "ERROR: dialog aborted!\n";
+ exit 1;
+ }
-chomp $o;
+ my $o;
+ read $tmpfd, $o, 100;
+ close $tmpfd;
+ unlink $tmpfilename;
-if ($o !~ /^\d+$/) {
- print "ERROR: Invalid return value from dialog!\n";
- exit 1;
-}
+ chomp $o;
+
+ if ($o !~ /^\d+$/)
+ {
+ print "ERROR: Invalid return value from dialog!\n";
+ exit 1;
+ }
-print STDERR $e[$o];
-exit 0;
+ print STDERR $e[$o];
+ exit 0;
+ }
+elsif ($ARGV[0] eq 'list')
+ {
+ print join("\n ", "Entries in modules file:", @e), "\n";
+ }