Files
foc/l4/tool/bin/entry-selector
2013-01-11 17:00:47 +01:00

68 lines
1.4 KiB
Perl
Executable File

#! /usr/bin/perl -W
#
# (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.
#
# Adam Lackorzynski <adam@os.inf.tu-dresden.de>
#
use strict;
use File::Temp qw/tempfile/;
BEGIN { unshift @INC, $ENV{L4DIR}.'/tool/lib'
if $ENV{L4DIR} && -d $ENV{L4DIR}.'/tool/lib/L4';}
use L4::ModList;
unless (defined $ARGV[1]) {
print "ERROR: Need to give command and modules file!\n";
exit 1;
}
my @e = L4::ModList::get_entries($ARGV[1]);
if ($ARGV[0] eq 'menu')
{
my ($tmpfd, $tmpfilename) = tempfile();
my $backtitle = '';
if (defined $ENV{BACKTITLE})
{
$backtitle = $ENV{BACKTITLE};
$backtitle =~ s/"/\\"/g;
$backtitle = "--backtitle \"$backtitle\"";
}
system("dialog $backtitle --title 'Entry selection' "
." --menu 'Select entry to launch' 18 65 18 ".
join(' ', map { "$_ '$e[$_]'" } (0 .. $#e) )." 2> $tmpfilename");
if ($?)
{
print "ERROR: dialog aborted!\n";
exit 1;
}
my $o;
read $tmpfd, $o, 100;
close $tmpfd;
unlink $tmpfilename;
chomp $o;
if ($o !~ /^\d+$/)
{
print "ERROR: Invalid return value from dialog!\n";
exit 1;
}
print STDERR $e[$o];
exit 0;
}
elsif ($ARGV[0] eq 'list')
{
print join("\n ", "Entries in modules file:", @e), "\n";
}