static void edit_read_char(int sock, void *eloop_ctx, void *sock_ctx) { int c; unsigned char buf[1]; int res; res = read(sock, buf, 1); if (res < 0) perror("read"); if (res <= 0) { edit_eof_cb(edit_cb_ctx); return; } c = buf[0]; if (c == '\r' || c == '\n') { cmdbuf[cmdbuf_pos] = '\0'; cmdbuf_pos = 0; edit_cmd_cb(edit_cb_ctx, cmdbuf); printf("> "); fflush(stdout); return; } if (c >= 32 && c <= 255) { if (cmdbuf_pos < (int) sizeof(cmdbuf) - 1) { cmdbuf[cmdbuf_pos++] = c; } } }
static void readline_cmd_handler(char *cmd) { if (cmd && *cmd) { HIST_ENTRY *h; while (next_history()) ; h = previous_history(); if (h == NULL || os_strcmp(cmd, h->line) != 0) add_history(cmd); next_history(); } if (cmd == NULL) { edit_eof_cb(edit_cb_ctx); return; } trunc_nl(cmd); edit_cmd_cb(edit_cb_ctx, cmd); }