Make the result of isatty into a global variable (is_tty).
Change the rl_gets() function so it takes the prompt string
instead of a "display prompt?" flag. rl_gets() then consults
the global to find out if it should display the prompt at all.
#include "hivex.h"
static int quit = 0;
#include "hivex.h"
static int quit = 0;
-static char *prompt_string = NULL; /* Prompt string. */
+static char *prompt_string = NULL; /* Normal prompt string. */
static char *loaded = NULL; /* Basename of loaded file, if any. */
static hive_node_h cwd; /* Current node. */
static int open_flags = 0; /* Flags used when loading a hive file. */
static char *loaded = NULL; /* Basename of loaded file, if any. */
static hive_node_h cwd; /* Current node. */
static int open_flags = 0; /* Flags used when loading a hive file. */
static void initialize_readline (void);
static void cleanup_readline (void);
static void add_history_line (const char *);
static void initialize_readline (void);
static void cleanup_readline (void);
static void add_history_line (const char *);
-static char *rl_gets (int prompt);
+static char *rl_gets (const char *prompt_string);
static void sort_strings (char **strings, int len);
static int dispatch (char *cmd, char *args);
static int cmd_cd (char *path);
static void sort_strings (char **strings, int len);
static int dispatch (char *cmd, char *args);
static int cmd_cd (char *path);
- int prompt = isatty (0);
printf (_(
"\n"
"Welcome to hivexsh, the hivex interactive shell for examining\n"
printf (_(
"\n"
"Welcome to hivexsh, the hivex interactive shell for examining\n"
- char *buf = rl_gets (prompt);
+ char *buf = rl_gets (prompt_string);
if (!buf) {
quit = 1;
printf ("\n");
if (!buf) {
quit = 1;
printf ("\n");
got_command:
/*printf ("command: '%s' args: '%s'\n", cmd, args)*/;
int r = dispatch (cmd, args);
got_command:
/*printf ("command: '%s' args: '%s'\n", cmd, args)*/;
int r = dispatch (cmd, args);
- if (!prompt && r == -1)
+ if (!is_tty && r == -1)
static char *line_read = NULL;
static char *
static char *line_read = NULL;
static char *
+rl_gets (const char *prompt_string)
{
#ifdef HAVE_LIBREADLINE
{
#ifdef HAVE_LIBREADLINE
if (line_read) {
free (line_read);
line_read = NULL;
if (line_read) {
free (line_read);
line_read = NULL;
static char buf[8192];
int len;
static char buf[8192];
int len;
printf ("%s", prompt_string);
line_read = fgets (buf, sizeof buf, stdin);
printf ("%s", prompt_string);
line_read = fgets (buf, sizeof buf, stdin);