#include <inttypes.h>
#include <fcntl.h>
#include <termios.h>
-
#include <netinet/in.h>
#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)
int ret = 0;
int i, same;
- /* XXX use defines instead of hardcoded values */
for (i=0; i<size; i++) {
ret = rdline_char_in(&cl->rdl, 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) {
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;
#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) {
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);
&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 &&
i++;
}
display_right_buffer(rdl);
- return 2; /* ?? */
+ return RDLINE_RES_COMPLETE; /* ?? */
}
/* choice */
rdline_redisplay(rdl);
}
- return 2;
+ return RDLINE_RES_COMPLETE;
case CMDLINE_KEY_RETURN:
case CMDLINE_KEY_RETURN2:
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:
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;
}
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