summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d85780c)
raw | patch | inline | side by side (parent: d85780c)
author | Sebastian Harl <sh@tokkee.org> | |
Tue, 4 Feb 2014 22:31:36 +0000 (23:31 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Tue, 4 Feb 2014 22:31:36 +0000 (23:31 +0100) |
… and added some overview documentation about how the "input" module works and
interacts with the other subsystems.
interacts with the other subsystems.
src/tools/sysdb/input.c | patch | blob | history | |
src/tools/sysdb/input.h | patch | blob | history | |
src/tools/sysdb/main.c | patch | blob | history |
index c42390f2d1fafd29801523449bbaa1a0c7192e7e..f115e3e2a51088efdf2dec9e5547ffa1a60642cc 100644 (file)
--- a/src/tools/sysdb/input.c
+++ b/src/tools/sysdb/input.c
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+/*
+ * This module implements the core of the command line tool. It handles all
+ * input from the user and the remote server, interacting with the scanner and
+ * command handling as needed.
+ *
+ * The main loop is managed by the flex scanner which parses the user input.
+ * It will call into this module (using sdb_input_readline()) whenever it
+ * needs further input to continue parsing. Whenever it finds a full query
+ * (terminated by a semicolon), it will hand the query back to this module
+ * (using sdb_input_exec_query()) which will then execute it.
+ *
+ * Most of the process life-time will be spend waiting for input. User input
+ * and (asynchronous) server replies are handled at the same time.
+ */
+
#if HAVE_CONFIG_H
# include "config.h"
#endif /* HAVE_CONFIG_H */
# endif
#endif /* READLINEs */
+extern int yylex(void);
+
/*
* public variables
*/
return 0;
} /* sdb_input_init */
+int
+sdb_input_mainloop(void)
+{
+ yylex();
+ return 0;
+} /* sdb_input_mainloop */
+
ssize_t
sdb_input_readline(char *buf, int *n_chars, size_t max_chars)
{
index 80f1bb5aeb669b6085c0b33c5c3daf65df6426f1..40bd7c0c6d869129b0435febc10271a071e1a9de 100644 (file)
--- a/src/tools/sysdb/input.h
+++ b/src/tools/sysdb/input.h
int
sdb_input_init(sdb_input_t *input);
+/*
+ * sdb_input_mainloop:
+ * Wait for and handle all user and server input until end-of-file is read
+ * from the user (on the standard input channel).
+ *
+ * Returns:
+ * - 0 on success
+ * - a negative value else
+ */
+int
+sdb_input_mainloop(void);
+
/*
* sdb_input_readline:
* This function is supposed to be used with a flex scanner's YY_INPUT. It
diff --git a/src/tools/sysdb/main.c b/src/tools/sysdb/main.c
index 9b575cc825746c47548b87968090c65c0d77b6b2..bc34a480f74ef7ebc9100a91a877aea97f6f2163 100644 (file)
--- a/src/tools/sysdb/main.c
+++ b/src/tools/sysdb/main.c
# define DEFAULT_SOCKET "unix:"LOCALSTATEDIR"/run/sysdbd.sock"
#endif
-extern int yylex(void);
-
static void
exit_usage(char *name, int status)
{
input.input = sdb_strbuf_create(2048);
sdb_input_init(&input);
- yylex();
+ sdb_input_mainloop();
if (hist_file[0] != '\0') {
errno = 0;