diff options
Diffstat (limited to 'sys/cmd/dvtm/vt.c')
-rw-r--r-- | sys/cmd/dvtm/vt.c | 416 |
1 files changed, 266 insertions, 150 deletions
diff --git a/sys/cmd/dvtm/vt.c b/sys/cmd/dvtm/vt.c index 916b8b4..c48a84f 100644 --- a/sys/cmd/dvtm/vt.c +++ b/sys/cmd/dvtm/vt.c @@ -1,20 +1,6 @@ -/* - * Copyright © 2004 Bruno T. C. de Oliveira - * Copyright © 2006 Pierre Habouzit - * Copyright © 2008-2016 Marc André Tanner - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER - * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ +/* See license for details */ +#include <u.h> + #include <stdlib.h> #include <stdint.h> #include <unistd.h> @@ -32,6 +18,7 @@ #include <sys/types.h> #include <termios.h> #include <wchar.h> + #if defined(__linux__) || defined(__CYGWIN__) # include <pty.h> #elif defined(__FreeBSD__) || defined(__DragonFly__) @@ -48,20 +35,24 @@ #ifndef NCURSES_ACS # ifdef PDCURSES -# define NCURSES_ACS(c) (acs_map[(unsigned char)(c)]) +# define NCURSES_ACS(c) (acs_map[(uchar)(c)]) # else /* BSD curses */ -# define NCURSES_ACS(c) (_acs_map[(unsigned char)(c)]) +# define NCURSES_ACS(c) (_acs_map[(uchar)(c)]) # endif #endif #ifdef NCURSES_VERSION -# ifndef NCURSES_EXT_COLORS -# define NCURSES_EXT_COLORS 0 -# endif -# if !NCURSES_EXT_COLORS -# define MAX_COLOR_PAIRS MIN(COLOR_PAIRS, 256) -# endif + +#ifndef NCURSES_EXT_COLORS +# define NCURSES_EXT_COLORS 0 +#endif + +#if !NCURSES_EXT_COLORS +# define MAX_COLOR_PAIRS MIN(COLOR_PAIRS, 256) #endif + +#endif + #ifndef MAX_COLOR_PAIRS # define MAX_COLOR_PAIRS COLOR_PAIRS #endif @@ -74,8 +65,6 @@ #endif #define IS_CONTROL(ch) !((ch) & 0xffffff60UL) -#define MIN(x, y) ((x) < (y) ? (x) : (y)) -#define LENGTH(arr) (sizeof(arr) / sizeof((arr)[0])) static bool is_utf8, has_default_colors; static short color_pairs_reserved, color_pairs_max, color_pair_current; @@ -91,7 +80,7 @@ typedef struct { typedef struct { Cell *cells; - unsigned dirty:1; + uint dirty:1; } Row; /* Buffer holding the current terminal window content (as an array) as well @@ -168,21 +157,21 @@ struct Vt { int pty; /* master side pty file descriptor */ pid_t pid; /* process id of the process running in this vt */ /* flags */ - unsigned seen_input:1; - unsigned insert:1; - unsigned escaped:1; - unsigned curshid:1; - unsigned curskeymode:1; - unsigned bell:1; - unsigned relposmode:1; - unsigned mousetrack:1; - unsigned graphmode:1; - unsigned savgraphmode:1; + uint seen_input:1; + uint insert:1; + uint escaped:1; + uint curshid:1; + uint curskeymode:1; + uint bell:1; + uint relposmode:1; + uint mousetrack:1; + uint graphmode:1; + uint savgraphmode:1; bool charsets[2]; /* buffers and parsing state */ char rbuf[BUFSIZ]; char ebuf[BUFSIZ]; - unsigned int rlen, elen; + uint rlen, elen; int srow, scol; /* last known offset to display start row, start column */ char title[256]; /* xterm style window title */ vt_title_handler_t title_handler; /* hook which is called when title changes */ @@ -249,14 +238,17 @@ static void puttab(Vt *t, int count); static void process_nonprinting(Vt *t, wchar_t wc); static void send_curs(Vt *t); -__attribute__ ((const)) -static attr_t build_attrs(attr_t curattrs) +const static +attr_t +build_attrs(attr_t curattrs) { return ((curattrs & ~A_COLOR) | COLOR_PAIR(curattrs & 0xff)) >> NCURSES_ATTR_SHIFT; } -static void row_set(Row *row, int start, int len, Buffer *t) +static +void +row_set(Row *row, int start, int len, Buffer *t) { Cell cell = { .text = L'\0', @@ -270,7 +262,9 @@ static void row_set(Row *row, int start, int len, Buffer *t) row->dirty = true; } -static void row_roll(Row *start, Row *end, int count) +static +void +row_roll(Row *start, Row *end, int count) { int n = end - start; @@ -288,7 +282,9 @@ static void row_roll(Row *start, Row *end, int count) } } -static void buffer_clear(Buffer *b) +static +void +buffer_clear(Buffer *b) { Cell cell = { .text = L'\0', @@ -306,7 +302,9 @@ static void buffer_clear(Buffer *b) } } -static void buffer_free(Buffer *b) +static +void +buffer_free(Buffer *b) { for (int i = 0; i < b->rows; i++) free(b->lines[i].cells); @@ -317,7 +315,9 @@ static void buffer_free(Buffer *b) free(b->tabs); } -static void buffer_scroll(Buffer *b, int s) +static +void +buffer_scroll(Buffer *b, int s) { /* work in screenfuls */ int ssz = b->scroll_bot - b->scroll_top; @@ -362,7 +362,9 @@ static void buffer_scroll(Buffer *b, int s) } } -static void buffer_resize(Buffer *b, int rows, int cols) +static +void +buffer_resize(Buffer *b, int rows, int cols) { Row *lines = b->lines; @@ -383,14 +385,14 @@ static void buffer_resize(Buffer *b, int rows, int cols) for (int row = 0; row < b->rows; row++) { lines[row].cells = realloc(lines[row].cells, sizeof(Cell) * cols); if (b->cols < cols) - row_set(lines + row, b->cols, cols - b->cols, NULL); + row_set(lines + row, b->cols, cols - b->cols, nil); lines[row].dirty = true; } Row *sbuf = b->scroll_buf; for (int row = 0; row < b->scroll_size; row++) { sbuf[row].cells = realloc(sbuf[row].cells, sizeof(Cell) * cols); if (b->cols < cols) - row_set(sbuf + row, b->cols, cols - b->cols, NULL); + row_set(sbuf + row, b->cols, cols - b->cols, nil); } b->tabs = realloc(b->tabs, sizeof(*b->tabs) * cols); for (int col = b->cols; col < cols; col++) @@ -431,7 +433,9 @@ static void buffer_resize(Buffer *b, int rows, int cols) } } -static bool buffer_init(Buffer *b, int rows, int cols, int scroll_size) +static +bool +buffer_init(Buffer *b, int rows, int cols, int scroll_size) { b->curattrs = A_NORMAL; /* white text over black background */ b->curfg = b->curbg = -1; @@ -444,15 +448,18 @@ static bool buffer_init(Buffer *b, int rows, int cols, int scroll_size) return true; } -static void buffer_boundry(Buffer *b, Row **bs, Row **be, Row **as, Row **ae) { +static +void +buffer_boundry(Buffer *b, Row **bs, Row **be, Row **as, Row **ae) +{ if (bs) - *bs = NULL; + *bs = nil; if (be) - *be = NULL; + *be = nil; if (as) - *as = NULL; + *as = nil; if (ae) - *ae = NULL; + *ae = nil; if (!b->scroll_size) return; @@ -470,29 +477,35 @@ static void buffer_boundry(Buffer *b, Row **bs, Row **be, Row **as, Row **ae) { } } -static Row *buffer_row_first(Buffer *b) { +static +Row * +buffer_row_first(Buffer *b) { Row *bstart; if (!b->scroll_size || !b->scroll_above) return b->lines; - buffer_boundry(b, &bstart, NULL, NULL, NULL); + buffer_boundry(b, &bstart, nil, nil, nil); return bstart; } -static Row *buffer_row_last(Buffer *b) { +static +Row * +buffer_row_last(Buffer *b) { Row *aend; if (!b->scroll_size || !b->scroll_below) return b->lines + b->rows - 1; - buffer_boundry(b, NULL, NULL, NULL, &aend); + buffer_boundry(b, nil, nil, nil, &aend); return aend; } -static Row *buffer_row_next(Buffer *b, Row *row) +static +Row * +buffer_row_next(Buffer *b, Row *row) { Row *before_start, *before_end, *after_start, *after_end; Row *first = b->lines, *last = b->lines + b->rows - 1; if (!row) - return NULL; + return nil; buffer_boundry(b, &before_start, &before_end, &after_start, &after_end); @@ -503,19 +516,21 @@ static Row *buffer_row_next(Buffer *b, Row *row) if (row == before_end) return first; if (row == after_end) - return NULL; + return nil; if (row == &b->scroll_buf[b->scroll_size - 1]) return b->scroll_buf; return ++row; } -static Row *buffer_row_prev(Buffer *b, Row *row) +static +Row * +buffer_row_prev(Buffer *b, Row *row) { Row *before_start, *before_end, *after_start, *after_end; Row *first = b->lines, *last = b->lines + b->rows - 1; if (!row) - return NULL; + return nil; buffer_boundry(b, &before_start, &before_end, &after_start, &after_end); @@ -524,7 +539,7 @@ static Row *buffer_row_prev(Buffer *b, Row *row) if (row == first) return before_end; if (row == before_start) - return NULL; + return nil; if (row == after_start) return last; if (row == b->scroll_buf) @@ -532,7 +547,9 @@ static Row *buffer_row_prev(Buffer *b, Row *row) return --row; } -static void cursor_clamp(Vt *t) +static +void +cursor_clamp(Vt *t) { Buffer *b = t->buffer; Row *lines = t->relposmode ? b->scroll_top : b->lines; @@ -548,10 +565,12 @@ static void cursor_clamp(Vt *t) b->curs_col = b->cols - 1; } -static void cursor_line_down(Vt *t) +static +void +cursor_line_down(Vt *t) { Buffer *b = t->buffer; - row_set(b->curs_row, b->cols, b->maxcols - b->cols, NULL); + row_set(b->curs_row, b->cols, b->maxcols - b->cols, nil); b->curs_row++; if (b->curs_row < b->scroll_bot) return; @@ -563,14 +582,18 @@ static void cursor_line_down(Vt *t) row_set(b->curs_row, 0, b->cols, b); } -static void cursor_save(Vt *t) +static +void +cursor_save(Vt *t) { Buffer *b = t->buffer; b->curs_srow = b->curs_row - b->lines; b->curs_scol = b->curs_col; } -static void cursor_restore(Vt *t) +static +void +cursor_restore(Vt *t) { Buffer *b = t->buffer; b->curs_row = b->lines + b->curs_srow; @@ -578,7 +601,9 @@ static void cursor_restore(Vt *t) cursor_clamp(t); } -static void attributes_save(Vt *t) +static +void +attributes_save(Vt *t) { Buffer *b = t->buffer; b->savattrs = b->curattrs; @@ -587,7 +612,9 @@ static void attributes_save(Vt *t) t->savgraphmode = t->graphmode; } -static void attributes_restore(Vt *t) +static +void +attributes_restore(Vt *t) { Buffer *b = t->buffer; b->curattrs = b->savattrs; @@ -596,21 +623,27 @@ static void attributes_restore(Vt *t) t->graphmode = t->savgraphmode; } -static void new_escape_sequence(Vt *t) +static +void +new_escape_sequence(Vt *t) { t->escaped = true; t->elen = 0; t->ebuf[0] = '\0'; } -static void cancel_escape_sequence(Vt *t) +static +void +cancel_escape_sequence(Vt *t) { t->escaped = false; t->elen = 0; t->ebuf[0] = '\0'; } -static bool is_valid_csi_ender(int c) +static +bool +is_valid_csi_ender(int c) { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') @@ -618,7 +651,9 @@ static bool is_valid_csi_ender(int c) } /* interprets a 'set attribute' (SGR) CSI escape sequence */ -static void interpret_csi_sgr(Vt *t, int param[], int pcount) +static +void +interpret_csi_sgr(Vt *t, int param[], int pcount) { Buffer *b = t->buffer; if (pcount == 0) { @@ -714,7 +749,9 @@ static void interpret_csi_sgr(Vt *t, int param[], int pcount) } /* interprets an 'erase display' (ED) escape sequence */ -static void interpret_csi_ed(Vt *t, int param[], int pcount) +static +void +interpret_csi_ed(Vt *t, int param[], int pcount) { Row *row, *start, *end; Buffer *b = t->buffer; @@ -743,7 +780,9 @@ static void interpret_csi_ed(Vt *t, int param[], int pcount) } /* interprets a 'move cursor' (CUP) escape sequence */ -static void interpret_csi_cup(Vt *t, int param[], int pcount) +static +void +interpret_csi_cup(Vt *t, int param[], int pcount) { Buffer *b = t->buffer; Row *lines = t->relposmode ? b->scroll_top : b->lines; @@ -764,7 +803,9 @@ static void interpret_csi_cup(Vt *t, int param[], int pcount) /* Interpret the 'relative mode' sequences: CUU, CUD, CUF, CUB, CNL, * CPL, CHA, HPR, VPA, VPR, HPA */ -static void interpret_csi_c(Vt *t, char verb, int param[], int pcount) +static +void +interpret_csi_c(Vt *t, char verb, int param[], int pcount) { Buffer *b = t->buffer; int n = (pcount && param[0] > 0) ? param[0] : 1; @@ -805,7 +846,9 @@ static void interpret_csi_c(Vt *t, char verb, int param[], int pcount) } /* Interpret the 'erase line' escape sequence */ -static void interpret_csi_el(Vt *t, int param[], int pcount) +static +void +interpret_csi_el(Vt *t, int param[], int pcount) { Buffer *b = t->buffer; switch (pcount ? param[0] : 0) { @@ -822,7 +865,9 @@ static void interpret_csi_el(Vt *t, int param[], int pcount) } /* Interpret the 'insert blanks' sequence (ICH) */ -static void interpret_csi_ich(Vt *t, int param[], int pcount) +static +void +interpret_csi_ich(Vt *t, int param[], int pcount) { Buffer *b = t->buffer; Row *row = b->curs_row; @@ -838,7 +883,9 @@ static void interpret_csi_ich(Vt *t, int param[], int pcount) } /* Interpret the 'delete chars' sequence (DCH) */ -static void interpret_csi_dch(Vt *t, int param[], int pcount) +static +void +interpret_csi_dch(Vt *t, int param[], int pcount) { Buffer *b = t->buffer; Row *row = b->curs_row; @@ -854,7 +901,9 @@ static void interpret_csi_dch(Vt *t, int param[], int pcount) } /* Interpret an 'insert line' sequence (IL) */ -static void interpret_csi_il(Vt *t, int param[], int pcount) +static +void +interpret_csi_il(Vt *t, int param[], int pcount) { Buffer *b = t->buffer; int n = (pcount && param[0] > 0) ? param[0] : 1; @@ -870,7 +919,9 @@ static void interpret_csi_il(Vt *t, int param[], int pcount) } /* Interpret a 'delete line' sequence (DL) */ -static void interpret_csi_dl(Vt *t, int param[], int pcount) +static +void +interpret_csi_dl(Vt *t, int param[], int pcount) { Buffer *b = t->buffer; int n = (pcount && param[0] > 0) ? param[0] : 1; @@ -886,7 +937,9 @@ static void interpret_csi_dl(Vt *t, int param[], int pcount) } /* Interpret an 'erase characters' (ECH) sequence */ -static void interpret_csi_ech(Vt *t, int param[], int pcount) +static +void +interpret_csi_ech(Vt *t, int param[], int pcount) { Buffer *b = t->buffer; int n = (pcount && param[0] > 0) ? param[0] : 1; @@ -898,7 +951,9 @@ static void interpret_csi_ech(Vt *t, int param[], int pcount) } /* Interpret a 'set scrolling region' (DECSTBM) sequence */ -static void interpret_csi_decstbm(Vt *t, int param[], int pcount) +static +void +interpret_csi_decstbm(Vt *t, int param[], int pcount) { Buffer *b = t->buffer; int new_top, new_bot; @@ -935,7 +990,9 @@ static void interpret_csi_decstbm(Vt *t, int param[], int pcount) b->curs_col = 0; } -static void interpret_csi_mode(Vt *t, int param[], int pcount, bool set) +static +void +interpret_csi_mode(Vt *t, int param[], int pcount, bool set) { for (int i = 0; i < pcount; i++) { switch (param[i]) { @@ -946,7 +1003,9 @@ static void interpret_csi_mode(Vt *t, int param[], int pcount, bool set) } } -static void interpret_csi_priv_mode(Vt *t, int param[], int pcount, bool set) +static +void +interpret_csi_priv_mode(Vt *t, int param[], int pcount, bool set) { for (int i = 0; i < pcount; i++) { switch (param[i]) { @@ -982,11 +1041,13 @@ static void interpret_csi_priv_mode(Vt *t, int param[], int pcount, bool set) } } -static void interpret_csi(Vt *t) +static +void +interpret_csi(Vt *t) { Buffer *b = t->buffer; int csiparam[16]; - unsigned int param_count = 0; + uint param_count = 0; const char *p = t->ebuf + 1; char verb = t->ebuf[t->elen - 1]; @@ -995,10 +1056,10 @@ static void interpret_csi(Vt *t) if (IS_CONTROL(*p)) { process_nonprinting(t, *p); } else if (*p == ';') { - if (param_count >= LENGTH(csiparam)) + if (param_count >= arrlen(csiparam)) return; /* too long! */ csiparam[param_count++] = 0; - } else if (isdigit((unsigned char)*p)) { + } else if (isdigit((uchar)*p)) { if (param_count == 0) csiparam[param_count++] = 0; csiparam[param_count - 1] *= 10; @@ -1101,7 +1162,9 @@ static void interpret_csi(Vt *t) } /* Interpret an 'index' (IND) sequence */ -static void interpret_csi_ind(Vt *t) +static +void +interpret_csi_ind(Vt *t) { Buffer *b = t->buffer; if (b->curs_row < b->lines + b->rows - 1) @@ -1109,7 +1172,9 @@ static void interpret_csi_ind(Vt *t) } /* Interpret a 'reverse index' (RI) sequence */ -static void interpret_csi_ri(Vt *t) +static +void +interpret_csi_ri(Vt *t) { Buffer *b = t->buffer; if (b->curs_row > b->scroll_top) @@ -1121,7 +1186,9 @@ static void interpret_csi_ri(Vt *t) } /* Interpret a 'next line' (NEL) sequence */ -static void interpret_csi_nel(Vt *t) +static +void +interpret_csi_nel(Vt *t) { Buffer *b = t->buffer; if (b->curs_row < b->lines + b->rows - 1) { @@ -1131,7 +1198,9 @@ static void interpret_csi_nel(Vt *t) } /* Interpret a 'select character set' (SCS) sequence */ -static void interpret_csi_scs(Vt *t) +static +void +interpret_csi_scs(Vt *t) { /* ESC ( sets G0, ESC ) sets G1 */ t->charsets[!!(t->ebuf[0] == ')')] = (t->ebuf[1] == '0'); @@ -1139,13 +1208,15 @@ static void interpret_csi_scs(Vt *t) } /* Interpret an 'operating system command' (OSC) sequence */ -static void interpret_osc(Vt *t) +static +void +interpret_osc(Vt *t) { /* ESC ] command ; data BEL * ESC ] command ; data ESC \\ * Note that BEL or ESC \\ have already been replaced with NUL. */ - char *data = NULL; + char *data = nil; int command = strtoul(t->ebuf + 1, &data, 10); if (data && *data == ';') { switch (command) { @@ -1165,7 +1236,9 @@ static void interpret_osc(Vt *t) } } -static void try_interpret_escape_seq(Vt *t) +static +void +try_interpret_escape_seq(Vt *t) { char lastchar = t->ebuf[t->elen - 1]; @@ -1232,7 +1305,7 @@ static void try_interpret_escape_seq(Vt *t) cancel: #ifndef NDEBUG fprintf(stderr, "cancelled: \\033"); - for (unsigned int i = 0; i < t->elen; i++) { + for (uint i = 0; i < t->elen; i++) { if (isprint(t->ebuf[i])) { fputc(t->ebuf[i], stderr); } else { @@ -1246,7 +1319,9 @@ handled: } } -static void puttab(Vt *t, int count) +static +void +puttab(Vt *t, int count) { Buffer *b = t->buffer; int direction = count >= 0 ? 1 : -1; @@ -1266,7 +1341,9 @@ static void puttab(Vt *t, int count) } } -static void process_nonprinting(Vt *t, wchar_t wc) +static +void +process_nonprinting(Vt *t, wchar_t wc) { Buffer *b = t->buffer; switch (wc) { @@ -1301,7 +1378,9 @@ static void process_nonprinting(Vt *t, wchar_t wc) } } -static void is_utf8_locale(void) +static +void +is_utf8_locale(void) { const char *cset = nl_langinfo(CODESET); if (!cset) @@ -1309,7 +1388,9 @@ static void is_utf8_locale(void) is_utf8 = !strcmp(cset, "UTF-8"); } -static wchar_t get_vt100_graphic(char c) +static +wchar_t +get_vt100_graphic(char c) { static char vt100_acs[] = "`afgjklmnopqrstuvwxyz{|}~"; @@ -1335,7 +1416,9 @@ static wchar_t get_vt100_graphic(char c) return '\0'; } -static void put_wc(Vt *t, wchar_t wc) +static +void +put_wc(Vt *t, wchar_t wc) { int width = 0; @@ -1392,10 +1475,11 @@ static void put_wc(Vt *t, wchar_t wc) } } -int vt_process(Vt *t) +int +vt_process(Vt *t) { int res; - unsigned int pos = 0; + uint pos = 0; mbstate_t ps; memset(&ps, 0, sizeof(ps)); @@ -1434,21 +1518,23 @@ int vt_process(Vt *t) return 0; } -void vt_default_colors_set(Vt *t, attr_t attrs, short fg, short bg) +void +vt_default_colors_set(Vt *t, attr_t attrs, short fg, short bg) { t->defattrs = attrs; t->deffg = fg; t->defbg = bg; } -Vt *vt_create(int rows, int cols, int scroll_size) +Vt * +vt_create(int rows, int cols, int scroll_size) { if (rows <= 0 || cols <= 0) - return NULL; + return nil; Vt *t = calloc(1, sizeof(Vt)); if (!t) - return NULL; + return nil; t->pty = -1; t->deffg = t->defbg = -1; @@ -1457,13 +1543,14 @@ Vt *vt_create(int rows, int cols, int scroll_size) if (!buffer_init(&t->buffer_normal, rows, cols, scroll_size) || !buffer_init(&t->buffer_alternate, rows, cols, 0)) { free(t); - return NULL; + return nil; } return t; } -void vt_resize(Vt *t, int rows, int cols) +void +vt_resize(Vt *t, int rows, int cols) { struct winsize ws = { .ws_row = rows, .ws_col = cols }; @@ -1478,7 +1565,8 @@ void vt_resize(Vt *t, int rows, int cols) kill(-t->pid, SIGWINCH); } -void vt_destroy(Vt *t) +void +vt_destroy(Vt *t) { if (!t) return; @@ -1488,14 +1576,16 @@ void vt_destroy(Vt *t) free(t); } -void vt_dirty(Vt *t) +void +vt_dirty(Vt *t) { Buffer *b = t->buffer; for (Row *row = b->lines, *end = row + b->rows; row < end; row++) row->dirty = true; } -void vt_draw(Vt *t, WINDOW *win, int srow, int scol) +void +vt_draw(Vt *t, WINDOW *win, int srow, int scol) { Buffer *b = t->buffer; @@ -1512,7 +1602,7 @@ void vt_draw(Vt *t, WINDOW *win, int srow, int scol) continue; wmove(win, srow + i, scol); - Cell *cell = NULL; + Cell *cell = nil; for (int j = 0; j < b->cols; j++) { Cell *prev_cell = cell; cell = row->cells + j; @@ -1526,12 +1616,12 @@ void vt_draw(Vt *t, WINDOW *win, int srow, int scol) if (cell->bg == -1) cell->bg = t->defbg; wattrset(win, cell->attr << NCURSES_ATTR_SHIFT); - wcolor_set(win, vt_color_get(t, cell->fg, cell->bg), NULL); + wcolor_set(win, vt_color_get(t, cell->fg, cell->bg), nil); } if (is_utf8 && cell->text >= 128) { char buf[MB_CUR_MAX + 1]; - size_t len = wcrtomb(buf, cell->text, NULL); + size_t len = wcrtomb(buf, cell->text, nil); if (len > 0) { waddnstr(win, buf, len); if (wcwidth(cell->text) > 1) @@ -1554,7 +1644,8 @@ void vt_draw(Vt *t, WINDOW *win, int srow, int scol) wmove(win, srow + b->curs_row - b->lines, scol + b->curs_col); } -void vt_scroll(Vt *t, int rows) +void +vt_scroll(Vt *t, int rows) { Buffer *b = t->buffer; if (!b->scroll_size) @@ -1570,14 +1661,16 @@ void vt_scroll(Vt *t, int rows) b->scroll_below -= rows; } -void vt_noscroll(Vt *t) +void +vt_noscroll(Vt *t) { int scroll_below = t->buffer->scroll_below; if (scroll_below) vt_scroll(t, scroll_below); } -pid_t vt_forkpty(Vt *t, const char *p, const char *argv[], const char *cwd, const char *env[], int *to, int *from) +pid_t +vt_forkpty(Vt *t, const char *p, const char *argv[], const char *cwd, const char *env[], int *to, int *from) { int vt2ed[2], ed2vt[2]; struct winsize ws; @@ -1587,14 +1680,14 @@ pid_t vt_forkpty(Vt *t, const char *p, const char *argv[], const char *cwd, cons if (to && pipe(vt2ed)) { *to = -1; - to = NULL; + to = nil; } if (from && pipe(ed2vt)) { *from = -1; - from = NULL; + from = nil; } - pid_t pid = forkpty(&t->pty, NULL, NULL, &ws); + pid_t pid = forkpty(&t->pty, nil, nil, &ws); if (pid < 0) return -1; @@ -1603,7 +1696,7 @@ pid_t vt_forkpty(Vt *t, const char *p, const char *argv[], const char *cwd, cons sigset_t emptyset; sigemptyset(&emptyset); - sigprocmask(SIG_SETMASK, &emptyset, NULL); + sigprocmask(SIG_SETMASK, &emptyset, nil); if (to) { close(vt2ed[1]); @@ -1647,12 +1740,14 @@ pid_t vt_forkpty(Vt *t, const char *p, const char *argv[], const char *cwd, cons return t->pid = pid; } -int vt_pty_get(Vt *t) +int +vt_pty_get(Vt *t) { return t->pty; } -ssize_t vt_write(Vt *t, const char *buf, size_t len) +ssize_t +vt_write(Vt *t, const char *buf, size_t len) { ssize_t ret = len; @@ -1670,7 +1765,9 @@ ssize_t vt_write(Vt *t, const char *buf, size_t len) return ret; } -static void send_curs(Vt *t) +static +void +send_curs(Vt *t) { Buffer *b = t->buffer; char keyseq[16]; @@ -1678,7 +1775,8 @@ static void send_curs(Vt *t) vt_write(t, keyseq, strlen(keyseq)); } -void vt_keypress(Vt *t, int keycode) +void +vt_keypress(Vt *t, int keycode) { vt_noscroll(t); @@ -1705,7 +1803,8 @@ void vt_keypress(Vt *t, int keycode) } } -void vt_mouse(Vt *t, int x, int y, mmask_t mask) +void +vt_mouse(Vt *t, int x, int y, mmask_t mask) { #ifdef NCURSES_MOUSE_VERSION char seq[6] = { '\e', '[', 'M' }, state = 0, button = 0; @@ -1744,7 +1843,9 @@ void vt_mouse(Vt *t, int x, int y, mmask_t mask) #endif /* NCURSES_MOUSE_VERSION */ } -static unsigned int color_hash(short fg, short bg) +static +uint +color_hash(short fg, short bg) { if (fg == -1) fg = COLORS; @@ -1753,7 +1854,8 @@ static unsigned int color_hash(short fg, short bg) return fg * (COLORS + 2) + bg; } -short vt_color_get(Vt *t, short fg, short bg) +short +vt_color_get(Vt *t, short fg, short bg) { if (fg >= COLORS) fg = (t ? t->deffg : default_fg); @@ -1769,14 +1871,14 @@ short vt_color_get(Vt *t, short fg, short bg) if (!color2palette || (fg == -1 && bg == -1)) return 0; - unsigned int index = color_hash(fg, bg); + uint index = color_hash(fg, bg); if (color2palette[index] == 0) { short oldfg, oldbg; for (;;) { if (++color_pair_current >= color_pairs_max) color_pair_current = color_pairs_reserved + 1; pair_content(color_pair_current, &oldfg, &oldbg); - unsigned int old_index = color_hash(oldfg, oldbg); + uint old_index = color_hash(oldfg, oldbg); if (color2palette[old_index] >= 0) { if (init_pair(color_pair_current, fg, bg) == OK) { color2palette[old_index] = 0; @@ -1791,7 +1893,8 @@ short vt_color_get(Vt *t, short fg, short bg) return color_pair >= 0 ? color_pair : -color_pair; } -short vt_color_reserve(short fg, short bg) +short +vt_color_reserve(short fg, short bg) { if (!color2palette || fg >= COLORS || bg >= COLORS) return 0; @@ -1801,7 +1904,7 @@ short vt_color_reserve(short fg, short bg) bg = default_bg; if (fg == -1 && bg == -1) return 0; - unsigned int index = color_hash(fg, bg); + uint index = color_hash(fg, bg); if (color2palette[index] >= 0) { if (init_pair(color_pairs_reserved + 1, fg, bg) == OK) color2palette[index] = -(++color_pairs_reserved); @@ -1810,7 +1913,9 @@ short vt_color_reserve(short fg, short bg) return color_pair >= 0 ? color_pair : -color_pair; } -static void init_colors(void) +static +void +init_colors(void) { pair_content(0, &default_fg, &default_bg); if (default_fg == -1) @@ -1832,7 +1937,8 @@ static void init_colors(void) vt_color_reserve(COLOR_WHITE, COLOR_BLACK); } -void vt_init(void) +void +vt_init(void) { init_colors(); is_utf8_locale(); @@ -1842,7 +1948,8 @@ void vt_init(void) snprintf(vt_term, sizeof vt_term, "%s%s", term, COLORS >= 256 ? "-256color" : ""); } -void vt_keytable_set(const char * const keytable_overlay[], int count) +void +vt_keytable_set(const char * const keytable_overlay[], int count) { for (int k = 0; k < count && k < KEY_MAX; k++) { const char *keyseq = keytable_overlay[k]; @@ -1851,42 +1958,50 @@ void vt_keytable_set(const char * const keytable_overlay[], int count) } } -void vt_shutdown(void) +void +vt_shutdown(void) { free(color2palette); } -void vt_title_handler_set(Vt *t, vt_title_handler_t handler) +void +vt_title_handler_set(Vt *t, vt_title_handler_t handler) { t->title_handler = handler; } -void vt_urgent_handler_set(Vt *t, vt_urgent_handler_t handler) +void +vt_urgent_handler_set(Vt *t, vt_urgent_handler_t handler) { t->urgent_handler = handler; } -void vt_data_set(Vt *t, void *data) +void +vt_data_set(Vt *t, void *data) { t->data = data; } -void *vt_data_get(Vt *t) +void * +vt_data_get(Vt *t) { return t->data; } -bool vt_cursor_visible(Vt *t) +bool +vt_cursor_visible(Vt *t) { return t->buffer->scroll_below ? false : !t->curshid; } -pid_t vt_pid_get(Vt *t) +pid_t +vt_pid_get(Vt *t) { return t->pid; } -size_t vt_content_get(Vt *t, char **buf, bool colored) +size_t +vt_content_get(Vt *t, char **buf, bool colored) { Buffer *b = t->buffer; int lines = b->scroll_above + b->scroll_below + b->rows + 1; @@ -1898,7 +2013,7 @@ size_t vt_content_get(Vt *t, char **buf, bool colored) return 0; char *s = *buf; - Cell *prev_cell = NULL; + Cell *prev_cell = nil; for (Row *row = buffer_row_first(b); row; row = buffer_row_next(b, row)) { size_t len = 0; @@ -1956,7 +2071,8 @@ size_t vt_content_get(Vt *t, char **buf, bool colored) return s - *buf; } -int vt_content_start(Vt *t) +int +vt_content_start(Vt *t) { return t->buffer->scroll_above; } |