ncurses 5.9 - patch 20120324

+ amend an old fix so that next_char() exits properly for empty files,
  e.g., from reading /dev/null (cf: 20080804).
+ modify tic so that it can read from the standard input, or from
  a character device.  Because tic uses seek's, this requires writing
  the data to a temporary file first (prompted by remark by Sven
  Joachim) (cf: 20000923).
This commit is contained in:
Thomas E. Dickey 2012-03-24 23:37:46 +00:00
parent 85b1a47885
commit 70e1890695
7 changed files with 144 additions and 63 deletions

10
NEWS
View File

@ -25,7 +25,7 @@
-- sale, use or other dealings in this Software without prior written --
-- authorization. --
-------------------------------------------------------------------------------
-- $Id: NEWS,v 1.1880 2012/03/17 21:16:50 tom Exp $
-- $Id: NEWS,v 1.1883 2012/03/24 22:27:20 tom Exp $
-------------------------------------------------------------------------------
This is a log of changes that ncurses has gone through since Zeyd started
@ -45,6 +45,14 @@ See the AUTHORS file for the corresponding full names.
Changes through 1.9.9e did not credit all contributions;
it is not possible to add this information.
20120324
+ amend an old fix so that next_char() exits properly for empty files,
e.g., from reading /dev/null (cf: 20080804).
+ modify tic so that it can read from the standard input, or from
a character device. Because tic uses seek's, this requires writing
the data to a temporary file first (prompted by remark by Sven
Joachim) (cf: 20000923).
20120317
+ correct a check made in lib_napms.c, so that terminfo applications
can again use napms() (cf: 20110604).

View File

@ -25,7 +25,7 @@
# use or other dealings in this Software without prior written #
# authorization. #
##############################################################################
# $Id: dist.mk,v 1.864 2012/03/17 13:40:53 tom Exp $
# $Id: dist.mk,v 1.865 2012/03/24 18:16:44 tom Exp $
# Makefile for creating ncurses distributions.
#
# This only needs to be used directly as a makefile by developers, but
@ -37,7 +37,7 @@ SHELL = /bin/sh
# These define the major/minor/patch versions of ncurses.
NCURSES_MAJOR = 5
NCURSES_MINOR = 9
NCURSES_PATCH = 20120317
NCURSES_PATCH = 20120324
# We don't append the patch to the version, since this only applies to releases
VERSION = $(NCURSES_MAJOR).$(NCURSES_MINOR)

View File

@ -26,7 +26,7 @@
.\" authorization. *
.\"***************************************************************************
.\"
.\" $Id: tic.1m,v 1.54 2012/02/04 23:09:43 tom Exp $
.\" $Id: tic.1m,v 1.55 2012/03/24 21:21:05 tom Exp $
.TH @TIC@ 1M ""
.ds n 5
.ds d @TERMINFO@
@ -265,26 +265,7 @@ indicating the desired level of detail of information.
If \fIn\fR is omitted, the default level is 1.
If \fIn\fR is specified and greater than 1, the level of
detail is increased.
.TP
\fB\-w\fR\fIn\fR
specifies the width of the output.
The parameter is optional.
If it is omitted, it defaults to 60.
.TP
\fB\-x\fR
Treat unknown capabilities as user-defined.
That is, if you supply a capability name which \fB@TIC@\fP does not recognize,
it will infer its type (boolean, number or string) from the syntax and
make an extended table entry for that.
User-defined capability strings
whose name begins with ``k'' are treated as function keys.
.SS PARAMETERS
.TP
\fIfile\fR
contains one or more \fBterminfo\fR terminal descriptions in source
format [see \fBterminfo\fR(\*n)].
Each description in the file
describes the capabilities of a particular terminal.
.RS
.PP
The debug flag levels are as follows:
.TP
@ -310,6 +291,30 @@ List of tokens encountered by scanner
All values computed in construction of the hash table
.LP
If the debug level \fIn\fR is not given, it is taken to be one.
.RE
.TP
\fB\-w\fR\fIn\fR
specifies the width of the output.
The parameter is optional.
If it is omitted, it defaults to 60.
.TP
\fB\-x\fR
Treat unknown capabilities as user-defined.
That is, if you supply a capability name which \fB@TIC@\fP does not recognize,
it will infer its type (boolean, number or string) from the syntax and
make an extended table entry for that.
User-defined capability strings
whose name begins with ``k'' are treated as function keys.
.SS PARAMETERS
.TP
\fIfile\fR
contains one or more \fBterminfo\fR terminal descriptions in source
format [see \fBterminfo\fR(\*n)].
Each description in the file
describes the capabilities of a particular terminal.
.IP
If \fIfile\fR is ``-'', then the data is read from the standard input.
The \fIfile\fR parameter may also be the path of a character-device.
.SS PROCESSING
.PP
All but one of the capabilities recognized by \fB@TIC@\fR are documented

