aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2007-08-07 08:31:47 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2007-08-07 08:31:47 +0000
commit7a8b7409ec5c59cb8a09ce78d42e0ce6c954a179 (patch)
tree2c4777336b9639c02fc893a584030876b53b37ca /lib
parent31385a04a9ce7101a1f564c61616ad11d8b1e061 (diff)
downloadanubis-7a8b7409ec5c59cb8a09ce78d42e0ce6c954a179.tar.gz
anubis-7a8b7409ec5c59cb8a09ce78d42e0ce6c954a179.tar.bz2
*** empty log message ***
Diffstat (limited to 'lib')
-rw-r--r--lib/exit.h32
-rw-r--r--lib/exitfail.c27
-rw-r--r--lib/exitfail.h20
-rw-r--r--lib/getdelim.c128
-rw-r--r--lib/getdelim.h28
-rw-r--r--lib/getopt_.h225
-rw-r--r--lib/getopt_int.h131
-rw-r--r--lib/getpass.h31
-rw-r--r--lib/snprintf.c829
-rw-r--r--lib/stdbool_.h115
10 files changed, 0 insertions, 1566 deletions
diff --git a/lib/exit.h b/lib/exit.h
deleted file mode 100644
index 9dbfb7c..0000000
--- a/lib/exit.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/* exit() function.
- Copyright (C) 1995, 2001 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 2, 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, write to the Free Software Foundation,
- Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
-
-#ifndef _EXIT_H
-#define _EXIT_H
-
-/* Get exit() declaration. */
-#include <stdlib.h>
-
-/* Some systems do not define EXIT_*, even with STDC_HEADERS. */
-#ifndef EXIT_SUCCESS
-# define EXIT_SUCCESS 0
-#endif
-#ifndef EXIT_FAILURE
-# define EXIT_FAILURE 1
-#endif
-
-#endif /* _EXIT_H */
diff --git a/lib/exitfail.c b/lib/exitfail.c
deleted file mode 100644
index 27d38c3..0000000
--- a/lib/exitfail.c
+++ /dev/null
@@ -1,27 +0,0 @@
-/* Failure exit status
-
- Copyright (C) 2002, 2003 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 2, 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; see the file COPYING.
- If not, write to the Free Software Foundation,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include "exitfail.h"
-#include "exit.h"
-
-int volatile exit_failure = EXIT_FAILURE;
diff --git a/lib/exitfail.h b/lib/exitfail.h
deleted file mode 100644
index e46cf9c..0000000
--- a/lib/exitfail.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/* Failure exit status
-
- Copyright (C) 2002 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 2, 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; see the file COPYING.
- If not, write to the Free Software Foundation,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
-
-extern int volatile exit_failure;
diff --git a/lib/getdelim.c b/lib/getdelim.c
deleted file mode 100644
index a131b0c..0000000
--- a/lib/getdelim.c
+++ /dev/null
@@ -1,128 +0,0 @@
-/* getdelim.c --- Implementation of replacement getdelim function.
- Copyright (C) 1994, 1996, 1997, 1998, 2001, 2003, 2005 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 2, 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, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA. */
-
-/* Ported from glibc by Simon Josefsson. */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include "getdelim.h"
-
-#include <limits.h>
-#include <stdlib.h>
-#include <errno.h>
-
-#ifndef SIZE_MAX
-# define SIZE_MAX ((size_t) -1)
-#endif
-#ifndef SSIZE_MAX
-# define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2))
-#endif
-#if !HAVE_FLOCKFILE
-# undef flockfile
-# define flockfile(x) ((void) 0)
-#endif
-#if !HAVE_FUNLOCKFILE
-# undef funlockfile
-# define funlockfile(x) ((void) 0)
-#endif
-
-/* Read up to (and including) a DELIMITER from FP into *LINEPTR (and
- NUL-terminate it). *LINEPTR is a pointer returned from malloc (or
- NULL), pointing to *N characters of space. It is realloc'ed as
- necessary. Returns the number of characters read (not including
- the null terminator), or -1 on error or EOF. */
-
-ssize_t
-getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp)
-{
- ssize_t result;
- size_t cur_len = 0;
-
- if (lineptr == NULL || n == NULL || fp == NULL)
- {
- errno = EINVAL;
- return -1;
- }
-
- flockfile (fp);
-
- if (*lineptr == NULL || *n == 0)
- {
- *n = 120;
- *lineptr = (char *) malloc (*n);
- if (*lineptr == NULL)
- {
- result = -1;
- goto unlock_return;
- }
- }
-
- for (;;)
- {
- int i;
-
- i = getc (fp);
- if (i == EOF)
- {
- result = -1;
- break;
- }
-
- /* Make enough space for len+1 (for final NUL) bytes. */
- if (cur_len + 1 >= *n)
- {
- size_t needed_max =
- SSIZE_MAX < SIZE_MAX ? (size_t) SSIZE_MAX + 1 : SIZE_MAX;
- size_t needed = 2 * *n + 1; /* Be generous. */
- char *new_lineptr;
-
- if (needed_max < needed)
- needed = needed_max;
- if (cur_len + 1 >= needed)
- {
- result = -1;
- goto unlock_return;
- }
-
- new_lineptr = (char *) realloc (*lineptr, needed);
- if (new_lineptr == NULL)
- {
- result = -1;
- goto unlock_return;
- }
-
- *lineptr = new_lineptr;
- *n = needed;
- }
-
- (*lineptr)[cur_len] = i;
- cur_len++;
-
- if (i == delimiter)
- break;
- }
- (*lineptr)[cur_len] = '\0';
- result = cur_len ? cur_len : result;
-
- unlock_return:
- funlockfile (fp);
- return result;
-}
diff --git a/lib/getdelim.h b/lib/getdelim.h
deleted file mode 100644
index 8bc6130..0000000
--- a/lib/getdelim.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/* getdelim.h --- Prototype for replacement getdelim function.
- Copyright (C) 2005 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 2, 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, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA. */
-
-/* Written by Simon Josefsson. */
-
-/* Get size_t, FILE, ssize_t. And getdelim, if available. */
-# include <stddef.h>
-# include <stdio.h>
-# include <sys/types.h>
-
-#if !HAVE_DECL_GETDELIM
-ssize_t getdelim (char **lineptr, size_t *n, int delimiter, FILE *stream);
-#endif /* !HAVE_GETDELIM */
diff --git a/lib/getopt_.h b/lib/getopt_.h
deleted file mode 100644
index 3c406e5..0000000
--- a/lib/getopt_.h
+++ /dev/null
@@ -1,225 +0,0 @@
-/* Declarations for getopt.
- Copyright (C) 1989-1994,1996-1999,2001,2003,2004,2005
- 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 2, 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, write to the Free Software Foundation,
- Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
-
-#ifndef _GETOPT_H
-
-#ifndef __need_getopt
-# define _GETOPT_H 1
-#endif
-
-/* Standalone applications should #define __GETOPT_PREFIX to an
- identifier that prefixes the external functions and variables
- defined in this header. When this happens, include the
- headers that might declare getopt so that they will not cause
- confusion if included after this file. Then systematically rename
- identifiers so that they do not collide with the system functions
- and variables. Renaming avoids problems with some compilers and
- linkers. */
-#if defined __GETOPT_PREFIX && !defined __need_getopt
-# include <stdlib.h>
-# include <stdio.h>
-# include <unistd.h>
-# undef __need_getopt
-# undef getopt
-# undef getopt_long
-# undef getopt_long_only
-# undef optarg
-# undef opterr
-# undef optind
-# undef optopt
-# define __GETOPT_CONCAT(x, y) x ## y
-# define __GETOPT_XCONCAT(x, y) __GETOPT_CONCAT (x, y)
-# define __GETOPT_ID(y) __GETOPT_XCONCAT (__GETOPT_PREFIX, y)
-# define getopt __GETOPT_ID (getopt)
-# define getopt_long __GETOPT_ID (getopt_long)
-# define getopt_long_only __GETOPT_ID (getopt_long_only)
-# define optarg __GETOPT_ID (optarg)
-# define opterr __GETOPT_ID (opterr)
-# define optind __GETOPT_ID (optind)
-# define optopt __GETOPT_ID (optopt)
-#endif
-
-/* Standalone applications get correct prototypes for getopt_long and
- getopt_long_only; they declare "char **argv". libc uses prototypes
- with "char *const *argv" that are incorrect because getopt_long and
- getopt_long_only can permute argv; this is required for backward
- compatibility (e.g., for LSB 2.0.1).
-
- This used to be `#if defined __GETOPT_PREFIX && !defined __need_getopt',
- but it caused redefinition warnings if both unistd.h and getopt.h were
- included, since unistd.h includes getopt.h having previously defined
- __need_getopt.
-
- The only place where __getopt_argv_const is used is in definitions
- of getopt_long and getopt_long_only below, but these are visible
- only if __need_getopt is not defined, so it is quite safe to rewrite
- the conditional as follows:
-*/
-#if !defined __need_getopt
-# if defined __GETOPT_PREFIX
-# define __getopt_argv_const /* empty */
-# else
-# define __getopt_argv_const const
-# endif
-#endif
-
-/* If __GNU_LIBRARY__ is not already defined, either we are being used
- standalone, or this is the first header included in the source file.
- If we are being used with glibc, we need to include <features.h>, but
- that does not exist if we are standalone. So: if __GNU_LIBRARY__ is
- not defined, include <ctype.h>, which will pull in <features.h> for us
- if it's from glibc. (Why ctype.h? It's guaranteed to exist and it
- doesn't flood the namespace with stuff the way some other headers do.) */
-#if !defined __GNU_LIBRARY__
-# include <ctype.h>
-#endif
-
-#ifndef __THROW
-# ifndef __GNUC_PREREQ
-# define __GNUC_PREREQ(maj, min) (0)
-# endif
-# if defined __cplusplus && __GNUC_PREREQ (2,8)
-# define __THROW throw ()
-# else
-# define __THROW
-# endif
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* For communication from `getopt' to the caller.
- When `getopt' finds an option that takes an argument,
- the argument value is returned here.
- Also, when `ordering' is RETURN_IN_ORDER,
- each non-option ARGV-element is returned here. */
-
-extern char *optarg;
-
-/* Index in ARGV of the next element to be scanned.
- This is used for communication to and from the caller
- and for communication between successive calls to `getopt'.
-
- On entry to `getopt', zero means this is the first call; initialize.
-
- When `getopt' returns -1, this is the index of the first of the
- non-option elements that the caller should itself scan.
-
- Otherwise, `optind' communicates from one call to the next
- how much of ARGV has been scanned so far. */
-
-extern int optind;
-
-/* Callers store zero here to inhibit the error message `getopt' prints
- for unrecognized options. */
-
-extern int opterr;
-
-/* Set to an option character which was unrecognized. */
-
-extern int optopt;
-
-#ifndef __need_getopt
-/* Describe the long-named options requested by the application.
- The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
- of `struct option' terminated by an element containing a name which is
- zero.
-
- The field `has_arg' is:
- no_argument (or 0) if the option does not take an argument,
- required_argument (or 1) if the option requires an argument,
- optional_argument (or 2) if the option takes an optional argument.
-
- If the field `flag' is not NULL, it points to a variable that is set
- to the value given in the field `val' when the option is found, but
- left unchanged if the option is not found.
-
- To have a long-named option do something other than set an `int' to
- a compiled-in constant, such as set a value from `optarg', set the
- option's `flag' field to zero and its `val' field to a nonzero
- value (the equivalent single-letter option character, if there is
- one). For long options that have a zero `flag' field, `getopt'
- returns the contents of the `val' field. */
-
-struct option
-{
- const char *name;
- /* has_arg can't be an enum because some compilers complain about
- type mismatches in all the code that assumes it is an int. */
- int has_arg;
- int *flag;
- int val;
-};
-
-/* Names for the values of the `has_arg' field of `struct option'. */
-
-# define no_argument 0
-# define required_argument 1
-# define optional_argument 2
-#endif /* need getopt */
-
-
-/* Get definitions and prototypes for functions to process the
- arguments in ARGV (ARGC of them, minus the program name) for
- options given in OPTS.
-
- Return the option character from OPTS just read. Return -1 when
- there are no more options. For unrecognized options, or options
- missing arguments, `optopt' is set to the option letter, and '?' is
- returned.
-
- The OPTS string is a list of characters which are recognized option
- letters, optionally followed by colons, specifying that that letter
- takes an argument, to be placed in `optarg'.
-
- If a letter in OPTS is followed by two colons, its argument is
- optional. This behavior is specific to the GNU `getopt'.
-
- The argument `--' causes premature termination of argument
- scanning, explicitly telling `getopt' that there are no more
- options.
-
- If OPTS begins with `--', then non-option arguments are treated as
- arguments to the option '\0'. This behavior is specific to the GNU
- `getopt'. */
-
-extern int getopt (int ___argc, char *const *___argv, const char *__shortopts)
- __THROW;
-
-#ifndef __need_getopt
-extern int getopt_long (int ___argc, char *__getopt_argv_const *___argv,
- const char *__shortopts,
- const struct option *__longopts, int *__longind)
- __THROW;
-extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv,
- const char *__shortopts,
- const struct option *__longopts, int *__longind)
- __THROW;
-
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-/* Make sure we later can get all the definitions and declarations. */
-#undef __need_getopt
-
-#endif /* getopt.h */
diff --git a/lib/getopt_int.h b/lib/getopt_int.h
deleted file mode 100644
index 401579f..0000000
--- a/lib/getopt_int.h
+++ /dev/null
@@ -1,131 +0,0 @@
-/* Internal declarations for getopt.
- Copyright (C) 1989-1994,1996-1999,2001,2003,2004
- 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 2, 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, write to the Free Software Foundation,
- Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
-
-#ifndef _GETOPT_INT_H
-#define _GETOPT_INT_H 1
-
-extern int _getopt_internal (int ___argc, char **___argv,
- const char *__shortopts,
- const struct option *__longopts, int *__longind,
- int __long_only, int __posixly_correct);
-
-
-/* Reentrant versions which can handle parsing multiple argument
- vectors at the same time. */
-
-/* Data type for reentrant functions. */
-struct _getopt_data
-{
- /* These have exactly the same meaning as the corresponding global
- variables, except that they are used for the reentrant
- versions of getopt. */
- int optind;
- int opterr;
- int optopt;
- char *optarg;
-
- /* Internal members. */
-
- /* True if the internal members have been initialized. */
- int __initialized;
-
- /* The next char to be scanned in the option-element
- in which the last option character we returned was found.
- This allows us to pick up the scan where we left off.
-
- If this is zero, or a null string, it means resume the scan
- by advancing to the next ARGV-element. */
- char *__nextchar;
-
- /* Describe how to deal with options that follow non-option ARGV-elements.
-
- If the caller did not specify anything,
- the default is REQUIRE_ORDER if the environment variable
- POSIXLY_CORRECT is defined, PERMUTE otherwise.
-
- REQUIRE_ORDER means don't recognize them as options;
- stop option processing when the first non-option is seen.
- This is what Unix does.
- This mode of operation is selected by either setting the environment
- variable POSIXLY_CORRECT, or using `+' as the first character
- of the list of option characters, or by calling getopt.
-
- PERMUTE is the default. We permute the contents of ARGV as we
- scan, so that eventually all the non-options are at the end.
- This allows options to be given in any order, even with programs
- that were not written to expect this.
-
- RETURN_IN_ORDER is an option available to programs that were
- written to expect options and other ARGV-elements in any order
- and that care about the ordering of the two. We describe each
- non-option ARGV-element as if it were the argument of an option
- with character code 1. Using `-' as the first character of the
- list of option characters selects this mode of operation.
-
- The special argument `--' forces an end of option-scanning regardless
- of the value of `ordering'. In the case of RETURN_IN_ORDER, only
- `--' can cause `getopt' to return -1 with `optind' != ARGC. */
-
- enum
- {
- REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
- } __ordering;
-
- /* If the POSIXLY_CORRECT environment variable is set
- or getopt was called. */
- int __posixly_correct;
-
-
- /* Handle permutation of arguments. */
-
- /* Describe the part of ARGV that contains non-options that have
- been skipped. `first_nonopt' is the index in ARGV of the first
- of them; `last_nonopt' is the index after the last of them. */
-
- int __first_nonopt;
- int __last_nonopt;
-
-#if defined _LIBC && defined USE_NONOPTION_FLAGS
- int __nonoption_flags_max_len;
- int __nonoption_flags_len;
-# endif
-};
-
-/* The initializer is necessary to set OPTIND and OPTERR to their
- default values and to clear the initialization flag. */
-#define _GETOPT_DATA_INITIALIZER { 1, 1 }
-
-extern int _getopt_internal_r (int ___argc, char **___argv,
- const char *__shortopts,
- const struct option *__longopts, int *__longind,
- int __long_only, int __posixly_correct,
- struct _getopt_data *__data);
-
-extern int _getopt_long_r (int ___argc, char **___argv,
- const char *__shortopts,
- const struct option *__longopts, int *__longind,
- struct _getopt_data *__data);
-
-extern int _getopt_long_only_r (int ___argc, char **___argv,
- const char *__shortopts,
- const struct option *__longopts,
- int *__longind,
- struct _getopt_data *__data);
-
-#endif /* getopt_int.h */
diff --git a/lib/getpass.h b/lib/getpass.h
deleted file mode 100644
index bdff875..0000000
--- a/lib/getpass.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/* getpass.h -- Read a password of arbitrary length from /dev/tty or stdin.
- Copyright (C) 2004 Free Software Foundation, Inc.
- Contributed by Simon Josefsson <jas@extundo.com>, 2004.
-
- 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 2, 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, write to the Free Software Foundation,
- Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
-
-#ifndef GETPASS_H
-# define GETPASS_H
-
-/* Get getpass declaration, if available. */
-# include <unistd.h>
-
-# if defined HAVE_DECL_GETPASS && !HAVE_DECL_GETPASS
-/* Read a password of arbitrary length from /dev/tty or stdin. */
-char *getpass (const char *prompt);
-
-# endif
-
-#endif /* GETPASS_H */
diff --git a/lib/snprintf.c b/lib/snprintf.c
deleted file mode 100644
index 9e03912..0000000
--- a/lib/snprintf.c
+++ /dev/null
@@ -1,829 +0,0 @@
-
-/*
- Unix snprintf implementation.
- Version 1.3
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU Library General Public License as published by
- the Free Software Foundation; either version 2 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 Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- Revision History:
-
- 1.3:
- * add #include <config.h> ifdef HAVE_CONFIG_H
- * cosmetic change, when exponent is 0 print xxxE+00
- instead of xxxE-00
- 1.2:
- * put the program under LGPL.
- 1.1:
- * added changes from Miles Bader
- * corrected a bug with %f
- * added support for %#g
- * added more comments :-)
- 1.0:
- * supporting must ANSI syntaxic_sugars
- 0.0:
- * suppot %s %c %d
-
- THANKS(for the patches and ideas):
- Miles Bader
- Cyrille Rustom
- Jacek Slabocewiz
- Mike Parker(mouse)
-
-*/
-
-#include "snprintf.h"
-
-/*
- * Find the nth power of 10
- */
-PRIVATE double
-#ifdef __STDC__
-pow_10(int n)
-#else
-pow_10(n)
-int n;
-#endif
-{
- int i;
- double P;
-
- if (n < 0)
- for (i = 1, P = 1., n = -n ; i <= n ; i++) {P *= .1;}
- else
- for (i = 1, P = 1. ; i <= n ; i++) {P *= 10.0;}
- return P;
-}
-
-/*
- * Find the integral part of the log in base 10
- * Note: this not a real log10()
- I just need and approximation(integerpart) of x in:
- 10^x ~= r
- * log_10(200) = 2;
- * log_10(250) = 2;
- */
-PRIVATE int
-#ifdef __STDC__
-log_10(double r)
-#else
-log_10(r)
-double r;
-#endif
-{
- int i = 0;
- double result = 1.;
-
- if (r < 0.)
- r = -r;
-
- if (r < 1.) {
- while (result >= r) {result *= .1; i++;}
- return (-i);
- } else {
- while (result <= r) {result *= 10.; i++;}
- return (i - 1);
- }
-}
-
-/*
- * This function return the fraction part of a double
- * and set in ip the integral part.
- * In many ways it resemble the modf() found on most Un*x
- */
-PRIVATE double
-#ifdef __STDC__
-integral(double real, double * ip)
-#else
-integral(real, ip)
-double real;
-double * ip;
-#endif
-{
- int j;
- double i, s, p;
- double real_integral = 0.;
-
-/* take care of the obvious */
-/* equal to zero ? */
- if (real == 0.) {
- *ip = 0.;
- return (0.);
- }
-
-/* negative number ? */
- if (real < 0.)
- real = -real;
-
-/* a fraction ? */
- if ( real < 1.) {
- *ip = 0.;
- return real;
- }
-/* the real work :-) */
- for (j = log_10(real); j >= 0; j--) {
- p = pow_10(j);
- s = (real - real_integral)/p;
- i = 0.;
- while (i + 1. <= s) {i++;}
- real_integral += i*p;
- }
- *ip = real_integral;
- return (real - real_integral);
-}
-
-#define PRECISION 1.e-6
-/*
- * return an ascii representation of the integral part of the number
- * and set fract to be an ascii representation of the fraction part
- * the container for the fraction and the integral part or staticly
- * declare with fix size
- */
-PRIVATE char *
-#ifdef __STDC__
-numtoa(double number, int base, int precision, char ** fract)
-#else
-numtoa(number, base, precision, fract)
-double number;
-int base;
-int precision;
-char ** fract;
-#endif
-{
- register int i, j;
- double ip, fp; /* integer and fraction part */
- double fraction;
- int digits = MAX_INT - 1;
- static char integral_part[MAX_INT];
- static char fraction_part[MAX_FRACT];
- double sign;
- int ch;
-
-/* taking care of the obvious case: 0.0 */
- if (number == 0.) {
- integral_part[0] = '0';
- integral_part[1] = '\0';
- fraction_part[0] = '0';
- fraction_part[1] = '\0';
- return integral_part;
- }
-
-/* for negative numbers */
- if ((sign = number) < 0.) {
- number = -number;
- digits--; /* sign consume one digit */
- }
-
- fraction = integral(number, &ip);
- number = ip;
-/* do the integral part */
- if ( ip == 0.) {
- integral_part[0] = '0';
- i = 1;
- } else {
- for ( i = 0; i < digits && number != 0.; ++i) {
- number /= base;
- fp = integral(number, &ip);
- ch = (int)((fp + PRECISION)*base); /* force to round */
- integral_part[i] = (ch <= 9) ? ch + '0' : ch + 'a' - 10;
- if (! isxdigit(integral_part[i])) /* bail out overflow !! */
- break;
- number = ip;
- }
- }
-
-/* Oh No !! out of bound, ho well fill it up ! */
- if (number != 0.)
- for (i = 0; i < digits; ++i)
- integral_part[i] = '9';
-
-/* put the sign ? */
- if (sign < 0.)
- integral_part[i++] = '-';
-
- integral_part[i] = '\0';
-
-/* reverse every thing */
- for ( i--, j = 0; j < i; j++, i--)
- SWAP_INT(integral_part[i], integral_part[j]);
-
-/* the fractionnal part */
- for (i=0, fp=fraction; precision > 0 && i < MAX_FRACT ; i++, precision-- ) {
- fraction_part[i] = (int)((fp + PRECISION)*10. + '0');
- if (! isdigit(fraction_part[i])) /* underflow ? */
- break;
- fp = (fp*10.0) - (double)(long)((fp + PRECISION)*10.);
- }
- fraction_part[i] = '\0';
-
- if (fract != (char **)0)
- *fract = fraction_part;
-
- return integral_part;
-
-}
-
-/* for %d and friends, it puts in holder
- * the representation with the right padding
- */
-PRIVATE void
-#ifdef __STDC__
-decimal(struct DATA *p, double d)
-#else
-decimal(p, d)
-struct DATA *p;
-double d;
-#endif
-{
- char *tmp;
-
- tmp = itoa(d);
- p->width -= strlen(tmp);
- PAD_RIGHT(p);
- PUT_PLUS(d, p);
- PUT_SPACE(d, p);
- while (*tmp) { /* the integral */
- PUT_CHAR(*tmp, p);
- tmp++;
- }
- PAD_LEFT(p);
-}
-
-/* for %o octal representation */
-PRIVATE void
-#ifdef __STDC__
-octal(struct DATA *p, double d)
-#else
-octal(p, d)
-struct DATA *p;
-double d;
-#endif
-{
- char *tmp;
-
- tmp = otoa(d);
- p->width -= strlen(tmp);
- PAD_RIGHT(p);
- if (p->square == FOUND) /* had prefix '0' for octal */
- PUT_CHAR('0', p);
- while (*tmp) { /* octal */
- PUT_CHAR(*tmp, p);
- tmp++;
- }
- PAD_LEFT(p);
-}
-
-/* for %x %X hexadecimal representation */
-PRIVATE void
-#ifdef __STDC__
-hexa(struct DATA *p, double d)
-#else
-hexa(p, d)
-struct DATA *p;
-double d;
-#endif
-{
- char *tmp;
-
- tmp = htoa(d);
- p->width -= strlen(tmp);
- PAD_RIGHT(p);
- if (p->square == FOUND) { /* prefix '0x' for hexa */
- PUT_CHAR('0', p); PUT_CHAR(*p->pf, p);
- }
- while (*tmp) { /* hexa */
- PUT_CHAR((*p->pf == 'X' ? toupper(*tmp) : *tmp), p);
- tmp++;
- }
- PAD_LEFT(p);
-}
-
-/* %s strings */
-PRIVATE void
-#ifdef __STDC__
-strings(struct DATA *p, char *tmp)
-#else
-strings(p, tmp)
-struct DATA *p;
-char *tmp;
-#endif
-{
- int i;
-
- i = strlen(tmp);
- if (p->precision != NOT_FOUND) /* the smallest number */
- i = (i < p->precision ? i : p->precision);
- p->width -= i;
- PAD_RIGHT(p);
- while (i-- > 0) { /* put the sting */
- PUT_CHAR(*tmp, p);
- tmp++;
- }
- PAD_LEFT(p);
-}
-
-/* %f or %g floating point representation */
-PRIVATE void
-#ifdef __STDC__
-floating(struct DATA *p, double d)
-#else
-floating(p, d)
-struct DATA *p;
-double d;
-#endif
-{
- char *tmp, *tmp2;
- int i;
-
- DEF_PREC(p);
- d = ROUND(d, p);
- tmp = dtoa(d, p->precision, &tmp2);
- /* calculate the padding. 1 for the dot */
- p->width = p->width -
- ((d > 0. && p->justify == RIGHT) ? 1:0) -
- ((p->space == FOUND) ? 1:0) -
- strlen(tmp) - p->precision - 1;
- PAD_RIGHT(p);
- PUT_PLUS(d, p);
- PUT_SPACE(d, p);
- while (*tmp) { /* the integral */
- PUT_CHAR(*tmp, p);
- tmp++;
- }
- if (p->precision != 0 || p->square == FOUND)
- PUT_CHAR('.', p); /* put the '.' */
- if (*p->pf == 'g' || *p->pf == 'G') /* smash the trailing zeros */
- for (i = strlen(tmp2) - 1; i >= 0 && tmp2[i] == '0'; i--)
- tmp2[i] = '\0';
- for (; *tmp2; tmp2++)
- PUT_CHAR(*tmp2, p); /* the fraction */
-
- PAD_LEFT(p);
-}
-
-/* %e %E %g exponent representation */
-PRIVATE void
-#ifdef __STDC__
-exponent(struct DATA *p, double d)
-#else
-exponent(p, d)
-struct DATA *p;
-double d;
-#endif
-{
- char *tmp, *tmp2;
- int j, i;
-
- DEF_PREC(p);
- j = log_10(d);
- d = d / pow_10(j); /* get the Mantissa */
- d = ROUND(d, p);
- tmp = dtoa(d, p->precision, &tmp2);
- /* 1 for unit, 1 for the '.', 1 for 'e|E',
- * 1 for '+|-', 3 for 'exp' */
- /* calculate how much padding need */
- p->width = p->width -
- ((d > 0. && p->justify == RIGHT) ? 1:0) -