ltlfilt: use error() to report errors.
* lib/error.c, lib/error.h, lib/msvc-inval.c, lib/msvc-inval.h, lib/msvc-nothrow.c, lib/msvc-nothrow.h, m4/error.m4, m4/msvc-inval.m4, m4/msvc-nothrow.m4: New files from gnulib 1af55d85d9762a679b4302d5995f05ccd883e956. * lib/Makefile.am, m4/gnulib-cache.m4, m4/gnulib-comp.m4: Adjust. * src/bin/ltlfilt.cc: Use error() and error_at_line().
This commit is contained in:
parent
8132f91867
commit
90279bd40c
13 changed files with 1043 additions and 25 deletions
|
|
@ -21,7 +21,7 @@
|
|||
# the same distribution terms as the rest of that program.
|
||||
#
|
||||
# Generated by gnulib-tool.
|
||||
# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=tools --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files argp progname
|
||||
# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=tools --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files argp error progname
|
||||
|
||||
AUTOMAKE_OPTIONS = 1.5 gnits
|
||||
|
||||
|
|
@ -140,6 +140,15 @@ EXTRA_DIST += errno.in.h
|
|||
|
||||
## end gnulib module errno
|
||||
|
||||
## begin gnulib module error
|
||||
|
||||
|
||||
EXTRA_DIST += error.c error.h
|
||||
|
||||
EXTRA_libgnu_a_SOURCES += error.c
|
||||
|
||||
## end gnulib module error
|
||||
|
||||
## begin gnulib module float
|
||||
|
||||
BUILT_SOURCES += $(FLOAT_H)
|
||||
|
|
@ -247,6 +256,24 @@ EXTRA_libgnu_a_SOURCES += mempcpy.c
|
|||
|
||||
## end gnulib module mempcpy
|
||||
|
||||
## begin gnulib module msvc-inval
|
||||
|
||||
|
||||
EXTRA_DIST += msvc-inval.c msvc-inval.h
|
||||
|
||||
EXTRA_libgnu_a_SOURCES += msvc-inval.c
|
||||
|
||||
## end gnulib module msvc-inval
|
||||
|
||||
## begin gnulib module msvc-nothrow
|
||||
|
||||
|
||||
EXTRA_DIST += msvc-nothrow.c msvc-nothrow.h
|
||||
|
||||
EXTRA_libgnu_a_SOURCES += msvc-nothrow.c
|
||||
|
||||
## end gnulib module msvc-nothrow
|
||||
|
||||
## begin gnulib module progname
|
||||
|
||||
libgnu_a_SOURCES += progname.h progname.c
|
||||
|
|
|
|||
401
lib/error.c
Normal file
401
lib/error.c
Normal file
|
|
@ -0,0 +1,401 @@
|
|||
/* Error handler for noninteractive utilities
|
||||
Copyright (C) 1990-1998, 2000-2007, 2009-2012 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
/* Written by David MacKenzie <djm@gnu.ai.mit.edu>. */
|
||||
|
||||
#if !_LIBC
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "error.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if !_LIBC && ENABLE_NLS
|
||||
# include "gettext.h"
|
||||
# define _(msgid) gettext (msgid)
|
||||
#endif
|
||||
|
||||
#ifdef _LIBC
|
||||
# include <libintl.h>
|
||||
# include <stdbool.h>
|
||||
# include <stdint.h>
|
||||
# include <wchar.h>
|
||||
# define mbsrtowcs __mbsrtowcs
|
||||
#endif
|
||||
|
||||
#if USE_UNLOCKED_IO
|
||||
# include "unlocked-io.h"
|
||||
#endif
|
||||
|
||||
#ifndef _
|
||||
# define _(String) String
|
||||
#endif
|
||||
|
||||
/* If NULL, error will flush stdout, then print on stderr the program
|
||||
name, a colon and a space. Otherwise, error will call this
|
||||
function without parameters instead. */
|
||||
void (*error_print_progname) (void);
|
||||
|
||||
/* This variable is incremented each time 'error' is called. */
|
||||
unsigned int error_message_count;
|
||||
|
||||
#ifdef _LIBC
|
||||
/* In the GNU C library, there is a predefined variable for this. */
|
||||
|
||||
# define program_name program_invocation_name
|
||||
# include <errno.h>
|
||||
# include <limits.h>
|
||||
# include <libio/libioP.h>
|
||||
|
||||
/* In GNU libc we want do not want to use the common name 'error' directly.
|
||||
Instead make it a weak alias. */
|
||||
extern void __error (int status, int errnum, const char *message, ...)
|
||||
__attribute__ ((__format__ (__printf__, 3, 4)));
|
||||
extern void __error_at_line (int status, int errnum, const char *file_name,
|
||||
unsigned int line_number, const char *message,
|
||||
...)
|
||||
__attribute__ ((__format__ (__printf__, 5, 6)));;
|
||||
# define error __error
|
||||
# define error_at_line __error_at_line
|
||||
|
||||
# include <libio/iolibio.h>
|
||||
# define fflush(s) INTUSE(_IO_fflush) (s)
|
||||
# undef putc
|
||||
# define putc(c, fp) INTUSE(_IO_putc) (c, fp)
|
||||
|
||||
# include <bits/libc-lock.h>
|
||||
|
||||
#else /* not _LIBC */
|
||||
|
||||
# include <fcntl.h>
|
||||
# include <unistd.h>
|
||||
|
||||
# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
|
||||
/* Get declarations of the native Windows API functions. */
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <windows.h>
|
||||
/* Get _get_osfhandle. */
|
||||
# include "msvc-nothrow.h"
|
||||
# endif
|
||||
|
||||
/* The gnulib override of fcntl is not needed in this file. */
|
||||
# undef fcntl
|
||||
|
||||
# if !HAVE_DECL_STRERROR_R
|
||||
# ifndef HAVE_DECL_STRERROR_R
|
||||
"this configure-time declaration test was not run"
|
||||
# endif
|
||||
# if STRERROR_R_CHAR_P
|
||||
char *strerror_r ();
|
||||
# else
|
||||
int strerror_r ();
|
||||
# endif
|
||||
# endif
|
||||
|
||||
/* The calling program should define program_name and set it to the
|
||||
name of the executing program. */
|
||||
extern char *program_name;
|
||||
|
||||
# if HAVE_STRERROR_R || defined strerror_r
|
||||
# define __strerror_r strerror_r
|
||||
# endif /* HAVE_STRERROR_R || defined strerror_r */
|
||||
#endif /* not _LIBC */
|
||||
|
||||
#if !_LIBC
|
||||
/* Return non-zero if FD is open. */
|
||||
static inline int
|
||||
is_open (int fd)
|
||||
{
|
||||
# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
|
||||
/* On native Windows: The initial state of unassigned standard file
|
||||
descriptors is that they are open but point to an INVALID_HANDLE_VALUE.
|
||||
There is no fcntl, and the gnulib replacement fcntl does not support
|
||||
F_GETFL. */
|
||||
return (HANDLE) _get_osfhandle (fd) != INVALID_HANDLE_VALUE;
|
||||
# else
|
||||
# ifndef F_GETFL
|
||||
# error Please port fcntl to your platform
|
||||
# endif
|
||||
return 0 <= fcntl (fd, F_GETFL);
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline void
|
||||
flush_stdout (void)
|
||||
{
|
||||
#if !_LIBC
|
||||
int stdout_fd;
|
||||
|
||||
# if GNULIB_FREOPEN_SAFER
|
||||
/* Use of gnulib's freopen-safer module normally ensures that
|
||||
fileno (stdout) == 1
|
||||
whenever stdout is open. */
|
||||
stdout_fd = STDOUT_FILENO;
|
||||
# else
|
||||
/* POSIX states that fileno (stdout) after fclose is unspecified. But in
|
||||
practice it is not a problem, because stdout is statically allocated and
|
||||
the fd of a FILE stream is stored as a field in its allocated memory. */
|
||||
stdout_fd = fileno (stdout);
|
||||
# endif
|
||||
/* POSIX states that fflush (stdout) after fclose is unspecified; it
|
||||
is safe in glibc, but not on all other platforms. fflush (NULL)
|
||||
is always defined, but too draconian. */
|
||||
if (0 <= stdout_fd && is_open (stdout_fd))
|
||||
#endif
|
||||
fflush (stdout);
|
||||
}
|
||||
|
||||
static void
|
||||
print_errno_message (int errnum)
|
||||
{
|
||||
char const *s;
|
||||
|
||||
#if defined HAVE_STRERROR_R || _LIBC
|
||||
char errbuf[1024];
|
||||
# if STRERROR_R_CHAR_P || _LIBC
|
||||
s = __strerror_r (errnum, errbuf, sizeof errbuf);
|
||||
# else
|
||||
if (__strerror_r (errnum, errbuf, sizeof errbuf) == 0)
|
||||
s = errbuf;
|
||||
else
|
||||
s = 0;
|
||||
# endif
|
||||
#else
|
||||
s = strerror (errnum);
|
||||
#endif
|
||||
|
||||
#if !_LIBC
|
||||
if (! s)
|
||||
s = _("Unknown system error");
|
||||
#endif
|
||||
|
||||
#if _LIBC
|
||||
__fxprintf (NULL, ": %s", s);
|
||||
#else
|
||||
fprintf (stderr, ": %s", s);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
error_tail (int status, int errnum, const char *message, va_list args)
|
||||
{
|
||||
#if _LIBC
|
||||
if (_IO_fwide (stderr, 0) > 0)
|
||||
{
|
||||
# define ALLOCA_LIMIT 2000
|
||||
size_t len = strlen (message) + 1;
|
||||
wchar_t *wmessage = NULL;
|
||||
mbstate_t st;
|
||||
size_t res;
|
||||
const char *tmp;
|
||||
bool use_malloc = false;
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (__libc_use_alloca (len * sizeof (wchar_t)))
|
||||
wmessage = (wchar_t *) alloca (len * sizeof (wchar_t));
|
||||
else
|
||||
{
|
||||
if (!use_malloc)
|
||||
wmessage = NULL;
|
||||
|
||||
wchar_t *p = (wchar_t *) realloc (wmessage,
|
||||
len * sizeof (wchar_t));
|
||||
if (p == NULL)
|
||||
{
|
||||
free (wmessage);
|
||||
fputws_unlocked (L"out of memory\n", stderr);
|
||||
return;
|
||||
}
|
||||
wmessage = p;
|
||||
use_malloc = true;
|
||||
}
|
||||
|
||||
memset (&st, '\0', sizeof (st));
|
||||
tmp = message;
|
||||
|
||||
res = mbsrtowcs (wmessage, &tmp, len, &st);
|
||||
if (res != len)
|
||||
break;
|
||||
|
||||
if (__builtin_expect (len >= SIZE_MAX / 2, 0))
|
||||
{
|
||||
/* This really should not happen if everything is fine. */
|
||||
res = (size_t) -1;
|
||||
break;
|
||||
}
|
||||
|
||||
len *= 2;
|
||||
}
|
||||
|
||||
if (res == (size_t) -1)
|
||||
{
|
||||
/* The string cannot be converted. */
|
||||
if (use_malloc)
|
||||
{
|
||||
free (wmessage);
|
||||
use_malloc = false;
|
||||
}
|
||||
wmessage = (wchar_t *) L"???";
|
||||
}
|
||||
|
||||
__vfwprintf (stderr, wmessage, args);
|
||||
|
||||
if (use_malloc)
|
||||
free (wmessage);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
vfprintf (stderr, message, args);
|
||||
va_end (args);
|
||||
|
||||
++error_message_count;
|
||||
if (errnum)
|
||||
print_errno_message (errnum);
|
||||
#if _LIBC
|
||||
__fxprintf (NULL, "\n");
|
||||
#else
|
||||
putc ('\n', stderr);
|
||||
#endif
|
||||
fflush (stderr);
|
||||
if (status)
|
||||
exit (status);
|
||||
}
|
||||
|
||||
|
||||
/* Print the program name and error message MESSAGE, which is a printf-style
|
||||
format string with optional args.
|
||||
If ERRNUM is nonzero, print its corresponding system error message.
|
||||
Exit with status STATUS if it is nonzero. */
|
||||
void
|
||||
error (int status, int errnum, const char *message, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
#if defined _LIBC && defined __libc_ptf_call
|
||||
/* We do not want this call to be cut short by a thread
|
||||
cancellation. Therefore disable cancellation for now. */
|
||||
int state = PTHREAD_CANCEL_ENABLE;
|
||||
__libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state),
|
||||
0);
|
||||
#endif
|
||||
|
||||
flush_stdout ();
|
||||
#ifdef _LIBC
|
||||
_IO_flockfile (stderr);
|
||||
#endif
|
||||
if (error_print_progname)
|
||||
(*error_print_progname) ();
|
||||
else
|
||||
{
|
||||
#if _LIBC
|
||||
__fxprintf (NULL, "%s: ", program_name);
|
||||
#else
|
||||
fprintf (stderr, "%s: ", program_name);
|
||||
#endif
|
||||
}
|
||||
|
||||
va_start (args, message);
|
||||
error_tail (status, errnum, message, args);
|
||||
|
||||
#ifdef _LIBC
|
||||
_IO_funlockfile (stderr);
|
||||
# ifdef __libc_ptf_call
|
||||
__libc_ptf_call (pthread_setcancelstate, (state, NULL), 0);
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Sometimes we want to have at most one error per line. This
|
||||
variable controls whether this mode is selected or not. */
|
||||
int error_one_per_line;
|
||||
|
||||
void
|
||||
error_at_line (int status, int errnum, const char *file_name,
|
||||
unsigned int line_number, const char *message, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
if (error_one_per_line)
|
||||
{
|
||||
static const char *old_file_name;
|
||||
static unsigned int old_line_number;
|
||||
|
||||
if (old_line_number == line_number
|
||||
&& (file_name == old_file_name
|
||||
|| strcmp (old_file_name, file_name) == 0))
|
||||
/* Simply return and print nothing. */
|
||||
return;
|
||||
|
||||
old_file_name = file_name;
|
||||
old_line_number = line_number;
|
||||
}
|
||||
|
||||
#if defined _LIBC && defined __libc_ptf_call
|
||||
/* We do not want this call to be cut short by a thread
|
||||
cancellation. Therefore disable cancellation for now. */
|
||||
int state = PTHREAD_CANCEL_ENABLE;
|
||||
__libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state),
|
||||
0);
|
||||
#endif
|
||||
|
||||
flush_stdout ();
|
||||
#ifdef _LIBC
|
||||
_IO_flockfile (stderr);
|
||||
#endif
|
||||
if (error_print_progname)
|
||||
(*error_print_progname) ();
|
||||
else
|
||||
{
|
||||
#if _LIBC
|
||||
__fxprintf (NULL, "%s:", program_name);
|
||||
#else
|
||||
fprintf (stderr, "%s:", program_name);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if _LIBC
|
||||
__fxprintf (NULL, file_name != NULL ? "%s:%d: " : " ",
|
||||
file_name, line_number);
|
||||
#else
|
||||
fprintf (stderr, file_name != NULL ? "%s:%d: " : " ",
|
||||
file_name, line_number);
|
||||
#endif
|
||||
|
||||
va_start (args, message);
|
||||
error_tail (status, errnum, message, args);
|
||||
|
||||
#ifdef _LIBC
|
||||
_IO_funlockfile (stderr);
|
||||
# ifdef __libc_ptf_call
|
||||
__libc_ptf_call (pthread_setcancelstate, (state, NULL), 0);
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef _LIBC
|
||||
/* Make the weak alias. */
|
||||
# undef error
|
||||
# undef error_at_line
|
||||
weak_alias (__error, error)
|
||||
weak_alias (__error_at_line, error_at_line)
|
||||
#endif
|
||||
65
lib/error.h
Normal file
65
lib/error.h
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
/* Declaration for error-reporting function
|
||||
Copyright (C) 1995-1997, 2003, 2006, 2008-2012 Free Software Foundation,
|
||||
Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _ERROR_H
|
||||
#define _ERROR_H 1
|
||||
|
||||
/* The __attribute__ feature is available in gcc versions 2.5 and later.
|
||||
The __-protected variants of the attributes 'format' and 'printf' are
|
||||
accepted by gcc versions 2.6.4 (effectively 2.7) and later.
|
||||
We enable _GL_ATTRIBUTE_FORMAT only if these are supported too, because
|
||||
gnulib and libintl do '#define printf __printf__' when they override
|
||||
the 'printf' function. */
|
||||
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
|
||||
# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
|
||||
#else
|
||||
# define _GL_ATTRIBUTE_FORMAT(spec) /* empty */
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Print a message with 'fprintf (stderr, FORMAT, ...)';
|
||||
if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM).
|
||||
If STATUS is nonzero, terminate the program with 'exit (STATUS)'. */
|
||||
|
||||
extern void error (int __status, int __errnum, const char *__format, ...)
|
||||
_GL_ATTRIBUTE_FORMAT ((__printf__, 3, 4));
|
||||
|
||||
extern void error_at_line (int __status, int __errnum, const char *__fname,
|
||||
unsigned int __lineno, const char *__format, ...)
|
||||
_GL_ATTRIBUTE_FORMAT ((__printf__, 5, 6));
|
||||
|
||||
/* If NULL, error will flush stdout, then print on stderr the program
|
||||
name, a colon and a space. Otherwise, error will call this
|
||||
function without parameters instead. */
|
||||
extern void (*error_print_progname) (void);
|
||||
|
||||
/* This variable is incremented each time 'error' is called. */
|
||||
extern unsigned int error_message_count;
|
||||
|
||||
/* Sometimes we want to have at most one error per line. This
|
||||
variable controls whether this mode is selected or not. */
|
||||
extern int error_one_per_line;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* error.h */
|
||||
129
lib/msvc-inval.c
Normal file
129
lib/msvc-inval.c
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
/* Invalid parameter handler for MSVC runtime libraries.
|
||||
Copyright (C) 2011-2012 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include "msvc-inval.h"
|
||||
|
||||
#if HAVE_MSVC_INVALID_PARAMETER_HANDLER \
|
||||
&& !(MSVC_INVALID_PARAMETER_HANDLING == SANE_LIBRARY_HANDLING)
|
||||
|
||||
/* Get _invalid_parameter_handler type and _set_invalid_parameter_handler
|
||||
declaration. */
|
||||
# include <stdlib.h>
|
||||
|
||||
# if MSVC_INVALID_PARAMETER_HANDLING == DEFAULT_HANDLING
|
||||
|
||||
static void cdecl
|
||||
gl_msvc_invalid_parameter_handler (const wchar_t *expression,
|
||||
const wchar_t *function,
|
||||
const wchar_t *file,
|
||||
unsigned int line,
|
||||
uintptr_t dummy)
|
||||
{
|
||||
}
|
||||
|
||||
# else
|
||||
|
||||
/* Get declarations of the native Windows API functions. */
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <windows.h>
|
||||
|
||||
# if defined _MSC_VER
|
||||
|
||||
static void cdecl
|
||||
gl_msvc_invalid_parameter_handler (const wchar_t *expression,
|
||||
const wchar_t *function,
|
||||
const wchar_t *file,
|
||||
unsigned int line,
|
||||
uintptr_t dummy)
|
||||
{
|
||||
RaiseException (STATUS_GNULIB_INVALID_PARAMETER, 0, 0, NULL);
|
||||
}
|
||||
|
||||
# else
|
||||
|
||||
/* An index to thread-local storage. */
|
||||
static DWORD tls_index;
|
||||
static int tls_initialized /* = 0 */;
|
||||
|
||||
/* Used as a fallback only. */
|
||||
static struct gl_msvc_inval_per_thread not_per_thread;
|
||||
|
||||
struct gl_msvc_inval_per_thread *
|
||||
gl_msvc_inval_current (void)
|
||||
{
|
||||
if (!tls_initialized)
|
||||
{
|
||||
tls_index = TlsAlloc ();
|
||||
tls_initialized = 1;
|
||||
}
|
||||
if (tls_index == TLS_OUT_OF_INDEXES)
|
||||
/* TlsAlloc had failed. */
|
||||
return ¬_per_thread;
|
||||
else
|
||||
{
|
||||
struct gl_msvc_inval_per_thread *pointer =
|
||||
(struct gl_msvc_inval_per_thread *) TlsGetValue (tls_index);
|
||||
if (pointer == NULL)
|
||||
{
|
||||
/* First call. Allocate a new 'struct gl_msvc_inval_per_thread'. */
|
||||
pointer =
|
||||
(struct gl_msvc_inval_per_thread *)
|
||||
malloc (sizeof (struct gl_msvc_inval_per_thread));
|
||||
if (pointer == NULL)
|
||||
/* Could not allocate memory. Use the global storage. */
|
||||
pointer = ¬_per_thread;
|
||||
TlsSetValue (tls_index, pointer);
|
||||
}
|
||||
return pointer;
|
||||
}
|
||||
}
|
||||
|
||||
static void cdecl
|
||||
gl_msvc_invalid_parameter_handler (const wchar_t *expression,
|
||||
const wchar_t *function,
|
||||
const wchar_t *file,
|
||||
unsigned int line,
|
||||
uintptr_t dummy)
|
||||
{
|
||||
struct gl_msvc_inval_per_thread *current = gl_msvc_inval_current ();
|
||||
if (current->restart_valid)
|
||||
longjmp (current->restart, 1);
|
||||
else
|
||||
/* An invalid parameter notification from outside the gnulib code.
|
||||
Give the caller a chance to intervene. */
|
||||
RaiseException (STATUS_GNULIB_INVALID_PARAMETER, 0, 0, NULL);
|
||||
}
|
||||
|
||||
# endif
|
||||
|
||||
# endif
|
||||
|
||||
static int gl_msvc_inval_initialized /* = 0 */;
|
||||
|
||||
void
|
||||
gl_msvc_inval_ensure_handler (void)
|
||||
{
|
||||
if (gl_msvc_inval_initialized == 0)
|
||||
{
|
||||
_set_invalid_parameter_handler (gl_msvc_invalid_parameter_handler);
|
||||
gl_msvc_inval_initialized = 1;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
222
lib/msvc-inval.h
Normal file
222
lib/msvc-inval.h
Normal file
|
|
@ -0,0 +1,222 @@
|
|||
/* Invalid parameter handler for MSVC runtime libraries.
|
||||
Copyright (C) 2011-2012 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _MSVC_INVAL_H
|
||||
#define _MSVC_INVAL_H
|
||||
|
||||
/* With MSVC runtime libraries with the "invalid parameter handler" concept,
|
||||
functions like fprintf(), dup2(), or close() crash when the caller passes
|
||||
an invalid argument. But POSIX wants error codes (such as EINVAL or EBADF)
|
||||
instead.
|
||||
This file defines macros that turn such an invalid parameter notification
|
||||
into a non-local exit. An error code can then be produced at the target
|
||||
of this exit. You can thus write code like
|
||||
|
||||
TRY_MSVC_INVAL
|
||||
{
|
||||
<Code that can trigger an invalid parameter notification
|
||||
but does not do 'return', 'break', 'continue', nor 'goto'.>
|
||||
}
|
||||
CATCH_MSVC_INVAL
|
||||
{
|
||||
<Code that handles an invalid parameter notification
|
||||
but does not do 'return', 'break', 'continue', nor 'goto'.>
|
||||
}
|
||||
DONE_MSVC_INVAL;
|
||||
|
||||
This entire block expands to a single statement.
|
||||
|
||||
The handling of invalid parameters can be done in three ways:
|
||||
|
||||
* The default way, which is reasonable for programs (not libraries):
|
||||
AC_DEFINE([MSVC_INVALID_PARAMETER_HANDLING], [DEFAULT_HANDLING])
|
||||
|
||||
* The way for libraries that make "hairy" calls (like close(-1), or
|
||||
fclose(fp) where fileno(fp) is closed, or simply getdtablesize()):
|
||||
AC_DEFINE([MSVC_INVALID_PARAMETER_HANDLING], [HAIRY_LIBRARY_HANDLING])
|
||||
|
||||
* The way for libraries that make no "hairy" calls:
|
||||
AC_DEFINE([MSVC_INVALID_PARAMETER_HANDLING], [SANE_LIBRARY_HANDLING])
|
||||
*/
|
||||
|
||||
#define DEFAULT_HANDLING 0
|
||||
#define HAIRY_LIBRARY_HANDLING 1
|
||||
#define SANE_LIBRARY_HANDLING 2
|
||||
|
||||
#if HAVE_MSVC_INVALID_PARAMETER_HANDLER \
|
||||
&& !(MSVC_INVALID_PARAMETER_HANDLING == SANE_LIBRARY_HANDLING)
|
||||
/* A native Windows platform with the "invalid parameter handler" concept,
|
||||
and either DEFAULT_HANDLING or HAIRY_LIBRARY_HANDLING. */
|
||||
|
||||
# if MSVC_INVALID_PARAMETER_HANDLING == DEFAULT_HANDLING
|
||||
/* Default handling. */
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
|
||||
/* Ensure that the invalid parameter handler in installed that just returns.
|
||||
Because we assume no other part of the program installs a different
|
||||
invalid parameter handler, this solution is multithread-safe. */
|
||||
extern void gl_msvc_inval_ensure_handler (void);
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
|
||||
# define TRY_MSVC_INVAL \
|
||||
do \
|
||||
{ \
|
||||
gl_msvc_inval_ensure_handler (); \
|
||||
if (1)
|
||||
# define CATCH_MSVC_INVAL \
|
||||
else
|
||||
# define DONE_MSVC_INVAL \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
# else
|
||||
/* Handling for hairy libraries. */
|
||||
|
||||
# include <excpt.h>
|
||||
|
||||
/* Gnulib can define its own status codes, as described in the page
|
||||
"Raising Software Exceptions" on microsoft.com
|
||||
<http://msdn.microsoft.com/en-us/library/het71c37.aspx>.
|
||||
Our status codes are composed of
|
||||
- 0xE0000000, mandatory for all user-defined status codes,
|
||||
- 0x474E550, a API identifier ("GNU"),
|
||||
- 0, 1, 2, ..., used to distinguish different status codes from the
|
||||
same API. */
|
||||
# define STATUS_GNULIB_INVALID_PARAMETER (0xE0000000 + 0x474E550 + 0)
|
||||
|
||||
# if defined _MSC_VER
|
||||
/* A compiler that supports __try/__except, as described in the page
|
||||
"try-except statement" on microsoft.com
|
||||
<http://msdn.microsoft.com/en-us/library/s58ftw19.aspx>.
|
||||
With __try/__except, we can use the multithread-safe exception handling. */
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
|
||||
/* Ensure that the invalid parameter handler in installed that raises a
|
||||
software exception with code STATUS_GNULIB_INVALID_PARAMETER.
|
||||
Because we assume no other part of the program installs a different
|
||||
invalid parameter handler, this solution is multithread-safe. */
|
||||
extern void gl_msvc_inval_ensure_handler (void);
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
|
||||
# define TRY_MSVC_INVAL \
|
||||
do \
|
||||
{ \
|
||||
gl_msvc_inval_ensure_handler (); \
|
||||
__try
|
||||
# define CATCH_MSVC_INVAL \
|
||||
__except (GetExceptionCode () == STATUS_GNULIB_INVALID_PARAMETER \
|
||||
? EXCEPTION_EXECUTE_HANDLER \
|
||||
: EXCEPTION_CONTINUE_SEARCH)
|
||||
# define DONE_MSVC_INVAL \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
# else
|
||||
/* Any compiler.
|
||||
We can only use setjmp/longjmp. */
|
||||
|
||||
# include <setjmp.h>
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
|
||||
struct gl_msvc_inval_per_thread
|
||||
{
|
||||
/* The restart that will resume execution at the code between
|
||||
CATCH_MSVC_INVAL and DONE_MSVC_INVAL. It is enabled only between
|
||||
TRY_MSVC_INVAL and CATCH_MSVC_INVAL. */
|
||||
jmp_buf restart;
|
||||
|
||||
/* Tells whether the contents of restart is valid. */
|
||||
int restart_valid;
|
||||
};
|
||||
|
||||
/* Ensure that the invalid parameter handler in installed that passes
|
||||
control to the gl_msvc_inval_restart if it is valid, or raises a
|
||||
software exception with code STATUS_GNULIB_INVALID_PARAMETER otherwise.
|
||||
Because we assume no other part of the program installs a different
|
||||
invalid parameter handler, this solution is multithread-safe. */
|
||||
extern void gl_msvc_inval_ensure_handler (void);
|
||||
|
||||
/* Return a pointer to the per-thread data for the current thread. */
|
||||
extern struct gl_msvc_inval_per_thread *gl_msvc_inval_current (void);
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
|
||||
# define TRY_MSVC_INVAL \
|
||||
do \
|
||||
{ \
|
||||
struct gl_msvc_inval_per_thread *msvc_inval_current; \
|
||||
gl_msvc_inval_ensure_handler (); \
|
||||
msvc_inval_current = gl_msvc_inval_current (); \
|
||||
/* First, initialize gl_msvc_inval_restart. */ \
|
||||
if (setjmp (msvc_inval_current->restart) == 0) \
|
||||
{ \
|
||||
/* Then, mark it as valid. */ \
|
||||
msvc_inval_current->restart_valid = 1;
|
||||
# define CATCH_MSVC_INVAL \
|
||||
/* Execution completed. \
|
||||
Mark gl_msvc_inval_restart as invalid. */ \
|
||||
msvc_inval_current->restart_valid = 0; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
/* Execution triggered an invalid parameter notification. \
|
||||
Mark gl_msvc_inval_restart as invalid. */ \
|
||||
msvc_inval_current->restart_valid = 0;
|
||||
# define DONE_MSVC_INVAL \
|
||||
} \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
# endif
|
||||
|
||||
# endif
|
||||
|
||||
#else
|
||||
/* A platform that does not need to the invalid parameter handler,
|
||||
or when SANE_LIBRARY_HANDLING is desired. */
|
||||
|
||||
/* The braces here avoid GCC warnings like
|
||||
"warning: suggest explicit braces to avoid ambiguous 'else'". */
|
||||
# define TRY_MSVC_INVAL \
|
||||
do \
|
||||
{ \
|
||||
if (1)
|
||||
# define CATCH_MSVC_INVAL \
|
||||
else
|
||||
# define DONE_MSVC_INVAL \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _MSVC_INVAL_H */
|
||||
49
lib/msvc-nothrow.c
Normal file
49
lib/msvc-nothrow.c
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/* Wrappers that don't throw invalid parameter notifications
|
||||
with MSVC runtime libraries.
|
||||
Copyright (C) 2011-2012 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include "msvc-nothrow.h"
|
||||
|
||||
/* Get declarations of the native Windows API functions. */
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
#include "msvc-inval.h"
|
||||
|
||||
#undef _get_osfhandle
|
||||
|
||||
#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
|
||||
intptr_t
|
||||
_gl_nothrow_get_osfhandle (int fd)
|
||||
{
|
||||
intptr_t result;
|
||||
|
||||
TRY_MSVC_INVAL
|
||||
{
|
||||
result = _get_osfhandle (fd);
|
||||
}
|
||||
CATCH_MSVC_INVAL
|
||||
{
|
||||
result = (intptr_t) INVALID_HANDLE_VALUE;
|
||||
}
|
||||
DONE_MSVC_INVAL;
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
43
lib/msvc-nothrow.h
Normal file
43
lib/msvc-nothrow.h
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/* Wrappers that don't throw invalid parameter notifications
|
||||
with MSVC runtime libraries.
|
||||
Copyright (C) 2011-2012 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _MSVC_NOTHROW_H
|
||||
#define _MSVC_NOTHROW_H
|
||||
|
||||
/* With MSVC runtime libraries with the "invalid parameter handler" concept,
|
||||
functions like fprintf(), dup2(), or close() crash when the caller passes
|
||||
an invalid argument. But POSIX wants error codes (such as EINVAL or EBADF)
|
||||
instead.
|
||||
This file defines wrappers that turn such an invalid parameter notification
|
||||
into an error code. */
|
||||
|
||||
#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
|
||||
|
||||
/* Get original declaration of _get_osfhandle. */
|
||||
# include <io.h>
|
||||
|
||||
# if HAVE_MSVC_INVALID_PARAMETER_HANDLER
|
||||
|
||||
/* Override _get_osfhandle. */
|
||||
extern intptr_t _gl_nothrow_get_osfhandle (int fd);
|
||||
# define _get_osfhandle _gl_nothrow_get_osfhandle
|
||||
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _MSVC_NOTHROW_H */
|
||||
28
m4/error.m4
Normal file
28
m4/error.m4
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#serial 14
|
||||
|
||||
# Copyright (C) 1996-1998, 2001-2004, 2009-2012 Free Software Foundation, Inc.
|
||||
#
|
||||
# This file is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
# with or without modifications, as long as this notice is preserved.
|
||||
|
||||
AC_DEFUN([gl_ERROR],
|
||||
[
|
||||
dnl We don't use AC_FUNC_ERROR_AT_LINE any more, because it is no longer
|
||||
dnl maintained in Autoconf and because it invokes AC_LIBOBJ.
|
||||
AC_CACHE_CHECK([for error_at_line], [ac_cv_lib_error_at_line],
|
||||
[AC_LINK_IFELSE(
|
||||
[AC_LANG_PROGRAM(
|
||||
[[#include <error.h>]],
|
||||
[[error_at_line (0, 0, "", 0, "an error occurred");]])],
|
||||
[ac_cv_lib_error_at_line=yes],
|
||||
[ac_cv_lib_error_at_line=no])])
|
||||
])
|
||||
|
||||
# Prerequisites of lib/error.c.
|
||||
AC_DEFUN([gl_PREREQ_ERROR],
|
||||
[
|
||||
AC_REQUIRE([AC_FUNC_STRERROR_R])
|
||||
AC_REQUIRE([AC_C_INLINE])
|
||||
:
|
||||
])
|
||||
|
|
@ -27,12 +27,13 @@
|
|||
|
||||
|
||||
# Specification in the form of a command-line invocation:
|
||||
# gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=tools --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files argp progname
|
||||
# gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=tools --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files argp error progname
|
||||
|
||||
# Specification in the form of a few gnulib-tool.m4 macro invocations:
|
||||
gl_LOCAL_DIR([])
|
||||
gl_MODULES([
|
||||
argp
|
||||
error
|
||||
progname
|
||||
])
|
||||
gl_AVOID([])
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ AC_DEFUN([gl_EARLY],
|
|||
# Code from module dosname:
|
||||
# Code from module double-slash-root:
|
||||
# Code from module errno:
|
||||
# Code from module error:
|
||||
# Code from module extensions:
|
||||
AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
|
||||
# Code from module float:
|
||||
|
|
@ -57,6 +58,8 @@ AC_DEFUN([gl_EARLY],
|
|||
# Code from module malloc-posix:
|
||||
# Code from module memchr:
|
||||
# Code from module mempcpy:
|
||||
# Code from module msvc-inval:
|
||||
# Code from module msvc-nothrow:
|
||||
# Code from module multiarch:
|
||||
# Code from module nocrash:
|
||||
# Code from module progname:
|
||||
|
|
@ -116,6 +119,14 @@ AC_DEFUN([gl_INIT],
|
|||
gl_DIRNAME_LGPL
|
||||
gl_DOUBLE_SLASH_ROOT
|
||||
gl_HEADER_ERRNO_H
|
||||
gl_ERROR
|
||||
if test $ac_cv_lib_error_at_line = no; then
|
||||
AC_LIBOBJ([error])
|
||||
gl_PREREQ_ERROR
|
||||
fi
|
||||
m4_ifdef([AM_XGETTEXT_OPTION],
|
||||
[AM_][XGETTEXT_OPTION([--flag=error:3:c-format])
|
||||
AM_][XGETTEXT_OPTION([--flag=error_at_line:5:c-format])])
|
||||
gl_FLOAT_H
|
||||
if test $REPLACE_FLOAT_LDBL = 1; then
|
||||
AC_LIBOBJ([float])
|
||||
|
|
@ -166,6 +177,14 @@ AC_DEFUN([gl_INIT],
|
|||
gl_PREREQ_MEMPCPY
|
||||
fi
|
||||
gl_STRING_MODULE_INDICATOR([mempcpy])
|
||||
gl_MSVC_INVAL
|
||||
if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then
|
||||
AC_LIBOBJ([msvc-inval])
|
||||
fi
|
||||
gl_MSVC_NOTHROW
|
||||
if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then
|
||||
AC_LIBOBJ([msvc-nothrow])
|
||||
fi
|
||||
gl_MULTIARCH
|
||||
AC_CHECK_DECLS([program_invocation_name], [], [], [#include <errno.h>])
|
||||
AC_CHECK_DECLS([program_invocation_short_name], [], [], [#include <errno.h>])
|
||||
|
|
@ -402,6 +421,8 @@ AC_DEFUN([gl_FILE_LIST], [
|
|||
lib/dirname.h
|
||||
lib/dosname.h
|
||||
lib/errno.in.h
|
||||
lib/error.c
|
||||
lib/error.h
|
||||
lib/float+.h
|
||||
lib/float.c
|
||||
lib/float.in.h
|
||||
|
|
@ -416,6 +437,10 @@ AC_DEFUN([gl_FILE_LIST], [
|
|||
lib/memchr.c
|
||||
lib/memchr.valgrind
|
||||
lib/mempcpy.c
|
||||
lib/msvc-inval.c
|
||||
lib/msvc-inval.h
|
||||
lib/msvc-nothrow.c
|
||||
lib/msvc-nothrow.h
|
||||
lib/printf-args.c
|
||||
lib/printf-args.h
|
||||
lib/printf-parse.c
|
||||
|
|
@ -459,6 +484,7 @@ AC_DEFUN([gl_FILE_LIST], [
|
|||
m4/dirname.m4
|
||||
m4/double-slash-root.m4
|
||||
m4/errno_h.m4
|
||||
m4/error.m4
|
||||
m4/exponentd.m4
|
||||
m4/extensions.m4
|
||||
m4/float_h.m4
|
||||
|
|
@ -473,6 +499,8 @@ AC_DEFUN([gl_FILE_LIST], [
|
|||
m4/memchr.m4
|
||||
m4/mempcpy.m4
|
||||
m4/mmap-anon.m4
|
||||
m4/msvc-inval.m4
|
||||
m4/msvc-nothrow.m4
|
||||
m4/multiarch.m4
|
||||
m4/nocrash.m4
|
||||
m4/off_t.m4
|
||||
|
|
|
|||
19
m4/msvc-inval.m4
Normal file
19
m4/msvc-inval.m4
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
# msvc-inval.m4 serial 1
|
||||
dnl Copyright (C) 2011-2012 Free Software Foundation, Inc.
|
||||
dnl This file is free software; the Free Software Foundation
|
||||
dnl gives unlimited permission to copy and/or distribute it,
|
||||
dnl with or without modifications, as long as this notice is preserved.
|
||||
|
||||
AC_DEFUN([gl_MSVC_INVAL],
|
||||
[
|
||||
AC_CHECK_FUNCS_ONCE([_set_invalid_parameter_handler])
|
||||
if test $ac_cv_func__set_invalid_parameter_handler = yes; then
|
||||
HAVE_MSVC_INVALID_PARAMETER_HANDLER=1
|
||||
AC_DEFINE([HAVE_MSVC_INVALID_PARAMETER_HANDLER], [1],
|
||||
[Define to 1 on MSVC platforms that have the "invalid parameter handler"
|
||||
concept.])
|
||||
else
|
||||
HAVE_MSVC_INVALID_PARAMETER_HANDLER=0
|
||||
fi
|
||||
AC_SUBST([HAVE_MSVC_INVALID_PARAMETER_HANDLER])
|
||||
])
|
||||
10
m4/msvc-nothrow.m4
Normal file
10
m4/msvc-nothrow.m4
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
# msvc-nothrow.m4 serial 1
|
||||
dnl Copyright (C) 2011-2012 Free Software Foundation, Inc.
|
||||
dnl This file is free software; the Free Software Foundation
|
||||
dnl gives unlimited permission to copy and/or distribute it,
|
||||
dnl with or without modifications, as long as this notice is preserved.
|
||||
|
||||
AC_DEFUN([gl_MSVC_NOTHROW],
|
||||
[
|
||||
AC_REQUIRE([gl_MSVC_INVAL])
|
||||
])
|
||||
|
|
@ -30,6 +30,7 @@
|
|||
#include <fstream>
|
||||
#include <argp.h>
|
||||
#include "progname.h"
|
||||
#include "error.h"
|
||||
|
||||
#include "misc/_config.h"
|
||||
#include "misc/hash.hh"
|
||||
|
|
@ -203,10 +204,7 @@ to_int(const char* s)
|
|||
char* endptr;
|
||||
int res = strtol(s, &endptr, 10);
|
||||
if (*endptr)
|
||||
{
|
||||
std::cerr << "Failed to parse `" << s << "' as an integer." << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
error(1, 0, "failed to parse '%s' as an integer.", s);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
@ -253,8 +251,7 @@ parse_opt(int key, char* arg, struct argp_state* state)
|
|||
level = arg[0] = '0';
|
||||
return 0;
|
||||
}
|
||||
std::cerr << "Invalid simplification LEVEL: " << arg << "\n";
|
||||
return 1;
|
||||
error(1, 0, "invalid simplification level '%s'", arg);
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
|
|
@ -364,7 +361,7 @@ namespace
|
|||
if (!quiet)
|
||||
{
|
||||
if (filename)
|
||||
std::cerr << "at " << filename << ":" << linenum << ":\n";
|
||||
error_at_line(0, 0, filename, linenum, "parse error:");
|
||||
spot::ltl::format_parse_errors(std::cerr, input, pel);
|
||||
}
|
||||
|
||||
|
|
@ -484,30 +481,29 @@ namespace
|
|||
}
|
||||
|
||||
int
|
||||
process_file(const char* filename)
|
||||
process_stream(std::istream& is, const char* filename)
|
||||
{
|
||||
int error = 0;
|
||||
int linenum = 0;
|
||||
std::string line;
|
||||
// Special case for stdin.
|
||||
if (filename[0] == '-' && filename[1] == 0)
|
||||
{
|
||||
while (std::getline(std::cin, line))
|
||||
error |= process_formula(line, "stdin", ++linenum);
|
||||
return error;
|
||||
}
|
||||
|
||||
std::ifstream input(filename);
|
||||
if (!input)
|
||||
{
|
||||
std::cerr << "cannot open " << filename << std::endl;
|
||||
return 1;
|
||||
}
|
||||
while (std::getline(input, line))
|
||||
while (std::getline(is, line))
|
||||
error |= process_formula(line, filename, ++linenum);
|
||||
return error;
|
||||
}
|
||||
|
||||
int
|
||||
process_file(const char* filename)
|
||||
{
|
||||
// Special case for stdin.
|
||||
if (filename[0] == '-' && filename[1] == 0)
|
||||
return process_stream(std::cin, filename);
|
||||
|
||||
errno = 0;
|
||||
std::ifstream input(filename);
|
||||
if (!input)
|
||||
error(1, errno, "cannot open '%s'", filename);
|
||||
return process_stream(input, filename);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue