diff options
author | thegeorg <thegeorg@yandex-team.com> | 2024-05-21 14:47:17 +0300 |
---|---|---|
committer | thegeorg <thegeorg@yandex-team.com> | 2024-05-21 14:57:46 +0300 |
commit | 04130c8898efdb4937a61db0e4d26c5130b52069 (patch) | |
tree | 0e14a5c5aabec6c0c5831b216629a94a0d716982 | |
parent | c2982258ce9938ec66a65fc04657010f10a2fe42 (diff) | |
download | ydb-04130c8898efdb4937a61db0e4d26c5130b52069.tar.gz |
Drop unused gnulib srcs from contrib/tools/bison
231e84067197fe69ac80bee1f6cd14648ba7f18c
65 files changed, 4 insertions, 8288 deletions
diff --git a/contrib/tools/bison/lib/asnprintf.c b/contrib/tools/bison/lib/asnprintf.c deleted file mode 100644 index 76e228d860..0000000000 --- a/contrib/tools/bison/lib/asnprintf.c +++ /dev/null @@ -1,34 +0,0 @@ -/* Formatted output to strings. - Copyright (C) 1999, 2002, 2006, 2009-2013 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 "vasnprintf.h" - -#include <stdarg.h> - -char * -asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...) -{ - va_list args; - char *result; - - va_start (args, format); - result = vasnprintf (resultbuf, lengthp, format, args); - va_end (args); - return result; -} diff --git a/contrib/tools/bison/lib/c-stack.c b/contrib/tools/bison/lib/c-stack.c deleted file mode 100644 index 52e46f83de..0000000000 --- a/contrib/tools/bison/lib/c-stack.c +++ /dev/null @@ -1,337 +0,0 @@ -/* Stack overflow handling. - - Copyright (C) 2002, 2004, 2006, 2008-2013 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 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 Paul Eggert. */ - -/* NOTES: - - A program that uses alloca, dynamic arrays, or large local - variables may extend the stack by more than a page at a time. If - so, when the stack overflows the operating system may not detect - the overflow until the program uses the array, and this module may - incorrectly report a program error instead of a stack overflow. - - To avoid this problem, allocate only small objects on the stack; a - program should be OK if it limits single allocations to a page or - less. Allocate larger arrays in static storage, or on the heap - (e.g., with malloc). Yes, this is a pain, but we don't know of any - better solution that is portable. - - No attempt has been made to deal with multithreaded applications. */ - -#include <config.h> - -#ifndef __attribute__ -# if __GNUC__ < 3 -# define __attribute__(x) -# endif -#endif - -#include "gettext.h" -#define _(msgid) gettext (msgid) - -#include <errno.h> - -#include <signal.h> -#if ! HAVE_STACK_T && ! defined stack_t -typedef struct sigaltstack stack_t; -#endif -#ifndef SIGSTKSZ -# define SIGSTKSZ 16384 -#elif defined __USE_DYNAMIC_STACK_SIZE -/* Redefining SIGSTKSZ here as dynamic stack size is not supported in this version of bison */ -# undef SIGSTKSZ -# define SIGSTKSZ 16384 -#elif HAVE_LIBSIGSEGV && SIGSTKSZ < 16384 -/* libsigsegv 2.6 through 2.8 have a bug where some architectures use - more than the Linux default of an 8k alternate stack when deciding - if a fault was caused by stack overflow. */ -# undef SIGSTKSZ -# define SIGSTKSZ 16384 -#endif - -#include <stdlib.h> -#include <string.h> - -/* Posix 2001 declares ucontext_t in <ucontext.h>, Posix 200x in - <signal.h>. */ -#if HAVE_UCONTEXT_H -# include <ucontext.h> -#endif - -#include <unistd.h> - -#if HAVE_LIBSIGSEGV -# include <sigsegv.h> -#endif - -#include "c-stack.h" -#include "exitfail.h" -#include "ignore-value.h" - -#if defined SA_ONSTACK && defined SA_SIGINFO -# define SIGINFO_WORKS 1 -#else -# define SIGINFO_WORKS 0 -# ifndef SA_ONSTACK -# define SA_ONSTACK 0 -# endif -#endif - -extern char *program_name; - -/* The user-specified action to take when a SEGV-related program error - or stack overflow occurs. */ -static void (* volatile segv_action) (int); - -/* Translated messages for program errors and stack overflow. Do not - translate them in the signal handler, since gettext is not - async-signal-safe. */ -static char const * volatile program_error_message; -static char const * volatile stack_overflow_message; - -/* Output an error message, then exit with status EXIT_FAILURE if it - appears to have been a stack overflow, or with a core dump - otherwise. This function is async-signal-safe. */ - -static _Noreturn void -die (int signo) -{ - char const *message; -#if !SIGINFO_WORKS && !HAVE_LIBSIGSEGV - /* We can't easily determine whether it is a stack overflow; so - assume that the rest of our program is perfect (!) and that - this segmentation violation is a stack overflow. */ - signo = 0; -#endif /* !SIGINFO_WORKS && !HAVE_LIBSIGSEGV */ - segv_action (signo); - message = signo ? program_error_message : stack_overflow_message; - ignore_value (write (STDERR_FILENO, program_name, strlen (program_name))); - ignore_value (write (STDERR_FILENO, ": ", 2)); - ignore_value (write (STDERR_FILENO, message, strlen (message))); - ignore_value (write (STDERR_FILENO, "\n", 1)); - if (! signo) - _exit (exit_failure); - raise (signo); - abort (); -} - -#if (HAVE_SIGALTSTACK && HAVE_DECL_SIGALTSTACK \ - && HAVE_STACK_OVERFLOW_HANDLING) || HAVE_LIBSIGSEGV - -/* Storage for the alternate signal stack. */ -static union -{ - char buffer[SIGSTKSZ]; - - /* These other members are for proper alignment. There's no - standard way to guarantee stack alignment, but this seems enough - in practice. */ - long double ld; - long l; - void *p; -} alternate_signal_stack; - -static void -null_action (int signo __attribute__ ((unused))) -{ -} - -#endif /* SIGALTSTACK || LIBSIGSEGV */ - -/* Only use libsigsegv if we need it; platforms like Solaris can - detect stack overflow without the overhead of an external - library. */ -#if HAVE_LIBSIGSEGV && ! HAVE_XSI_STACK_OVERFLOW_HEURISTIC - -/* Nonzero if general segv handler could not be installed. */ -static volatile int segv_handler_missing; - -/* Handle a segmentation violation and exit if it cannot be stack - overflow. This function is async-signal-safe. */ - -static int segv_handler (void *address __attribute__ ((unused)), - int serious) -{ -# if DEBUG - { - char buf[1024]; - sprintf (buf, "segv_handler serious=%d\n", serious); - write (STDERR_FILENO, buf, strlen (buf)); - } -# endif - - /* If this fault is not serious, return 0 to let the stack overflow - handler take a shot at it. */ - if (!serious) - return 0; - die (SIGSEGV); -} - -/* Handle a segmentation violation that is likely to be a stack - overflow and exit. This function is async-signal-safe. */ - -static _Noreturn void -overflow_handler (int emergency, - stackoverflow_context_t context __attribute__ ((unused))) -{ -# if DEBUG - { - char buf[1024]; - sprintf (buf, "overflow_handler emergency=%d segv_handler_missing=%d\n", - emergency, segv_handler_missing); - write (STDERR_FILENO, buf, strlen (buf)); - } -# endif - - die ((!emergency || segv_handler_missing) ? 0 : SIGSEGV); -} - -int -c_stack_action (void (*action) (int)) -{ - segv_action = action ? action : null_action; - program_error_message = _("program error"); - stack_overflow_message = _("stack overflow"); - - /* Always install the overflow handler. */ - if (stackoverflow_install_handler (overflow_handler, - alternate_signal_stack.buffer, - sizeof alternate_signal_stack.buffer)) - { - errno = ENOTSUP; - return -1; - } - /* Try installing a general handler; if it fails, then treat all - segv as stack overflow. */ - segv_handler_missing = sigsegv_install_handler (segv_handler); - return 0; -} - -#elif HAVE_SIGALTSTACK && HAVE_DECL_SIGALTSTACK && HAVE_STACK_OVERFLOW_HANDLING - -# if SIGINFO_WORKS - -/* Handle a segmentation violation and exit. This function is - async-signal-safe. */ - -static _Noreturn void -segv_handler (int signo, siginfo_t *info, - void *context __attribute__ ((unused))) -{ - /* Clear SIGNO if it seems to have been a stack overflow. */ -# if ! HAVE_XSI_STACK_OVERFLOW_HEURISTIC - /* We can't easily determine whether it is a stack overflow; so - assume that the rest of our program is perfect (!) and that - this segmentation violation is a stack overflow. - - Note that although both Linux and Solaris provide - sigaltstack, SA_ONSTACK, and SA_SIGINFO, currently only - Solaris satisfies the XSI heuristic. This is because - Solaris populates uc_stack with the details of the - interrupted stack, while Linux populates it with the details - of the current stack. */ - signo = 0; -# else - if (0 < info->si_code) - { - /* If the faulting address is within the stack, or within one - page of the stack, assume that it is a stack overflow. */ - ucontext_t const *user_context = context; - char const *stack_base = user_context->uc_stack.ss_sp; - size_t stack_size = user_context->uc_stack.ss_size; - char const *faulting_address = info->si_addr; - size_t page_size = sysconf (_SC_PAGESIZE); - size_t s = faulting_address - stack_base + page_size; - if (s < stack_size + 2 * page_size) - signo = 0; - -# if DEBUG - { - char buf[1024]; - sprintf (buf, - "segv_handler fault=%p base=%p size=%lx page=%lx signo=%d\n", - faulting_address, stack_base, (unsigned long) stack_size, - (unsigned long) page_size, signo); - write (STDERR_FILENO, buf, strlen (buf)); - } -# endif - } -# endif - - die (signo); -} -# endif - -int -c_stack_action (void (*action) (int)) -{ - int r; - stack_t st; - struct sigaction act; - st.ss_flags = 0; -# if SIGALTSTACK_SS_REVERSED - /* Irix mistakenly treats ss_sp as the upper bound, rather than - lower bound, of the alternate stack. */ - st.ss_sp = alternate_signal_stack.buffer + SIGSTKSZ - sizeof (void *); - st.ss_size = sizeof alternate_signal_stack.buffer - sizeof (void *); -# else - st.ss_sp = alternate_signal_stack.buffer; - st.ss_size = sizeof alternate_signal_stack.buffer; -# endif - r = sigaltstack (&st, NULL); - if (r != 0) - return r; - - segv_action = action ? action : null_action; - program_error_message = _("program error"); - stack_overflow_message = _("stack overflow"); - - sigemptyset (&act.sa_mask); - -# if SIGINFO_WORKS - /* POSIX 1003.1-2001 says SA_RESETHAND implies SA_NODEFER, but - this is not true on Solaris 8 at least. It doesn't hurt to use - SA_NODEFER here, so leave it in. */ - act.sa_flags = SA_NODEFER | SA_ONSTACK | SA_RESETHAND | SA_SIGINFO; - act.sa_sigaction = segv_handler; -# else - act.sa_flags = SA_NODEFER | SA_ONSTACK | SA_RESETHAND; - act.sa_handler = die; -# endif - -# if FAULT_YIELDS_SIGBUS - if (sigaction (SIGBUS, &act, NULL) < 0) - return -1; -# endif - return sigaction (SIGSEGV, &act, NULL); -} - -#else /* ! ((HAVE_SIGALTSTACK && HAVE_DECL_SIGALTSTACK - && HAVE_STACK_OVERFLOW_HANDLING) || HAVE_LIBSIGSEGV) */ - -int -c_stack_action (void (*action) (int) __attribute__ ((unused))) -{ -#if (defined _MSC_VER) && (_MSC_VER < 1800) -#else - errno = ENOTSUP; -#endif - return -1; -} - -#endif diff --git a/contrib/tools/bison/lib/c-stack.h b/contrib/tools/bison/lib/c-stack.h deleted file mode 100644 index 2e61bdf01d..0000000000 --- a/contrib/tools/bison/lib/c-stack.h +++ /dev/null @@ -1,44 +0,0 @@ -/* Stack overflow handling. - - Copyright (C) 2002, 2004, 2008-2013 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 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/>. */ - - -/* Set up ACTION so that it is invoked on C stack overflow and on other, - stack-unrelated, segmentation violation. - Return -1 (setting errno) if this cannot be done. - - When a stack overflow or segmentation violation occurs: - 1) ACTION is called. It is passed an argument equal to - - 0, for a stack overflow, - - SIGSEGV, for a segmentation violation that does not appear related - to stack overflow. - On many platforms the two cases are hard to distinguish; when in doubt, - zero is passed. - 2) If ACTION returns, a message is written to standard error, and the - program is terminated: in the case of stack overflow, with exit code - exit_failure (see "exitfail.h"), otherwise through a signal SIGSEGV. - - A null ACTION acts like an action that does nothing. - - ACTION must be async-signal-safe. ACTION together with its callees - must not require more than SIGSTKSZ bytes of stack space. Also, - ACTION should not call longjmp, because this implementation does - not guarantee that it is safe to return to the original stack. - - This function may install a handler for the SIGSEGV signal or for the SIGBUS - signal or exercise other system dependent exception handling APIs. */ - -extern int c_stack_action (void (* /*action*/) (int)); diff --git a/contrib/tools/bison/lib/calloc.c b/contrib/tools/bison/lib/calloc.c deleted file mode 100644 index 475d0aeab9..0000000000 --- a/contrib/tools/bison/lib/calloc.c +++ /dev/null @@ -1,73 +0,0 @@ -/* calloc() function that is glibc compatible. - This wrapper function is required at least on Tru64 UNIX 5.1 and mingw. - Copyright (C) 2004-2007, 2009-2013 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 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 Jim Meyering and Bruno Haible */ - -#include <config.h> -/* Only the AC_FUNC_CALLOC macro defines 'calloc' already in config.h. */ -#ifdef calloc -# define NEED_CALLOC_GNU 1 -# undef calloc -/* Whereas the gnulib module 'calloc-gnu' defines HAVE_CALLOC_GNU. */ -#elif GNULIB_CALLOC_GNU && !HAVE_CALLOC_GNU -# define NEED_CALLOC_GNU 1 -#endif - -/* Specification. */ -#include <stdlib.h> - -#include <errno.h> - -/* Call the system's calloc below. */ -#undef calloc - -/* Allocate and zero-fill an NxS-byte block of memory from the heap. - If N or S is zero, allocate and zero-fill a 1-byte block. */ - -void * -rpl_calloc (size_t n, size_t s) -{ - void *result; - -#if NEED_CALLOC_GNU - if (n == 0 || s == 0) - { - n = 1; - s = 1; - } - else - { - /* Defend against buggy calloc implementations that mishandle - size_t overflow. */ - size_t bytes = n * s; - if (bytes / s != n) - { - errno = ENOMEM; - return NULL; - } - } -#endif - - result = calloc (n, s); - -#if !HAVE_CALLOC_POSIX - if (result == NULL) - errno = ENOMEM; -#endif - - return result; -} diff --git a/contrib/tools/bison/lib/clean-temp.c b/contrib/tools/bison/lib/clean-temp.c deleted file mode 100644 index 2961114168..0000000000 --- a/contrib/tools/bison/lib/clean-temp.c +++ /dev/null @@ -1,793 +0,0 @@ -/* Temporary directories and temporary files with automatic cleanup. - Copyright (C) 2001, 2003, 2006-2007, 2009-2013 Free Software Foundation, - Inc. - Written by Bruno Haible <bruno@clisp.org>, 2006. - - 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/>. */ - - -#include <config.h> - -/* Specification. */ -#include "clean-temp.h" - -#include <errno.h> -#include <fcntl.h> -#include <limits.h> -#include <stdbool.h> -#include "stdlib--.h" -#include <string.h> -#include <unistd.h> - -#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ -# define WIN32_LEAN_AND_MEAN /* avoid including junk */ -# include <windows.h> -#endif - -#include "error.h" -#include "fatal-signal.h" -#include "pathmax.h" -#include "tmpdir.h" -#include "xalloc.h" -#include "xmalloca.h" -#include "gl_xlist.h" -#include "gl_linkedhash_list.h" -#include "gettext.h" -#if GNULIB_FWRITEERROR -# include "fwriteerror.h" -#endif -#if GNULIB_CLOSE_STREAM -# include "close-stream.h" -#endif -#if GNULIB_FCNTL_SAFER -# include "fcntl--.h" -#endif -#if GNULIB_FOPEN_SAFER -# include "stdio--.h" -#endif - -#define _(str) gettext (str) - -/* GNU Hurd doesn't have PATH_MAX. Use a fallback. - Temporary directory names are usually not that long. */ -#ifndef PATH_MAX -# define PATH_MAX 1024 -#endif - -#ifndef uintptr_t -# define uintptr_t unsigned long -#endif - -#if !GNULIB_FCNTL_SAFER -/* The results of open() in this file are not used with fchdir, - therefore save some unnecessary work in fchdir.c. */ -# undef open -# undef close -#endif - - -/* The use of 'volatile' in the types below (and ISO C 99 section 5.1.2.3.(5)) - ensure that while constructing or modifying the data structures, the field - values are written to memory in the order of the C statements. So the - signal handler can rely on these field values to be up to date. */ - - -/* Registry for a single temporary directory. - 'struct temp_dir' from the public header file overlaps with this. */ -struct tempdir -{ - /* The absolute pathname of the directory. */ - char * volatile dirname; - /* Whether errors during explicit cleanup are reported to standard error. */ - bool cleanup_verbose; - /* Absolute pathnames of subdirectories. */ - gl_list_t /* <char *> */ volatile subdirs; - /* Absolute pathnames of files. */ - gl_list_t /* <char *> */ volatile files; -}; - -/* List of all temporary directories. */ -static struct -{ - struct tempdir * volatile * volatile tempdir_list; - size_t volatile tempdir_count; - size_t tempdir_allocated; -} cleanup_list /* = { NULL, 0, 0 } */; - -/* List of all open file descriptors to temporary files. */ -static gl_list_t /* <int> */ volatile descriptors; - - -/* For the subdirs and for the files, we use a gl_list_t of type LINKEDHASH. - Why? We need a data structure that - - 1) Can contain an arbitrary number of 'char *' values. The strings - are compared via strcmp, not pointer comparison. - 2) Has insertion and deletion operations that are fast: ideally O(1), - or possibly O(log n). This is important for GNU sort, which may - create a large number of temporary files. - 3) Allows iteration through all elements from within a signal handler. - 4) May or may not allow duplicates. It doesn't matter here, since - any file or subdir can only be removed once. - - Criterion 1) would allow any gl_list_t or gl_oset_t implementation. - - Criterion 2) leaves only GL_LINKEDHASH_LIST, GL_TREEHASH_LIST, or - GL_TREE_OSET. - - Criterion 3) puts at disadvantage GL_TREEHASH_LIST and GL_TREE_OSET. - Namely, iteration through the elements of a binary tree requires access - to many ->left, ->right, ->parent pointers. However, the rebalancing - code for insertion and deletion in an AVL or red-black tree is so - complicated that we cannot assume that >left, ->right, ->parent pointers - are in a consistent state throughout these operations. Therefore, to - avoid a crash in the signal handler, all destructive operations to the - lists would have to be protected by a - block_fatal_signals (); - ... - unblock_fatal_signals (); - pair. Which causes extra system calls. - - Criterion 3) would also discourage GL_ARRAY_LIST and GL_CARRAY_LIST, - if they were not already excluded. Namely, these implementations use - xrealloc(), leaving a time window in which in the list->elements pointer - points to already deallocated memory. To avoid a crash in the signal - handler at such a moment, all destructive operations would have to - protected by block/unblock_fatal_signals (), in this case too. - - A list of type GL_LINKEDHASH_LIST without duplicates fulfills all - requirements: - 2) Insertion and deletion are O(1) on average. - 3) The gl_list_iterator, gl_list_iterator_next implementations do - not trigger memory allocations, nor other system calls, and are - therefore safe to be called from a signal handler. - Furthermore, since SIGNAL_SAFE_LIST is defined, the implementation - of the destructive functions ensures that the list structure is - safe to be traversed at any moment, even when interrupted by an - asynchronous signal. - */ - -/* String equality and hash code functions used by the lists. */ - -static bool -string_equals (const void *x1, const void *x2) -{ - const char *s1 = (const char *) x1; - const char *s2 = (const char *) x2; - return strcmp (s1, s2) == 0; -} - -#define SIZE_BITS (sizeof (size_t) * CHAR_BIT) - -/* A hash function for NUL-terminated char* strings using - the method described by Bruno Haible. - See http://www.haible.de/bruno/hashfunc.html. */ -static size_t -string_hash (const void *x) -{ - const char *s = (const char *) x; - size_t h = 0; - - for (; *s; s++) - h = *s + ((h << 9) | (h >> (SIZE_BITS - 9))); - - return h; -} - - -/* The signal handler. It gets called asynchronously. */ -static void -cleanup () -{ - size_t i; - - /* First close all file descriptors to temporary files. */ - { - gl_list_t fds = descriptors; - - if (fds != NULL) - { - gl_list_iterator_t iter; - const void *element; - - iter = gl_list_iterator (fds); - while (gl_list_iterator_next (&iter, &element, NULL)) - { - int fd = (int) (uintptr_t) element; - close (fd); - } - gl_list_iterator_free (&iter); - } - } - - for (i = 0; i < cleanup_list.tempdir_count; i++) - { - struct tempdir *dir = cleanup_list.tempdir_list[i]; - - if (dir != NULL) - { - gl_list_iterator_t iter; - const void *element; - - /* First cleanup the files in the subdirectories. */ - iter = gl_list_iterator (dir->files); - while (gl_list_iterator_next (&iter, &element, NULL)) - { - const char *file = (const char *) element; - unlink (file); - } - gl_list_iterator_free (&iter); - - /* Then cleanup the subdirectories. */ - iter = gl_list_iterator (dir->subdirs); - while (gl_list_iterator_next (&iter, &element, NULL)) - { - const char *subdir = (const char *) element; - rmdir (subdir); - } - gl_list_iterator_free (&iter); - - /* Then cleanup the temporary directory itself. */ - rmdir (dir->dirname); - } - } -} - -/* Create a temporary directory. - PREFIX is used as a prefix for the name of the temporary directory. It - should be short and still give an indication about the program. - PARENTDIR can be used to specify the parent directory; if NULL, a default - parent directory is used (either $TMPDIR or /tmp or similar). - CLEANUP_VERBOSE determines whether errors during explicit cleanup are - reported to standard error. - Return a fresh 'struct temp_dir' on success. Upon error, an error message - is shown and NULL is returned. */ -struct temp_dir * -create_temp_dir (const char *prefix, const char *parentdir, - bool cleanup_verbose) -{ - struct tempdir * volatile *tmpdirp = NULL; - struct tempdir *tmpdir; - size_t i; - char *xtemplate; - char *tmpdirname; - - /* See whether it can take the slot of an earlier temporary directory - already cleaned up. */ - for (i = 0; i < cleanup_list.tempdir_count; i++) - if (cleanup_list.tempdir_list[i] == NULL) - { - tmpdirp = &cleanup_list.tempdir_list[i]; - break; - } - if (tmpdirp == NULL) - { - /* See whether the array needs to be extended. */ - if (cleanup_list.tempdir_count == cleanup_list.tempdir_allocated) - { - /* Note that we cannot use xrealloc(), because then the cleanup() - function could access an already deallocated array. */ - struct tempdir * volatile *old_array = cleanup_list.tempdir_list; - size_t old_allocated = cleanup_list.tempdir_allocated; - size_t new_allocated = 2 * cleanup_list.tempdir_allocated + 1; - struct tempdir * volatile *new_array = - XNMALLOC (new_allocated, struct tempdir * volatile); - - if (old_allocated == 0) - /* First use of this facility. Register the cleanup handler. */ - at_fatal_signal (&cleanup); - else - { - /* Don't use memcpy() here, because memcpy takes non-volatile - arguments and is therefore not guaranteed to complete all - memory stores before the next statement. */ - size_t k; - - for (k = 0; k < old_allocated; k++) - new_array[k] = old_array[k]; - } - - cleanup_list.tempdir_list = new_array; - cleanup_list.tempdir_allocated = new_allocated; - - /* Now we can free the old array. */ - if (old_array != NULL) - free ((struct tempdir **) old_array); - } - - tmpdirp = &cleanup_list.tempdir_list[cleanup_list.tempdir_count]; - /* Initialize *tmpdirp before incrementing tempdir_count, so that - cleanup() will skip this entry before it is fully initialized. */ - *tmpdirp = NULL; - cleanup_list.tempdir_count++; - } - - /* Initialize a 'struct tempdir'. */ - tmpdir = XMALLOC (struct tempdir); - tmpdir->dirname = NULL; - tmpdir->cleanup_verbose = cleanup_verbose; - tmpdir->subdirs = gl_list_create_empty (GL_LINKEDHASH_LIST, - string_equals, string_hash, NULL, - false); - tmpdir->files = gl_list_create_empty (GL_LINKEDHASH_LIST, - string_equals, string_hash, NULL, - false); - - /* Create the temporary directory. */ - xtemplate = (char *) xmalloca (PATH_MAX); - if (path_search (xtemplate, PATH_MAX, parentdir, prefix, parentdir == NULL)) - { - error (0, errno, - _("cannot find a temporary directory, try setting $TMPDIR")); - goto quit; - } - block_fatal_signals (); - tmpdirname = mkdtemp (xtemplate); - if (tmpdirname != NULL) - { - tmpdir->dirname = tmpdirname; - *tmpdirp = tmpdir; - } - unblock_fatal_signals (); - if (tmpdirname == NULL) - { - error (0, errno, - _("cannot create a temporary directory using template \"%s\""), - xtemplate); - goto quit; - } - /* Replace tmpdir->dirname with a copy that has indefinite extent. - We cannot do this inside the block_fatal_signals/unblock_fatal_signals - block because then the cleanup handler would not remove the directory - if xstrdup fails. */ - tmpdir->dirname = xstrdup (tmpdirname); - freea (xtemplate); - return (struct temp_dir *) tmpdir; - - quit: - freea (xtemplate); - return NULL; -} - -/* Register the given ABSOLUTE_FILE_NAME as being a file inside DIR, that - needs to be removed before DIR can be removed. - Should be called before the file ABSOLUTE_FILE_NAME is created. */ -void -register_temp_file (struct temp_dir *dir, - const char *absolute_file_name) -{ - struct tempdir *tmpdir = (struct tempdir *)dir; - - /* Add absolute_file_name to tmpdir->files, without duplicates. */ - if (gl_list_search (tmpdir->files, absolute_file_name) == NULL) - gl_list_add_first (tmpdir->files, xstrdup (absolute_file_name)); -} - -/* Unregister the given ABSOLUTE_FILE_NAME as being a file inside DIR, that - needs to be removed before DIR can be removed. - Should be called when the file ABSOLUTE_FILE_NAME could not be created. */ -void -unregister_temp_file (struct temp_dir *dir, - const char *absolute_file_name) -{ - struct tempdir *tmpdir = (struct tempdir *)dir; - gl_list_t list = tmpdir->files; - gl_list_node_t node; - - node = gl_list_search (list, absolute_file_name); - if (node != NULL) - { - char *old_string = (char *) gl_list_node_value (list, node); - - gl_list_remove_node (list, node); - free (old_string); - } -} - -/* Register the given ABSOLUTE_DIR_NAME as being a subdirectory inside DIR, - that needs to be removed before DIR can be removed. - Should be called before the subdirectory ABSOLUTE_DIR_NAME is created. */ -void -register_temp_subdir (struct temp_dir *dir, - const char *absolute_dir_name) -{ - struct tempdir *tmpdir = (struct tempdir *)dir; - - /* Add absolute_dir_name to tmpdir->subdirs, without duplicates. */ - if (gl_list_search (tmpdir->subdirs, absolute_dir_name) == NULL) - gl_list_add_first (tmpdir->subdirs, xstrdup (absolute_dir_name)); -} - -/* Unregister the given ABSOLUTE_DIR_NAME as being a subdirectory inside DIR, - that needs to be removed before DIR can be removed. - Should be called when the subdirectory ABSOLUTE_DIR_NAME could not be - created. */ -void -unregister_temp_subdir (struct temp_dir *dir, - const char *absolute_dir_name) -{ - struct tempdir *tmpdir = (struct tempdir *)dir; - gl_list_t list = tmpdir->subdirs; - gl_list_node_t node; - - node = gl_list_search (list, absolute_dir_name); - if (node != NULL) - { - char *old_string = (char *) gl_list_node_value (list, node); - - gl_list_remove_node (list, node); - free (old_string); - } -} - -/* Remove a file, with optional error message. - Return 0 upon success, or -1 if there was some problem. */ -static int -do_unlink (struct temp_dir *dir, const char *absolute_file_name) -{ - if (unlink (absolute_file_name) < 0 && dir->cleanup_verbose - && errno != ENOENT) - { - error (0, errno, _("cannot remove temporary file %s"), absolute_file_name); - return -1; - } - return 0; -} - -/* Remove a directory, with optional error message. - Return 0 upon success, or -1 if there was some problem. */ -static int -do_rmdir (struct temp_dir *dir, const char *absolute_dir_name) -{ - if (rmdir (absolute_dir_name) < 0 && dir->cleanup_verbose - && errno != ENOENT) - { - error (0, errno, - _("cannot remove temporary directory %s"), absolute_dir_name); - return -1; - } - return 0; -} - -/* Remove the given ABSOLUTE_FILE_NAME and unregister it. - Return 0 upon success, or -1 if there was some problem. */ -int -cleanup_temp_file (struct temp_dir *dir, - const char *absolute_file_name) -{ - int err; - - err = do_unlink (dir, absolute_file_name); - unregister_temp_file (dir, absolute_file_name); - - return err; -} - -/* Remove the given ABSOLUTE_DIR_NAME and unregister it. - Return 0 upon success, or -1 if there was some problem. */ -int -cleanup_temp_subdir (struct temp_dir *dir, - const char *absolute_dir_name) -{ - int err; - - err = do_rmdir (dir, absolute_dir_name); - unregister_temp_subdir (dir, absolute_dir_name); - - return err; -} - -/* Remove all registered files and subdirectories inside DIR. - Return 0 upon success, or -1 if there was some problem. */ -int -cleanup_temp_dir_contents (struct temp_dir *dir) -{ - struct tempdir *tmpdir = (struct tempdir *)dir; - int err = 0; - gl_list_t list; - gl_list_iterator_t iter; - const void *element; - gl_list_node_t node; - - /* First cleanup the files in the subdirectories. */ - list = tmpdir->files; - iter = gl_list_iterator (list); - while (gl_list_iterator_next (&iter, &element, &node)) - { - char *file = (char *) element; - - err |= do_unlink (dir, file); - gl_list_remove_node (list, node); - /* Now only we can free file. */ - free (file); - } - gl_list_iterator_free (&iter); - - /* Then cleanup the subdirectories. */ - list = tmpdir->subdirs; - iter = gl_list_iterator (list); - while (gl_list_iterator_next (&iter, &element, &node)) - { - char *subdir = (char *) element; - - err |= do_rmdir (dir, subdir); - gl_list_remove_node (list, node); - /* Now only we can free subdir. */ - free (subdir); - } - gl_list_iterator_free (&iter); - - return err; -} - -/* Remove all registered files and subdirectories inside DIR and DIR itself. - DIR cannot be used any more after this call. - Return 0 upon success, or -1 if there was some problem. */ -int -cleanup_temp_dir (struct temp_dir *dir) -{ - struct tempdir *tmpdir = (struct tempdir *)dir; - int err = 0; - size_t i; - - err |= cleanup_temp_dir_contents (dir); - err |= do_rmdir (dir, tmpdir->dirname); - - for (i = 0; i < cleanup_list.tempdir_count; i++) - if (cleanup_list.tempdir_list[i] == tmpdir) - { - /* Remove cleanup_list.tempdir_list[i]. */ - if (i + 1 == cleanup_list.tempdir_count) - { - while (i > 0 && cleanup_list.tempdir_list[i - 1] == NULL) - i--; - cleanup_list.tempdir_count = i; - } - else - cleanup_list.tempdir_list[i] = NULL; - /* Now only we can free the tmpdir->dirname, tmpdir->subdirs, - tmpdir->files, and tmpdir itself. */ - gl_list_free (tmpdir->files); - gl_list_free (tmpdir->subdirs); - free (tmpdir->dirname); - free (tmpdir); - return err; - } - - /* The user passed an invalid DIR argument. */ - abort (); -} - - -#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - -/* On Windows, opening a file with _O_TEMPORARY has the effect of passing - the FILE_FLAG_DELETE_ON_CLOSE flag to CreateFile(), which has the effect - of deleting the file when it is closed - even when the program crashes. - But (according to the Cygwin sources) it works only on Windows NT or newer. - So we cache the info whether we are running on Windows NT or newer. */ - -static bool -supports_delete_on_close () -{ - static int known; /* 1 = yes, -1 = no, 0 = unknown */ - /* M4 wants to close and later reopen a temporary file, so - delete-on-close must not be used. */ - known = -1; - if (!known) - { - OSVERSIONINFO v; - - /* According to - <http://msdn.microsoft.com/en-us/library/windows/desktop/ms724451(v=vs.85).aspx> - this structure must be initialised as follows: */ - v.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); - - if (GetVersionEx (&v)) - known = (v.dwPlatformId == VER_PLATFORM_WIN32_NT ? 1 : -1); - else - known = -1; - } - return (known > 0); -} - -#endif - - -/* Register a file descriptor to be closed. */ -static void -register_fd (int fd) -{ - if (descriptors == NULL) - descriptors = gl_list_create_empty (GL_LINKEDHASH_LIST, NULL, NULL, NULL, - false); - gl_list_add_first (descriptors, (void *) (uintptr_t) fd); -} - -/* Unregister a file descriptor to be closed. */ -static void -unregister_fd (int fd) -{ - gl_list_t fds = descriptors; - gl_list_node_t node; - - if (fds == NULL) - /* descriptors should already contain fd. */ - abort (); - node = gl_list_search (fds, (void *) (uintptr_t) fd); - if (node == NULL) - /* descriptors should already contain fd. */ - abort (); - gl_list_remove_node (fds, node); -} - -/* Open a temporary file in a temporary directory. - Registers the resulting file descriptor to be closed. */ -int -open_temp (const char *file_name, int flags, mode_t mode) -{ - int fd; - int saved_errno; - - block_fatal_signals (); - /* Note: 'open' here is actually open() or open_safer(). */ -#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - /* Use _O_TEMPORARY when possible, to increase the chances that the - temporary file is removed when the process crashes. */ - if (supports_delete_on_close ()) - fd = open (file_name, flags | _O_TEMPORARY, mode); - else -#endif - fd = open (file_name, flags, mode); - saved_errno = errno; - if (fd >= 0) - register_fd (fd); - unblock_fatal_signals (); - errno = saved_errno; - return fd; -} - -/* Open a temporary file in a temporary directory. - Registers the resulting file descriptor to be closed. */ -FILE * -fopen_temp (const char *file_name, const char *mode) -{ - FILE *fp; - int saved_errno; - - block_fatal_signals (); - /* Note: 'fopen' here is actually fopen() or fopen_safer(). */ -#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - /* Use _O_TEMPORARY when possible, to increase the chances that the - temporary file is removed when the process crashes. */ - if (supports_delete_on_close ()) - { - size_t mode_len = strlen (mode); - char *augmented_mode = (char *) xmalloca (mode_len + 2); - memcpy (augmented_mode, mode, mode_len); - memcpy (augmented_mode + mode_len, "D", 2); - - fp = fopen (file_name, augmented_mode); - saved_errno = errno; - - freea (augmented_mode); - } - else -#endif - { - fp = fopen (file_name, mode); - saved_errno = errno; - } - if (fp != NULL) - { - /* It is sufficient to register fileno (fp) instead of the entire fp, - because at cleanup time there is no need to do an fflush (fp); a - close (fileno (fp)) will be enough. */ - int fd = fileno (fp); - if (!(fd >= 0)) - abort (); - register_fd (fd); - } - unblock_fatal_signals (); - errno = saved_errno; - return fp; -} - -/* Close a temporary file in a temporary directory. - Unregisters the previously registered file descriptor. */ -int -close_temp (int fd) -{ - if (fd >= 0) - { - /* No blocking of signals is needed here, since a double close of a - file descriptor is harmless. */ - int result = close (fd); - int saved_errno = errno; - - /* No race condition here: we assume a single-threaded program, hence - fd cannot be re-opened here. */ - - unregister_fd (fd); - - errno = saved_errno; - return result; - } - else - return close (fd); -} - -/* Close a temporary file in a temporary directory. - Unregisters the previously registered file descriptor. */ -int -fclose_temp (FILE *fp) -{ - int fd = fileno (fp); - /* No blocking of signals is needed here, since a double close of a - file descriptor is harmless. */ - int result = fclose (fp); - int saved_errno = errno; - - /* No race condition here: we assume a single-threaded program, hence - fd cannot be re-opened here. */ - - unregister_fd (fd); - - errno = saved_errno; - return result; -} - -#if GNULIB_FWRITEERROR -/* Like fwriteerror. - Unregisters the previously registered file descriptor. */ -int -fwriteerror_temp (FILE *fp) -{ - int fd = fileno (fp); - /* No blocking of signals is needed here, since a double close of a - file descriptor is harmless. */ - int result = fwriteerror (fp); - int saved_errno = errno; - - /* No race condition here: we assume a single-threaded program, hence - fd cannot be re-opened here. */ - - unregister_fd (fd); - - errno = saved_errno; - return result; -} -#endif - -#if GNULIB_CLOSE_STREAM -/* Like close_stream. - Unregisters the previously registered file descriptor. */ -int -close_stream_temp (FILE *fp) -{ - int fd = fileno (fp); - /* No blocking of signals is needed here, since a double close of a - file descriptor is harmless. */ - int result = close_stream (fp); - int saved_errno = errno; - - /* No race condition here: we assume a single-threaded program, hence - fd cannot be re-opened here. */ - - unregister_fd (fd); - - errno = saved_errno; - return result; -} -#endif diff --git a/contrib/tools/bison/lib/clean-temp.h b/contrib/tools/bison/lib/clean-temp.h deleted file mode 100644 index 24aeca83eb..0000000000 --- a/contrib/tools/bison/lib/clean-temp.h +++ /dev/null @@ -1,142 +0,0 @@ -/* Temporary directories and temporary files with automatic cleanup. - Copyright (C) 2006, 2011-2013 Free Software Foundation, Inc. - Written by Bruno Haible <bruno@clisp.org>, 2006. - - 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 _CLEAN_TEMP_H -#define _CLEAN_TEMP_H - -#include <stdbool.h> -#include <stdio.h> -#include <sys/types.h> - -#ifdef __cplusplus -extern "C" { -#endif - - -/* Temporary directories and temporary files should be automatically removed - when the program exits either normally or through a fatal signal. We can't - rely on the "unlink before close" idiom, because it works only on Unix and - also - if no signal blocking is used - leaves a time window where a fatal - signal would not clean up the temporary file. - - Also, open file descriptors need to be closed before the temporary files - and the temporary directories can be removed, because only on Unix - (excluding Cygwin) can one remove directories containing open files. - - This module provides support for temporary directories and temporary files - inside these temporary directories. Temporary files without temporary - directories are not supported here. The temporary directories and files - are automatically cleaned up (at the latest) when the program exits or - dies from a fatal signal such as SIGINT, SIGTERM, SIGHUP, but not if it - dies from a fatal signal such as SIGQUIT, SIGKILL, or SIGABRT, SIGSEGV, - SIGBUS, SIGILL, SIGFPE. - - For the cleanup in the normal case, programs that use this module need to - call 'cleanup_temp_dir' for each successful return of 'create_temp_dir'. - The cleanup in the case of a fatal signal such as SIGINT, SIGTERM, SIGHUP, - is done entirely automatically by the functions of this module. */ - -struct temp_dir -{ - /* The absolute pathname of the directory. */ - const char * const dir_name; - /* Whether errors during explicit cleanup are reported to standard error. */ - bool cleanup_verbose; - /* More fields are present here, but not public. */ -}; - -/* Create a temporary directory. - PREFIX is used as a prefix for the name of the temporary directory. It - should be short and still give an indication about the program. - PARENTDIR can be used to specify the parent directory; if NULL, a default - parent directory is used (either $TMPDIR or /tmp or similar). - CLEANUP_VERBOSE determines whether errors during explicit cleanup are - reported to standard error. - Return a fresh 'struct temp_dir' on success. Upon error, an error message - is shown and NULL is returned. */ -extern struct temp_dir * create_temp_dir (const char *prefix, - const char *parentdir, - bool cleanup_verbose); - -/* Register the given ABSOLUTE_FILE_NAME as being a file inside DIR, that - needs to be removed before DIR can be removed. - Should be called before the file ABSOLUTE_FILE_NAME is created. */ -extern void register_temp_file (struct temp_dir *dir, - const char *absolute_file_name); - -/* Unregister the given ABSOLUTE_FILE_NAME as being a file inside DIR, that - needs to be removed before DIR can be removed. - Should be called when the file ABSOLUTE_FILE_NAME could not be created. */ -extern void unregister_temp_file (struct temp_dir *dir, - const char *absolute_file_name); - -/* Register the given ABSOLUTE_DIR_NAME as being a subdirectory inside DIR, - that needs to be removed before DIR can be removed. - Should be called before the subdirectory ABSOLUTE_DIR_NAME is created. */ -extern void register_temp_subdir (struct temp_dir *dir, - const char *absolute_dir_name); - -/* Unregister the given ABSOLUTE_DIR_NAME as being a subdirectory inside DIR, - that needs to be removed before DIR can be removed. - Should be called when the subdirectory ABSOLUTE_DIR_NAME could not be - created. */ -extern void unregister_temp_subdir (struct temp_dir *dir, - const char *absolute_dir_name); - -/* Remove the given ABSOLUTE_FILE_NAME and unregister it. - Return 0 upon success, or -1 if there was some problem. */ -extern int cleanup_temp_file (struct temp_dir *dir, - const char *absolute_file_name); - -/* Remove the given ABSOLUTE_DIR_NAME and unregister it. - Return 0 upon success, or -1 if there was some problem. */ -extern int cleanup_temp_subdir (struct temp_dir *dir, - const char *absolute_dir_name); - -/* Remove all registered files and subdirectories inside DIR. - Return 0 upon success, or -1 if there was some problem. */ -extern int cleanup_temp_dir_contents (struct temp_dir *dir); - -/* Remove all registered files and subdirectories inside DIR and DIR itself. - DIR cannot be used any more after this call. - Return 0 upon success, or -1 if there was some problem. */ -extern int cleanup_temp_dir (struct temp_dir *dir); - -/* Open a temporary file in a temporary directory. - Registers the resulting file descriptor to be closed. */ -extern int open_temp (const char *file_name, int flags, mode_t mode); -extern FILE * fopen_temp (const char *file_name, const char *mode); - -/* Close a temporary file in a temporary directory. - Unregisters the previously registered file descriptor. */ -extern int close_temp (int fd); -extern int fclose_temp (FILE *fp); - -/* Like fwriteerror. - Unregisters the previously registered file descriptor. */ -extern int fwriteerror_temp (FILE *fp); - -/* Like close_stream. - Unregisters the previously registered file descriptor. */ -extern int close_stream_temp (FILE *fp); - - -#ifdef __cplusplus -} -#endif - -#endif /* _CLEAN_TEMP_H */ diff --git a/contrib/tools/bison/lib/closein.c b/contrib/tools/bison/lib/closein.c deleted file mode 100644 index c9bf73781f..0000000000 --- a/contrib/tools/bison/lib/closein.c +++ /dev/null @@ -1,112 +0,0 @@ -/* Close standard input, rewinding seekable stdin if necessary. - - Copyright (C) 2007, 2009-2013 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 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/>. */ - -#include <config.h> - -#include "closein.h" - -#include <errno.h> -#include <stdbool.h> -#include "stdio--.h" -#include <unistd.h> - -#include "gettext.h" -#define _(msgid) gettext (msgid) - -#include "close-stream.h" -#include "closeout.h" -#include "error.h" -#include "exitfail.h" -#include "freadahead.h" -#include "quotearg.h" - -static const char *file_name; - -/* Set the file name to be reported in the event an error is detected - on stdin by close_stdin. See also close_stdout_set_file_name, if - an error is detected when closing stdout. */ -void -close_stdin_set_file_name (const char *file) -{ - file_name = file; -} - -/* Close standard input, rewinding any unused input if stdin is - seekable. On error, issue a diagnostic and _exit with status - 'exit_failure'. Then call close_stdout. - - Most programs can get by with close_stdout. close_stdin is only - needed when a program wants to guarantee that partially read input - from seekable stdin is not consumed, for any subsequent clients. - For example, POSIX requires that these two commands behave alike: - - (sed -ne 1q; cat) < file - tail -n +2 file - - Since close_stdin is commonly registered via 'atexit', POSIX - and the C standard both say that it should not call 'exit', - because the behavior is undefined if 'exit' is called more than - once. So it calls '_exit' instead of 'exit'. If close_stdin - is registered via atexit before other functions are registered, - the other functions can act before this _exit is invoked. - - Applications that use close_stdout should flush any streams other - than stdin, stdout, and stderr before exiting, since the call to - _exit will bypass other buffer flushing. Applications should be - flushing and closing other streams anyway, to check for I/O errors. - Also, applications should not use tmpfile, since _exit can bypass - the removal of these files. - - It's important to detect such failures and exit nonzero because many - tools (most notably 'make' and other build-management systems) depend - on being able to detect failure in other tools via their exit status. */ - -void -close_stdin (void) -{ - bool fail = false; - - /* There is no need to flush stdin if we can determine quickly that stdin's - input buffer is empty; in this case we know that if stdin is seekable, - (fseeko (stdin, 0, SEEK_CUR), ftello (stdin)) - == lseek (0, 0, SEEK_CUR). */ - if (freadahead (stdin) > 0) - { - /* Only attempt flush if stdin is seekable, as fflush is entitled to - fail on non-seekable streams. */ - if (fseeko (stdin, 0, SEEK_CUR) == 0 && fflush (stdin) != 0) - fail = true; - } - if (close_stream (stdin) != 0) - fail = true; - if (fail) - { - /* Report failure, but defer exit until after closing stdout, - since the failure report should still be flushed. */ - char const *close_error = _("error closing file"); - if (file_name) - error (0, errno, "%s: %s", quotearg_colon (file_name), - close_error); - else - error (0, errno, "%s", close_error); - } - - close_stdout (); - - if (fail) - _exit (exit_failure); -} diff --git a/contrib/tools/bison/lib/closein.h b/contrib/tools/bison/lib/closein.h deleted file mode 100644 index 84bbeefceb..0000000000 --- a/contrib/tools/bison/lib/closein.h +++ /dev/null @@ -1,32 +0,0 @@ -/* Close standard input, rewinding seekable stdin if necessary. - - Copyright (C) 2007, 2009-2013 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 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 _GL_CLOSEIN_H -# define _GL_CLOSEIN_H 1 - -# ifdef __cplusplus -extern "C" { -# endif - -void close_stdin_set_file_name (const char *file); -void close_stdin (void); - -# ifdef __cplusplus -} -# endif - -#endif diff --git a/contrib/tools/bison/lib/execute.c b/contrib/tools/bison/lib/execute.c deleted file mode 100644 index 1bb577100e..0000000000 --- a/contrib/tools/bison/lib/execute.c +++ /dev/null @@ -1,279 +0,0 @@ -/* Creation of autonomous subprocesses. - Copyright (C) 2001-2004, 2006-2013 Free Software Foundation, Inc. - Written by Bruno Haible <haible@clisp.cons.org>, 2001. - - 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/>. */ - - -#include <config.h> - -/* Specification. */ -#include "execute.h" - -#include <errno.h> -#include <fcntl.h> -#include <stdbool.h> -#include <stdlib.h> -#include <signal.h> -#include <unistd.h> - -#include "penviron.h" -#include "error.h" -#include "fatal-signal.h" -#include "wait-process.h" -#include "gettext.h" - -#define _(str) gettext (str) - -#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - -/* Native Windows API. */ -# include <process.h> -# include "w32spawn.h" - -#else - -/* Unix API. */ -# include <spawn.h> - -#endif - -/* The results of open() in this file are not used with fchdir, - therefore save some unnecessary work in fchdir.c. */ -#undef open -#undef close - - -#if defined EINTR && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__) - -/* EINTR handling for close(), open(). - These functions can return -1/EINTR even though we don't have any - signal handlers set up, namely when we get interrupted via SIGSTOP. */ - -static int -nonintr_close (int fd) -{ - int retval; - - do - retval = close (fd); - while (retval < 0 && errno == EINTR); - - return retval; -} -#define close nonintr_close - -static int -nonintr_open (const char *pathname, int oflag, mode_t mode) -{ - int retval; - - do - retval = open (pathname, oflag, mode); - while (retval < 0 && errno == EINTR); - - return retval; -} -#undef open /* avoid warning on VMS */ -#define open nonintr_open - -#endif - - -/* Execute a command, optionally redirecting any of the three standard file - descriptors to /dev/null. Return its exit code. - If it didn't terminate correctly, exit if exit_on_error is true, otherwise - return 127. - If slave_process is true, the child process will be terminated when its - creator receives a catchable fatal signal. */ -int -execute (const char *progname, - const char *prog_path, char **prog_argv, - bool ignore_sigpipe, - bool null_stdin, bool null_stdout, bool null_stderr, - bool slave_process, bool exit_on_error, - int *termsigp) -{ -#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - - /* Native Windows API. */ - int orig_stdin; - int orig_stdout; - int orig_stderr; - int exitcode; - int nullinfd; - int nulloutfd; - - /* FIXME: Need to free memory allocated by prepare_spawn. */ - prog_argv = prepare_spawn (prog_argv); - - /* Save standard file handles of parent process. */ - if (null_stdin) - orig_stdin = dup_safer_noinherit (STDIN_FILENO); - if (null_stdout) - orig_stdout = dup_safer_noinherit (STDOUT_FILENO); - if (null_stderr) - orig_stderr = dup_safer_noinherit (STDERR_FILENO); - exitcode = -1; - - /* Create standard file handles of child process. */ - nullinfd = -1; - nulloutfd = -1; - if ((!null_stdin - || ((nullinfd = open ("NUL", O_RDONLY, 0)) >= 0 - && (nullinfd == STDIN_FILENO - || (dup2 (nullinfd, STDIN_FILENO) >= 0 - && close (nullinfd) >= 0)))) - && (!(null_stdout || null_stderr) - || ((nulloutfd = open ("NUL", O_RDWR, 0)) >= 0 - && (!null_stdout - || nulloutfd == STDOUT_FILENO - || dup2 (nulloutfd, STDOUT_FILENO) >= 0) - && (!null_stderr - || nulloutfd == STDERR_FILENO - || dup2 (nulloutfd, STDERR_FILENO) >= 0) - && ((null_stdout && nulloutfd == STDOUT_FILENO) - || (null_stderr && nulloutfd == STDERR_FILENO) - || close (nulloutfd) >= 0)))) - /* Use spawnvpe and pass the environment explicitly. This is needed if - the program has modified the environment using putenv() or [un]setenv(). - On Windows, programs have two environments, one in the "environment - block" of the process and managed through SetEnvironmentVariable(), and - one inside the process, in the location retrieved by the 'environ' - macro. When using spawnvp() without 'e', the child process inherits a - copy of the environment block - ignoring the effects of putenv() and - [un]setenv(). */ - { - exitcode = spawnvpe (P_WAIT, prog_path, (const char **) prog_argv, - (const char **) environ); - if (exitcode < 0 && errno == ENOEXEC) - { - /* prog is not a native executable. Try to execute it as a - shell script. Note that prepare_spawn() has already prepended - a hidden element "sh.exe" to prog_argv. */ - --prog_argv; - exitcode = spawnvpe (P_WAIT, prog_argv[0], (const char **) prog_argv, - (const char **) environ); - } - } - if (nulloutfd >= 0) - close (nulloutfd); - if (nullinfd >= 0) - close (nullinfd); - - /* Restore standard file handles of parent process. */ - if (null_stderr) - undup_safer_noinherit (orig_stderr, STDERR_FILENO); - if (null_stdout) - undup_safer_noinherit (orig_stdout, STDOUT_FILENO); - if (null_stdin) - undup_safer_noinherit (orig_stdin, STDIN_FILENO); - - if (termsigp != NULL) - *termsigp = 0; - - if (exitcode == -1) - { - if (exit_on_error || !null_stderr) - error (exit_on_error ? EXIT_FAILURE : 0, errno, - _("%s subprocess failed"), progname); - return 127; - } - - return exitcode; - -#else - - /* Unix API. */ - /* Note about 127: Some errors during posix_spawnp() cause the function - posix_spawnp() to return an error code; some other errors cause the - subprocess to exit with return code 127. It is implementation - dependent which error is reported which way. We treat both cases as - equivalent. */ - sigset_t blocked_signals; - posix_spawn_file_actions_t actions; - bool actions_allocated; - posix_spawnattr_t attrs; - bool attrs_allocated; - int err; - pid_t child; - - if (slave_process) - { - sigprocmask (SIG_SETMASK, NULL, &blocked_signals); - block_fatal_signals (); - } - actions_allocated = false; - attrs_allocated = false; - if ((err = posix_spawn_file_actions_init (&actions)) != 0 - || (actions_allocated = true, - (null_stdin - && (err = posix_spawn_file_actions_addopen (&actions, - STDIN_FILENO, - "/dev/null", O_RDONLY, - 0)) - != 0) - || (null_stdout - && (err = posix_spawn_file_actions_addopen (&actions, - STDOUT_FILENO, - "/dev/null", O_RDWR, - 0)) - != 0) - || (null_stderr - && (err = posix_spawn_file_actions_addopen (&actions, - STDERR_FILENO, - "/dev/null", O_RDWR, - 0)) - != 0) - || (slave_process - && ((err = posix_spawnattr_init (&attrs)) != 0 - || (attrs_allocated = true, - (err = posix_spawnattr_setsigmask (&attrs, - &blocked_signals)) - != 0 - || (err = posix_spawnattr_setflags (&attrs, - POSIX_SPAWN_SETSIGMASK)) - != 0))) - || (err = posix_spawnp (&child, prog_path, &actions, - attrs_allocated ? &attrs : NULL, prog_argv, - environ)) - != 0)) - { - if (actions_allocated) - posix_spawn_file_actions_destroy (&actions); - if (attrs_allocated) - posix_spawnattr_destroy (&attrs); - if (slave_process) - unblock_fatal_signals (); - if (termsigp != NULL) - *termsigp = 0; - if (exit_on_error || !null_stderr) - error (exit_on_error ? EXIT_FAILURE : 0, err, - _("%s subprocess failed"), progname); - return 127; - } - posix_spawn_file_actions_destroy (&actions); - if (attrs_allocated) - posix_spawnattr_destroy (&attrs); - if (slave_process) - { - register_slave_subprocess (child); - unblock_fatal_signals (); - } - - return wait_subprocess (child, progname, ignore_sigpipe, null_stderr, - slave_process, exit_on_error, termsigp); - -#endif -} diff --git a/contrib/tools/bison/lib/execute.h b/contrib/tools/bison/lib/execute.h deleted file mode 100644 index 1fdc2abbad..0000000000 --- a/contrib/tools/bison/lib/execute.h +++ /dev/null @@ -1,44 +0,0 @@ -/* Creation of autonomous subprocesses. - Copyright (C) 2001-2003, 2008-2013 Free Software Foundation, Inc. - Written by Bruno Haible <haible@clisp.cons.org>, 2001. - - 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 _EXECUTE_H -#define _EXECUTE_H - -#include <stdbool.h> - -/* Execute a command, optionally redirecting any of the three standard file - descriptors to /dev/null. Return its exit code. - If it didn't terminate correctly, exit if exit_on_error is true, otherwise - return 127. - If ignore_sigpipe is true, consider a subprocess termination due to SIGPIPE - as equivalent to a success. This is suitable for processes whose only - purpose is to write to standard output. - If slave_process is true, the child process will be terminated when its - creator receives a catchable fatal signal. - If termsigp is not NULL, *termsig will be set to the signal that terminated - the subprocess (if supported by the platform: not on native Windows - platforms), otherwise 0. - It is recommended that no signal is blocked or ignored while execute() - is called. See pipe.h for the reason. */ -extern int execute (const char *progname, - const char *prog_path, char **prog_argv, - bool ignore_sigpipe, - bool null_stdin, bool null_stdout, bool null_stderr, - bool slave_process, bool exit_on_error, - int *termsigp); - -#endif /* _EXECUTE_H */ diff --git a/contrib/tools/bison/lib/fclose.c b/contrib/tools/bison/lib/fclose.c deleted file mode 100644 index 90ed653a0e..0000000000 --- a/contrib/tools/bison/lib/fclose.c +++ /dev/null @@ -1,110 +0,0 @@ -/* fclose replacement. - Copyright (C) 2008-2013 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 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/>. */ - -#include <config.h> - -/* Specification. */ -#include <stdio.h> - -#include <errno.h> -#include <unistd.h> - -#include "freading.h" -#include "msvc-inval.h" - -#undef fclose - -#if HAVE_MSVC_INVALID_PARAMETER_HANDLER -static int -fclose_nothrow (FILE *fp) -{ - int result; - - TRY_MSVC_INVAL - { - result = fclose (fp); - } - CATCH_MSVC_INVAL - { - result = EOF; - errno = EBADF; - } - DONE_MSVC_INVAL; - - return result; -} -#else -# define fclose_nothrow fclose -#endif - -/* Override fclose() to call the overridden fflush() or close(). */ - -int -rpl_fclose (FILE *fp) -{ - int saved_errno = 0; - int fd; - int result = 0; - - /* Don't change behavior on memstreams. */ - fd = fileno (fp); - if (fd < 0) - return fclose_nothrow (fp); - - /* We only need to flush the file if it is not reading or if it is - seekable. This only guarantees the file position of input files - if the fflush module is also in use. */ - if ((!freading (fp) || lseek (fileno (fp), 0, SEEK_CUR) != -1) - && fflush (fp)) - saved_errno = errno; - - /* fclose() calls close(), but we need to also invoke all hooks that our - overridden close() function invokes. See lib/close.c. */ -#if WINDOWS_SOCKETS - /* Call the overridden close(), then the original fclose(). - Note about multithread-safety: There is a race condition where some - other thread could open fd between our close and fclose. */ - if (close (fd) < 0 && saved_errno == 0) - saved_errno = errno; - - fclose_nothrow (fp); /* will fail with errno = EBADF, - if we did not lose a race */ - -#else /* !WINDOWS_SOCKETS */ - /* Call fclose() and invoke all hooks of the overridden close(). */ - -# if REPLACE_FCHDIR - /* Note about multithread-safety: There is a race condition here as well. - Some other thread could open fd between our calls to fclose and - _gl_unregister_fd. */ - result = fclose_nothrow (fp); - if (result == 0) - _gl_unregister_fd (fd); -# else - /* No race condition here. */ - result = fclose_nothrow (fp); -# endif - -#endif /* !WINDOWS_SOCKETS */ - - if (saved_errno != 0) - { - errno = saved_errno; - result = EOF; - } - - return result; -} diff --git a/contrib/tools/bison/lib/fflush.c b/contrib/tools/bison/lib/fflush.c deleted file mode 100644 index c182ac1fa4..0000000000 --- a/contrib/tools/bison/lib/fflush.c +++ /dev/null @@ -1,225 +0,0 @@ -/* fflush.c -- allow flushing input streams - Copyright (C) 2007-2013 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 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 Eric Blake. */ - -#include <config.h> - -/* Specification. */ -#include "stdio--.h" - -#include <errno.h> -#include <unistd.h> - -#include "freading.h" - -#include "stdio-impl.h" - -#include "unused-parameter.h" - -#undef fflush - - -#if defined _IO_EOF_SEEN || defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */ - -/* Clear the stream's ungetc buffer, preserving the value of ftello (fp). */ -static void -clear_ungetc_buffer_preserving_position (FILE *fp) -{ - if (fp->_flags & _IO_IN_BACKUP) - /* _IO_free_backup_area is a bit complicated. Simply call fseek. */ - fseeko (fp, 0, SEEK_CUR); -} - -#else - -/* Clear the stream's ungetc buffer. May modify the value of ftello (fp). */ -static void -clear_ungetc_buffer (FILE *fp) -{ -# if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */ - if (HASUB (fp)) - { - fp_->_p += fp_->_r; - fp_->_r = 0; - } -# elif defined __EMX__ /* emx+gcc */ - if (fp->_ungetc_count > 0) - { - fp->_ungetc_count = 0; - fp->_rcount = - fp->_rcount; - } -# elif defined _IOERR /* Minix, AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw, NonStop Kernel */ - /* Nothing to do. */ -# else /* other implementations */ - fseeko (fp, 0, SEEK_CUR); -# endif -} - -#endif - -#if ! (defined _IO_EOF_SEEN || defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */) - -# if (defined __sferror || defined __DragonFly__) && defined __SNPT /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */ - -static int -disable_seek_optimization (FILE *fp) -{ - int saved_flags = fp_->_flags & (__SOPT | __SNPT); - fp_->_flags = (fp_->_flags & ~__SOPT) | __SNPT; - return saved_flags; -} - -static void -restore_seek_optimization (FILE *fp, int saved_flags) -{ - fp_->_flags = (fp_->_flags & ~(__SOPT | __SNPT)) | saved_flags; -} - -# else - -static void -update_fpos_cache (FILE *fp _GL_UNUSED_PARAMETER, - off_t pos _GL_UNUSED_PARAMETER) -{ -# if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */ -# if defined __CYGWIN__ - /* fp_->_offset is typed as an integer. */ - fp_->_offset = pos; -# else - /* fp_->_offset is an fpos_t. */ - /* Use a union, since on NetBSD, the compilation flags determine - whether fpos_t is typedef'd to off_t or a struct containing a - single off_t member. */ - union - { - fpos_t f; - off_t o; - } u; - u.o = pos; - fp_->_offset = u.f; -# endif - fp_->_flags |= __SOFF; -# endif -} -# endif -#endif - -/* Flush all pending data on STREAM according to POSIX rules. Both - output and seekable input streams are supported. */ -int -rpl_fflush (FILE *stream) -{ - /* When stream is NULL, POSIX and C99 only require flushing of "output - streams and update streams in which the most recent operation was not - input", and all implementations do this. - - When stream is "an output stream or an update stream in which the most - recent operation was not input", POSIX and C99 requires that fflush - writes out any buffered data, and all implementations do this. - - When stream is, however, an input stream or an update stream in - which the most recent operation was input, C99 specifies nothing, - and POSIX only specifies behavior if the stream is seekable. - mingw, in particular, drops the input buffer, leaving the file - descriptor positioned at the end of the input buffer. I.e. ftell - (stream) is lost. We don't want to call the implementation's - fflush in this case. - - We test ! freading (stream) here, rather than fwriting (stream), because - what we need to know is whether the stream holds a "read buffer", and on - mingw this is indicated by _IOREAD, regardless of _IOWRT. */ - if (stream == NULL || ! freading (stream)) - return fflush (stream); - -#if defined _IO_EOF_SEEN || defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */ - - clear_ungetc_buffer_preserving_position (stream); - - return fflush (stream); - -#else - { - /* Notes about the file-position indicator: - 1) The file position indicator is incremented by fgetc() and decremented - by ungetc(): - <http://www.opengroup.org/susv3/functions/fgetc.html> - "... the fgetc() function shall ... advance the associated file - position indicator for the stream ..." - <http://www.opengroup.org/susv3/functions/ungetc.html> - "The file-position indicator is decremented by each successful - call to ungetc()..." - 2) <http://www.opengroup.org/susv3/functions/ungetc.html> says: - "The value of the file-position indicator for the stream after - reading or discarding all pushed-back bytes shall be the same - as it was before the bytes were pushed back." - Here we are discarding all pushed-back bytes. But more specifically, - 3) <http://www.opengroup.org/austin/aardvark/latest/xshbug3.txt> says: - "[After fflush(),] the file offset of the underlying open file - description shall be set to the file position of the stream, and - any characters pushed back onto the stream by ungetc() ... shall - be discarded." */ - - /* POSIX does not specify fflush behavior for non-seekable input - streams. Some implementations purge unread data, some return - EBADF, some do nothing. */ - off_t pos = ftello (stream); - if (pos == -1) - { - errno = EBADF; - return EOF; - } - - /* Clear the ungetc buffer. */ - clear_ungetc_buffer (stream); - - /* To get here, we must be flushing a seekable input stream, so the - semantics of fpurge are now appropriate to clear the buffer. To - avoid losing data, the lseek is also necessary. */ - { - int result = fpurge (stream); - if (result != 0) - return result; - } - -# if (defined __sferror || defined __DragonFly__) && defined __SNPT /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */ - - { - /* Disable seek optimization for the next fseeko call. This tells the - following fseeko call to seek to the desired position directly, rather - than to seek to a block-aligned boundary. */ - int saved_flags = disable_seek_optimization (stream); - int result = fseeko (stream, pos, SEEK_SET); - - restore_seek_optimization (stream, saved_flags); - return result; - } - -# else - - pos = lseek (fileno (stream), pos, SEEK_SET); - if (pos == -1) - return EOF; - /* After a successful lseek, update the file descriptor's position cache - in the stream. */ - update_fpos_cache (stream, pos); - - return 0; - -# endif - } -#endif -} diff --git a/contrib/tools/bison/lib/filenamecat-lgpl.c b/contrib/tools/bison/lib/filenamecat-lgpl.c deleted file mode 100644 index 60c4988b4d..0000000000 --- a/contrib/tools/bison/lib/filenamecat-lgpl.c +++ /dev/null @@ -1,88 +0,0 @@ -/* Concatenate two arbitrary file names. - - Copyright (C) 1996-2007, 2009-2013 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 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 Jim Meyering. */ - -#include <config.h> - -/* Specification. */ -#include "filenamecat.h" - -#include <stdlib.h> -#include <string.h> - -#include "dirname.h" - -#if ! HAVE_MEMPCPY && ! defined mempcpy -# define mempcpy(D, S, N) ((void *) ((char *) memcpy (D, S, N) + (N))) -#endif - -/* Return the longest suffix of F that is a relative file name. - If it has no such suffix, return the empty string. */ - -static char const * _GL_ATTRIBUTE_PURE -longest_relative_suffix (char const *f) -{ - for (f += FILE_SYSTEM_PREFIX_LEN (f); ISSLASH (*f); f++) - continue; - return f; -} - -/* Concatenate two file name components, DIR and ABASE, in - newly-allocated storage and return the result. - The resulting file name F is such that the commands "ls F" and "(cd - DIR; ls BASE)" refer to the same file, where BASE is ABASE with any - file system prefixes and leading separators removed. - Arrange for a directory separator if necessary between DIR and BASE - in the result, removing any redundant separators. - In any case, if BASE_IN_RESULT is non-NULL, set - *BASE_IN_RESULT to point to the copy of ABASE in the returned - concatenation. However, if ABASE begins with more than one slash, - set *BASE_IN_RESULT to point to the sole corresponding slash that - is copied into the result buffer. - - Return NULL if malloc fails. */ - -char * -mfile_name_concat (char const *dir, char const *abase, char **base_in_result) -{ - char const *dirbase = last_component (dir); - size_t dirbaselen = base_len (dirbase); - size_t dirlen = dirbase - dir + dirbaselen; - size_t needs_separator = (dirbaselen && ! ISSLASH (dirbase[dirbaselen - 1])); - - char const *base = longest_relative_suffix (abase); - size_t baselen = strlen (base); - - char *p_concat = malloc (dirlen + needs_separator + baselen + 1); - char *p; - - if (p_concat == NULL) - return NULL; - - p = mempcpy (p_concat, dir, dirlen); - *p = DIRECTORY_SEPARATOR; - p += needs_separator; - - if (base_in_result) - *base_in_result = p - IS_ABSOLUTE_FILE_NAME (abase); - - p = mempcpy (p, base, baselen); - *p = '\0'; - - return p_concat; -} diff --git a/contrib/tools/bison/lib/filenamecat.c b/contrib/tools/bison/lib/filenamecat.c deleted file mode 100644 index 8809b571f5..0000000000 --- a/contrib/tools/bison/lib/filenamecat.c +++ /dev/null @@ -1,41 +0,0 @@ -/* Concatenate two arbitrary file names. - - Copyright (C) 1996-2007, 2009-2013 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 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 Jim Meyering. */ - -#include <config.h> - -/* Specification. */ -#include "filenamecat.h" - -#include <stdlib.h> -#include <string.h> - -#include "xalloc.h" - -/* Just like mfile_name_concat (filenamecat-lgpl.c), except, rather than - returning NULL upon malloc failure, here, we report the - "memory exhausted" condition and exit. */ - -char * -file_name_concat (char const *dir, char const *abase, char **base_in_result) -{ - char *p = mfile_name_concat (dir, abase, base_in_result); - if (p == NULL) - xalloc_die (); - return p; -} diff --git a/contrib/tools/bison/lib/filenamecat.h b/contrib/tools/bison/lib/filenamecat.h deleted file mode 100644 index 1476e14c74..0000000000 --- a/contrib/tools/bison/lib/filenamecat.h +++ /dev/null @@ -1,27 +0,0 @@ -/* Concatenate two arbitrary file names. - - Copyright (C) 1996-1997, 2003, 2005, 2007, 2009-2013 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 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 Jim Meyering. */ - -#if GNULIB_FILENAMECAT -char *file_name_concat (char const *dir, char const *base, - char **base_in_result); -#endif - -char *mfile_name_concat (char const *dir, char const *base, - char **base_in_result); diff --git a/contrib/tools/bison/lib/float.c b/contrib/tools/bison/lib/float.c deleted file mode 100644 index 366945fa38..0000000000 --- a/contrib/tools/bison/lib/float.c +++ /dev/null @@ -1,33 +0,0 @@ -/* Auxiliary definitions for <float.h>. - Copyright (C) 2011-2013 Free Software Foundation, Inc. - Written by Bruno Haible <bruno@clisp.org>, 2011. - - 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/>. */ - -#include <config.h> - -/* Specification. */ -#include <float.h> - -#if (defined _ARCH_PPC || defined _POWER) && (defined _AIX || defined __linux__) && (LDBL_MANT_DIG == 106) && defined __GNUC__ -const union gl_long_double_union gl_LDBL_MAX = - { { DBL_MAX, DBL_MAX / (double)134217728UL / (double)134217728UL } }; -#elif defined __i386__ -const union gl_long_double_union gl_LDBL_MAX = - { { 0xFFFFFFFF, 0xFFFFFFFF, 32766 } }; -#else -/* This declaration is solely to ensure that after preprocessing - this file is never empty. */ -typedef int dummy; -#endif diff --git a/contrib/tools/bison/lib/fpurge.c b/contrib/tools/bison/lib/fpurge.c deleted file mode 100644 index 09c9ea82c7..0000000000 --- a/contrib/tools/bison/lib/fpurge.c +++ /dev/null @@ -1,150 +0,0 @@ -/* Flushing buffers of a FILE stream. - Copyright (C) 2007-2013 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 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/>. */ - -#include <config.h> - -/* Specification. */ -#include <stdio.h> - -#if HAVE___FPURGE /* glibc >= 2.2, Haiku, Solaris >= 7 */ -# include <stdio_ext.h> -#endif -#include <stdlib.h> - -#include "stdio-impl.h" - -int -fpurge (FILE *fp) -{ -#if HAVE___FPURGE /* glibc >= 2.2, Haiku, Solaris >= 7, musl libc */ - - __fpurge (fp); - /* The __fpurge function does not have a return value. */ - return 0; - -#elif HAVE_FPURGE /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin 1.7 */ - - /* Call the system's fpurge function. */ -# undef fpurge -# if !HAVE_DECL_FPURGE - extern int fpurge (FILE *); -# endif - int result = fpurge (fp); -# if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */ - if (result == 0) - /* Correct the invariants that fpurge broke. - <stdio.h> on BSD systems says: - "The following always hold: if _flags & __SRD, _w is 0." - If this invariant is not fulfilled and the stream is read-write but - currently reading, subsequent putc or fputc calls will write directly - into the buffer, although they shouldn't be allowed to. */ - if ((fp_->_flags & __SRD) != 0) - fp_->_w = 0; -# endif - return result; - -#else - - /* Most systems provide FILE as a struct and the necessary bitmask in - <stdio.h>, because they need it for implementing getc() and putc() as - fast macros. */ -# if defined _IO_EOF_SEEN || defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */ - fp->_IO_read_end = fp->_IO_read_ptr; - fp->_IO_write_ptr = fp->_IO_write_base; - /* Avoid memory leak when there is an active ungetc buffer. */ - if (fp->_IO_save_base != NULL) - { - free (fp->_IO_save_base); - fp->_IO_save_base = NULL; - } - return 0; -# elif defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */ - fp_->_p = fp_->_bf._base; - fp_->_r = 0; - fp_->_w = ((fp_->_flags & (__SLBF | __SNBF | __SRD)) == 0 /* fully buffered and not currently reading? */ - ? fp_->_bf._size - : 0); - /* Avoid memory leak when there is an active ungetc buffer. */ - if (fp_ub._base != NULL) - { - if (fp_ub._base != fp_->_ubuf) - free (fp_ub._base); - fp_ub._base = NULL; - } - return 0; -# elif defined __EMX__ /* emx+gcc */ - fp->_ptr = fp->_buffer; - fp->_rcount = 0; - fp->_wcount = 0; - fp->_ungetc_count = 0; - return 0; -# elif defined __minix /* Minix */ - fp->_ptr = fp->_buf; - if (fp->_ptr != NULL) - fp->_count = 0; - return 0; -# elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw, NonStop Kernel */ - fp->_ptr = fp->_base; - if (fp->_ptr != NULL) - fp->_cnt = 0; - return 0; -# elif WIN_SDK10 - ((TWinSdk10File*)fp)->_ptr = ((TWinSdk10File*)fp)->_base; - if (((TWinSdk10File*)fp)->_ptr != NULL) - ((TWinSdk10File*)fp)->_cnt = 0; - return 0; -# elif defined __UCLIBC__ /* uClibc */ -# ifdef __STDIO_BUFFERS - if (fp->__modeflags & __FLAG_WRITING) - fp->__bufpos = fp->__bufstart; - else if (fp->__modeflags & (__FLAG_READONLY | __FLAG_READING)) - fp->__bufpos = fp->__bufread; -# endif - return 0; -# elif defined __QNX__ /* QNX */ - fp->_Rback = fp->_Back + sizeof (fp->_Back); - fp->_Rsave = NULL; - if (fp->_Mode & 0x2000 /* _MWRITE */) - /* fp->_Buf <= fp->_Next <= fp->_Wend */ - fp->_Next = fp->_Buf; - else - /* fp->_Buf <= fp->_Next <= fp->_Rend */ - fp->_Rend = fp->_Next; - return 0; -# elif defined __MINT__ /* Atari FreeMiNT */ - if (fp->__pushed_back) - { - fp->__bufp = fp->__pushback_bufp; - fp->__pushed_back = 0; - } - /* Preserve the current file position. */ - if (fp->__target != -1) - fp->__target += fp->__bufp - fp->__buffer; - fp->__bufp = fp->__buffer; - /* Nothing in the buffer, next getc is nontrivial. */ - fp->__get_limit = fp->__bufp; - /* Nothing in the buffer, next putc is nontrivial. */ - fp->__put_limit = fp->__buffer; - return 0; -# elif defined EPLAN9 /* Plan9 */ - fp->rp = fp->wp = fp->lp = fp->buf; - return 0; -# else -# error "Please port gnulib fpurge.c to your platform! Look at the definitions of fflush, setvbuf and ungetc on your system, then report this to bug-gnulib." -# endif - -#endif -} diff --git a/contrib/tools/bison/lib/freadahead.c b/contrib/tools/bison/lib/freadahead.c deleted file mode 100644 index ae24e3b8a3..0000000000 --- a/contrib/tools/bison/lib/freadahead.c +++ /dev/null @@ -1,97 +0,0 @@ -/* Retrieve information about a FILE stream. - Copyright (C) 2007-2013 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 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/>. */ - -#include <config.h> - -/* Specification. */ -#include "freadahead.h" - -#include <stdlib.h> -#include "stdio-impl.h" - -size_t -freadahead (FILE *fp) -{ -#if defined _IO_EOF_SEEN || defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */ - if (fp->_IO_write_ptr > fp->_IO_write_base) - return 0; - return (fp->_IO_read_end - fp->_IO_read_ptr) - + (fp->_flags & _IO_IN_BACKUP ? fp->_IO_save_end - fp->_IO_save_base : - 0); -#elif defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */ - if ((fp_->_flags & __SWR) != 0 || fp_->_r < 0) - return 0; -# if defined __DragonFly__ - return __sreadahead (fp); -# else - return fp_->_r - + (HASUB (fp) ? fp_->_ur : 0); -# endif -#elif defined __EMX__ /* emx+gcc */ - if ((fp->_flags & _IOWRT) != 0) - return 0; - /* Note: fp->_ungetc_count > 0 implies fp->_rcount <= 0, - fp->_ungetc_count = 0 implies fp->_rcount >= 0. */ - /* equivalent to - (fp->_ungetc_count == 0 ? fp->_rcount : fp->_ungetc_count - fp->_rcount) */ - return (fp->_rcount > 0 ? fp->_rcount : fp->_ungetc_count - fp->_rcount); -#elif defined __minix /* Minix */ - if ((fp_->_flags & _IOWRITING) != 0) - return 0; - return fp_->_count; -#elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw, NonStop Kernel */ - if ((fp_->_flag & _IOWRT) != 0) - return 0; - return fp_->_cnt; -#elif WIN_SDK10 - if ((((TWinSdk10File*)fp)->_flags & WIN_SDK10_IOWRITE) != 0) - return 0; - return ((TWinSdk10File*)fp)->_cnt; -#elif defined __UCLIBC__ /* uClibc */ -# ifdef __STDIO_BUFFERS - if (fp->__modeflags & __FLAG_WRITING) - return 0; - return (fp->__bufread - fp->__bufpos) - + (fp->__modeflags & __FLAG_UNGOT ? 1 : 0); -# else - return 0; -# endif -#elif defined __QNX__ /* QNX */ - if ((fp->_Mode & 0x2000 /* _MWRITE */) != 0) - return 0; - /* fp->_Buf <= fp->_Next <= fp->_Rend, - and fp->_Rend may be overridden by fp->_Rsave. */ - return ((fp->_Rsave ? fp->_Rsave : fp->_Rend) - fp->_Next) - + (fp->_Mode & 0x4000 /* _MBYTE */ - ? (fp->_Back + sizeof (fp->_Back)) - fp->_Rback - : 0); -#elif defined __MINT__ /* Atari FreeMiNT */ - if (!fp->__mode.__read) - return 0; - return (fp->__pushed_back - ? fp->__get_limit - fp->__pushback_bufp + 1 - : fp->__get_limit - fp->__bufp); -#elif defined EPLAN9 /* Plan9 */ - if (fp->state == 4 /* WR */ || fp->rp >= fp->wp) - return 0; - return fp->wp - fp->rp; -#elif defined SLOW_BUT_NO_HACKS /* users can define this */ - abort (); - return 0; -#else - #error "Please port gnulib freadahead.c to your platform! Look at the definition of fflush, fread, ungetc on your system, then report this to bug-gnulib." -#endif -} diff --git a/contrib/tools/bison/lib/freadahead.h b/contrib/tools/bison/lib/freadahead.h deleted file mode 100644 index c691f89c0f..0000000000 --- a/contrib/tools/bison/lib/freadahead.h +++ /dev/null @@ -1,47 +0,0 @@ -/* Retrieve information about a FILE stream. - Copyright (C) 2007-2013 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 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/>. */ - -#include <stddef.h> -#include <stdio.h> - -/* Assuming the stream STREAM is open for reading: - Return the number of bytes waiting in the input buffer of STREAM. - This includes both the bytes that have been read from the underlying input - source and the bytes that have been pushed back through 'ungetc'. - - If this number is 0 and the stream is not currently writing, - fflush (STREAM) is known to be a no-op. - - STREAM must not be wide-character oriented. */ - -#if HAVE___FREADAHEAD /* musl libc */ - -# include <stdio_ext.h> -# define freadahead(stream) __freadahead (stream) - -#else - -# ifdef __cplusplus -extern "C" { -# endif - -extern size_t freadahead (FILE *stream) _GL_ATTRIBUTE_PURE; - -# ifdef __cplusplus -} -# endif - -#endif diff --git a/contrib/tools/bison/lib/freading.c b/contrib/tools/bison/lib/freading.c deleted file mode 100644 index c2ffd93735..0000000000 --- a/contrib/tools/bison/lib/freading.c +++ /dev/null @@ -1,76 +0,0 @@ -/* Retrieve information about a FILE stream. - Copyright (C) 2007-2013 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 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/>. */ - -#include <config.h> - -/* Specification. */ -#include "freading.h" - -#include "stdio-impl.h" - -/* Don't use glibc's __freading function in glibc < 2.7, see - <http://sourceware.org/bugzilla/show_bug.cgi?id=4359> */ -#if !(HAVE___FREADING && (!defined __GLIBC__ || defined __UCLIBC__ || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7))) - -bool -freading (FILE *fp) -{ - /* Most systems provide FILE as a struct and the necessary bitmask in - <stdio.h>, because they need it for implementing getc() and putc() as - fast macros. */ -# if defined _IO_EOF_SEEN || defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */ - return ((fp->_flags & _IO_NO_WRITES) != 0 - || ((fp->_flags & (_IO_NO_READS | _IO_CURRENTLY_PUTTING)) == 0 - && fp->_IO_read_base != NULL)); -# elif defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */ - return (fp_->_flags & __SRD) != 0; -# elif defined __EMX__ /* emx+gcc */ - return (fp->_flags & _IOREAD) != 0; -# elif defined __minix /* Minix */ - return (fp->_flags & _IOREADING) != 0; -# elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw, NonStop Kernel */ -# if defined __sun /* Solaris */ - return (fp->_flag & _IOREAD) != 0 && (fp->_flag & _IOWRT) == 0; -# else - return (fp->_flag & _IOREAD) != 0; -# endif -# elif WIN_SDK10 - return (((TWinSdk10File*)fp)->_flags & WIN_SDK10_IOREAD) != 0; -# elif defined __UCLIBC__ /* uClibc */ - return (fp->__modeflags & (__FLAG_READONLY | __FLAG_READING)) != 0; -# elif defined __QNX__ /* QNX */ - return ((fp->_Mode & 0x2 /* _MOPENW */) == 0 - || (fp->_Mode & 0x1000 /* _MREAD */) != 0); -# elif defined __MINT__ /* Atari FreeMiNT */ - if (!fp->__mode.__write) - return 1; - if (!fp->__mode.__read) - return 0; -# ifdef _IO_CURRENTLY_GETTING /* Flag added on 2009-02-28 */ - return (fp->__flags & _IO_CURRENTLY_GETTING) != 0; -# else - return (fp->__buffer < fp->__get_limit /*|| fp->__bufp == fp->__put_limit ??*/); -# endif -# elif defined EPLAN9 /* Plan9 */ - if (fp->state == 0 /* CLOSED */ || fp->state == 4 /* WR */) - return 0; - return (fp->state == 3 /* RD */ && (fp->bufl == 0 || fp->rp < fp->wp)); -# else -# error "Please port gnulib freading.c to your platform!" -# endif -} - -#endif diff --git a/contrib/tools/bison/lib/freading.h b/contrib/tools/bison/lib/freading.h deleted file mode 100644 index 88ea789ea4..0000000000 --- a/contrib/tools/bison/lib/freading.h +++ /dev/null @@ -1,53 +0,0 @@ -/* Retrieve information about a FILE stream. - Copyright (C) 2007-2013 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 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/>. */ - -#include <stdbool.h> -#include <stdio.h> - -/* Return true if the stream STREAM is opened read-only, or if the - last operation on the stream was a read operation. Return false if - the stream is opened write-only or append-only, or if it supports - writing and there is no current read operation (such as fgetc). - - freading and fwriting will never both be true. If STREAM supports - both reads and writes, then: - - both freading and fwriting might be false when the stream is first - opened, after read encounters EOF, or after fflush, - - freading might be false or true and fwriting might be false - after repositioning (such as fseek, fsetpos, or rewind), - depending on the underlying implementation. - - STREAM must not be wide-character oriented. */ - -#if HAVE___FREADING && (!defined __GLIBC__ || defined __UCLIBC__ || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) -/* Solaris >= 7, not glibc >= 2.2, but glibc >= 2.7, or musl libc */ - -# include <stdio_ext.h> -# define freading(stream) (__freading (stream) != 0) - -#else - -# ifdef __cplusplus -extern "C" { -# endif - -extern bool freading (FILE *stream); - -# ifdef __cplusplus -} -# endif - -#endif diff --git a/contrib/tools/bison/lib/gl_anyhash_list1.h b/contrib/tools/bison/lib/gl_anyhash_list1.h deleted file mode 100644 index 57ead45073..0000000000 --- a/contrib/tools/bison/lib/gl_anyhash_list1.h +++ /dev/null @@ -1,27 +0,0 @@ -/* Sequential list data type implemented by a hash table with another list. - Copyright (C) 2006, 2009-2013 Free Software Foundation, Inc. - Written by Bruno Haible <bruno@clisp.org>, 2006. - - 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/>. */ - -/* Common code of - gl_linkedhash_list.c, gl_avltreehash_list.c, gl_rbtreehash_list.c. */ - -/* Hash table entry. */ -struct gl_hash_entry -{ - struct gl_hash_entry *hash_next; /* chain of entries in same bucket */ - size_t hashcode; /* cache of values' common hash code */ -}; -typedef struct gl_hash_entry * gl_hash_entry_t; diff --git a/contrib/tools/bison/lib/gl_anyhash_list2.h b/contrib/tools/bison/lib/gl_anyhash_list2.h deleted file mode 100644 index 3791ae2432..0000000000 --- a/contrib/tools/bison/lib/gl_anyhash_list2.h +++ /dev/null @@ -1,138 +0,0 @@ -/* Sequential list data type implemented by a hash table with another list. - Copyright (C) 2006, 2009-2013 Free Software Foundation, Inc. - Written by Bruno Haible <bruno@clisp.org>, 2006. - - 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/>. */ - -/* Common code of - gl_linkedhash_list.c, gl_avltreehash_list.c, gl_rbtreehash_list.c. */ - -/* Array of primes, approximately in steps of factor 1.2. - This table was computed by executing the Common Lisp expression - (dotimes (i 244) (format t "nextprime(~D)~%" (ceiling (expt 1.2d0 i)))) - and feeding the result to PARI/gp. */ -static const size_t primes[] = - { - 11, 13, 17, 19, 23, 29, 37, 41, 47, 59, 67, 83, 97, 127, 139, 167, 199, - 239, 293, 347, 419, 499, 593, 709, 853, 1021, 1229, 1471, 1777, 2129, 2543, - 3049, 3659, 4391, 5273, 6323, 7589, 9103, 10937, 13109, 15727, 18899, - 22651, 27179, 32609, 39133, 46957, 56359, 67619, 81157, 97369, 116849, - 140221, 168253, 201907, 242309, 290761, 348889, 418667, 502409, 602887, - 723467, 868151, 1041779, 1250141, 1500181, 1800191, 2160233, 2592277, - 3110741, 3732887, 4479463, 5375371, 6450413, 7740517, 9288589, 11146307, - 13375573, 16050689, 19260817, 23112977, 27735583, 33282701, 39939233, - 47927081, 57512503, 69014987, 82818011, 99381577, 119257891, 143109469, - 171731387, 206077643, 247293161, 296751781, 356102141, 427322587, - 512787097, 615344489, 738413383, 886096061, 1063315271, 1275978331, - 1531174013, 1837408799, 2204890543UL, 2645868653UL, 3175042391UL, - 3810050851UL, -#if SIZE_MAX > 4294967295UL - 4572061027UL, 5486473229UL, 6583767889UL, 7900521449UL, 9480625733UL, - 11376750877UL, 13652101063UL, 16382521261UL, 19659025513UL, 23590830631UL, - 28308996763UL, 33970796089UL, 40764955463UL, 48917946377UL, 58701535657UL, - 70441842749UL, 84530211301UL, 101436253561UL, 121723504277UL, - 146068205131UL, 175281846149UL, 210338215379UL, 252405858521UL, - 302887030151UL, 363464436191UL, 436157323417UL, 523388788231UL, - 628066545713UL, 753679854847UL, 904415825857UL, 1085298991109UL, - 1302358789181UL, 1562830547009UL, 1875396656429UL, 2250475987709UL, - 2700571185239UL, 3240685422287UL, 3888822506759UL, 4666587008147UL, - 5599904409713UL, 6719885291641UL, 8063862349969UL, 9676634819959UL, - 11611961783951UL, 13934354140769UL, 16721224968907UL, 20065469962669UL, - 24078563955191UL, 28894276746229UL, 34673132095507UL, 41607758514593UL, - 49929310217531UL, 59915172260971UL, 71898206713183UL, 86277848055823UL, - 103533417666967UL, 124240101200359UL, 149088121440451UL, 178905745728529UL, - 214686894874223UL, 257624273849081UL, 309149128618903UL, 370978954342639UL, - 445174745211143UL, 534209694253381UL, 641051633104063UL, 769261959724877UL, - 923114351670013UL, 1107737222003791UL, 1329284666404567UL, - 1595141599685509UL, 1914169919622551UL, 2297003903547091UL, - 2756404684256459UL, 3307685621107757UL, 3969222745329323UL, - 4763067294395177UL, 5715680753274209UL, 6858816903929113UL, - 8230580284714831UL, 9876696341657791UL, 11852035609989371UL, - 14222442731987227UL, 17066931278384657UL, 20480317534061597UL, - 24576381040873903UL, 29491657249048679UL, 35389988698858471UL, - 42467986438630267UL, 50961583726356109UL, 61153900471627387UL, - 73384680565952851UL, 88061616679143347UL, 105673940014972061UL, - 126808728017966413UL, 152170473621559703UL, 182604568345871671UL, - 219125482015045997UL, 262950578418055169UL, 315540694101666193UL, - 378648832921999397UL, 454378599506399233UL, 545254319407679131UL, - 654305183289214771UL, 785166219947057701UL, 942199463936469157UL, - 1130639356723763129UL, 1356767228068515623UL, 1628120673682218619UL, - 1953744808418662409UL, 2344493770102394881UL, 2813392524122873857UL, - 3376071028947448339UL, 4051285234736937517UL, 4861542281684325481UL, - 5833850738021191727UL, 7000620885625427969UL, 8400745062750513217UL, - 10080894075300616261UL, 12097072890360739951UL, 14516487468432885797UL, - 17419784962119465179UL, -#endif - SIZE_MAX /* sentinel, to ensure the search terminates */ - }; - -/* Return a suitable prime >= ESTIMATE. */ -static size_t -next_prime (size_t estimate) -{ - size_t i; - - for (i = 0; i < sizeof (primes) / sizeof (primes[0]); i++) - if (primes[i] >= estimate) - return primes[i]; - return SIZE_MAX; /* not a prime, but better than nothing */ -} - -/* Resize the hash table with a new estimated size. */ -static void -hash_resize (gl_list_t list, size_t estimate) -{ - size_t new_size = next_prime (estimate); - - if (new_size > list->table_size) - { - gl_hash_entry_t *old_table = list->table; - /* Allocate the new table. */ - gl_hash_entry_t *new_table; - size_t i; - - if (size_overflow_p (xtimes (new_size, sizeof (gl_hash_entry_t)))) - goto fail; - new_table = - (gl_hash_entry_t *) calloc (new_size, sizeof (gl_hash_entry_t)); - if (new_table == NULL) - goto fail; - - /* Iterate through the entries of the old table. */ - for (i = list->table_size; i > 0; ) - { - gl_hash_entry_t node = old_table[--i]; - - while (node != NULL) - { - gl_hash_entry_t next = node->hash_next; - /* Add the entry to the new table. */ - size_t bucket = node->hashcode % new_size; - node->hash_next = new_table[bucket]; - new_table[bucket] = node; - - node = next; - } - } - - list->table = new_table; - list->table_size = new_size; - free (old_table); - } - return; - - fail: - /* Just continue without resizing the table. */ - return; -} diff --git a/contrib/tools/bison/lib/gl_anylinked_list1.h b/contrib/tools/bison/lib/gl_anylinked_list1.h deleted file mode 100644 index c8879f0f68..0000000000 --- a/contrib/tools/bison/lib/gl_anylinked_list1.h +++ /dev/null @@ -1,48 +0,0 @@ -/* Sequential list data type implemented by a linked list. - Copyright (C) 2006, 2009-2013 Free Software Foundation, Inc. - Written by Bruno Haible <bruno@clisp.org>, 2006. - - 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/>. */ - -/* Common code of gl_linked_list.c and gl_linkedhash_list.c. */ - -/* -------------------------- gl_list_t Data Type -------------------------- */ - -/* Concrete list node implementation, valid for this file only. */ -struct gl_list_node_impl -{ -#if WITH_HASHTABLE - struct gl_hash_entry h; /* hash table entry fields; must be first */ -#endif - struct gl_list_node_impl *next; - struct gl_list_node_impl *prev; - const void *value; -}; - -/* Concrete gl_list_impl type, valid for this file only. */ -struct gl_list_impl -{ - struct gl_list_impl_base base; -#if WITH_HASHTABLE - /* A hash table: managed as an array of collision lists. */ - struct gl_hash_entry **table; - size_t table_size; -#endif - /* A circular list anchored at root. - The first node is = root.next, the last node is = root.prev. - The root's value is unused. */ - struct gl_list_node_impl root; - /* Number of list nodes, excluding the root. */ - size_t count; -}; diff --git a/contrib/tools/bison/lib/gl_anylinked_list2.h b/contrib/tools/bison/lib/gl_anylinked_list2.h deleted file mode 100644 index 45ca7c829a..0000000000 --- a/contrib/tools/bison/lib/gl_anylinked_list2.h +++ /dev/null @@ -1,1195 +0,0 @@ -/* Sequential list data type implemented by a linked list. - Copyright (C) 2006-2013 Free Software Foundation, Inc. - Written by Bruno Haible <bruno@clisp.org>, 2006. - - 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/>. */ - -/* Common code of gl_linked_list.c and gl_linkedhash_list.c. */ - -/* If the symbol SIGNAL_SAFE_LIST is defined, the code is compiled in such - a way that a gl_list_t data structure may be used from within a signal - handler. The operations allowed in the signal handler are: - gl_list_iterator, gl_list_iterator_next, gl_list_iterator_free. - The list and node fields that are therefore accessed from the signal handler - are: - list->root, node->next, node->value. - We are careful to make modifications to these fields only in an order - that maintains the consistency of the list data structure at any moment, - and we use 'volatile' assignments to prevent the compiler from reordering - such assignments. */ -#ifdef SIGNAL_SAFE_LIST -# define ASYNCSAFE(type) *(volatile type *)& -#else -# define ASYNCSAFE(type) -#endif - -/* -------------------------- gl_list_t Data Type -------------------------- */ - -static gl_list_t -gl_linked_nx_create_empty (gl_list_implementation_t implementation, - gl_listelement_equals_fn equals_fn, - gl_listelement_hashcode_fn hashcode_fn, - gl_listelement_dispose_fn dispose_fn, - bool allow_duplicates) -{ - struct gl_list_impl *list = - (struct gl_list_impl *) malloc (sizeof (struct gl_list_impl)); - - if (list == NULL) - return NULL; - - list->base.vtable = implementation; - list->base.equals_fn = equals_fn; - list->base.hashcode_fn = hashcode_fn; - list->base.dispose_fn = dispose_fn; - list->base.allow_duplicates = allow_duplicates; -#if WITH_HASHTABLE - list->table_size = 11; - list->table = - (gl_hash_entry_t *) calloc (list->table_size, sizeof (gl_hash_entry_t)); - if (list->table == NULL) - goto fail; -#endif - list->root.next = &list->root; - list->root.prev = &list->root; - list->count = 0; - - return list; - -#if WITH_HASHTABLE - fail: - free (list); - return NULL; -#endif -} - -static gl_list_t -gl_linked_nx_create (gl_list_implementation_t implementation, - gl_listelement_equals_fn equals_fn, - gl_listelement_hashcode_fn hashcode_fn, - gl_listelement_dispose_fn dispose_fn, - bool allow_duplicates, - size_t count, const void **contents) -{ - struct gl_list_impl *list = - (struct gl_list_impl *) malloc (sizeof (struct gl_list_impl)); - gl_list_node_t tail; - - if (list == NULL) - return NULL; - - list->base.vtable = implementation; - list->base.equals_fn = equals_fn; - list->base.hashcode_fn = hashcode_fn; - list->base.dispose_fn = dispose_fn; - list->base.allow_duplicates = allow_duplicates; -#if WITH_HASHTABLE - { - size_t estimate = xsum (count, count / 2); /* 1.5 * count */ - if (estimate < 10) - estimate = 10; - list->table_size = next_prime (estimate); - if (size_overflow_p (xtimes (list->table_size, sizeof (gl_hash_entry_t)))) - goto fail1; - list->table = - (gl_hash_entry_t *) calloc (list->table_size, sizeof (gl_hash_entry_t)); - if (list->table == NULL) - goto fail1; - } -#endif - list->count = count; - tail = &list->root; - for (; count > 0; contents++, count--) - { - gl_list_node_t node = - (struct gl_list_node_impl *) malloc (sizeof (struct gl_list_node_impl)); - - if (node == NULL) - goto fail2; - - node->value = *contents; -#if WITH_HASHTABLE - node->h.hashcode = - (list->base.hashcode_fn != NULL - ? list->base.hashcode_fn (node->value) - : (size_t)(uintptr_t) node->value); - - /* Add node to the hash table. */ - if (add_to_bucket (list, node) < 0) - { - free (node); - goto fail2; - } -#endif - - /* Add node to the list. */ - node->prev = tail; - tail->next = node; - tail = node; - } - tail->next = &list->root; - list->root.prev = tail; - - return list; - - fail2: - { - gl_list_node_t node; - - for (node = tail; node != &list->root; ) - { - gl_list_node_t prev = node->prev; - - free (node); - node = prev; - } - } -#if WITH_HASHTABLE - free (list->table); - fail1: -#endif - free (list); - return NULL; -} - -static size_t -gl_linked_size (gl_list_t list) -{ - return list->count; -} - -static const void * -gl_linked_node_value (gl_list_t list, gl_list_node_t node) -{ - return node->value; -} - -static int -gl_linked_node_nx_set_value (gl_list_t list, gl_list_node_t node, - const void *elt) -{ -#if WITH_HASHTABLE - if (elt != node->value) - { - size_t new_hashcode = - (list->base.hashcode_fn != NULL - ? list->base.hashcode_fn (elt) - : (size_t)(uintptr_t) elt); - - if (new_hashcode != node->h.hashcode) - { - remove_from_bucket (list, node); - node->value = elt; - node->h.hashcode = new_hashcode; - if (add_to_bucket (list, node) < 0) - { - /* Out of memory. We removed node from a bucket but cannot add - it to another bucket. In order to avoid inconsistencies, we - must remove node entirely from the list. */ - gl_list_node_t before_removed = node->prev; - gl_list_node_t after_removed = node->next; - ASYNCSAFE(gl_list_node_t) before_removed->next = after_removed; - after_removed->prev = before_removed; - list->count--; - free (node); - return -1; - } - } - else - node->value = elt; - } -#else - node->value = elt; -#endif - return 0; -} - -static gl_list_node_t -gl_linked_next_node (gl_list_t list, gl_list_node_t node) -{ - return (node->next != &list->root ? node->next : NULL); -} - -static gl_list_node_t -gl_linked_previous_node (gl_list_t list, gl_list_node_t node) -{ - return (node->prev != &list->root ? node->prev : NULL); -} - -static const void * -gl_linked_get_at (gl_list_t list, size_t position) -{ - size_t count = list->count; - gl_list_node_t node; - - if (!(position < count)) - /* Invalid argument. */ - abort (); - /* Here we know count > 0. */ - if (position <= ((count - 1) / 2)) - { - node = list->root.next; - for (; position > 0; position--) - node = node->next; - } - else - { - position = count - 1 - position; - node = list->root.prev; - for (; position > 0; position--) - node = node->prev; - } - return node->value; -} - -static gl_list_node_t -gl_linked_nx_set_at (gl_list_t list, size_t position, const void *elt) -{ - size_t count = list->count; - gl_list_node_t node; - - if (!(position < count)) - /* Invalid argument. */ - abort (); - /* Here we know count > 0. */ - if (position <= ((count - 1) / 2)) - { - node = list->root.next; - for (; position > 0; position--) - node = node->next; - } - else - { - position = count - 1 - position; - node = list->root.prev; - for (; position > 0; position--) - node = node->prev; - } -#if WITH_HASHTABLE - if (elt != node->value) - { - size_t new_hashcode = - (list->base.hashcode_fn != NULL - ? list->base.hashcode_fn (elt) - : (size_t)(uintptr_t) elt); - - if (new_hashcode != node->h.hashcode) - { - remove_from_bucket (list, node); - node->value = elt; - node->h.hashcode = new_hashcode; - if (add_to_bucket (list, node) < 0) - { - /* Out of memory. We removed node from a bucket but cannot add - it to another bucket. In order to avoid inconsistencies, we - must remove node entirely from the list. */ - gl_list_node_t before_removed = node->prev; - gl_list_node_t after_removed = node->next; - ASYNCSAFE(gl_list_node_t) before_removed->next = after_removed; - after_removed->prev = before_removed; - list->count--; - free (node); - return NULL; - } - } - else - node->value = elt; - } -#else - node->value = elt; -#endif - return node; -} - -static gl_list_node_t -gl_linked_search_from_to (gl_list_t list, size_t start_index, size_t end_index, - const void *elt) -{ - size_t count = list->count; - - if (!(start_index <= end_index && end_index <= count)) - /* Invalid arguments. */ - abort (); - { -#if WITH_HASHTABLE - size_t hashcode = - (list->base.hashcode_fn != NULL - ? list->base.hashcode_fn (elt) - : (size_t)(uintptr_t) elt); - size_t bucket = hashcode % list->table_size; - gl_listelement_equals_fn equals = list->base.equals_fn; - - if (!list->base.allow_duplicates) - { - /* Look for the first match in the hash bucket. */ - gl_list_node_t found = NULL; - gl_list_node_t node; - - for (node = (gl_list_node_t) list->table[bucket]; - node != NULL; - node = (gl_list_node_t) node->h.hash_next) - if (node->h.hashcode == hashcode - && (equals != NULL - ? equals (elt, node->value) - : elt == node->value)) - { - found = node; - break; - } - if (start_index > 0) - /* Look whether found's index is < start_index. */ - for (node = list->root.next; ; node = node->next) - { - if (node == found) - return NULL; - if (--start_index == 0) - break; - } - if (end_index < count) - /* Look whether found's index is >= end_index. */ - { - end_index = count - end_index; - for (node = list->root.prev; ; node = node->prev) - { - if (node == found) - return NULL; - if (--end_index == 0) - break; - } - } - return found; - } - else - { - /* Look whether there is more than one match in the hash bucket. */ - bool multiple_matches = false; - gl_list_node_t first_match = NULL; - gl_list_node_t node; - - for (node = (gl_list_node_t) list->table[bucket]; - node != NULL; - node = (gl_list_node_t) node->h.hash_next) - if (node->h.hashcode == hashcode - && (equals != NULL - ? equals (elt, node->value) - : elt == node->value)) - { - if (first_match == NULL) - first_match = node; - else - { - multiple_matches = true; - break; - } - } - if (multiple_matches) - { - /* We need the match with the smallest index. But we don't have - a fast mapping node -> index. So we have to walk the list. */ - end_index -= start_index; - node = list->root.next; - for (; start_index > 0; start_index--) - node = node->next; - - for (; - end_index > 0; - node = node->next, end_index--) - if (node->h.hashcode == hashcode - && (equals != NULL - ? equals (elt, node->value) - : elt == node->value)) - return node; - /* The matches must have all been at indices < start_index or - >= end_index. */ - return NULL; - } - else - { - if (start_index > 0) - /* Look whether first_match's index is < start_index. */ - for (node = list->root.next; node != &list->root; node = node->next) - { - if (node == first_match) - return NULL; - if (--start_index == 0) - break; - } - if (end_index < list->count) - /* Look whether first_match's index is >= end_index. */ - { - end_index = list->count - end_index; - for (node = list->root.prev; ; node = node->prev) - { - if (node == first_match) - return NULL; - if (--end_index == 0) - break; - } - } - return first_match; - } - } -#else - gl_listelement_equals_fn equals = list->base.equals_fn; - gl_list_node_t node = list->root.next; - - end_index -= start_index; - for (; start_index > 0; start_index--) - node = node->next; - - if (equals != NULL) - { - for (; end_index > 0; node = node->next, end_index--) - if (equals (elt, node->value)) - return node; - } - else - { - for (; end_index > 0; node = node->next, end_index--) - if (elt == node->value) - return node; - } - return NULL; -#endif - } -} - -static size_t -gl_linked_indexof_from_to (gl_list_t list, size_t start_index, size_t end_index, - const void *elt) -{ - size_t count = list->count; - - if (!(start_index <= end_index && end_index <= count)) - /* Invalid arguments. */ - abort (); - { -#if WITH_HASHTABLE - /* Here the hash table doesn't help much. It only allows us to minimize - the number of equals() calls, by looking up first the node and then - its index. */ - size_t hashcode = - (list->base.hashcode_fn != NULL - ? list->base.hashcode_fn (elt) - : (size_t)(uintptr_t) elt); - size_t bucket = hashcode % list->table_size; - gl_listelement_equals_fn equals = list->base.equals_fn; - gl_list_node_t node; - - /* First step: Look up the node. */ - if (!list->base.allow_duplicates) - { - /* Look for the first match in the hash bucket. */ - for (node = (gl_list_node_t) list->table[bucket]; - node != NULL; - node = (gl_list_node_t) node->h.hash_next) - if (node->h.hashcode == hashcode - && (equals != NULL - ? equals (elt, node->value) - : elt == node->value)) - break; - } - else - { - /* Look whether there is more than one match in the hash bucket. */ - bool multiple_matches = false; - gl_list_node_t first_match = NULL; - - for (node = (gl_list_node_t) list->table[bucket]; - node != NULL; - node = (gl_list_node_t) node->h.hash_next) - if (node->h.hashcode == hashcode - && (equals != NULL - ? equals (elt, node->value) - : elt == node->value)) - { - if (first_match == NULL) - first_match = node; - else - { - multiple_matches = true; - break; - } - } - if (multiple_matches) - { - /* We need the match with the smallest index. But we don't have - a fast mapping node -> index. So we have to walk the list. */ - size_t index; - - index = start_index; - node = list->root.next; - for (; start_index > 0; start_index--) - node = node->next; - - for (; - index < end_index; - node = node->next, index++) - if (node->h.hashcode == hashcode - && (equals != NULL - ? equals (elt, node->value) - : elt == node->value)) - return index; - /* The matches must have all been at indices < start_index or - >= end_index. */ - return (size_t)(-1); - } - node = first_match; - } - - /* Second step: Look up the index of the node. */ - if (node == NULL) - return (size_t)(-1); - else - { - size_t index = 0; - - for (; node->prev != &list->root; node = node->prev) - index++; - - if (index >= start_index && index < end_index) - return index; - else - return (size_t)(-1); - } -#else - gl_listelement_equals_fn equals = list->base.equals_fn; - size_t index = start_index; - gl_list_node_t node = list->root.next; - - for (; start_index > 0; start_index--) - node = node->next; - - if (equals != NULL) - { - for (; - index < end_index; - node = node->next, index++) - if (equals (elt, node->value)) - return index; - } - else - { - for (; - index < end_index; - node = node->next, index++) - if (elt == node->value) - return index; - } - return (size_t)(-1); -#endif - } -} - -static gl_list_node_t -gl_linked_nx_add_first (gl_list_t list, const void *elt) -{ - gl_list_node_t node = - (struct gl_list_node_impl *) malloc (sizeof (struct gl_list_node_impl)); - - if (node == NULL) - return NULL; - - ASYNCSAFE(const void *) node->value = elt; -#if WITH_HASHTABLE - node->h.hashcode = - (list->base.hashcode_fn != NULL - ? list->base.hashcode_fn (node->value) - : (size_t)(uintptr_t) node->value); - - /* Add node to the hash table. */ - if (add_to_bucket (list, node) < 0) - { - free (node); - return NULL; - } -#endif - - /* Add node to the list. */ - node->prev = &list->root; - ASYNCSAFE(gl_list_node_t) node->next = list->root.next; - node->next->prev = node; - ASYNCSAFE(gl_list_node_t) list->root.next = node; - list->count++; - -#if WITH_HASHTABLE - hash_resize_after_add (list); -#endif - - return node; -} - -static gl_list_node_t -gl_linked_nx_add_last (gl_list_t list, const void *elt) -{ - gl_list_node_t node = - (struct gl_list_node_impl *) malloc (sizeof (struct gl_list_node_impl)); - - if (node == NULL) - return NULL; - - ASYNCSAFE(const void *) node->value = elt; -#if WITH_HASHTABLE - node->h.hashcode = - (list->base.hashcode_fn != NULL - ? list->base.hashcode_fn (node->value) - : (size_t)(uintptr_t) node->value); - - /* Add node to the hash table. */ - if (add_to_bucket (list, node) < 0) - { - free (node); - return NULL; - } -#endif - - /* Add node to the list. */ - ASYNCSAFE(gl_list_node_t) node->next = &list->root; - node->prev = list->root.prev; - ASYNCSAFE(gl_list_node_t) node->prev->next = node; - list->root.prev = node; - list->count++; - -#if WITH_HASHTABLE - hash_resize_after_add (list); -#endif - - return node; -} - -static gl_list_node_t -gl_linked_nx_add_before (gl_list_t list, gl_list_node_t node, const void *elt) -{ - gl_list_node_t new_node = - (struct gl_list_node_impl *) malloc (sizeof (struct gl_list_node_impl)); - - if (new_node == NULL) - return NULL; - - ASYNCSAFE(const void *) new_node->value = elt; -#if WITH_HASHTABLE - new_node->h.hashcode = - (list->base.hashcode_fn != NULL - ? list->base.hashcode_fn (new_node->value) - : (size_t)(uintptr_t) new_node->value); - - /* Add new_node to the hash table. */ - if (add_to_bucket (list, new_node) < 0) - { - free (new_node); - return NULL; - } -#endif - - /* Add new_node to the list. */ - ASYNCSAFE(gl_list_node_t) new_node->next = node; - new_node->prev = node->prev; - ASYNCSAFE(gl_list_node_t) new_node->prev->next = new_node; - node->prev = new_node; - list->count++; - -#if WITH_HASHTABLE - hash_resize_after_add (list); -#endif - - return new_node; -} - -static gl_list_node_t -gl_linked_nx_add_after (gl_list_t list, gl_list_node_t node, const void *elt) -{ - gl_list_node_t new_node = - (struct gl_list_node_impl *) malloc (sizeof (struct gl_list_node_impl)); - - if (new_node == NULL) - return NULL; - - ASYNCSAFE(const void *) new_node->value = elt; -#if WITH_HASHTABLE - new_node->h.hashcode = - (list->base.hashcode_fn != NULL - ? list->base.hashcode_fn (new_node->value) - : (size_t)(uintptr_t) new_node->value); - - /* Add new_node to the hash table. */ - if (add_to_bucket (list, new_node) < 0) - { - free (new_node); - return NULL; - } -#endif - - /* Add new_node to the list. */ - new_node->prev = node; - ASYNCSAFE(gl_list_node_t) new_node->next = node->next; - new_node->next->prev = new_node; - ASYNCSAFE(gl_list_node_t) node->next = new_node; - list->count++; - -#if WITH_HASHTABLE - hash_resize_after_add (list); -#endif - - return new_node; -} - -static gl_list_node_t -gl_linked_nx_add_at (gl_list_t list, size_t position, const void *elt) -{ - size_t count = list->count; - gl_list_node_t new_node; - - if (!(position <= count)) - /* Invalid argument. */ - abort (); - - new_node = (struct gl_list_node_impl *) malloc (sizeof (struct gl_list_node_impl)); - if (new_node == NULL) - return NULL; - - ASYNCSAFE(const void *) new_node->value = elt; -#if WITH_HASHTABLE - new_node->h.hashcode = - (list->base.hashcode_fn != NULL - ? list->base.hashcode_fn (new_node->value) - : (size_t)(uintptr_t) new_node->value); - - /* Add new_node to the hash table. */ - if (add_to_bucket (list, new_node) < 0) - { - free (new_node); - return NULL; - } -#endif - - /* Add new_node to the list. */ - if (position <= (count / 2)) - { - gl_list_node_t node; - - node = &list->root; - for (; position > 0; position--) - node = node->next; - new_node->prev = node; - ASYNCSAFE(gl_list_node_t) new_node->next = node->next; - new_node->next->prev = new_node; - ASYNCSAFE(gl_list_node_t) node->next = new_node; - } - else - { - gl_list_node_t node; - - position = count - position; - node = &list->root; - for (; position > 0; position--) - node = node->prev; - ASYNCSAFE(gl_list_node_t) new_node->next = node; - new_node->prev = node->prev; - ASYNCSAFE(gl_list_node_t) new_node->prev->next = new_node; - node->prev = new_node; - } - list->count++; - -#if WITH_HASHTABLE - hash_resize_after_add (list); -#endif - - return new_node; -} - -static bool -gl_linked_remove_node (gl_list_t list, gl_list_node_t node) -{ - gl_list_node_t prev; - gl_list_node_t next; - -#if WITH_HASHTABLE - /* Remove node from the hash table. */ - remove_from_bucket (list, node); -#endif - - /* Remove node from the list. */ - prev = node->prev; - next = node->next; - - ASYNCSAFE(gl_list_node_t) prev->next = next; - next->prev = prev; - list->count--; - - if (list->base.dispose_fn != NULL) - list->base.dispose_fn (node->value); - free (node); - return true; -} - -static bool -gl_linked_remove_at (gl_list_t list, size_t position) -{ - size_t count = list->count; - gl_list_node_t removed_node; - - if (!(position < count)) - /* Invalid argument. */ - abort (); - /* Here we know count > 0. */ - if (position <= ((count - 1) / 2)) - { - gl_list_node_t node; - gl_list_node_t after_removed; - - node = &list->root; - for (; position > 0; position--) - node = node->next; - removed_node = node->next; - after_removed = node->next->next; - ASYNCSAFE(gl_list_node_t) node->next = after_removed; - after_removed->prev = node; - } - else - { - gl_list_node_t node; - gl_list_node_t before_removed; - - position = count - 1 - position; - node = &list->root; - for (; position > 0; position--) - node = node->prev; - removed_node = node->prev; - before_removed = node->prev->prev; - node->prev = before_removed; - ASYNCSAFE(gl_list_node_t) before_removed->next = node; - } -#if WITH_HASHTABLE - remove_from_bucket (list, removed_node); -#endif - list->count--; - - if (list->base.dispose_fn != NULL) - list->base.dispose_fn (removed_node->value); - free (removed_node); - return true; -} - -static bool -gl_linked_remove (gl_list_t list, const void *elt) -{ - gl_list_node_t node = gl_linked_search_from_to (list, 0, list->count, elt); - - if (node != NULL) - return gl_linked_remove_node (list, node); - else - return false; -} - -static void -gl_linked_list_free (gl_list_t list) -{ - gl_listelement_dispose_fn dispose = list->base.dispose_fn; - gl_list_node_t node; - - for (node = list->root.next; node != &list->root; ) - { - gl_list_node_t next = node->next; - if (dispose != NULL) - dispose (node->value); - free (node); - node = next; - } -#if WITH_HASHTABLE - free (list->table); -#endif - free (list); -} - -/* --------------------- gl_list_iterator_t Data Type --------------------- */ - -static gl_list_iterator_t -gl_linked_iterator (gl_list_t list) -{ - gl_list_iterator_t result; - - result.vtable = list->base.vtable; - result.list = list; - result.p = list->root.next; - result.q = &list->root; -#ifdef lint - result.i = 0; - result.j = 0; - result.count = 0; -#endif - - return result; -} - -static gl_list_iterator_t -gl_linked_iterator_from_to (gl_list_t list, - size_t start_index, size_t end_index) -{ - gl_list_iterator_t result; - size_t n1, n2, n3; - - if (!(start_index <= end_index && end_index <= list->count)) - /* Invalid arguments. */ - abort (); - result.vtable = list->base.vtable; - result.list = list; - n1 = start_index; - n2 = end_index - start_index; - n3 = list->count - end_index; - /* Find the maximum among n1, n2, n3, so as to reduce the number of - loop iterations to n1 + n2 + n3 - max(n1,n2,n3). */ - if (n1 > n2 && n1 > n3) - { - /* n1 is the maximum, use n2 and n3. */ - gl_list_node_t node; - size_t i; - - node = &list->root; - for (i = n3; i > 0; i--) - node = node->prev; - result.q = node; - for (i = n2; i > 0; i--) - node = node->prev; - result.p = node; - } - else if (n2 > n3) - { - /* n2 is the maximum, use n1 and n3. */ - gl_list_node_t node; - size_t i; - - node = list->root.next; - for (i = n1; i > 0; i--) - node = node->next; - result.p = node; - - node = &list->root; - for (i = n3; i > 0; i--) - node = node->prev; - result.q = node; - } - else - { - /* n3 is the maximum, use n1 and n2. */ - gl_list_node_t node; - size_t i; - - node = list->root.next; - for (i = n1; i > 0; i--) - node = node->next; - result.p = node; - for (i = n2; i > 0; i--) - node = node->next; - result.q = node; - } - -#ifdef lint - result.i = 0; - result.j = 0; - result.count = 0; -#endif - - return result; -} - -static bool -gl_linked_iterator_next (gl_list_iterator_t *iterator, - const void **eltp, gl_list_node_t *nodep) -{ - if (iterator->p != iterator->q) - { - gl_list_node_t node = (gl_list_node_t) iterator->p; - *eltp = node->value; - if (nodep != NULL) - *nodep = node; - iterator->p = node->next; - return true; - } - else - return false; -} - -static void -gl_linked_iterator_free (gl_list_iterator_t *iterator) -{ -} - -/* ---------------------- Sorted gl_list_t Data Type ---------------------- */ - -static gl_list_node_t -gl_linked_sortedlist_search (gl_list_t list, gl_listelement_compar_fn compar, - const void *elt) -{ - gl_list_node_t node; - - for (node = list->root.next; node != &list->root; node = node->next) - { - int cmp = compar (node->value, elt); - - if (cmp > 0) - break; - if (cmp == 0) - return node; - } - return NULL; -} - -static gl_list_node_t -gl_linked_sortedlist_search_from_to (gl_list_t list, - gl_listelement_compar_fn compar, - size_t low, size_t high, - const void *elt) -{ - size_t count = list->count; - - if (!(low <= high && high <= list->count)) - /* Invalid arguments. */ - abort (); - - high -= low; - if (high > 0) - { - /* Here we know low < count. */ - size_t position = low; - gl_list_node_t node; - - if (position <= ((count - 1) / 2)) - { - node = list->root.next; - for (; position > 0; position--) - node = node->next; - } - else - { - position = count - 1 - position; - node = list->root.prev; - for (; position > 0; position--) - node = node->prev; - } - - do - { - int cmp = compar (node->value, elt); - - if (cmp > 0) - break; - if (cmp == 0) - return node; - node = node->next; - } - while (--high > 0); - } - return NULL; -} - -static size_t -gl_linked_sortedlist_indexof (gl_list_t list, gl_listelement_compar_fn compar, - const void *elt) -{ - gl_list_node_t node; - size_t index; - - for (node = list->root.next, index = 0; - node != &list->root; - node = node->next, index++) - { - int cmp = compar (node->value, elt); - - if (cmp > 0) - break; - if (cmp == 0) - return index; - } - return (size_t)(-1); -} - -static size_t -gl_linked_sortedlist_indexof_from_to (gl_list_t list, - gl_listelement_compar_fn compar, - size_t low, size_t high, - const void *elt) -{ - size_t count = list->count; - - if (!(low <= high && high <= list->count)) - /* Invalid arguments. */ - abort (); - - high -= low; - if (high > 0) - { - /* Here we know low < count. */ - size_t index = low; - size_t position = low; - gl_list_node_t node; - - if (position <= ((count - 1) / 2)) - { - node = list->root.next; - for (; position > 0; position--) - node = node->next; - } - else - { - position = count - 1 - position; - node = list->root.prev; - for (; position > 0; position--) - node = node->prev; - } - - do - { - int cmp = compar (node->value, elt); - - if (cmp > 0) - break; - if (cmp == 0) - return index; - node = node->next; - index++; - } - while (--high > 0); - } - return (size_t)(-1); -} - -static gl_list_node_t -gl_linked_sortedlist_nx_add (gl_list_t list, gl_listelement_compar_fn compar, - const void *elt) -{ - gl_list_node_t node; - - for (node = list->root.next; node != &list->root; node = node->next) - if (compar (node->value, elt) >= 0) - return gl_linked_nx_add_before (list, node, elt); - return gl_linked_nx_add_last (list, elt); -} - -static bool -gl_linked_sortedlist_remove (gl_list_t list, gl_listelement_compar_fn compar, - const void *elt) -{ - gl_list_node_t node; - - for (node = list->root.next; node != &list->root; node = node->next) - { - int cmp = compar (node->value, elt); - - if (cmp > 0) - break; - if (cmp == 0) - return gl_linked_remove_node (list, node); - } - return false; -} diff --git a/contrib/tools/bison/lib/gl_anytree_oset.h b/contrib/tools/bison/lib/gl_anytree_oset.h deleted file mode 100644 index e1f90a99a2..0000000000 --- a/contrib/tools/bison/lib/gl_anytree_oset.h +++ /dev/null @@ -1,297 +0,0 @@ -/* Ordered set data type implemented by a binary tree. - Copyright (C) 2006-2007, 2009-2013 Free Software Foundation, Inc. - Written by Bruno Haible <bruno@clisp.org>, 2006. - - 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/>. */ - -/* Common code of gl_avltree_oset.c and gl_rbtree_oset.c. */ - -/* An item on the stack used for iterating across the elements. */ -typedef struct -{ - gl_oset_node_t node; - bool rightp; -} iterstack_item_t; - -/* A stack used for iterating across the elements. */ -typedef iterstack_item_t iterstack_t[MAXHEIGHT]; - -static gl_oset_t -gl_tree_nx_create_empty (gl_oset_implementation_t implementation, - gl_setelement_compar_fn compar_fn, - gl_setelement_dispose_fn dispose_fn) -{ - struct gl_oset_impl *set = - (struct gl_oset_impl *) malloc (sizeof (struct gl_oset_impl)); - - if (set == NULL) - return NULL; - - set->base.vtable = implementation; - set->base.compar_fn = compar_fn; - set->base.dispose_fn = dispose_fn; - set->root = NULL; - set->count = 0; - - return set; -} - -static size_t -gl_tree_size (gl_oset_t set) -{ - return set->count; -} - -static bool -gl_tree_search (gl_oset_t set, const void *elt) -{ - gl_setelement_compar_fn compar = set->base.compar_fn; - gl_oset_node_t node; - - for (node = set->root; node != NULL; ) - { - int cmp = (compar != NULL - ? compar (node->value, elt) - : (node->value > elt ? 1 : - node->value < elt ? -1 : 0)); - - if (cmp < 0) - node = node->right; - else if (cmp > 0) - node = node->left; - else /* cmp == 0 */ - /* We have an element equal to ELT. */ - return true; - } - return false; -} - -static bool -gl_tree_search_atleast (gl_oset_t set, - gl_setelement_threshold_fn threshold_fn, - const void *threshold, - const void **eltp) -{ - gl_oset_node_t node; - - for (node = set->root; node != NULL; ) - { - if (! threshold_fn (node->value, threshold)) - node = node->right; - else - { - /* We have an element >= VALUE. But we need the leftmost such - element. */ - gl_oset_node_t found = node; - node = node->left; - for (; node != NULL; ) - { - if (! threshold_fn (node->value, threshold)) - node = node->right; - else - { - found = node; - node = node->left; - } - } - *eltp = found->value; - return true; - } - } - return false; -} - -static gl_oset_node_t -gl_tree_search_node (gl_oset_t set, const void *elt) -{ - gl_setelement_compar_fn compar = set->base.compar_fn; - gl_oset_node_t node; - - for (node = set->root; node != NULL; ) - { - int cmp = (compar != NULL - ? compar (node->value, elt) - : (node->value > elt ? 1 : - node->value < elt ? -1 : 0)); - - if (cmp < 0) - node = node->right; - else if (cmp > 0) - node = node->left; - else /* cmp == 0 */ - /* We have an element equal to ELT. */ - return node; - } - return NULL; -} - -static int -gl_tree_nx_add (gl_oset_t set, const void *elt) -{ - gl_setelement_compar_fn compar; - gl_oset_node_t node = set->root; - - if (node == NULL) - { - if (gl_tree_nx_add_first (set, elt) == NULL) - return -1; - return true; - } - - compar = set->base.compar_fn; - - for (;;) - { - int cmp = (compar != NULL - ? compar (node->value, elt) - : (node->value > elt ? 1 : - node->value < elt ? -1 : 0)); - - if (cmp < 0) - { - if (node->right == NULL) - { - if (gl_tree_nx_add_after (set, node, elt) == NULL) - return -1; - return true; - } - node = node->right; - } - else if (cmp > 0) - { - if (node->left == NULL) - { - if (gl_tree_nx_add_before (set, node, elt) == NULL) - return -1; - return true; - } - node = node->left; - } - else /* cmp == 0 */ - return false; - } -} - -static bool -gl_tree_remove (gl_oset_t set, const void *elt) -{ - gl_oset_node_t node = gl_tree_search_node (set, elt); - - if (node != NULL) - return gl_tree_remove_node (set, node); - else - return false; -} - -static void -gl_tree_oset_free (gl_oset_t set) -{ - /* Iterate across all elements in post-order. */ - gl_oset_node_t node = set->root; - iterstack_t stack; - iterstack_item_t *stack_ptr = &stack[0]; - - for (;;) - { - /* Descend on left branch. */ - for (;;) - { - if (node == NULL) - break; - stack_ptr->node = node; - stack_ptr->rightp = false; - node = node->left; - stack_ptr++; - } - /* Climb up again. */ - for (;;) - { - if (stack_ptr == &stack[0]) - goto done_iterate; - stack_ptr--; - node = stack_ptr->node; - if (!stack_ptr->rightp) - break; - /* Free the current node. */ - if (set->base.dispose_fn != NULL) - set->base.dispose_fn (node->value); - free (node); - } - /* Descend on right branch. */ - stack_ptr->rightp = true; - node = node->right; - stack_ptr++; - } - done_iterate: - free (set); -} - -/* --------------------- gl_oset_iterator_t Data Type --------------------- */ - -static gl_oset_iterator_t -gl_tree_iterator (gl_oset_t set) -{ - gl_oset_iterator_t result; - gl_oset_node_t node; - - result.vtable = set->base.vtable; - result.set = set; - /* Start node is the leftmost node. */ - node = set->root; - if (node != NULL) - while (node->left != NULL) - node = node->left; - result.p = node; - /* End point is past the rightmost node. */ - result.q = NULL; -#ifdef lint - result.i = 0; - result.j = 0; - result.count = 0; -#endif - - return result; -} - -static bool -gl_tree_iterator_next (gl_oset_iterator_t *iterator, const void **eltp) -{ - if (iterator->p != iterator->q) - { - gl_oset_node_t node = (gl_oset_node_t) iterator->p; - *eltp = node->value; - /* Advance to the next node. */ - if (node->right != NULL) - { - node = node->right; - while (node->left != NULL) - node = node->left; - } - else - { - while (node->parent != NULL && node->parent->right == node) - node = node->parent; - node = node->parent; - } - iterator->p = node; - return true; - } - else - return false; -} - -static void -gl_tree_iterator_free (gl_oset_iterator_t *iterator) -{ -} diff --git a/contrib/tools/bison/lib/gl_avltree_oset.c b/contrib/tools/bison/lib/gl_avltree_oset.c deleted file mode 100644 index 09202ae0cc..0000000000 --- a/contrib/tools/bison/lib/gl_avltree_oset.c +++ /dev/null @@ -1,583 +0,0 @@ -/* Ordered set data type implemented by a binary tree. - Copyright (C) 2006-2007, 2009-2013 Free Software Foundation, Inc. - Written by Bruno Haible <bruno@clisp.org>, 2006. - - 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/>. */ - -#include <config.h> - -/* Specification. */ -#include "gl_avltree_oset.h" - -#include <stdlib.h> - -/* An AVL tree is a binary tree where - 1. The height of each node is calculated as - heightof(node) = 1 + max (heightof(node.left), heightof(node.right)). - 2. The heights of the subtrees of each node differ by at most 1: - | heightof(right) - heightof(left) | <= 1. - 3. The index of the elements in the node.left subtree are smaller than - the index of node. - The index of the elements in the node.right subtree are larger than - the index of node. - */ - -/* -------------------------- gl_oset_t Data Type -------------------------- */ - -/* Tree node implementation, valid for this file only. */ -struct gl_oset_node_impl -{ - struct gl_oset_node_impl *left; /* left branch, or NULL */ - struct gl_oset_node_impl *right; /* right branch, or NULL */ - /* Parent pointer, or NULL. The parent pointer is not needed for most - operations. It is needed so that a gl_oset_node_t can be returned - without memory allocation, on which the functions gl_oset_remove_node, - gl_oset_add_before, gl_oset_add_after can be implemented. */ - struct gl_oset_node_impl *parent; - int balance; /* heightof(right) - heightof(left), - always = -1 or 0 or 1 */ - const void *value; -}; -typedef struct gl_oset_node_impl * gl_oset_node_t; - -/* Concrete gl_oset_impl type, valid for this file only. */ -struct gl_oset_impl -{ - struct gl_oset_impl_base base; - struct gl_oset_node_impl *root; /* root node or NULL */ - size_t count; /* number of nodes */ -}; - -/* An AVL tree of height h has at least F_(h+2) [Fibonacci number] and at most - 2^h - 1 elements. So, h <= 84 (because a tree of height h >= 85 would have - at least F_87 elements, and because even on 64-bit machines, - sizeof (gl_oset_node_impl) * F_87 > 2^64 - this would exceed the address space of the machine. */ -#define MAXHEIGHT 83 - -/* Ensure the tree is balanced, after an insertion or deletion operation. - The height of NODE is incremented by HEIGHT_DIFF (1 or -1). - PARENT = NODE->parent. (NODE can also be NULL. But PARENT is non-NULL.) - Rotation operations are performed starting at PARENT (not NODE itself!). */ -static void -rebalance (gl_oset_t set, - gl_oset_node_t node, int height_diff, gl_oset_node_t parent) -{ - for (;;) - { - gl_oset_node_t child; - int previous_balance; - int balance_diff; - gl_oset_node_t nodeleft; - gl_oset_node_t noderight; - - child = node; - node = parent; - - previous_balance = node->balance; - - /* The balance of NODE is incremented by BALANCE_DIFF: +1 if the right - branch's height has increased by 1 or the left branch's height has - decreased by 1, -1 if the right branch's height has decreased by 1 or - the left branch's height has increased by 1, 0 if no height change. */ - if (node->left != NULL || node->right != NULL) - balance_diff = (child == node->right ? height_diff : -height_diff); - else - /* Special case where above formula doesn't work, because the caller - didn't tell whether node's left or right branch shrunk from height 1 - to NULL. */ - balance_diff = - previous_balance; - - node->balance += balance_diff; - if (balance_diff == previous_balance) - { - /* node->balance is outside the range [-1,1]. Must rotate. */ - gl_oset_node_t *nodep; - - if (node->parent == NULL) - /* node == set->root */ - nodep = &set->root; - else if (node->parent->left == node) - nodep = &node->parent->left; - else if (node->parent->right == node) - nodep = &node->parent->right; - else - abort (); - - nodeleft = node->left; - noderight = node->right; - - if (balance_diff < 0) - { - /* node->balance = -2. The subtree is heavier on the left side. - Rotate from left to right: - - * - / \ - h+2 h - */ - gl_oset_node_t nodeleftright = nodeleft->right; - if (nodeleft->balance <= 0) - { - /* - * h+2|h+3 - / \ / \ - h+2 h --> / h+1|h+2 - / \ | / \ - h+1 h|h+1 h+1 h|h+1 h - */ - node->left = nodeleftright; - nodeleft->right = node; - - nodeleft->parent = node->parent; - node->parent = nodeleft; - if (nodeleftright != NULL) - nodeleftright->parent = node; - - nodeleft->balance += 1; - node->balance = - nodeleft->balance; - - *nodep = nodeleft; - height_diff = (height_diff < 0 - ? /* noderight's height had been decremented from - h+1 to h. The subtree's height changes from - h+3 to h+2|h+3. */ - nodeleft->balance - 1 - : /* nodeleft's height had been incremented from - h+1 to h+2. The subtree's height changes from - h+2 to h+2|h+3. */ - nodeleft->balance); - } - else - { - /* - * h+2 - / \ / \ - h+2 h --> h+1 h+1 - / \ / \ / \ - h h+1 h L R h - / \ - L R - - */ - gl_oset_node_t L = nodeleft->right = nodeleftright->left; - gl_oset_node_t R = node->left = nodeleftright->right; - nodeleftright->left = nodeleft; - nodeleftright->right = node; - - nodeleftright->parent = node->parent; - if (L != NULL) - L->parent = nodeleft; - if (R != NULL) - R->parent = node; - nodeleft->parent = nodeleftright; - node->parent = nodeleftright; - - nodeleft->balance = (nodeleftright->balance > 0 ? -1 : 0); - node->balance = (nodeleftright->balance < 0 ? 1 : 0); - nodeleftright->balance = 0; - - *nodep = nodeleftright; - height_diff = (height_diff < 0 - ? /* noderight's height had been decremented from - h+1 to h. The subtree's height changes from - h+3 to h+2. */ - -1 - : /* nodeleft's height had been incremented from - h+1 to h+2. The subtree's height changes from - h+2 to h+2. */ - 0); - } - } - else - { - /* node->balance = 2. The subtree is heavier on the right side. - Rotate from right to left: - - * - / \ - h h+2 - */ - gl_oset_node_t noderightleft = noderight->left; - if (noderight->balance >= 0) - { - /* - * h+2|h+3 - / \ / \ - h h+2 --> h+1|h+2 \ - / \ / \ | - h|h+1 h+1 h h|h+1 h+1 - */ - node->right = noderightleft; - noderight->left = node; - - noderight->parent = node->parent; - node->parent = noderight; - if (noderightleft != NULL) - noderightleft->parent = node; - - noderight->balance -= 1; - node->balance = - noderight->balance; - - *nodep = noderight; - height_diff = (height_diff < 0 - ? /* nodeleft's height had been decremented from - h+1 to h. The subtree's height changes from - h+3 to h+2|h+3. */ - - noderight->balance - 1 - : /* noderight's height had been incremented from - h+1 to h+2. The subtree's height changes from - h+2 to h+2|h+3. */ - - noderight->balance); - } - else - { - /* - * h+2 - / \ / \ - h h+2 --> h+1 h+1 - / \ / \ / \ - h+1 h h L R h - / \ - L R - - */ - gl_oset_node_t L = node->right = noderightleft->left; - gl_oset_node_t R = noderight->left = noderightleft->right; - noderightleft->left = node; - noderightleft->right = noderight; - - noderightleft->parent = node->parent; - if (L != NULL) - L->parent = node; - if (R != NULL) - R->parent = noderight; - node->parent = noderightleft; - noderight->parent = noderightleft; - - node->balance = (noderightleft->balance > 0 ? -1 : 0); - noderight->balance = (noderightleft->balance < 0 ? 1 : 0); - noderightleft->balance = 0; - - *nodep = noderightleft; - height_diff = (height_diff < 0 - ? /* nodeleft's height had been decremented from - h+1 to h. The subtree's height changes from - h+3 to h+2. */ - -1 - : /* noderight's height had been incremented from - h+1 to h+2. The subtree's height changes from - h+2 to h+2. */ - 0); - } - } - node = *nodep; - } - else - { - /* No rotation needed. Only propagation of the height change to the - next higher level. */ - if (height_diff < 0) - height_diff = (previous_balance == 0 ? 0 : -1); - else - height_diff = (node->balance == 0 ? 0 : 1); - } - - if (height_diff == 0) - break; - - parent = node->parent; - if (parent == NULL) - break; - } -} - -static gl_oset_node_t -gl_tree_nx_add_first (gl_oset_t set, const void *elt) -{ - /* Create new node. */ - gl_oset_node_t new_node = - (struct gl_oset_node_impl *) malloc (sizeof (struct gl_oset_node_impl)); - - if (new_node == NULL) - return NULL; - - new_node->left = NULL; - new_node->right = NULL; - new_node->balance = 0; - new_node->value = elt; - - /* Add it to the tree. */ - if (set->root == NULL) - { - set->root = new_node; - new_node->parent = NULL; - } - else - { - gl_oset_node_t node; - - for (node = set->root; node->left != NULL; ) - node = node->left; - - node->left = new_node; - new_node->parent = node; - node->balance--; - - /* Rebalance. */ - if (node->right == NULL && node->parent != NULL) - rebalance (set, node, 1, node->parent); - } - - set->count++; - return new_node; -} - -static gl_oset_node_t -gl_tree_nx_add_before (gl_oset_t set, gl_oset_node_t node, const void *elt) -{ - /* Create new node. */ - gl_oset_node_t new_node = - (struct gl_oset_node_impl *) malloc (sizeof (struct gl_oset_node_impl)); - bool height_inc; - - if (new_node == NULL) - return NULL; - - new_node->left = NULL; - new_node->right = NULL; - new_node->balance = 0; - new_node->value = elt; - - /* Add it to the tree. */ - if (node->left == NULL) - { - node->left = new_node; - node->balance--; - height_inc = (node->right == NULL); - } - else - { - for (node = node->left; node->right != NULL; ) - node = node->right; - node->right = new_node; - node->balance++; - height_inc = (node->left == NULL); - } - new_node->parent = node; - - /* Rebalance. */ - if (height_inc && node->parent != NULL) - rebalance (set, node, 1, node->parent); - - set->count++; - return new_node; -} - -static gl_oset_node_t -gl_tree_nx_add_after (gl_oset_t set, gl_oset_node_t node, const void *elt) -{ - /* Create new node. */ - gl_oset_node_t new_node = - (struct gl_oset_node_impl *) malloc (sizeof (struct gl_oset_node_impl)); - bool height_inc; - - if (new_node == NULL) - return NULL; - - new_node->left = NULL; - new_node->right = NULL; - new_node->balance = 0; - new_node->value = elt; - - /* Add it to the tree. */ - if (node->right == NULL) - { - node->right = new_node; - node->balance++; - height_inc = (node->left == NULL); - } - else - { - for (node = node->right; node->left != NULL; ) - node = node->left; - node->left = new_node; - node->balance--; - height_inc = (node->right == NULL); - } - new_node->parent = node; - - /* Rebalance. */ - if (height_inc && node->parent != NULL) - rebalance (set, node, 1, node->parent); - - set->count++; - return new_node; -} - -static bool -gl_tree_remove_node (gl_oset_t set, gl_oset_node_t node) -{ - gl_oset_node_t parent = node->parent; - - if (node->left == NULL) - { - /* Replace node with node->right. */ - gl_oset_node_t child = node->right; - - if (child != NULL) - child->parent = parent; - if (parent == NULL) - set->root = child; - else - { - if (parent->left == node) - parent->left = child; - else /* parent->right == node */ - parent->right = child; - - rebalance (set, child, -1, parent); - } - } - else if (node->right == NULL) - { - /* It is not absolutely necessary to treat this case. But the more - general case below is more complicated, hence slower. */ - /* Replace node with node->left. */ - gl_oset_node_t child = node->left; - - child->parent = parent; - if (parent == NULL) - set->root = child; - else - { - if (parent->left == node) - parent->left = child; - else /* parent->right == node */ - parent->right = child; - - rebalance (set, child, -1, parent); - } - } - else - { - /* Replace node with the rightmost element of the node->left subtree. */ - gl_oset_node_t subst; - gl_oset_node_t subst_parent; - gl_oset_node_t child; - - for (subst = node->left; subst->right != NULL; ) - subst = subst->right; - - subst_parent = subst->parent; - - child = subst->left; - - /* The case subst_parent == node is special: If we do nothing special, - we get confusion about node->left, subst->left and child->parent. - subst_parent == node - <==> The 'for' loop above terminated immediately. - <==> subst == subst_parent->left - [otherwise subst == subst_parent->right] - In this case, we would need to first set - child->parent = node; node->left = child; - and later - when we copy subst into node's position - again - child->parent = subst; subst->left = child; - Altogether a no-op. */ - if (subst_parent != node) - { - if (child != NULL) - child->parent = subst_parent; - subst_parent->right = child; - } - - /* Copy subst into node's position. - (This is safer than to copy subst's value into node, keep node in - place, and free subst.) */ - if (subst_parent != node) - { - subst->left = node->left; - subst->left->parent = subst; - } - subst->right = node->right; - subst->right->parent = subst; - subst->balance = node->balance; - subst->parent = parent; - if (parent == NULL) - set->root = subst; - else if (parent->left == node) - parent->left = subst; - else /* parent->right == node */ - parent->right = subst; - - /* Rebalancing starts at child's parent, that is subst_parent - - except when subst_parent == node. In this case, we need to use - its replacement, subst. */ - rebalance (set, child, -1, subst_parent != node ? subst_parent : subst); - } - - set->count--; - if (set->base.dispose_fn != NULL) - set->base.dispose_fn (node->value); - free (node); - return true; -} - -/* Generic binary tree code. */ -#include "gl_anytree_oset.h" - -/* For debugging. */ -static unsigned int -check_invariants (gl_oset_node_t node, gl_oset_node_t parent, size_t *counterp) -{ - unsigned int left_height = - (node->left != NULL ? check_invariants (node->left, node, counterp) : 0); - unsigned int right_height = - (node->right != NULL ? check_invariants (node->right, node, counterp) : 0); - int balance = (int)right_height - (int)left_height; - - if (!(node->parent == parent)) - abort (); - if (!(balance >= -1 && balance <= 1)) - abort (); - if (!(node->balance == balance)) - abort (); - - (*counterp)++; - - return 1 + (left_height > right_height ? left_height : right_height); -} -void -gl_avltree_oset_check_invariants (gl_oset_t set) -{ - size_t counter = 0; - if (set->root != NULL) - check_invariants (set->root, NULL, &counter); - if (!(set->count == counter)) - abort (); -} - -const struct gl_oset_implementation gl_avltree_oset_implementation = - { - gl_tree_nx_create_empty, - gl_tree_size, - gl_tree_search, - gl_tree_search_atleast, - gl_tree_nx_add, - gl_tree_remove, - gl_tree_oset_free, - gl_tree_iterator, - gl_tree_iterator_next, - gl_tree_iterator_free - }; diff --git a/contrib/tools/bison/lib/gl_avltree_oset.h b/contrib/tools/bison/lib/gl_avltree_oset.h deleted file mode 100644 index abac895f08..0000000000 --- a/contrib/tools/bison/lib/gl_avltree_oset.h +++ /dev/null @@ -1,34 +0,0 @@ -/* Ordered set data type implemented by a binary tree. - Copyright (C) 2006, 2009-2013 Free Software Foundation, Inc. - Written by Bruno Haible <bruno@clisp.org>, 2006. - - 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 _GL_AVLTREE_OSET_H -#define _GL_AVLTREE_OSET_H - -#include "gl_oset.h" - -#ifdef __cplusplus -extern "C" { -#endif - -extern const struct gl_oset_implementation gl_avltree_oset_implementation; -#define GL_AVLTREE_OSET &gl_avltree_oset_implementation - -#ifdef __cplusplus -} -#endif - -#endif /* _GL_AVLTREE_OSET_H */ diff --git a/contrib/tools/bison/lib/gl_linkedhash_list.c b/contrib/tools/bison/lib/gl_linkedhash_list.c deleted file mode 100644 index 2f4e05f3a7..0000000000 --- a/contrib/tools/bison/lib/gl_linkedhash_list.c +++ /dev/null @@ -1,124 +0,0 @@ -/* Sequential list data type implemented by a hash table with a linked list. - Copyright (C) 2006, 2008-2013 Free Software Foundation, Inc. - Written by Bruno Haible <bruno@clisp.org>, 2006. - - 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/>. */ - -#include <config.h> - -/* Specification. */ -#include "gl_linkedhash_list.h" - -#include <stdint.h> /* for SIZE_MAX */ -#include <stdlib.h> - -#include "xsize.h" - -#ifndef uintptr_t -# define uintptr_t unsigned long -#endif - -#define WITH_HASHTABLE 1 - -/* -------------------------- gl_list_t Data Type -------------------------- */ - -/* Generic hash-table code. */ -#include "gl_anyhash_list1.h" - -/* Generic linked list code. */ -#include "gl_anylinked_list1.h" - -/* Generic hash-table code. */ -#include "gl_anyhash_list2.h" - -/* Resize the hash table if needed, after list->count was incremented. */ -static void -hash_resize_after_add (gl_list_t list) -{ - size_t count = list->count; - size_t estimate = xsum (count, count / 2); /* 1.5 * count */ - if (estimate > list->table_size) - hash_resize (list, estimate); -} - -/* Add a node to the hash table structure. */ -static void -add_to_bucket (gl_list_t list, gl_list_node_t node) -{ - size_t bucket = node->h.hashcode % list->table_size; - - node->h.hash_next = list->table[bucket]; - list->table[bucket] = &node->h; -} -/* Tell all compilers that the return value is 0. */ -#define add_to_bucket(list,node) ((add_to_bucket) (list, node), 0) - -/* Remove a node from the hash table structure. */ -static void -remove_from_bucket (gl_list_t list, gl_list_node_t node) -{ - size_t bucket = node->h.hashcode % list->table_size; - gl_hash_entry_t *p; - - for (p = &list->table[bucket]; ; p = &(*p)->hash_next) - { - if (*p == &node->h) - { - *p = node->h.hash_next; - break; - } - if (*p == NULL) - /* node is not in the right bucket. Did the hash codes - change inadvertently? */ - abort (); - } -} - -/* Generic linked list code. */ -#include "gl_anylinked_list2.h" - - -const struct gl_list_implementation gl_linkedhash_list_implementation = - { - gl_linked_nx_create_empty, - gl_linked_nx_create, - gl_linked_size, - gl_linked_node_value, - gl_linked_node_nx_set_value, - gl_linked_next_node, - gl_linked_previous_node, - gl_linked_get_at, - gl_linked_nx_set_at, - gl_linked_search_from_to, - gl_linked_indexof_from_to, - gl_linked_nx_add_first, - gl_linked_nx_add_last, - gl_linked_nx_add_before, - gl_linked_nx_add_after, - gl_linked_nx_add_at, - gl_linked_remove_node, - gl_linked_remove_at, - gl_linked_remove, - gl_linked_list_free, - gl_linked_iterator, - gl_linked_iterator_from_to, - gl_linked_iterator_next, - gl_linked_iterator_free, - gl_linked_sortedlist_search, - gl_linked_sortedlist_search_from_to, - gl_linked_sortedlist_indexof, - gl_linked_sortedlist_indexof_from_to, - gl_linked_sortedlist_nx_add, - gl_linked_sortedlist_remove - }; diff --git a/contrib/tools/bison/lib/gl_linkedhash_list.h b/contrib/tools/bison/lib/gl_linkedhash_list.h deleted file mode 100644 index 577756c9d4..0000000000 --- a/contrib/tools/bison/lib/gl_linkedhash_list.h +++ /dev/null @@ -1,34 +0,0 @@ -/* Sequential list data type implemented by a hash table with a linked list. - Copyright (C) 2006, 2009-2013 Free Software Foundation, Inc. - Written by Bruno Haible <bruno@clisp.org>, 2006. - - 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 _GL_LINKEDHASH_LIST_H -#define _GL_LINKEDHASH_LIST_H - -#include "gl_list.h" - -#ifdef __cplusplus -extern "C" { -#endif - -extern const struct gl_list_implementation gl_linkedhash_list_implementation; -#define GL_LINKEDHASH_LIST &gl_linkedhash_list_implementation - -#ifdef __cplusplus -} -#endif - -#endif /* _GL_LINKEDHASH_LIST_H */ diff --git a/contrib/tools/bison/lib/gl_list.c b/contrib/tools/bison/lib/gl_list.c deleted file mode 100644 index 8793298070..0000000000 --- a/contrib/tools/bison/lib/gl_list.c +++ /dev/null @@ -1,3 +0,0 @@ -#include <config.h> -#define GL_LIST_INLINE _GL_EXTERN_INLINE -#include "gl_list.h" diff --git a/contrib/tools/bison/lib/gl_list.h b/contrib/tools/bison/lib/gl_list.h deleted file mode 100644 index 9094723fe5..0000000000 --- a/contrib/tools/bison/lib/gl_list.h +++ /dev/null @@ -1,841 +0,0 @@ -/* Abstract sequential list data type. - Copyright (C) 2006-2013 Free Software Foundation, Inc. - Written by Bruno Haible <bruno@clisp.org>, 2006. - - 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 _GL_LIST_H -#define _GL_LIST_H - -#include <stdbool.h> -#include <stddef.h> - -#ifndef _GL_INLINE_HEADER_BEGIN - #error "Please include config.h first." -#endif -_GL_INLINE_HEADER_BEGIN -#ifndef GL_LIST_INLINE -# define GL_LIST_INLINE _GL_INLINE -#endif - -#ifdef __cplusplus -extern "C" { -#endif - - -/* gl_list is an abstract list data type. It can contain any number of - objects ('void *' or 'const void *' pointers) in any given order. - Duplicates are allowed, but can optionally be forbidden. - - There are several implementations of this list datatype, optimized for - different operations or for memory. You can start using the simplest list - implementation, GL_ARRAY_LIST, and switch to a different implementation - later, when you realize which operations are performed the most frequently. - The API of the different implementations is exactly the same; when - switching to a different implementation, you only have to change the - gl_list_create call. - - The implementations are: - GL_ARRAY_LIST a growable array - GL_CARRAY_LIST a growable circular array - GL_LINKED_LIST a linked list - GL_AVLTREE_LIST a binary tree (AVL tree) - GL_RBTREE_LIST a binary tree (red-black tree) - GL_LINKEDHASH_LIST a hash table with a linked list - GL_AVLTREEHASH_LIST a hash table with a binary tree (AVL tree) - GL_RBTREEHASH_LIST a hash table with a binary tree (red-black tree) - - The memory consumption is asymptotically the same: O(1) for every object - in the list. When looking more closely at the average memory consumed - for an object, GL_ARRAY_LIST is the most compact representation, and - GL_LINKEDHASH_LIST and GL_TREEHASH_LIST need more memory. - - The guaranteed average performance of the operations is, for a list of - n elements: - - Operation ARRAY LINKED TREE LINKEDHASH TREEHASH - CARRAY with|without with|without - duplicates duplicates - - gl_list_size O(1) O(1) O(1) O(1) O(1) - gl_list_node_value O(1) O(1) O(1) O(1) O(1) - gl_list_node_set_value O(1) O(1) O(1) O(1) O((log n)²)/O(1) - gl_list_next_node O(1) O(1) O(log n) O(1) O(log n) - gl_list_previous_node O(1) O(1) O(log n) O(1) O(log n) - gl_list_get_at O(1) O(n) O(log n) O(n) O(log n) - gl_list_set_at O(1) O(n) O(log n) O(n) O((log n)²)/O(log n) - gl_list_search O(n) O(n) O(n) O(n)/O(1) O(log n)/O(1) - gl_list_search_from O(n) O(n) O(n) O(n)/O(1) O((log n)²)/O(log n) - gl_list_search_from_to O(n) O(n) O(n) O(n)/O(1) O((log n)²)/O(log n) - gl_list_indexof O(n) O(n) O(n) O(n) O(log n) - gl_list_indexof_from O(n) O(n) O(n) O(n) O((log n)²)/O(log n) - gl_list_indexof_from_to O(n) O(n) O(n) O(n) O((log n)²)/O(log n) - gl_list_add_first O(n)/O(1) O(1) O(log n) O(1) O((log n)²)/O(log n) - gl_list_add_last O(1) O(1) O(log n) O(1) O((log n)²)/O(log n) - gl_list_add_before O(n) O(1) O(log n) O(1) O((log n)²)/O(log n) - gl_list_add_after O(n) O(1) O(log n) O(1) O((log n)²)/O(log n) - gl_list_add_at O(n) O(n) O(log n) O(n) O((log n)²)/O(log n) - gl_list_remove_node O(n) O(1) O(log n) O(n)/O(1) O((log n)²)/O(log n) - gl_list_remove_at O(n) O(n) O(log n) O(n) O((log n)²)/O(log n) - gl_list_remove O(n) O(n) O(n) O(n)/O(1) O((log n)²)/O(log n) - gl_list_iterator O(1) O(1) O(log n) O(1) O(log n) - gl_list_iterator_from_to O(1) O(n) O(log n) O(n) O(log n) - gl_list_iterator_next O(1) O(1) O(log n) O(1) O(log n) - gl_sortedlist_search O(log n) O(n) O(log n) O(n) O(log n) - gl_sortedlist_search_from O(log n) O(n) O(log n) O(n) O(log n) - gl_sortedlist_indexof O(log n) O(n) O(log n) O(n) O(log n) - gl_sortedlist_indexof_fro O(log n) O(n) O(log n) O(n) O(log n) - gl_sortedlist_add O(n) O(n) O(log n) O(n) O((log n)²)/O(log n) - gl_sortedlist_remove O(n) O(n) O(log n) O(n) O((log n)²)/O(log n) - */ - -/* -------------------------- gl_list_t Data Type -------------------------- */ - -/* Type of function used to compare two elements. - NULL denotes pointer comparison. */ -typedef bool (*gl_listelement_equals_fn) (const void *elt1, const void *elt2); - -/* Type of function used to compute a hash code. - NULL denotes a function that depends only on the pointer itself. */ -typedef size_t (*gl_listelement_hashcode_fn) (const void *elt); - -/* Type of function used to dispose an element once it's removed from a list. - NULL denotes a no-op. */ -typedef void (*gl_listelement_dispose_fn) (const void *elt); - -struct gl_list_impl; -/* Type representing an entire list. */ -typedef struct gl_list_impl * gl_list_t; - -struct gl_list_node_impl; -/* Type representing the position of an element in the list, in a way that - is more adapted to the list implementation than a plain index. - Note: It is invalidated by insertions and removals! */ -typedef struct gl_list_node_impl * gl_list_node_t; - -struct gl_list_implementation; -/* Type representing a list datatype implementation. */ -typedef const struct gl_list_implementation * gl_list_implementation_t; - -#if 0 /* Unless otherwise specified, these are defined inline below. */ - -/* Create an empty list. - IMPLEMENTATION is one of GL_ARRAY_LIST, GL_CARRAY_LIST, GL_LINKED_LIST, - GL_AVLTREE_LIST, GL_RBTREE_LIST, GL_LINKEDHASH_LIST, GL_AVLTREEHASH_LIST, - GL_RBTREEHASH_LIST. - EQUALS_FN is an element comparison function or NULL. - HASHCODE_FN is an element hash code function or NULL. - DISPOSE_FN is an element disposal function or NULL. - ALLOW_DUPLICATES is false if duplicate elements shall not be allowed in - the list. The implementation may verify this at runtime. */ -/* declared in gl_xlist.h */ -extern gl_list_t gl_list_create_empty (gl_list_implementation_t implementation, - gl_listelement_equals_fn equals_fn, - gl_listelement_hashcode_fn hashcode_fn, - gl_listelement_dispose_fn dispose_fn, - bool allow_duplicates); -/* Likewise. Return NULL upon out-of-memory. */ -extern gl_list_t gl_list_nx_create_empty (gl_list_implementation_t implementation, - gl_listelement_equals_fn equals_fn, - gl_listelement_hashcode_fn hashcode_fn, - gl_listelement_dispose_fn dispose_fn, - bool allow_duplicates); - -/* Create a list with given contents. - IMPLEMENTATION is one of GL_ARRAY_LIST, GL_CARRAY_LIST, GL_LINKED_LIST, - GL_AVLTREE_LIST, GL_RBTREE_LIST, GL_LINKEDHASH_LIST, GL_AVLTREEHASH_LIST, - GL_RBTREEHASH_LIST. - EQUALS_FN is an element comparison function or NULL. - HASHCODE_FN is an element hash code function or NULL. - DISPOSE_FN is an element disposal function or NULL. - ALLOW_DUPLICATES is false if duplicate elements shall not be allowed in - the list. The implementation may verify this at runtime. - COUNT is the number of initial elements. - CONTENTS[0..COUNT-1] is the initial contents. */ -/* declared in gl_xlist.h */ -extern gl_list_t gl_list_create (gl_list_implementation_t implementation, - gl_listelement_equals_fn equals_fn, - gl_listelement_hashcode_fn hashcode_fn, - gl_listelement_dispose_fn dispose_fn, - bool allow_duplicates, - size_t count, const void **contents); -/* Likewise. Return NULL upon out-of-memory. */ -extern gl_list_t gl_list_nx_create (gl_list_implementation_t implementation, - gl_listelement_equals_fn equals_fn, - gl_listelement_hashcode_fn hashcode_fn, - gl_listelement_dispose_fn dispose_fn, - bool allow_duplicates, - size_t count, const void **contents); - -/* Return the current number of elements in a list. */ -extern size_t gl_list_size (gl_list_t list); - -/* Return the element value represented by a list node. */ -extern const void * gl_list_node_value (gl_list_t list, gl_list_node_t node); - -/* Replace the element value represented by a list node. */ -/* declared in gl_xlist.h */ -extern void gl_list_node_set_value (gl_list_t list, gl_list_node_t node, - const void *elt); -/* Likewise. Return 0 upon success, -1 upon out-of-memory. */ -extern int gl_list_node_nx_set_value (gl_list_t list, gl_list_node_t node, - const void *elt) -#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) - __attribute__ ((__warn_unused_result__)) -#endif - ; - -/* Return the node immediately after the given node in the list, or NULL - if the given node is the last (rightmost) one in the list. */ -extern gl_list_node_t gl_list_next_node (gl_list_t list, gl_list_node_t node); - -/* Return the node immediately before the given node in the list, or NULL - if the given node is the first (leftmost) one in the list. */ -extern gl_list_node_t gl_list_previous_node (gl_list_t list, gl_list_node_t node); - -/* Return the element at a given position in the list. - POSITION must be >= 0 and < gl_list_size (list). */ -extern const void * gl_list_get_at (gl_list_t list, size_t position); - -/* Replace the element at a given position in the list. - POSITION must be >= 0 and < gl_list_size (list). - Return its node. */ -/* declared in gl_xlist.h */ -extern gl_list_node_t gl_list_set_at (gl_list_t list, size_t position, - const void *elt); -/* Likewise. Return NULL upon out-of-memory. */ -extern gl_list_node_t gl_list_nx_set_at (gl_list_t list, size_t position, - const void *elt) -#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) - __attribute__ ((__warn_unused_result__)) -#endif - ; - -/* Search whether an element is already in the list. - Return its node if found, or NULL if not present in the list. */ -extern gl_list_node_t gl_list_search (gl_list_t list, const void *elt); - -/* Search whether an element is already in the list, - at a position >= START_INDEX. - Return its node if found, or NULL if not present in the list. */ -extern gl_list_node_t gl_list_search_from (gl_list_t list, size_t start_index, - const void *elt); - -/* Search whether an element is already in the list, - at a position >= START_INDEX and < END_INDEX. - Return its node if found, or NULL if not present in the list. */ -extern gl_list_node_t gl_list_search_from_to (gl_list_t list, - size_t start_index, - size_t end_index, - const void *elt); - -/* Search whether an element is already in the list. - Return its position if found, or (size_t)(-1) if not present in the list. */ -extern size_t gl_list_indexof (gl_list_t list, const void *elt); - -/* Search whether an element is already in the list, - at a position >= START_INDEX. - Return its position if found, or (size_t)(-1) if not present in the list. */ -extern size_t gl_list_indexof_from (gl_list_t list, size_t start_index, - const void *elt); - -/* Search whether an element is already in the list, - at a position >= START_INDEX and < END_INDEX. - Return its position if found, or (size_t)(-1) if not present in the list. */ -extern size_t gl_list_indexof_from_to (gl_list_t list, - size_t start_index, size_t end_index, - const void *elt); - -/* Add an element as the first element of the list. - Return its node. */ -/* declared in gl_xlist.h */ -extern gl_list_node_t gl_list_add_first (gl_list_t list, const void *elt); -/* Likewise. Return NULL upon out-of-memory. */ -extern gl_list_node_t gl_list_nx_add_first (gl_list_t list, const void *elt) -#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) - __attribute__ ((__warn_unused_result__)) -#endif - ; - -/* Add an element as the last element of the list. - Return its node. */ -/* declared in gl_xlist.h */ -extern gl_list_node_t gl_list_add_last (gl_list_t list, const void *elt); -/* Likewise. Return NULL upon out-of-memory. */ -extern gl_list_node_t gl_list_nx_add_last (gl_list_t list, const void *elt) -#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) - __attribute__ ((__warn_unused_result__)) -#endif - ; - -/* Add an element before a given element node of the list. - Return its node. */ -/* declared in gl_xlist.h */ -extern gl_list_node_t gl_list_add_before (gl_list_t list, gl_list_node_t node, - const void *elt); -/* Likewise. Return NULL upon out-of-memory. */ -extern gl_list_node_t gl_list_nx_add_before (gl_list_t list, - gl_list_node_t node, - const void *elt) -#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) - __attribute__ ((__warn_unused_result__)) -#endif - ; - -/* Add an element after a given element node of the list. - Return its node. */ -/* declared in gl_xlist.h */ -extern gl_list_node_t gl_list_add_after (gl_list_t list, gl_list_node_t node, - const void *elt); -/* Likewise. Return NULL upon out-of-memory. */ -extern gl_list_node_t gl_list_nx_add_after (gl_list_t list, gl_list_node_t node, - const void *elt) -#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) - __attribute__ ((__warn_unused_result__)) -#endif - ; - -/* Add an element at a given position in the list. - POSITION must be >= 0 and <= gl_list_size (list). */ -/* declared in gl_xlist.h */ -extern gl_list_node_t gl_list_add_at (gl_list_t list, size_t position, - const void *elt); -/* Likewise. Return NULL upon out-of-memory. */ -extern gl_list_node_t gl_list_nx_add_at (gl_list_t list, size_t position, - const void *elt) -#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) - __attribute__ ((__warn_unused_result__)) -#endif - ; - -/* Remove an element from the list. - Return true. */ -extern bool gl_list_remove_node (gl_list_t list, gl_list_node_t node); - -/* Remove an element at a given position from the list. - POSITION must be >= 0 and < gl_list_size (list). - Return true. */ -extern bool gl_list_remove_at (gl_list_t list, size_t position); - -/* Search and remove an element from the list. - Return true if it was found and removed. */ -extern bool gl_list_remove (gl_list_t list, const void *elt); - -/* Free an entire list. - (But this call does not free the elements of the list.) */ -extern void gl_list_free (gl_list_t list); - -#endif /* End of inline and gl_xlist.h-defined functions. */ - -/* --------------------- gl_list_iterator_t Data Type --------------------- */ - -/* Functions for iterating through a list. */ - -/* Type of an iterator that traverses a list. - This is a fixed-size struct, so that creation of an iterator doesn't need - memory allocation on the heap. */ -typedef struct -{ - /* For fast dispatch of gl_list_iterator_next. */ - const struct gl_list_implementation *vtable; - /* For detecting whether the last returned element was removed. */ - gl_list_t list; - size_t count; - /* Other, implementation-private fields. */ - void *p; void *q; - size_t i; size_t j; -} gl_list_iterator_t; - -#if 0 /* These are defined inline below. */ - -/* Create an iterator traversing a list. - The list contents must not be modified while the iterator is in use, - except for replacing or removing the last returned element. */ -extern gl_list_iterator_t gl_list_iterator (gl_list_t list); - -/* Create an iterator traversing the element with indices i, - start_index <= i < end_index, of a list. - The list contents must not be modified while the iterator is in use, - except for replacing or removing the last returned element. */ -extern gl_list_iterator_t gl_list_iterator_from_to (gl_list_t list, - size_t start_index, - size_t end_index); - -/* If there is a next element, store the next element in *ELTP, store its - node in *NODEP if NODEP is non-NULL, advance the iterator and return true. - Otherwise, return false. */ -extern bool gl_list_iterator_next (gl_list_iterator_t *iterator, - const void **eltp, gl_list_node_t *nodep); - -/* Free an iterator. */ -extern void gl_list_iterator_free (gl_list_iterator_t *iterator); - -#endif /* End of inline functions. */ - -/* ---------------------- Sorted gl_list_t Data Type ---------------------- */ - -/* The following functions are for lists without duplicates where the - order is given by a sort criterion. */ - -/* Type of function used to compare two elements. Same as for qsort(). - NULL denotes pointer comparison. */ -typedef int (*gl_listelement_compar_fn) (const void *elt1, const void *elt2); - -#if 0 /* Unless otherwise specified, these are defined inline below. */ - -/* Search whether an element is already in the list. - The list is assumed to be sorted with COMPAR. - Return its node if found, or NULL if not present in the list. - If the list contains several copies of ELT, the node of the leftmost one is - returned. */ -extern gl_list_node_t gl_sortedlist_search (gl_list_t list, - gl_listelement_compar_fn compar, - const void *elt); - -/* Search whether an element is already in the list. - The list is assumed to be sorted with COMPAR. - Only list elements with indices >= START_INDEX and < END_INDEX are - considered; the implementation uses these bounds to minimize the number - of COMPAR invocations. - Return its node if found, or NULL if not present in the list. - If the list contains several copies of ELT, the node of the leftmost one is - returned. */ -extern gl_list_node_t gl_sortedlist_search_from_to (gl_list_t list, - gl_listelement_compar_fn compar, - size_t start_index, - size_t end_index, - const void *elt); - -/* Search whether an element is already in the list. - The list is assumed to be sorted with COMPAR. - Return its position if found, or (size_t)(-1) if not present in the list. - If the list contains several copies of ELT, the position of the leftmost one - is returned. */ -extern size_t gl_sortedlist_indexof (gl_list_t list, - gl_listelement_compar_fn compar, - const void *elt); - -/* Search whether an element is already in the list. - The list is assumed to be sorted with COMPAR. - Only list elements with indices >= START_INDEX and < END_INDEX are - considered; the implementation uses these bounds to minimize the number - of COMPAR invocations. - Return its position if found, or (size_t)(-1) if not present in the list. - If the list contains several copies of ELT, the position of the leftmost one - is returned. */ -extern size_t gl_sortedlist_indexof_from_to (gl_list_t list, - gl_listelement_compar_fn compar, - size_t start_index, - size_t end_index, - const void *elt); - -/* Add an element at the appropriate position in the list. - The list is assumed to be sorted with COMPAR. - Return its node. */ -/* declared in gl_xlist.h */ -extern gl_list_node_t gl_sortedlist_add (gl_list_t list, - gl_listelement_compar_fn compar, - const void *elt); -/* Likewise. Return NULL upon out-of-memory. */ -extern gl_list_node_t gl_sortedlist_nx_add (gl_list_t list, - gl_listelement_compar_fn compar, - const void *elt) -#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) - __attribute__ ((__warn_unused_result__)) -#endif - ; - -/* Search and remove an element from the list. - The list is assumed to be sorted with COMPAR. - Return true if it was found and removed. - If the list contains several copies of ELT, only the leftmost one is - removed. */ -extern bool gl_sortedlist_remove (gl_list_t list, - gl_listelement_compar_fn compar, - const void *elt); - -#endif /* End of inline and gl_xlist.h-defined functions. */ - -/* ------------------------ Implementation Details ------------------------ */ - -struct gl_list_implementation -{ - /* gl_list_t functions. */ - gl_list_t (*nx_create_empty) (gl_list_implementation_t implementation, - gl_listelement_equals_fn equals_fn, - gl_listelement_hashcode_fn hashcode_fn, - gl_listelement_dispose_fn dispose_fn, - bool allow_duplicates); - gl_list_t (*nx_create) (gl_list_implementation_t implementation, - gl_listelement_equals_fn equals_fn, - gl_listelement_hashcode_fn hashcode_fn, - gl_listelement_dispose_fn dispose_fn, - bool allow_duplicates, - size_t count, const void **contents); - size_t (*size) (gl_list_t list); - const void * (*node_value) (gl_list_t list, gl_list_node_t node); - int (*node_nx_set_value) (gl_list_t list, gl_list_node_t node, - const void *elt); - gl_list_node_t (*next_node) (gl_list_t list, gl_list_node_t node); - gl_list_node_t (*previous_node) (gl_list_t list, gl_list_node_t node); - const void * (*get_at) (gl_list_t list, size_t position); - gl_list_node_t (*nx_set_at) (gl_list_t list, size_t position, - const void *elt); - gl_list_node_t (*search_from_to) (gl_list_t list, size_t start_index, - size_t end_index, const void *elt); - size_t (*indexof_from_to) (gl_list_t list, size_t start_index, - size_t end_index, const void *elt); - gl_list_node_t (*nx_add_first) (gl_list_t list, const void *elt); - gl_list_node_t (*nx_add_last) (gl_list_t list, const void *elt); - gl_list_node_t (*nx_add_before) (gl_list_t list, gl_list_node_t node, - const void *elt); - gl_list_node_t (*nx_add_after) (gl_list_t list, gl_list_node_t node, - const void *elt); - gl_list_node_t (*nx_add_at) (gl_list_t list, size_t position, - const void *elt); - bool (*remove_node) (gl_list_t list, gl_list_node_t node); - bool (*remove_at) (gl_list_t list, size_t position); - bool (*remove_elt) (gl_list_t list, const void *elt); - void (*list_free) (gl_list_t list); - /* gl_list_iterator_t functions. */ - gl_list_iterator_t (*iterator) (gl_list_t list); - gl_list_iterator_t (*iterator_from_to) (gl_list_t list, - size_t start_index, - size_t end_index); - bool (*iterator_next) (gl_list_iterator_t *iterator, - const void **eltp, gl_list_node_t *nodep); - void (*iterator_free) (gl_list_iterator_t *iterator); - /* Sorted gl_list_t functions. */ - gl_list_node_t (*sortedlist_search) (gl_list_t list, - gl_listelement_compar_fn compar, - const void *elt); - gl_list_node_t (*sortedlist_search_from_to) (gl_list_t list, - gl_listelement_compar_fn compar, - size_t start_index, - size_t end_index, - const void *elt); - size_t (*sortedlist_indexof) (gl_list_t list, - gl_listelement_compar_fn compar, - const void *elt); - size_t (*sortedlist_indexof_from_to) (gl_list_t list, - gl_listelement_compar_fn compar, - size_t start_index, size_t end_index, - const void *elt); - gl_list_node_t (*sortedlist_nx_add) (gl_list_t list, - gl_listelement_compar_fn compar, - const void *elt); - bool (*sortedlist_remove) (gl_list_t list, - gl_listelement_compar_fn compar, - const void *elt); -}; - -struct gl_list_impl_base -{ - const struct gl_list_implementation *vtable; - gl_listelement_equals_fn equals_fn; - gl_listelement_hashcode_fn hashcode_fn; - gl_listelement_dispose_fn dispose_fn; - bool allow_duplicates; -}; - -/* Define all functions of this file as accesses to the - struct gl_list_implementation. */ - -GL_LIST_INLINE gl_list_t -gl_list_nx_create_empty (gl_list_implementation_t implementation, - gl_listelement_equals_fn equals_fn, - gl_listelement_hashcode_fn hashcode_fn, - gl_listelement_dispose_fn dispose_fn, - bool allow_duplicates) -{ - return implementation->nx_create_empty (implementation, equals_fn, - hashcode_fn, dispose_fn, - allow_duplicates); -} - -GL_LIST_INLINE gl_list_t -gl_list_nx_create (gl_list_implementation_t implementation, - gl_listelement_equals_fn equals_fn, - gl_listelement_hashcode_fn hashcode_fn, - gl_listelement_dispose_fn dispose_fn, - bool allow_duplicates, - size_t count, const void **contents) -{ - return implementation->nx_create (implementation, equals_fn, hashcode_fn, - dispose_fn, allow_duplicates, count, - contents); -} - -GL_LIST_INLINE size_t -gl_list_size (gl_list_t list) -{ - return ((const struct gl_list_impl_base *) list)->vtable - ->size (list); -} - -GL_LIST_INLINE const void * -gl_list_node_value (gl_list_t list, gl_list_node_t node) -{ - return ((const struct gl_list_impl_base *) list)->vtable - ->node_value (list, node); -} - -GL_LIST_INLINE int -#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) - __attribute__ ((__warn_unused_result__)) -#endif -gl_list_node_nx_set_value (gl_list_t list, gl_list_node_t node, - const void *elt) -{ - return ((const struct gl_list_impl_base *) list)->vtable - ->node_nx_set_value (list, node, elt); -} - -GL_LIST_INLINE gl_list_node_t -gl_list_next_node (gl_list_t list, gl_list_node_t node) -{ - return ((const struct gl_list_impl_base *) list)->vtable - ->next_node (list, node); -} - -GL_LIST_INLINE gl_list_node_t -gl_list_previous_node (gl_list_t list, gl_list_node_t node) -{ - return ((const struct gl_list_impl_base *) list)->vtable - ->previous_node (list, node); -} - -GL_LIST_INLINE const void * -gl_list_get_at (gl_list_t list, size_t position) -{ - return ((const struct gl_list_impl_base *) list)->vtable - ->get_at (list, position); -} - -GL_LIST_INLINE gl_list_node_t -#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) - __attribute__ ((__warn_unused_result__)) -#endif -gl_list_nx_set_at (gl_list_t list, size_t position, const void *elt) -{ - return ((const struct gl_list_impl_base *) list)->vtable - ->nx_set_at (list, position, elt); -} - -GL_LIST_INLINE gl_list_node_t -gl_list_search (gl_list_t list, const void *elt) -{ - size_t size = ((const struct gl_list_impl_base *) list)->vtable->size (list); - return ((const struct gl_list_impl_base *) list)->vtable - ->search_from_to (list, 0, size, elt); -} - -GL_LIST_INLINE gl_list_node_t -gl_list_search_from (gl_list_t list, size_t start_index, const void *elt) -{ - size_t size = ((const struct gl_list_impl_base *) list)->vtable->size (list); - return ((const struct gl_list_impl_base *) list)->vtable - ->search_from_to (list, start_index, size, elt); -} - -GL_LIST_INLINE gl_list_node_t -gl_list_search_from_to (gl_list_t list, size_t start_index, size_t end_index, - const void *elt) -{ - return ((const struct gl_list_impl_base *) list)->vtable - ->search_from_to (list, start_index, end_index, elt); -} - -GL_LIST_INLINE size_t -gl_list_indexof (gl_list_t list, const void *elt) -{ - size_t size = ((const struct gl_list_impl_base *) list)->vtable->size (list); - return ((const struct gl_list_impl_base *) list)->vtable - ->indexof_from_to (list, 0, size, elt); -} - -GL_LIST_INLINE size_t -gl_list_indexof_from (gl_list_t list, size_t start_index, const void *elt) -{ - size_t size = ((const struct gl_list_impl_base *) list)->vtable->size (list); - return ((const struct gl_list_impl_base *) list)->vtable - ->indexof_from_to (list, start_index, size, elt); -} - -GL_LIST_INLINE size_t -gl_list_indexof_from_to (gl_list_t list, size_t start_index, size_t end_index, - const void *elt) -{ - return ((const struct gl_list_impl_base *) list)->vtable - ->indexof_from_to (list, start_index, end_index, elt); -} - -GL_LIST_INLINE gl_list_node_t -#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) - __attribute__ ((__warn_unused_result__)) -#endif -gl_list_nx_add_first (gl_list_t list, const void *elt) -{ - return ((const struct gl_list_impl_base *) list)->vtable - ->nx_add_first (list, elt); -} - -GL_LIST_INLINE gl_list_node_t -#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) - __attribute__ ((__warn_unused_result__)) -#endif -gl_list_nx_add_last (gl_list_t list, const void *elt) -{ - return ((const struct gl_list_impl_base *) list)->vtable - ->nx_add_last (list, elt); -} - -GL_LIST_INLINE gl_list_node_t -#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) - __attribute__ ((__warn_unused_result__)) -#endif -gl_list_nx_add_before (gl_list_t list, gl_list_node_t node, const void *elt) -{ - return ((const struct gl_list_impl_base *) list)->vtable - ->nx_add_before (list, node, elt); -} - -GL_LIST_INLINE gl_list_node_t -#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) - __attribute__ ((__warn_unused_result__)) -#endif -gl_list_nx_add_after (gl_list_t list, gl_list_node_t node, const void *elt) -{ - return ((const struct gl_list_impl_base *) list)->vtable - ->nx_add_after (list, node, elt); -} - -GL_LIST_INLINE gl_list_node_t -#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) - __attribute__ ((__warn_unused_result__)) -#endif -gl_list_nx_add_at (gl_list_t list, size_t position, const void *elt) -{ - return ((const struct gl_list_impl_base *) list)->vtable - ->nx_add_at (list, position, elt); -} - -GL_LIST_INLINE bool -gl_list_remove_node (gl_list_t list, gl_list_node_t node) -{ - return ((const struct gl_list_impl_base *) list)->vtable - ->remove_node (list, node); -} - -GL_LIST_INLINE bool -gl_list_remove_at (gl_list_t list, size_t position) -{ - return ((const struct gl_list_impl_base *) list)->vtable - ->remove_at (list, position); -} - -GL_LIST_INLINE bool -gl_list_remove (gl_list_t list, const void *elt) -{ - return ((const struct gl_list_impl_base *) list)->vtable - ->remove_elt (list, elt); -} - -GL_LIST_INLINE void -gl_list_free (gl_list_t list) -{ - ((const struct gl_list_impl_base *) list)->vtable->list_free (list); -} - -GL_LIST_INLINE gl_list_iterator_t -gl_list_iterator (gl_list_t list) -{ - return ((const struct gl_list_impl_base *) list)->vtable - ->iterator (list); -} - -GL_LIST_INLINE gl_list_iterator_t -gl_list_iterator_from_to (gl_list_t list, size_t start_index, size_t end_index) -{ - return ((const struct gl_list_impl_base *) list)->vtable - ->iterator_from_to (list, start_index, end_index); -} - -GL_LIST_INLINE bool -gl_list_iterator_next (gl_list_iterator_t *iterator, - const void **eltp, gl_list_node_t *nodep) -{ - return iterator->vtable->iterator_next (iterator, eltp, nodep); -} - -GL_LIST_INLINE void -gl_list_iterator_free (gl_list_iterator_t *iterator) -{ - iterator->vtable->iterator_free (iterator); -} - -GL_LIST_INLINE gl_list_node_t -gl_sortedlist_search (gl_list_t list, gl_listelement_compar_fn compar, const void *elt) -{ - return ((const struct gl_list_impl_base *) list)->vtable - ->sortedlist_search (list, compar, elt); -} - -GL_LIST_INLINE gl_list_node_t -gl_sortedlist_search_from_to (gl_list_t list, gl_listelement_compar_fn compar, size_t start_index, size_t end_index, const void *elt) -{ - return ((const struct gl_list_impl_base *) list)->vtable - ->sortedlist_search_from_to (list, compar, start_index, end_index, - elt); -} - -GL_LIST_INLINE size_t -gl_sortedlist_indexof (gl_list_t list, gl_listelement_compar_fn compar, const void *elt) -{ - return ((const struct gl_list_impl_base *) list)->vtable - ->sortedlist_indexof (list, compar, elt); -} - -GL_LIST_INLINE size_t -gl_sortedlist_indexof_from_to (gl_list_t list, gl_listelement_compar_fn compar, size_t start_index, size_t end_index, const void *elt) -{ - return ((const struct gl_list_impl_base *) list)->vtable - ->sortedlist_indexof_from_to (list, compar, start_index, end_index, - elt); -} - -GL_LIST_INLINE gl_list_node_t -#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) - __attribute__ ((__warn_unused_result__)) -#endif -gl_sortedlist_nx_add (gl_list_t list, gl_listelement_compar_fn compar, const void *elt) -{ - return ((const struct gl_list_impl_base *) list)->vtable - ->sortedlist_nx_add (list, compar, elt); -} - -GL_LIST_INLINE bool -gl_sortedlist_remove (gl_list_t list, gl_listelement_compar_fn compar, const void *elt) -{ - return ((const struct gl_list_impl_base *) list)->vtable - ->sortedlist_remove (list, compar, elt); -} - -#ifdef __cplusplus -} -#endif - -_GL_INLINE_HEADER_END - -#endif /* _GL_LIST_H */ diff --git a/contrib/tools/bison/lib/gl_oset.c b/contrib/tools/bison/lib/gl_oset.c deleted file mode 100644 index 21f731a31a..0000000000 --- a/contrib/tools/bison/lib/gl_oset.c +++ /dev/null @@ -1,3 +0,0 @@ -#include <config.h> -#define GL_OSET_INLINE _GL_EXTERN_INLINE -#include "gl_oset.h" diff --git a/contrib/tools/bison/lib/gl_oset.h b/contrib/tools/bison/lib/gl_oset.h deleted file mode 100644 index 5134065e5e..0000000000 --- a/contrib/tools/bison/lib/gl_oset.h +++ /dev/null @@ -1,293 +0,0 @@ -/* Abstract ordered set data type. - Copyright (C) 2006-2007, 2009-2013 Free Software Foundation, Inc. - Written by Bruno Haible <bruno@clisp.org>, 2006. - - 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 _GL_OSET_H -#define _GL_OSET_H - -#include <stdbool.h> -#include <stddef.h> - -#ifndef _GL_INLINE_HEADER_BEGIN - #error "Please include config.h first." -#endif -_GL_INLINE_HEADER_BEGIN -#ifndef GL_OSET_INLINE -# define GL_OSET_INLINE _GL_INLINE -#endif - -#ifdef __cplusplus -extern "C" { -#endif - - -/* gl_oset is an abstract ordered set data type. It can contain any number - of objects ('void *' or 'const void *' pointers) in the order of a given - comparator function. Duplicates (in the sense of the comparator) are - forbidden. - - There are several implementations of this ordered set datatype, optimized - for different operations or for memory. You can start using the simplest - ordered set implementation, GL_ARRAY_OSET, and switch to a different - implementation later, when you realize which operations are performed - the most frequently. The API of the different implementations is exactly - the same; when switching to a different implementation, you only have to - change the gl_oset_create call. - - The implementations are: - GL_ARRAY_OSET a growable array - GL_AVLTREE_OSET a binary tree (AVL tree) - GL_RBTREE_OSET a binary tree (red-black tree) - - The memory consumption is asymptotically the same: O(1) for every object - in the set. When looking more closely at the average memory consumed - for an object, GL_ARRAY_OSET is the most compact representation, and - GL_AVLTREE_OSET, GL_RBTREE_OSET need more memory. - - The guaranteed average performance of the operations is, for a set of - n elements: - - Operation ARRAY TREE - - gl_oset_size O(1) O(1) - gl_oset_add O(n) O(log n) - gl_oset_remove O(n) O(log n) - gl_oset_search O(log n) O(log n) - gl_oset_search_atleast O(log n) O(log n) - gl_oset_iterator O(1) O(log n) - gl_oset_iterator_next O(1) O(log n) - */ - -/* -------------------------- gl_oset_t Data Type -------------------------- */ - -/* Type of function used to compare two elements. Same as for qsort(). - NULL denotes pointer comparison. */ -typedef int (*gl_setelement_compar_fn) (const void *elt1, const void *elt2); - -/* Type of function used to dispose an element once it's removed from a set. - NULL denotes a no-op. */ -typedef void (*gl_setelement_dispose_fn) (const void *elt); - -/* Type of function used to compare an element with a threshold. - Return true if the element is greater or equal than the threshold. */ -typedef bool (*gl_setelement_threshold_fn) (const void *elt, const void *threshold); - -struct gl_oset_impl; -/* Type representing an entire ordered set. */ -typedef struct gl_oset_impl * gl_oset_t; - -struct gl_oset_implementation; -/* Type representing a ordered set datatype implementation. */ -typedef const struct gl_oset_implementation * gl_oset_implementation_t; - -#if 0 /* Unless otherwise specified, these are defined inline below. */ - -/* Create an empty set. - IMPLEMENTATION is one of GL_ARRAY_OSET, GL_AVLTREE_OSET, GL_RBTREE_OSET. - COMPAR_FN is an element comparison function or NULL. - DISPOSE_FN is an element disposal function or NULL. */ -/* declared in gl_xoset.h */ -extern gl_oset_t gl_oset_create_empty (gl_oset_implementation_t implementation, - gl_setelement_compar_fn compar_fn, - gl_setelement_dispose_fn dispose_fn); -/* Likewise. Return NULL upon out-of-memory. */ -extern gl_oset_t gl_oset_nx_create_empty (gl_oset_implementation_t implementation, - gl_setelement_compar_fn compar_fn, - gl_setelement_dispose_fn dispose_fn); - -/* Return the current number of elements in an ordered set. */ -extern size_t gl_oset_size (gl_oset_t set); - -/* Search whether an element is already in the ordered set. - Return true if found, or false if not present in the set. */ -extern bool gl_oset_search (gl_oset_t set, const void *elt); - -/* Search the least element in the ordered set that compares greater or equal - to the given THRESHOLD. The representation of the THRESHOLD is defined - by the THRESHOLD_FN. - Return true and store the found element in *ELTP if found, otherwise return - false. */ -extern bool gl_oset_search_atleast (gl_oset_t set, - gl_setelement_threshold_fn threshold_fn, - const void *threshold, - const void **eltp); - -/* Add an element to an ordered set. - Return true if it was not already in the set and added, false otherwise. */ -/* declared in gl_xoset.h */ -extern bool gl_oset_add (gl_oset_t set, const void *elt); -/* Likewise. Return -1 upon out-of-memory. */ -extern int gl_oset_nx_add (gl_oset_t set, const void *elt) -#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) - __attribute__ ((__warn_unused_result__)) -#endif - ; - -/* Remove an element from an ordered set. - Return true if it was found and removed. */ -extern bool gl_oset_remove (gl_oset_t set, const void *elt); - -/* Free an entire ordered set. - (But this call does not free the elements of the set.) */ -extern void gl_oset_free (gl_oset_t set); - -#endif /* End of inline and gl_xlist.h-defined functions. */ - -/* --------------------- gl_oset_iterator_t Data Type --------------------- */ - -/* Functions for iterating through an ordered set. */ - -/* Type of an iterator that traverses an ordered set. - This is a fixed-size struct, so that creation of an iterator doesn't need - memory allocation on the heap. */ -typedef struct -{ - /* For fast dispatch of gl_oset_iterator_next. */ - const struct gl_oset_implementation *vtable; - /* For detecting whether the last returned element was removed. */ - gl_oset_t set; - size_t count; - /* Other, implementation-private fields. */ - void *p; void *q; - size_t i; size_t j; -} gl_oset_iterator_t; - -#if 0 /* These are defined inline below. */ - -/* Create an iterator traversing an ordered set. - The set's contents must not be modified while the iterator is in use, - except for removing the last returned element. */ -extern gl_oset_iterator_t gl_oset_iterator (gl_oset_t set); - -/* If there is a next element, store the next element in *ELTP, advance the - iterator and return true. Otherwise, return false. */ -extern bool gl_oset_iterator_next (gl_oset_iterator_t *iterator, - const void **eltp); - -/* Free an iterator. */ -extern void gl_oset_iterator_free (gl_oset_iterator_t *iterator); - -#endif /* End of inline functions. */ - -/* ------------------------ Implementation Details ------------------------ */ - -struct gl_oset_implementation -{ - /* gl_oset_t functions. */ - gl_oset_t (*nx_create_empty) (gl_oset_implementation_t implementation, - gl_setelement_compar_fn compar_fn, - gl_setelement_dispose_fn dispose_fn); - size_t (*size) (gl_oset_t set); - bool (*search) (gl_oset_t set, const void *elt); - bool (*search_atleast) (gl_oset_t set, - gl_setelement_threshold_fn threshold_fn, - const void *threshold, const void **eltp); - int (*nx_add) (gl_oset_t set, const void *elt); - bool (*remove_elt) (gl_oset_t set, const void *elt); - void (*oset_free) (gl_oset_t set); - /* gl_oset_iterator_t functions. */ - gl_oset_iterator_t (*iterator) (gl_oset_t set); - bool (*iterator_next) (gl_oset_iterator_t *iterator, const void **eltp); - void (*iterator_free) (gl_oset_iterator_t *iterator); -}; - -struct gl_oset_impl_base -{ - const struct gl_oset_implementation *vtable; - gl_setelement_compar_fn compar_fn; - gl_setelement_dispose_fn dispose_fn; -}; - -/* Define all functions of this file as accesses to the - struct gl_oset_implementation. */ - -GL_OSET_INLINE gl_oset_t -gl_oset_nx_create_empty (gl_oset_implementation_t implementation, - gl_setelement_compar_fn compar_fn, - gl_setelement_dispose_fn dispose_fn) -{ - return implementation->nx_create_empty (implementation, compar_fn, - dispose_fn); -} - -GL_OSET_INLINE size_t -gl_oset_size (gl_oset_t set) -{ - return ((const struct gl_oset_impl_base *) set)->vtable->size (set); -} - -GL_OSET_INLINE bool -gl_oset_search (gl_oset_t set, const void *elt) -{ - return ((const struct gl_oset_impl_base *) set)->vtable->search (set, elt); -} - -GL_OSET_INLINE bool -gl_oset_search_atleast (gl_oset_t set, - gl_setelement_threshold_fn threshold_fn, - const void *threshold, const void **eltp) -{ - return ((const struct gl_oset_impl_base *) set)->vtable - ->search_atleast (set, threshold_fn, threshold, eltp); -} - -GL_OSET_INLINE int -#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) - __attribute__ ((__warn_unused_result__)) -#endif -gl_oset_nx_add (gl_oset_t set, const void *elt) -{ - return ((const struct gl_oset_impl_base *) set)->vtable->nx_add (set, elt); -} - -GL_OSET_INLINE bool -gl_oset_remove (gl_oset_t set, const void *elt) -{ - return ((const struct gl_oset_impl_base *) set)->vtable - ->remove_elt (set, elt); -} - -GL_OSET_INLINE void -gl_oset_free (gl_oset_t set) -{ - ((const struct gl_oset_impl_base *) set)->vtable->oset_free (set); -} - -GL_OSET_INLINE gl_oset_iterator_t -gl_oset_iterator (gl_oset_t set) -{ - return ((const struct gl_oset_impl_base *) set)->vtable->iterator (set); -} - -GL_OSET_INLINE bool -gl_oset_iterator_next (gl_oset_iterator_t *iterator, const void **eltp) -{ - return iterator->vtable->iterator_next (iterator, eltp); -} - -GL_OSET_INLINE void -gl_oset_iterator_free (gl_oset_iterator_t *iterator) -{ - iterator->vtable->iterator_free (iterator); -} - -#ifdef __cplusplus -} -#endif - -_GL_INLINE_HEADER_END - -#endif /* _GL_OSET_H */ diff --git a/contrib/tools/bison/lib/gl_xlist.c b/contrib/tools/bison/lib/gl_xlist.c deleted file mode 100644 index fe3c893396..0000000000 --- a/contrib/tools/bison/lib/gl_xlist.c +++ /dev/null @@ -1,3 +0,0 @@ -#include <config.h> -#define GL_XLIST_INLINE _GL_EXTERN_INLINE -#include "gl_xlist.h" diff --git a/contrib/tools/bison/lib/gl_xlist.h b/contrib/tools/bison/lib/gl_xlist.h deleted file mode 100644 index 1c9451c1ab..0000000000 --- a/contrib/tools/bison/lib/gl_xlist.h +++ /dev/null @@ -1,177 +0,0 @@ -/* Abstract sequential list data type, with out-of-memory checking. - Copyright (C) 2009-2013 Free Software Foundation, Inc. - Written by Bruno Haible <bruno@clisp.org>, 2009. - - 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 _GL_XLIST_H -#define _GL_XLIST_H - -#include "gl_list.h" -#include "xalloc.h" - -#ifndef _GL_INLINE_HEADER_BEGIN - #error "Please include config.h first." -#endif -_GL_INLINE_HEADER_BEGIN -#ifndef GL_XLIST_INLINE -# define GL_XLIST_INLINE _GL_INLINE -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/* These functions are thin wrappers around the corresponding functions with - _nx_ infix from gl_list.h. Upon out-of-memory, they invoke xalloc_die (), - instead of returning an error indicator. */ -#if 0 /* These are defined inline below. */ -extern gl_list_t gl_list_create_empty (gl_list_implementation_t implementation, - gl_listelement_equals_fn equals_fn, - gl_listelement_hashcode_fn hashcode_fn, - gl_listelement_dispose_fn dispose_fn, - bool allow_duplicates); -extern gl_list_t gl_list_create (gl_list_implementation_t implementation, - gl_listelement_equals_fn equals_fn, - gl_listelement_hashcode_fn hashcode_fn, - gl_listelement_dispose_fn dispose_fn, - bool allow_duplicates, - size_t count, const void **contents); -extern void gl_list_node_set_value (gl_list_t list, gl_list_node_t node, - const void *elt); -extern gl_list_node_t gl_list_set_at (gl_list_t list, size_t position, - const void *elt); -extern gl_list_node_t gl_list_add_first (gl_list_t list, const void *elt); -extern gl_list_node_t gl_list_add_last (gl_list_t list, const void *elt); -extern gl_list_node_t gl_list_add_before (gl_list_t list, gl_list_node_t node, - const void *elt); -extern gl_list_node_t gl_list_add_after (gl_list_t list, gl_list_node_t node, - const void *elt); -extern gl_list_node_t gl_list_add_at (gl_list_t list, size_t position, - const void *elt); -extern gl_list_node_t gl_sortedlist_add (gl_list_t list, - gl_listelement_compar_fn compar, - const void *elt); -#endif - -GL_XLIST_INLINE gl_list_t -gl_list_create_empty (gl_list_implementation_t implementation, - gl_listelement_equals_fn equals_fn, - gl_listelement_hashcode_fn hashcode_fn, - gl_listelement_dispose_fn dispose_fn, - bool allow_duplicates) -{ - gl_list_t result = - gl_list_nx_create_empty (implementation, equals_fn, hashcode_fn, dispose_fn, - allow_duplicates); - if (result == NULL) - xalloc_die (); - return result; -} - -GL_XLIST_INLINE gl_list_t -gl_list_create (gl_list_implementation_t implementation, - gl_listelement_equals_fn equals_fn, - gl_listelement_hashcode_fn hashcode_fn, - gl_listelement_dispose_fn dispose_fn, - bool allow_duplicates, - size_t count, const void **contents) -{ - gl_list_t result = - gl_list_nx_create (implementation, equals_fn, hashcode_fn, dispose_fn, - allow_duplicates, count, contents); - if (result == NULL) - xalloc_die (); - return result; -} - -GL_XLIST_INLINE void -gl_list_node_set_value (gl_list_t list, gl_list_node_t node, const void *elt) -{ - int result = gl_list_node_nx_set_value (list, node, elt); - if (result < 0) - xalloc_die (); -} - -GL_XLIST_INLINE gl_list_node_t -gl_list_set_at (gl_list_t list, size_t position, const void *elt) -{ - gl_list_node_t result = gl_list_nx_set_at (list, position, elt); - if (result == NULL) - xalloc_die (); - return result; -} - -GL_XLIST_INLINE gl_list_node_t -gl_list_add_first (gl_list_t list, const void *elt) -{ - gl_list_node_t result = gl_list_nx_add_first (list, elt); - if (result == NULL) - xalloc_die (); - return result; -} - -GL_XLIST_INLINE gl_list_node_t -gl_list_add_last (gl_list_t list, const void *elt) -{ - gl_list_node_t result = gl_list_nx_add_last (list, elt); - if (result == NULL) - xalloc_die (); - return result; -} - -GL_XLIST_INLINE gl_list_node_t -gl_list_add_before (gl_list_t list, gl_list_node_t node, const void *elt) -{ - gl_list_node_t result = gl_list_nx_add_before (list, node, elt); - if (result == NULL) - xalloc_die (); - return result; -} - -GL_XLIST_INLINE gl_list_node_t -gl_list_add_after (gl_list_t list, gl_list_node_t node, const void *elt) -{ - gl_list_node_t result = gl_list_nx_add_after (list, node, elt); - if (result == NULL) - xalloc_die (); - return result; -} - -GL_XLIST_INLINE gl_list_node_t -gl_list_add_at (gl_list_t list, size_t position, const void *elt) -{ - gl_list_node_t result = gl_list_nx_add_at (list, position, elt); - if (result == NULL) - xalloc_die (); - return result; -} - -GL_XLIST_INLINE gl_list_node_t -gl_sortedlist_add (gl_list_t list, gl_listelement_compar_fn compar, - const void *elt) -{ - gl_list_node_t result = gl_sortedlist_nx_add (list, compar, elt); - if (result == NULL) - xalloc_die (); - return result; -} - -#ifdef __cplusplus -} -#endif - -_GL_INLINE_HEADER_END - -#endif /* _GL_XLIST_H */ diff --git a/contrib/tools/bison/lib/gl_xoset.c b/contrib/tools/bison/lib/gl_xoset.c deleted file mode 100644 index 6b05d94996..0000000000 --- a/contrib/tools/bison/lib/gl_xoset.c +++ /dev/null @@ -1,3 +0,0 @@ -#include <config.h> -#define GL_XOSET_INLINE _GL_EXTERN_INLINE -#include "gl_xoset.h" diff --git a/contrib/tools/bison/lib/gl_xoset.h b/contrib/tools/bison/lib/gl_xoset.h deleted file mode 100644 index b30b2ced83..0000000000 --- a/contrib/tools/bison/lib/gl_xoset.h +++ /dev/null @@ -1,74 +0,0 @@ -/* Abstract ordered set data type, with out-of-memory checking. - Copyright (C) 2009-2013 Free Software Foundation, Inc. - Written by Bruno Haible <bruno@clisp.org>, 2009. - - 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 _GL_XOSET_H -#define _GL_XOSET_H - -#include "gl_oset.h" -#include "xalloc.h" - -#ifndef _GL_INLINE_HEADER_BEGIN - #error "Please include config.h first." -#endif -_GL_INLINE_HEADER_BEGIN -#ifndef GL_XOSET_INLINE -# define GL_XOSET_INLINE _GL_INLINE -#endif - - -#ifdef __cplusplus -extern "C" { -#endif - -/* These functions are thin wrappers around the corresponding functions with - _nx_ infix from gl_oset.h. Upon out-of-memory, they invoke xalloc_die (), - instead of returning an error indicator. */ -#if 0 /* These are defined inline below. */ -extern gl_oset_t gl_oset_create_empty (gl_oset_implementation_t implementation, - gl_setelement_compar_fn compar_fn, - gl_setelement_dispose_fn dispose_fn); -extern bool gl_oset_add (gl_oset_t set, const void *elt); -#endif - -GL_XOSET_INLINE gl_oset_t -gl_oset_create_empty (gl_oset_implementation_t implementation, - gl_setelement_compar_fn compar_fn, - gl_setelement_dispose_fn dispose_fn) -{ - gl_oset_t result = - gl_oset_nx_create_empty (implementation, compar_fn, dispose_fn); - if (result == NULL) - xalloc_die (); - return result; -} - -GL_XOSET_INLINE bool -gl_oset_add (gl_oset_t set, const void *elt) -{ - int result = gl_oset_nx_add (set, elt); - if (result < 0) - xalloc_die (); - return result; -} - -#ifdef __cplusplus -} -#endif - -_GL_INLINE_HEADER_END - -#endif /* _GL_XOSET_H */ diff --git a/contrib/tools/bison/lib/ignore-value.h b/contrib/tools/bison/lib/ignore-value.h deleted file mode 100644 index ebd6bf42f5..0000000000 --- a/contrib/tools/bison/lib/ignore-value.h +++ /dev/null @@ -1,48 +0,0 @@ -/* ignore a function return without a compiler warning - - Copyright (C) 2008-2013 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 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 Jim Meyering, Eric Blake and Pádraig Brady. */ - -/* Use "ignore_value" to avoid a warning when using a function declared with - gcc's warn_unused_result attribute, but for which you really do want to - ignore the result. Traditionally, people have used a "(void)" cast to - indicate that a function's return value is deliberately unused. However, - if the function is declared with __attribute__((warn_unused_result)), - gcc issues a warning even with the cast. - - Caution: most of the time, you really should heed gcc's warning, and - check the return value. However, in those exceptional cases in which - you're sure you know what you're doing, use this function. - - For the record, here's one of the ignorable warnings: - "copy.c:233: warning: ignoring return value of 'fchown', - declared with attribute warn_unused_result". */ - -#ifndef _GL_IGNORE_VALUE_H -#define _GL_IGNORE_VALUE_H - -/* The __attribute__((__warn_unused_result__)) feature - is available in gcc versions 3.4 and newer, - while the typeof feature has been available since 2.7 at least. */ -#if 3 < __GNUC__ + (4 <= __GNUC_MINOR__) -# define ignore_value(x) \ - (__extension__ ({ __typeof__ (x) __x = (x); (void) __x; })) -#else -# define ignore_value(x) ((void) (x)) -#endif - -#endif diff --git a/contrib/tools/bison/lib/isnanf-nolibm.h b/contrib/tools/bison/lib/isnanf-nolibm.h deleted file mode 100644 index 804c65f06c..0000000000 --- a/contrib/tools/bison/lib/isnanf-nolibm.h +++ /dev/null @@ -1,40 +0,0 @@ -/* Test for NaN that does not need libm. - Copyright (C) 2007-2013 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 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/>. */ - -#if HAVE_ISNANF_IN_LIBC -/* Get declaration of isnan macro or (older) isnanf function. */ -# include <math.h> -# if __GNUC__ >= 4 && !__clang__ - /* GCC 4.0 and newer provides three built-ins for isnan. */ -# undef isnanf -# define isnanf(x) __builtin_isnanf ((float)(x)) -# elif defined isnan -# undef isnanf -# define isnanf(x) isnan ((float)(x)) -# else - /* Get declaration of isnanf(), if not declared in <math.h>. */ -# if defined __sgi - /* We can't include <ieeefp.h>, because it conflicts with our definition of - isnand. Therefore declare isnanf separately. */ -extern int isnanf (float x); -# endif -# endif -#else -/* Test whether X is a NaN. */ -# undef isnanf -# define isnanf rpl_isnanf -extern int isnanf (float x); -#endif diff --git a/contrib/tools/bison/lib/isnanf.c b/contrib/tools/bison/lib/isnanf.c deleted file mode 100644 index 946cb69ce0..0000000000 --- a/contrib/tools/bison/lib/isnanf.c +++ /dev/null @@ -1,20 +0,0 @@ -/* Test for NaN that does not need libm. - Copyright (C) 2007, 2009-2013 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 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 Bruno Haible <bruno@clisp.org>, 2007. */ - -#define USE_FLOAT -#include "isnan.c" diff --git a/contrib/tools/bison/lib/platform/posix/unused-parameter.h b/contrib/tools/bison/lib/platform/posix/unused-parameter.h deleted file mode 100644 index 53474b5754..0000000000 --- a/contrib/tools/bison/lib/platform/posix/unused-parameter.h +++ /dev/null @@ -1,20 +0,0 @@ -/* _GL_UNUSED_PARAMETER is a marker that can be appended to function parameter - declarations for parameters that are not used. This helps to reduce - warnings, such as from GCC -Wunused-parameter. The syntax is as follows: - type param _GL_UNUSED_PARAMETER - or more generally - param_decl _GL_UNUSED_PARAMETER - For example: - int param _GL_UNUSED_PARAMETER - int *(*param)(void) _GL_UNUSED_PARAMETER - Other possible, but obscure and discouraged syntaxes: - int _GL_UNUSED_PARAMETER *(*param)(void) - _GL_UNUSED_PARAMETER int *(*param)(void) - */ -#ifndef _GL_UNUSED_PARAMETER -# if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) -# define _GL_UNUSED_PARAMETER __attribute__ ((__unused__)) -# else -# define _GL_UNUSED_PARAMETER -# endif -#endif diff --git a/contrib/tools/bison/lib/platform/win64/unused-parameter.h b/contrib/tools/bison/lib/platform/win64/unused-parameter.h deleted file mode 100644 index 53474b5754..0000000000 --- a/contrib/tools/bison/lib/platform/win64/unused-parameter.h +++ /dev/null @@ -1,20 +0,0 @@ -/* _GL_UNUSED_PARAMETER is a marker that can be appended to function parameter - declarations for parameters that are not used. This helps to reduce - warnings, such as from GCC -Wunused-parameter. The syntax is as follows: - type param _GL_UNUSED_PARAMETER - or more generally - param_decl _GL_UNUSED_PARAMETER - For example: - int param _GL_UNUSED_PARAMETER - int *(*param)(void) _GL_UNUSED_PARAMETER - Other possible, but obscure and discouraged syntaxes: - int _GL_UNUSED_PARAMETER *(*param)(void) - _GL_UNUSED_PARAMETER int *(*param)(void) - */ -#ifndef _GL_UNUSED_PARAMETER -# if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) -# define _GL_UNUSED_PARAMETER __attribute__ ((__unused__)) -# else -# define _GL_UNUSED_PARAMETER -# endif -#endif diff --git a/contrib/tools/bison/lib/signbitd.c b/contrib/tools/bison/lib/signbitd.c deleted file mode 100644 index 7a434f8eea..0000000000 --- a/contrib/tools/bison/lib/signbitd.c +++ /dev/null @@ -1,64 +0,0 @@ -/* signbit() macro: Determine the sign bit of a floating-point number. - Copyright (C) 2007-2013 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 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/>. */ - -#include <config.h> - -/* Specification. */ -#include <math.h> - -#include <string.h> -#include "isnand-nolibm.h" -#include "float+.h" - -#ifdef gl_signbitd_OPTIMIZED_MACRO -# undef gl_signbitd -#endif - -int -gl_signbitd (double arg) -{ -#if defined DBL_SIGNBIT_WORD && defined DBL_SIGNBIT_BIT - /* The use of a union to extract the bits of the representation of a - 'long double' is safe in practice, despite of the "aliasing rules" of - C99, because the GCC docs say - "Even with '-fstrict-aliasing', type-punning is allowed, provided the - memory is accessed through the union type." - and similarly for other compilers. */ -# define NWORDS \ - ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)) - union { double value; unsigned int word[NWORDS]; } m; - m.value = arg; - return (m.word[DBL_SIGNBIT_WORD] >> DBL_SIGNBIT_BIT) & 1; -#elif HAVE_COPYSIGN_IN_LIBC - return copysign (1.0, arg) < 0; -#else - /* This does not do the right thing for NaN, but this is irrelevant for - most use cases. */ - if (isnand (arg)) - return 0; - if (arg < 0.0) - return 1; - else if (arg == 0.0) - { - /* Distinguish 0.0 and -0.0. */ - static double plus_zero = 0.0; - double arg_mem = arg; - return (memcmp (&plus_zero, &arg_mem, SIZEOF_DBL) != 0); - } - else - return 0; -#endif -} diff --git a/contrib/tools/bison/lib/signbitf.c b/contrib/tools/bison/lib/signbitf.c deleted file mode 100644 index f133be57f5..0000000000 --- a/contrib/tools/bison/lib/signbitf.c +++ /dev/null @@ -1,64 +0,0 @@ -/* signbit() macro: Determine the sign bit of a floating-point number. - Copyright (C) 2007, 2009-2013 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 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/>. */ - -#include <config.h> - -/* Specification. */ -#include <math.h> - -#include <string.h> -#include "isnanf-nolibm.h" -#include "float+.h" - -#ifdef gl_signbitf_OPTIMIZED_MACRO -# undef gl_signbitf -#endif - -int -gl_signbitf (float arg) -{ -#if defined FLT_SIGNBIT_WORD && defined FLT_SIGNBIT_BIT - /* The use of a union to extract the bits of the representation of a - 'long double' is safe in practice, despite of the "aliasing rules" of - C99, because the GCC docs say - "Even with '-fstrict-aliasing', type-punning is allowed, provided the - memory is accessed through the union type." - and similarly for other compilers. */ -# define NWORDS \ - ((sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int)) - union { float value; unsigned int word[NWORDS]; } m; - m.value = arg; - return (m.word[FLT_SIGNBIT_WORD] >> FLT_SIGNBIT_BIT) & 1; -#elif HAVE_COPYSIGNF_IN_LIBC - return copysignf (1.0f, arg) < 0; -#else - /* This does not do the right thing for NaN, but this is irrelevant for - most use cases. */ - if (isnanf (arg)) - return 0; - if (arg < 0.0f) - return 1; - else if (arg == 0.0f) - { - /* Distinguish 0.0f and -0.0f. */ - static float plus_zero = 0.0f; - float arg_mem = arg; - return (memcmp (&plus_zero, &arg_mem, SIZEOF_FLT) != 0); - } - else - return 0; -#endif -} diff --git a/contrib/tools/bison/lib/signbitl.c b/contrib/tools/bison/lib/signbitl.c deleted file mode 100644 index 9e1e900e16..0000000000 --- a/contrib/tools/bison/lib/signbitl.c +++ /dev/null @@ -1,64 +0,0 @@ -/* signbit() macro: Determine the sign bit of a floating-point number. - Copyright (C) 2007, 2009-2013 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 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/>. */ - -#include <config.h> - -/* Specification. */ -#include <math.h> - -#include <string.h> -#include "isnanl-nolibm.h" -#include "float+.h" - -#ifdef gl_signbitl_OPTIMIZED_MACRO -# undef gl_signbitl -#endif - -int -gl_signbitl (long double arg) -{ -#if defined LDBL_SIGNBIT_WORD && defined LDBL_SIGNBIT_BIT - /* The use of a union to extract the bits of the representation of a - 'long double' is safe in practice, despite of the "aliasing rules" of - C99, because the GCC docs say - "Even with '-fstrict-aliasing', type-punning is allowed, provided the - memory is accessed through the union type." - and similarly for other compilers. */ -# define NWORDS \ - ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)) - union { long double value; unsigned int word[NWORDS]; } m; - m.value = arg; - return (m.word[LDBL_SIGNBIT_WORD] >> LDBL_SIGNBIT_BIT) & 1; -#elif HAVE_COPYSIGNL_IN_LIBC - return copysignl (1.0L, arg) < 0; -#else - /* This does not do the right thing for NaN, but this is irrelevant for - most use cases. */ - if (isnanl (arg)) - return 0; - if (arg < 0.0L) - return 1; - else if (arg == 0.0L) - { - /* Distinguish 0.0L and -0.0L. */ - static long double plus_zero = 0.0L; - long double arg_mem = arg; - return (memcmp (&plus_zero, &arg_mem, SIZEOF_LDBL) != 0); - } - else - return 0; -#endif -} diff --git a/contrib/tools/bison/lib/spawn_faction_addclose.c b/contrib/tools/bison/lib/spawn_faction_addclose.c deleted file mode 100644 index 86a9aba2e7..0000000000 --- a/contrib/tools/bison/lib/spawn_faction_addclose.c +++ /dev/null @@ -1,69 +0,0 @@ -/* Copyright (C) 2000, 2009-2013 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/>. */ - -#include <config.h> - -/* Specification. */ -#include <spawn.h> - -#include <errno.h> -#include <unistd.h> - -#if !_LIBC -# define __sysconf(open_max) getdtablesize () -#endif - -#if !HAVE_WORKING_POSIX_SPAWN -# include "spawn_int.h" -#endif - -/* Add an action to FILE-ACTIONS which tells the implementation to call - 'close' for the given file descriptor during the 'spawn' call. */ -int -posix_spawn_file_actions_addclose (posix_spawn_file_actions_t *file_actions, - int fd) -#undef posix_spawn_file_actions_addclose -{ - int maxfd = __sysconf (_SC_OPEN_MAX); - - /* Test for the validity of the file descriptor. */ - if (fd < 0 || fd >= maxfd) - return EBADF; - -#if HAVE_WORKING_POSIX_SPAWN - return posix_spawn_file_actions_addclose (file_actions, fd); -#else - /* Allocate more memory if needed. */ - if (file_actions->_used == file_actions->_allocated - && __posix_spawn_file_actions_realloc (file_actions) != 0) - /* This can only mean we ran out of memory. */ - return ENOMEM; - - { - struct __spawn_action *rec; - - /* Add the new value. */ - rec = &file_actions->_actions[file_actions->_used]; - rec->tag = spawn_do_close; - rec->action.open_action.fd = fd; - - /* Account for the new entry. */ - ++file_actions->_used; - - return 0; - } -#endif -} diff --git a/contrib/tools/bison/lib/spawn_faction_adddup2.c b/contrib/tools/bison/lib/spawn_faction_adddup2.c deleted file mode 100644 index 56ff1ecc18..0000000000 --- a/contrib/tools/bison/lib/spawn_faction_adddup2.c +++ /dev/null @@ -1,70 +0,0 @@ -/* Copyright (C) 2000, 2009-2013 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/>. */ - -#include <config.h> - -/* Specification. */ -#include <spawn.h> - -#include <errno.h> -#include <unistd.h> - -#if !_LIBC -# define __sysconf(open_max) getdtablesize () -#endif - -#if !HAVE_WORKING_POSIX_SPAWN -# include "spawn_int.h" -#endif - -/* Add an action to FILE-ACTIONS which tells the implementation to call - 'dup2' for the given file descriptors during the 'spawn' call. */ -int -posix_spawn_file_actions_adddup2 (posix_spawn_file_actions_t *file_actions, - int fd, int newfd) -#undef posix_spawn_file_actions_adddup2 -{ - int maxfd = __sysconf (_SC_OPEN_MAX); - - /* Test for the validity of the file descriptor. */ - if (fd < 0 || newfd < 0 || fd >= maxfd || newfd >= maxfd) - return EBADF; - -#if HAVE_WORKING_POSIX_SPAWN - return posix_spawn_file_actions_adddup2 (file_actions, fd, newfd); -#else - /* Allocate more memory if needed. */ - if (file_actions->_used == file_actions->_allocated - && __posix_spawn_file_actions_realloc (file_actions) != 0) - /* This can only mean we ran out of memory. */ - return ENOMEM; - - { - struct __spawn_action *rec; - - /* Add the new value. */ - rec = &file_actions->_actions[file_actions->_used]; - rec->tag = spawn_do_dup2; - rec->action.dup2_action.fd = fd; - rec->action.dup2_action.newfd = newfd; - - /* Account for the new entry. */ - ++file_actions->_used; - - return 0; - } -#endif -} diff --git a/contrib/tools/bison/lib/spawn_faction_addopen.c b/contrib/tools/bison/lib/spawn_faction_addopen.c deleted file mode 100644 index 8aaeca6a50..0000000000 --- a/contrib/tools/bison/lib/spawn_faction_addopen.c +++ /dev/null @@ -1,73 +0,0 @@ -/* Copyright (C) 2000, 2009-2013 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/>. */ - -#include <config.h> - -/* Specification. */ -#include <spawn.h> - -#include <errno.h> -#include <unistd.h> - -#if !_LIBC -# define __sysconf(open_max) getdtablesize () -#endif - -#if !HAVE_WORKING_POSIX_SPAWN -# include "spawn_int.h" -#endif - -/* Add an action to FILE-ACTIONS which tells the implementation to call - 'open' for the given file during the 'spawn' call. */ -int -posix_spawn_file_actions_addopen (posix_spawn_file_actions_t *file_actions, - int fd, const char *path, int oflag, - mode_t mode) -#undef posix_spawn_file_actions_addopen -{ - int maxfd = __sysconf (_SC_OPEN_MAX); - - /* Test for the validity of the file descriptor. */ - if (fd < 0 || fd >= maxfd) - return EBADF; - -#if HAVE_WORKING_POSIX_SPAWN - return posix_spawn_file_actions_addopen (file_actions, fd, path, oflag, mode); -#else - /* Allocate more memory if needed. */ - if (file_actions->_used == file_actions->_allocated - && __posix_spawn_file_actions_realloc (file_actions) != 0) - /* This can only mean we ran out of memory. */ - return ENOMEM; - - { - struct __spawn_action *rec; - - /* Add the new value. */ - rec = &file_actions->_actions[file_actions->_used]; - rec->tag = spawn_do_open; - rec->action.open_action.fd = fd; - rec->action.open_action.path = path; - rec->action.open_action.oflag = oflag; - rec->action.open_action.mode = mode; - - /* Account for the new entry. */ - ++file_actions->_used; - - return 0; - } -#endif -} diff --git a/contrib/tools/bison/lib/spawn_faction_destroy.c b/contrib/tools/bison/lib/spawn_faction_destroy.c deleted file mode 100644 index 942733dc6b..0000000000 --- a/contrib/tools/bison/lib/spawn_faction_destroy.c +++ /dev/null @@ -1,31 +0,0 @@ -/* Copyright (C) 2000, 2009-2013 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/>. */ - -#include <config.h> - -/* Specification. */ -#include <spawn.h> - -#include <stdlib.h> - -/* Initialize data structure for file attribute for 'spawn' call. */ -int -posix_spawn_file_actions_destroy (posix_spawn_file_actions_t *file_actions) -{ - /* Free the memory allocated. */ - free (file_actions->_actions); - return 0; -} diff --git a/contrib/tools/bison/lib/spawn_faction_init.c b/contrib/tools/bison/lib/spawn_faction_init.c deleted file mode 100644 index cf1d0a6adc..0000000000 --- a/contrib/tools/bison/lib/spawn_faction_init.c +++ /dev/null @@ -1,56 +0,0 @@ -/* Copyright (C) 2000, 2009-2013 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/>. */ - -#include <config.h> - -/* Specification. */ -#include <spawn.h> - -#include <errno.h> -#include <stdlib.h> -#include <string.h> - -#include "spawn_int.h" - - -/* Function used to increase the size of the allocated array. This - function is called from the 'add'-functions. */ -int -__posix_spawn_file_actions_realloc (posix_spawn_file_actions_t *file_actions) -{ - int newalloc = file_actions->_allocated + 8; - void *newmem = realloc (file_actions->_actions, - newalloc * sizeof (struct __spawn_action)); - - if (newmem == NULL) - /* Not enough memory. */ - return ENOMEM; - - file_actions->_actions = (struct __spawn_action *) newmem; - file_actions->_allocated = newalloc; - - return 0; -} - - -/* Initialize data structure for file attribute for 'spawn' call. */ -int -posix_spawn_file_actions_init (posix_spawn_file_actions_t *file_actions) -{ - /* Simply clear all the elements. */ - memset (file_actions, '\0', sizeof (*file_actions)); - return 0; -} diff --git a/contrib/tools/bison/lib/spawnattr_destroy.c b/contrib/tools/bison/lib/spawnattr_destroy.c deleted file mode 100644 index ec6c7cf003..0000000000 --- a/contrib/tools/bison/lib/spawnattr_destroy.c +++ /dev/null @@ -1,28 +0,0 @@ -/* Copyright (C) 2000, 2009-2013 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/>. */ - -#include <config.h> - -/* Specification. */ -#include <spawn.h> - -/* Initialize data structure for file attribute for 'spawn' call. */ -int -posix_spawnattr_destroy (posix_spawnattr_t *attr) -{ - /* Nothing to do in the moment. */ - return 0; -} diff --git a/contrib/tools/bison/lib/spawnattr_init.c b/contrib/tools/bison/lib/spawnattr_init.c deleted file mode 100644 index b050fb4ab7..0000000000 --- a/contrib/tools/bison/lib/spawnattr_init.c +++ /dev/null @@ -1,33 +0,0 @@ -/* Copyright (C) 2000, 2009-2013 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/>. */ - -#include <config.h> - -/* Specification. */ -#include <spawn.h> - -#include <string.h> - -/* Initialize data structure for file attribute for 'spawn' call. */ -int -posix_spawnattr_init (posix_spawnattr_t *attr) -{ - /* All elements have to be initialized to the default values which - is generally zero. */ - memset (attr, '\0', sizeof (*attr)); - - return 0; -} diff --git a/contrib/tools/bison/lib/spawnattr_setflags.c b/contrib/tools/bison/lib/spawnattr_setflags.c deleted file mode 100644 index babbb19593..0000000000 --- a/contrib/tools/bison/lib/spawnattr_setflags.c +++ /dev/null @@ -1,45 +0,0 @@ -/* Copyright (C) 2000, 2004, 2009-2013 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/>. */ - -#include <config.h> - -/* Specification. */ -#include <spawn.h> - -#include <errno.h> -#include <string.h> - -#define ALL_FLAGS (POSIX_SPAWN_RESETIDS \ - | POSIX_SPAWN_SETPGROUP \ - | POSIX_SPAWN_SETSIGDEF \ - | POSIX_SPAWN_SETSIGMASK \ - | POSIX_SPAWN_SETSCHEDPARAM \ - | POSIX_SPAWN_SETSCHEDULER \ - | POSIX_SPAWN_USEVFORK) - -/* Store flags in the attribute structure. */ -int -posix_spawnattr_setflags (posix_spawnattr_t *attr, short int flags) -{ - /* Check no invalid bits are set. */ - if (flags & ~ALL_FLAGS) - return EINVAL; - - /* Store the flag word. */ - attr->_flags = flags; - - return 0; -} diff --git a/contrib/tools/bison/lib/spawnattr_setsigmask.c b/contrib/tools/bison/lib/spawnattr_setsigmask.c deleted file mode 100644 index 8aa6da9437..0000000000 --- a/contrib/tools/bison/lib/spawnattr_setsigmask.c +++ /dev/null @@ -1,33 +0,0 @@ -/* Copyright (C) 2000, 2009-2013 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/>. */ - -#include <config.h> - -/* Specification. */ -#include <spawn.h> - -#include <string.h> - -/* Set signal mask for the new process in ATTR to SIGMASK. */ -int -posix_spawnattr_setsigmask (posix_spawnattr_t *attr, - const sigset_t *sigmask) -{ - /* Copy the sigset_t data to the user buffer. */ - memcpy (&attr->_ss, sigmask, sizeof (sigset_t)); - - return 0; -} diff --git a/contrib/tools/bison/lib/stdio--.h b/contrib/tools/bison/lib/stdio--.h deleted file mode 100644 index 5d9b19b50a..0000000000 --- a/contrib/tools/bison/lib/stdio--.h +++ /dev/null @@ -1,48 +0,0 @@ -/* Like stdio.h, but redefine some names to avoid glitches. - - Copyright (C) 2005-2006, 2009-2013 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 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 Paul Eggert. */ - -#include <stdio.h> -#include <unistd.h> -#include "stdio-safer.h" - -#if defined(_WIN32) -int fpurge(FILE *stream); -int fseeko(FILE *stream, off_t offset, int whence); -off_t ftello(FILE *stream); -#endif - -#if GNULIB_FOPEN_SAFER -# undef fopen -# define fopen fopen_safer -#endif - -#if GNULIB_FREOPEN_SAFER -# undef freopen -# define freopen freopen_safer -#endif - -#if GNULIB_TMPFILE_SAFER -# undef tmpfile -# define tmpfile tmpfile_safer -#endif - -#if GNULIB_POPEN_SAFER -# undef popen -# define popen popen_safer -#endif diff --git a/contrib/tools/bison/lib/unsetenv.c b/contrib/tools/bison/lib/unsetenv.c deleted file mode 100644 index c58c82f4f4..0000000000 --- a/contrib/tools/bison/lib/unsetenv.c +++ /dev/null @@ -1,127 +0,0 @@ -/* Copyright (C) 1992, 1995-2002, 2005-2013 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/>. */ - -/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc - optimizes away the name == NULL test below. */ -#define _GL_ARG_NONNULL(params) - -#include <config.h> - -/* Specification. */ -#include <stdlib.h> - -#include <errno.h> -#if !_LIBC -# define __set_errno(ev) ((errno) = (ev)) -#endif - -#include <string.h> -#include <unistd.h> - -#if !_LIBC -# define __environ environ -#endif - -#if _LIBC -/* This lock protects against simultaneous modifications of 'environ'. */ -# include <bits/libc-lock.h> -__libc_lock_define_initialized (static, envlock) -# define LOCK __libc_lock_lock (envlock) -# define UNLOCK __libc_lock_unlock (envlock) -#else -# define LOCK -# define UNLOCK -#endif - -/* In the GNU C library we must keep the namespace clean. */ -#ifdef _LIBC -# define unsetenv __unsetenv -#endif - -#if _LIBC || !HAVE_UNSETENV - -int -unsetenv (const char *name) -{ - size_t len; - char **ep; - - if (name == NULL || *name == '\0' || strchr (name, '=') != NULL) - { - __set_errno (EINVAL); - return -1; - } - - len = strlen (name); - - LOCK; - - ep = __environ; - while (*ep != NULL) - if (!strncmp (*ep, name, len) && (*ep)[len] == '=') - { - /* Found it. Remove this pointer by moving later ones back. */ - char **dp = ep; - - do - dp[0] = dp[1]; - while (*dp++); - /* Continue the loop in case NAME appears again. */ - } - else - ++ep; - - UNLOCK; - - return 0; -} - -#ifdef _LIBC -# undef unsetenv -weak_alias (__unsetenv, unsetenv) -#endif - -#else /* HAVE_UNSETENV */ - -# undef unsetenv -# if !HAVE_DECL_UNSETENV -# if VOID_UNSETENV -extern void unsetenv (const char *); -# else -extern int unsetenv (const char *); -# endif -# endif - -/* Call the underlying unsetenv, in case there is hidden bookkeeping - that needs updating beyond just modifying environ. */ -int -rpl_unsetenv (const char *name) -{ - int result = 0; - if (!name || !*name || strchr (name, '=')) - { - errno = EINVAL; - return -1; - } - while (getenv (name)) -# if !VOID_UNSETENV - result = -# endif - unsetenv (name); - return result; -} - -#endif /* HAVE_UNSETENV */ diff --git a/contrib/tools/bison/lib/vasprintf.c b/contrib/tools/bison/lib/vasprintf.c deleted file mode 100644 index afc8056194..0000000000 --- a/contrib/tools/bison/lib/vasprintf.c +++ /dev/null @@ -1,53 +0,0 @@ -/* Formatted output to strings. - Copyright (C) 1999, 2002, 2006-2013 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. */ -#ifdef IN_LIBASPRINTF -# include "vasprintf.h" -#else -# include <stdio.h> -#endif - -#include <errno.h> -#include <limits.h> -#include <stdlib.h> - -#include "vasnprintf.h" - -int -vasprintf (char **resultp, const char *format, va_list args) -{ - size_t length; - char *result = vasnprintf (NULL, &length, format, args); - if (result == NULL) - return -1; - - if (length > INT_MAX) - { - free (result); -#if (defined _MSC_VER) && (_MSC_VER < 1800) -#else - errno = EOVERFLOW; -#endif - return -1; - } - - *resultp = result; - /* Return the number of resulting bytes, excluding the trailing NUL. */ - return length; -} diff --git a/contrib/tools/bison/lib/version-etc-fsf.c b/contrib/tools/bison/lib/version-etc-fsf.c deleted file mode 100644 index e1c69da94a..0000000000 --- a/contrib/tools/bison/lib/version-etc-fsf.c +++ /dev/null @@ -1,30 +0,0 @@ -/* Variable with FSF copyright information, for version-etc. - Copyright (C) 1999-2006, 2009-2013 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 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 Jim Meyering. */ - -#include <config.h> - -/* Specification. */ -#include "version-etc.h" - -/* Default copyright goes to the FSF. */ - -const char version_etc_copyright[] = - /* Do *not* mark this string for translation. %s is a copyright - symbol suitable for this locale, and %d is the copyright - year. */ - "Copyright %s %d Free Software Foundation, Inc."; diff --git a/contrib/tools/bison/lib/version-etc.c b/contrib/tools/bison/lib/version-etc.c deleted file mode 100644 index b7d23ab597..0000000000 --- a/contrib/tools/bison/lib/version-etc.c +++ /dev/null @@ -1,258 +0,0 @@ -/* Print --version and bug-reporting information in a consistent format. - Copyright (C) 1999-2013 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 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 Jim Meyering. */ - -#include <config.h> - -/* Specification. */ -#include "version-etc.h" - -#include <stdarg.h> -#include <stdio.h> -#include <stdlib.h> - -#if USE_UNLOCKED_IO -# include "unlocked-io.h" -#endif - -#include "gettext.h" -#define _(msgid) gettext (msgid) - -/* If you use AM_INIT_AUTOMAKE's no-define option, - PACKAGE is not defined. Use PACKAGE_TARNAME instead. */ -#if ! defined PACKAGE && defined PACKAGE_TARNAME -# define PACKAGE PACKAGE_TARNAME -#endif - -enum { COPYRIGHT_YEAR = 2013 }; - -/* The three functions below display the --version information the - standard way. - - If COMMAND_NAME is NULL, the PACKAGE is assumed to be the name of - the program. The formats are therefore: - - PACKAGE VERSION - - or - - COMMAND_NAME (PACKAGE) VERSION. - - The functions differ in the way they are passed author names. */ - -/* Display the --version information the standard way. - - Author names are given in the array AUTHORS. N_AUTHORS is the - number of elements in the array. */ -void -version_etc_arn (FILE *stream, - const char *command_name, const char *package, - const char *version, - const char * const * authors, size_t n_authors) -{ - if (command_name) - fprintf (stream, "%s (%s) %s\n", command_name, package, version); - else - fprintf (stream, "%s %s\n", package, version); - -#ifdef PACKAGE_PACKAGER -# ifdef PACKAGE_PACKAGER_VERSION - fprintf (stream, _("Packaged by %s (%s)\n"), PACKAGE_PACKAGER, - PACKAGE_PACKAGER_VERSION); -# else - fprintf (stream, _("Packaged by %s\n"), PACKAGE_PACKAGER); -# endif -#endif - - /* TRANSLATORS: Translate "(C)" to the copyright symbol - (C-in-a-circle), if this symbol is available in the user's - locale. Otherwise, do not translate "(C)"; leave it as-is. */ - fprintf (stream, version_etc_copyright, _("(C)"), COPYRIGHT_YEAR); - - fputs (_("\ -\n\ -License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n\ -This is free software: you are free to change and redistribute it.\n\ -There is NO WARRANTY, to the extent permitted by law.\n\ -\n\ -"), - stream); - - switch (n_authors) - { - case 0: - /* The caller must provide at least one author name. */ - abort (); - case 1: - /* TRANSLATORS: %s denotes an author name. */ - fprintf (stream, _("Written by %s.\n"), authors[0]); - break; - case 2: - /* TRANSLATORS: Each %s denotes an author name. */ - fprintf (stream, _("Written by %s and %s.\n"), authors[0], authors[1]); - break; - case 3: - /* TRANSLATORS: Each %s denotes an author name. */ - fprintf (stream, _("Written by %s, %s, and %s.\n"), - authors[0], authors[1], authors[2]); - break; - case 4: - /* TRANSLATORS: Each %s denotes an author name. - You can use line breaks, estimating that each author name occupies - ca. 16 screen columns and that a screen line has ca. 80 columns. */ - fprintf (stream, _("Written by %s, %s, %s,\nand %s.\n"), - authors[0], authors[1], authors[2], authors[3]); - break; - case 5: - /* TRANSLATORS: Each %s denotes an author name. - You can use line breaks, estimating that each author name occupies - ca. 16 screen columns and that a screen line has ca. 80 columns. */ - fprintf (stream, _("Written by %s, %s, %s,\n%s, and %s.\n"), - authors[0], authors[1], authors[2], authors[3], authors[4]); - break; - case 6: - /* TRANSLATORS: Each %s denotes an author name. - You can use line breaks, estimating that each author name occupies - ca. 16 screen columns and that a screen line has ca. 80 columns. */ - fprintf (stream, _("Written by %s, %s, %s,\n%s, %s, and %s.\n"), - authors[0], authors[1], authors[2], authors[3], authors[4], - authors[5]); - break; - case 7: - /* TRANSLATORS: Each %s denotes an author name. - You can use line breaks, estimating that each author name occupies - ca. 16 screen columns and that a screen line has ca. 80 columns. */ - fprintf (stream, _("Written by %s, %s, %s,\n%s, %s, %s, and %s.\n"), - authors[0], authors[1], authors[2], authors[3], authors[4], - authors[5], authors[6]); - break; - case 8: - /* TRANSLATORS: Each %s denotes an author name. - You can use line breaks, estimating that each author name occupies - ca. 16 screen columns and that a screen line has ca. 80 columns. */ - fprintf (stream, _("\ -Written by %s, %s, %s,\n%s, %s, %s, %s,\nand %s.\n"), - authors[0], authors[1], authors[2], authors[3], authors[4], - authors[5], authors[6], authors[7]); - break; - case 9: - /* TRANSLATORS: Each %s denotes an author name. - You can use line breaks, estimating that each author name occupies - ca. 16 screen columns and that a screen line has ca. 80 columns. */ - fprintf (stream, _("\ -Written by %s, %s, %s,\n%s, %s, %s, %s,\n%s, and %s.\n"), - authors[0], authors[1], authors[2], authors[3], authors[4], - authors[5], authors[6], authors[7], authors[8]); - break; - default: - /* 10 or more authors. Use an abbreviation, since the human reader - will probably not want to read the entire list anyway. */ - /* TRANSLATORS: Each %s denotes an author name. - You can use line breaks, estimating that each author name occupies - ca. 16 screen columns and that a screen line has ca. 80 columns. */ - fprintf (stream, _("\ -Written by %s, %s, %s,\n%s, %s, %s, %s,\n%s, %s, and others.\n"), - authors[0], authors[1], authors[2], authors[3], authors[4], - authors[5], authors[6], authors[7], authors[8]); - break; - } -} - -/* Display the --version information the standard way. See the initial - comment to this module, for more information. - - Author names are given in the NULL-terminated array AUTHORS. */ -void -version_etc_ar (FILE *stream, - const char *command_name, const char *package, - const char *version, const char * const * authors) -{ - size_t n_authors; - - for (n_authors = 0; authors[n_authors]; n_authors++) - ; - version_etc_arn (stream, command_name, package, version, authors, n_authors); -} - -/* Display the --version information the standard way. See the initial - comment to this module, for more information. - - Author names are given in the NULL-terminated va_list AUTHORS. */ -void -version_etc_va (FILE *stream, - const char *command_name, const char *package, - const char *version, va_list authors) -{ - size_t n_authors; - const char *authtab[10]; - - for (n_authors = 0; - n_authors < 10 - && (authtab[n_authors] = va_arg (authors, const char *)) != NULL; - n_authors++) - ; - version_etc_arn (stream, command_name, package, version, - authtab, n_authors); -} - - -/* Display the --version information the standard way. - - If COMMAND_NAME is NULL, the PACKAGE is assumed to be the name of - the program. The formats are therefore: - - PACKAGE VERSION - - or - - COMMAND_NAME (PACKAGE) VERSION. - - The authors names are passed as separate arguments, with an additional - NULL argument at the end. */ -void -version_etc (FILE *stream, - const char *command_name, const char *package, - const char *version, /* const char *author1, ...*/ ...) -{ - va_list authors; - - va_start (authors, version); - version_etc_va (stream, command_name, package, version, authors); - va_end (authors); -} - -void -emit_bug_reporting_address (void) -{ - /* TRANSLATORS: The placeholder indicates the bug-reporting address - for this package. Please add _another line_ saying - "Report translation bugs to <...>\n" with the address for translation - bugs (typically your translation team's web or email address). */ - printf (_("\nReport bugs to: %s\n"), PACKAGE_BUGREPORT); -#ifdef PACKAGE_PACKAGER_BUG_REPORTS - printf (_("Report %s bugs to: %s\n"), PACKAGE_PACKAGER, - PACKAGE_PACKAGER_BUG_REPORTS); -#endif -#ifdef PACKAGE_URL - printf (_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL); -#else - printf (_("%s home page: <http://www.gnu.org/software/%s/>\n"), - PACKAGE_NAME, PACKAGE); -#endif - fputs (_("General help using GNU software: <http://www.gnu.org/gethelp/>\n"), - stdout); -} diff --git a/contrib/tools/bison/lib/version-etc.h b/contrib/tools/bison/lib/version-etc.h deleted file mode 100644 index 6c3d08431c..0000000000 --- a/contrib/tools/bison/lib/version-etc.h +++ /dev/null @@ -1,78 +0,0 @@ -/* Print --version and bug-reporting information in a consistent format. - Copyright (C) 1999, 2003, 2005, 2009-2013 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 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 Jim Meyering. */ - -#ifndef VERSION_ETC_H -# define VERSION_ETC_H 1 - -# include <stdarg.h> -# include <stdio.h> - -/* The 'sentinel' attribute was added in gcc 4.0. */ -#ifndef _GL_ATTRIBUTE_SENTINEL -# if 4 <= __GNUC__ -# define _GL_ATTRIBUTE_SENTINEL __attribute__ ((__sentinel__)) -# else -# define _GL_ATTRIBUTE_SENTINEL /* empty */ -# endif -#endif - -extern const char version_etc_copyright[]; - -/* The three functions below display the --version information in the - standard way: command and package names, package version, followed - by a short GPLv3+ notice and a list of up to 10 author names. - - If COMMAND_NAME is NULL, the PACKAGE is assumed to be the name of - the program. The formats are therefore: - - PACKAGE VERSION - - or - - COMMAND_NAME (PACKAGE) VERSION. - - The functions differ in the way they are passed author names: */ - -/* N_AUTHORS names are supplied in array AUTHORS. */ -extern void version_etc_arn (FILE *stream, - const char *command_name, const char *package, - const char *version, - const char * const * authors, size_t n_authors); - -/* Names are passed in the NULL-terminated array AUTHORS. */ -extern void version_etc_ar (FILE *stream, - const char *command_name, const char *package, - const char *version, const char * const * authors); - -/* Names are passed in the NULL-terminated va_list. */ -extern void version_etc_va (FILE *stream, - const char *command_name, const char *package, - const char *version, va_list authors); - -/* Names are passed as separate arguments, with an additional - NULL argument at the end. */ -extern void version_etc (FILE *stream, - const char *command_name, const char *package, - const char *version, - /* const char *author1, ..., NULL */ ...) - _GL_ATTRIBUTE_SENTINEL; - -/* Display the usual "Report bugs to" stanza. */ -extern void emit_bug_reporting_address (void); - -#endif /* VERSION_ETC_H */ diff --git a/contrib/tools/bison/lib/xasprintf.c b/contrib/tools/bison/lib/xasprintf.c deleted file mode 100644 index 1808b70182..0000000000 --- a/contrib/tools/bison/lib/xasprintf.c +++ /dev/null @@ -1,34 +0,0 @@ -/* vasprintf and asprintf with out-of-memory checking. - Copyright (C) 1999, 2002-2004, 2006, 2009-2013 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 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/>. */ - -#include <config.h> - -/* Specification. */ -#include "xvasprintf.h" - -char * -xasprintf (const char *format, ...) -{ - va_list args; - char *result; - - va_start (args, format); - result = xvasprintf (format, args); - va_end (args); - - return result; -} diff --git a/contrib/tools/bison/lib/xprintf.c b/contrib/tools/bison/lib/xprintf.c deleted file mode 100644 index e24b4f1875..0000000000 --- a/contrib/tools/bison/lib/xprintf.c +++ /dev/null @@ -1,79 +0,0 @@ -/* printf wrappers that fail immediately for non-file-related errors - Copyright (C) 2007, 2009-2013 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 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/>. */ - -#include <config.h> - -#include "xprintf.h" - -#include <errno.h> - -#include "error.h" -#include "exitfail.h" -#include "gettext.h" - -/* written by Jim Meyering */ - -/* Just like printf, but call error if it fails without setting the - stream's error indicator. */ -int -xprintf (char const *restrict format, ...) -{ - va_list args; - int retval; - va_start (args, format); - retval = xvprintf (format, args); - va_end (args); - - return retval; -} - -/* Just like vprintf, but call error if it fails without setting the - stream's error indicator. */ -int -xvprintf (char const *restrict format, va_list args) -{ - int retval = vprintf (format, args); - if (retval < 0 && ! ferror (stdout)) - error (exit_failure, errno, gettext ("cannot perform formatted output")); - - return retval; -} - -/* Just like fprintf, but call error if it fails without setting the - stream's error indicator. */ -int -xfprintf (FILE *restrict stream, char const *restrict format, ...) -{ - va_list args; - int retval; - va_start (args, format); - retval = xvfprintf (stream, format, args); - va_end (args); - - return retval; -} - -/* Just like vfprintf, but call error if it fails without setting the - stream's error indicator. */ -int -xvfprintf (FILE *restrict stream, char const *restrict format, va_list args) -{ - int retval = vfprintf (stream, format, args); - if (retval < 0 && ! ferror (stream)) - error (exit_failure, errno, gettext ("cannot perform formatted output")); - - return retval; -} diff --git a/contrib/tools/bison/lib/xprintf.h b/contrib/tools/bison/lib/xprintf.h deleted file mode 100644 index 62986a8cee..0000000000 --- a/contrib/tools/bison/lib/xprintf.h +++ /dev/null @@ -1,45 +0,0 @@ -/* printf wrappers that fail immediately for non-file-related errors - Copyright (C) 2007-2013 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 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 _XPRINTF_H -#define _XPRINTF_H - -#include <stdarg.h> -#include <stdio.h> - -/* 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 - -extern int xprintf (char const *restrict format, ...) - _GL_ATTRIBUTE_FORMAT ((__printf__, 1, 2)); -extern int xvprintf (char const *restrict format, va_list args) - _GL_ATTRIBUTE_FORMAT ((__printf__, 1, 0)); -extern int xfprintf (FILE *restrict stream, char const *restrict format, ...) - _GL_ATTRIBUTE_FORMAT ((__printf__, 2, 3)); -extern int xvfprintf (FILE *restrict stream, char const *restrict format, - va_list args) - _GL_ATTRIBUTE_FORMAT ((__printf__, 2, 0)); - -#endif diff --git a/contrib/tools/bison/lib/ya.make b/contrib/tools/bison/lib/ya.make index c08666010c..74520fe268 100644 --- a/contrib/tools/bison/lib/ya.make +++ b/contrib/tools/bison/lib/ya.make @@ -46,7 +46,6 @@ ENDIF() SRCS( abitset.c argmatch.c - asnprintf.c basename-lgpl.c basename.c binary-io.c @@ -56,15 +55,11 @@ SRCS( bitsetv-print.c bitsetv.c c-ctype.c - c-stack.c c-strcasecmp.c c-strncasecmp.c - calloc.c - clean-temp.c cloexec.c - close-stream.c close.c - closein.c + close-stream.c closeout.c concat-filename.c dirname-lgpl.c @@ -74,45 +69,30 @@ SRCS( dup2.c ebitset.c error.c - execute.c exitfail.c fatal-signal.c - fclose.c fcntl.c fd-hook.c fd-safer-flag.c fd-safer.c - fflush.c - filenamecat-lgpl.c - filenamecat.c - float.c fopen-safer.c - fpurge.c - freading.c fstat.c get-errno.c getdtablesize.c getopt.c getopt1.c - gl_avltree_oset.c - gl_linkedhash_list.c - gl_list.c - gl_oset.c - gl_xlist.c - gl_xoset.c hash.c - isnand.c - isnanf.c - isnanl.c itold.c + isnanl.c + isnand.c lbitset.c localcharset.c lseek.c lstat.c malloc.c malloca.c - mbrtowc.c mbswidth.c + mbrtowc.c memchr2.c mkstemp-safer.c nl_langinfo.c @@ -133,9 +113,6 @@ SRCS( rmdir.c secure_getenv.c sig-handler.c - signbitd.c - signbitf.c - signbitl.c spawn-pipe.c stat.c stpcpy.c @@ -146,21 +123,16 @@ SRCS( timevar.c tmpdir.c unistd.c - unsetenv.c vasnprintf.c vbitset.c verror.c - version-etc-fsf.c - version-etc.c wait-process.c wctype-h.c xalloc-die.c - xasprintf.c xconcat-filename.c xmalloc.c xmalloca.c xmemdup0.c - xprintf.c xsize.c xstrndup.c xvasprintf.c @@ -168,9 +140,7 @@ SRCS( IF (NOT MUSL) SRCS( - freadahead.c fseterr.c - # fseek.c ) ENDIF() @@ -194,7 +164,6 @@ IF (OS_WINDOWS) perror.c strstr.c mkstemp.c - vasprintf.c strsignal.c mkdtemp.c fseeko.c @@ -208,15 +177,6 @@ IF (OS_WINDOWS) sigaction.c sigprocmask.c snprintf.c - spawn_faction_addclose.c - spawn_faction_adddup2.c - spawn_faction_addopen.c - spawn_faction_destroy.c - spawn_faction_init.c - spawnattr_destroy.c - spawnattr_init.c - spawnattr_setflags.c - spawnattr_setsigmask.c spawni.c spawnp.c strndup.c |