Lines Matching refs:con
70 static void add_history(console_t *con, const char *line);
71 static uint start_history_cursor(console_t *con);
72 static const char *next_history(console_t *con, uint *cursor);
73 static const char *prev_history(console_t *con, uint *cursor);
74 static void dump_history(console_t *con);
115 static inline char *history_line(console_t *con, uint line) { in history_line() argument
116 return con->history + line * LINE_LEN; in history_line()
127 static void dump_history(console_t *con) { in dump_history() argument
129 uint ptr = ptrprev(con->history_next); in dump_history()
132 if (history_line(con, ptr)[0] != 0) in dump_history() local
133 printf("\t%s\n", history_line(con, ptr)); in dump_history()
138 static void add_history(console_t *con, const char *line) { in add_history() argument
143 size_t last = ptrprev(con->history_next); in add_history()
144 if (strcmp(line, history_line(con, last)) == 0) in add_history()
147 strlcpy(history_line(con, con->history_next), line, LINE_LEN); in add_history()
148 con->history_next = ptrnext(con->history_next); in add_history()
151 static uint start_history_cursor(console_t *con) { in start_history_cursor() argument
152 return ptrprev(con->history_next); in start_history_cursor()
155 static const char *next_history(console_t *con, uint *cursor) { in next_history() argument
158 if (i == con->history_next) in next_history()
162 return history_line(con, i); in next_history()
165 static const char *prev_history(console_t *con, uint *cursor) { in prev_history() argument
167 const char *str = history_line(con, *cursor); in prev_history()
170 if (*cursor == con->history_next) in prev_history()
177 if (history_line(con, i)[0] == '\0') in prev_history() local
187 console_t *con = (console_t *)tls_get(TLS_ENTRY_CONSOLE); in console_get_current() local
188 DEBUG_ASSERT(con); in console_get_current()
189 return con; in console_get_current()
192 console_t *console_set_current(console_t *con) { in console_set_current() argument
194 tls_set(TLS_ENTRY_CONSOLE, (uintptr_t)con); in console_set_current()
195 LTRACEF("setting new %p, old %p\n", con, old); in console_set_current()
263 console_t *con = (console_t *)cookie; in read_debug_line() local
265 uint history_cursor = start_history_cursor(con); in read_debug_line()
268 char *buffer = con->debug_buffer; in read_debug_line()
282 if (con->echo) in read_debug_line()
300 if (con->echo) in read_debug_line()
315 if (con->echo) in read_debug_line()
321 if (con->echo) { in read_debug_line()
332 if (con->echo) { in read_debug_line()
338 strlcpy(buffer, prev_history(con, &history_cursor), LINE_LEN); in read_debug_line()
340 strlcpy(buffer, next_history(con, &history_cursor), LINE_LEN); in read_debug_line()
342 if (con->echo) in read_debug_line()
368 add_history(con, buffer); in read_debug_line()
569 static status_t command_loop(console_t *con, int (*get_line)(const char **, void *), void *get_line… in command_loop() argument
636 mutex_acquire(&con->lock); in command_loop()
638 con->abort_script = false; in command_loop()
639 con->lastresult = command->cmd_callback(argc, args); in command_loop()
645 if (con->lastresult < 0) in command_loop()
646 printf("FAIL %d\n", con->lastresult); in command_loop()
648 printf("PASS %d\n", con->lastresult); in command_loop()
654 env_set_int("?", con->lastresult, true); in command_loop()
658 if (con->abort_script) in command_loop()
660 con->abort_script = false; in command_loop()
663 mutex_release(&con->lock); in command_loop()
681 void console_abort_script(console_t *con) { in console_abort_script() argument
682 if (!con) { in console_abort_script()
683 con = console_get_current(); in console_abort_script()
685 con->abort_script = true; in console_abort_script()
689 console_t *con = calloc(1, sizeof(console_t)); in console_create() local
690 if (!con) { in console_create()
696 mutex_init(&con->lock); in console_create()
697 con->echo = true; in console_create()
698 con->debug_buffer = malloc(LINE_LEN); in console_create()
700 return con; in console_create()
703 void console_start(console_t *con) { in console_start() argument
706 console_set_current(con); in console_start()
708 while (command_loop(con, &read_debug_line, con, true, false) == NO_ERROR) in console_start()
749 static int console_run_script_etc(console_t *con, const char *string, bool locked) { in console_run_script_etc() argument
757 command_loop(con, &fetch_next_line, (void *)&lineread, false, locked); in console_run_script_etc()
761 return con->lastresult; in console_run_script_etc()
764 int console_run_script(console_t *con, const char *string) { in console_run_script() argument
765 if (!con) { in console_run_script()
766 con = console_get_current(); in console_run_script()
768 return console_run_script_etc(con, string, false); in console_run_script()
771 int console_run_script_locked(console_t *con, const char *string) { in console_run_script_locked() argument
772 if (!con) { in console_run_script_locked()
773 con = console_get_current(); in console_run_script_locked()
775 return console_run_script_etc(con, string, true); in console_run_script_locked()