char *get_from_buf(int *len) { int end_ind = end_of_str(buffer + processed_ind, read_ind); char *res = NULL; if (end_ind < 0) { return NULL; } else { res = buffer + processed_ind; *len = (end_ind + 1) - processed_ind; processed_ind = end_ind + 1; return res; } }
static unsigned char esl_console_complete(const char *buffer, const char *cursor, const char *lastchar) { char cmd_str[2048] = ""; unsigned char ret = CC_REDISPLAY; char *dup = _strndup(buffer, (int)(lastchar - buffer)); char *buf = dup; int sc = 0, offset = (int)(cursor - buffer), pos = (offset > 0) ? offset : 0; char *p; if (pos > 0) { *(buf + pos) = '\0'; } if ((p = strchr(buf, '\r')) || (p = strchr(buf, '\n'))) { *p = '\0'; } while (*buf == ' ') { buf++; sc++; } #ifdef HAVE_EDITLINE if (!*buf && sc) { el_deletestr(el, sc); sc = 0; } #endif p = end_of_str(buf); while(p >= buf && *p == ' ') { sc++; p--; } #ifdef HAVE_EDITLINE if (sc > 1) { el_deletestr(el, sc - 1); *(p + 2) = '\0'; } #endif if (*cursor) { snprintf(cmd_str, sizeof(cmd_str), "api console_complete c=%ld;%s\n\n", (long)pos, buf); } else { snprintf(cmd_str, sizeof(cmd_str), "api console_complete %s\n\n", buf); } esl_send_recv(global_handle, cmd_str); if (global_handle->last_sr_event && global_handle->last_sr_event->body) { char *r = global_handle->last_sr_event->body; char *w, *p1; if (r) { if ((w = strstr(r, "\n\nwrite="))) { int len = 0; *w = '\0'; w += 8; len = atoi(w); if ((p1= strchr(w, ':'))) { w = p1+ 1; } printf("%s\n\n\n", r); #ifdef HAVE_EDITLINE el_deletestr(el, len); el_insertstr(el, w); #else #ifdef _MSC_VER console_bufferInput(0, len, (char*)buffer, DELETE_REFRESH_OP); console_bufferInput(w, (int)strlen(w), (char*)buffer, 0); #endif #endif } else { printf("%s\n", r); #ifdef _MSC_VER console_bufferInput(0, 0, (char*)buffer, DELETE_REFRESH_OP); #endif } } fflush(stdout); } esl_safe_free(dup); return ret; }