summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 52fd6fa)
raw | patch | inline | side by side (parent: 52fd6fa)
author | Sebastian Harl <sh@tokkee.org> | |
Sat, 19 Jul 2014 12:06:33 +0000 (14:06 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Sat, 19 Jul 2014 12:06:33 +0000 (14:06 +0200) |
libedit's implementation of the callback-mode does not play well in
non-interactive mode (e.g. it does not correctly detect EOF) but works fine
when using readline().
Also, there's no need for the somewhat more complex callback mode in
non-interactive operation anyway.
non-interactive mode (e.g. it does not correctly detect EOF) but works fine
when using readline().
Also, there's no need for the somewhat more complex callback mode in
non-interactive operation anyway.
src/tools/sysdb/input.c | patch | blob | history | |
src/tools/sysdb/input.h | patch | blob | history |
index 8d91048e35c5714fe7522f112aa5e736208b5a85..21a2e5d3112fe2b2da323ea2af782e8b95cb2626 100644 (file)
--- a/src/tools/sysdb/input.c
+++ b/src/tools/sysdb/input.c
#include "utils/error.h"
#include "utils/strbuf.h"
+#include <errno.h>
+
#include <sys/select.h>
#include <stdio.h>
sdb_strbuf_append(sysdb_input->input, "\n");
free(line);
- rl_callback_handler_remove();
+ if (sysdb_input->interactive)
+ rl_callback_handler_remove();
} /* handle_input */
/* wait for a new line of data to be available */
const char *prompt = "sysdb=> ";
+ len = sdb_strbuf_len(sysdb_input->input);
+
+ if (! sysdb_input->interactive) {
+ char *line = readline("");
+ handle_input(line);
+ return (ssize_t)(sdb_strbuf_len(sysdb_input->input) - len);
+ }
+
if (sysdb_input->query_len)
prompt = "sysdb-> ";
rl_callback_handler_install(prompt, handle_input);
client_fd = sdb_client_sockfd(sysdb_input->client);
-
- len = sdb_strbuf_len(sysdb_input->input);
while ((sdb_strbuf_len(sysdb_input->input) == len)
&& (! sysdb_input->eof)) {
int n;
/* register input handler */
sysdb_input = input;
- if (! isatty(STDIN_FILENO))
- return -1;
-
- term_rawmode();
+ input->interactive = isatty(STDIN_FILENO) != 0;
+ errno = 0;
+ if (input->interactive)
+ term_rawmode();
return 0;
} /* sdb_input_init */
index 35b37b800b80f2b6651a43d195beee174bca3c8f..ccdce039881ca27893c53e3d5e0cb6ee6ea4cca0 100644 (file)
--- a/src/tools/sysdb/input.h
+++ b/src/tools/sysdb/input.h
size_t tokenizer_pos;
size_t query_len;
+ _Bool interactive;
_Bool eof;
} sdb_input_t;
-#define SDB_INPUT_INIT { NULL, NULL, 0, 0, 0 }
+#define SDB_INPUT_INIT { NULL, NULL, 0, 0, 1, 0 }
/*
* sysdb_input: