summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 535ba6b)
raw | patch | inline | side by side (parent: 535ba6b)
author | Sebastian Harl <sh@tokkee.org> | |
Fri, 10 Jan 2014 09:01:15 +0000 (10:01 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Fri, 10 Jan 2014 09:01:15 +0000 (10:01 +0100) |
Mimic zsh's histignorespace option and ignore commands when the first
character is a space.
character is a space.
index b568aaec3289f0b5dd29c1db48d1d232e7ab2288..30e6419e334d1b105749db8861826f2adf5f2883 100644 (file)
#include <assert.h>
#include <ctype.h>
+#include <string.h>
/*
* public API
*/
-int
+char *
sdb_command_exec(sdb_input_t *input)
{
const char *query;
uint32_t query_len;
+ char *data = NULL;
+
query = sdb_strbuf_string(input->input);
query_len = (uint32_t)input->query_len;
recv_buf = sdb_strbuf_create(1024);
if (! recv_buf)
- return -1;
+ return NULL;
+
+ data = strndup(query, query_len);
+ /* ignore errors; we'll only hide the command from the caller */
sdb_client_send(input->client, CONNECTION_QUERY, query_len, query);
if (sdb_client_recv(input->client, &rcode, recv_buf) < 0)
sdb_strbuf_skip(input->input, 0, input->query_len);
input->tokenizer_pos -= input->query_len;
input->query_len = 0;
- return 0;
+ return data;
} /* sdb_command_exec */
/* vim: set tw=78 sw=4 ts=4 noexpandtab : */
index 3cf9fcad2025e4dc951fdae3763252f24650dddd..06b1ce9f26080faaec92cb91af59a36fe648a679 100644 (file)
/*
* sdb_command_exec:
- * Execute the current command buffer.
+ * Execute the current command buffer and return the query as send to the
+ * server. The query buffer points to dynamically allocated memory which has
+ * to be free'd by the caller.
*
* Returns:
- * - 0 on success
- * - a negative value else
+ * - the query (nul-terminated string) on success
+ * - NULL else
*/
-int
+char *
sdb_command_exec(sdb_input_t *input);
#endif /* SYSDB_COMMAND_H */
index d5deb1dd61b9cf6f26a215ae0efba955a233a48d..dcd12b033d76cbaa61836013617bccde9acb64e4 100644 (file)
--- a/src/tools/sysdb/input.c
+++ b/src/tools/sysdb/input.c
#endif /* HAVE_CONFIG_H */
#include "tools/sysdb/input.h"
+#include "tools/sysdb/command.h"
#include "utils/strbuf.h"
return (ssize_t)len;
} /* sdb_input_readline */
+int
+sdb_input_exec_query(sdb_input_t *input)
+{
+ char *query = sdb_command_exec(input);
+
+ if (! query)
+ return -1;
+
+ if (*query != ' ')
+ add_history(query);
+ free(query);
+ return 0;
+} /* sdb_input_exec_query */
+
/* vim: set tw=78 sw=4 ts=4 noexpandtab : */
index 7fd8d587de8961f70a2107048ca782ed53a39659..00b915beabea13735804bc3c1ebc480630d1aa84 100644 (file)
--- a/src/tools/sysdb/input.h
+++ b/src/tools/sysdb/input.h
sdb_input_readline(sdb_input_t *input, char *buf,
int *n_chars, size_t max_chars);
+/*
+ * sdb_input_exec_query:
+ * Execute the query currently stored in the input buffer. Waits for the
+ * server's reply and prints errors or returned data to standard output.
+ */
+int
+sdb_input_exec_query(sdb_input_t *input);
+
/*
* scanner
*/
index c9b527e7d9cdb74785f891b6ea99553ff478a9b3..518d299bea4707eabd1843b82f375e0c58f6f6c3 100644 (file)
*/
#include "tools/sysdb/input.h"
-#include "tools/sysdb/command.h"
#include <string.h>
* The following rules are specific to the command line tool.
*/
-";" { APPEND(); sdb_command_exec(sdb_input); }
+";" { APPEND(); sdb_input_exec_query(sdb_input); }
. { APPEND(); }