View File

@ -1,5 +1,5 @@
/****************************************************************************
* Copyright (c) 1998-2010,2011 Free Software Foundation, Inc. *
* Copyright (c) 1998-2011,2012 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 *
@ -35,7 +35,7 @@
#include <ctype.h>
#include <tic.h>
MODULE_ID("$Id: comp_expand.c,v 1.24 2012/02/22 22:40:24 tom Exp $")
MODULE_ID("$Id: comp_expand.c,v 1.25 2012/03/24 18:37:17 tom Exp $")
static int
trailing_spaces(const char *src)

View File

@ -50,7 +50,7 @@
#include <ctype.h>
#include <tic.h>
MODULE_ID("$Id: comp_scan.c,v 1.96 2012/02/22 22:26:58 tom Exp $")
MODULE_ID("$Id: comp_scan.c,v 1.97 2012/03/24 22:24:19 tom Exp $")
/*
* Maximum length of string capability we'll accept before raising an error.
@ -196,7 +196,8 @@ next_char(void)
result = typeRealloc(char, allocated, result);
if (result == 0)
return (EOF);
bufstart = result;
if (bufstart)
bufstart = result;
}
if (used == 0)
_nc_curr_file_pos = ftell(yyin);

View File

@ -1,5 +1,5 @@
/****************************************************************************
* Copyright (c) 2001-2010,2011 Free Software Foundation, Inc. *
* Copyright (c) 2001-2011,2012 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 *
@ -35,7 +35,7 @@
#include <curses.priv.h>
MODULE_ID("$Id: lib_cchar.c,v 1.25 2012/03/10 20:52:21 tom Exp $")
MODULE_ID("$Id: lib_cchar.c,v 1.26 2012/03/24 18:37:17 tom Exp $")
/*
* The SuSv2 description leaves some room for interpretation. We'll assume wch

View File

@ -46,7 +46,9 @@
#include <hashed_db.h>
#include <transform.h>
MODULE_ID("$Id: tic.c,v 1.162 2012/02/22 23:59:45 tom Exp $")
MODULE_ID("$Id: tic.c,v 1.165 2012/03/24 22:07:10 tom Exp $")
#define STDIN_NAME "<stdin>"
const char *_nc_progname = "tic";
@ -365,19 +367,96 @@ stripped(char *src)
}
static FILE *
open_input(const char *filename)
open_tempfile(char *filename)
{
FILE *fp = fopen(filename, "r");
struct stat sb;
FILE *result = 0;
if (fp == 0) {
fprintf(stderr, "%s: Can't open %s\n", _nc_progname, filename);
ExitProgram(EXIT_FAILURE);
_nc_STRCPY(filename, "/tmp/XXXXXX", PATH_MAX);
#if HAVE_MKSTEMP
{
int fd = mkstemp(filename);
if (fd >= 0)
result = fdopen(fd, "w");
}
if (fstat(fileno(fp), &sb) < 0
|| (sb.st_mode & S_IFMT) != S_IFREG) {
#else
if (tmpnam(filename) != 0)
result = fopen(filename, "w");
#endif
return result;
}
static FILE *
copy_input(FILE *source, const char *filename, char *alt_file)
{
FILE *result = 0;
FILE *target = open_tempfile(alt_file);
int ch;
if (source == 0) {
failed("copy_input (source)");
} else if (target == 0) {
failed("copy_input (target)");
} else {
clearerr(source);
for (;;) {
ch = fgetc(source);
if (feof(source)) {
break;
} else if (ferror(source)) {
failed(filename);
} else if (ch == 0) {
/* don't loop in case someone wants to convert /dev/zero */
fprintf(stderr, "%s: %s is not a text-file\n", _nc_progname, filename);
ExitProgram(EXIT_FAILURE);
}
fputc(ch, target);
}
fclose(source);
/*
* rewind() does not force the target file's data to disk (not does
* fflush()...). So open a second stream on the data and then close
* the one that we were writing on before starting to read from the
* second stream.
*/
result = fopen(alt_file, "r+");
fclose(target);
to_remove = alt_file;
}
return result;
}
static FILE *
open_input(const char *filename, char *alt_file)
{
FILE *fp;
struct stat sb;
int mode;
if (!strcmp(filename, "-")) {
fp = copy_input(stdin, STDIN_NAME, alt_file);
} else if (stat(filename, &sb) < 0) {
fprintf(stderr, "%s: %s %s\n", _nc_progname, filename, strerror(errno));
ExitProgram(EXIT_FAILURE);
} else if ((mode = (sb.st_mode & S_IFMT)) == S_IFDIR
|| (mode != S_IFREG && mode != S_IFCHR)) {
fprintf(stderr, "%s: %s is not a file\n", _nc_progname, filename);
ExitProgram(EXIT_FAILURE);
} else {
fp = fopen(filename, "r");
if (fp == 0) {
fprintf(stderr, "%s: Can't open %s\n", _nc_progname, filename);
ExitProgram(EXIT_FAILURE);
}
if (mode != S_IFREG) {
if (alt_file != 0) {
FILE *fp2 = copy_input(fp, filename, alt_file);
fp = fp2;
} else {
fprintf(stderr, "%s: %s is not a file\n", _nc_progname, filename);
ExitProgram(EXIT_FAILURE);
}
}
}
return fp;
}
@ -395,7 +474,7 @@ make_namelist(char *src)
if (src == 0) {
/* EMPTY */ ;
} else if (strchr(src, '/') != 0) { /* a filename */
FILE *fp = open_input(src);
FILE *fp = open_input(src, (char *) 0);
for (pass = 1; pass <= 2; pass++) {
nn = 0;
@ -462,21 +541,6 @@ matches(char **needle, const char *haystack)
return (code);
}
static FILE *
open_tempfile(char *name)
{
FILE *result = 0;
#if HAVE_MKSTEMP
int fd = mkstemp(name);
if (fd >= 0)
result = fdopen(fd, "w");
#else
if (tmpnam(name) != 0)
result = fopen(name, "w");
#endif
return result;
}
static const char *
valid_db_path(const char *nominal)
{
@ -582,6 +646,7 @@ int
main(int argc, char *argv[])
{
char my_tmpname[PATH_MAX];
char my_altfile[PATH_MAX];
int v_opt = -1;
unsigned debug_level;
int smart_defaults = TRUE;
@ -796,14 +861,11 @@ main(int argc, char *argv[])
/* file exists */
source_file = termcap;
} else {
_nc_STRCPY(my_tmpname,
"/tmp/XXXXXX",
sizeof(my_tmpname));
if ((tmp_fp = open_tempfile(my_tmpname)) != 0) {
source_file = my_tmpname;
fprintf(tmp_fp, "%s\n", termcap);
fclose(tmp_fp);
tmp_fp = open_input(source_file);
tmp_fp = open_input(source_file, (char *) 0);
to_remove = source_file;
} else {
failed("tmpnam");
@ -822,19 +884,24 @@ main(int argc, char *argv[])
}
}
if (tmp_fp == 0)
tmp_fp = open_input(source_file);
if (tmp_fp == 0) {
tmp_fp = open_input(source_file, my_altfile);
if (!strcmp(source_file, "-")) {
source_file = STDIN_NAME;
}
}
if (infodump)
if (infodump) {
dump_init(tversion,
smart_defaults
? outform
: F_LITERAL,
sortmode, width, height, debug_level, formatted);
else if (capdump)
} else if (capdump) {
dump_init(tversion,
outform,
sortmode, width, height, debug_level, FALSE);
}
/* parse entries out of the source file */
_nc_set_source(source_file);