From 98772744e904127cda466f1b5be3969ae5fbdcc2 Mon Sep 17 00:00:00 2001 From: Mike Newman Date: Mon, 9 Jun 2003 21:35:39 +0000 Subject: Committing patch to fall back to dialog if DISPLAY not set from Kevin C. Krinke --- src/gdialog.in | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) (limited to 'src/gdialog.in') diff --git a/src/gdialog.in b/src/gdialog.in index a27c0e9a..48699d8c 100755 --- a/src/gdialog.in +++ b/src/gdialog.in @@ -20,6 +20,83 @@ my $argn = 0; # counter for walking args my $args = $#ARGV + 1; # total number of command line arguments my $separator = 0; # set if --separate-output is in use + +# Additon by: Kevin C. Krinke (kck) +# +# gdialog itself supports both the X-Windows interface as well as a console +# interface. Here's a fix to use regular dialog when appropriate. +# This should probably be a more advanced test of some sort, but I don't know +# of any other easy way of detecting and X-Windows environment. If someone does +# know better, please let me know. So for now this works: "no DISPLAY; no X". + +unless (defined $ENV{'DISPLAY'} && length($ENV{'DISPLAY'})) { + + # reset the command string + + $command = ""; + + # examine all the available/default paths + + my $PATHS = ($ENV{'PATH'}||'/bin:/usr/bin:/usr/local/bin:/opt/bin'); + + BIN: foreach my $PATH (split(/\:/,$PATHS)) { + + if (-x $PATH."/gdialog.real") { + + # Some GNU/Linux distributions divert binaries when + # other packages are installed. If this exists, chances + # are it's the real gdialog and not the Zenity wrapper. + # gdialog has full support for the Console medium and + # as such is the preference over using the "regular" + # dialog interface. + + $command = $PATH."/gdialog.real "; + last BIN; + + } elsif (-x $PATH."/dialog") { + + # change the command and skip ahead! + + $command = $PATH."/dialog "; + last BIN; + + } + + + } + + unless ($command) { + + # we didn't find the dialog binary, exit(254) with a message + # to STDERR. + + print STDERR "missing DISPLAY and a console dialog could". + " not be found.\n"; + + # exit code 254 is used because 255, 1, 2, 3 are used by Zenity + # and cDialog. This error, is a very _bad_ error so it's semi- + # non-standard at 254. + + exit(254); + + } + + # all is well if we've made it this far + + # so join the arguments double-quoting things so that proper shell + # notation is saved. + + $command .= '"'.join('" "',@ARGV).'"'; + + # and fork the process + + exec($command); + +} + +# Got DISPLAY, has X continue as normal... +# End Addtition by: KCK + # this just loads the current arg into $element sub get_arg () { -- cgit