static void setup(VALUE self) { TERMINAL *old; TERMINAL *term = check_rt(self); if (term == NULL) { rb_raise(eTermInfoError, "terminfo object not initialized"); } if (cur_term == term) return; old = set_curterm(term); }
static void cleanup(MYDATA * data) { set_curterm(data->term); del_curterm(data->term); #if !NO_LEAKS free(data->sp); /* cannot use delscreen in tinfo */ #endif free(data); }
set_term(SCREEN *screenp) { SCREEN *oldSP; SCREEN *newSP; T((T_CALLED("set_term(%p)"), screenp)); _nc_lock_global(curses); oldSP = SP; _nc_set_screen(screenp); newSP = SP; if (newSP != 0) { set_curterm(newSP->_term); #if !USE_REENTRANT curscr = newSP->_curscr; newscr = newSP->_newscr; stdscr = newSP->_stdscr; COLORS = newSP->_color_count; COLOR_PAIRS = newSP->_pair_count; #endif } else { set_curterm(0); #if !USE_REENTRANT curscr = 0; newscr = 0; stdscr = 0; COLORS = 0; COLOR_PAIRS = 0; #endif } _nc_unlock_global(curses); T((T_RETURN("%p"), oldSP)); return (oldSP); }
static void curses_resume(const struct sessmgr_sw *sm) { extern int Numrows, Numcols; if (!--Suspense) { #ifdef RAW_SESSMGR set_curterm(my_term); #endif clearok(((struct curses_data *) curscreen)->win, TRUE); wrefresh(((struct curses_data *) curscreen)->win); Numrows = LINES; Numcols = COLS; } }
/* * _cursesi_resetterm -- * Copy the terminal instance data for the given screen to the global * variables. */ void _cursesi_resetterm(SCREEN *screen) { LINES = screen->LINES; COLS = screen->COLS; __GT = screen->GT; __noqch = screen->noqch; __mask_op = screen->mask_op; __mask_me = screen->mask_me; __mask_ue = screen->mask_ue; __mask_se = screen->mask_se; set_curterm(screen->term); }
/* * Switch current terminal for Curses layer. */ SCREEN * set_term(SCREEN *screen) { SCREEN *osp = __m_screen; if (screen != NULL) { (void) set_curterm(screen->_term); curscr = screen->_curscr; __m_screen = screen; LINES = lines; COLS = columns; COLORS = max_colors; COLOR_PAIRS = max_pairs; } return (osp); }
del_curterm(TERMINAL * termp) { int rc = ERR; T((T_CALLED("del_curterm(%p)"), termp)); _nc_lock_global(curses); if (termp != 0) { _nc_free_termtype(&(termp->type)); FreeIfNeeded(termp->_termname); free(termp); if (termp == cur_term) set_curterm(0); rc = OK; } _nc_unlock_global(curses); returnCode(rc); }
set_term(SCREEN *screenp) { SCREEN *oldSP; T((T_CALLED("set_term(%p)"), screenp)); oldSP = SP; _nc_set_screen(screenp); set_curterm(SP->_term); curscr = SP->_curscr; newscr = SP->_newscr; stdscr = SP->_stdscr; COLORS = SP->_color_count; COLOR_PAIRS = SP->_pair_count; T((T_RETURN("%p"), oldSP)); return (oldSP); }
int setupterm(const char *tname, int Filedes, int *errret) { struct term *term_ptr; int status; T((T_CALLED("setupterm(\"%s\",%d,%p)"), tname, Filedes, errret)); if (tname == 0) { tname = getenv("TERM"); if (tname == 0 || *tname == '\0') { ret_error0(-1, "TERM environment variable not set.\n"); } } if (strlen(tname) > MAX_NAME_SIZE) { ret_error(-1, "TERM environment must be <= %d characters.\n", MAX_NAME_SIZE); } T(("your terminal name is %s", tname)); term_ptr = typeCalloc(TERMINAL, 1); if (term_ptr == 0) { ret_error0(-1, "Not enough memory to create terminal structure.\n") ; } #if USE_DATABASE status = grab_entry(tname, &term_ptr->type); #else status = 0; #endif /* try fallback list if entry on disk */ if (status != 1) { const TERMTYPE *fallback = _nc_fallback(tname); if (fallback) { memcpy(&term_ptr->type, fallback, sizeof(TERMTYPE)); status = 1; } } if (status == -1) { ret_error0(-1, "terminals database is inaccessible\n"); } else if (status == 0) { ret_error(0, "'%s': unknown terminal type.\n", tname); } set_curterm(term_ptr); if (command_character && getenv("CC")) do_prototype(); strlcpy(ttytype, cur_term->type.term_names, NAMESIZE); /* * Allow output redirection. This is what SVr3 does. * If stdout is directed to a file, screen updates go * to standard error. */ if (Filedes == STDOUT_FILENO && !isatty(Filedes)) Filedes = STDERR_FILENO; cur_term->Filedes = Filedes; _nc_get_screensize(&LINES, &COLS); if (errret) *errret = 1; T((T_CREATE("screen %s %dx%d"), tname, LINES, COLS)); if (generic_type) { ret_error(0, "'%s': I need something more specific.\n", tname); } if (hard_copy) { ret_error(1, "'%s': I can't handle hardcopy terminals.\n", tname); } returnCode(OK); }
_nc_resolve_uses2(bool fullresolve, bool literal) /* try to resolve all use capabilities */ { ENTRY *qp, *rp, *lastread = 0; bool keepgoing; unsigned i; int unresolved, total_unresolved, multiples; DEBUG(2, ("RESOLUTION BEGINNING")); /* * Check for multiple occurrences of the same name. */ multiples = 0; for_entry_list(qp) { int matchcount = 0; for_entry_list(rp) { if (qp > rp && check_collisions(qp->tterm.term_names, rp->tterm.term_names, matchcount + 1)) { if (!matchcount++) { (void) fprintf(stderr, "\t%s\n", rp->tterm.term_names); } (void) fprintf(stderr, "and\t%s\n", qp->tterm.term_names); if (!remove_collision(rp->tterm.term_names, qp->tterm.term_names)) { ++multiples; } } } } if (multiples > 0) return (FALSE); DEBUG(2, ("NO MULTIPLE NAME OCCURRENCES")); /* * First resolution stage: compute link pointers corresponding to names. */ total_unresolved = 0; _nc_curr_col = -1; for_entry_list(qp) { unresolved = 0; for (i = 0; i < qp->nuses; i++) { bool foundit; char *child = _nc_first_name(qp->tterm.term_names); char *lookfor = qp->uses[i].name; long lookline = qp->uses[i].line; foundit = FALSE; _nc_set_type(child); /* first, try to resolve from in-core records */ for_entry_list(rp) { if (rp != qp && _nc_name_match(rp->tterm.term_names, lookfor, "|")) { DEBUG(2, ("%s: resolving use=%s (in core)", child, lookfor)); qp->uses[i].link = rp; foundit = TRUE; } } /* if that didn't work, try to merge in a compiled entry */ if (!foundit) { TERMTYPE thisterm; char filename[PATH_MAX]; memset(&thisterm, 0, sizeof(thisterm)); if (_nc_read_entry(lookfor, filename, &thisterm) == 1) { DEBUG(2, ("%s: resolving use=%s (compiled)", child, lookfor)); TYPE_MALLOC(ENTRY, 1, rp); rp->tterm = thisterm; rp->nuses = 0; rp->next = lastread; lastread = rp; qp->uses[i].link = rp; foundit = TRUE; } } /* no good, mark this one unresolvable and complain */ if (!foundit) { unresolved++; total_unresolved++; _nc_curr_line = (int) lookline; _nc_warning("resolution of use=%s failed", lookfor); qp->uses[i].link = 0; } } } if (total_unresolved) { /* free entries read in off disk */ _nc_free_entries(lastread); return (FALSE); } DEBUG(2, ("NAME RESOLUTION COMPLETED OK")); /* * OK, at this point all (char *) references in `name' members * have been successfully converted to (ENTRY *) pointers in * `link' members. Time to do the actual merges. */ if (fullresolve) { do { TERMTYPE merged; keepgoing = FALSE; for_entry_list(qp) { if (qp->nuses > 0) { DEBUG(2, ("%s: attempting merge", _nc_first_name(qp->tterm.term_names))); /* * If any of the use entries we're looking for is * incomplete, punt. We'll catch this entry on a * subsequent pass. */ for (i = 0; i < qp->nuses; i++) if (qp->uses[i].link->nuses) { DEBUG(2, ("%s: use entry %d unresolved", _nc_first_name(qp->tterm.term_names), i)); goto incomplete; } /* * First, make sure there is no garbage in the * merge block. As a side effect, copy into * the merged entry the name field and string * table pointer. */ _nc_copy_termtype(&merged, &(qp->tterm)); /* * Now merge in each use entry in the proper * (reverse) order. */ for (; qp->nuses; qp->nuses--) _nc_merge_entry(&merged, &qp->uses[qp->nuses - 1].link->tterm); /* * Now merge in the original entry. */ _nc_merge_entry(&merged, &qp->tterm); /* * Replace the original entry with the merged one. */ FreeIfNeeded(qp->tterm.Booleans); FreeIfNeeded(qp->tterm.Numbers); FreeIfNeeded(qp->tterm.Strings); #if NCURSES_XNAMES FreeIfNeeded(qp->tterm.ext_Names); #endif qp->tterm = merged; _nc_wrap_entry(qp, TRUE); /* * We know every entry is resolvable because name resolution * didn't bomb. So go back for another pass. */ /* FALLTHRU */ incomplete: keepgoing = TRUE; } } } while (keepgoing); DEBUG(2, ("MERGES COMPLETED OK")); } /* * We'd like to free entries read in off disk at this point, but can't. * The merge_entry() code doesn't copy the strings in the use entries, * it just aliases them. If this ever changes, do a * free_entries(lastread) here. */ DEBUG(2, ("RESOLUTION FINISHED")); if (fullresolve) if (_nc_check_termtype != 0) { _nc_curr_col = -1; for_entry_list(qp) { _nc_curr_line = (int) qp->startline; _nc_set_type(_nc_first_name(qp->tterm.term_names)); /* * tic overrides this function pointer to provide more verbose * checking. */ if (_nc_check_termtype2 != sanity_check2) { SCREEN *save_SP = SP; SCREEN fake_sp; TERMINAL fake_tm; TERMINAL *save_tm = cur_term; /* * Setup so that tic can use ordinary terminfo interface * to obtain capability information. */ memset(&fake_sp, 0, sizeof(fake_sp)); memset(&fake_tm, 0, sizeof(fake_tm)); fake_sp._term = &fake_tm; fake_tm.type = qp->tterm; _nc_set_screen(&fake_sp); set_curterm(&fake_tm); _nc_check_termtype2(&qp->tterm, literal); _nc_set_screen(save_SP); set_curterm(save_tm); } else { fixup_acsc(&qp->tterm, literal); } } DEBUG(2, ("SANITY CHECK FINISHED")); }
static int curses_init(const struct sessmgr_sw *sm) { extern int Numrows, Numcols; if (!isatty(0)) return 0; if (initted) { #ifdef RAW_SESSMGR set_curterm(my_term); #endif refresh(); /* bring curses back to life */ } else { initscr(); /* be nice to trap errors... */ #ifdef COLOR_SUPPORT /* * I assume the curses manpage tells the truth when it claims that * colors are initialized to RGB defaults. If not, I may need to set * up the colors in question... */ if (has_colors() && start_color() != ERR && COLORS >= 8) { color_pair_map = mallocw(COLOR_PAIRS * sizeof *color_pair_map); memset(color_pair_map, -1, COLOR_PAIRS * sizeof *color_pair_map); map_colors(COLOR_BLACK, COLOR_WHITE); /* default color pair */ if(!MainColors) MainColors = LIGHTGRAY+(BLACK<<4); /* not high-intensity */ } else MainColors = 0; /* no colors available */ #endif my_term = cur_term; noecho(); nonl(); raw(); keys = key_init(); key_add(key_down, DNARROW); key_add(key_f1, -3); key_add(key_f2, -4); key_add(key_f3, -5); key_add(key_f4, -6); key_add(key_f5, -7); key_add(key_f6, -8); key_add(key_f7, -9); key_add(key_f8, -10); key_add(key_f9, -11); #ifdef M_UNIX /* SCO botches it, as per usual */ key_add(key_f0, -2); #else key_add(key_f10, -2); #endif key_add(key_left, LTARROW); key_add(key_right, RTARROW); key_add(key_up, UPARROW); key_add("\177", '\b'); /* so DEL behaves as BS */ initted = 1; } Suspense = 0; Numrows = LINES; Numcols = COLS; return 1; }