From: Olivier Matz Date: Fri, 24 Dec 2010 12:54:31 +0000 (+0100) Subject: cmdline (merge-intel): replace harcoded return values with defines X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=459a3fb8149c6112631c6c54ef02bc38bb52b950;p=libcmdline.git cmdline (merge-intel): replace harcoded return values with defines Signed-off-by: Olivier Matz --- diff --git a/src/lib/cmdline.c b/src/lib/cmdline.c index 31af819..3e52be3 100644 --- a/src/lib/cmdline.c +++ b/src/lib/cmdline.c @@ -67,19 +67,12 @@ #include #include #include - #include #include "cmdline_parse.h" #include "cmdline_rdline.h" #include "cmdline.h" - -#define PROMPT_SUFFIX "> " - - -/**********************/ - static void cmdline_valid_buffer(struct rdline *rdl, const char *buf, __attribute__((unused)) unsigned int size) @@ -173,11 +166,10 @@ cmdline_in(struct cmdline *cl, const char *buf, int size) int ret = 0; int i, same; - /* XXX use defines instead of hardcoded values */ for (i=0; irdl, buf[i]); - if (ret == 1) { + if (ret == RDLINE_RES_VALIDATED) { buffer = rdline_get_buffer(&cl->rdl); history = rdline_get_history_item(&cl->rdl, 0); if (history) { @@ -190,7 +182,7 @@ cmdline_in(struct cmdline *cl, const char *buf, int size) rdline_add_history(&cl->rdl, buffer); rdline_newline(&cl->rdl, cl->prompt); } - else if (ret == -2) + else if (ret == RDLINE_RES_EOF) return -1; } return i; diff --git a/src/lib/cmdline_rdline.c b/src/lib/cmdline_rdline.c index 6c2d9dd..44ad5ed 100644 --- a/src/lib/cmdline_rdline.c +++ b/src/lib/cmdline_rdline.c @@ -197,11 +197,11 @@ rdline_char_in(struct rdline *rdl, char c) #endif if (rdl->status != RDLINE_RUNNING) - return -1; + return RDLINE_RES_NOT_RUNNING; cmd = vt100_parser(&rdl->vt100, c); if (cmd == -2) - return 0; + return RDLINE_RES_SUCCESS; if (cmd >= 0) { switch (cmd) { @@ -283,7 +283,7 @@ rdline_char_in(struct rdline *rdl, char c) if (cmd == CMDLINE_KEY_CTRL_D && CIRBUF_IS_EMPTY(&rdl->left) && CIRBUF_IS_EMPTY(&rdl->right)) { - return -2; + return RDLINE_RES_EOF; } if (!cirbuf_del_head_safe(&rdl->right)) { display_right_buffer(rdl); @@ -365,12 +365,12 @@ rdline_char_in(struct rdline *rdl, char c) &complete_state); /* no completion or error */ if (ret <= 0) { - return 2; + return RDLINE_RES_COMPLETE; } tmp_size = strlen(tmp_buf); /* add chars */ - if (ret == 2) { + if (ret == RDLINE_RES_COMPLETE) { i=0; while(CIRBUF_GET_LEN(&rdl->right) + CIRBUF_GET_LEN(&rdl->left) < RDLINE_BUF_SIZE && @@ -380,7 +380,7 @@ rdline_char_in(struct rdline *rdl, char c) i++; } display_right_buffer(rdl); - return 2; /* ?? */ + return RDLINE_RES_COMPLETE; /* ?? */ } /* choice */ @@ -397,7 +397,7 @@ rdline_char_in(struct rdline *rdl, char c) rdline_redisplay(rdl); } - return 2; + return RDLINE_RES_COMPLETE; case CMDLINE_KEY_RETURN: case CMDLINE_KEY_RETURN2: @@ -411,7 +411,7 @@ rdline_char_in(struct rdline *rdl, char c) if (rdl->validate) rdl->validate(rdl, rdl->left_buf, CIRBUF_GET_LEN(&rdl->left)+2); - return 1; + return RDLINE_RES_VALIDATED; #ifndef NO_RDLINE_HISTORY case CMDLINE_KEY_UP_ARR: @@ -457,23 +457,23 @@ rdline_char_in(struct rdline *rdl, char c) break; } - return 0; + return RDLINE_RES_SUCCESS; } if (!isprint((int)c)) - return 0; + return RDLINE_RES_SUCCESS; /* standard chars */ if (CIRBUF_GET_LEN(&rdl->left) + CIRBUF_GET_LEN(&rdl->right) >= RDLINE_BUF_SIZE) - return 0; + return RDLINE_RES_SUCCESS; if (cirbuf_add_tail_safe(&rdl->left, c)) - return 0; + return RDLINE_RES_SUCCESS; rdl->write_char(rdl, c); display_right_buffer(rdl); - return 0; + return RDLINE_RES_SUCCESS; } diff --git a/src/lib/cmdline_rdline.h b/src/lib/cmdline_rdline.h index 702a0ab..1129cb8 100644 --- a/src/lib/cmdline_rdline.h +++ b/src/lib/cmdline_rdline.h @@ -208,13 +208,20 @@ void rdline_restart(struct rdline *rdl); void rdline_redisplay(struct rdline *rdl); +/* return status for rdline_char_in() */ +#define RDLINE_RES_SUCCESS 0 +#define RDLINE_RES_VALIDATED 1 +#define RDLINE_RES_COMPLETE 2 +#define RDLINE_RES_NOT_RUNNING -1 +#define RDLINE_RES_EOF -2 + /** * append a char to the readline buffer. - * Return 1 when the line has been validated. - * Return 2 when the user asked to complete the buffer. - * Return -1 if it is not running. - * Return -2 if EOF (ctrl-d on an empty line). - * Else return 0. + * Return RDLINE_RES_VALIDATE when the line has been validated. + * Return RDLINE_RES_COMPLETE when the user asked to complete the buffer. + * Return RDLINE_RES_NOT_RUNNING if it is not running. + * Return RDLINE_RES_EOF if EOF (ctrl-d on an empty line). + * Else return RDLINE_RES_SUCCESS. * XXX error case when the buffer is full ? * * \param rdl A pointer to a struct rdline