_nc_slk_initialize(WINDOW *stwin, int cols) { int i; int res = OK; unsigned max_length; SCREEN *sp; TERMINAL *term; int numlab; T((T_CALLED("_nc_slk_initialize()"))); assert(stwin); sp = _nc_screen_of(stwin); if (0 == sp) returnCode(ERR); term = TerminalOf(SP_PARM); assert(term); numlab = NumLabels; if (SP_PARM->_slk) { /* we did this already, so simply return */ returnCode(OK); } else if ((SP_PARM->_slk = typeCalloc(SLK, 1)) == 0) returnCode(ERR); if (!SP_PARM->slk_format) SP_PARM->slk_format = _nc_globals.slk_format; /* * If we use colors, vidputs() will suppress video attributes that conflict * with colors. In that case, we're still guaranteed that "reverse" would * work. */ if ((NoColorVideo & 1) == 0) SetAttr(SP_PARM->_slk->attr, A_STANDOUT); else SetAttr(SP_PARM->_slk->attr, A_REVERSE); SP_PARM->_slk->maxlab = ((numlab > 0) ? numlab : MAX_SKEY(SP_PARM->slk_format)); SP_PARM->_slk->maxlen = ((numlab > 0) ? LabelWidth * LabelHeight : MAX_SKEY_LEN(SP_PARM->slk_format)); SP_PARM->_slk->labcnt = ((SP_PARM->_slk->maxlab < MAX_SKEY(SP_PARM->slk_format)) ? MAX_SKEY(SP_PARM->slk_format) : SP_PARM->_slk->maxlab); if (SP_PARM->_slk->maxlen <= 0 || SP_PARM->_slk->labcnt <= 0 || (SP_PARM->_slk->ent = typeCalloc(slk_ent, (unsigned) SP_PARM->_slk->labcnt)) == NULL) returnCode(slk_failed(NCURSES_SP_ARG)); max_length = SP_PARM->_slk->maxlen; for (i = 0; i < SP_PARM->_slk->labcnt; i++) { size_t used = max_length + 1; SP_PARM->_slk->ent[i].ent_text = (char *) _nc_doalloc(0, used); if (SP_PARM->_slk->ent[i].ent_text == 0) returnCode(slk_failed(NCURSES_SP_ARG)); memset(SP_PARM->_slk->ent[i].ent_text, 0, used); SP_PARM->_slk->ent[i].form_text = (char *) _nc_doalloc(0, used); if (SP_PARM->_slk->ent[i].form_text == 0) returnCode(slk_failed(NCURSES_SP_ARG)); memset(SP_PARM->_slk->ent[i].form_text, 0, used); memset(SP_PARM->_slk->ent[i].form_text, ' ', max_length); SP_PARM->_slk->ent[i].visible = (char) (i < SP_PARM->_slk->maxlab); } res = _nc_format_slks(NCURSES_SP_ARGx cols); if ((SP_PARM->_slk->win = stwin) == NULL) { returnCode(slk_failed(NCURSES_SP_ARG)); } /* We now reset the format so that the next newterm has again * per default no SLK keys and may call slk_init again to * define a new layout. (juergen 03-Mar-1999) */ _nc_globals.slk_format = 0; returnCode(res); }
/* ** lib_wattroff.c ** ** The routine wattr_off(). ** */ #include <curses.priv.h> #include <ctype.h> MODULE_ID("$Id: lib_wattroff.c,v 1.1 2009-05-21 08:33:45 steven Exp $") NCURSES_EXPORT(int) wattr_off(WINDOW *win, attr_t at, void *opts GCC_UNUSED) { T((T_CALLED("wattr_off(%p,%s)"), win, _traceattr(at))); if (win) { T(("... current %s (%d)", _traceattr(WINDOW_ATTRS(win)), GET_WINDOW_PAIR(win))); if_EXT_COLORS({ if (at & A_COLOR) win->_color = 0; }); toggle_attr_off(WINDOW_ATTRS(win), at); returnCode(OK); } else returnCode(ERR); }
NCURSES_SP_NAME(resetty) (NCURSES_SP_DCL0) { T((T_CALLED("resetty(%p)"), (void *) SP_PARM)); returnCode(NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx saved_tty(NCURSES_SP_ARG))); }
new_page(const FIELD *field) { T((T_CALLED("new_page(%p)"), (const void *)field)); returnBool((Normalize_Field(field)->status & _NEWPAGE) ? TRUE : FALSE); }
form_fields(const FORM *form) { T((T_CALLED("form_field(%p)"), (const void *)form)); returnFieldPtr(Normalize_Form(form)->field); }
} #endif /* * This call does the same thing as the qiflush()/noqiflush() pair. We know * for certain that SVr3 intrflush() tweaks the NOFLSH bit; on the other hand, * the match (in the SVr4 man pages) between the language describing NOFLSH in * termio(7) and the language describing qiflush()/noqiflush() in * curs_inopts(3x) is too exact to be coincidence. */ NCURSES_EXPORT(int) NCURSES_SP_NAME(intrflush) (NCURSES_SP_DCLx WINDOW *win GCC_UNUSED, bool flag) { int result = ERR; T((T_CALLED("intrflush(%d)"), flag)); if (cur_term != 0) { TTY buf; BEFORE("intrflush"); buf = cur_term->Nttyb; #ifdef TERMIOS if (flag) buf.c_lflag &= ~(NOFLSH); else buf.c_lflag |= (NOFLSH); result = _nc_set_tty_mode(&buf); #else /* FIXME */ #endif
savetty(void) { T((T_CALLED("savetty()"))); returnCode(_nc_get_tty_mode(&buf)); }
_nc_wgetch(WINDOW *win, unsigned long *result, int use_meta EVENTLIST_2nd(_nc_eventlist * evl)) { int ch; #ifdef NCURSES_WGETCH_EVENTS long event_delay = -1; #endif T((T_CALLED("_nc_wgetch(%p)"), win)); *result = 0; if (win == 0 || SP == 0) returnCode(ERR); if (cooked_key_in_fifo()) { if (wgetch_should_refresh(win)) wrefresh(win); *result = fifo_pull(); returnCode(OK); } #ifdef NCURSES_WGETCH_EVENTS if (evl && (evl->count == 0)) evl = NULL; event_delay = _nc_eventlist_timeout(evl); #endif /* * Handle cooked mode. Grab a string from the screen, * stuff its contents in the FIFO queue, and pop off * the first character to return it. */ if (head == -1 && !SP->_notty && !SP->_raw && !SP->_cbreak && !SP->_called_wgetch) { char buf[MAXCOLUMNS], *sp; int rc; TR(TRACE_IEVENT, ("filling queue in cooked mode")); SP->_called_wgetch = TRUE; rc = wgetnstr(win, buf, MAXCOLUMNS); SP->_called_wgetch = FALSE; /* ungetch in reverse order */ #ifdef NCURSES_WGETCH_EVENTS if (rc != KEY_EVENT) #endif ungetch('\n'); for (sp = buf + strlen(buf); sp > buf; sp--) ungetch(sp[-1]); #ifdef NCURSES_WGETCH_EVENTS /* Return it first */ if (rc == KEY_EVENT) { *result = rc; returnCode(OK); } #endif *result = fifo_pull(); returnCode(OK); } if (win->_use_keypad != SP->_keypad_on) _nc_keypad(win->_use_keypad); if (wgetch_should_refresh(win)) wrefresh(win); if (!win->_notimeout && (win->_delay >= 0 || SP->_cbreak > 1)) { int delay; TR(TRACE_IEVENT, ("timed delay in wgetch()")); if (SP->_cbreak > 1) delay = (SP->_cbreak - 1) * 100; else delay = win->_delay; #ifdef NCURSES_WGETCH_EVENTS if (event_delay >= 0 && delay > event_delay) delay = event_delay; #endif TR(TRACE_IEVENT, ("delay is %d milliseconds", delay)); if (head == -1) { /* fifo is empty */ int rc = check_mouse_activity(delay EVENTLIST_2nd(evl)); #ifdef NCURSES_WGETCH_EVENTS if (rc & 4) { *result = KEY_EVENT; returnCode(OK); } #endif if (!rc) returnCode(ERR); } /* else go on to read data available */ } if (win->_use_keypad) { /* * This is tricky. We only want to get special-key * events one at a time. But we want to accumulate * mouse events until either (a) the mouse logic tells * us it's picked up a complete gesture, or (b) * there's a detectable time lapse after one. * * Note: if the mouse code starts failing to compose * press/release events into clicks, you should probably * increase the wait with mouseinterval(). */ int runcount = 0; int rc; do { ch = kgetch(EVENTLIST_1st(evl)); if (ch == KEY_MOUSE) { ++runcount; if (SP->_mouse_inline(SP)) break; } if (SP->_maxclick < 0) break; } while (ch == KEY_MOUSE && (((rc = check_mouse_activity(SP->_maxclick EVENTLIST_2nd(evl))) != 0 && !(rc & 4)) || !SP->_mouse_parse(runcount))); #ifdef NCURSES_WGETCH_EVENTS if ((rc & 4) && !ch == KEY_EVENT) { ungetch(ch); ch = KEY_EVENT; } #endif if (runcount > 0 && ch != KEY_MOUSE) { #ifdef NCURSES_WGETCH_EVENTS /* mouse event sequence ended by an event, report event */ if (ch == KEY_EVENT) { ungetch(KEY_MOUSE); /* FIXME This interrupts a gesture... */ } else #endif { /* mouse event sequence ended by keystroke, store keystroke */ ungetch(ch); ch = KEY_MOUSE; } } } else { if (head == -1) fifo_push(EVENTLIST_1st(evl)); ch = fifo_pull(); } if (ch == ERR) { #if USE_SIZECHANGE if (SP->_sig_winch) { _nc_update_screensize(); /* resizeterm can push KEY_RESIZE */ if (cooked_key_in_fifo()) { *result = fifo_pull(); returnCode(*result >= KEY_MIN ? KEY_CODE_YES : OK); } } #endif returnCode(ERR); } /* * If echo() is in effect, display the printable version of the * key on the screen. Carriage return and backspace are treated * specially by Solaris curses: * * If carriage return is defined as a function key in the * terminfo, e.g., kent, then Solaris may return either ^J (or ^M * if nonl() is set) or KEY_ENTER depending on the echo() mode. * We echo before translating carriage return based on nonl(), * since the visual result simply moves the cursor to column 0. * * Backspace is a different matter. Solaris curses does not * translate it to KEY_BACKSPACE if kbs=^H. This does not depend * on the stty modes, but appears to be a hardcoded special case. * This is a difference from ncurses, which uses the terminfo entry. * However, we provide the same visual result as Solaris, moving the * cursor to the left. */ if (SP->_echo && !(win->_flags & _ISPAD)) { chtype backup = (ch == KEY_BACKSPACE) ? '\b' : ch; if (backup < KEY_MIN) wechochar(win, backup); } /* * Simulate ICRNL mode */ if ((ch == '\r') && SP->_nl) ch = '\n'; /* Strip 8th-bit if so desired. We do this only for characters that * are in the range 128-255, to provide compatibility with terminals * that display only 7-bit characters. Note that 'ch' may be a * function key at this point, so we mustn't strip _those_. */ if (!use_meta) if ((ch < KEY_MIN) && (ch & 0x80)) ch &= 0x7f; T(("wgetch returning : %s", _tracechar(ch))); *result = ch; returnCode(ch >= KEY_MIN ? KEY_CODE_YES : OK); }
dupwin(WINDOW *win) /* make an exact duplicate of the given window */ { WINDOW *nwin = 0; size_t linesize; int i; T((T_CALLED("dupwin(%p)"), (void *) win)); if (win != 0) { #if NCURSES_SP_FUNCS SCREEN *sp = _nc_screen_of(win); #endif _nc_lock_global(curses); if (win->_flags & _ISPAD) { nwin = NCURSES_SP_NAME(newpad) (NCURSES_SP_ARGx win->_maxy + 1, win->_maxx + 1); } else { nwin = NCURSES_SP_NAME(newwin) (NCURSES_SP_ARGx win->_maxy + 1, win->_maxx + 1, win->_begy, win->_begx); } if (nwin != 0) { nwin->_curx = win->_curx; nwin->_cury = win->_cury; nwin->_maxy = win->_maxy; nwin->_maxx = win->_maxx; nwin->_begy = win->_begy; nwin->_begx = win->_begx; nwin->_yoffset = win->_yoffset; nwin->_flags = win->_flags & ~_SUBWIN; /* Due to the use of newwin(), the clone is not a subwindow. * The text is really copied into the clone. */ WINDOW_ATTRS(nwin) = WINDOW_ATTRS(win); nwin->_nc_bkgd = win->_nc_bkgd; nwin->_notimeout = win->_notimeout; nwin->_clear = win->_clear; nwin->_leaveok = win->_leaveok; nwin->_scroll = win->_scroll; nwin->_idlok = win->_idlok; nwin->_idcok = win->_idcok; nwin->_immed = win->_immed; nwin->_sync = win->_sync; nwin->_use_keypad = win->_use_keypad; nwin->_delay = win->_delay; nwin->_parx = 0; nwin->_pary = 0; nwin->_parent = (WINDOW *) 0; /* See above: the clone isn't a subwindow! */ nwin->_regtop = win->_regtop; nwin->_regbottom = win->_regbottom; if (win->_flags & _ISPAD) nwin->_pad = win->_pad; linesize = (unsigned) (win->_maxx + 1) * sizeof(NCURSES_CH_T); for (i = 0; i <= nwin->_maxy; i++) { memcpy(nwin->_line[i].text, win->_line[i].text, linesize); nwin->_line[i].firstchar = win->_line[i].firstchar; nwin->_line[i].lastchar = win->_line[i].lastchar; } } _nc_unlock_global(curses); } returnWin(nwin); }
field_status(const FIELD *field) { T((T_CALLED("field_status(%p)"), (const void *)field)); returnBool((Normalize_Field(field)->status & _CHANGED) ? TRUE : FALSE); }
#include <curses.priv.h> MODULE_ID("$Id: lib_chgat.c,v 1.12 2017/03/16 23:45:20 tom Exp $") NCURSES_EXPORT(int) wchgat(WINDOW *win, int n, attr_t attr, NCURSES_PAIRS_T pair_arg, const void *opts GCC_UNUSED) { int code = ERR; int color_pair = pair_arg; T((T_CALLED("wchgat(%p,%d,%s,%d)"), (void *) win, n, _traceattr(attr), color_pair)); set_extended_pair(opts, color_pair); if (win) { struct ldat *line = &(win->_line[win->_cury]); int i; toggle_attr_on(attr, ColorPair(color_pair)); for (i = win->_curx; i <= win->_maxx && (n == -1 || (n-- > 0)); i++) { SetAttr(line->text[i], attr); SetPair(line->text[i], color_pair);
wresize(WINDOW *win, int ToLines, int ToCols) { int col, row, size_x, size_y; struct ldat *pline; struct ldat *new_lines = 0; #ifdef TRACE T((T_CALLED("wresize(%p,%d,%d)"), win, ToLines, ToCols)); if (win) { TR(TRACE_UPDATE, ("...beg (%ld, %ld), max(%ld,%ld), reg(%ld,%ld)", (long) win->_begy, (long) win->_begx, (long) win->_maxy, (long) win->_maxx, (long) win->_regtop, (long) win->_regbottom)); if (USE_TRACEF(TRACE_UPDATE)) { _tracedump("...before", win); _nc_unlock_global(tracef); } } #endif if (!win || --ToLines < 0 || --ToCols < 0) returnCode(ERR); size_x = win->_maxx; size_y = win->_maxy; if (ToLines == size_y && ToCols == size_x) returnCode(OK); if ((win->_flags & _SUBWIN)) { /* * Check if the new limits will fit into the parent window's size. If * not, do not resize. We could adjust the location of the subwindow, * but the application may not like that. */ if (win->_pary + ToLines > win->_parent->_maxy || win->_parx + ToCols > win->_parent->_maxx) { returnCode(ERR); } pline = win->_parent->_line; } else { pline = 0; } /* * Allocate new memory as needed. Do the allocations without modifying * the original window, in case an allocation fails. Always allocate * (at least temporarily) the array pointing to the individual lines. */ new_lines = typeCalloc(struct ldat, (unsigned) (ToLines + 1)); if (new_lines == 0) returnCode(ERR); /* * For each line in the target, allocate or adjust pointers for the * corresponding text, depending on whether this is a window or a * subwindow. */ for (row = 0; row <= ToLines; ++row) { int begin = (row > size_y) ? 0 : (size_x + 1); int end = ToCols; NCURSES_CH_T *s; if (!(win->_flags & _SUBWIN)) { if (row <= size_y) { if (ToCols != size_x) { if ((s = typeMalloc(NCURSES_CH_T, ToCols + 1)) == 0) returnCode(cleanup_lines(new_lines, row)); for (col = 0; col <= ToCols; ++col) { s[col] = (col <= size_x ? win->_line[row].text[col] : win->_nc_bkgd); } } else { s = win->_line[row].text; } } else { if ((s = typeMalloc(NCURSES_CH_T, ToCols + 1)) == 0) returnCode(cleanup_lines(new_lines, row)); for (col = 0; col <= ToCols; ++col) s[col] = win->_nc_bkgd; } } else { s = &pline[win->_pary + row].text[win->_parx]; } if_USE_SCROLL_HINTS(new_lines[row].oldindex = row); if (row <= size_y) { new_lines[row].firstchar = win->_line[row].firstchar; new_lines[row].lastchar = win->_line[row].lastchar; } if ((ToCols != size_x) || (row > size_y)) { if (end >= begin) { /* growing */ if (new_lines[row].firstchar < begin) new_lines[row].firstchar = begin; } else { /* shrinking */ new_lines[row].firstchar = 0; } new_lines[row].lastchar = ToCols; } new_lines[row].text = s; } /* * Dispose of unwanted memory. */ if (!(win->_flags & _SUBWIN)) { if (ToCols == size_x) { for (row = ToLines + 1; row <= size_y; row++) { free(win->_line[row].text); } } else { for (row = 0; row <= size_y; row++) { free(win->_line[row].text); } } } free(win->_line); win->_line = new_lines; /* * Finally, adjust the parameters showing screen size and cursor * position: */ win->_maxx = ToCols; win->_maxy = ToLines; if (win->_regtop > win->_maxy) win->_regtop = win->_maxy; if (win->_regbottom > win->_maxy || win->_regbottom == size_y) win->_regbottom = win->_maxy; if (win->_curx > win->_maxx) win->_curx = win->_maxx; if (win->_cury > win->_maxy) win->_cury = win->_maxy; /* * Check for subwindows of this one, and readjust pointers to our text, * if needed. */ repair_subwindows(win); #ifdef TRACE TR(TRACE_UPDATE, ("...beg (%ld, %ld), max(%ld,%ld), reg(%ld,%ld)", (long) win->_begy, (long) win->_begx, (long) win->_maxy, (long) win->_maxx, (long) win->_regtop, (long) win->_regbottom)); if (USE_TRACEF(TRACE_UPDATE)) { _tracedump("...after:", win); _nc_unlock_global(tracef); } #endif returnCode(OK); }
wadd_wchnstr(WINDOW *win, const cchar_t *astr, int n) { NCURSES_CH_T blank = NewChar(BLANK_TEXT); NCURSES_SIZE_T y = win->_cury; NCURSES_SIZE_T x = win->_curx; int code = OK; struct ldat *line; int i, j, start, len, end; T((T_CALLED("wadd_wchnstr(%p,%s,%d)"), win, _nc_viscbuf(astr, n), n)); if (!win) returnCode(ERR); if (n < 0) { n = _nc_wchstrlen(astr); } if (n > win->_maxx - x + 1) n = win->_maxx - x + 1; if (n == 0) returnCode(code); line = &(win->_line[y]); start = x; end = x + n - 1; /* * Reset orphaned cells of multi-column characters that extend up to the * new string's location to blanks. */ if (x > 0 && isWidecExt(line->text[x])) { for (i = 0; i <= x; ++i) { if (!isWidecExt(line->text[x - i])) { /* must be isWidecBase() */ start -= i; while (i > 0) { line->text[x - i--] = _nc_render(win, blank); } break; } } } /* * Copy the new string to the window. */ for (i = 0; i < n && x <= win->_maxx; ++i) { if (isWidecExt(astr[i])) continue; len = wcwidth(CharOf(astr[i])); if (x + len - 1 <= win->_maxx) { line->text[x] = _nc_render(win, astr[i]); if (len > 1) { for (j = 0; j < len; ++j) { if (j != 0) { line->text[x + j] = line->text[x]; } SetWidecExt(line->text[x + j], j); } } x += len; end += len - 1; } else { break; } } /* * Set orphaned cells of multi-column characters which lie after the new * string to blanks. */ while (x <= win->_maxx && isWidecExt(line->text[x])) { line->text[x] = _nc_render(win, blank); ++end; ++x; } CHANGED_RANGE(line, start, end); _nc_synchook(win); returnCode(code); }
static inline int #endif wborder_set(WINDOW *win, const ARG_CH_T ls, const ARG_CH_T rs, const ARG_CH_T ts, const ARG_CH_T bs, const ARG_CH_T tl, const ARG_CH_T tr, const ARG_CH_T bl, const ARG_CH_T br) { NCURSES_SIZE_T i; NCURSES_SIZE_T endx, endy; NCURSES_CH_T wls, wrs, wts, wbs, wtl, wtr, wbl, wbr; T((T_CALLED("wborder(%p,%s,%s,%s,%s,%s,%s,%s,%s)"), win, _tracech_t2(1, ls), _tracech_t2(2, rs), _tracech_t2(3, ts), _tracech_t2(4, bs), _tracech_t2(5, tl), _tracech_t2(6, tr), _tracech_t2(7, bl), _tracech_t2(8, br))); if (!win) returnCode(ERR); #define RENDER_WITH_DEFAULT(ch,def) \ if (ch == 0) \ SetChar(w ## ch,ChCharOf(def),ChAttrOf(def)); \ else w ## ch = CHDEREF(ch); \ w ## ch = _nc_render(win, w ## ch) RENDER_WITH_DEFAULT(ls, ACS_VLINE); RENDER_WITH_DEFAULT(rs, ACS_VLINE); RENDER_WITH_DEFAULT(ts, ACS_HLINE); RENDER_WITH_DEFAULT(bs, ACS_HLINE); RENDER_WITH_DEFAULT(tl, ACS_ULCORNER); RENDER_WITH_DEFAULT(tr, ACS_URCORNER); RENDER_WITH_DEFAULT(bl, ACS_LLCORNER); RENDER_WITH_DEFAULT(br, ACS_LRCORNER); T(("using %s, %s, %s, %s, %s, %s, %s, %s", _tracech_t2(1, CHREF(wls)), _tracech_t2(2, CHREF(wrs)), _tracech_t2(3, CHREF(wts)), _tracech_t2(4, CHREF(wbs)), _tracech_t2(5, CHREF(wtl)), _tracech_t2(6, CHREF(wtr)), _tracech_t2(7, CHREF(wbl)), _tracech_t2(8, CHREF(wbr)))); endx = win->_maxx; endy = win->_maxy; for (i = 0; i <= endx; i++) { win->_line[0].text[i] = wts; win->_line[endy].text[i] = wbs; } win->_line[endy].firstchar = win->_line[0].firstchar = 0; win->_line[endy].lastchar = win->_line[0].lastchar = endx; for (i = 0; i <= endy; i++) { win->_line[i].text[0] = wls; win->_line[i].text[endx] = wrs; win->_line[i].firstchar = 0; win->_line[i].lastchar = endx; } win->_line[0].text[0] = wtl; win->_line[0].text[endx] = wtr; win->_line[endy].text[0] = wbl; win->_line[endy].text[endx] = wbr; _nc_synchook(win); returnCode(OK); }
/* ** lib_chgat.c ** ** The routine wchgat(). ** */ #include <curses.priv.h> MODULE_ID("$Id: lib_chgat.c,v 1.1.1.1 2001/11/29 20:40:56 jevans Exp $") NCURSES_EXPORT(int) wchgat (WINDOW *win, int n, attr_t attr, short color, const void *opts GCC_UNUSED) { int i; T((T_CALLED("wchgat(%p,%d,%s,%d)"), win, n, _traceattr(attr), color)); if (win) { toggle_attr_on(attr, COLOR_PAIR(color)); for (i = win->_curx; i <= win->_maxx && (n == -1 || (n-- > 0)); i++) SetAttr(win->_line[win->_cury].text[i], attr); returnCode(OK); } else returnCode(ERR); }
_nc_slk_initialize(WINDOW *stwin, int cols) { int i, x; int res = OK; unsigned max_length; T((T_CALLED("_nc_slk_initialize()"))); if (SP->_slk) { /* we did this already, so simply return */ returnCode(OK); } else if ((SP->_slk = typeCalloc(SLK, 1)) == 0) returnCode(ERR); SP->_slk->ent = NULL; /* * If we use colors, vidputs() will suppress video attributes that conflict * with colors. In that case, we're still guaranteed that "reverse" would * work. */ if ((no_color_video & 1) == 0) SetAttr(SP->_slk->attr, A_STANDOUT); else SetAttr(SP->_slk->attr, A_REVERSE); SP->_slk->maxlab = ((num_labels > 0) ? num_labels : MAX_SKEY(_nc_slk_format)); SP->_slk->maxlen = ((num_labels > 0) ? label_width * label_height : MAX_SKEY_LEN(_nc_slk_format)); SP->_slk->labcnt = ((SP->_slk->maxlab < MAX_SKEY(_nc_slk_format)) ? MAX_SKEY(_nc_slk_format) : SP->_slk->maxlab); if (SP->_slk->maxlen <= 0 || SP->_slk->labcnt <= 0 || (SP->_slk->ent = typeCalloc(slk_ent, (unsigned) SP->_slk->labcnt)) == NULL) returnCode(slk_failed()); max_length = SP->_slk->maxlen; for (i = 0; i < SP->_slk->labcnt; i++) { size_t used = max_length + 1; if ((SP->_slk->ent[i].ent_text = (char *) _nc_doalloc(0, used)) == 0) returnCode(slk_failed()); memset(SP->_slk->ent[i].ent_text, 0, used); if ((SP->_slk->ent[i].form_text = (char *) _nc_doalloc(0, used)) == 0) returnCode(slk_failed()); memset(SP->_slk->ent[i].form_text, 0, used); memset(SP->_slk->ent[i].form_text, ' ', max_length); SP->_slk->ent[i].visible = (i < SP->_slk->maxlab); } if (_nc_slk_format >= 3) { /* PC style */ int gap = (cols - 3 * (3 + 4 * max_length)) / 2; if (gap < 1) gap = 1; for (i = x = 0; i < SP->_slk->maxlab; i++) { SP->_slk->ent[i].ent_x = x; x += max_length; x += (i == 3 || i == 7) ? gap : 1; } slk_paint_info(stwin); } else { if (_nc_slk_format == 2) { /* 4-4 */ int gap = cols - (SP->_slk->maxlab * max_length) - 6; if (gap < 1) gap = 1; for (i = x = 0; i < SP->_slk->maxlab; i++) { SP->_slk->ent[i].ent_x = x; x += max_length; x += (i == 3) ? gap : 1; } } else { if (_nc_slk_format == 1) { /* 1 -> 3-2-3 */ int gap = (cols - (SP->_slk->maxlab * max_length) - 5) / 2; if (gap < 1) gap = 1; for (i = x = 0; i < SP->_slk->maxlab; i++) { SP->_slk->ent[i].ent_x = x; x += max_length; x += (i == 2 || i == 4) ? gap : 1; } } else returnCode(slk_failed()); } } SP->_slk->dirty = TRUE; if ((SP->_slk->win = stwin) == NULL) { returnCode(slk_failed()); } /* We now reset the format so that the next newterm has again * per default no SLK keys and may call slk_init again to * define a new layout. (juergen 03-Mar-1999) */ SP->slk_format = _nc_slk_format; _nc_slk_format = 0; returnCode(res); }
int wnoutrefresh(WINDOW *win) { short limit_x; short i, j; short begx; short begy; short m, n; bool wide; T((T_CALLED("wnoutrefresh(%p)"), win)); #ifdef TRACE if (_nc_tracing & TRACE_UPDATE) _tracedump("...win", win); #endif /* TRACE */ /* * This function will break badly if we try to refresh a pad. */ if ((win == 0) || (win->_flags & _ISPAD)) returnCode(ERR); /* put them here so "win == 0" won't break our code */ begx = win->_begx; begy = win->_begy; /* * If 'newscr' has a different background than the window that we're * trying to refresh, we'll have to copy the whole thing. */ if (win->_bkgd != newscr->_bkgd) { touchwin(win); newscr->_bkgd = win->_bkgd; } newscr->_attrs = win->_attrs; /* merge in change information from all subwindows of this window */ wsyncdown(win); /* * For pure efficiency, we'd want to transfer scrolling information * from the window to newscr whenever the window is wide enough that * its update will dominate the cost of the update for the horizontal * band of newscr that it occupies. Unfortunately, this threshold * tends to be complex to estimate, and in any case scrolling the * whole band and rewriting the parts outside win's image would look * really ugly. So. What we do is consider the window "wide" if it * either (a) occupies the whole width of newscr, or (b) occupies * all but at most one column on either vertical edge of the screen * (this caters to fussy people who put boxes around full-screen * windows). Note that changing this formula will not break any code, * merely change the costs of various update cases. */ wide = (begx <= 1 && win->_maxx >= (newscr->_maxx - 1)); win->_flags &= ~_HASMOVED; /* * Microtweaking alert! This double loop is one of the genuine * hot spots in the code. Even gcc doesn't seem to do enough * common-subexpression chunking to make it really tense, * so we'll force the issue. */ /* limit(n) */ limit_x = win->_maxx; /* limit(j) */ if (limit_x > win->_maxx) limit_x = win->_maxx; for (i = 0, m = begy + win->_yoffset; i <= win->_maxy && m <= newscr->_maxy; i++, m++) { register struct ldat *nline = &newscr->_line[m]; register struct ldat *oline = &win->_line[i]; if (oline->firstchar != _NOCHANGE) { int last = oline->lastchar; if (last > limit_x) last = limit_x; for (j = oline->firstchar, n = j + begx; j <= last; j++, n++) { if (oline->text[j] != nline->text[n]) { nline->text[n] = oline->text[j]; CHANGED_CELL(nline, n); } } } #if USE_SCROLL_HINTS if (wide) { int oind = oline->oldindex; nline->oldindex = (oind == _NEWINDEX) ? _NEWINDEX : begy + oind + win->_yoffset; } #endif /* USE_SCROLL_HINTS */ oline->firstchar = oline->lastchar = _NOCHANGE; if_USE_SCROLL_HINTS(oline->oldindex = i); } if (win->_clear) { win->_clear = FALSE; newscr->_clear = TRUE; } if (! win->_leaveok) { newscr->_cury = win->_cury + win->_begy + win->_yoffset; newscr->_curx = win->_curx + win->_begx; } newscr->_leaveok = win->_leaveok; #ifdef TRACE if (_nc_tracing & TRACE_UPDATE) _tracedump("newscr", newscr); #endif /* TRACE */ returnCode(OK); }
dupwin(WINDOW *win) /* make an exact duplicate of the given window */ { WINDOW *nwin = 0; size_t linesize; int i; T((T_CALLED("dupwin(%p)"), win)); if (win != 0) { if (win->_flags & _ISPAD) { nwin = newpad(win->_maxy + 1, win->_maxx + 1); } else { nwin = newwin(win->_maxy + 1, win->_maxx + 1, win->_begy, win->_begx); } if (nwin != 0) { nwin->_curx = win->_curx; nwin->_cury = win->_cury; nwin->_maxy = win->_maxy; nwin->_maxx = win->_maxx; nwin->_begy = win->_begy; nwin->_begx = win->_begx; nwin->_yoffset = win->_yoffset; nwin->_flags = win->_flags & ~_SUBWIN; /* Due to the use of newwin(), the clone is not a subwindow. * The text is really copied into the clone. */ nwin->_attrs = win->_attrs; nwin->_nc_bkgd = win->_nc_bkgd; nwin->_notimeout = win->_notimeout; nwin->_clear = win->_clear; nwin->_leaveok = win->_leaveok; nwin->_scroll = win->_scroll; nwin->_idlok = win->_idlok; nwin->_idcok = win->_idcok; nwin->_immed = win->_immed; nwin->_sync = win->_sync; nwin->_use_keypad = win->_use_keypad; nwin->_delay = win->_delay; nwin->_parx = 0; nwin->_pary = 0; nwin->_parent = (WINDOW *) 0; /* See above: the clone isn't a subwindow! */ nwin->_regtop = win->_regtop; nwin->_regbottom = win->_regbottom; if (win->_flags & _ISPAD) nwin->_pad = win->_pad; linesize = (win->_maxx + 1) * sizeof(NCURSES_CH_T); for (i = 0; i <= nwin->_maxy; i++) { memcpy(nwin->_line[i].text, win->_line[i].text, linesize); nwin->_line[i].firstchar = win->_line[i].firstchar; nwin->_line[i].lastchar = win->_line[i].lastchar; } } } returnWin(nwin); }
getwin(FILE * filep) { WINDOW tmp, *nwin; int n; T((T_CALLED("getwin(%p)"), filep)); clearerr(filep); (void) fread(&tmp, sizeof(WINDOW), 1, filep); if (ferror(filep)) returnWin(0); if (tmp._flags & _ISPAD) { nwin = newpad(tmp._maxy + 1, tmp._maxx + 1); } else { nwin = newwin(tmp._maxy + 1, tmp._maxx + 1, 0, 0); } /* * We deliberately do not restore the _parx, _pary, or _parent * fields, because the window hierarchy within which they * made sense is probably gone. */ if (nwin != 0) { nwin->_curx = tmp._curx; nwin->_cury = tmp._cury; nwin->_maxy = tmp._maxy; nwin->_maxx = tmp._maxx; nwin->_begy = tmp._begy; nwin->_begx = tmp._begx; nwin->_yoffset = tmp._yoffset; nwin->_flags = tmp._flags & ~(_SUBWIN); nwin->_attrs = tmp._attrs; nwin->_nc_bkgd = tmp._nc_bkgd; nwin->_notimeout = tmp._notimeout; nwin->_clear = tmp._clear; nwin->_leaveok = tmp._leaveok; nwin->_idlok = tmp._idlok; nwin->_idcok = tmp._idcok; nwin->_immed = tmp._immed; nwin->_scroll = tmp._scroll; nwin->_sync = tmp._sync; nwin->_use_keypad = tmp._use_keypad; nwin->_delay = tmp._delay; nwin->_regtop = tmp._regtop; nwin->_regbottom = tmp._regbottom; if (tmp._flags & _ISPAD) nwin->_pad = tmp._pad; for (n = 0; n <= nwin->_maxy; n++) { clearerr(filep); (void) fread(nwin->_line[n].text, sizeof(NCURSES_CH_T), (size_t) (nwin->_maxx + 1), filep); if (ferror(filep)) { delwin(nwin); returnWin(0); } } touchwin(nwin); } returnWin(nwin); }
field_type(const FIELD *field) { T((T_CALLED("field_type(%p)"), field)); returnFieldType(Normalize_Field(field)->type); }
resetty(void) { T((T_CALLED("resetty()"))); returnCode(_nc_set_tty_mode(&buf)); }
form_userptr(const FORM *form) { T((T_CALLED("form_userptr(%p)"), (const void *)form)); returnVoidPtr(Normalize_Form(form)->usrptr); }
/*--------------------------------------------------------------------------- | Facility : libnform | Function : static int Connect_Fields(FORM *form, FIELD **fields) | | Description : Set association between form and array of fields. | | Return Values : E_OK - no error | E_CONNECTED - a field is already connected | E_BAD_ARGUMENT - Invalid form pointer or field array | E_SYSTEM_ERROR - not enough memory +--------------------------------------------------------------------------*/ static int Connect_Fields(FORM *form, FIELD **fields) { int field_cnt, j; int page_nr; int maximum_row_in_field, maximum_col_in_field; _PAGE *pg; T((T_CALLED("Connect_Fields(%p,%p)"), (void *)form, (void *)fields)); assert(form); form->field = fields; form->maxfield = 0; form->maxpage = 0; if (!fields) RETURN(E_OK); page_nr = 0; /* store formpointer in fields and count pages */ for (field_cnt = 0; fields[field_cnt]; field_cnt++) { if (fields[field_cnt]->form) RETURN(E_CONNECTED); if (field_cnt == 0 || (fields[field_cnt]->status & _NEWPAGE)) page_nr++; fields[field_cnt]->form = form; } if (field_cnt == 0 || (short)field_cnt < 0) RETURN(E_BAD_ARGUMENT); /* allocate page structures */ if ((pg = typeMalloc(_PAGE, page_nr)) != (_PAGE *) 0) { T((T_CREATE("_PAGE %p"), (void *)pg)); form->page = pg; } else RETURN(E_SYSTEM_ERROR); /* Cycle through fields and calculate page boundaries as well as size of the form */ for (j = 0; j < field_cnt; j++) { if (j == 0) pg->pmin = j; else { if (fields[j]->status & _NEWPAGE) { pg->pmax = j - 1; pg++; pg->pmin = j; } } maximum_row_in_field = fields[j]->frow + fields[j]->rows; maximum_col_in_field = fields[j]->fcol + fields[j]->cols; if (form->rows < maximum_row_in_field) form->rows = maximum_row_in_field; if (form->cols < maximum_col_in_field) form->cols = maximum_col_in_field; } pg->pmax = field_cnt - 1; form->maxfield = field_cnt; form->maxpage = page_nr; /* Sort fields on form pages */ for (page_nr = 0; page_nr < form->maxpage; page_nr++) { FIELD *fld = (FIELD *)0; for (j = form->page[page_nr].pmin; j <= form->page[page_nr].pmax; j++) { fields[j]->index = j; fields[j]->page = page_nr; fld = Insert_Field_By_Position(fields[j], fld); } if (fld) { form->page[page_nr].smin = fld->index; form->page[page_nr].smax = fld->sprev->index; } else { form->page[page_nr].smin = 0; form->page[page_nr].smax = 0; } } RETURN(E_OK); }
NCURSES_SP_NAME(slk_set) (NCURSES_SP_DCLx int i, const char *astr, int format) { SLK *slk; int offset; int numchrs; int numcols; int limit; const char *str = astr; const char *p; T((T_CALLED("slk_set(%p, %d, \"%s\", %d)"), (void *) SP_PARM, i, str, format)); if (SP_PARM == 0 || (slk = SP_PARM->_slk) == 0 || i < 1 || i > slk->labcnt || format < 0 || format > 2) returnCode(ERR); if (str == 0) str = ""; --i; /* Adjust numbering of labels */ limit = MAX_SKEY_LEN(SP_PARM->slk_format); while (isspace(UChar(*str))) str++; /* skip over leading spaces */ p = str; #if USE_WIDEC_SUPPORT numcols = 0; while (*p != 0) { mbstate_t state; wchar_t wc; size_t need; init_mb(state); need = mbrtowc(0, p, strlen(p), &state); if (need == (size_t) -1) break; mbrtowc(&wc, p, need, &state); if (!iswprint((wint_t) wc)) break; if (wcwidth(wc) + numcols > limit) break; numcols += wcwidth(wc); p += need; } numchrs = (p - str); #else while (isprint(UChar(*p))) p++; /* The first non-print stops */ numcols = (p - str); if (numcols > limit) numcols = limit; numchrs = numcols; #endif FreeIfNeeded(slk->ent[i].ent_text); if ((slk->ent[i].ent_text = strdup(str)) == 0) returnCode(ERR); slk->ent[i].ent_text[numchrs] = '\0'; if ((slk->ent[i].form_text = (char *) _nc_doalloc(slk->ent[i].form_text, (unsigned) (limit + numchrs + 1)) ) == 0) returnCode(ERR); switch (format) { default: case 0: /* left-justified */ offset = 0; break; case 1: /* centered */ offset = (limit - numcols) / 2; break; case 2: /* right-justified */ offset = limit - numcols; break; } if (offset <= 0) offset = 0; else memset(slk->ent[i].form_text, ' ', (unsigned) offset); memcpy(slk->ent[i].form_text + offset, slk->ent[i].ent_text, (unsigned) numchrs); if (offset < limit) { memset(slk->ent[i].form_text + offset + numchrs, ' ', (unsigned) (limit - (offset + numcols))); } slk->ent[i].form_text[numchrs - numcols + limit] = 0; slk->ent[i].dirty = TRUE; returnCode(OK); }
field_count(const FORM *form) { T((T_CALLED("field_count(%p)"), (const void *)form)); returnCode(Normalize_Form(form)->maxfield); }
item_name(const ITEM * item) { T((T_CALLED("item_name(%p)"), item)); returnCPtr((item) ? item->name.str : (char *)0); }
tgetent(char *bufp, const char *name) { int errcode; int n; bool found_cache = FALSE; START_TRACE(); T((T_CALLED("tgetent()"))); _nc_setupterm((NCURSES_CONST char *) name, STDOUT_FILENO, &errcode, TRUE); /* * In general we cannot tell if the fixed sgr0 is still used by the * caller, but if tgetent() is called with the same buffer, that is * good enough, since the previous data would be invalidated by the * current call. * * bufp may be a null pointer, e.g., GNU termcap. That allocates data, * which is good until the next tgetent() call. The conventional termcap * is inconvenient because of the fixed buffer size, but because it uses * caller-supplied buffers, can have multiple terminal descriptions in * use at a given time. */ for (n = 0; n < TGETENT_MAX; ++n) { bool same_result = (MyCache[n].last_used && MyCache[n].last_bufp == bufp); if (same_result) { CacheInx = n; if (FIX_SGR0 != 0) { FreeAndNull(FIX_SGR0); } /* * Also free the terminfo data that we loaded (much bigger leak). */ if (LAST_TRM != 0 && LAST_TRM != cur_term) { TERMINAL *trm = LAST_TRM; del_curterm(LAST_TRM); for (CacheInx = 0; CacheInx < TGETENT_MAX; ++CacheInx) if (LAST_TRM == trm) LAST_TRM = 0; CacheInx = n; } found_cache = TRUE; break; } } if (!found_cache) { int best = 0; for (CacheInx = 0; CacheInx < TGETENT_MAX; ++CacheInx) { if (LAST_SEQ < MyCache[best].sequence) { best = CacheInx; } } CacheInx = best; } LAST_TRM = cur_term; LAST_SEQ = ++CacheSeq; PC = 0; UP = 0; BC = 0; FIX_SGR0 = 0; /* don't free it - application may still use */ if (errcode == 1) { if (cursor_left) if ((backspaces_with_bs = (char) !strcmp(cursor_left, "\b")) == 0) backspace_if_not_bs = cursor_left; /* we're required to export these */ if (pad_char != NULL) PC = pad_char[0]; if (cursor_up != NULL) UP = cursor_up; if (backspace_if_not_bs != NULL) BC = backspace_if_not_bs; if ((FIX_SGR0 = _nc_trim_sgr0(&(cur_term->type))) != 0) { if (!strcmp(FIX_SGR0, exit_attribute_mode)) { if (FIX_SGR0 != exit_attribute_mode) { free(FIX_SGR0); } FIX_SGR0 = 0; } } LAST_BUF = bufp; LAST_USE = TRUE; SetNoPadding(SP); (void) baudrate(); /* sets ospeed as a side-effect */ /* LINT_PREPRO #if 0*/ #include <capdefaults.c> /* LINT_PREPRO #endif*/ } returnCode(errcode); }
item_description(const ITEM * item) { T((T_CALLED("item_description(%p)"), item)); returnCPtr((item) ? item->description.str : (char *)0); }
T((T_CALLED("keypad(%p,%d)"), win, flag)); if (win) { win->_use_keypad = flag; returnCode(_nc_keypad(SP, flag)); } else returnCode(ERR); } NCURSES_EXPORT(int) meta(WINDOW *win GCC_UNUSED, bool flag) { int result; /* Ok, we stay relaxed and don't signal an error if win is NULL */ T((T_CALLED("meta(%p,%d)"), win, flag)); result = _nc_meta(SP, flag); returnCode(result); } /* curs_set() moved here to narrow the kernel interface */ NCURSES_EXPORT(int) curs_set(int vis) { int result; T((T_CALLED("curs_set(%d)"), vis)); result = _nc_curs_set(SP, vis); returnCode(result); }
field_opts(const FIELD *field) { T((T_CALLED("field_opts(%p)"), field)); returnCode(ALL_FIELD_OPTS & Normalize_Field(field)->opts); }