diff options
author | Jim Meyering <meyering@redhat.com> | 2009-09-24 18:46:45 +0200 |
---|---|---|
committer | Jim Meyering <meyering@redhat.com> | 2009-09-24 19:27:25 +0200 |
commit | c602ac5f634d2354d7a7805b415aa198878f94b3 (patch) | |
tree | 5105344d65a16a9ca51bf8b24a253b12e2a7b1f2 /parted | |
parent | 389bd98b434e88e753957f2e33e2f22a1687682a (diff) | |
download | parted-c602ac5f634d2354d7a7805b415aa198878f94b3.tar.gz |
ui: do not initialize readline (which would output!) in --script mode
Running parted with its --script (-s) option would, surprisingly,
print a few control characters if TERM were set appropriately,
and if readline and curses support were compiled in.
This fixes it not to do that.
* parted/parted.c (_init): Initialize readline support only after
parsing command line options, so we can skip it in --script mode.
* parted/ui.c (init_readline): New function.
Body extracted from ...
(init_ui): ...here.
* parted/ui.h (init_readline): Declare.
* tests/t0010-script-no-ctrl-chars.sh: New file. Test for the above.
* tests/Makefile.am (TESTS): Add that new file.
Diffstat (limited to 'parted')
-rw-r--r-- | parted/parted.c | 3 | ||||
-rw-r--r-- | parted/ui.c | 18 | ||||
-rw-r--r-- | parted/ui.h | 3 |
3 files changed, 17 insertions, 7 deletions
diff --git a/parted/parted.c b/parted/parted.c index addd775..97932c8 100644 --- a/parted/parted.c +++ b/parted/parted.c @@ -2459,6 +2459,9 @@ _init_commands (); if (!_parse_options (argc_ptr, argv_ptr)) goto error_done_commands; +if (!opt_script_mode) + init_readline (); + #ifdef HAVE_GETUID if (getuid() != 0 && !opt_script_mode) { puts (_("WARNING: You are not superuser. Watch out for " diff --git a/parted/ui.c b/parted/ui.c index d61f6ac..3b55024 100644 --- a/parted/ui.c +++ b/parted/ui.c @@ -1394,6 +1394,18 @@ init_disk_type_str () } int +init_readline (void) +{ +#ifdef HAVE_LIBREADLINE + if (!opt_script_mode) { + rl_initialize (); + rl_attempted_completion_function = (CPPFunction*) complete_function; + readline_state.in_readline = 0; + } +#endif +} + +int init_ui () { if (!init_ex_opt_str () @@ -1403,12 +1415,6 @@ init_ui () return 0; ped_exception_set_handler (exception_handler); -#ifdef HAVE_LIBREADLINE - rl_initialize (); - rl_attempted_completion_function = (CPPFunction*) complete_function; - readline_state.in_readline = 0; -#endif - #ifdef SA_SIGINFO sigset_t curr; sigfillset (&curr); diff --git a/parted/ui.h b/parted/ui.h index 77bb194..da3fca5 100644 --- a/parted/ui.h +++ b/parted/ui.h @@ -1,6 +1,6 @@ /* parted - a frontend to libparted - Copyright (C) 1999, 2000, 2001, 2007-2008 Free Software Foundation, Inc. + Copyright (C) 1999, 2000, 2001, 2007-2009 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -24,6 +24,7 @@ extern const char *prog_name; extern int init_ui (); +extern int init_readline (); extern int non_interactive_mode (PedDevice** dev, Command* cmd_list[], int argc, char* argv[]); extern int interactive_mode (PedDevice** dev, Command* cmd_list[]); |