Lines Matching refs:h
173 bc_history_init(BcHistory* h) in bc_history_init() argument
197 h->hist = history_init(); in bc_history_init()
198 if (BC_ERR(h->hist == NULL)) bc_vm_fatalError(BC_ERR_FATAL_ALLOC_ERR); in bc_history_init()
200 h->el = el_init(vm->name, stdin, stdout, stderr); in bc_history_init()
201 if (BC_ERR(h->el == NULL)) bc_vm_fatalError(BC_ERR_FATAL_ALLOC_ERR); in bc_history_init()
204 history(h->hist, &bc_history_event, H_SETSIZE, 100); in bc_history_init()
205 history(h->hist, &bc_history_event, H_SETUNIQUE, 1); in bc_history_init()
206 el_set(h->el, EL_EDITOR, "emacs"); in bc_history_init()
207 el_set(h->el, EL_HIST, history, h->hist); in bc_history_init()
208 el_set(h->el, EL_PROMPT, bc_history_promptFunc); in bc_history_init()
211 el_source(h->el, v.v); in bc_history_init()
215 h->badTerm = false; in bc_history_init()
220 bc_history_free(BcHistory* h) in bc_history_free() argument
223 el_end(h->el); in bc_history_free()
224 history_end(h->hist); in bc_history_free()
228 bc_history_line(BcHistory* h, BcVec* vec, const char* prompt) in bc_history_line() argument
280 line = el_gets(h->el, &len); in bc_history_line()
306 history(h->hist, &bc_history_event, H_ENTER, line); in bc_history_line()
336 bc_history_init(BcHistory* h) in bc_history_init() argument
338 h->line = NULL; in bc_history_init()
339 h->badTerm = false; in bc_history_init()
346 bc_history_free(BcHistory* h) in bc_history_free() argument
348 if (h->line != NULL) free(h->line); in bc_history_free()
352 bc_history_line(BcHistory* h, BcVec* vec, const char* prompt) in bc_history_line() argument
370 if (h->line != NULL) in bc_history_line()
372 free(h->line); in bc_history_line()
373 h->line = NULL; in bc_history_line()
377 h->line = readline(BC_PROMPT ? prompt : ""); in bc_history_line()
381 if (h->line != NULL && h->line[0]) in bc_history_line()
383 add_history(h->line); in bc_history_line()
385 len = strlen(h->line); in bc_history_line()
389 bc_vec_string(vec, len, h->line); in bc_history_line()
392 else if (h->line == NULL) in bc_history_line()
831 bc_history_enableRaw(BcHistory* h) in bc_history_enableRaw() argument
842 if (h->rawMode) return; in bc_history_enableRaw()
846 if (BC_ERR(tcgetattr(STDIN_FILENO, &h->orig_termios) == -1)) in bc_history_enableRaw()
854 raw = h->orig_termios; in bc_history_enableRaw()
886 h->rawMode = true; in bc_history_enableRaw()
894 bc_history_disableRaw(BcHistory* h) in bc_history_disableRaw() argument
898 if (!h->rawMode) return; in bc_history_disableRaw()
903 if (BC_ERR(tcsetattr(STDIN_FILENO, TCSAFLUSH, &h->orig_termios) != -1)) in bc_history_disableRaw()
905 h->rawMode = false; in bc_history_disableRaw()
1045 bc_history_refresh(BcHistory* h) in bc_history_refresh() argument
1047 char* buf = h->buf.v; in bc_history_refresh()
1048 size_t colpos, len = BC_HIST_BUF_LEN(h), pos = h->pos, extras_len = 0; in bc_history_refresh()
1055 while (h->pcol + bc_history_colPos(buf, len, pos) >= h->cols) in bc_history_refresh()
1065 while (h->pcol + bc_history_colPos(buf, len, len) > h->cols) in bc_history_refresh()
1075 if (h->extras.len > 1) in bc_history_refresh()
1077 extras_len = h->extras.len - 1; in bc_history_refresh()
1079 bc_vec_grow(&h->buf, extras_len); in bc_history_refresh()
1084 bc_file_write(&vm->fout, bc_flush_none, h->extras.v, extras_len); in bc_history_refresh()
1088 if (BC_PROMPT) bc_file_write(&vm->fout, bc_flush_none, h->prompt, h->plen); in bc_history_refresh()
1090 bc_file_write(&vm->fout, bc_flush_none, h->buf.v, len - extras_len); in bc_history_refresh()
1096 if (pos >= h->buf.len - extras_len) bc_vec_grow(&h->buf, pos + extras_len); in bc_history_refresh()
1102 colpos = bc_history_colPos(h->buf.v, len - extras_len, pos) + h->pcol; in bc_history_refresh()
1117 bc_history_edit_insert(BcHistory* h, const char* cbuf, size_t clen) in bc_history_edit_insert() argument
1121 bc_vec_grow(&h->buf, clen); in bc_history_edit_insert()
1124 if (h->pos == BC_HIST_BUF_LEN(h)) in bc_history_edit_insert()
1129 memcpy(bc_vec_item(&h->buf, h->pos), cbuf, clen); in bc_history_edit_insert()
1132 h->pos += clen; in bc_history_edit_insert()
1133 h->buf.len += clen - 1; in bc_history_edit_insert()
1134 bc_vec_pushByte(&h->buf, '\0'); in bc_history_edit_insert()
1137 len = BC_HIST_BUF_LEN(h) + h->extras.len - 1; in bc_history_edit_insert()
1138 colpos = bc_history_promptColLen(h->prompt, h->plen); in bc_history_edit_insert()
1139 colpos += bc_history_colPos(h->buf.v, len, len); in bc_history_edit_insert()
1142 if (colpos < h->cols) in bc_history_edit_insert()
1148 else bc_history_refresh(h); in bc_history_edit_insert()
1153 size_t amt = BC_HIST_BUF_LEN(h) - h->pos; in bc_history_edit_insert()
1156 memmove(h->buf.v + h->pos + clen, h->buf.v + h->pos, amt); in bc_history_edit_insert()
1157 memcpy(h->buf.v + h->pos, cbuf, clen); in bc_history_edit_insert()
1160 h->pos += clen; in bc_history_edit_insert()
1161 h->buf.len += clen; in bc_history_edit_insert()
1162 h->buf.v[BC_HIST_BUF_LEN(h)] = '\0'; in bc_history_edit_insert()
1164 bc_history_refresh(h); in bc_history_edit_insert()
1173 bc_history_edit_left(BcHistory* h) in bc_history_edit_left() argument
1178 if (h->pos <= 0) return; in bc_history_edit_left()
1180 h->pos -= bc_history_prevLen(h->buf.v, h->pos); in bc_history_edit_left()
1182 bc_history_refresh(h); in bc_history_edit_left()
1190 bc_history_edit_right(BcHistory* h) in bc_history_edit_right() argument
1195 if (h->pos == BC_HIST_BUF_LEN(h)) return; in bc_history_edit_right()
1197 h->pos += bc_history_nextLen(h->buf.v, BC_HIST_BUF_LEN(h), h->pos, NULL); in bc_history_edit_right()
1199 bc_history_refresh(h); in bc_history_edit_right()
1207 bc_history_edit_wordEnd(BcHistory* h) in bc_history_edit_wordEnd() argument
1209 size_t len = BC_HIST_BUF_LEN(h); in bc_history_edit_wordEnd()
1214 if (!len || h->pos >= len) return; in bc_history_edit_wordEnd()
1217 while (h->pos < len && isspace(h->buf.v[h->pos])) in bc_history_edit_wordEnd()
1219 h->pos += 1; in bc_history_edit_wordEnd()
1221 while (h->pos < len && !isspace(h->buf.v[h->pos])) in bc_history_edit_wordEnd()
1223 h->pos += 1; in bc_history_edit_wordEnd()
1226 bc_history_refresh(h); in bc_history_edit_wordEnd()
1234 bc_history_edit_wordStart(BcHistory* h) in bc_history_edit_wordStart() argument
1236 size_t len = BC_HIST_BUF_LEN(h); in bc_history_edit_wordStart()
1244 while (h->pos > 0 && isspace(h->buf.v[h->pos - 1])) in bc_history_edit_wordStart()
1246 h->pos -= 1; in bc_history_edit_wordStart()
1248 while (h->pos > 0 && !isspace(h->buf.v[h->pos - 1])) in bc_history_edit_wordStart()
1250 h->pos -= 1; in bc_history_edit_wordStart()
1253 bc_history_refresh(h); in bc_history_edit_wordStart()
1261 bc_history_edit_home(BcHistory* h) in bc_history_edit_home() argument
1266 if (!h->pos) return; in bc_history_edit_home()
1268 h->pos = 0; in bc_history_edit_home()
1270 bc_history_refresh(h); in bc_history_edit_home()
1278 bc_history_edit_end(BcHistory* h) in bc_history_edit_end() argument
1283 if (h->pos == BC_HIST_BUF_LEN(h)) return; in bc_history_edit_end()
1285 h->pos = BC_HIST_BUF_LEN(h); in bc_history_edit_end()
1287 bc_history_refresh(h); in bc_history_edit_end()
1297 bc_history_edit_next(BcHistory* h, bool dir) in bc_history_edit_next() argument
1305 if (h->history.len <= 1) return; in bc_history_edit_next()
1308 if (h->buf.v[0]) dup = bc_vm_strdup(h->buf.v); in bc_history_edit_next()
1312 bc_vec_replaceAt(&h->history, h->history.len - 1 - h->idx, &dup); in bc_history_edit_next()
1315 h->idx += (dir == BC_HIST_PREV ? 1 : SIZE_MAX); in bc_history_edit_next()
1318 if (h->idx == SIZE_MAX) in bc_history_edit_next()
1320 h->idx = 0; in bc_history_edit_next()
1323 else if (h->idx >= h->history.len) in bc_history_edit_next()
1325 h->idx = h->history.len - 1; in bc_history_edit_next()
1330 str = *((char**) bc_vec_item(&h->history, h->history.len - 1 - h->idx)); in bc_history_edit_next()
1331 bc_vec_string(&h->buf, strlen(str), str); in bc_history_edit_next()
1333 assert(h->buf.len > 0); in bc_history_edit_next()
1336 h->pos = BC_HIST_BUF_LEN(h); in bc_history_edit_next()
1338 bc_history_refresh(h); in bc_history_edit_next()
1347 bc_history_edit_delete(BcHistory* h) in bc_history_edit_delete() argument
1349 size_t chlen, len = BC_HIST_BUF_LEN(h); in bc_history_edit_delete()
1354 if (!len || h->pos >= len) return; in bc_history_edit_delete()
1357 chlen = bc_history_nextLen(h->buf.v, len, h->pos, NULL); in bc_history_edit_delete()
1360 memmove(h->buf.v + h->pos, h->buf.v + h->pos + chlen, len - h->pos - chlen); in bc_history_edit_delete()
1363 h->buf.len -= chlen; in bc_history_edit_delete()
1364 h->buf.v[BC_HIST_BUF_LEN(h)] = '\0'; in bc_history_edit_delete()
1366 bc_history_refresh(h); in bc_history_edit_delete()
1375 bc_history_edit_backspace(BcHistory* h) in bc_history_edit_backspace() argument
1377 size_t chlen, len = BC_HIST_BUF_LEN(h); in bc_history_edit_backspace()
1382 if (!h->pos || !len) return; in bc_history_edit_backspace()
1385 chlen = bc_history_prevLen(h->buf.v, h->pos); in bc_history_edit_backspace()
1388 memmove(h->buf.v + h->pos - chlen, h->buf.v + h->pos, len - h->pos); in bc_history_edit_backspace()
1391 h->pos -= chlen; in bc_history_edit_backspace()
1392 h->buf.len -= chlen; in bc_history_edit_backspace()
1393 h->buf.v[BC_HIST_BUF_LEN(h)] = '\0'; in bc_history_edit_backspace()
1395 bc_history_refresh(h); in bc_history_edit_backspace()
1404 bc_history_edit_deletePrevWord(BcHistory* h) in bc_history_edit_deletePrevWord() argument
1406 size_t diff, old_pos = h->pos; in bc_history_edit_deletePrevWord()
1414 while (h->pos > 0 && isspace(h->buf.v[h->pos - 1])) in bc_history_edit_deletePrevWord()
1416 h->pos -= 1; in bc_history_edit_deletePrevWord()
1418 while (h->pos > 0 && !isspace(h->buf.v[h->pos - 1])) in bc_history_edit_deletePrevWord()
1420 h->pos -= 1; in bc_history_edit_deletePrevWord()
1424 diff = old_pos - h->pos; in bc_history_edit_deletePrevWord()
1427 memmove(h->buf.v + h->pos, h->buf.v + old_pos, in bc_history_edit_deletePrevWord()
1428 BC_HIST_BUF_LEN(h) - old_pos + 1); in bc_history_edit_deletePrevWord()
1431 h->buf.len -= diff; in bc_history_edit_deletePrevWord()
1433 bc_history_refresh(h); in bc_history_edit_deletePrevWord()
1441 bc_history_edit_deleteNextWord(BcHistory* h) in bc_history_edit_deleteNextWord() argument
1443 size_t next_end = h->pos, len = BC_HIST_BUF_LEN(h); in bc_history_edit_deleteNextWord()
1451 while (next_end < len && isspace(h->buf.v[next_end])) in bc_history_edit_deleteNextWord()
1455 while (next_end < len && !isspace(h->buf.v[next_end])) in bc_history_edit_deleteNextWord()
1461 memmove(h->buf.v + h->pos, h->buf.v + next_end, len - next_end); in bc_history_edit_deleteNextWord()
1464 h->buf.len -= next_end - h->pos; in bc_history_edit_deleteNextWord()
1466 bc_history_refresh(h); in bc_history_edit_deleteNextWord()
1474 bc_history_swap(BcHistory* h) in bc_history_swap() argument
1482 if (!h->pos) return; in bc_history_swap()
1485 pcl = bc_history_prevLen(h->buf.v, h->pos); in bc_history_swap()
1486 ncl = bc_history_nextLen(h->buf.v, BC_HIST_BUF_LEN(h), h->pos, NULL); in bc_history_swap()
1491 if (pcl && h->pos != BC_HIST_BUF_LEN(h) && pcl < 5 && ncl < 5) in bc_history_swap()
1494 memcpy(auxb, h->buf.v + h->pos - pcl, pcl); in bc_history_swap()
1495 memcpy(h->buf.v + h->pos - pcl, h->buf.v + h->pos, ncl); in bc_history_swap()
1496 memcpy(h->buf.v + h->pos - pcl + ncl, auxb, pcl); in bc_history_swap()
1499 h->pos += ((~pcl) + 1) + ncl; in bc_history_swap()
1501 bc_history_refresh(h); in bc_history_swap()
1511 bc_history_raise(BcHistory* h, int sig) in bc_history_raise() argument
1514 bc_history_disableRaw(h); in bc_history_raise()
1524 bc_history_escape(BcHistory* h) in bc_history_escape() argument
1538 if (c == 'f') bc_history_edit_wordEnd(h); in bc_history_escape()
1539 else if (c == 'b') bc_history_edit_wordStart(h); in bc_history_escape()
1540 else if (c == 'd') bc_history_edit_deleteNextWord(h); in bc_history_escape()
1569 bc_history_edit_home(h); in bc_history_escape()
1575 bc_history_edit_delete(h); in bc_history_escape()
1581 bc_history_edit_end(h); in bc_history_escape()
1600 else if (seq[1] == 'C') bc_history_edit_wordEnd(h); in bc_history_escape()
1601 else if (seq[1] == 'D') bc_history_edit_wordStart(h); in bc_history_escape()
1611 bc_history_edit_next(h, BC_HIST_PREV); in bc_history_escape()
1618 bc_history_edit_next(h, BC_HIST_NEXT); in bc_history_escape()
1625 bc_history_edit_right(h); in bc_history_escape()
1632 bc_history_edit_left(h); in bc_history_escape()
1640 bc_history_edit_home(h); in bc_history_escape()
1648 bc_history_edit_end(h); in bc_history_escape()
1654 bc_history_edit_deleteNextWord(h); in bc_history_escape()
1667 bc_history_edit_next(h, BC_HIST_PREV); in bc_history_escape()
1673 bc_history_edit_next(h, BC_HIST_NEXT); in bc_history_escape()
1679 bc_history_edit_right(h); in bc_history_escape()
1685 bc_history_edit_left(h); in bc_history_escape()
1691 bc_history_edit_end(h); in bc_history_escape()
1697 bc_history_edit_home(h); in bc_history_escape()
1711 bc_history_add(BcHistory* h, char* line) in bc_history_add() argument
1716 if (h->history.len) in bc_history_add()
1719 char* s = *((char**) bc_vec_item_rev(&h->history, 0)); in bc_history_add()
1729 bc_vec_push(&h->history, &line); in bc_history_add()
1738 bc_history_add_empty(BcHistory* h) in bc_history_add_empty() argument
1745 if (h->history.len) in bc_history_add_empty()
1748 char* s = *((char**) bc_vec_item_rev(&h->history, 0)); in bc_history_add_empty()
1754 bc_vec_push(&h->history, &line); in bc_history_add_empty()
1762 bc_history_reset(BcHistory* h) in bc_history_reset() argument
1766 h->oldcolpos = h->pos = h->idx = 0; in bc_history_reset()
1767 h->cols = bc_history_columns(); in bc_history_reset()
1771 bc_history_add_empty(h); in bc_history_reset()
1774 bc_vec_empty(&h->buf); in bc_history_reset()
1783 bc_history_printCtrl(BcHistory* h, unsigned int c) in bc_history_printCtrl() argument
1794 bc_vec_concat(&h->buf, str); in bc_history_printCtrl()
1796 h->pos = BC_HIST_BUF_LEN(h); in bc_history_printCtrl()
1797 bc_history_refresh(h); in bc_history_printCtrl()
1800 bc_vec_npop(&h->buf, sizeof(str)); in bc_history_printCtrl()
1801 bc_vec_pushByte(&h->buf, '\0'); in bc_history_printCtrl()
1802 h->pos = 0; in bc_history_printCtrl()
1809 bc_history_refresh(h); in bc_history_printCtrl()
1822 bc_history_edit(BcHistory* h, const char* prompt) in bc_history_edit() argument
1826 bc_history_reset(h); in bc_history_edit()
1836 h->prompt = prompt; in bc_history_edit()
1837 h->plen = strlen(prompt); in bc_history_edit()
1838 h->pcol = bc_history_promptColLen(prompt, h->plen); in bc_history_edit()
1840 bc_file_write(&vm->fout, bc_flush_none, prompt, h->plen); in bc_history_edit()
1866 bc_vec_pop(&h->history); in bc_history_edit()
1875 bc_history_edit_insert(h, cbuf, bc_history_tab_len); in bc_history_edit()
1881 bc_history_printCtrl(h, c); in bc_history_edit()
1895 bc_history_reset(h); in bc_history_edit()
1896 bc_history_refresh(h); in bc_history_edit()
1904 bc_history_edit_backspace(h); in bc_history_edit()
1913 if (BC_HIST_BUF_LEN(h) == 0) in bc_history_edit()
1915 bc_history_printCtrl(h, c); in bc_history_edit()
1920 bc_history_edit_delete(h); in bc_history_edit()
1928 bc_history_swap(h); in bc_history_edit()
1934 bc_history_edit_left(h); in bc_history_edit()
1940 bc_history_edit_right(h); in bc_history_edit()
1946 bc_history_edit_next(h, BC_HIST_PREV); in bc_history_edit()
1952 bc_history_edit_next(h, BC_HIST_NEXT); in bc_history_edit()
1958 bc_history_escape(h); in bc_history_edit()
1965 bc_vec_string(&h->buf, 0, ""); in bc_history_edit()
1966 h->pos = 0; in bc_history_edit()
1968 bc_history_refresh(h); in bc_history_edit()
1976 bc_vec_npop(&h->buf, h->buf.len - h->pos); in bc_history_edit()
1977 bc_vec_pushByte(&h->buf, '\0'); in bc_history_edit()
1978 bc_history_refresh(h); in bc_history_edit()
1985 bc_history_edit_home(h); in bc_history_edit()
1992 bc_history_edit_end(h); in bc_history_edit()
2000 bc_history_refresh(h); in bc_history_edit()
2007 bc_history_edit_deletePrevWord(h); in bc_history_edit()
2018 bc_history_printCtrl(h, c); in bc_history_edit()
2020 if (c == BC_ACTION_CTRL_Z) bc_history_raise(h, SIGTSTP); in bc_history_edit()
2021 if (c == BC_ACTION_CTRL_S) bc_history_raise(h, SIGSTOP); in bc_history_edit()
2024 bc_history_raise(h, SIGQUIT); in bc_history_edit()
2033 else bc_history_edit_insert(h, cbuf, nread); in bc_history_edit()
2050 bc_history_stdinHasData(BcHistory* h) in bc_history_stdinHasData() argument
2054 return pselect(1, &h->rdset, NULL, NULL, &h->ts, &h->sigmask) > 0 || in bc_history_stdinHasData()
2062 bc_history_line(BcHistory* h, BcVec* vec, const char* prompt) in bc_history_line() argument
2069 bc_history_enableRaw(h); in bc_history_line()
2074 s = bc_history_edit(h, prompt); in bc_history_line()
2083 if (h->buf.v[0]) in bc_history_line()
2086 line = bc_vm_strdup(h->buf.v); in bc_history_line()
2089 bc_history_add(h, line); in bc_history_line()
2092 else bc_history_add_empty(h); in bc_history_line()
2097 bc_vec_concat(vec, h->buf.v); in bc_history_line()
2100 while (!s && bc_history_stdinHasData(h)); in bc_history_line()
2104 bc_history_disableRaw(h); in bc_history_line()
2118 bc_history_init(BcHistory* h) in bc_history_init() argument
2127 h->rawMode = false; in bc_history_init()
2128 h->badTerm = bc_history_isBadTerm(); in bc_history_init()
2131 if (h->badTerm) return; in bc_history_init()
2135 h->orig_in = 0; in bc_history_init()
2136 h->orig_out = 0; in bc_history_init()
2146 if (!GetConsoleMode(in, &h->orig_in) || !GetConsoleMode(out, &h->orig_out)) in bc_history_init()
2149 h->badTerm = true; in bc_history_init()
2155 DWORD reqOut = h->orig_out | ENABLE_VIRTUAL_TERMINAL_PROCESSING; in bc_history_init()
2156 DWORD reqIn = h->orig_in | ENABLE_VIRTUAL_TERMINAL_INPUT; in bc_history_init()
2170 h->badTerm = true; in bc_history_init()
2176 bc_vec_init(&h->buf, sizeof(char), BC_DTOR_NONE); in bc_history_init()
2177 bc_vec_init(&h->history, sizeof(char*), BC_DTOR_HISTORY_STRING); in bc_history_init()
2178 bc_vec_init(&h->extras, sizeof(char), BC_DTOR_NONE); in bc_history_init()
2181 FD_ZERO(&h->rdset); in bc_history_init()
2182 FD_SET(STDIN_FILENO, &h->rdset); in bc_history_init()
2183 h->ts.tv_sec = 0; in bc_history_init()
2184 h->ts.tv_nsec = 0; in bc_history_init()
2186 sigemptyset(&h->sigmask); in bc_history_init()
2187 sigaddset(&h->sigmask, SIGINT); in bc_history_init()
2192 bc_history_free(BcHistory* h) in bc_history_free() argument
2196 bc_history_disableRaw(h); in bc_history_free()
2198 SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), h->orig_in); in bc_history_free()
2199 SetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), h->orig_out); in bc_history_free()
2202 bc_vec_free(&h->buf); in bc_history_free()
2203 bc_vec_free(&h->history); in bc_history_free()
2204 bc_vec_free(&h->extras); in bc_history_free()
2216 bc_history_printKeyCodes(BcHistory* h) in bc_history_printKeyCodes() argument
2224 bc_history_enableRaw(h); in bc_history_printKeyCodes()
2250 bc_history_disableRaw(h); in bc_history_printKeyCodes()