| 132 | } |
| 133 | |
| 134 | int |
| 135 | cmdline_in(struct cmdline *cl, const char *buf, int size) |
| 136 | { |
| 137 | const char *history, *buffer; |
| 138 | size_t histlen, buflen; |
| 139 | int ret = 0; |
| 140 | int i, same; |
| 141 | |
| 142 | if (!cl || !buf) |
| 143 | return -1; |
| 144 | |
| 145 | for (i=0; i<size; i++) { |
| 146 | ret = rdline_char_in(&cl->rdl, buf[i]); |
| 147 | |
| 148 | if (ret == RDLINE_RES_VALIDATED) { |
| 149 | buffer = rdline_get_buffer(&cl->rdl); |
| 150 | history = rdline_get_history_item(&cl->rdl, 0); |
| 151 | if (history) { |
| 152 | histlen = strnlen(history, RDLINE_BUF_SIZE); |
| 153 | same = !memcmp(buffer, history, histlen) && |
| 154 | buffer[histlen] == '\n'; |
| 155 | } |
| 156 | else |
| 157 | same = 0; |
| 158 | buflen = strnlen(buffer, RDLINE_BUF_SIZE); |
| 159 | if (buflen > 1 && !same) |
| 160 | rdline_add_history(&cl->rdl, buffer); |
| 161 | rdline_newline(&cl->rdl, cl->prompt); |
| 162 | } |
| 163 | else if (ret == RDLINE_RES_EOF) |
| 164 | return -1; |
| 165 | else if (ret == RDLINE_RES_EXITED) |
| 166 | return -1; |
| 167 | } |
| 168 | return i; |
| 169 | } |
| 170 | |
| 171 | void |
| 172 | cmdline_quit(struct cmdline *cl) |