static void ExitProgram(int code) { while (termcount-- > 0) _nc_free_termtype(&term[termcount], FALSE); _nc_leaks_dump_entry(); _nc_free_and_exit(code); }
/* prototype is to get gcc to accept the noreturn attribute */ static void ExitProgram(int code) { while (termcount-- > 0) _nc_free_termtype(&entries[termcount].tterm); _nc_leaks_dump_entry(); _nc_free_tic(code); }
_nc_free_entries(ENTRY * headp) /* free the allocated storage consumed by list entries */ { (void) headp; /* unused - _nc_head is altered here! */ while (_nc_head != 0) { _nc_free_termtype(&(_nc_head->tterm)); } }
del_curterm(TERMINAL * termp) { T((T_CALLED("del_curterm(%p)"), termp)); if (termp != 0) { _nc_free_termtype(&(termp->type)); free(termp); if (termp == cur_term) cur_term = 0; returnCode(OK); } returnCode(ERR); }
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); }
NCURSES_SP_NAME(del_curterm) (NCURSES_SP_DCLx TERMINAL * termp) { int rc = ERR; T((T_CALLED("del_curterm(%p, %p)"), (void *) SP_PARM, (void *) termp)); if (termp != 0) { #ifdef USE_TERM_DRIVER TERMINAL_CONTROL_BLOCK *TCB = (TERMINAL_CONTROL_BLOCK *) termp; #endif TERMINAL *cur = ( #if USE_REENTRANT NCURSES_SP_NAME(_nc_get_cur_term) (NCURSES_SP_ARG) #else cur_term #endif ); _nc_free_termtype(&(termp->type)); if (termp == cur) NCURSES_SP_NAME(set_curterm) (NCURSES_SP_ARGx 0); FreeIfNeeded(termp->_termname); #if USE_HOME_TERMINFO if (_nc_globals.home_terminfo != 0) { FreeAndNull(_nc_globals.home_terminfo); } #endif #ifdef USE_TERM_DRIVER if (TCB->drv) TCB->drv->release(TCB); #endif free(termp); rc = OK; } returnCode(rc); }
static int typelist(int eargc, char *eargv[], bool verbosity, void (*hook) (const char *, TERMTYPE *tp)) /* apply a function to each entry in given terminfo directories */ { int i; for (i = 0; i < eargc; i++) { #if USE_DATABASE if (_nc_is_dir_path(eargv[i])) { char *cwd_buf = 0; DIR *termdir; DIRENT *subdir; if ((termdir = opendir(eargv[i])) == 0) { (void) fflush(stdout); (void) fprintf(stderr, "%s: can't open terminfo directory %s\n", _nc_progname, eargv[i]); return (EXIT_FAILURE); } else if (verbosity) (void) printf("#\n#%s:\n#\n", eargv[i]); while ((subdir = readdir(termdir)) != 0) { size_t len = NAMLEN(subdir); size_t cwd_len = len + strlen(eargv[i]) + 3; char name_1[PATH_MAX]; DIR *entrydir; DIRENT *entry; cwd_buf = typeRealloc(char, cwd_len, cwd_buf); if (cwd_buf == 0) failed("realloc cwd_buf"); assert(cwd_buf != 0); strncpy(name_1, subdir->d_name, len)[len] = '\0'; if (isDotname(name_1)) continue; (void) sprintf(cwd_buf, "%s/%.*s/", eargv[i], (int) len, name_1); if (chdir(cwd_buf) != 0) continue; entrydir = opendir("."); if (entrydir == 0) { perror(cwd_buf); continue; } while ((entry = readdir(entrydir)) != 0) { char name_2[PATH_MAX]; TERMTYPE lterm; char *cn; int status; len = NAMLEN(entry); strncpy(name_2, entry->d_name, len)[len] = '\0'; if (isDotname(name_2) || !_nc_is_file_path(name_2)) continue; status = _nc_read_file_entry(name_2, <erm); if (status <= 0) { (void) fflush(stdout); (void) fprintf(stderr, "%s: couldn't open terminfo file %s.\n", _nc_progname, name_2); return (EXIT_FAILURE); } /* only visit things once, by primary name */ cn = _nc_first_name(lterm.term_names); if (!strcmp(cn, name_2)) { /* apply the selected hook function */ (*hook) (cn, <erm); } _nc_free_termtype(<erm); } closedir(entrydir); } closedir(termdir); if (cwd_buf != 0) free(cwd_buf); } #if USE_HASHED_DB else { DB *capdbp; char filename[PATH_MAX]; if (make_db_name(filename, eargv[i], sizeof(filename))) { if ((capdbp = _nc_db_open(filename, FALSE)) != 0) { DBT key, data; int code; code = _nc_db_first(capdbp, &key, &data); while (code == 0) { TERMTYPE lterm; int used; char *have; char *cn; if (_nc_db_have_data(&key, &data, &have, &used)) { if (_nc_read_termtype(<erm, have, used) > 0) { /* only visit things once, by primary name */ cn = _nc_first_name(lterm.term_names); /* apply the selected hook function */ (*hook) (cn, <erm); _nc_free_termtype(<erm); } } code = _nc_db_next(capdbp, &key, &data); } _nc_db_close(capdbp); } } } #endif #endif #if USE_TERMCAP #if HAVE_BSD_CGETENT char *db_array[2]; char *buffer = 0; if (verbosity) (void) printf("#\n#%s:\n#\n", eargv[i]); db_array[0] = eargv[i]; db_array[1] = 0; if (cgetfirst(&buffer, db_array)) { show_termcap(buffer, hook); free(buffer); while (cgetnext(&buffer, db_array)) { show_termcap(buffer, hook); free(buffer); } } cgetclose(); #else /* scan termcap text-file only */ if (_nc_is_file_path(eargv[i])) { char buffer[2048]; FILE *fp; if ((fp = fopen(eargv[i], "r")) != 0) { while (fgets(buffer, sizeof(buffer), fp) != 0) { if (*buffer == '#') continue; if (isspace(*buffer)) continue; show_termcap(buffer, hook); } fclose(fp); } } #endif #endif }
/* ** curses_setup(exec_name) ** ** Startup ncurses */ void curses_setup( char *exec_name) { int status; TERMTYPE term; char tty_filename[2048]; tty_init(); /* * See if the terminal is in the terminfo data base. This call has two * useful benefits, 1) it returns the filename of the terminfo entry, * and 2) it searches only terminfo's. This allows us to abort before * ncurses starts scanning the termcap file. */ if ((status = _nc_read_entry(tty_basename, tty_filename, &term)) == 0) { const TERMTYPE *fallback = _nc_fallback(tty_basename); if (fallback) { term = *fallback; sprintf(tty_filename, "(fallback)%s", tty_basename); status = 1; } else { fprintf(stderr, "Terminal not found: TERM=%s\n", tty_basename); show_usage(exec_name); ExitProgram(EXIT_FAILURE); } } if (status == -1) { fprintf(stderr, "Terminfo database is inaccessible\n"); ExitProgram(EXIT_FAILURE); } #if NO_LEAKS _nc_free_termtype(&term); #endif /** * This call will load the terminfo data base and set the cur-term * variable. Only terminals that actually exist will get here so its * OK to ignore errors. This is a good thing since ncurses does not * permit (os) or (gn) to be set. */ setupterm(tty_basename, 1, &status); /** * Get the current terminal definitions. This must be done before * getting the baudrate. */ _nc_get_curterm(&cur_term->Nttyb); if (baudrate() > 0) tty_baud_rate = (unsigned) baudrate(); else tty_baud_rate = 1; tty_cps = (tty_baud_rate << 1) / tty_frame_size; /* set up the defaults */ replace_mode = TRUE; scan_mode = 0; char_count = 0; select_delay_type = debug_level = 0; char_mask = (meta_on && meta_on[0] == '\0') ? ALLOW_PARITY : STRIP_PARITY; /* Don't change the XON/XOFF modes yet. */ select_xon_xoff = initial_stty_query(TTY_XON_XOFF) ? 1 : needs_xon_xoff; fflush(stdout); /* flush any output */ tty_set(); go_home(); /* set can_go_home */ put_clear(); /* set can_clear_screen */ if (send_reset_init) { reset_init(); } /* * I assume that the reset and init strings may not have the correct * pads. (Because that part of the test comes much later.) Because * of this, I allow the terminal some time to catch up. */ fflush(stdout); /* waste some time */ sleep(1); /* waste more time */ charset_can_test(); can_test("lines cols cr nxon rf if iprog rmp smcup rmcup", FLAG_CAN_TEST); edit_init(); /* initialize the edit data base */ if (send_reset_init && enter_ca_mode) { tc_putp(enter_ca_mode); put_clear(); /* just in case we switched pages */ } put_crlf(); ptext("Using terminfo from: "); ptextln(tty_filename); put_crlf(); if (tty_can_sync == SYNC_NEEDED) { verify_time(); } display_basic(); }