summaryrefslogtreecommitdiffstats
path: root/urpm/msg.pm
diff options
context:
space:
mode:
authorRafael Garcia-Suarez <rgarciasuarez@mandriva.org>2004-12-07 17:25:49 +0000
committerRafael Garcia-Suarez <rgarciasuarez@mandriva.org>2004-12-07 17:25:49 +0000
commitd2dd263af5e1437afa03b29ab5d4508be81683ab (patch)
tree3ecdc92e08474976770adb066d9edb7e52a93fac /urpm/msg.pm
parent9454a369c8700f45633c466b9edfd84be194f954 (diff)
downloadurpmi-d2dd263af5e1437afa03b29ab5d4508be81683ab.tar
urpmi-d2dd263af5e1437afa03b29ab5d4508be81683ab.tar.gz
urpmi-d2dd263af5e1437afa03b29ab5d4508be81683ab.tar.bz2
urpmi-d2dd263af5e1437afa03b29ab5d4508be81683ab.tar.xz
urpmi-d2dd263af5e1437afa03b29ab5d4508be81683ab.zip
Remove GUI messages.
Diffstat (limited to 'urpm/msg.pm')
-rw-r--r--urpm/msg.pm80
1 files changed, 27 insertions, 53 deletions
diff --git a/urpm/msg.pm b/urpm/msg.pm
index 8c681fa9..00dc5b75 100644
--- a/urpm/msg.pm
+++ b/urpm/msg.pm
@@ -3,7 +3,7 @@ package urpm::msg;
use strict;
use Exporter;
our @ISA = 'Exporter';
-our @EXPORT = qw(N log_it to_utf8 message_input gmessage message toMb);
+our @EXPORT = qw(N log_it to_utf8 message_input message toMb);
#- I18N.
eval {
@@ -35,68 +35,42 @@ sub log_it {
sub to_utf8 { Locale::gettext::iconv($_[0], undef, "UTF-8") }
-#- this function returns a value via $?. this is evil; FIXME (and use zenity)
-sub gmessage {
- my ($msg, %params) = @_;
- my $ok = to_utf8($params{ok} || N("Ok"));
- my $cancel = to_utf8($params{cancel} || N("Cancel"));
- $ok =~ s/,/\\,/g; $cancel =~ s/,/\\,/g;
- my $buttons = $params{ok_only} ? "$ok:0" : "$ok:0,$cancel:2";
- foreach (@{$params{add_buttons}}) {
- s/,/\\,/g;
- $buttons .= ",$_";
- }
- $msg = to_utf8($msg);
- `gmessage -default "$ok" -buttons "$buttons" "$msg"`;
-}
-
sub message_input {
my ($msg, $default_input, %opts) = @_;
my $input;
- if ($urpm::args::options{X} && !$default_input) {
- #- if a default input is given, the user doesn't have to choose (and being asked).
- gmessage($msg, ok_only => 1);
- $urpm::args::options{bug} and log_it($msg);
- } else {
- while (1) {
- if ($urpm::args::options{bug} || !defined fileno ::SAVEOUT) {
- print STDOUT $msg;
- } else {
- print ::SAVEOUT $msg;
- }
- if ($default_input) {
- $urpm::args::options{bug} and log_it($default_input);
- return $default_input;
- }
- $input = <STDIN>;
- defined $input or return undef;
- chomp $input;
- $urpm::args::options{bug} and log_it($input);
- if ($opts{boolean}) {
- $input =~ /^[$noexpr$yesexpr]?$/ and last;
- } elsif ($opts{range}) {
- $input eq "" and $input = 1; #- defaults to first choice
- (defined $opts{range_min} ? $opts{range_min} : 1) <= $input && $input <= $opts{range} and last;
- } else {
- last;
- }
- message(N("Sorry, bad choice, try again\n"));
+ while (1) {
+ if ($urpm::args::options{bug} || !defined fileno ::SAVEOUT) {
+ print STDOUT $msg;
+ } else {
+ print ::SAVEOUT $msg;
}
+ if ($default_input) {
+ $urpm::args::options{bug} and log_it($default_input);
+ return $default_input;
+ }
+ $input = <STDIN>;
+ defined $input or return undef;
+ chomp $input;
+ $urpm::args::options{bug} and log_it($input);
+ if ($opts{boolean}) {
+ $input =~ /^[$noexpr$yesexpr]?$/ and last;
+ } elsif ($opts{range}) {
+ $input eq "" and $input = 1; #- defaults to first choice
+ (defined $opts{range_min} ? $opts{range_min} : 1) <= $input && $input <= $opts{range} and last;
+ } else {
+ last;
+ }
+ message(N("Sorry, bad choice, try again\n"));
}
return $input;
}
sub message {
- my ($msg, $no_X) = @_;
- if ($urpm::args::options{X} && !$no_X && !$::auto) {
- gmessage($msg, ok_only => 1);
- $urpm::args::options{bug} and log_it($msg);
+ my ($msg) = @_;
+ if ($urpm::args::options{bug} || !defined fileno ::SAVEOUT) {
+ print STDOUT "$msg\n";
} else {
- if ($urpm::args::options{bug} || !defined fileno ::SAVEOUT) {
- print STDOUT "$msg\n";
- } else {
- print ::SAVEOUT "$msg\n";
- }
+ print ::SAVEOUT "$msg\n";
}
}
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
/* cmd line facility for slang */
/* Copyright (c) 1992, 1999, 2001 John E. Davis
 * This file is part of the S-Lang library.
 *
 * You may distribute under the terms of either the GNU General Public
 * License or the Perl Artistic License.
 */
#include "slinclud.h"

#if SLANG_HAS_FLOAT
# include <math.h>
#endif

#include "slang.h"
#include "_slang.h"

#ifndef HAVE_STDLIB_H
/* Oh dear.  Where is the prototype for atof?  If not in stdlib, then
 * I do not know where.  Not in math.h onsome systems either.
 */
extern double atof ();
#endif

static SLcmd_Cmd_Type *SLcmd_find_command (char *s, SLcmd_Cmd_Type *cmd)
{
   char *cmdstr;
   char chs = *s++, ch;

   while ((cmd->cmdfun != NULL)
	  && (NULL != (cmdstr = cmd->cmd))
	  && (0 != (ch = *cmdstr++)))
     {
	if ((ch == chs) && !strcmp (s, cmdstr)) return cmd;
	cmd++;
     }
   return NULL;
}

static int extract_token (char **strptr, char *buf)
{
   char *s, *b;
   char ch, quote;

   *buf = 0;

   s = *strptr;
   while (((ch = *s) != 0)
	  && ((ch == ' ') || (ch == '\t') || (ch == '\n')))
     s++;

   *strptr = s;

   if (ch == 0) return 0;
   if (ch == '%') return 0;

   b = buf;

   *b++ = ch;
   s++;

   if ((ch == '\'') || (ch == '"'))
     {
	quote = ch;
	while ((ch = *s) != 0)
	  {
	     s++;
	     *b++ = ch;
	     if (ch == quote)
	       break;

	     if (ch == '\\')
	       {
		  if (0 == (ch = *s))
		    break;
		  *b++ = ch;
		  s++;
	       }
	  }
	*strptr = s;
	*b = 0;
	return 1;
     }

   while (((ch = *s) != 0)
	  && (ch != ' ')
	  && (ch != '\t')
	  && (ch != '\n')
	  && (ch != '%'))
     *b++ = *s++;

   *strptr = s;
   *b = 0;
   return 1;
}

static int allocate_arg_space (SLcmd_Cmd_Table_Type *table, int argc, unsigned int *space_ptr)
{
   unsigned int space = *space_ptr;
   char *p;

   if (argc + 1 < (int) space)
     return 0;

   if (space > 128)
     {
	if (space > 1024) space += 1024;
	else space += 128;
     }
   else space += 32;

   if (NULL == (p = SLrealloc ((char *)table->string_args, space * sizeof (char *))))
     return -1;
   table->string_args = (char **)p;
   table->string_args [argc] = NULL;

   if (NULL == (p = SLrealloc ((char *)table->int_args, space * sizeof (int))))
     return -1;
   table->int_args = (int *)p;

   if (NULL == (p = SLrealloc ((char *)table->double_args, space * sizeof (double))))
     return -1;
   table->double_args = (double *)p;

   if (NULL == (p = SLrealloc ((char *)table->arg_type, space * sizeof (unsigned char))))
     return -1;
   table->arg_type = (unsigned char *)p;

   *space_ptr = space;
   return 0;
}

int SLcmd_execute_string (char *str, SLcmd_Cmd_Table_Type *table)
{
   char *s, *b = NULL, *arg_type, *last_str, *cmd_name;
   SLcmd_Cmd_Type *cmd;
   char *buf;
   int token_present;
   int i;
   int status;
   unsigned int len;
   int argc;
   unsigned int space;

   table->argc = 0;
   table->string_args = NULL;
   table->int_args = NULL;
   table->double_args = NULL;
   table->arg_type = NULL;

   buf = SLmake_string (str);
   if (buf == NULL)
     return -1;

   status = extract_token (&str, buf);
   if (status <= 0)
     {
	SLfree (buf);
	return status;
     }

   if (((len = strlen (buf)) >= 32)
       || (NULL == (cmd = SLcmd_find_command (buf, table->table))))
     {
	SLang_verror (SL_UNDEFINED_NAME,"%s: invalid command", buf);
	SLfree (buf);
	return -1;
     }

   if (NULL == (cmd_name = SLmake_string (buf)))
     {
	SLfree (buf);
	return -1;
     }

   space = 0;
   argc = 0;
   if (-1 == allocate_arg_space (table, argc, &space))
     {
	SLfree (buf);
	return -1;
     }
   table->arg_type[argc] = SLANG_STRING_TYPE;
   table->string_args[argc++] = cmd_name;

   arg_type = cmd->arg_type;
   status = -1;
   while (*arg_type)
     {
	int guess_type = 0;

	last_str = str;

	if (-1 == allocate_arg_space (table, argc, &space))
	  goto error;

	if (-1 == (token_present = extract_token (&str, buf)))
	  goto error;

	table->string_args[argc] = NULL;

	if (token_present)
	  {
	     b = buf;
	     len = strlen (b);

	     if ((*b == '"') && (len > 1))
	       {
		  b++;
		  len -= 2;
		  b[len] = 0;
		  guess_type = SLANG_STRING_TYPE;
		  SLexpand_escaped_string (buf, b, b + len);
		  len = strlen (buf);
	       }
	     else if ((*b == '\'') && (len > 1))
	       {
		  char ch;
		  b++;
		  len -= 2;
		  b[len] = 0;
		  guess_type = SLANG_INT_TYPE;
		  ch = *b;
		  if (ch == '\\')
		    (void) _SLexpand_escaped_char (b, &ch);
		  sprintf (buf, "%d", (unsigned char) ch);
		  len = strlen (buf);
	       }
	     else guess_type = SLang_guess_type (buf);
	  }

	switch (*arg_type++)
	  {
	     /* variable argument number */
	   case 'v':
	     if (token_present == 0) break;
	   case 'V':
	     if (token_present == 0)
	       {
		  SLang_verror (SL_INVALID_PARM, "%s: Expecting argument", cmd_name);
		  goto error;
	       }

	     while (*last_str == ' ') last_str++;
	     len = strlen (last_str);
	     str = last_str + len;

	     s = SLmake_nstring (last_str, len);
	     if (s == NULL) goto error;

	     table->arg_type[argc] = SLANG_STRING_TYPE;
	     table->string_args[argc++] = s;
	     break;

	   case 's':
	     if (token_present == 0) break;
	   case 'S':
	     if (token_present == 0)
	       {
		  SLang_verror (SL_TYPE_MISMATCH, "%s: Expecting string argument", cmd_name);
		  goto error;
	       }

	     s = SLmake_nstring (buf, len);
	     if (s == NULL) goto error;
	     table->arg_type[argc] = SLANG_STRING_TYPE;
	     table->string_args[argc++] = s;
	     break;

	     /* integer argument */
	   case 'i':
	     if (token_present == 0) break;
	   case 'I':
	     if ((token_present == 0) || (SLANG_INT_TYPE != guess_type))
	       {
		  SLang_verror (SL_TYPE_MISMATCH, "%s: Expecting integer argument", cmd_name);
		  goto error;
	       }

	     table->arg_type[argc] = SLANG_INT_TYPE;
	     table->int_args[argc++] = SLatoi((unsigned char *) buf);
	     break;

	     /* floating point arg */
#if SLANG_HAS_FLOAT
	   case 'f':
	     if (token_present == 0) break;
	   case 'F':
	     if ((token_present == 0) || (SLANG_STRING_TYPE == guess_type))
	       {
		  SLang_verror (SL_TYPE_MISMATCH, "%s: Expecting double argument", cmd_name);
		  goto error;
	       }
	     table->arg_type[argc] = SLANG_DOUBLE_TYPE;
	     table->double_args[argc++] = atof(buf);
	     break;
#endif
	     /* Generic type */
	   case 'g':
	     if (token_present == 0) break;
	   case 'G':
	     if (token_present == 0)
	       {
		  SLang_verror (SL_TYPE_MISMATCH, "%s: Expecting argument", cmd_name);
		  goto error;
	       }

	     switch (guess_type)
	       {
		case SLANG_INT_TYPE:
		  table->arg_type[argc] = SLANG_INT_TYPE;
		  table->int_args[argc++] = SLatoi((unsigned char *) buf);
		  break;

		case SLANG_STRING_TYPE:
		  s = SLmake_nstring (buf, len);
		  if (s == NULL) goto error;

		  table->arg_type[argc] = SLANG_STRING_TYPE;
		  table->string_args[argc++] = s;
		  break;
#if SLANG_HAS_FLOAT
		case SLANG_DOUBLE_TYPE:
		  table->arg_type[argc] = SLANG_DOUBLE_TYPE;
		  table->double_args[argc++] = atof(buf);
#endif
	       }
	     break;
	  }
     }

   /*                 call function */
   status = (*cmd->cmdfun)(argc, table);

   error:
   if (table->string_args != NULL) for (i = 0; i < argc; i++)
     {
	if (NULL != table->string_args[i])
	  {
	     SLfree (table->string_args[i]);
	     table->string_args[i] = NULL;
	  }
     }
   SLfree ((char *)table->string_args); table->string_args = NULL;
   SLfree ((char *)table->double_args); table->double_args = NULL;
   SLfree ((char *)table->int_args); table->int_args = NULL;
   SLfree ((char *)table->arg_type); table->arg_type = NULL;

   SLfree (buf);
   return status;
}