]> rtime.felk.cvut.cz Git - l4.git/blob - l4/tool/bin/entry-selector
update
[l4.git] / l4 / tool / bin / entry-selector
1 #! /usr/bin/perl -W
2 #
3 # (c) 2009-2011 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[1]) {
20   print "ERROR: Need to give command and modules file!\n";
21   exit 1;
22 }
23
24 my @e = L4::ModList::get_entries($ARGV[1]);
25
26 if ($ARGV[0] eq 'menu')
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       {
44         print "ERROR: dialog aborted!\n";
45         exit 1;
46       }
47
48     my $o;
49     read $tmpfd, $o, 100;
50     close $tmpfd;
51     unlink $tmpfilename;
52
53     chomp $o;
54
55     if ($o !~ /^\d+$/)
56       {
57         print "ERROR: Invalid return value from dialog!\n";
58         exit 1;
59       }
60
61     print STDERR $e[$o];
62     exit 0;
63   }
64 elsif ($ARGV[0] eq 'list')
65   {
66     print join("\n ", "Entries in modules file:", @e), "\n";
67   }