From: Olivier Matz Date: Fri, 24 Dec 2010 12:55:04 +0000 (+0100) Subject: cmdline (merge-intel): add cmdline_quit() X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=c39d452741fe5b6c771bb655fa0c827a064f4460;p=libcmdline.git cmdline (merge-intel): add cmdline_quit() Signed-off-by: Olivier Matz --- diff --git a/src/lib/cmdline.c b/src/lib/cmdline.c index 3e52be3..bafaace 100644 --- a/src/lib/cmdline.c +++ b/src/lib/cmdline.c @@ -184,10 +184,18 @@ cmdline_in(struct cmdline *cl, const char *buf, int size) } else if (ret == RDLINE_RES_EOF) return -1; + else if (ret == RDLINE_RES_EXITED) + return -1; } return i; } +void +cmdline_quit(struct cmdline *cl) +{ + rdline_quit(&cl->rdl); +} + void cmdline_interact(struct cmdline *cl) { diff --git a/src/lib/cmdline.h b/src/lib/cmdline.h index c28cf8b..60a3bbb 100644 --- a/src/lib/cmdline.h +++ b/src/lib/cmdline.h @@ -82,5 +82,6 @@ void cmdline_printf(const struct cmdline *cl, const char *fmt, ...); int cmdline_in(struct cmdline *cl, const char *buf, int size); void cmdline_write_char(struct rdline *rdl, char c); void cmdline_interact(struct cmdline *cl); +void cmdline_quit(struct cmdline *cl); #endif /* _CMDLINE_SOCKET_H_ */ diff --git a/src/lib/cmdline_rdline.c b/src/lib/cmdline_rdline.c index 15f096d..d5eac3b 100644 --- a/src/lib/cmdline_rdline.c +++ b/src/lib/cmdline_rdline.c @@ -135,6 +135,12 @@ rdline_stop(struct rdline *rdl) rdl->status = RDLINE_INIT; } +void +rdline_quit(struct rdline *rdl) +{ + rdl->status = RDLINE_EXITED; +} + void rdline_restart(struct rdline *rdl) { @@ -198,6 +204,8 @@ rdline_char_in(struct rdline *rdl, char c) char *buf; #endif + if (rdl->status == RDLINE_EXITED) + return RDLINE_RES_EXITED; if (rdl->status != RDLINE_RUNNING) return RDLINE_RES_NOT_RUNNING; @@ -413,6 +421,9 @@ rdline_char_in(struct rdline *rdl, char c) if (rdl->validate) rdl->validate(rdl, rdl->left_buf, CIRBUF_GET_LEN(&rdl->left)+2); + /* user may have stopped rdline */ + if (rdl->status == RDLINE_EXITED) + return RDLINE_RES_EXITED; return RDLINE_RES_VALIDATED; #ifndef NO_RDLINE_HISTORY diff --git a/src/lib/cmdline_rdline.h b/src/lib/cmdline_rdline.h index 1118b29..a6b3275 100644 --- a/src/lib/cmdline_rdline.h +++ b/src/lib/cmdline_rdline.h @@ -97,7 +97,8 @@ enum rdline_status { RDLINE_INIT, - RDLINE_RUNNING + RDLINE_RUNNING, + RDLINE_EXITED }; struct rdline; @@ -174,7 +175,14 @@ void rdline_newline(struct rdline *rdl, const char *prompt); void rdline_stop(struct rdline *rdl); /** - * Restart after a call to rdline_stop() + * Same than rdline_stop() except that next calls to rdline_char_in() + * will return RDLINE_RES_EXITED. + * \param rdl A pointer to a struct rdline + */ +void rdline_quit(struct rdline *rdl); + +/** + * Restart after a call to rdline_stop() or rdline_quit() * \param rdl A pointer to a struct rdline */ void rdline_restart(struct rdline *rdl); @@ -192,6 +200,7 @@ void rdline_redisplay(struct rdline *rdl); #define RDLINE_RES_COMPLETE 2 #define RDLINE_RES_NOT_RUNNING -1 #define RDLINE_RES_EOF -2 +#define RDLINE_RES_EXITED -3 /** * append a char to the readline buffer.