From: Sebastian Harl Date: Tue, 4 Feb 2014 22:31:36 +0000 (+0100) Subject: sysdb: Hide implementation details in the "input" module. X-Git-Tag: sysdb-0.1.0~223 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=78fe39914ac0b2faa559a42eff7e9662085c335d;p=sysdb.git sysdb: Hide implementation details in the "input" module. … and added some overview documentation about how the "input" module works and interacts with the other subsystems. --- diff --git a/src/tools/sysdb/input.c b/src/tools/sysdb/input.c index c42390f..f115e3e 100644 --- a/src/tools/sysdb/input.c +++ b/src/tools/sysdb/input.c @@ -25,6 +25,21 @@ * 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 */ @@ -61,6 +76,8 @@ # endif #endif /* READLINEs */ +extern int yylex(void); + /* * public variables */ @@ -189,6 +206,13 @@ sdb_input_init(sdb_input_t *input) 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) { diff --git a/src/tools/sysdb/input.h b/src/tools/sysdb/input.h index 80f1bb5..40bd7c0 100644 --- a/src/tools/sysdb/input.h +++ b/src/tools/sysdb/input.h @@ -56,6 +56,18 @@ extern sdb_input_t *sysdb_input; 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 9b575cc..bc34a48 100644 --- a/src/tools/sysdb/main.c +++ b/src/tools/sysdb/main.c @@ -78,8 +78,6 @@ # define DEFAULT_SOCKET "unix:"LOCALSTATEDIR"/run/sysdbd.sock" #endif -extern int yylex(void); - static void exit_usage(char *name, int status) { @@ -242,7 +240,7 @@ main(int argc, char **argv) input.input = sdb_strbuf_create(2048); sdb_input_init(&input); - yylex(); + sdb_input_mainloop(); if (hist_file[0] != '\0') { errno = 0;