void
input_init(void)
{
- retrieve_symbols();
- printf("BIRD Client " BIRD_VERSION " ready.\n");
+ prompt_active = 0;
+
+ if (interactive)
+ {
+ prompt_active = 1;
+
+ retrieve_symbols();
+ printf("BIRD Client " BIRD_VERSION " ready.\n");
- rl_readline_name = "birdc";
- rl_add_defun("bird-complete", input_complete, '\t');
- rl_add_defun("bird-help", input_help, '?');
- rl_callback_handler_install("bird> ", input_got_line);
+ rl_readline_name = "birdc";
+ rl_add_defun("bird-complete", input_complete, '\t');
+ rl_add_defun("bird-help", input_help, '?');
+ rl_callback_handler_install("bird> ", input_got_line);
+ }
// rl_get_screen_size();
term_lns = LINES;
term_cls = COLS;
- prompt_active = 1;
-
// readline library does strange things when stdin is nonblocking.
// if (fcntl(0, F_SETFL, O_NONBLOCK) < 0)
// die("fcntl: %m");
void
input_read(void)
{
- rl_callback_read_char();
+ if (interactive)
+ rl_callback_read_char();
+ else
+ simple_input_read();
}
void
#include "client/client.h"
#include "sysdep/unix/unix.h"
-#define INPUT_BUF_LEN 2048
-
struct termios tty_save;
void
input_notify(int prompt)
{
/* No ncurses -> no status to reveal/hide, print prompt manually. */
- if (!prompt)
+ if (!prompt || !interactive)
return;
printf("bird> ");
fflush(stdout);
}
-
-static int
-lastnb(char *str, int i)
-{
- while (i--)
- if ((str[i] != ' ') && (str[i] != '\t'))
- return str[i];
-
- return 0;
-}
-
void
input_read(void)
{
- char buf[INPUT_BUF_LEN];
-
- if ((fgets(buf, INPUT_BUF_LEN, stdin) == NULL) || (buf[0] == 0))
- {
- putchar('\n');
- cleanup();
- exit(0);
- }
-
- int l = strlen(buf);
- if ((l+1) == INPUT_BUF_LEN)
- {
- printf("Input too long.\n");
- return;
- }
-
- if (buf[l-1] == '\n')
- buf[--l] = '\0';
-
- if (!interactive)
- printf("%s\n", buf);
-
- if (l == 0)
- return;
-
- if (lastnb(buf, l) == '?')
- {
- cmd_help(buf, strlen(buf));
- return;
- }
-
- submit_command(buf);
+ simple_input_read();
}
static struct termios stored_tty;
#include "client/reply_codes.h"
#define SERVER_READ_BUF_LEN 4096
+#define INPUT_BUF_LEN 2048
static char *opt_list = "s:vr";
static int verbose, restricted, once;
}
}
+static int
+lastnb(char *str, int i)
+{
+ while (i--)
+ if ((str[i] != ' ') && (str[i] != '\t'))
+ return str[i];
+
+ return 0;
+}
+
+void
+simple_input_read(void)
+{
+ char buf[INPUT_BUF_LEN];
+
+ if ((fgets(buf, INPUT_BUF_LEN, stdin) == NULL) || (buf[0] == 0))
+ {
+ if (interactive)
+ putchar('\n');
+ cleanup();
+ exit(0);
+ }
+
+ int l = strlen(buf);
+ if ((l+1) == INPUT_BUF_LEN)
+ {
+ printf("Input too long.\n");
+ return;
+ }
+
+ if (buf[l-1] == '\n')
+ buf[--l] = '\0';
+
+ if (l == 0)
+ return;
+
+ if (lastnb(buf, l) == '?')
+ {
+ cmd_help(buf, strlen(buf));
+ return;
+ }
+
+ submit_command(buf);
+}
+
static void
select_loop(void)
{
void add_keywords_to_symbols(void);
list *cli_get_symbol_list(void);
uint cli_get_symbol_maxlen(void);
+void simple_input_read(void);
#endif