diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2000-01-09 05:06:03 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2000-01-09 05:06:03 +0000 |
commit | ebc42814930af81c58a08d49ec49f811ad07f536 (patch) | |
tree | afaf4143a978a455e8fe8f19c732146b126ce3b4 /lib | |
parent | 8f07a2500fbd49bc7163892c584f45cd85322fcd (diff) |
Update to ncurses-5.0-20000108:
+ add prototype for erase() to curses.h
+ add TRACE_DATABASE flag for trace().
+ formatting changes (style)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libcurses/base/lib_mouse.c | 17 | ||||
-rw-r--r-- | lib/libcurses/base/lib_nl.c | 34 | ||||
-rw-r--r-- | lib/libcurses/curses.h | 8 | ||||
-rw-r--r-- | lib/libcurses/curses.priv.h | 12 | ||||
-rw-r--r-- | lib/libcurses/terminfo.5tbl | 8 | ||||
-rw-r--r-- | lib/libcurses/tinfo/lib_raw.c | 18 | ||||
-rw-r--r-- | lib/libcurses/tinfo/read_entry.c | 77 | ||||
-rw-r--r-- | lib/libcurses/tinfo/read_termcap.c | 1428 | ||||
-rw-r--r-- | lib/libcurses/trace/lib_trace.c | 248 | ||||
-rw-r--r-- | lib/libcurses/trace/lib_tracebits.c | 195 |
10 files changed, 1022 insertions, 1023 deletions
diff --git a/lib/libcurses/base/lib_mouse.c b/lib/libcurses/base/lib_mouse.c index e3ef84222d5..29cec56f17e 100644 --- a/lib/libcurses/base/lib_mouse.c +++ b/lib/libcurses/base/lib_mouse.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_mouse.c,v 1.6 1999/12/28 15:57:59 millert Exp $ */ +/* $OpenBSD: lib_mouse.c,v 1.7 2000/01/09 05:06:02 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 * @@ -66,8 +66,7 @@ */ #ifdef __EMX__ -# include "io.h" -# include "fcntl.h" +# include <io.h> # define INCL_DOS # define INCL_VIO # define INCL_KBD @@ -87,7 +86,7 @@ #endif #endif -MODULE_ID("$From: lib_mouse.c,v 1.47 1999/12/19 01:49:40 tom Exp $") +MODULE_ID("$From: lib_mouse.c,v 1.48 2000/01/08 17:34:43 tom Exp $"); #define MY_TRACE TRACE_ICALLS|TRACE_IEVENT @@ -422,7 +421,7 @@ _nc_mouse_inline(SCREEN * sp) kbuf[3] = '\0'; TR(TRACE_IEVENT, - ("_nc_mouse_inline sees the following xterm data: '%s'", kbuf)); + ("_nc_mouse_inline sees the following xterm data: '%s'", kbuf)); eventp->id = 0; /* there's only one mouse... */ @@ -491,7 +490,7 @@ _nc_mouse_inline(SCREEN * sp) eventp->x = (kbuf[1] - ' ') - 1; eventp->y = (kbuf[2] - ' ') - 1; TR(MY_TRACE, - ("_nc_mouse_inline: primitive mouse-event %s has slot %ld", + ("_nc_mouse_inline: primitive mouse-event %s has slot %ld", _tracemouse(eventp), (long) (eventp - events))); @@ -601,7 +600,7 @@ _nc_mouse_parse(int runcount) */ if (runcount == 1) { TR(MY_TRACE, - ("_nc_mouse_parse: returning simple mouse event %s at slot %ld", + ("_nc_mouse_parse: returning simple mouse event %s at slot %ld", _tracemouse(prev), (long) (prev - events))); return (prev->id >= 0) @@ -789,7 +788,7 @@ _nc_mouse_parse(int runcount) for (ep = runp; ep != eventp; ep = NEXT(ep)) if (ep->id != INVALID_EVENT) TR(MY_TRACE, - ("_nc_mouse_parse: returning composite mouse event %s at slot %ld", + ("_nc_mouse_parse: returning composite mouse event %s at slot %ld", _tracemouse(ep), (long) (ep - events))); #endif /* TRACE */ diff --git a/lib/libcurses/base/lib_nl.c b/lib/libcurses/base/lib_nl.c index 9895d1d6f8a..5e69c25e300 100644 --- a/lib/libcurses/base/lib_nl.c +++ b/lib/libcurses/base/lib_nl.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_nl.c,v 1.2 1999/11/28 17:49:53 millert Exp $ */ +/* $OpenBSD: lib_nl.c,v 1.3 2000/01/09 05:06:02 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> * ****************************************************************************/ - /* * nl.c * @@ -45,37 +44,38 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_nl.c,v 1.4 1999/10/22 22:31:51 tom Exp $") +MODULE_ID("$From: lib_nl.c,v 1.5 2000/01/08 17:33:30 tom Exp $") #ifdef __EMX__ #include <io.h> -#include <fcntl.h> #endif -int nl(void) +int +nl(void) { - T((T_CALLED("nl()"))); + T((T_CALLED("nl()"))); - SP->_nl = TRUE; + SP->_nl = TRUE; #ifdef __EMX__ - _nc_flush(); - _fsetmode(NC_OUTPUT, "t"); + _nc_flush(); + _fsetmode(NC_OUTPUT, "t"); #endif - returnCode(OK); + returnCode(OK); } -int nonl(void) +int +nonl(void) { - T((T_CALLED("nonl()"))); + T((T_CALLED("nonl()"))); - SP->_nl = FALSE; + SP->_nl = FALSE; #ifdef __EMX__ - _nc_flush(); - _fsetmode(NC_OUTPUT, "b"); + _nc_flush(); + _fsetmode(NC_OUTPUT, "b"); #endif - returnCode(OK); + returnCode(OK); } diff --git a/lib/libcurses/curses.h b/lib/libcurses/curses.h index 11dba55f958..0689baa1e28 100644 --- a/lib/libcurses/curses.h +++ b/lib/libcurses/curses.h @@ -1,4 +1,4 @@ -/* $OpenBSD: curses.h,v 1.42 2000/01/02 22:06:50 millert Exp $ */ +/* $OpenBSD: curses.h,v 1.43 2000/01/09 05:06:01 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -33,7 +33,7 @@ * and: Eric S. Raymond <esr@snark.thyrsus.com> * ****************************************************************************/ -/* $From: curses.h.in,v 1.87 1999/11/14 00:21:57 tom Exp $ */ +/* $From: curses.h.in,v 1.89 2000/01/09 01:10:20 tom Exp $ */ #ifndef __NCURSES_H #define __NCURSES_H @@ -50,7 +50,7 @@ /* These are defined only in curses.h, and are used for conditional compiles */ #define NCURSES_VERSION_MAJOR 5 #define NCURSES_VERSION_MINOR 0 -#define NCURSES_VERSION_PATCH 20000101 +#define NCURSES_VERSION_PATCH 20000108 /* This is defined in more than one ncurses header, for identification */ #undef NCURSES_VERSION @@ -439,6 +439,7 @@ extern int doupdate(void); /* implemented */ extern WINDOW *dupwin(WINDOW *); /* implemented */ extern int echo(void); /* implemented */ extern int echochar(const chtype); /* generated */ +extern int erase(void); /* generated */ #ifdef _XOPEN_SOURCE_EXTENDED extern int echo_wchar(const cchar_t *); /* missing */ extern int erasewchar(wchar_t*); /* missing */ @@ -1335,6 +1336,7 @@ extern void trace(const unsigned int); #define TRACE_BITS 0x0100 /* trace state of TTY control bits */ #define TRACE_ICALLS 0x0200 /* trace internal/nested calls */ #define TRACE_CCALLS 0x0400 /* trace per-character calls */ +#define TRACE_DATABASE 0x0800 /* trace read/write of terminfo/termcap data */ #define TRACE_MAXIMUM 0xffff /* maximum trace level */ #if defined(TRACE) || defined(NCURSES_TEST) diff --git a/lib/libcurses/curses.priv.h b/lib/libcurses/curses.priv.h index 02925ff0114..7f1c55e4dca 100644 --- a/lib/libcurses/curses.priv.h +++ b/lib/libcurses/curses.priv.h @@ -1,4 +1,4 @@ -/* $OpenBSD: curses.priv.h,v 1.22 1999/12/06 02:13:31 millert Exp $ */ +/* $OpenBSD: curses.priv.h,v 1.23 2000/01/09 05:06:01 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -35,7 +35,7 @@ /* - * $From: curses.priv.h,v 1.148 1999/12/04 18:09:40 tom Exp $ + * $From: curses.priv.h,v 1.149 2000/01/08 17:17:39 tom Exp $ * * curses.priv.h * @@ -460,6 +460,14 @@ typedef struct { #define F_OK 0 /* Test for existence. */ #endif +#if HAVE_FCNTL_H +#include <fcntl.h> /* may define O_BINARY */ +#endif + +#ifndef O_BINARY +#define O_BINARY 0 +#endif + #define TextOf(c) ((c) & (chtype)A_CHARTEXT) #define AttrOf(c) ((c) & (chtype)A_ATTRIBUTES) diff --git a/lib/libcurses/terminfo.5tbl b/lib/libcurses/terminfo.5tbl index 295d2bfaca2..587bf6b767f 100644 --- a/lib/libcurses/terminfo.5tbl +++ b/lib/libcurses/terminfo.5tbl @@ -33,7 +33,7 @@ .\"*************************************************************************** .\" .\" $From: terminfo.head,v 1.8 1998/03/11 21:12:53 juergen Exp $ -.\" $OpenBSD: terminfo.5tbl,v 1.5 1999/03/12 04:36:02 millert Exp $ +.\" $OpenBSD: terminfo.5tbl,v 1.6 2000/01/09 05:06:01 millert Exp $ .TH TERMINFO 5 "" "" "File Formats" .ds n 5 .ds d /usr/share/terminfo @@ -1623,7 +1623,7 @@ YI Set page length to #1 hundredth of an inch T} .TE .ad -.\" $From: terminfo.tail,v 1.29 1999/03/07 02:09:07 tom Exp $ +.\" $From: terminfo.tail,v 1.30 2000/01/08 22:09:12 tom Exp $ .\" Beginning of terminfo.tail file .ps +1 .PP @@ -3050,10 +3050,6 @@ of terminfo (under HP-UX and AIX) which diverged from System V terminfo after SVr1, and have added extension capabilities to the string table that (in the binary format) collide with System V and XSI Curses extensions. .SH EXTENSIONS -The %x operator in parameterized strings is unique to the ncurses implementation -of \fBtparm\fR (it is required in order to support an unfortunate choice of -\fBinitc\fR format on the Linux console). -.PP Some SVr4 \fBcurses\fR implementations, and all previous to SVr4, don't interpret the %A and %O operators in parameter strings. .PP diff --git a/lib/libcurses/tinfo/lib_raw.c b/lib/libcurses/tinfo/lib_raw.c index c84fcde44de..59452bf0517 100644 --- a/lib/libcurses/tinfo/lib_raw.c +++ b/lib/libcurses/tinfo/lib_raw.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_raw.c,v 1.3 1999/12/28 15:57:59 millert Exp $ */ +/* $OpenBSD: lib_raw.c,v 1.4 2000/01/09 05:06:02 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 * @@ -50,7 +50,7 @@ #include <curses.priv.h> #include <term.h> /* cur_term */ -MODULE_ID("$From: lib_raw.c,v 1.5 1999/12/19 01:57:23 tom Exp $") +MODULE_ID("$From: lib_raw.c,v 1.6 2000/01/08 17:28:48 tom Exp $") #if defined(SVR4_TERMIO) && !defined(_POSIX_SOURCE) #define _POSIX_SOURCE @@ -62,7 +62,6 @@ MODULE_ID("$From: lib_raw.c,v 1.5 1999/12/19 01:57:23 tom Exp $") #ifdef __EMX__ #include <io.h> -#include <fcntl.h> #endif #define COOKED_INPUT (IXON|BRKINT|PARMRK) @@ -218,12 +217,11 @@ intrflush(WINDOW *win GCC_UNUSED, bool flag) T((T_CALLED("intrflush(%d)"), flag)); /* - * 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. + * 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. */ #ifdef TERMIOS diff --git a/lib/libcurses/tinfo/read_entry.c b/lib/libcurses/tinfo/read_entry.c index 59e791ebcca..deb6601e8f8 100644 --- a/lib/libcurses/tinfo/read_entry.c +++ b/lib/libcurses/tinfo/read_entry.c @@ -1,4 +1,4 @@ -/* $OpenBSD: read_entry.c,v 1.6 2000/01/02 22:06:51 millert Exp $ */ +/* $OpenBSD: read_entry.c,v 1.7 2000/01/09 05:06:02 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998-2000 Free Software Foundation, Inc. * @@ -40,23 +40,13 @@ #include <curses.priv.h> -#if HAVE_FCNTL_H -#include <fcntl.h> -#endif - #include <tic.h> #include <term_entry.h> -MODULE_ID("$From: read_entry.c,v 1.63 2000/01/01 23:06:40 tom Exp $") - -#ifndef O_BINARY -#define O_BINARY 0 -#endif +MODULE_ID("$From: read_entry.c,v 1.65 2000/01/08 18:59:49 tom Exp $") -#if 0 -#define TRACE_IN(p) DEBUG(2, p) -#else -#define TRACE_IN(p) /*nothing */ +#if !HAVE_TELL +#define tell(fd) 0 /* lseek() is POSIX, but not tell() - odd... */ #endif /* @@ -123,7 +113,7 @@ convert_shorts(char *buf, short *Numbers, int count) Numbers[i] = CANCELLED_NUMERIC; else Numbers[i] = LOW_MSB(buf + 2 * i); - TRACE_IN(("get Numbers[%d]=%d", i, Numbers[i])); + TR(TRACE_DATABASE, ("get Numbers[%d]=%d", i, Numbers[i])); } } @@ -142,7 +132,7 @@ convert_strings(char *buf, char **Strings, int count, int size, char *table) Strings[i] = ABSENT_STRING; } else { Strings[i] = (LOW_MSB(buf + 2 * i) + table); - TRACE_IN(("Strings[%d] = %s", i, _nc_visbuf(Strings[i]))); + TR(TRACE_DATABASE, ("Strings[%d] = %s", i, _nc_visbuf(Strings[i]))); } /* make sure all strings are NUL terminated */ @@ -170,7 +160,7 @@ read_termtype(int fd, TERMTYPE * ptr) int i; char buf[MAX_ENTRY_SIZE]; - TRACE_IN(("READ termtype header @%d", tell(fd))); + TR(TRACE_DATABASE, ("READ termtype header @%d", tell(fd))); memset(ptr, 0, sizeof(*ptr)); @@ -187,8 +177,10 @@ read_termtype(int fd, TERMTYPE * ptr) 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)); + TR(TRACE_DATABASE, + ("TERMTYPE name_size=%d, bool=%d/%d, num=%d/%d str=%d/%d(%d)", + name_size, bool_count, BOOLCOUNT, num_count, NUMCOUNT, + str_count, STRCOUNT, str_size)); if (name_size < 0 || bool_count < 0 || num_count < 0 @@ -262,7 +254,7 @@ read_termtype(int fd, TERMTYPE * ptr) * Read extended entries, if any, after the normal end of terminfo data. */ even_boundary(str_size); - TRACE_IN(("READ extended_header @%d", tell(fd))); + TR(TRACE_DATABASE, ("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); @@ -290,60 +282,67 @@ read_termtype(int fd, TERMTYPE * ptr) ptr->Numbers = typeRealloc(short, ptr->num_Numbers, ptr->Numbers); 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)); + TR(TRACE_DATABASE, ("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))); + TR(TRACE_DATABASE, ("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) + 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))); + TR(TRACE_DATABASE, ("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); - TRACE_IN(("Before converting extended-numbers")); + TR(TRACE_DATABASE, ("Before converting extended-numbers")); convert_shorts(buf, ptr->Numbers + NUMCOUNT, ext_num_count); } - TRACE_IN(("READ extended-offsets @%d", tell(fd))); + TR(TRACE_DATABASE, ("READ extended-offsets @%d", tell(fd))); if ((ext_str_count || need) && !read_shorts(fd, buf, ext_str_count + need)) return (0); - TRACE_IN(("READ %d bytes of extended-strings @%d", ext_str_limit, - tell(fd))); + TR(TRACE_DATABASE, ("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); if (read(fd, ptr->ext_str_table, ext_str_limit) != ext_str_limit) return (0); - TRACE_IN(("first extended-string is %s", _nc_visbuf(ptr->ext_str_table))); + TR(TRACE_DATABASE, ("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", + TR(TRACE_DATABASE, + ("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, + TR(TRACE_DATABASE, ("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]))); + TR(TRACE_DATABASE, ("... 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", + TR(TRACE_DATABASE, + ("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); @@ -354,15 +353,13 @@ read_termtype(int fd, TERMTYPE * ptr) ptr->num_Numbers, ptr->ext_Numbers, ptr->num_Strings, ptr->ext_Strings)); - TRACE_IN(("extend: num_Booleans:%d", ptr->num_Booleans)); + TR(TRACE_DATABASE, ("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)); - TRACE_IN(("normal: num_Booleans:%d", ptr->num_Booleans)); + bool_count, num_count, str_count)); + TR(TRACE_DATABASE, ("normal: num_Booleans:%d", ptr->num_Booleans)); } for (i = bool_count; i < BOOLCOUNT; i++) diff --git a/lib/libcurses/tinfo/read_termcap.c b/lib/libcurses/tinfo/read_termcap.c index ab9513d5965..9f73a03b77f 100644 --- a/lib/libcurses/tinfo/read_termcap.c +++ b/lib/libcurses/tinfo/read_termcap.c @@ -1,7 +1,7 @@ -/* $OpenBSD: read_termcap.c,v 1.3 1999/05/08 20:29:02 millert Exp $ */ +/* $OpenBSD: read_termcap.c,v 1.4 2000/01/09 05:06:02 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> * ****************************************************************************/ - /* * Termcap compatibility support * @@ -58,11 +57,7 @@ #include <tic.h> #include <term_entry.h> -#if HAVE_FCNTL_H -#include <fcntl.h> -#endif - -MODULE_ID("$From: read_termcap.c,v 1.43 1999/04/10 20:52:52 tom Exp $") +MODULE_ID("$From: read_termcap.c,v 1.44 2000/01/08 17:27:31 tom Exp $") #ifndef PURE_TERMINFO @@ -88,7 +83,7 @@ MODULE_ID("$From: read_termcap.c,v 1.43 1999/04/10 20:52:52 tom Exp $") #define _nc_cgetset cgetset #else static int _nc_cgetmatch(char *, const char *); -static int _nc_getent(char **, unsigned int *, int *, int, char **, int, const char *, int, char *); +static int _nc_getent(char **, unsigned *, int *, int, char **, int, const char *, int, char *); static int _nc_nfcmp(const char *, char *); /*- @@ -132,16 +127,16 @@ static int _nc_nfcmp(const char *, char *); #define BFRAG 1024 #define BSIZE 1024 #define ESC ('[' & 037) /* ASCII ESC */ -#define MAX_RECURSION 32 /* maximum getent recursion */ -#define SFRAG 100 /* cgetstr mallocs in SFRAG chunks */ +#define MAX_RECURSION 32 /* maximum getent recursion */ +#define SFRAG 100 /* cgetstr mallocs in SFRAG chunks */ #define RECOK (char)0 #define TCERR (char)1 #define SHADOW (char)2 -static size_t topreclen; /* toprec length */ -static char *toprec; /* Additional record specified by cgetset() */ -static int gottoprec; /* Flag indicating retrieval of toprecord */ +static size_t topreclen; /* toprec length */ +static char *toprec; /* Additional record specified by cgetset() */ +static int gottoprec; /* Flag indicating retrieval of toprecord */ /* * Cgetset() allows the addition of a user specified buffer to be added to the @@ -151,20 +146,20 @@ static int gottoprec; /* Flag indicating retrieval of toprecord */ static int _nc_cgetset(const char *ent) { - if (ent == 0) { - FreeIfNeeded(toprec); - toprec = 0; - topreclen = 0; - return (0); - } - topreclen = strlen(ent); - if ((toprec = typeMalloc(char, topreclen + 1)) == 0) { - errno = ENOMEM; - return (-1); - } - gottoprec = 0; - (void)strcpy(toprec, ent); + if (ent == 0) { + FreeIfNeeded(toprec); + toprec = 0; + topreclen = 0; return (0); + } + topreclen = strlen(ent); + if ((toprec = typeMalloc(char, topreclen + 1)) == 0) { + errno = ENOMEM; + return (-1); + } + gottoprec = 0; + (void) strcpy(toprec, ent); + return (0); } /* @@ -182,43 +177,43 @@ _nc_cgetset(const char *ent) static char * _nc_cgetcap(char *buf, const char *cap, int type) { - register const char *cp; - register char *bp; + register const char *cp; + register char *bp; - bp = buf; + bp = buf; + for (;;) { + /* + * Skip past the current capability field - it's either the + * name field if this is the first time through the loop, or + * the remainder of a field whose name failed to match cap. + */ for (;;) { - /* - * Skip past the current capability field - it's either the - * name field if this is the first time through the loop, or - * the remainder of a field whose name failed to match cap. - */ - for (;;) { - if (*bp == '\0') - return (0); - else if (*bp++ == ':') - break; - } + if (*bp == '\0') + return (0); + else if (*bp++ == ':') + break; + } - /* - * Try to match (cap, type) in buf. - */ - for (cp = cap; *cp == *bp && *bp != '\0'; cp++, bp++) - continue; - if (*cp != '\0') - continue; - if (*bp == '@') - return (0); - if (type == ':') { - if (*bp != '\0' && *bp != ':') - continue; - return(bp); - } - if (*bp != type) - continue; - bp++; - return (*bp == '@' ? 0 : bp); + /* + * Try to match (cap, type) in buf. + */ + for (cp = cap; *cp == *bp && *bp != '\0'; cp++, bp++) + continue; + if (*cp != '\0') + continue; + if (*bp == '@') + return (0); + if (type == ':') { + if (*bp != '\0' && *bp != ':') + continue; + return (bp); } - /* NOTREACHED */ + if (*bp != type) + continue; + bp++; + return (*bp == '@' ? 0 : bp); + } + /* NOTREACHED */ } /* @@ -238,9 +233,9 @@ _nc_cgetcap(char *buf, const char *cap, int type) static int _nc_cgetent(char **buf, int *oline, char **db_array, const char *name) { - unsigned int dummy; + unsigned dummy; - return (_nc_getent(buf, &dummy, oline, 0, db_array, -1, name, 0, 0)); + return (_nc_getent(buf, &dummy, oline, 0, db_array, -1, name, 0, 0)); } /* @@ -264,327 +259,327 @@ _nc_cgetent(char **buf, int *oline, char **db_array, const char *name) #define DOALLOC(size) typeRealloc(char, size, record) static int _nc_getent( - char **cap, /* termcap-content */ - unsigned int *len, /* length, needed for recursion */ - int *beginning, /* line-number at match */ - int in_array, /* index in 'db_array[] */ - char **db_array, /* list of files to search */ - int fd, - const char *name, - int depth, - char *nfield) + char **cap, /* termcap-content */ + unsigned *len, /* length, needed for recursion */ + int *beginning, /* line-number at match */ + int in_array, /* index in 'db_array[] */ + char **db_array, /* list of files to search */ + int fd, + const char *name, + int depth, + char *nfield) { - register char *r_end, *rp; - int myfd = FALSE; - char *record = 0; - int tc_not_resolved; - int current; - int lineno; - - /* - * Return with ``loop detected'' error if we've recurred more than - * MAX_RECURSION times. - */ - if (depth > MAX_RECURSION) - return (TC_REF_LOOP); + register char *r_end, *rp; + int myfd = FALSE; + char *record = 0; + int tc_not_resolved; + int current; + int lineno; + + /* + * Return with ``loop detected'' error if we've recurred more than + * MAX_RECURSION times. + */ + if (depth > MAX_RECURSION) + return (TC_REF_LOOP); + + /* + * Check if we have a top record from cgetset(). + */ + if (depth == 0 && toprec != 0 && _nc_cgetmatch(toprec, name) == 0) { + if ((record = DOALLOC(topreclen + BFRAG)) == 0) { + errno = ENOMEM; + return (TC_SYS_ERR); + } + (void) strcpy(record, toprec); + rp = record + topreclen + 1; + r_end = rp + BFRAG; + current = in_array; + } else { + int foundit; /* - * Check if we have a top record from cgetset(). + * Allocate first chunk of memory. */ - if (depth == 0 && toprec != 0 && _nc_cgetmatch(toprec, name) == 0) { - if ((record = DOALLOC(topreclen + BFRAG)) == 0) { - errno = ENOMEM; - return (TC_SYS_ERR); - } - (void)strcpy(record, toprec); - rp = record + topreclen + 1; - r_end = rp + BFRAG; - current = in_array; - } else { - int foundit; - - /* - * Allocate first chunk of memory. - */ - if ((record = DOALLOC(BFRAG)) == 0) { - errno = ENOMEM; - return (TC_SYS_ERR); - } - rp = r_end = record + BFRAG; - foundit = FALSE; - - /* - * Loop through database array until finding the record. - */ - for (current = in_array; db_array[current] != 0; current++) { - int eof = FALSE; - - /* - * Open database if not already open. - */ - if (fd >= 0) { - (void)lseek(fd, (off_t)0, SEEK_SET); - } else if ((_nc_access(db_array[current], R_OK) < 0) - || (fd = open(db_array[current], O_RDONLY, 0)) < 0) { - /* No error on unfound file. */ - if (errno == ENOENT) - continue; - free(record); - return (TC_SYS_ERR); - } else { - myfd = TRUE; - } - lineno = 0; - - /* - * Find the requested capability record ... - */ - { - char buf[2048]; - register char *b_end = buf; - register char *bp = buf; - register int c; - - /* - * Loop invariants: - * There is always room for one more character in record. - * R_end always points just past end of record. - * Rp always points just past last character in record. - * B_end always points just past last character in buf. - * Bp always points at next character in buf. - */ - - for (;;) { - int first = lineno + 1; - - /* - * Read in a line implementing (\, newline) - * line continuation. - */ - rp = record; - for (;;) { - if (bp >= b_end) { - int n; - - n = read(fd, buf, sizeof(buf)); - if (n <= 0) { - if (myfd) - (void)close(fd); - if (n < 0) { - free(record); - return (TC_SYS_ERR); - } - fd = -1; - eof = TRUE; - break; - } - b_end = buf+n; - bp = buf; - } - - c = *bp++; - if (c == '\n') { - lineno++; - if (rp == record || *(rp-1) != '\\') - break; - } - *rp++ = c; - - /* - * Enforce loop invariant: if no room - * left in record buffer, try to get - * some more. - */ - if (rp >= r_end) { - unsigned int pos; - size_t newsize; - - pos = rp - record; - newsize = r_end - record + BFRAG; - record = DOALLOC(newsize); - if (record == 0) { - if (myfd) - (void)close(fd); - errno = ENOMEM; - return (TC_SYS_ERR); - } - r_end = record + newsize; - rp = record + pos; - } - } - /* loop invariant lets us do this */ - *rp++ = '\0'; - - /* - * If encountered eof check next file. - */ - if (eof) - break; - - /* - * Toss blank lines and comments. - */ - if (*record == '\0' || *record == '#') - continue; - - /* - * See if this is the record we want ... - */ - if (_nc_cgetmatch(record, name) == 0 - && (nfield == 0 - || !_nc_nfcmp(nfield, record))) { - foundit = TRUE; - *beginning = first; - break; /* found it! */ - } - } - } - if (foundit) - break; - } - - if (!foundit) - return (TC_NOT_FOUND); + if ((record = DOALLOC(BFRAG)) == 0) { + errno = ENOMEM; + return (TC_SYS_ERR); } + rp = r_end = record + BFRAG; + foundit = FALSE; /* - * Got the capability record, but now we have to expand all tc=name - * references in it ... + * Loop through database array until finding the record. */ - { - register char *newicap, *s; - register int newilen; - unsigned int ilen; - int diff, iret, tclen, oline; - char *icap, *scan, *tc, *tcstart, *tcend; + for (current = in_array; db_array[current] != 0; current++) { + int eof = FALSE; + + /* + * Open database if not already open. + */ + if (fd >= 0) { + (void) lseek(fd, (off_t) 0, SEEK_SET); + } else if ((_nc_access(db_array[current], R_OK) < 0) + || (fd = open(db_array[current], O_RDONLY, 0)) < 0) { + /* No error on unfound file. */ + if (errno == ENOENT) + continue; + free(record); + return (TC_SYS_ERR); + } else { + myfd = TRUE; + } + lineno = 0; + + /* + * Find the requested capability record ... + */ + { + char buf[2048]; + register char *b_end = buf; + register char *bp = buf; + register int c; /* * Loop invariants: - * There is room for one more character in record. - * R_end points just past end of record. - * Rp points just past last character in record. - * Scan points at remainder of record that needs to be - * scanned for tc=name constructs. + * There is always room for one more character in record. + * R_end always points just past end of record. + * Rp always points just past last character in record. + * B_end always points just past last character in buf. + * Bp always points at next character in buf. */ - scan = record; - tc_not_resolved = FALSE; - for (;;) { - if ((tc = _nc_cgetcap(scan, "tc", '=')) == 0) - break; - /* - * Find end of tc=name and stomp on the trailing `:' - * (if present) so we can use it to call ourselves. - */ - s = tc; - while (*s != '\0') { - if (*s++ == ':') { - *(s - 1) = '\0'; - break; - } - } - tcstart = tc - 3; - tclen = s - tcstart; - tcend = s; - - iret = _nc_getent(&icap, &ilen, &oline, current, db_array, fd, tc, depth+1, 0); - newicap = icap; /* Put into a register. */ - newilen = ilen; - if (iret != TC_SUCCESS) { - /* an error */ - if (iret < TC_NOT_FOUND) { - if (myfd) - (void)close(fd); - free(record); - return (iret); - } - if (iret == TC_UNRESOLVED) - tc_not_resolved = TRUE; - /* couldn't resolve tc */ - if (iret == TC_NOT_FOUND) { - *(s - 1) = ':'; - scan = s - 1; - tc_not_resolved = TRUE; - continue; + for (;;) { + int first = lineno + 1; + + /* + * Read in a line implementing (\, newline) + * line continuation. + */ + rp = record; + for (;;) { + if (bp >= b_end) { + int n; + + n = read(fd, buf, sizeof(buf)); + if (n <= 0) { + if (myfd) + (void) close(fd); + if (n < 0) { + free(record); + return (TC_SYS_ERR); } + fd = -1; + eof = TRUE; + break; + } + b_end = buf + n; + bp = buf; } - /* not interested in name field of tc'ed record */ - s = newicap; - while (*s != '\0' && *s++ != ':') - ; - newilen -= s - newicap; - newicap = s; - - /* make sure interpolated record is `:'-terminated */ - s += newilen; - if (*(s-1) != ':') { - *s = ':'; /* overwrite NUL with : */ - newilen++; + c = *bp++; + if (c == '\n') { + lineno++; + if (rp == record || *(rp - 1) != '\\') + break; } + *rp++ = c; /* - * Make sure there's enough room to insert the - * new record. + * Enforce loop invariant: if no room + * left in record buffer, try to get + * some more. */ - diff = newilen - tclen; - if (diff >= r_end - rp) { - unsigned int pos, tcpos, tcposend; - size_t newsize; - - pos = rp - record; - newsize = r_end - record + diff + BFRAG; - tcpos = tcstart - record; - tcposend = tcend - record; - record = DOALLOC(newsize); - if (record == 0) { - if (myfd) - (void)close(fd); - free(icap); - errno = ENOMEM; - return (TC_SYS_ERR); - } - r_end = record + newsize; - rp = record + pos; - tcstart = record + tcpos; - tcend = record + tcposend; + if (rp >= r_end) { + unsigned pos; + size_t newsize; + + pos = rp - record; + newsize = r_end - record + BFRAG; + record = DOALLOC(newsize); + if (record == 0) { + if (myfd) + (void) close(fd); + errno = ENOMEM; + return (TC_SYS_ERR); + } + r_end = record + newsize; + rp = record + pos; } + } + /* loop invariant lets us do this */ + *rp++ = '\0'; + + /* + * If encountered eof check next file. + */ + if (eof) + break; - /* - * Insert tc'ed record into our record. - */ - s = tcstart + newilen; - memmove(s, tcend, (size_t)(rp - tcend)); - memmove(tcstart, newicap, (size_t)newilen); - rp += diff; - free(icap); + /* + * Toss blank lines and comments. + */ + if (*record == '\0' || *record == '#') + continue; - /* - * Start scan on `:' so next cgetcap works properly - * (cgetcap always skips first field). - */ - scan = s-1; + /* + * See if this is the record we want ... + */ + if (_nc_cgetmatch(record, name) == 0 + && (nfield == 0 + || !_nc_nfcmp(nfield, record))) { + foundit = TRUE; + *beginning = first; + break; /* found it! */ + } } + } + if (foundit) + break; } + if (!foundit) + return (TC_NOT_FOUND); + } + + /* + * Got the capability record, but now we have to expand all tc=name + * references in it ... + */ + { + register char *newicap, *s; + register int newilen; + unsigned ilen; + int diff, iret, tclen, oline; + char *icap, *scan, *tc, *tcstart, *tcend; + /* - * Close file (if we opened it), give back any extra memory, and - * return capability, length and success. + * Loop invariants: + * There is room for one more character in record. + * R_end points just past end of record. + * Rp points just past last character in record. + * Scan points at remainder of record that needs to be + * scanned for tc=name constructs. */ - if (myfd) - (void)close(fd); - *len = rp - record - 1; /* don't count NUL */ - if (r_end > rp) { - if ((record = DOALLOC((size_t)(rp - record))) == 0) { - errno = ENOMEM; - return (TC_SYS_ERR); + scan = record; + tc_not_resolved = FALSE; + for (;;) { + if ((tc = _nc_cgetcap(scan, "tc", '=')) == 0) + break; + + /* + * Find end of tc=name and stomp on the trailing `:' + * (if present) so we can use it to call ourselves. + */ + s = tc; + while (*s != '\0') { + if (*s++ == ':') { + *(s - 1) = '\0'; + break; + } + } + tcstart = tc - 3; + tclen = s - tcstart; + tcend = s; + + iret = _nc_getent(&icap, &ilen, &oline, current, db_array, fd, + tc, depth + 1, 0); + newicap = icap; /* Put into a register. */ + newilen = ilen; + if (iret != TC_SUCCESS) { + /* an error */ + if (iret < TC_NOT_FOUND) { + if (myfd) + (void) close(fd); + free(record); + return (iret); } + if (iret == TC_UNRESOLVED) + tc_not_resolved = TRUE; + /* couldn't resolve tc */ + if (iret == TC_NOT_FOUND) { + *(s - 1) = ':'; + scan = s - 1; + tc_not_resolved = TRUE; + continue; + } + } + + /* not interested in name field of tc'ed record */ + s = newicap; + while (*s != '\0' && *s++ != ':') ; + newilen -= s - newicap; + newicap = s; + + /* make sure interpolated record is `:'-terminated */ + s += newilen; + if (*(s - 1) != ':') { + *s = ':'; /* overwrite NUL with : */ + newilen++; + } + + /* + * Make sure there's enough room to insert the + * new record. + */ + diff = newilen - tclen; + if (diff >= r_end - rp) { + unsigned pos, tcpos, tcposend; + size_t newsize; + + pos = rp - record; + newsize = r_end - record + diff + BFRAG; + tcpos = tcstart - record; + tcposend = tcend - record; + record = DOALLOC(newsize); + if (record == 0) { + if (myfd) + (void) close(fd); + free(icap); + errno = ENOMEM; + return (TC_SYS_ERR); + } + r_end = record + newsize; + rp = record + pos; + tcstart = record + tcpos; + tcend = record + tcposend; + } + + /* + * Insert tc'ed record into our record. + */ + s = tcstart + newilen; + memmove(s, tcend, (size_t) (rp - tcend)); + memmove(tcstart, newicap, (size_t) newilen); + rp += diff; + free(icap); + + /* + * Start scan on `:' so next cgetcap works properly + * (cgetcap always skips first field). + */ + scan = s - 1; + } + } + + /* + * Close file (if we opened it), give back any extra memory, and + * return capability, length and success. + */ + if (myfd) + (void) close(fd); + *len = rp - record - 1; /* don't count NUL */ + if (r_end > rp) { + if ((record = DOALLOC((size_t) (rp - record))) == 0) { + errno = ENOMEM; + return (TC_SYS_ERR); } + } - *cap = record; - if (tc_not_resolved) - return (TC_UNRESOLVED); - return (current); + *cap = record; + if (tc_not_resolved) + return (TC_UNRESOLVED); + return (current); } /* @@ -594,40 +589,40 @@ _nc_getent( static int _nc_cgetmatch(char *buf, const char *name) { - register const char *np; - register char *bp; - + register const char *np; + register char *bp; + + /* + * Start search at beginning of record. + */ + bp = buf; + for (;;) { /* - * Start search at beginning of record. + * Try to match a record name. */ - bp = buf; + np = name; for (;;) { - /* - * Try to match a record name. - */ - np = name; - for (;;) { - if (*np == '\0') { - if (*bp == '|' || *bp == ':' || *bp == '\0') - return (0); - else - break; - } else if (*bp++ != *np++) { - break; - } - } + if (*np == '\0') { + if (*bp == '|' || *bp == ':' || *bp == '\0') + return (0); + else + break; + } else if (*bp++ != *np++) { + break; + } + } - /* - * Match failed, skip to next name in record. - */ - bp--; /* a '|' or ':' may have stopped the match */ - for (;;) { - if (*bp == '\0' || *bp == ':') - return (-1); /* match failed totally */ - else if (*bp++ == '|') - break; /* found next name */ - } + /* + * Match failed, skip to next name in record. + */ + bp--; /* a '|' or ':' may have stopped the match */ + for (;;) { + if (*bp == '\0' || *bp == ':') + return (-1); /* match failed totally */ + else if (*bp++ == '|') + break; /* found next name */ } + } } /* @@ -636,18 +631,17 @@ _nc_cgetmatch(char *buf, const char *name) static int _nc_nfcmp(const char *nf, char *rec) { - char *cp, tmp; - int ret; + char *cp, tmp; + int ret; - for (cp = rec; *cp != ':'; cp++) - ; + for (cp = rec; *cp != ':'; cp++) ; - tmp = *(cp + 1); - *(cp + 1) = '\0'; - ret = strcmp(nf, rec); - *(cp + 1) = tmp; + tmp = *(cp + 1); + *(cp + 1) = '\0'; + ret = strcmp(nf, rec); + *(cp + 1) = tmp; - return (ret); + return (ret); } #endif /* HAVE_BSD_CGETENT */ @@ -708,63 +702,63 @@ static char *tbuf; static char * get_tc_token(char **srcp, int *endp) { - int ch; - bool found = FALSE; - char *s, *base; - char *tok = 0; - - *endp = TRUE; - for (s = base = *srcp; *s != '\0'; ) { - ch = *s++; - if (ch == '\\') { - if (*s == '\0') { - break; - } else if (*s++ == '\n') { - while (isspace(*s)) - s++; - } else { - found = TRUE; - } - } else if (ch == ':') { - if (found) { - tok = base; - s[-1] = '\0'; - *srcp = s; - *endp = FALSE; - break; - } - base = s; - } else if (isgraph(ch)) { - found = TRUE; - } - } - - /* malformed entry may end without a ':' */ - if (tok == 0 && found) { + int ch; + bool found = FALSE; + char *s, *base; + char *tok = 0; + + *endp = TRUE; + for (s = base = *srcp; *s != '\0';) { + ch = *s++; + if (ch == '\\') { + if (*s == '\0') { + break; + } else if (*s++ == '\n') { + while (isspace(*s)) + s++; + } else { + found = TRUE; + } + } else if (ch == ':') { + if (found) { tok = base; + s[-1] = '\0'; + *srcp = s; + *endp = FALSE; + break; + } + base = s; + } else if (isgraph(ch)) { + found = TRUE; } + } + + /* malformed entry may end without a ':' */ + if (tok == 0 && found) { + tok = base; + } - return tok; + return tok; } static char * copy_tc_token(char *dst, const char *src, size_t len) { - int ch; + int ch; - while ((ch = *src++) != '\0') { - if (ch == '\\' && *src == '\n') { - while (isspace(*src)) - src++; - continue; - } - if (--len == 0) { - dst = 0; - break; - } - *dst++ = ch; + while ((ch = *src++) != '\0') { + if (ch == '\\' && *src == '\n') { + while (isspace(*src)) + src++; + continue; + } + if (--len == 0) { + dst = 0; + break; } - return dst; + *dst++ = ch; + } + return dst; } /* @@ -773,129 +767,128 @@ copy_tc_token(char *dst, const char *src, size_t len) static int _nc_tgetent(char *bp, char **sourcename, int *lineno, const char *name) { - static char *the_source; - - register char *p; - register char *cp; - char *dummy; - char **fname; - char *home; - int i; - char pathbuf[PBUFSIZ]; /* holds raw path of filenames */ - char *pathvec[PVECSIZ]; /* to point to names in pathbuf */ - char **pvec; /* holds usable tail of path vector */ - char *termpath; - - fname = pathvec; - pvec = pathvec; - tbuf = bp; - p = pathbuf; - cp = getenv("TERMCAP"); - - /* - * TERMCAP can have one of two things in it. It can be the name of a - * file to use instead of /etc/termcap. In this case it better start - * with a "/". Or it can be an entry to use so we don't have to read - * the file. In this case it has to already have the newlines crunched - * out. If TERMCAP does not hold a file name then a path of names is - * searched instead. The path is found in the TERMPATH variable, or - * becomes "$HOME/.termcap /etc/termcap" if no TERMPATH exists. - */ + static char *the_source; + + register char *p; + register char *cp; + char *dummy; + char **fname; + char *home; + int i; + char pathbuf[PBUFSIZ]; /* holds raw path of filenames */ + char *pathvec[PVECSIZ]; /* to point to names in pathbuf */ + char **pvec; /* holds usable tail of path vector */ + char *termpath; + + fname = pathvec; + pvec = pathvec; + tbuf = bp; + p = pathbuf; + cp = getenv("TERMCAP"); + + /* + * TERMCAP can have one of two things in it. It can be the name of a file + * to use instead of /etc/termcap. In this case it better start with a + * "/". Or it can be an entry to use so we don't have to read the file. + * In this case it has to already have the newlines crunched out. If + * TERMCAP does not hold a file name then a path of names is searched + * instead. The path is found in the TERMPATH variable, or becomes + * "$HOME/.termcap /etc/termcap" if no TERMPATH exists. + */ #define MY_PATH_DEF "/etc/termcap /usr/share/misc/termcap" - if (issetugid()) - strlcpy(pathbuf, MY_PATH_DEF, PBUFSIZ); - else if (!is_pathname(cp)) { /* no TERMCAP or it holds an entry */ - if ((termpath = getenv("TERMPATH")) != 0) { - strlcpy(pathbuf, termpath, PBUFSIZ); - } else { - if ((home = getenv("HOME")) != 0 && - strlen(home) < PBUFSIZ) { /* setup path */ - p += strlen(home); /* path, looking in */ - strcpy(pathbuf, home); /* $HOME first */ - *p++ = '/'; - } /* if no $HOME look in current directory */ - strlcpy(p, ".termcap " MY_PATH_DEF, - (size_t)(PBUFSIZ - (p - pathbuf))); - } + if (issetugid()) + strlcpy(pathbuf, MY_PATH_DEF, PBUFSIZ); + else if (!is_pathname(cp)) { /* no TERMCAP or it holds an entry */ + if ((termpath = getenv("TERMPATH")) != 0) { + strlcpy(pathbuf, termpath, PBUFSIZ); + } else { + if ((home = getenv("HOME")) != 0 && + strlen(home) < PBUFSIZ) { /* setup path */ + p += strlen(home); /* path, looking in */ + strcpy(pathbuf, home); /* $HOME first */ + *p++ = '/'; + } /* if no $HOME look in current directory */ + strlcpy(p, ".termcap " MY_PATH_DEF, + (size_t) (PBUFSIZ - (p - pathbuf))); } - else /* user-defined name in TERMCAP */ - strlcpy(pathbuf, cp, PBUFSIZ); /* still can be tokenized */ - - *fname++ = pathbuf; /* tokenize path into vector of names */ - while (*++p) { - if (*p == ' ' || *p == ':') { - *p = '\0'; - while (*++p) - if (*p != ' ' && *p != ':') - break; - if (*p == '\0') - break; - *fname++ = p; - if (fname >= pathvec + PVECSIZ) { - fname--; - break; - } - } + } else /* user-defined name in TERMCAP */ + strlcpy(pathbuf, cp, PBUFSIZ); /* still can be tokenized */ + + *fname++ = pathbuf; /* tokenize path into vector of names */ + while (*++p) { + if (*p == ' ' || *p == ':') { + *p = '\0'; + while (*++p) + if (*p != ' ' && *p != ':') + break; + if (*p == '\0') + break; + *fname++ = p; + if (fname >= pathvec + PVECSIZ) { + fname--; + break; + } } - *fname = 0; /* mark end of vector */ - if (is_pathname(cp)) { - if (_nc_cgetset(cp) < 0) { - return(TC_SYS_ERR); - } + } + *fname = 0; /* mark end of vector */ + if (is_pathname(cp)) { + if (_nc_cgetset(cp) < 0) { + return (TC_SYS_ERR); } - - i = _nc_cgetent(&dummy, lineno, pathvec, name); - - /* ncurses' termcap-parsing routines cannot handle multiple adjacent - * empty fields, and mistakenly use the last valid cap entry instead of - * the first (breaks tc= includes) - */ - if (i >= 0) { - char *pd, *ps, *tok; - int endflag = FALSE; - char *list[1023]; - size_t n, count = 0; - - pd = bp; - ps = dummy; - while (!endflag && (tok = get_tc_token(&ps, &endflag)) != 0) { - bool ignore = FALSE; - - for (n = 1; n < count; n++) { - char *s = list[n]; - if (s[0] == tok[0] - && s[1] == tok[1]) { - ignore = TRUE; - break; - } - } - if (ignore != TRUE) { - list[count++] = tok; - pd = copy_tc_token(pd, tok, TBUFSIZ - (2+pd-bp)); - if (pd == 0) { - i = -1; - break; - } - *pd++ = ':'; - *pd = '\0'; - } + } + + i = _nc_cgetent(&dummy, lineno, pathvec, name); + + /* ncurses' termcap-parsing routines cannot handle multiple adjacent + * empty fields, and mistakenly use the last valid cap entry instead of + * the first (breaks tc= includes) + */ + if (i >= 0) { + char *pd, *ps, *tok; + int endflag = FALSE; + char *list[1023]; + size_t n, count = 0; + + pd = bp; + ps = dummy; + while (!endflag && (tok = get_tc_token(&ps, &endflag)) != 0) { + bool ignore = FALSE; + + for (n = 1; n < count; n++) { + char *s = list[n]; + if (s[0] == tok[0] + && s[1] == tok[1]) { + ignore = TRUE; + break; } + } + if (ignore != TRUE) { + list[count++] = tok; + pd = copy_tc_token(pd, tok, TBUFSIZ - (2 + pd - bp)); + if (pd == 0) { + i = -1; + break; + } + *pd++ = ':'; + *pd = '\0'; + } } - - FreeIfNeeded(dummy); - FreeIfNeeded(the_source); - the_source = 0; - - /* This is not related to the BSD cgetent(), but to fake up a suitable - * filename for ncurses' error reporting. (If we are not using BSD - * cgetent, then it is the actual filename). - */ - if (i >= 0) { - if ((the_source = strdup(pathvec[i])) != 0) - *sourcename = the_source; - } - - return(i); + } + + FreeIfNeeded(dummy); + FreeIfNeeded(the_source); + the_source = 0; + + /* This is not related to the BSD cgetent(), but to fake up a suitable + * filename for ncurses' error reporting. (If we are not using BSD + * cgetent, then it is the actual filename). + */ + if (i >= 0) { + if ((the_source = strdup(pathvec[i])) != 0) + *sourcename = the_source; + } + + return (i); } #endif /* USE_BSD_TGETENT */ #endif /* USE_GETCAP */ @@ -907,214 +900,199 @@ _nc_tgetent(char *bp, char **sourcename, int *lineno, const char *name) * a right to open the file. */ #if !USE_GETCAP -static int add_tc(char *termpaths[], char *path, int count) +static int +add_tc(char *termpaths[], char *path, int count) { - if (count < MAXPATHS - && _nc_access(path, R_OK) == 0) - termpaths[count++] = path; - termpaths[count] = 0; - return count; + if (count < MAXPATHS + && _nc_access(path, R_OK) == 0) + termpaths[count++] = path; + termpaths[count] = 0; + return count; } #define ADD_TC(path, count) filecount = add_tc(termpaths, path, count) #endif /* !USE_GETCAP */ -int _nc_read_termcap_entry(const char *const tn, TERMTYPE *const tp) +int +_nc_read_termcap_entry(const char *const tn, TERMTYPE * const tp) { - int found = FALSE; - ENTRY *ep; + int found = FALSE; + ENTRY *ep; #if USE_GETCAP_CACHE - char cwd_buf[PATH_MAX]; + char cwd_buf[PATH_MAX]; #endif #if USE_GETCAP - char tc[TBUFSIZ]; - static char *source; - static int lineno; + char tc[TBUFSIZ]; + static char *source; + static int lineno; - /* we're using getcap(3) */ - if (_nc_tgetent(tc, &source, &lineno, tn) < 0) - return (ERR); + /* we're using getcap(3) */ + if (_nc_tgetent(tc, &source, &lineno, tn) < 0) + return (ERR); - _nc_curr_line = lineno; - _nc_set_source(source); - _nc_read_entry_source((FILE *)0, tc, FALSE, FALSE, NULLHOOK); + _nc_curr_line = lineno; + _nc_set_source(source); + _nc_read_entry_source((FILE *) 0, tc, FALSE, FALSE, NULLHOOK); #else - /* - * Here is what the 4.4BSD termcap(3) page prescribes: - * - * It will look in the environment for a TERMCAP variable. If found, - * and the value does not begin with a slash, and the terminal type - * name is the same as the environment string TERM, the TERMCAP string - * is used instead of reading a termcap file. If it does begin with a - * slash, the string is used as a path name of the termcap file to - * search. If TERMCAP does not begin with a slash and name is - * different from TERM, tgetent() searches the files $HOME/.termcap and - * /usr/share/misc/termcap, in that order, unless the environment - * variable TERMPATH exists, in which case it specifies a list of file - * pathnames (separated by spaces or colons) to be searched instead. - * - * It goes on to state: - * - * Whenever multiple files are searched and a tc field occurs in the - * requested entry, the entry it names must be found in the same file - * or one of the succeeding files. - * - * However, this restriction is relaxed in ncurses; tc references to - * previous files are permitted. - * - * This routine returns 1 if an entry is found, 0 if not found, and -1 - * if the database is not accessible. - */ - FILE *fp; - char *tc, *termpaths[MAXPATHS]; - int filecount = 0; - bool use_buffer = FALSE; - char tc_buf[1024]; - char pathbuf[PATH_MAX]; - - termpaths[filecount] = 0; - if ((tc = getenv("TERMCAP")) != 0 && (!issetugid() || !is_pathname(tc))) - { - if (is_pathname(tc)) /* interpret as a filename */ - { - ADD_TC(tc, 0); - } - else if (_nc_name_match(tc, tn, "|:")) /* treat as a capability file */ - { - use_buffer = TRUE; - (void) sprintf(tc_buf, "%.*s\n", (int)sizeof(tc_buf)-2, tc); - } - else if ((tc = getenv("TERMPATH")) != 0) - { - char *cp; - - for (cp = tc; *cp; cp++) - { - if (*cp == ':') - *cp = '\0'; - else if (cp == tc || cp[-1] == '\0') - { - ADD_TC(cp, filecount); - } - } + /* + * Here is what the 4.4BSD termcap(3) page prescribes: + * + * It will look in the environment for a TERMCAP variable. If found, and + * the value does not begin with a slash, and the terminal type name is the + * same as the environment string TERM, the TERMCAP string is used instead + * of reading a termcap file. If it does begin with a slash, the string is + * used as a path name of the termcap file to search. If TERMCAP does not + * begin with a slash and name is different from TERM, tgetent() searches + * the files $HOME/.termcap and /usr/share/misc/termcap, in that order, + * unless the environment variable TERMPATH exists, in which case it + * specifies a list of file pathnames (separated by spaces or colons) to be + * searched instead. + * + * It goes on to state: + * + * Whenever multiple files are searched and a tc field occurs in the + * requested entry, the entry it names must be found in the same file or + * one of the succeeding files. + * + * However, this restriction is relaxed in ncurses; tc references to + * previous files are permitted. + * + * This routine returns 1 if an entry is found, 0 if not found, and -1 if + * the database is not accessible. + */ + FILE *fp; + char *tc, *termpaths[MAXPATHS]; + int filecount = 0; + bool use_buffer = FALSE; + char tc_buf[1024]; + char pathbuf[PATH_MAX]; + + termpaths[filecount] = 0; + if ((tc = getenv("TERMCAP")) != 0 && (!issetugid() || !is_pathname(tc))) { + if (is_pathname(tc)) { /* interpret as a filename */ + ADD_TC(tc, 0); + } else if (_nc_name_match(tc, tn, "|:")) { /* treat as a capability file */ + use_buffer = TRUE; + (void) sprintf(tc_buf, "%.*s\n", (int) sizeof(tc_buf) - 2, tc); + } else if ((tc = getenv("TERMPATH")) != 0) { + char *cp; + + for (cp = tc; *cp; cp++) { + if (*cp == ':') + *cp = '\0'; + else if (cp == tc || cp[-1] == '\0') { + ADD_TC(cp, filecount); } + } } - else /* normal case */ - { - char envhome[PATH_MAX], *h; + } else { /* normal case */ + char envhome[PATH_MAX], *h; - filecount = 0; + filecount = 0; - /* - * Probably /etc/termcap is a symlink to /usr/share/misc/termcap. - * Avoid reading the same file twice. - */ - if (_nc_access("/etc/termcap", F_OK) == 0) - ADD_TC("/etc/termcap", filecount); - else - ADD_TC("/usr/share/misc/termcap", filecount); + /* + * Probably /etc/termcap is a symlink to /usr/share/misc/termcap. + * Avoid reading the same file twice. + */ + if (_nc_access("/etc/termcap", F_OK) == 0) + ADD_TC("/etc/termcap", filecount); + else + ADD_TC("/usr/share/misc/termcap", filecount); #define PRIVATE_CAP "%s/.termcap" - if (!issetugid() && (h = getenv("HOME")) != NULL - && (strlen(h) + sizeof(PRIVATE_CAP)) < PATH_MAX) - { - /* user's .termcap, if any, should override it */ - (void) strcpy(envhome, h); - (void) sprintf(pathbuf, PRIVATE_CAP, envhome); - ADD_TC(pathbuf, filecount); - } + if (!issetugid() && (h = getenv("HOME")) != NULL + && (strlen(h) + sizeof(PRIVATE_CAP)) < PATH_MAX) { + /* user's .termcap, if any, should override it */ + (void) strcpy(envhome, h); + (void) sprintf(pathbuf, PRIVATE_CAP, envhome); + ADD_TC(pathbuf, filecount); } + } - /* parse the sources */ - if (use_buffer) - { - _nc_set_source("TERMCAP"); + /* parse the sources */ + if (use_buffer) { + _nc_set_source("TERMCAP"); - /* - * We don't suppress warning messages here. The presumption is - * that since it's just a single entry, they won't be a pain. - */ - _nc_read_entry_source((FILE *)0, tc_buf, FALSE, FALSE, NULLHOOK); - } else { - int i; + /* + * We don't suppress warning messages here. The presumption is + * that since it's just a single entry, they won't be a pain. + */ + _nc_read_entry_source((FILE *) 0, tc_buf, FALSE, FALSE, NULLHOOK); + } else { + int i; - for (i = 0; i < filecount; i++) { + for (i = 0; i < filecount; i++) { - T(("Looking for %s in %s", tn, termpaths[i])); - if ((fp = fopen(termpaths[i], "r")) != (FILE *)0) - { - _nc_set_source(termpaths[i]); + T(("Looking for %s in %s", tn, termpaths[i])); + if ((fp = fopen(termpaths[i], "r")) != (FILE *) 0) { + _nc_set_source(termpaths[i]); - /* - * Suppress warning messages. Otherwise you - * get 400 lines of crap from archaic termcap - * files as ncurses complains about all the - * obsolete capabilities. - */ - _nc_read_entry_source(fp, (char*)0, FALSE, TRUE, NULLHOOK); + /* + * Suppress warning messages. Otherwise you get 400 lines of + * crap from archaic termcap files as ncurses complains about + * all the obsolete capabilities. + */ + _nc_read_entry_source(fp, (char *) 0, FALSE, TRUE, NULLHOOK); - (void) fclose(fp); - } - } + (void) fclose(fp); + } } + } #endif /* USE_GETCAP */ - if (_nc_head == 0) - return(ERR); + if (_nc_head == 0) + return (ERR); - /* resolve all use references */ - _nc_resolve_uses(); + /* resolve all use references */ + _nc_resolve_uses(); - /* find a terminal matching tn, if we can */ + /* find a terminal matching tn, if we can */ #if USE_GETCAP_CACHE - if (getcwd(cwd_buf, sizeof(cwd_buf)) != 0) - { - _nc_set_writedir((char *)0); /* note: this does a chdir */ + if (getcwd(cwd_buf, sizeof(cwd_buf)) != 0) { + _nc_set_writedir((char *) 0); /* note: this does a chdir */ #endif - for_entry_list(ep) { - if (_nc_name_match(ep->tterm.term_names, tn, "|:")) - { - /* - * Make a local copy of the terminal - * capabilities. Free all entry storage except - * the string table for the loaded type (which - * we disconnected from the list by NULLing out - * ep->tterm.str_table above). - */ - *tp = ep->tterm; - ep->tterm.str_table = (char *)0; - - /* - * OK, now try to write the type to user's - * terminfo directory. Next time he loads - * this, it will come through terminfo. - * - * Advantage: Second and subsequent fetches of - * this entry will be very fast. - * - * Disadvantage: After the first time a - * termcap type is loaded by its user, editing - * it in the /etc/termcap file, or in TERMCAP, - * or in a local ~/.termcap, will be - * ineffective unless the terminfo entry is - * explicitly removed. - */ + for_entry_list(ep) { + if (_nc_name_match(ep->tterm.term_names, tn, "|:")) { + /* + * Make a local copy of the terminal capabilities. Free all + * entry storage except the string table for the loaded type + * (which we disconnected from the list by NULLing out + * ep->tterm.str_table above). + */ + *tp = ep->tterm; + ep->tterm.str_table = (char *) 0; + + /* + * OK, now try to write the type to user's terminfo directory. + * Next time he loads this, it will come through terminfo. + * + * Advantage: Second and subsequent fetches of this entry will + * be very fast. + * + * Disadvantage: After the first time a termcap type is loaded + * by its user, editing it in the /etc/termcap file, or in + * TERMCAP, or in a local ~/.termcap, will be ineffective + * unless the terminfo entry is explicitly removed. + */ #if USE_GETCAP_CACHE - (void) _nc_write_entry(tp); + (void) _nc_write_entry(tp); #endif - found = TRUE; - break; - } - } -#if USE_GETCAP_CACHE - chdir(cwd_buf); + found = TRUE; + break; + } } +#if USE_GETCAP_CACHE + chdir(cwd_buf); + } #endif - _nc_free_entries(_nc_head); - return(found); + _nc_free_entries(_nc_head); + return (found); } #else -extern void _nc_read_termcap(void); - void _nc_read_termcap(void) { } -#endif /* PURE_TERMINFO */ +extern void _nc_read_termcap(void); +void +_nc_read_termcap(void) +{ +} +#endif /* PURE_TERMINFO */ diff --git a/lib/libcurses/trace/lib_trace.c b/lib/libcurses/trace/lib_trace.c index fbdf5abf455..70ed577b50d 100644 --- a/lib/libcurses/trace/lib_trace.c +++ b/lib/libcurses/trace/lib_trace.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_trace.c,v 1.2 1999/11/28 17:49:54 millert Exp $ */ +/* $OpenBSD: lib_trace.c,v 1.3 2000/01/09 05:06:02 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 * @@ -40,12 +40,9 @@ #include <curses.priv.h> #include <tic.h> -MODULE_ID("$From: lib_trace.c,v 1.31 1999/10/30 23:00:15 tom Exp $") - #include <ctype.h> -#if HAVE_FCNTL_H -#include <fcntl.h> -#endif + +MODULE_ID("$From: lib_trace.c,v 1.32 2000/01/08 17:37:04 tom Exp $") unsigned _nc_tracing = 0; /* always define this */ @@ -53,150 +50,163 @@ unsigned _nc_tracing = 0; /* always define this */ const char *_nc_tputs_trace = ""; long _nc_outchars = 0; -static FILE * tracefp; /* default to writing to stderr */ +static FILE *tracefp; /* default to writing to stderr */ #endif -void trace(const unsigned int tracelevel GCC_UNUSED) +void +trace(const unsigned int tracelevel GCC_UNUSED) { #ifdef TRACE -static bool been_here = FALSE; -static char my_name[] = "trace"; - - _nc_tracing = tracelevel; - if (! been_here && tracelevel) { - been_here = TRUE; - - if (_nc_access(my_name, W_OK) < 0 - || (tracefp = fopen(my_name, "w")) == 0) { - perror("curses: Can't open 'trace' file: "); - exit(EXIT_FAILURE); - } - /* Try to set line-buffered mode, or (failing that) unbuffered, - * so that the trace-output gets flushed automatically at the - * end of each line. This is useful in case the program dies. - */ -#if HAVE_SETVBUF /* ANSI */ - (void) setvbuf(tracefp, (char *)0, _IOLBF, 0); -#elif HAVE_SETBUF /* POSIX */ - (void) setbuffer(tracefp, (char *)0); -#endif - _tracef("TRACING NCURSES version %s (%d)", - NCURSES_VERSION, NCURSES_VERSION_PATCH); + static bool been_here = FALSE; + static char my_name[] = "trace"; + + _nc_tracing = tracelevel; + if (!been_here && tracelevel) { + been_here = TRUE; + + if (_nc_access(my_name, W_OK) < 0 + || (tracefp = fopen(my_name, "w")) == 0) { + perror("curses: Can't open 'trace' file: "); + exit(EXIT_FAILURE); } + /* Try to set line-buffered mode, or (failing that) unbuffered, + * so that the trace-output gets flushed automatically at the + * end of each line. This is useful in case the program dies. + */ +#if HAVE_SETVBUF /* ANSI */ + (void) setvbuf(tracefp, (char *) 0, _IOLBF, 0); +#elif HAVE_SETBUF /* POSIX */ + (void) setbuffer(tracefp, (char *) 0); +#endif + _tracef("TRACING NCURSES version %s (%d)", + NCURSES_VERSION, NCURSES_VERSION_PATCH); + } #endif } -const char *_nc_visbuf2(int bufnum, const char *buf) +const char * +_nc_visbuf2(int bufnum, const char *buf) /* visibilize a given string */ { -char *vbuf; -char *tp; -int c; - - if (buf == 0) - return("(null)"); - if (buf == CANCELLED_STRING) - return("(cancelled)"); - - tp = vbuf = _nc_trace_buf(bufnum, (strlen(buf) * 4) + 5); - *tp++ = '"'; - while ((c = *buf++) != '\0') { - if (c == '"') { - *tp++ = '\\'; *tp++ = '"'; - } else if (is7bits(c) && (isgraph(c) || c == ' ')) { - *tp++ = c; - } else if (c == '\n') { - *tp++ = '\\'; *tp++ = 'n'; - } else if (c == '\r') { - *tp++ = '\\'; *tp++ = 'r'; - } else if (c == '\b') { - *tp++ = '\\'; *tp++ = 'b'; - } else if (c == '\033') { - *tp++ = '\\'; *tp++ = 'e'; - } else if (is7bits(c) && iscntrl(c)) { - *tp++ = '\\'; *tp++ = '^'; *tp++ = '@' + c; - } else { - sprintf(tp, "\\%03o", c & 0xff); - tp += strlen(tp); - } + char *vbuf; + char *tp; + int c; + + if (buf == 0) + return ("(null)"); + if (buf == CANCELLED_STRING) + return ("(cancelled)"); + + tp = vbuf = _nc_trace_buf(bufnum, (strlen(buf) * 4) + 5); + *tp++ = '"'; + while ((c = *buf++) != '\0') { + if (c == '"') { + *tp++ = '\\'; + *tp++ = '"'; + } else if (is7bits(c) && (isgraph(c) || c == ' ')) { + *tp++ = c; + } else if (c == '\n') { + *tp++ = '\\'; + *tp++ = 'n'; + } else if (c == '\r') { + *tp++ = '\\'; + *tp++ = 'r'; + } else if (c == '\b') { + *tp++ = '\\'; + *tp++ = 'b'; + } else if (c == '\033') { + *tp++ = '\\'; + *tp++ = 'e'; + } else if (is7bits(c) && iscntrl(c)) { + *tp++ = '\\'; + *tp++ = '^'; + *tp++ = '@' + c; + } else { + sprintf(tp, "\\%03o", c & 0xff); + tp += strlen(tp); } - *tp++ = '"'; - *tp++ = '\0'; - return(vbuf); + } + *tp++ = '"'; + *tp++ = '\0'; + return (vbuf); } -const char *_nc_visbuf(const char *buf) +const char * +_nc_visbuf(const char *buf) { - return _nc_visbuf2(0, buf); + return _nc_visbuf2(0, buf); } #ifdef TRACE void -_tracef(const char *fmt, ...) +_tracef(const char *fmt,...) { -static const char Called[] = T_CALLED(""); -static const char Return[] = T_RETURN(""); -static int level; -va_list ap; -bool before = FALSE; -bool after = FALSE; -int doit = _nc_tracing; -int save_err = errno; - - if (strlen(fmt) >= sizeof(Called) - 1) { - if (!strncmp(fmt, Called, sizeof(Called)-1)) { - before = TRUE; - level++; - } else if (!strncmp(fmt, Return, sizeof(Return)-1)) { - after = TRUE; - } - if (before || after) { - if ((level <= 1) - || (doit & TRACE_ICALLS) != 0) - doit &= (TRACE_CALLS|TRACE_CCALLS); - else - doit = 0; - } + static const char Called[] = T_CALLED(""); + static const char Return[] = T_RETURN(""); + static int level; + va_list ap; + bool before = FALSE; + bool after = FALSE; + int doit = _nc_tracing; + int save_err = errno; + + if (strlen(fmt) >= sizeof(Called) - 1) { + if (!strncmp(fmt, Called, sizeof(Called) - 1)) { + before = TRUE; + level++; + } else if (!strncmp(fmt, Return, sizeof(Return) - 1)) { + after = TRUE; } - - if (doit != 0) { - if (tracefp == 0) - tracefp = stderr; - if (before || after) { - int n; - for (n = 1; n < level; n++) - fputs("+ ", tracefp); - } - va_start(ap, fmt); - vfprintf(tracefp, fmt, ap); - fputc('\n', tracefp); - va_end(ap); - fflush(tracefp); + if (before || after) { + if ((level <= 1) + || (doit & TRACE_ICALLS) != 0) + doit &= (TRACE_CALLS | TRACE_CCALLS); + else + doit = 0; } - - if (after && level) - level--; - errno = save_err; + } + + if (doit != 0) { + if (tracefp == 0) + tracefp = stderr; + if (before || after) { + int n; + for (n = 1; n < level; n++) + fputs("+ ", tracefp); + } + va_start(ap, fmt); + vfprintf(tracefp, fmt, ap); + fputc('\n', tracefp); + va_end(ap); + fflush(tracefp); + } + + if (after && level) + level--; + errno = save_err; } /* Trace 'int' return-values */ -int _nc_retrace_int(int code) +int +_nc_retrace_int(int code) { - T((T_RETURN("%d"), code)); - return code; + T((T_RETURN("%d"), code)); + return code; } /* Trace 'char*' return-values */ -char * _nc_retrace_ptr(char * code) +char * +_nc_retrace_ptr(char *code) { - T((T_RETURN("%s"), _nc_visbuf(code))); - return code; + T((T_RETURN("%s"), _nc_visbuf(code))); + return code; } /* Trace 'WINDOW *' return-values */ -WINDOW *_nc_retrace_win(WINDOW *code) +WINDOW * +_nc_retrace_win(WINDOW *code) { - T((T_RETURN("%p"), code)); - return code; + T((T_RETURN("%p"), code)); + return code; } #endif /* TRACE */ diff --git a/lib/libcurses/trace/lib_tracebits.c b/lib/libcurses/trace/lib_tracebits.c index 5469470e1fe..2548638bc71 100644 --- a/lib/libcurses/trace/lib_tracebits.c +++ b/lib/libcurses/trace/lib_tracebits.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_tracebits.c,v 1.3 1999/08/22 17:42:37 millert Exp $ */ +/* $OpenBSD: lib_tracebits.c,v 1.4 2000/01/09 05:06:02 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 * @@ -34,21 +34,20 @@ ****************************************************************************/ #include <curses.priv.h> -#include <term.h> /* cur_term */ +#include <term.h> /* cur_term */ -MODULE_ID("$From: lib_tracebits.c,v 1.3 1999/08/21 21:43:48 tom Exp $") +MODULE_ID("$From: lib_tracebits.c,v 1.4 2000/01/08 17:41:41 tom Exp $") #if defined(SVR4_TERMIO) && !defined(_POSIX_SOURCE) #define _POSIX_SOURCE #endif #if HAVE_SYS_TERMIO_H -#include <sys/termio.h> /* needed for ISC */ +#include <sys/termio.h> /* needed for ISC */ #endif #ifdef __EMX__ #include <io.h> -#include <fcntl.h> #endif /* may be undefined if we're using termio.h */ @@ -61,90 +60,89 @@ MODULE_ID("$From: lib_tracebits.c,v 1.3 1999/08/21 21:43:48 tom Exp $") #ifdef TRACE -typedef struct {unsigned int val; const char *name;} BITNAMES; +typedef struct { + unsigned int val; + const char *name; +} BITNAMES; -static void lookup_bits(char *buf, const BITNAMES *table, const char *label, unsigned int val) +static void +lookup_bits(char *buf, const BITNAMES * table, const char *label, unsigned int val) { - const BITNAMES *sp; - - (void) strcat(buf, label); - (void) strcat(buf, ": {"); - for (sp = table; sp->name; sp++) - if (sp->val != 0 - && (val & sp->val) == sp->val) - { - (void) strcat(buf, sp->name); - (void) strcat(buf, ", "); - } - if (buf[strlen(buf) - 2] == ',') - buf[strlen(buf) - 2] = '\0'; - (void) strcat(buf,"} "); + const BITNAMES *sp; + + (void) strcat(buf, label); + (void) strcat(buf, ": {"); + for (sp = table; sp->name; sp++) + if (sp->val != 0 + && (val & sp->val) == sp->val) { + (void) strcat(buf, sp->name); + (void) strcat(buf, ", "); + } + if (buf[strlen(buf) - 2] == ',') + buf[strlen(buf) - 2] = '\0'; + (void) strcat(buf, "} "); } -char *_nc_tracebits(void) +char * +_nc_tracebits(void) /* describe the state of the terminal control bits exactly */ { -char *buf; -static const BITNAMES + char *buf; #ifdef TERMIOS -iflags[] = + static const BITNAMES iflags[] = { - {BRKINT, "BRKINT"}, - {IGNBRK, "IGNBRK"}, - {IGNPAR, "IGNPAR"}, - {PARMRK, "PARMRK"}, - {INPCK, "INPCK"}, - {ISTRIP, "ISTRIP"}, - {INLCR, "INLCR"}, - {IGNCR, "IGNC"}, - {ICRNL, "ICRNL"}, - {IXON, "IXON"}, - {IXOFF, "IXOFF"}, - {0, NULL} + {BRKINT, "BRKINT"}, + {IGNBRK, "IGNBRK"}, + {IGNPAR, "IGNPAR"}, + {PARMRK, "PARMRK"}, + {INPCK, "INPCK"}, + {ISTRIP, "ISTRIP"}, + {INLCR, "INLCR"}, + {IGNCR, "IGNC"}, + {ICRNL, "ICRNL"}, + {IXON, "IXON"}, + {IXOFF, "IXOFF"}, + {0, NULL} #define ALLIN (BRKINT|IGNBRK|IGNPAR|PARMRK|INPCK|ISTRIP|INLCR|IGNCR|ICRNL|IXON|IXOFF) - }, -oflags[] = + }, oflags[] = { - {OPOST, "OPOST"}, - {0, NULL} + {OPOST, "OPOST"}, + {0, NULL} #define ALLOUT (OPOST) - }, -cflags[] = + }, cflags[] = { - {CLOCAL, "CLOCAL"}, - {CREAD, "CREAD"}, - {CSTOPB, "CSTOPB"}, + {CLOCAL, "CLOCAL"}, + {CREAD, "CREAD"}, + {CSTOPB, "CSTOPB"}, #if !defined(CS5) || !defined(CS8) - {CSIZE, "CSIZE"}, + {CSIZE, "CSIZE"}, #endif - {HUPCL, "HUPCL"}, - {PARENB, "PARENB"}, - {PARODD|PARENB, "PARODD"}, /* concession to readability */ - {0, NULL} + {HUPCL, "HUPCL"}, + {PARENB, "PARENB"}, + {PARODD | PARENB, "PARODD"}, /* concession to readability */ + {0, NULL} #define ALLCTRL (CLOCAL|CREAD|CSIZE|CSTOPB|HUPCL|PARENB|PARODD) - }, -lflags[] = + }, lflags[] = { - {ECHO, "ECHO"}, - {ECHOE|ECHO, "ECHOE"}, /* concession to readability */ - {ECHOK|ECHO, "ECHOK"}, /* concession to readability */ - {ECHONL, "ECHONL"}, - {ICANON, "ICANON"}, - {ISIG, "ISIG"}, - {NOFLSH, "NOFLSH"}, - {TOSTOP, "TOSTOP"}, - {IEXTEN, "IEXTEN"}, - {0, NULL} + {ECHO, "ECHO"}, + {ECHOE | ECHO, "ECHOE"}, /* concession to readability */ + {ECHOK | ECHO, "ECHOK"}, /* concession to readability */ + {ECHONL, "ECHONL"}, + {ICANON, "ICANON"}, + {ISIG, "ISIG"}, + {NOFLSH, "NOFLSH"}, + {TOSTOP, "TOSTOP"}, + {IEXTEN, "IEXTEN"}, + {0, NULL} #define ALLLOCAL (ECHO|ECHONL|ICANON|ISIG|NOFLSH|TOSTOP|IEXTEN) }; - buf = _nc_trace_buf(0, - 8 + sizeof(iflags) + - 8 + sizeof(oflags) + - 8 + sizeof(cflags) + - 8 + sizeof(lflags) + + 8 + sizeof(iflags) + + 8 + sizeof(oflags) + + 8 + sizeof(cflags) + + 8 + sizeof(lflags) + 8); if (cur_term->Nttyb.c_iflag & ALLIN) @@ -159,18 +157,28 @@ lflags[] = #if defined(CS5) && defined(CS8) switch (cur_term->Nttyb.c_cflag & CSIZE) { #if defined(CS5) && (CS5 != 0) - case CS5: strcat(buf, "CS5 "); break; + case CS5: + strcat(buf, "CS5 "); + break; #endif #if defined(CS6) && (CS6 != 0) - case CS6: strcat(buf, "CS6 "); break; + case CS6: + strcat(buf, "CS6 "); + break; #endif #if defined(CS7) && (CS7 != 0) - case CS7: strcat(buf, "CS7 "); break; + case CS7: + strcat(buf, "CS7 "); + break; #endif #if defined(CS8) && (CS8 != 0) - case CS8: strcat(buf, "CS8 "); break; + case CS8: + strcat(buf, "CS8 "); + break; #endif - default: strcat(buf, "CSIZE? "); break; + default: + strcat(buf, "CSIZE? "); + break; } #endif @@ -195,33 +203,36 @@ lflags[] = #define TANDEM 0 #endif -cflags[] = + static const BITNAMES cflags[] = { - {CBREAK, "CBREAK"}, - {CRMOD, "CRMOD"}, - {ECHO, "ECHO"}, - {EVENP, "EVENP"}, - {LCASE, "LCASE"}, - {LLITOUT, "LLITOUT"}, - {ODDP, "ODDP"}, - {RAW, "RAW"}, - {TANDEM, "TANDEM"}, - {XTABS, "XTABS"}, - {0, NULL} + {CBREAK, "CBREAK"}, + {CRMOD, "CRMOD"}, + {ECHO, "ECHO"}, + {EVENP, "EVENP"}, + {LCASE, "LCASE"}, + {LLITOUT, "LLITOUT"}, + {ODDP, "ODDP"}, + {RAW, "RAW"}, + {TANDEM, "TANDEM"}, + {XTABS, "XTABS"}, + {0, NULL} #define ALLCTRL (CBREAK|CRMOD|ECHO|EVENP|LCASE|LLITOUT|ODDP|RAW|TANDEM|XTABS) }; buf = _nc_trace_buf(0, - 8 + sizeof(cflags)); + 8 + sizeof(cflags)); - if (cur_term->Nttyb.sg_flags & ALLCTRL) - { + if (cur_term->Nttyb.sg_flags & ALLCTRL) { lookup_bits(buf, cflags, "cflags", cur_term->Nttyb.sg_flags); } - #endif - return(buf); + return (buf); } #else -char *_nc_tracebits(void) { static char tmp[] = ""; return tmp; } +char * +_nc_tracebits(void) +{ + static char tmp[] = ""; + return tmp; +} #endif /* TRACE */ |