void ntshell_execute( ntshell_t *p, int (*func_read)(char *buf, int cnt), int (*func_write)(const char *buf, int cnt), int (*func_cb)(const char *text)) { ntshell_user_data_t user_data; user_data.editor = &(p->editor); user_data.history = &(p->history); user_data.func_read = func_read; user_data.func_write = func_write; user_data.func_cb = func_cb; p->parser.user_data = &user_data; vtparse_init(&(p->parser), parser_callback); text_editor_init(GET_EDITOR(&(p->parser))); text_history_init(GET_HISTORY(&(p->parser))); SUGGEST_INDEX(&(p->parser)) = -1; SERIAL_WRITE(&(p->parser), ">", 1); while(1) { unsigned char ch; SERIAL_READ(&(p->parser), (char *)&ch, sizeof(ch)); vtparse(&(p->parser), &ch, sizeof(ch)); } }
struct vtesc_token *vtesc_consume(struct vtesc_executor *executor, char ch) { executor->token.type = VTESC_NOT_COMPLETE; vtparse(&executor->parser, ch); if (executor->token.type != VTESC_NOT_COMPLETE) { return &executor->token; } return NULL; }
int main() { unsigned char buf[1024]; int bytes; vtparse_t parser; vtparse_init(&parser, parser_callback); while(1) { bytes = read(0, buf, 1024); vtparse(&parser, buf, bytes); } }
void BarConsoleFlush() { char buffer[BAR_BUFFER_CAPACITY]; size_t bufferSize = 0; if (g_BarConsole.BufferSize == 0) return; bufferSize = g_BarConsole.BufferSize; memcpy(buffer, g_BarConsole.Buffer, bufferSize); g_BarConsole.BufferSize = 0; vtparse(&g_BarConsole.Parser, buffer, bufferSize); }