]> rtime.felk.cvut.cz Git - l4.git/blob - l4/tool/bin/entry-selector
433020a5cff8d5051298b310ad3b8058ae884bc0
[l4.git] / l4 / tool / bin / entry-selector
1 #! /usr/bin/perl -W
2 #
3 # (c) 2009 Technische Universität Dresden
4 # This file is part of TUD:OS and distributed under the terms of the
5 # GNU General Public License 2.
6 # Please see the COPYING-GPL-2 file for details.
7 #
8 # Adam Lackorzynski <adam@os.inf.tu-dresden.de>
9 #
10
11 use strict;
12 use File::Temp qw/tempfile/;
13
14 BEGIN { unshift @INC, $ENV{L4DIR}.'/tool/lib'
15            if $ENV{L4DIR} && -d $ENV{L4DIR}.'/tool/lib/L4';}
16
17 use L4::ModList;
18
19 unless (defined $ARGV[0]) {
20   print "ERROR: Need to give modules file!\n";
21   exit 1;
22 }
23
24 my @e = L4::ModList::get_entries($ARGV[0]);
25
26 print join("\n", @e), "\n";
27
28 my ($tmpfd, $tmpfilename) = tempfile();
29
30 my $backtitle = '';
31 if (defined $ENV{BACKTITLE})
32   {
33     $backtitle = $ENV{BACKTITLE};
34     $backtitle =~ s/"/\\"/g;
35     $backtitle = "--backtitle \"$backtitle\"";
36   }
37
38 system("dialog $backtitle --title 'Entry selection' "
39        ." --menu 'Select entry to launch' 18 65 18 ".
40        join(' ', map { "$_ '$e[$_]'" } (0 .. $#e) )." 2> $tmpfilename");
41
42 if ($?) {
43   print "ERROR: dialog aborted!\n";
44   exit 1;
45 }
46
47 my $o;
48 read $tmpfd, $o, 100;
49 close $tmpfd;
50 unlink $tmpfilename;
51
52 chomp $o;
53
54 if ($o !~ /^\d+$/) {
55   print "ERROR: Invalid return value from dialog!\n";
56   exit 1;
57 }
58
59 print STDERR $e[$o];
60 exit 0;