]> rtime.felk.cvut.cz Git - l4.git/blob - l4/tool/bin/entry-selector
Some minor fixes.
[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 # Do not use 'perl -W' here, as with perl-5.20 we'll get
11 # Use of uninitialized value in string ne at /usr/lib/..../perl/5.20/File/Spec/Unix.pm line 92.
12 # Maybe sometime later we could use -W again?
13
14 use strict;
15 use File::Temp qw/tempfile/;
16
17 BEGIN { unshift @INC, $ENV{L4DIR}.'/tool/lib'
18            if $ENV{L4DIR} && -d $ENV{L4DIR}.'/tool/lib/L4';}
19
20 use L4::ModList;
21
22 unless (defined $ARGV[1]) {
23   print "ERROR: Need to give command and modules file!\n";
24   exit 1;
25 }
26
27 my @e = L4::ModList::get_entries($ARGV[1]);
28
29 if ($ARGV[0] eq 'menu')
30   {
31     my ($tmpfd, $tmpfilename) = tempfile();
32
33     my $backtitle = '';
34     if (defined $ENV{BACKTITLE})
35       {
36         $backtitle = $ENV{BACKTITLE};
37         $backtitle =~ s/"/\\"/g;
38         $backtitle = "--backtitle \"$backtitle\"";
39       }
40
41     system("dialog $backtitle --title 'Entry selection' "
42         ." --menu 'Select entry to launch' 18 65 18 ".
43         join(' ', map { "$_ '$e[$_]'" } (0 .. $#e) )." 2> $tmpfilename");
44
45     if ($?)
46       {
47         print "ERROR: dialog aborted!\n";
48         exit 1;
49       }
50
51     my $o;
52     read $tmpfd, $o, 100;
53     close $tmpfd;
54     unlink $tmpfilename;
55
56     chomp $o;
57
58     if ($o !~ /^\d+$/)
59       {
60         print "ERROR: Invalid return value from dialog!\n";
61         exit 1;
62       }
63
64     print STDERR $e[$o];
65     exit 0;
66   }
67 elsif ($ARGV[0] eq 'list')
68   {
69     print join("\n ", "Entries in modules file:", @e), "\n";
70   }