diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2000-01-02 22:06:52 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2000-01-02 22:06:52 +0000 |
commit | d058cd399506bf5b5e3d43742d30cdabda06a8e7 (patch) | |
tree | b17920dcead3b7816d7cd0f534c3aba3ac561c07 /lib/libcurses/tinfo | |
parent | 4170262b3e51f04453aa1a283175a95e4f9cf41b (diff) |
+ corrected conversion from terminfo rs2 to termcap rs (cf: 980704)
+ make conversion to termcap ug (underline glitch) more consistently applied.
+ modify read_termtype(), fixing 'toe', which could dump core when it
found an incomplete entry such as "dumb" because it did not
initialize its buffer for _nc_read_file_entry().
+ use explicit VALID_NUMERIC() checks in a few places that had been
overlooked, and add a check to ensure that init_tabs is nonzero,
to avoid divide-by-zero (reported by Todd C Miller).
Diffstat (limited to 'lib/libcurses/tinfo')
-rw-r--r-- | lib/libcurses/tinfo/lib_options.c | 288 | ||||
-rw-r--r-- | lib/libcurses/tinfo/lib_setup.c | 446 | ||||
-rw-r--r-- | lib/libcurses/tinfo/lib_termcap.c | 147 | ||||
-rw-r--r-- | lib/libcurses/tinfo/lib_ti.c | 96 | ||||
-rw-r--r-- | lib/libcurses/tinfo/read_entry.c | 346 | ||||
-rw-r--r-- | lib/libcurses/tinfo/write_entry.c | 654 |
6 files changed, 994 insertions, 983 deletions
diff --git a/lib/libcurses/tinfo/lib_options.c b/lib/libcurses/tinfo/lib_options.c index 5420fa1964f..9cef80e29fb 100644 --- a/lib/libcurses/tinfo/lib_options.c +++ b/lib/libcurses/tinfo/lib_options.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_options.c,v 1.4 1999/11/28 17:49:54 millert Exp $ */ +/* $OpenBSD: lib_options.c,v 1.5 2000/01/02 22:06:51 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998 Free Software Foundation, Inc. * + * Copyright (c) 1998-2000 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -33,7 +33,6 @@ * and: Eric S. Raymond <esr@snark.thyrsus.com> * ****************************************************************************/ - /* ** lib_options.c ** @@ -43,168 +42,163 @@ #include <curses.priv.h> -#include <term.h> /* keypad_xmit, keypad_local, meta_on, meta_off */ - /* cursor_visible,cursor_normal,cursor_invisible */ +#include <term.h> -MODULE_ID("$From: lib_options.c,v 1.36 1999/10/22 21:38:57 tom Exp $") +MODULE_ID("$From: lib_options.c,v 1.37 2000/01/01 16:59:50 tom Exp $") -int idlok(WINDOW *win, bool flag) +int +idlok(WINDOW *win, bool flag) { - T((T_CALLED("idlok(%p,%d)"), win, flag)); + T((T_CALLED("idlok(%p,%d)"), win, flag)); - if (win) { - _nc_idlok = win->_idlok = flag && (has_il() || change_scroll_region); - returnCode(OK); - } - else - returnCode(ERR); + if (win) { + _nc_idlok = win->_idlok = flag && (has_il() || change_scroll_region); + returnCode(OK); + } else + returnCode(ERR); } - -void idcok(WINDOW *win, bool flag) +void +idcok(WINDOW *win, bool flag) { - T((T_CALLED("idcok(%p,%d)"), win, flag)); + T((T_CALLED("idcok(%p,%d)"), win, flag)); - if (win) - _nc_idcok = win->_idcok = flag && has_ic(); + if (win) + _nc_idcok = win->_idcok = flag && has_ic(); - returnVoid; + returnVoid; } -int halfdelay(int t) +int +halfdelay(int t) { - T((T_CALLED("halfdelay(%d)"), t)); + T((T_CALLED("halfdelay(%d)"), t)); - if (t < 1 || t > 255) - returnCode(ERR); + if (t < 1 || t > 255) + returnCode(ERR); - cbreak(); - SP->_cbreak = t+1; - returnCode(OK); + cbreak(); + SP->_cbreak = t + 1; + returnCode(OK); } -int nodelay(WINDOW *win, bool flag) +int +nodelay(WINDOW *win, bool flag) { - T((T_CALLED("nodelay(%p,%d)"), win, flag)); + T((T_CALLED("nodelay(%p,%d)"), win, flag)); - if (win) { - if (flag == TRUE) + if (win) { + if (flag == TRUE) win->_delay = 0; - else win->_delay = -1; - returnCode(OK); - } else - returnCode(ERR); + win->_delay = -1; + returnCode(OK); + } else + returnCode(ERR); } -int notimeout(WINDOW *win, bool f) +int +notimeout(WINDOW *win, bool f) { - T((T_CALLED("notimout(%p,%d)"), win, f)); + T((T_CALLED("notimout(%p,%d)"), win, f)); - if (win) { - win->_notimeout = f; - returnCode(OK); - } - else - returnCode(ERR); + if (win) { + win->_notimeout = f; + returnCode(OK); + } else + returnCode(ERR); } -void wtimeout(WINDOW *win, int delay) +void +wtimeout(WINDOW *win, int delay) { - T((T_CALLED("wtimeout(%p,%d)"), win, delay)); + T((T_CALLED("wtimeout(%p,%d)"), win, delay)); - if (win) { - win->_delay = delay; - } + if (win) { + win->_delay = delay; + } } -int keypad(WINDOW *win, bool flag) +int +keypad(WINDOW *win, bool flag) { - T((T_CALLED("keypad(%p,%d)"), win, flag)); + T((T_CALLED("keypad(%p,%d)"), win, flag)); - if (win) { - win->_use_keypad = flag; - returnCode(_nc_keypad(flag)); - } - else - returnCode(ERR); + if (win) { + win->_use_keypad = flag; + returnCode(_nc_keypad(flag)); + } else + returnCode(ERR); } - -int meta(WINDOW *win GCC_UNUSED, bool flag) +int +meta(WINDOW *win GCC_UNUSED, bool flag) { - /* Ok, we stay relaxed and don't signal an error if win is NULL */ - T((T_CALLED("meta(%p,%d)"), win, flag)); - - SP->_use_meta = flag; - - if (flag && meta_on) - { - TPUTS_TRACE("meta_on"); - putp(meta_on); - } - else if (! flag && meta_off) - { - TPUTS_TRACE("meta_off"); - putp(meta_off); - } - returnCode(OK); + /* Ok, we stay relaxed and don't signal an error if win is NULL */ + T((T_CALLED("meta(%p,%d)"), win, flag)); + + SP->_use_meta = flag; + + if (flag && meta_on) { + TPUTS_TRACE("meta_on"); + putp(meta_on); + } else if (!flag && meta_off) { + TPUTS_TRACE("meta_off"); + putp(meta_off); + } + returnCode(OK); } /* curs_set() moved here to narrow the kernel interface */ -int curs_set(int vis) +int +curs_set(int vis) { -int cursor = SP->_cursor; - - T((T_CALLED("curs_set(%d)"), vis)); - - if (vis < 0 || vis > 2) - returnCode(ERR); - - if (vis == cursor) - returnCode(cursor); - - switch(vis) { - case 2: - if (cursor_visible) - { - TPUTS_TRACE("cursor_visible"); - putp(cursor_visible); - } - else - returnCode(ERR); - break; - case 1: - if (cursor_normal) - { - TPUTS_TRACE("cursor_normal"); - putp(cursor_normal); - } - else - returnCode(ERR); - break; - case 0: - if (cursor_invisible) - { - TPUTS_TRACE("cursor_invisible"); - putp(cursor_invisible); - } - else - returnCode(ERR); - break; - } - SP->_cursor = vis; - _nc_flush(); - - returnCode(cursor==-1 ? 1 : cursor); + int cursor = SP->_cursor; + + T((T_CALLED("curs_set(%d)"), vis)); + + if (vis < 0 || vis > 2) + returnCode(ERR); + + if (vis == cursor) + returnCode(cursor); + + switch (vis) { + case 2: + if (cursor_visible) { + TPUTS_TRACE("cursor_visible"); + putp(cursor_visible); + } else + returnCode(ERR); + break; + case 1: + if (cursor_normal) { + TPUTS_TRACE("cursor_normal"); + putp(cursor_normal); + } else + returnCode(ERR); + break; + case 0: + if (cursor_invisible) { + TPUTS_TRACE("cursor_invisible"); + putp(cursor_invisible); + } else + returnCode(ERR); + break; + } + SP->_cursor = vis; + _nc_flush(); + + returnCode(cursor == -1 ? 1 : cursor); } -int typeahead(int fd) +int +typeahead(int fd) { - T((T_CALLED("typeahead(%d)"), fd)); - SP->_checkfd = fd; - returnCode(OK); + T((T_CALLED("typeahead(%d)"), fd)); + SP->_checkfd = fd; + returnCode(OK); } /* @@ -215,18 +209,20 @@ int typeahead(int fd) */ #ifdef NCURSES_EXT_FUNCS -static int has_key_internal(int keycode, struct tries *tp) +static int +has_key_internal(int keycode, struct tries *tp) { if (tp == 0) - return(FALSE); + return (FALSE); else if (tp->value == keycode) - return(TRUE); + return (TRUE); else - return(has_key_internal(keycode, tp->child) - || has_key_internal(keycode, tp->sibling)); + return (has_key_internal(keycode, tp->child) + || has_key_internal(keycode, tp->sibling)); } -int has_key(int keycode) +int +has_key(int keycode) { T((T_CALLED("has_key(%d)"), keycode)); returnCode(has_key_internal(keycode, SP->_keytry)); @@ -240,24 +236,22 @@ int has_key(int keycode) * flush, then the next wgetch may get the escape sequence that corresponds to * the terminal state _before_ switching modes. */ -int _nc_keypad(bool flag) +int +_nc_keypad(bool flag) { - if (flag && keypad_xmit) - { - TPUTS_TRACE("keypad_xmit"); - putp(keypad_xmit); - _nc_flush(); - } - else if (! flag && keypad_local) - { - TPUTS_TRACE("keypad_local"); - putp(keypad_local); - _nc_flush(); - } - - if (flag && !SP->_tried) { - _nc_init_keytry(); - SP->_tried = TRUE; - } - return(OK); + if (flag && keypad_xmit) { + TPUTS_TRACE("keypad_xmit"); + putp(keypad_xmit); + _nc_flush(); + } else if (!flag && keypad_local) { + TPUTS_TRACE("keypad_local"); + putp(keypad_local); + _nc_flush(); + } + + if (flag && !SP->_tried) { + _nc_init_keytry(); + SP->_tried = TRUE; + } + return (OK); } diff --git a/lib/libcurses/tinfo/lib_setup.c b/lib/libcurses/tinfo/lib_setup.c index 36fd188c42d..2f722cee697 100644 --- a/lib/libcurses/tinfo/lib_setup.c +++ b/lib/libcurses/tinfo/lib_setup.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_setup.c,v 1.7 1999/11/28 17:49:54 millert Exp $ */ +/* $OpenBSD: lib_setup.c,v 1.8 2000/01/02 22:06:51 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999 Free Software Foundation, Inc. * + * Copyright (c) 1998-2000 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -33,7 +33,6 @@ * and: Eric S. Raymond <esr@snark.thyrsus.com> * ****************************************************************************/ - /* * Terminal setup routines common to termcap and terminfo: * @@ -42,16 +41,16 @@ */ #include <curses.priv.h> -#include <tic.h> /* for MAX_NAME_SIZE */ +#include <tic.h> /* for MAX_NAME_SIZE */ #include <term_entry.h> #if defined(SVR4_TERMIO) && !defined(_POSIX_SOURCE) #define _POSIX_SOURCE #endif -#include <term.h> /* lines, columns, cur_term */ +#include <term.h> /* lines, columns, cur_term */ -MODULE_ID("$From: lib_setup.c,v 1.56 1999/10/30 23:00:16 tom Exp $") +MODULE_ID("$From: lib_setup.c,v 1.58 2000/01/01 16:46:57 tom Exp $") /**************************************************************************** * @@ -97,120 +96,116 @@ static int _use_env = TRUE; static void do_prototype(void); -void use_env(bool f) +void +use_env(bool f) { - _use_env = f; + _use_env = f; } int LINES = 0, COLS = 0, TABSIZE = 0; -static void _nc_get_screensize(int *linep, int *colp) +static void +_nc_get_screensize(int *linep, int *colp) /* Obtain lines/columns values from the environment and/or terminfo entry */ { - /* figure out the size of the screen */ - T(("screen size: terminfo lines = %d columns = %d", lines, columns)); + /* figure out the size of the screen */ + T(("screen size: terminfo lines = %d columns = %d", lines, columns)); - if (!_use_env) - { - *linep = (int)lines; - *colp = (int)columns; - } - else /* usually want to query LINES and COLUMNS from environment */ - { - int value; + if (!_use_env) { + *linep = (int) lines; + *colp = (int) columns; + } else { /* usually want to query LINES and COLUMNS from environment */ + int value; - *linep = *colp = 0; + *linep = *colp = 0; - /* first, look for environment variables */ - if ((value = _nc_getenv_num("LINES")) > 0) { - *linep = value; - } - if ((value = _nc_getenv_num("COLUMNS")) > 0) { - *colp = value; - } - T(("screen size: environment LINES = %d COLUMNS = %d",*linep,*colp)); + /* first, look for environment variables */ + if ((value = _nc_getenv_num("LINES")) > 0) { + *linep = value; + } + if ((value = _nc_getenv_num("COLUMNS")) > 0) { + *colp = value; + } + T(("screen size: environment LINES = %d COLUMNS = %d", *linep, *colp)); #ifdef __EMX__ - if (*linep <= 0 || *colp <= 0) - { - int screendata[2]; - _scrsize(screendata); - *colp = screendata[0]; - *linep = screendata[1]; - T(("EMX screen size: environment LINES = %d COLUMNS = %d",*linep,*colp)); - } + if (*linep <= 0 || *colp <= 0) { + int screendata[2]; + _scrsize(screendata); + *colp = screendata[0]; + *linep = screendata[1]; + T(("EMX screen size: environment LINES = %d COLUMNS = %d", + *linep, *colp)); + } #endif #if HAVE_SIZECHANGE - /* if that didn't work, maybe we can try asking the OS */ - if (*linep <= 0 || *colp <= 0) - { - if (isatty(cur_term->Filedes)) - { - STRUCT_WINSIZE size; - - errno = 0; - do { - if (ioctl(cur_term->Filedes, IOCTL_WINSIZE, &size) < 0 - && errno != EINTR) - goto failure; - } while - (errno == EINTR); - - /* - * Solaris lets users override either dimension with an - * environment variable. - */ - if (*linep <= 0) - *linep = WINSIZE_ROWS(size); - if (*colp <= 0) - *colp = WINSIZE_COLS(size); - } - /* FALLTHRU */ - failure:; + /* if that didn't work, maybe we can try asking the OS */ + if (*linep <= 0 || *colp <= 0) { + if (isatty(cur_term->Filedes)) { + STRUCT_WINSIZE size; + + errno = 0; + do { + if (ioctl(cur_term->Filedes, IOCTL_WINSIZE, &size) < 0 + && errno != EINTR) + goto failure; + } while + (errno == EINTR); + + /* + * Solaris lets users override either dimension with an + * environment variable. + */ + if (*linep <= 0) + *linep = WINSIZE_ROWS(size); + if (*colp <= 0) + *colp = WINSIZE_COLS(size); } + /* FALLTHRU */ + failure:; + } #endif /* HAVE_SIZECHANGE */ - /* if we can't get dynamic info about the size, use static */ - if (*linep <= 0 || *colp <= 0) - if (lines > 0 && columns > 0) - { - *linep = (int)lines; - *colp = (int)columns; - } - - /* the ultimate fallback, assume fixed 24x80 size */ - if (*linep <= 0 || *colp <= 0) - { - *linep = 24; - *colp = 80; + /* if we can't get dynamic info about the size, use static */ + if (*linep <= 0 || *colp <= 0) + if (lines > 0 && columns > 0) { + *linep = (int) lines; + *colp = (int) columns; } - /* - * Put the derived values back in the screen-size caps, so - * tigetnum() and tgetnum() will do the right thing. - */ - lines = (short)(*linep); - columns = (short)(*colp); + /* the ultimate fallback, assume fixed 24x80 size */ + if (*linep <= 0 || *colp <= 0) { + *linep = 24; + *colp = 80; } - T(("screen size is %dx%d", *linep, *colp)); + /* + * Put the derived values back in the screen-size caps, so + * tigetnum() and tgetnum() will do the right thing. + */ + lines = (short) (*linep); + columns = (short) (*colp); + } + + T(("screen size is %dx%d", *linep, *colp)); - if (init_tabs != -1) - TABSIZE = (int)init_tabs; - else - TABSIZE = 8; - T(("TABSIZE = %d", TABSIZE)); + if (VALID_NUMERIC(init_tabs)) + TABSIZE = (int) init_tabs; + else + TABSIZE = 8; + T(("TABSIZE = %d", TABSIZE)); } #if USE_SIZECHANGE -void _nc_update_screensize(void) +void +_nc_update_screensize(void) { - int my_lines, my_cols; + int my_lines, my_cols; - _nc_get_screensize(&my_lines, &my_cols); - if (SP != 0 && SP->_resize != 0) - SP->_resize(my_lines, my_cols); + _nc_get_screensize(&my_lines, &my_cols); + if (SP != 0 && SP->_resize != 0) + SP->_resize(my_lines, my_cols); } #endif @@ -237,48 +232,49 @@ void _nc_update_screensize(void) } #if USE_DATABASE -static int grab_entry(const char *const tn, TERMTYPE *const tp) +static int +grab_entry(const char *const tn, TERMTYPE * const tp) /* return 1 if entry found, 0 if not found, -1 if database not accessible */ { - char filename[PATH_MAX]; - int status; + char filename[PATH_MAX]; + int status; - /* - * $TERM shouldn't contain pathname delimiters. - */ - if (strchr(tn, '/')) - return 0; + /* + * $TERM shouldn't contain pathname delimiters. + */ + if (strchr(tn, '/')) + return 0; - if ((status = _nc_read_entry(tn, filename, tp)) != 1) { + if ((status = _nc_read_entry(tn, filename, tp)) != 1) { #ifndef PURE_TERMINFO - /* - * Try falling back on the termcap file. - * Note: allowing this call links the entire terminfo/termcap - * compiler into the startup code. It's preferable to build a - * real terminfo database and use that. - */ - status = _nc_read_termcap_entry(tn, tp); -#endif /* PURE_TERMINFO */ - - } - /* - * If we have an entry, force all of the cancelled strings to null - * pointers so we don't have to test them in the rest of the library. - * (The terminfo compiler bypasses this logic, since it must know if - * a string is cancelled, for merging entries). + * Try falling back on the termcap file. + * Note: allowing this call links the entire terminfo/termcap + * compiler into the startup code. It's preferable to build a + * real terminfo database and use that. */ - if (status == 1) { - int n; - for_each_boolean(n,tp) - if (!VALID_BOOLEAN(tp->Booleans[n])) - tp->Booleans[n] = FALSE; - for_each_string(n,tp) - if (tp->Strings[n] == CANCELLED_STRING) - tp->Strings[n] = ABSENT_STRING; - } - return(status); + status = _nc_read_termcap_entry(tn, tp); +#endif /* PURE_TERMINFO */ + + } + + /* + * If we have an entry, force all of the cancelled strings to null + * pointers so we don't have to test them in the rest of the library. + * (The terminfo compiler bypasses this logic, since it must know if + * a string is cancelled, for merging entries). + */ + if (status == 1) { + int n; + for_each_boolean(n, tp) + if (!VALID_BOOLEAN(tp->Booleans[n])) + tp->Booleans[n] = FALSE; + for_each_string(n, tp) + if (tp->Strings[n] == CANCELLED_STRING) + tp->Strings[n] = ABSENT_STRING; + } + return (status); } #endif @@ -292,106 +288,102 @@ char ttytype[NAMESIZE] = ""; * */ -int setupterm(NCURSES_CONST char *tname, int Filedes, int *errret) +int +setupterm(NCURSES_CONST char *tname, int Filedes, int *errret) { -struct term *term_ptr; -int status; + struct term *term_ptr; + int status; - T((T_CALLED("setupterm(%s,%d,%p)"), _nc_visbuf(tname), Filedes, errret)); + T((T_CALLED("setupterm(%s,%d,%p)"), _nc_visbuf(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); + 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)); + T(("your terminal name is %s", tname)); - term_ptr = typeCalloc(TERMINAL, 1); + term_ptr = typeCalloc(TERMINAL, 1); - if (term_ptr == 0) { - ret_error0(-1, "Not enough memory to create terminal structure.\n") ; - } + 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); + status = grab_entry(tname, &term_ptr->type); #else - status = 0; + status = 0; #endif - /* try fallback list if entry on disk */ - if (status != 1) - { - const TERMTYPE *fallback = _nc_fallback(tname); - - if (fallback) - { - term_ptr->type = *fallback; - 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); - } - - /* - * Improve on SVr4 curses. If an application mixes curses and termcap - * calls, it may call both initscr and tgetent. This is not really a - * good thing to do, but can happen if someone tries using ncurses with - * the readline library. The problem we are fixing is that when - * tgetent calls setupterm, the resulting Ottyb struct in cur_term is - * zeroed. A subsequent call to endwin uses the zeroed terminal - * settings rather than the ones saved in initscr. So we check if - * cur_term appears to contain terminal settings for the same output - * file as our current call - and copy those terminal settings. (SVr4 - * curses does not do this, however applications that are working - * around the problem will still work properly with this feature). - */ - if (cur_term != 0) { - if (cur_term->Filedes == Filedes) - term_ptr->Ottyb = cur_term->Ottyb; - } - - 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; + /* try fallback list if entry on disk */ + if (status != 1) { + const TERMTYPE *fallback = _nc_fallback(tname); - 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); + if (fallback) { + term_ptr->type = *fallback; + status = 1; } - returnCode(OK); + } + + if (status == -1) { + ret_error0(-1, "terminals database is inaccessible\n"); + } else if (status == 0) { + ret_error(0, "'%s': unknown terminal type.\n", tname); + } + + /* + * Improve on SVr4 curses. If an application mixes curses and termcap + * calls, it may call both initscr and tgetent. This is not really a + * good thing to do, but can happen if someone tries using ncurses with + * the readline library. The problem we are fixing is that when + * tgetent calls setupterm, the resulting Ottyb struct in cur_term is + * zeroed. A subsequent call to endwin uses the zeroed terminal + * settings rather than the ones saved in initscr. So we check if + * cur_term appears to contain terminal settings for the same output + * file as our current call - and copy those terminal settings. (SVr4 + * curses does not do this, however applications that are working + * around the problem will still work properly with this feature). + */ + if (cur_term != 0) { + if (cur_term->Filedes == Filedes) + term_ptr->Ottyb = cur_term->Ottyb; + } + + 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); } /* @@ -405,19 +397,19 @@ int status; static void do_prototype(void) { -int i; -char CC; -char proto; -char *tmp; - - tmp = getenv("CC"); - CC = *tmp; - proto = *command_character; - - for_each_string(i, &(cur_term->type)) { - for (tmp = cur_term->type.Strings[i]; *tmp; tmp++) { - if (*tmp == proto) - *tmp = CC; - } + int i; + char CC; + char proto; + char *tmp; + + tmp = getenv("CC"); + CC = *tmp; + proto = *command_character; + + for_each_string(i, &(cur_term->type)) { + for (tmp = cur_term->type.Strings[i]; *tmp; tmp++) { + if (*tmp == proto) + *tmp = CC; } + } } diff --git a/lib/libcurses/tinfo/lib_termcap.c b/lib/libcurses/tinfo/lib_termcap.c index 2ead2fded90..d99749636e0 100644 --- a/lib/libcurses/tinfo/lib_termcap.c +++ b/lib/libcurses/tinfo/lib_termcap.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_termcap.c,v 1.3 1999/11/28 17:49:54 millert Exp $ */ +/* $OpenBSD: lib_termcap.c,v 1.4 2000/01/02 22:06:51 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999 Free Software Foundation, Inc. * + * Copyright (c) 1998-2000 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -41,7 +41,7 @@ #define __INTERNAL_CAPS_VISIBLE #include <term_entry.h> -MODULE_ID("$From: lib_termcap.c,v 1.30 1999/10/30 23:00:16 tom Exp $") +MODULE_ID("$From: lib_termcap.c,v 1.32 2000/01/01 16:49:54 tom Exp $") /* some of the code in here was contributed by: @@ -66,29 +66,30 @@ char *BC = 0; * ***************************************************************************/ -int tgetent(char *bufp GCC_UNUSED, const char *name) +int +tgetent(char *bufp GCC_UNUSED, const char *name) { -int errcode; + int errcode; - T((T_CALLED("tgetent()"))); + T((T_CALLED("tgetent()"))); - setupterm((NCURSES_CONST char *)name, STDOUT_FILENO, &errcode); + setupterm((NCURSES_CONST char *) name, STDOUT_FILENO, &errcode); - if (errcode == 1) { + if (errcode == 1) { - if (cursor_left) - if ((backspaces_with_bs = !strcmp(cursor_left, "\b")) == 0) - backspace_if_not_bs = cursor_left; + if (cursor_left) + if ((backspaces_with_bs = !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; + /* 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; - (void) baudrate(); /* sets ospeed as a side-effect */ + (void) baudrate(); /* sets ospeed as a side-effect */ /* LINT_PREPRO #if 0*/ @@ -96,8 +97,8 @@ int errcode; /* LINT_PREPRO #endif*/ - } - returnCode(errcode); + } + returnCode(errcode); } /*************************************************************************** @@ -109,22 +110,23 @@ int errcode; * ***************************************************************************/ -int tgetflag(NCURSES_CONST char *id) +int +tgetflag(NCURSES_CONST char *id) { -int i; - - T((T_CALLED("tgetflag(%s)"), id)); - if (cur_term != 0) { - TERMTYPE *tp = &(cur_term->type); - for_each_boolean(i, tp) { - const char *capname = ExtBoolname(tp, i, boolcodes); - if (!strncmp(id, capname, 2)) { - /* setupterm forces invalid booleans to false */ - returnCode(tp->Booleans[i]); - } + int i; + + T((T_CALLED("tgetflag(%s)"), id)); + if (cur_term != 0) { + TERMTYPE *tp = &(cur_term->type); + for_each_boolean(i, tp) { + const char *capname = ExtBoolname(tp, i, boolcodes); + if (!strncmp(id, capname, 2)) { + /* setupterm forces invalid booleans to false */ + returnCode(tp->Booleans[i]); } } - returnCode(0); /* Solaris does this */ + } + returnCode(0); /* Solaris does this */ } /*************************************************************************** @@ -136,23 +138,24 @@ int i; * ***************************************************************************/ -int tgetnum(NCURSES_CONST char *id) +int +tgetnum(NCURSES_CONST char *id) { -int i; - - T((T_CALLED("tgetnum(%s)"), id)); - if (cur_term != 0) { - TERMTYPE *tp = &(cur_term->type); - for_each_number(i, tp) { - const char *capname = ExtNumname(tp, i, numcodes); - if (!strncmp(id, capname, 2)) { - if (!VALID_NUMERIC(tp->Numbers[i])) - return -1; - returnCode(tp->Numbers[i]); - } + int i; + + T((T_CALLED("tgetnum(%s)"), id)); + if (cur_term != 0) { + TERMTYPE *tp = &(cur_term->type); + for_each_number(i, tp) { + const char *capname = ExtNumname(tp, i, numcodes); + if (!strncmp(id, capname, 2)) { + if (!VALID_NUMERIC(tp->Numbers[i])) + return ABSENT_NUMERIC; + returnCode(tp->Numbers[i]); } } - returnCode(ERR); + } + returnCode(ABSENT_NUMERIC); } /*************************************************************************** @@ -164,30 +167,31 @@ int i; * ***************************************************************************/ -char *tgetstr(NCURSES_CONST char *id, char **area) +char * +tgetstr(NCURSES_CONST char *id, char **area) { -int i; - - T((T_CALLED("tgetstr(%s,%p)"), id, area)); - if (cur_term != 0) { - TERMTYPE *tp = &(cur_term->type); - for_each_string(i, tp) { - const char *capname = ExtStrname(tp, i, strcodes); - T(("trying %s", capname)); - if (!strncmp(id, capname, 2)) { - T(("found match : %s", _nc_visbuf(tp->Strings[i]))); - /* setupterm forces cancelled strings to null */ - if (area != 0 - && *area != 0 - && VALID_STRING(tp->Strings[i])) { - (void) strcpy(*area, tp->Strings[i]); - *area += strlen(*area) + 1; - } - returnPtr(tp->Strings[i]); + int i; + + T((T_CALLED("tgetstr(%s,%p)"), id, area)); + if (cur_term != 0) { + TERMTYPE *tp = &(cur_term->type); + for_each_string(i, tp) { + const char *capname = ExtStrname(tp, i, strcodes); + T(("trying %s", capname)); + if (!strncmp(id, capname, 2)) { + T(("found match : %s", _nc_visbuf(tp->Strings[i]))); + /* setupterm forces cancelled strings to null */ + if (area != 0 + && *area != 0 + && VALID_STRING(tp->Strings[i])) { + (void) strcpy(*area, tp->Strings[i]); + *area += strlen(*area) + 1; } + returnPtr(tp->Strings[i]); } } - returnPtr(NULL); + } + returnPtr(NULL); } /* @@ -199,8 +203,9 @@ int i; * */ -char *tgoto(const char *string, int x, int y) +char * +tgoto(const char *string, int x, int y) { - T((T_CALLED("tgoto(%s,%d,%d)"), string, x, y)); - returnPtr(tparm((NCURSES_CONST char *)string, y, x)); + T((T_CALLED("tgoto(%s,%d,%d)"), string, x, y)); + returnPtr(tparm((NCURSES_CONST char *) string, y, x)); } diff --git a/lib/libcurses/tinfo/lib_ti.c b/lib/libcurses/tinfo/lib_ti.c index bfa484cfd95..91164f528fb 100644 --- a/lib/libcurses/tinfo/lib_ti.c +++ b/lib/libcurses/tinfo/lib_ti.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_ti.c,v 1.2 1999/03/02 06:23:29 millert Exp $ */ +/* $OpenBSD: lib_ti.c,v 1.3 2000/01/02 22:06:51 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998 Free Software Foundation, Inc. * + * Copyright (c) 1998-2000 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -33,71 +33,73 @@ * and: Eric S. Raymond <esr@snark.thyrsus.com> * ****************************************************************************/ - #include <curses.priv.h> #include <term_entry.h> #include <tic.h> -MODULE_ID("$From: lib_ti.c,v 1.16 1999/02/28 23:11:28 tom Exp $") +MODULE_ID("$From: lib_ti.c,v 1.18 2000/01/01 16:58:30 tom Exp $") -int tigetflag(NCURSES_CONST char *str) +int +tigetflag(NCURSES_CONST char *str) { -int i; - - T((T_CALLED("tigetflag(%s)"), str)); - - if (cur_term != 0) { - TERMTYPE *tp = &(cur_term->type); - for_each_boolean(i,tp) { - const char *capname = ExtBoolname(tp, i, boolnames); - if (!strcmp(str, capname)) { - /* setupterm forces invalid booleans to false */ - returnCode(tp->Booleans[i]); - } + int i; + + T((T_CALLED("tigetflag(%s)"), str)); + + if (cur_term != 0) { + TERMTYPE *tp = &(cur_term->type); + for_each_boolean(i, tp) { + const char *capname = ExtBoolname(tp, i, boolnames); + if (!strcmp(str, capname)) { + /* setupterm forces invalid booleans to false */ + returnCode(tp->Booleans[i]); } } + } - returnCode(ABSENT_BOOLEAN); + returnCode(ABSENT_BOOLEAN); } -int tigetnum(NCURSES_CONST char *str) +int +tigetnum(NCURSES_CONST char *str) { -int i; - - T((T_CALLED("tigetnum(%s)"), str)); - - if (cur_term != 0) { - TERMTYPE *tp = &(cur_term->type); - for_each_number(i, tp) { - const char *capname = ExtNumname(tp, i, numnames); - if (!strcmp(str, capname)) { - if (!VALID_NUMERIC(tp->Numbers[i])) - return -1; - returnCode(tp->Numbers[i]); - } + int i; + + T((T_CALLED("tigetnum(%s)"), str)); + + if (cur_term != 0) { + TERMTYPE *tp = &(cur_term->type); + for_each_number(i, tp) { + const char *capname = ExtNumname(tp, i, numnames); + if (!strcmp(str, capname)) { + if (!VALID_NUMERIC(tp->Numbers[i])) + return ABSENT_NUMERIC; + returnCode(tp->Numbers[i]); } } + } - returnCode(CANCELLED_NUMERIC); /* Solaris returns a -1 instead */ + returnCode(CANCELLED_NUMERIC); /* Solaris returns a -1 instead */ } -char *tigetstr(NCURSES_CONST char *str) +char * +tigetstr(NCURSES_CONST char *str) { -int i; - - T((T_CALLED("tigetstr(%s)"), str)); - - if (cur_term != 0) { - TERMTYPE *tp = &(cur_term->type); - for_each_string(i, tp) { - const char *capname = ExtStrname(tp, i, strnames); - if (!strcmp(str, capname)) { - /* setupterm forces cancelled strings to null */ - returnPtr(tp->Strings[i]); - } + int i; + + T((T_CALLED("tigetstr(%s)"), str)); + + if (cur_term != 0) { + TERMTYPE *tp = &(cur_term->type); + for_each_string(i, tp) { + const char *capname = ExtStrname(tp, i, strnames); + if (!strcmp(str, capname)) { + /* setupterm forces cancelled strings to null */ + returnPtr(tp->Strings[i]); } } + } - returnPtr(CANCELLED_STRING); + returnPtr(CANCELLED_STRING); } diff --git a/lib/libcurses/tinfo/read_entry.c b/lib/libcurses/tinfo/read_entry.c index 7737580f544..59e791ebcca 100644 --- a/lib/libcurses/tinfo/read_entry.c +++ b/lib/libcurses/tinfo/read_entry.c @@ -1,7 +1,7 @@ -/* $OpenBSD: read_entry.c,v 1.5 1999/08/15 11:40:56 millert Exp $ */ +/* $OpenBSD: read_entry.c,v 1.6 2000/01/02 22:06:51 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1999 Free Software Foundation, Inc. * + * Copyright (c) 1998-2000 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -33,8 +33,6 @@ * and: Eric S. Raymond <esr@snark.thyrsus.com> * ****************************************************************************/ - - /* * read_entry.c -- Routine for reading in a compiled terminfo file * @@ -49,7 +47,7 @@ #include <tic.h> #include <term_entry.h> -MODULE_ID("$From: read_entry.c,v 1.61 1999/07/24 20:07:20 tom Exp $") +MODULE_ID("$From: read_entry.c,v 1.63 2000/01/01 23:06:40 tom Exp $") #ifndef O_BINARY #define O_BINARY 0 @@ -58,7 +56,7 @@ MODULE_ID("$From: read_entry.c,v 1.61 1999/07/24 20:07:20 tom Exp $") #if 0 #define TRACE_IN(p) DEBUG(2, p) #else -#define TRACE_IN(p) /*nothing*/ +#define TRACE_IN(p) /*nothing */ #endif /* @@ -84,7 +82,8 @@ static bool keep_tic_directory = FALSE; * Record the "official" location of the terminfo directory, according to * the place where we're writing to, or the normal default, if not. */ -const char *_nc_tic_dir(const char *path) +const char * +_nc_tic_dir(const char *path) { static const char *result = TERMINFO; @@ -106,41 +105,43 @@ const char *_nc_tic_dir(const char *path) * has chdir'd to it. If we let it be changed, then if $TERMINFO has a * relative path, we'll lose track of the actual directory. */ -void _nc_keep_tic_dir(const char *path) +void +_nc_keep_tic_dir(const char *path) { _nc_tic_dir(path); keep_tic_directory = TRUE; } -static void convert_shorts(char *buf, short *Numbers, int count) +static void +convert_shorts(char *buf, short *Numbers, int count) { int i; - for (i = 0; i < count; i++) - { - if (IS_NEG1(buf + 2*i)) + for (i = 0; i < count; i++) { + if (IS_NEG1(buf + 2 * i)) Numbers[i] = ABSENT_NUMERIC; - else if (IS_NEG2(buf + 2*i)) + else if (IS_NEG2(buf + 2 * i)) Numbers[i] = CANCELLED_NUMERIC; else - Numbers[i] = LOW_MSB(buf + 2*i); + Numbers[i] = LOW_MSB(buf + 2 * i); TRACE_IN(("get Numbers[%d]=%d", i, Numbers[i])); } } -static void convert_strings(char *buf, char **Strings, int count, int size, char *table) +static void +convert_strings(char *buf, char **Strings, int count, int size, char *table) { int i; char *p; for (i = 0; i < count; i++) { - if (IS_NEG1(buf + 2*i)) { + if (IS_NEG1(buf + 2 * i)) { Strings[i] = ABSENT_STRING; - } else if (IS_NEG2(buf + 2*i)) { + } else if (IS_NEG2(buf + 2 * i)) { Strings[i] = CANCELLED_STRING; - } else if (LOW_MSB(buf + 2*i) > size) { + } else if (LOW_MSB(buf + 2 * i) > size) { Strings[i] = ABSENT_STRING; } else { - Strings[i] = (LOW_MSB(buf+2*i) + table); + Strings[i] = (LOW_MSB(buf + 2 * i) + table); TRACE_IN(("Strings[%d] = %s", i, _nc_visbuf(Strings[i]))); } @@ -161,53 +162,57 @@ static void convert_strings(char *buf, char **Strings, int count, int size, char #define even_boundary(value) \ if ((value) % 2 != 0) read(fd, buf, 1) -static int read_termtype(int fd, TERMTYPE *ptr) +static int +read_termtype(int fd, TERMTYPE * ptr) /* return 1 if read, 0 if not found or garbled */ { - int name_size, bool_count, num_count, str_count, str_size; - int i; - char buf[MAX_ENTRY_SIZE]; + int name_size, bool_count, num_count, str_count, str_size; + int i; + char buf[MAX_ENTRY_SIZE]; TRACE_IN(("READ termtype header @%d", tell(fd))); + memset(ptr, 0, sizeof(*ptr)); + /* grab the header */ if (!read_shorts(fd, buf, 6) - || LOW_MSB(buf) != MAGIC) { - return(0); + || LOW_MSB(buf) != MAGIC) { + return (0); } _nc_free_termtype(ptr); - name_size = LOW_MSB(buf + 2); + name_size = LOW_MSB(buf + 2); bool_count = LOW_MSB(buf + 4); - num_count = LOW_MSB(buf + 6); - str_count = LOW_MSB(buf + 8); - str_size = LOW_MSB(buf + 10); - - TRACE_IN(("header is %d/%d/%d/%d(%d)", name_size, bool_count, num_count, str_count, str_size)); - if (name_size < 0 - || bool_count < 0 - || num_count < 0 - || str_count < 0 - || str_size < 0) { - return(0); + num_count = LOW_MSB(buf + 6); + str_count = LOW_MSB(buf + 8); + str_size = LOW_MSB(buf + 10); + + TRACE_IN(("header is %d/%d/%d/%d(%d)", name_size, bool_count, num_count, + str_count, str_size)); + if (name_size < 0 + || bool_count < 0 + || num_count < 0 + || str_count < 0 + || str_size < 0) { + return (0); } if (str_size) { /* try to allocate space for the string table */ - if (str_count*2 >= (int) sizeof(buf) - || (ptr->str_table = typeMalloc(char, (unsigned)str_size)) == 0) { - return(0); + if (str_count * 2 >= (int) sizeof(buf) + || (ptr->str_table = typeMalloc(char, (unsigned) str_size)) == 0) { + return (0); } } else { str_count = 0; } /* grab the name (a null-terminate string) */ - read(fd, buf, min(MAX_NAME_SIZE, (unsigned)name_size)); + read(fd, buf, min(MAX_NAME_SIZE, (unsigned) name_size)); buf[MAX_NAME_SIZE] = '\0'; ptr->term_names = typeCalloc(char, strlen(buf) + 1); if (ptr->term_names == NULL) { - return(0); + return (0); } (void) strcpy(ptr->term_names, buf); if (name_size > MAX_NAME_SIZE) @@ -215,8 +220,8 @@ static int read_termtype(int fd, TERMTYPE *ptr) /* grab the booleans */ if ((ptr->Booleans = typeCalloc(char, max(BOOLCOUNT, bool_count))) == 0 - || read(fd, ptr->Booleans, (unsigned)bool_count) < bool_count) { - return(0); + || read(fd, ptr->Booleans, (unsigned) bool_count) < bool_count) { + return (0); } /* @@ -229,31 +234,29 @@ static int read_termtype(int fd, TERMTYPE *ptr) /* grab the numbers */ if ((ptr->Numbers = typeCalloc(short, max(NUMCOUNT, num_count))) == 0 - || !read_shorts(fd, buf, num_count)) { - return(0); + || !read_shorts(fd, buf, num_count)) { + return (0); } convert_shorts(buf, ptr->Numbers, num_count); if ((ptr->Strings = typeCalloc(char *, max(STRCOUNT, str_count))) == 0) - return(0); + return (0); - if (str_count) - { + if (str_count) { /* grab the string offsets */ if (!read_shorts(fd, buf, str_count)) { - return(0); + return (0); } /* finally, grab the string table itself */ - if (read(fd, ptr->str_table, (unsigned)str_size) != str_size) - return(0); + if (read(fd, ptr->str_table, (unsigned) str_size) != str_size) + return (0); convert_strings(buf, ptr->Strings, str_count, str_size, ptr->str_table); } - #if NCURSES_XNAMES ptr->num_Booleans = BOOLCOUNT; - ptr->num_Numbers = NUMCOUNT; - ptr->num_Strings = STRCOUNT; + ptr->num_Numbers = NUMCOUNT; + ptr->num_Strings = STRCOUNT; /* * Read extended entries, if any, after the normal end of terminfo data. @@ -262,94 +265,103 @@ static int read_termtype(int fd, TERMTYPE *ptr) TRACE_IN(("READ extended_header @%d", tell(fd))); if (_nc_user_definable && read_shorts(fd, buf, 5)) { int ext_bool_count = LOW_MSB(buf + 0); - int ext_num_count = LOW_MSB(buf + 2); - int ext_str_count = LOW_MSB(buf + 4); - int ext_str_size = LOW_MSB(buf + 6); - int ext_str_limit = LOW_MSB(buf + 8); + int ext_num_count = LOW_MSB(buf + 2); + int ext_str_count = LOW_MSB(buf + 4); + int ext_str_size = LOW_MSB(buf + 6); + int ext_str_limit = LOW_MSB(buf + 8); int need = (ext_bool_count + ext_num_count + ext_str_count); int base = 0; if (need >= (int) sizeof(buf) - || ext_str_size >= (int) sizeof(buf) - || ext_str_limit >= (int) sizeof(buf) - || ext_bool_count < 0 - || ext_num_count < 0 - || ext_str_count < 0 - || ext_str_size < 0 - || ext_str_limit < 0) - return(0); + || ext_str_size >= (int) sizeof(buf) + || ext_str_limit >= (int) sizeof(buf) + || ext_bool_count < 0 + || ext_num_count < 0 + || ext_str_count < 0 + || ext_str_size < 0 + || ext_str_limit < 0) + return (0); ptr->num_Booleans = BOOLCOUNT + ext_bool_count; - ptr->num_Numbers = NUMCOUNT + ext_num_count; - ptr->num_Strings = STRCOUNT + ext_str_count; + ptr->num_Numbers = NUMCOUNT + ext_num_count; + ptr->num_Strings = STRCOUNT + ext_str_count; - ptr->Booleans = typeRealloc(char, ptr->num_Booleans,ptr->Booleans); + ptr->Booleans = typeRealloc(char, ptr->num_Booleans, ptr->Booleans); ptr->Numbers = typeRealloc(short, ptr->num_Numbers, ptr->Numbers); - ptr->Strings = typeRealloc(char*, ptr->num_Strings, ptr->Strings); + ptr->Strings = typeRealloc(char *, ptr->num_Strings, ptr->Strings); - TRACE_IN(("extended header is %d/%d/%d(%d:%d)", ext_bool_count, ext_num_count, ext_str_count, ext_str_size, ext_str_limit)); + TRACE_IN(("extended header is %d/%d/%d(%d:%d)", ext_bool_count, + ext_num_count, ext_str_count, ext_str_size, ext_str_limit)); TRACE_IN(("READ %d extended-booleans @%d", ext_bool_count, tell(fd))); if ((ptr->ext_Booleans = ext_bool_count) != 0) { - if (read(fd, ptr->Booleans + BOOLCOUNT, (unsigned)ext_bool_count) != ext_bool_count) - return(0); + if (read(fd, ptr->Booleans + BOOLCOUNT, (unsigned) + ext_bool_count) != ext_bool_count) + return (0); } even_boundary(ext_bool_count); TRACE_IN(("READ %d extended-numbers @%d", ext_num_count, tell(fd))); if ((ptr->ext_Numbers = ext_num_count) != 0) { if (!read_shorts(fd, buf, ext_num_count)) - return(0); + return (0); TRACE_IN(("Before converting extended-numbers")); convert_shorts(buf, ptr->Numbers + NUMCOUNT, ext_num_count); } TRACE_IN(("READ extended-offsets @%d", tell(fd))); if ((ext_str_count || need) - && !read_shorts(fd, buf, ext_str_count+need)) - return(0); + && !read_shorts(fd, buf, ext_str_count + need)) + return (0); - TRACE_IN(("READ %d bytes of extended-strings @%d", ext_str_limit, tell(fd))); + TRACE_IN(("READ %d bytes of extended-strings @%d", ext_str_limit, + tell(fd))); if (ext_str_limit) { if ((ptr->ext_str_table = typeMalloc(char, ext_str_limit)) == 0) - return(0); + return (0); if (read(fd, ptr->ext_str_table, ext_str_limit) != ext_str_limit) - return(0); + return (0); TRACE_IN(("first extended-string is %s", _nc_visbuf(ptr->ext_str_table))); } if ((ptr->ext_Strings = ext_str_count) != 0) { - TRACE_IN(("Before computing extended-string capabilities str_count=%d, ext_str_count=%d", str_count, ext_str_count)); - convert_strings(buf, ptr->Strings + str_count, ext_str_count, ext_str_limit, ptr->ext_str_table); - for (i = ext_str_count-1; i >= 0; i--) { - TRACE_IN(("MOVE from [%d:%d] %s", i, i+str_count, _nc_visbuf(ptr->Strings[i+str_count]))); - ptr->Strings[i+STRCOUNT] = ptr->Strings[i+str_count]; - if (VALID_STRING(ptr->Strings[i+STRCOUNT])) - base += (strlen(ptr->Strings[i+STRCOUNT]) + 1); - TRACE_IN(("... to [%d] %s", i+STRCOUNT, _nc_visbuf(ptr->Strings[i+STRCOUNT]))); + TRACE_IN(("Before computing extended-string capabilities str_count=%d, ext_str_count=%d", + str_count, ext_str_count)); + convert_strings(buf, ptr->Strings + str_count, ext_str_count, + ext_str_limit, ptr->ext_str_table); + for (i = ext_str_count - 1; i >= 0; i--) { + TRACE_IN(("MOVE from [%d:%d] %s", i, i + str_count, + _nc_visbuf(ptr->Strings[i + str_count]))); + ptr->Strings[i + STRCOUNT] = ptr->Strings[i + str_count]; + if (VALID_STRING(ptr->Strings[i + STRCOUNT])) + base += (strlen(ptr->Strings[i + STRCOUNT]) + 1); + TRACE_IN(("... to [%d] %s", i + STRCOUNT, + _nc_visbuf(ptr->Strings[i + STRCOUNT]))); } } if (need) { if ((ptr->ext_Names = typeCalloc(char *, need)) == 0) - return(0); - TRACE_IN(("ext_NAMES starting @%d in extended_strings, first = %s", base, _nc_visbuf(ptr->ext_str_table+base))); - convert_strings(buf + (2 * ext_str_count), ptr->ext_Names, need, ext_str_limit, ptr->ext_str_table + base); + return (0); + TRACE_IN(("ext_NAMES starting @%d in extended_strings, first = %s", + base, _nc_visbuf(ptr->ext_str_table + base))); + convert_strings(buf + (2 * ext_str_count), ptr->ext_Names, need, + ext_str_limit, ptr->ext_str_table + base); } T(("...done reading terminfo bool %d(%d) num %d(%d) str %d(%d)", - ptr->num_Booleans, ptr->ext_Booleans, - ptr->num_Numbers, ptr->ext_Numbers, - ptr->num_Strings, ptr->ext_Strings)); + ptr->num_Booleans, ptr->ext_Booleans, + ptr->num_Numbers, ptr->ext_Numbers, + ptr->num_Strings, ptr->ext_Strings)); TRACE_IN(("extend: num_Booleans:%d", ptr->num_Booleans)); } else #endif /* NCURSES_XNAMES */ { T(("...done reading terminfo bool %d num %d str %d", - bool_count, - num_count, - str_count)); + bool_count, + num_count, + str_count)); TRACE_IN(("normal: num_Booleans:%d", ptr->num_Booleans)); } @@ -360,23 +372,24 @@ static int read_termtype(int fd, TERMTYPE *ptr) for (i = str_count; i < STRCOUNT; i++) ptr->Strings[i] = ABSENT_STRING; - return(1); + return (1); } -int _nc_read_file_entry(const char *const filename, TERMTYPE *ptr) +int +_nc_read_file_entry(const char *const filename, TERMTYPE * ptr) /* return 1 if read, 0 if not found or garbled */ { int code, fd = -1; #ifdef __OpenBSD__ if (_nc_read_bsd_terminfo_file(filename, ptr) == 1) - return(1); + return (1); #endif /* __OpenBSD__ */ if (_nc_access(filename, R_OK) < 0 - || (fd = open(filename, O_RDONLY|O_BINARY)) < 0) { + || (fd = open(filename, O_RDONLY | O_BINARY)) < 0) { T(("cannot open terminfo %s (errno=%d)", filename, errno)); - return(0); + return (0); } T(("read terminfo %s", filename)); @@ -391,51 +404,54 @@ int _nc_read_file_entry(const char *const filename, TERMTYPE *ptr) * Build a terminfo pathname and try to read the data. Returns 1 on success, * 0 on failure. */ -static int _nc_read_tic_entry(char *const filename, - const char *const dir, const char *ttn, TERMTYPE *const tp) +static int +_nc_read_tic_entry(char *const filename, + const char *const dir, const char *ttn, TERMTYPE * const tp) { /* maximum safe length of terminfo root directory name */ #define MAX_TPATH (PATH_MAX - MAX_ALIAS - 6) - if (strlen(dir) > MAX_TPATH) - return 0; - (void) sprintf(filename, "%s/%s", dir, ttn); - return _nc_read_file_entry(filename, tp); + if (strlen(dir) > MAX_TPATH) + return 0; + (void) sprintf(filename, "%s/%s", dir, ttn); + return _nc_read_file_entry(filename, tp); } /* * Process the list of :-separated directories, looking for the terminal type. * We don't use strtok because it does not show us empty tokens. */ -static int _nc_read_terminfo_dirs(const char *dirs, char *const filename, const char *const ttn, TERMTYPE *const tp) +static int +_nc_read_terminfo_dirs(const char *dirs, char *const filename, const char *const + ttn, TERMTYPE * const tp) { - char *list, *a; - const char *b; - int code = 0; - - /* we'll modify the argument, so we must copy */ - if ((b = a = list = strdup(dirs)) == NULL) - return(0); - - for (;;) { - int c = *a; - if (c == 0 || c == ':') { - *a = 0; - if ((b + 1) >= a) - b = TERMINFO; - if (_nc_read_tic_entry(filename, b, ttn, tp) == 1) { - code = 1; - break; - } - b = a + 1; - if (c == 0) - break; - } - a++; + char *list, *a; + const char *b; + int code = 0; + + /* we'll modify the argument, so we must copy */ + if ((b = a = list = strdup(dirs)) == NULL) + return (0); + + for (;;) { + int c = *a; + if (c == 0 || c == ':') { + *a = 0; + if ((b + 1) >= a) + b = TERMINFO; + if (_nc_read_tic_entry(filename, b, ttn, tp) == 1) { + code = 1; + break; + } + b = a + 1; + if (c == 0) + break; } + a++; + } - free(list); - return(code); + free(list); + return (code); } /* @@ -447,49 +463,49 @@ static int _nc_read_terminfo_dirs(const char *dirs, char *const filename, const * overrun the file buffer. */ -int _nc_read_entry(const char *const tn, char *const filename, TERMTYPE *const tp) +int +_nc_read_entry(const char *const tn, char *const filename, TERMTYPE * const tp) { -char *envp; -char ttn[MAX_ALIAS + 3]; + char *envp; + char ttn[MAX_ALIAS + 3]; #ifdef __OpenBSD__ - /* First check the BSD terminfo.db file */ - if (_nc_read_bsd_terminfo_entry(tn, filename, tp) == 1) - return 1; + /* First check the BSD terminfo.db file */ + if (_nc_read_bsd_terminfo_entry(tn, filename, tp) == 1) + return (1); #endif /* __OpenBSD__ */ - /* truncate the terminal name to prevent dangerous buffer airline */ - (void) sprintf(ttn, "%c/%.*s", *tn, MAX_ALIAS, tn); + /* truncate the terminal name to prevent dangerous buffer airline */ + (void) sprintf(ttn, "%c/%.*s", *tn, MAX_ALIAS, tn); - /* This is System V behavior, in conjunction with our requirements for - * writing terminfo entries. - */ - if (have_tic_directory - && _nc_read_tic_entry(filename, _nc_tic_dir(0), ttn, tp) == 1) - return 1; + /* This is System V behavior, in conjunction with our requirements for + * writing terminfo entries. + */ + if (have_tic_directory + && _nc_read_tic_entry(filename, _nc_tic_dir(0), ttn, tp) == 1) + return 1; - if (!issetugid() && (envp = getenv("TERMINFO")) != 0 - && _nc_read_tic_entry(filename, _nc_tic_dir(envp), ttn, tp) == 1) - return 1; + if (!issetugid() && (envp = getenv("TERMINFO")) != 0 + && _nc_read_tic_entry(filename, _nc_tic_dir(envp), ttn, tp) == 1) + return 1; - if ((envp = _nc_home_terminfo()) != 0) { - if (_nc_read_tic_entry(filename, envp, ttn, tp) == 1) { - return(1); - } + if ((envp = _nc_home_terminfo()) != 0) { + if (_nc_read_tic_entry(filename, envp, ttn, tp) == 1) { + return (1); } + } - /* this is an ncurses extension */ - if (!issetugid() && (envp = getenv("TERMINFO_DIRS")) != 0) - return _nc_read_terminfo_dirs(envp, filename, ttn, tp); + /* this is an ncurses extension */ + if (!issetugid() && (envp = getenv("TERMINFO_DIRS")) != 0) + return _nc_read_terminfo_dirs(envp, filename, ttn, tp); - /* Try the system directory. Note that the TERMINFO_DIRS value, if - * defined by the configure script, begins with a ":", which will be - * interpreted as TERMINFO. - */ + /* Try the system directory. Note that the TERMINFO_DIRS value, if + * defined by the configure script, begins with a ":", which will be + * interpreted as TERMINFO. + */ #ifdef TERMINFO_DIRS - return _nc_read_terminfo_dirs(TERMINFO_DIRS, filename, ttn, tp); + return _nc_read_terminfo_dirs(TERMINFO_DIRS, filename, ttn, tp); #else - return _nc_read_tic_entry(filename, TERMINFO, ttn, tp); + return _nc_read_tic_entry(filename, TERMINFO, ttn, tp); #endif } - diff --git a/lib/libcurses/tinfo/write_entry.c b/lib/libcurses/tinfo/write_entry.c index 60f95451505..fa91c603775 100644 --- a/lib/libcurses/tinfo/write_entry.c +++ b/lib/libcurses/tinfo/write_entry.c @@ -1,7 +1,7 @@ -/* $OpenBSD: write_entry.c,v 1.5 1999/12/06 02:12:46 millert Exp $ */ +/* $OpenBSD: write_entry.c,v 1.6 2000/01/02 22:06:51 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998 Free Software Foundation, Inc. * + * Copyright (c) 1998-2000 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -33,8 +33,6 @@ * and: Eric S. Raymond <esr@snark.thyrsus.com> * ****************************************************************************/ - - /* * write_entry.c -- write a terminfo structure onto the file system */ @@ -53,28 +51,29 @@ #if 0 #define TRACE_OUT(p) DEBUG(2, p) #else -#define TRACE_OUT(p) /*nothing*/ +#define TRACE_OUT(p) /*nothing */ #endif -MODULE_ID("$From: write_entry.c,v 1.48 1999/12/04 23:02:59 tom Exp $") +MODULE_ID("$From: write_entry.c,v 1.50 2000/01/01 16:35:44 tom Exp $") static int total_written; static int write_object(FILE *, TERMTYPE *); -static void write_file(char *filename, TERMTYPE *tp) +static void +write_file(char *filename, TERMTYPE * tp) { - FILE *fp = (_nc_access(filename, W_OK) == 0) ? fopen(filename, "wb") : 0; - if (fp == 0) { - perror(filename); - _nc_syserr_abort("can't open %s/%s", _nc_tic_dir(0), filename); - } - DEBUG(1, ("Created %s", filename)); + FILE *fp = (_nc_access(filename, W_OK) == 0) ? fopen(filename, "wb") : 0; + if (fp == 0) { + perror(filename); + _nc_syserr_abort("can't open %s/%s", _nc_tic_dir(0), filename); + } + DEBUG(1, ("Created %s", filename)); - if (write_object(fp, tp) == ERR) { - _nc_syserr_abort("error writing %s/%s", _nc_tic_dir(0), filename); - } - fclose(fp); + if (write_object(fp, tp) == ERR) { + _nc_syserr_abort("error writing %s/%s", _nc_tic_dir(0), filename); + } + fclose(fp); } /* @@ -82,36 +81,38 @@ static void write_file(char *filename, TERMTYPE *tp) * * Make a directory if it doesn't exist. */ -static int make_directory(const char *path) +static int +make_directory(const char *path) { -int rc; -struct stat statbuf; -char fullpath[PATH_MAX]; -const char *destination = _nc_tic_dir(0); - - if (path == destination || *path == '/') { - if (strlen(path) + 1 > sizeof(fullpath)) - return(-1); - (void)strcpy(fullpath, path); - } else { - if (strlen(destination) + strlen(path) + 2 > sizeof(fullpath)) - return(-1); - (void)sprintf(fullpath, "%s/%s", destination, path); - } + int rc; + struct stat statbuf; + char fullpath[PATH_MAX]; + const char *destination = _nc_tic_dir(0); + + if (path == destination || *path == '/') { + if (strlen(path) + 1 > sizeof(fullpath)) + return (-1); + (void) strcpy(fullpath, path); + } else { + if (strlen(destination) + strlen(path) + 2 > sizeof(fullpath)) + return (-1); + (void) sprintf(fullpath, "%s/%s", destination, path); + } - if ((rc = stat(path, &statbuf)) < 0) { - rc = mkdir(path, 0777); - } else { - if (_nc_access(path, R_OK|W_OK|X_OK) < 0) { - rc = -1; /* permission denied */ - } else if (!(S_ISDIR(statbuf.st_mode))) { - rc = -1; /* not a directory */ - } + if ((rc = stat(path, &statbuf)) < 0) { + rc = mkdir(path, 0777); + } else { + if (_nc_access(path, R_OK | W_OK | X_OK) < 0) { + rc = -1; /* permission denied */ + } else if (!(S_ISDIR(statbuf.st_mode))) { + rc = -1; /* not a directory */ } - return rc; + } + return rc; } -void _nc_set_writedir(char *dir) +void +_nc_set_writedir(char *dir) /* set the write directory for compiled entries */ { const char *destination; @@ -123,15 +124,14 @@ void _nc_set_writedir(char *dir) (void) _nc_tic_dir(getenv("TERMINFO")); destination = _nc_tic_dir(0); - if (make_directory(destination) < 0) - { - char *home = _nc_home_terminfo(); + if (make_directory(destination) < 0) { + char *home = _nc_home_terminfo(); if (home != 0) { destination = home; if (make_directory(destination) < 0) _nc_err_abort("%s: permission denied (errno %d)", - destination, errno); + destination, errno); } } @@ -140,7 +140,7 @@ void _nc_set_writedir(char *dir) * *once only* per run. */ if (chdir(_nc_tic_dir(destination)) < 0 - || getcwd(actual, sizeof(actual)) == 0) + || getcwd(actual, sizeof(actual)) == 0) _nc_err_abort("%s: not a directory", destination); _nc_keep_tic_dir(strdup(actual)); } @@ -157,27 +157,28 @@ void _nc_set_writedir(char *dir) * */ -static void check_writeable(int code) +static void +check_writeable(int code) { -static const char dirnames[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; -static bool verified[sizeof(dirnames)]; + static const char dirnames[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + static bool verified[sizeof(dirnames)]; -char dir[2]; -char *s; + char dir[2]; + char *s; - if (code == 0 || (s = strchr(dirnames, code)) == 0) - _nc_err_abort("Illegal terminfo subdirectory \"%c\"", code); + if (code == 0 || (s = strchr(dirnames, code)) == 0) + _nc_err_abort("Illegal terminfo subdirectory \"%c\"", code); - if (verified[s-dirnames]) - return; + if (verified[s - dirnames]) + return; - dir[0] = code; - dir[1] = '\0'; - if (make_directory(dir) < 0) { - _nc_err_abort("%s/%s: permission denied", _nc_tic_dir(0), dir); - } + dir[0] = code; + dir[1] = '\0'; + if (make_directory(dir) < 0) { + _nc_err_abort("%s/%s: permission denied", _nc_tic_dir(0), dir); + } - verified[s-dirnames] = TRUE; + verified[s - dirnames] = TRUE; } /* @@ -202,163 +203,159 @@ char *s; * _nc_curr_line is properly set before the write_entry() call. */ -void _nc_write_entry(TERMTYPE *const tp) +void +_nc_write_entry(TERMTYPE * const tp) { -struct stat statbuf; -char name_list[MAX_TERMINFO_LENGTH]; -char *first_name, *other_names; -char *ptr; -char filename[PATH_MAX]; -char linkname[PATH_MAX]; + struct stat statbuf; + char name_list[MAX_TERMINFO_LENGTH]; + char *first_name, *other_names; + char *ptr; + char filename[PATH_MAX]; + char linkname[PATH_MAX]; #if USE_SYMLINKS -char symlinkname[PATH_MAX]; + char symlinkname[PATH_MAX]; #endif /* USE_SYMLINKS */ -static int call_count; -static time_t start_time; /* time at start of writes */ + static int call_count; + static time_t start_time; /* time at start of writes */ - if (call_count++ == 0) { - start_time = 0; - } + if (call_count++ == 0) { + start_time = 0; + } - (void) strcpy(name_list, tp->term_names); - DEBUG(7, ("Name list = '%s'", name_list)); + (void) strcpy(name_list, tp->term_names); + DEBUG(7, ("Name list = '%s'", name_list)); - first_name = name_list; + first_name = name_list; - ptr = &name_list[strlen(name_list) - 1]; - other_names = ptr + 1; + ptr = &name_list[strlen(name_list) - 1]; + other_names = ptr + 1; - while (ptr > name_list && *ptr != '|') - ptr--; + while (ptr > name_list && *ptr != '|') + ptr--; - if (ptr != name_list) { - *ptr = '\0'; + if (ptr != name_list) { + *ptr = '\0'; - for (ptr = name_list; *ptr != '\0' && *ptr != '|'; ptr++) - continue; + for (ptr = name_list; *ptr != '\0' && *ptr != '|'; ptr++) + continue; - if (*ptr == '\0') - other_names = ptr; - else { - *ptr = '\0'; - other_names = ptr + 1; - } + if (*ptr == '\0') + other_names = ptr; + else { + *ptr = '\0'; + other_names = ptr + 1; } + } - DEBUG(7, ("First name = '%s'", first_name)); - DEBUG(7, ("Other names = '%s'", other_names)); + DEBUG(7, ("First name = '%s'", first_name)); + DEBUG(7, ("Other names = '%s'", other_names)); - _nc_set_type(first_name); + _nc_set_type(first_name); - if (strlen(first_name) > sizeof(filename)-3) - _nc_warning("terminal name too long."); + if (strlen(first_name) > sizeof(filename) - 3) + _nc_warning("terminal name too long."); - sprintf(filename, "%c/%s", first_name[0], first_name); + sprintf(filename, "%c/%s", first_name[0], first_name); - /* - * Has this primary name been written since the first call to - * write_entry()? If so, the newer write will step on the older, - * so warn the user. - */ - if (start_time > 0 && - stat(filename, &statbuf) >= 0 - && statbuf.st_mtime >= start_time) - { - _nc_warning("name multiply defined."); + /* + * Has this primary name been written since the first call to + * write_entry()? If so, the newer write will step on the older, + * so warn the user. + */ + if (start_time > 0 && + stat(filename, &statbuf) >= 0 + && statbuf.st_mtime >= start_time) { + _nc_warning("name multiply defined."); + } + + check_writeable(first_name[0]); + write_file(filename, tp); + + if (start_time == 0) { + if (stat(filename, &statbuf) < 0 + || (start_time = statbuf.st_mtime) == 0) { + _nc_syserr_abort("error obtaining time from %s/%s", + _nc_tic_dir(0), filename); } + } + while (*other_names != '\0') { + ptr = other_names++; + while (*other_names != '|' && *other_names != '\0') + other_names++; - check_writeable(first_name[0]); - write_file(filename, tp); + if (*other_names != '\0') + *(other_names++) = '\0'; - if (start_time == 0) { - if (stat(filename, &statbuf) < 0 - || (start_time = statbuf.st_mtime) == 0) { - _nc_syserr_abort("error obtaining time from %s/%s", - _nc_tic_dir(0), filename); - } + if (strlen(ptr) > sizeof(linkname) - 3) { + _nc_warning("terminal alias %s too long.", ptr); + continue; } - while (*other_names != '\0') { - ptr = other_names++; - while (*other_names != '|' && *other_names != '\0') - other_names++; - - if (*other_names != '\0') - *(other_names++) = '\0'; - - if (strlen(ptr) > sizeof(linkname)-3) { - _nc_warning("terminal alias %s too long.", ptr); - continue; - } - if (strchr(ptr, '/') != 0) { - _nc_warning("cannot link alias %s.", ptr); - continue; - } - - check_writeable(ptr[0]); - sprintf(linkname, "%c/%s", ptr[0], ptr); - - if (strcmp(filename, linkname) == 0) { - _nc_warning("self-synonym ignored"); - } - else if (stat(linkname, &statbuf) >= 0 && - statbuf.st_mtime < start_time) - { - _nc_warning("alias %s multiply defined.", ptr); - } - else if (_nc_access(linkname, W_OK) == 0) + if (strchr(ptr, '/') != 0) { + _nc_warning("cannot link alias %s.", ptr); + continue; + } + + check_writeable(ptr[0]); + sprintf(linkname, "%c/%s", ptr[0], ptr); + + if (strcmp(filename, linkname) == 0) { + _nc_warning("self-synonym ignored"); + } else if (stat(linkname, &statbuf) >= 0 && + statbuf.st_mtime < start_time) { + _nc_warning("alias %s multiply defined.", ptr); + } else if (_nc_access(linkname, W_OK) == 0) #if HAVE_LINK - { - int code; + { + int code; #if USE_SYMLINKS - strcpy(symlinkname, "../"); - strncat(symlinkname, filename, sizeof(symlinkname) - 4); - symlinkname[sizeof(symlinkname) - 1] = '\0'; + strcpy(symlinkname, "../"); + strncat(symlinkname, filename, sizeof(symlinkname) - 4); + symlinkname[sizeof(symlinkname) - 1] = '\0'; #endif /* USE_SYMLINKS */ #if HAVE_REMOVE - code = remove(linkname); + code = remove(linkname); #else - code = unlink(linkname); + code = unlink(linkname); #endif - if (code != 0 && errno == ENOENT) - code = 0; + if (code != 0 && errno == ENOENT) + code = 0; #if USE_SYMLINKS - if (symlink(symlinkname, linkname) < 0) + if (symlink(symlinkname, linkname) < 0) #else - if (link(filename, linkname) < 0) + if (link(filename, linkname) < 0) #endif /* USE_SYMLINKS */ - { - /* - * If there wasn't anything there, and we cannot - * link to the target because it is the same as the - * target, then the source must be on a filesystem - * that uses caseless filenames, such as Win32, etc. - */ - if (code == 0 && errno == EEXIST) - _nc_warning("can't link %s to %s", filename, linkname); - else if (code == 0 && errno == EPERM) - write_file(linkname, tp); - else - _nc_syserr_abort("can't link %s to %s", filename, linkname); - } - else - { - DEBUG(1, ("Linked %s", linkname)); - } - } + { + /* + * If there wasn't anything there, and we cannot + * link to the target because it is the same as the + * target, then the source must be on a filesystem + * that uses caseless filenames, such as Win32, etc. + */ + if (code == 0 && errno == EEXIST) + _nc_warning("can't link %s to %s", filename, linkname); + else if (code == 0 && errno == EPERM) + write_file(linkname, tp); + else + _nc_syserr_abort("can't link %s to %s", filename, linkname); + } else { + DEBUG(1, ("Linked %s", linkname)); + } + } #else /* just make copies */ - write_file(linkname, tp); + write_file(linkname, tp); #endif /* HAVE_LINK */ - } + } } -#undef LITTLE_ENDIAN /* BSD/OS defines this as a feature macro */ +#undef LITTLE_ENDIAN /* BSD/OS defines this as a feature macro */ #define HI(x) ((x) / 256) #define LO(x) ((x) % 256) #define LITTLE_ENDIAN(p, x) (p)[0] = LO(x), (p)[1] = HI(x) #define WRITE_STRING(str) (fwrite(str, sizeof(char), strlen(str) + 1, fp) == strlen(str) + 1) -static int compute_offsets(char **Strings, int strmax, short *offsets) +static int +compute_offsets(char **Strings, int strmax, short *offsets) { size_t nextfree = 0; int i; @@ -377,17 +374,18 @@ static int compute_offsets(char **Strings, int strmax, short *offsets) return nextfree; } -static void convert_shorts(unsigned char *buf, short *Numbers, int count) +static void +convert_shorts(unsigned char *buf, short *Numbers, int count) { int i; for (i = 0; i < count; i++) { - if (Numbers[i] == -1) { /* HI/LO won't work */ - buf[2*i] = buf[2*i + 1] = 0377; - } else if (Numbers[i] == -2) { /* HI/LO won't work */ - buf[2*i] = 0376; - buf[2*i + 1] = 0377; + if (Numbers[i] == ABSENT_NUMERIC) { /* HI/LO won't work */ + buf[2 * i] = buf[2 * i + 1] = 0377; + } else if (Numbers[i] == CANCELLED_NUMERIC) { /* HI/LO won't work */ + buf[2 * i] = 0376; + buf[2 * i + 1] = 0377; } else { - LITTLE_ENDIAN(buf + 2*i, Numbers[i]); + LITTLE_ENDIAN(buf + 2 * i, Numbers[i]); TRACE_OUT(("put Numbers[%d]=%d", i, Numbers[i])); } } @@ -396,177 +394,181 @@ static void convert_shorts(unsigned char *buf, short *Numbers, int count) #define even_boundary(value) \ ((value) % 2 != 0 && fwrite(&zero, sizeof(char), 1, fp) != 1) -static int write_object(FILE *fp, TERMTYPE *tp) +static int +write_object(FILE * fp, TERMTYPE * tp) { -char *namelist; -size_t namelen, boolmax, nummax, strmax; -char zero = '\0'; -size_t i; -short nextfree; -short offsets[MAX_ENTRY_SIZE/2]; -unsigned char buf[MAX_ENTRY_SIZE]; -unsigned last_bool = BOOLWRITE; -unsigned last_num = NUMWRITE; -unsigned last_str = STRWRITE; + char *namelist; + size_t namelen, boolmax, nummax, strmax; + char zero = '\0'; + size_t i; + short nextfree; + short offsets[MAX_ENTRY_SIZE / 2]; + unsigned char buf[MAX_ENTRY_SIZE]; + unsigned last_bool = BOOLWRITE; + unsigned last_num = NUMWRITE; + unsigned last_str = STRWRITE; #if NCURSES_XNAMES - /* - * Normally we limit the list of values to exclude the "obsolete" - * capabilities. However, if we are accepting extended names, add - * these as well, since they are used for supporting translation - * to/from termcap. - */ - if (_nc_user_definable) { - last_bool = BOOLCOUNT; - last_num = NUMCOUNT; - last_str = STRCOUNT; - } + /* + * Normally we limit the list of values to exclude the "obsolete" + * capabilities. However, if we are accepting extended names, add + * these as well, since they are used for supporting translation + * to/from termcap. + */ + if (_nc_user_definable) { + last_bool = BOOLCOUNT; + last_num = NUMCOUNT; + last_str = STRCOUNT; + } #endif - namelist = tp->term_names; - namelen = strlen(namelist) + 1; + namelist = tp->term_names; + namelen = strlen(namelist) + 1; - boolmax = 0; - for (i = 0; i < last_bool; i++) { - if (tp->Booleans[i]) - boolmax = i+1; - } + boolmax = 0; + for (i = 0; i < last_bool; i++) { + if (tp->Booleans[i]) + boolmax = i + 1; + } - nummax = 0; - for (i = 0; i < last_num; i++) { - if (tp->Numbers[i] != ABSENT_NUMERIC) - nummax = i+1; - } + nummax = 0; + for (i = 0; i < last_num; i++) { + if (tp->Numbers[i] != ABSENT_NUMERIC) + nummax = i + 1; + } - strmax = 0; - for (i = 0; i < last_str; i++) { - if (tp->Strings[i] != ABSENT_STRING) - strmax = i+1; - } + strmax = 0; + for (i = 0; i < last_str; i++) { + if (tp->Strings[i] != ABSENT_STRING) + strmax = i + 1; + } - nextfree = compute_offsets(tp->Strings, strmax, offsets); + nextfree = compute_offsets(tp->Strings, strmax, offsets); - /* fill in the header */ - LITTLE_ENDIAN(buf, MAGIC); - LITTLE_ENDIAN(buf+2, min(namelen, MAX_NAME_SIZE + 1)); - LITTLE_ENDIAN(buf+4, boolmax); - LITTLE_ENDIAN(buf+6, nummax); - LITTLE_ENDIAN(buf+8, strmax); - LITTLE_ENDIAN(buf+10, nextfree); + /* fill in the header */ + LITTLE_ENDIAN(buf, MAGIC); + LITTLE_ENDIAN(buf + 2, min(namelen, MAX_NAME_SIZE + 1)); + LITTLE_ENDIAN(buf + 4, boolmax); + LITTLE_ENDIAN(buf + 6, nummax); + LITTLE_ENDIAN(buf + 8, strmax); + LITTLE_ENDIAN(buf + 10, nextfree); - /* write out the header */ - TRACE_OUT(("Header of %s @%ld", namelist, ftell(fp))); - if (fwrite(buf, 12, 1, fp) != 1 - || fwrite(namelist, sizeof(char), namelen, fp) != namelen - || fwrite(tp->Booleans, sizeof(char), boolmax, fp) != boolmax) - return(ERR); + /* write out the header */ + TRACE_OUT(("Header of %s @%ld", namelist, ftell(fp))); + if (fwrite(buf, 12, 1, fp) != 1 + || fwrite(namelist, sizeof(char), namelen, fp) != namelen + || fwrite(tp->Booleans, sizeof(char), boolmax, fp) != boolmax) + return (ERR); - if (even_boundary(namelen+boolmax)) - return(ERR); + if (even_boundary(namelen + boolmax)) + return (ERR); - TRACE_OUT(("Numerics begin at %04lx", ftell(fp))); + TRACE_OUT(("Numerics begin at %04lx", ftell(fp))); - /* the numerics */ - convert_shorts(buf, tp->Numbers, nummax); - if (fwrite(buf, 2, nummax, fp) != nummax) - return(ERR); + /* the numerics */ + convert_shorts(buf, tp->Numbers, nummax); + if (fwrite(buf, 2, nummax, fp) != nummax) + return (ERR); - TRACE_OUT(("String offsets begin at %04lx", ftell(fp))); + TRACE_OUT(("String offsets begin at %04lx", ftell(fp))); - /* the string offsets */ - convert_shorts(buf, offsets, strmax); - if (fwrite(buf, 2, strmax, fp) != strmax) - return(ERR); + /* the string offsets */ + convert_shorts(buf, offsets, strmax); + if (fwrite(buf, 2, strmax, fp) != strmax) + return (ERR); - TRACE_OUT(("String table begins at %04lx", ftell(fp))); + TRACE_OUT(("String table begins at %04lx", ftell(fp))); - /* the strings */ - for (i = 0; i < strmax; i++) - if (VALID_STRING(tp->Strings[i])) - if (!WRITE_STRING(tp->Strings[i])) - return(ERR); + /* the strings */ + for (i = 0; i < strmax; i++) + if (VALID_STRING(tp->Strings[i])) + if (!WRITE_STRING(tp->Strings[i])) + return (ERR); #if NCURSES_XNAMES - if (NUM_EXT_NAMES(tp)) { - unsigned extcnt = NUM_EXT_NAMES(tp); - - if (even_boundary(nextfree)) - return(ERR); - - nextfree = compute_offsets(tp->Strings + STRCOUNT, tp->ext_Strings, offsets); - TRACE_OUT(("after extended string capabilities, nextfree=%d", nextfree)); - nextfree += compute_offsets(tp->ext_Names, extcnt, offsets + tp->ext_Strings); - TRACE_OUT(("after extended capnames, nextfree=%d", nextfree)); - strmax = tp->ext_Strings + extcnt; - - /* - * Write the extended header - */ - LITTLE_ENDIAN(buf+0, tp->ext_Booleans); - LITTLE_ENDIAN(buf+2, tp->ext_Numbers); - LITTLE_ENDIAN(buf+4, tp->ext_Strings); - LITTLE_ENDIAN(buf+6, strmax); - LITTLE_ENDIAN(buf+8, nextfree); - TRACE_OUT(("WRITE extended-header @%ld", ftell(fp))); - if (fwrite(buf, 10, 1, fp) != 1) - return(ERR); - - TRACE_OUT(("WRITE %d booleans @%ld", tp->ext_Booleans, ftell(fp))); - if (tp->ext_Booleans - && fwrite(tp->Booleans + BOOLCOUNT, sizeof(char), tp->ext_Booleans, fp) != tp->ext_Booleans) - return(ERR); - - if (even_boundary(tp->ext_Booleans)) - return(ERR); - - TRACE_OUT(("WRITE %d numbers @%ld", tp->ext_Numbers, ftell(fp))); - if (tp->ext_Numbers) { - convert_shorts(buf, tp->Numbers + NUMCOUNT, tp->ext_Numbers); - if (fwrite(buf, 2, tp->ext_Numbers, fp) != tp->ext_Numbers) - return(ERR); - } + if (NUM_EXT_NAMES(tp)) { + unsigned extcnt = NUM_EXT_NAMES(tp); - /* - * Convert the offsets for the ext_Strings and ext_Names tables, - * in that order. - */ - convert_shorts(buf, offsets, strmax); - TRACE_OUT(("WRITE offsets @%ld", ftell(fp))); - if (fwrite(buf, 2, strmax, fp) != strmax) - return(ERR); - - /* - * Write the string table after the offset tables so we do not - * have to do anything about alignment. - */ - for (i = 0; i < tp->ext_Strings; i++) { - if (VALID_STRING(tp->Strings[i+STRCOUNT])) { - TRACE_OUT(("WRITE ext_Strings[%d]=%s", i, _nc_visbuf(tp->Strings[i+STRCOUNT]))); - if (!WRITE_STRING(tp->Strings[i+STRCOUNT])) - return(ERR); - } - } + if (even_boundary(nextfree)) + return (ERR); + + nextfree = compute_offsets(tp->Strings + STRCOUNT, tp->ext_Strings, offsets); + TRACE_OUT(("after extended string capabilities, nextfree=%d", nextfree)); + nextfree += compute_offsets(tp->ext_Names, extcnt, offsets + tp->ext_Strings); + TRACE_OUT(("after extended capnames, nextfree=%d", nextfree)); + strmax = tp->ext_Strings + extcnt; - /* - * Write the extended names - */ - for (i = 0; i < extcnt; i++) { - TRACE_OUT(("WRITE ext_Names[%d]=%s", i, tp->ext_Names[i])); - if (!WRITE_STRING(tp->ext_Names[i])) - return(ERR); + /* + * Write the extended header + */ + LITTLE_ENDIAN(buf + 0, tp->ext_Booleans); + LITTLE_ENDIAN(buf + 2, tp->ext_Numbers); + LITTLE_ENDIAN(buf + 4, tp->ext_Strings); + LITTLE_ENDIAN(buf + 6, strmax); + LITTLE_ENDIAN(buf + 8, nextfree); + TRACE_OUT(("WRITE extended-header @%ld", ftell(fp))); + if (fwrite(buf, 10, 1, fp) != 1) + return (ERR); + + TRACE_OUT(("WRITE %d booleans @%ld", tp->ext_Booleans, ftell(fp))); + if (tp->ext_Booleans + && fwrite(tp->Booleans + BOOLCOUNT, sizeof(char), + tp->ext_Booleans, fp) != tp->ext_Booleans) + return (ERR); + + if (even_boundary(tp->ext_Booleans)) + return (ERR); + + TRACE_OUT(("WRITE %d numbers @%ld", tp->ext_Numbers, ftell(fp))); + if (tp->ext_Numbers) { + convert_shorts(buf, tp->Numbers + NUMCOUNT, tp->ext_Numbers); + if (fwrite(buf, 2, tp->ext_Numbers, fp) != tp->ext_Numbers) + return (ERR); + } + + /* + * Convert the offsets for the ext_Strings and ext_Names tables, + * in that order. + */ + convert_shorts(buf, offsets, strmax); + TRACE_OUT(("WRITE offsets @%ld", ftell(fp))); + if (fwrite(buf, 2, strmax, fp) != strmax) + return (ERR); + + /* + * Write the string table after the offset tables so we do not + * have to do anything about alignment. + */ + for (i = 0; i < tp->ext_Strings; i++) { + if (VALID_STRING(tp->Strings[i + STRCOUNT])) { + TRACE_OUT(("WRITE ext_Strings[%d]=%s", i, + _nc_visbuf(tp->Strings[i + STRCOUNT]))); + if (!WRITE_STRING(tp->Strings[i + STRCOUNT])) + return (ERR); } + } + /* + * Write the extended names + */ + for (i = 0; i < extcnt; i++) { + TRACE_OUT(("WRITE ext_Names[%d]=%s", i, tp->ext_Names[i])); + if (!WRITE_STRING(tp->ext_Names[i])) + return (ERR); } + + } #endif /* NCURSES_XNAMES */ - total_written++; - return(OK); + total_written++; + return (OK); } /* * Returns the total number of entries written by this process */ -int _nc_tic_written(void) +int +_nc_tic_written(void) { - return total_written; + return total_written; } |