Commit 195dcbcc 195dcbcca00a2c07ea18cf707261246d20c44c42 by Sergey Poznyakoff

Added to the repository by gnulib-sync

1 parent 2db5c711
Showing 89 changed files with 8448 additions and 0 deletions
1 #define __strtol strtoul
2 #define __strtol_t unsigned long int
3 #define __xstrtol xstrtoul
4 #define STRTOL_T_MINIMUM 0
5 #define STRTOL_T_MAXIMUM ULONG_MAX
6 #include "xstrtol.c"
1 # alloca.m4 serial 5
2 dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN([gl_FUNC_ALLOCA],
8 [
9 dnl Work around a bug of AC_EGREP_CPP in autoconf-2.57.
10 AC_REQUIRE([AC_PROG_CPP])
11 AC_REQUIRE([AC_PROG_EGREP])
12
13 AC_REQUIRE([AC_FUNC_ALLOCA])
14 if test $ac_cv_func_alloca_works = no; then
15 gl_PREREQ_ALLOCA
16 fi
17
18 # Define an additional variable used in the Makefile substitution.
19 if test $ac_cv_working_alloca_h = yes; then
20 AC_EGREP_CPP([Need own alloca], [
21 #if defined __GNUC__ || defined _AIX || defined _MSC_VER
22 Need own alloca
23 #endif
24 ],
25 [AC_DEFINE(HAVE_ALLOCA, 1,
26 [Define to 1 if you have `alloca' after including <alloca.h>,
27 a header that may be supplied by this distribution.])
28 ALLOCA_H=alloca.h],
29 [ALLOCA_H=])
30 else
31 ALLOCA_H=alloca.h
32 fi
33 AC_SUBST([ALLOCA_H])
34
35 AC_DEFINE(HAVE_ALLOCA_H, 1,
36 [Define HAVE_ALLOCA_H for backward compatibility with older code
37 that includes <alloca.h> only if HAVE_ALLOCA_H is defined.])
38 ])
39
40 # Prerequisites of lib/alloca.c.
41 # STACK_DIRECTION is already handled by AC_FUNC_ALLOCA.
42 AC_DEFUN([gl_PREREQ_ALLOCA], [:])
1 # allocsa.m4 serial 3
2 dnl Copyright (C) 2003-2004 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN([gl_ALLOCSA],
8 [
9 dnl Use the autoconf tests for alloca(), but not the AC_SUBSTed variables
10 dnl @ALLOCA@ and @LTALLOCA@.
11 AC_REQUIRE([gl_FUNC_ALLOCA])
12 AC_REQUIRE([gl_EEMALLOC])
13 AC_REQUIRE([gl_AC_TYPE_LONG_LONG])
14 AC_REQUIRE([gt_TYPE_LONGDOUBLE])
15 ])
1 # argp.m4 serial 4
2 dnl Copyright (C) 2003, 2004 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN([gl_ARGP],
8 [
9 AC_REQUIRE([AC_C_INLINE])
10 dnl AC_REQUIRE([gl_FUNC_GLIBC_UNLOCKED_IO])
11 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
12 AC_REQUIRE([gl_GETOPT_SUBSTITUTE])
13 AC_CHECK_DECLS([program_invocation_name, program_invocation_short_name],,,
14 [#include <errno.h>])
15 AC_CHECK_FUNCS_ONCE([flockfile funlockfile])
16 AC_CHECK_HEADERS_ONCE([features.h linewrap.h])
17 ])
1 # eealloc.m4 serial 1
2 dnl Copyright (C) 2003 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN([gl_EEALLOC],
8 [
9 AC_REQUIRE([gl_EEMALLOC])
10 AC_REQUIRE([gl_EEREALLOC])
11 AC_REQUIRE([AC_C_INLINE])
12 ])
13
14 AC_DEFUN([gl_EEMALLOC],
15 [
16 _AC_FUNC_MALLOC_IF(
17 [gl_cv_func_malloc_0_nonnull=1],
18 [gl_cv_func_malloc_0_nonnull=0])
19 AC_DEFINE_UNQUOTED([MALLOC_0_IS_NONNULL], $gl_cv_func_malloc_0_nonnull,
20 [If malloc(0) is != NULL, define this to 1. Otherwise define this
21 to 0.])
22 ])
23
24 AC_DEFUN([gl_EEREALLOC],
25 [
26 _AC_FUNC_REALLOC_IF(
27 [gl_cv_func_realloc_0_nonnull=1],
28 [gl_cv_func_realloc_0_nonnull=0])
29 AC_DEFINE_UNQUOTED([REALLOC_0_IS_NONNULL], $gl_cv_func_realloc_0_nonnull,
30 [If realloc(NULL,0) is != NULL, define this to 1. Otherwise define this
31 to 0.])
32 ])
1 # eoverflow.m4 serial 1
2 dnl Copyright (C) 2004 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 dnl From Bruno Haible.
8
9 # The EOVERFLOW errno value ought to be defined in <errno.h>, according to
10 # POSIX. But some systems (like AIX 3) don't define it, and some systems
11 # (like OSF/1) define it when _XOPEN_SOURCE_EXTENDED is defined.
12
13 # Define EOVERFLOW as a C macro and as a substituted macro in such a way that
14 # 1. on all systems, after inclusion of <errno.h>, EOVERFLOW is usable,
15 # 2. on systems where EOVERFLOW is defined elsewhere, we use the same numeric
16 # value.
17
18 AC_DEFUN([gl_EOVERFLOW],
19 [
20 AC_REQUIRE([AC_PROG_CC])dnl
21
22 AC_CACHE_CHECK([for EOVERFLOW], ac_cv_decl_EOVERFLOW, [
23 AC_EGREP_CPP(yes,[
24 #include <errno.h>
25 #ifdef EOVERFLOW
26 yes
27 #endif
28 ], have_eoverflow=1)
29 if test -n "$have_eoverflow"; then
30 dnl EOVERFLOW exists in <errno.h>. Don't need to define EOVERFLOW ourselves.
31 ac_cv_decl_EOVERFLOW=yes
32 else
33 AC_EGREP_CPP(yes,[
34 #define _XOPEN_SOURCE_EXTENDED 1
35 #include <errno.h>
36 #ifdef EOVERFLOW
37 yes
38 #endif
39 ], have_eoverflow=1)
40 if test -n "$have_eoverflow"; then
41 dnl EOVERFLOW exists but is hidden.
42 dnl Define it to the same value.
43 _AC_COMPUTE_INT([EOVERFLOW], ac_cv_decl_EOVERFLOW, [
44 #define _XOPEN_SOURCE_EXTENDED 1
45 #include <errno.h>
46 /* The following two lines are a workaround against an autoconf-2.52 bug. */
47 #include <stdio.h>
48 #include <stdlib.h>
49 ])
50 else
51 dnl EOVERFLOW isn't defined by the system. Define EOVERFLOW ourselves, but
52 dnl don't define it as EINVAL, because snprintf() callers want to
53 dnl distinguish EINVAL and EOVERFLOW.
54 ac_cv_decl_EOVERFLOW=E2BIG
55 fi
56 fi
57 ])
58 if test "$ac_cv_decl_EOVERFLOW" != yes; then
59 AC_DEFINE_UNQUOTED([EOVERFLOW], [$ac_cv_decl_EOVERFLOW],
60 [Define as good substitute value for EOVERFLOW.])
61 EOVERFLOW="$ac_cv_decl_EOVERFLOW"
62 AC_SUBST(EOVERFLOW)
63 fi
64 ])
1 #serial 11
2
3 # Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2004 Free Software
4 # Foundation, Inc.
5 #
6 # This file is free software; the Free Software Foundation
7 # gives unlimited permission to copy and/or distribute it,
8 # with or without modifications, as long as this notice is preserved.
9
10 AC_DEFUN([gl_ERROR],
11 [
12 AC_FUNC_ERROR_AT_LINE
13 dnl Note: AC_FUNC_ERROR_AT_LINE does AC_LIBSOURCES([error.h, error.c]).
14 gl_PREREQ_ERROR
15 ])
16
17 # Prerequisites of lib/error.c.
18 AC_DEFUN([gl_PREREQ_ERROR],
19 [
20 AC_REQUIRE([AC_FUNC_STRERROR_R])
21 :
22 ])
1 # exitfail.m4 serial 4
2 dnl Copyright (C) 2002, 2003 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN([gl_EXITFAIL],
8 [
9 dnl No prerequisites of lib/exitfail.c.
10 :
11 ])
1 # Enable extensions on systems that normally disable them.
2
3 # Copyright (C) 2003 Free Software Foundation, Inc.
4 # This file is free software; the Free Software Foundation
5 # gives unlimited permission to copy and/or distribute it,
6 # with or without modifications, as long as this notice is preserved.
7
8 # gl_USE_SYSTEM_EXTENSIONS
9 # ------------------------
10 # Enable extensions on systems that normally disable them,
11 # typically due to standards-conformance issues.
12 AC_DEFUN([gl_USE_SYSTEM_EXTENSIONS], [
13 AC_BEFORE([$0], [AC_COMPILE_IFELSE])
14 AC_BEFORE([$0], [AC_RUN_IFELSE])
15
16 AC_REQUIRE([AC_GNU_SOURCE])
17 AC_REQUIRE([AC_AIX])
18 AC_REQUIRE([AC_MINIX])
19
20 AH_VERBATIM([__EXTENSIONS__],
21 [/* Enable extensions on Solaris. */
22 #ifndef __EXTENSIONS__
23 # undef __EXTENSIONS__
24 #endif])
25 AC_DEFINE([__EXTENSIONS__])
26 ])
1 # Check for fnmatch.
2
3 # This is a modified version of autoconf's AC_FUNC_FNMATCH.
4 # This file should be simplified after Autoconf 2.57 is required.
5
6 # Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
7 # This file is free software; the Free Software Foundation
8 # gives unlimited permission to copy and/or distribute it,
9 # with or without modifications, as long as this notice is preserved.
10
11 # _AC_FUNC_FNMATCH_IF(STANDARD = GNU | POSIX, CACHE_VAR, IF-TRUE, IF-FALSE)
12 # -------------------------------------------------------------------------
13 # If a STANDARD compliant fnmatch is found, run IF-TRUE, otherwise
14 # IF-FALSE. Use CACHE_VAR.
15 AC_DEFUN([_AC_FUNC_FNMATCH_IF],
16 [AC_CACHE_CHECK(
17 [for working $1 fnmatch],
18 [$2],
19 [dnl Some versions of Solaris, SCO, and the GNU C Library
20 dnl have a broken or incompatible fnmatch.
21 dnl So we run a test program. If we are cross-compiling, take no chance.
22 dnl Thanks to John Oleynick, François Pinard, and Paul Eggert for this test.
23 AC_RUN_IFELSE(
24 [AC_LANG_PROGRAM(
25 [
26 # include <stdlib.h>
27 # include <fnmatch.h>
28 # define y(a, b, c) (fnmatch (a, b, c) == 0)
29 # define n(a, b, c) (fnmatch (a, b, c) == FNM_NOMATCH)
30 ],
31 [exit
32 (!(y ("a*", "abc", 0)
33 && n ("d*/*1", "d/s/1", FNM_PATHNAME)
34 && y ("a\\\\bc", "abc", 0)
35 && n ("a\\\\bc", "abc", FNM_NOESCAPE)
36 && y ("*x", ".x", 0)
37 && n ("*x", ".x", FNM_PERIOD)
38 && m4_if([$1], [GNU],
39 [y ("xxXX", "xXxX", FNM_CASEFOLD)
40 && y ("a++(x|yy)b", "a+xyyyyxb", FNM_EXTMATCH)
41 && n ("d*/*1", "d/s/1", FNM_FILE_NAME)
42 && y ("*", "x", FNM_FILE_NAME | FNM_LEADING_DIR)
43 && y ("x*", "x/y/z", FNM_FILE_NAME | FNM_LEADING_DIR)
44 && y ("*c*", "c/x", FNM_FILE_NAME | FNM_LEADING_DIR)],
45 1)));])],
46 [$2=yes],
47 [$2=no],
48 [$2=cross])])
49 AS_IF([test $$2 = yes], [$3], [$4])
50 ])# _AC_FUNC_FNMATCH_IF
51
52
53 # _AC_LIBOBJ_FNMATCH
54 # ------------------
55 # Prepare the replacement of fnmatch.
56 AC_DEFUN([_AC_LIBOBJ_FNMATCH],
57 [AC_REQUIRE([AC_C_CONST])dnl
58 AC_REQUIRE([AC_FUNC_ALLOCA])dnl
59 AC_REQUIRE([AC_TYPE_MBSTATE_T])dnl
60 AC_CHECK_DECLS([getenv])
61 AC_CHECK_FUNCS([btowc mbsrtowcs mempcpy wmemchr wmemcpy wmempcpy])
62 AC_CHECK_HEADERS([wchar.h wctype.h])
63 AC_LIBOBJ([fnmatch])
64 FNMATCH_H=fnmatch.h
65 ])# _AC_LIBOBJ_FNMATCH
66
67
68 AC_DEFUN([gl_FUNC_FNMATCH_POSIX],
69 [
70 FNMATCH_H=
71 _AC_FUNC_FNMATCH_IF([POSIX], [ac_cv_func_fnmatch_posix],
72 [rm -f lib/fnmatch.h],
73 [_AC_LIBOBJ_FNMATCH])
74 if test $ac_cv_func_fnmatch_posix != yes; then
75 dnl We must choose a different name for our function, since on ELF systems
76 dnl a broken fnmatch() in libc.so would override our fnmatch() if it is
77 dnl compiled into a shared library.
78 AC_DEFINE([fnmatch], [posix_fnmatch],
79 [Define to a replacement function name for fnmatch().])
80 fi
81 AC_SUBST([FNMATCH_H])
82 ])
83
84
85 AC_DEFUN([gl_FUNC_FNMATCH_GNU],
86 [
87 dnl Persuade glibc <fnmatch.h> to declare FNM_CASEFOLD etc.
88 AC_REQUIRE([AC_GNU_SOURCE])
89
90 FNMATCH_H=
91 _AC_FUNC_FNMATCH_IF([GNU], [ac_cv_func_fnmatch_gnu],
92 [rm -f lib/fnmatch.h],
93 [_AC_LIBOBJ_FNMATCH])
94 if test $ac_cv_func_fnmatch_gnu != yes; then
95 dnl We must choose a different name for our function, since on ELF systems
96 dnl a broken fnmatch() in libc.so would override our fnmatch() if it is
97 dnl compiled into a shared library.
98 AC_DEFINE([fnmatch], [gnu_fnmatch],
99 [Define to a replacement function name for fnmatch().])
100 fi
101 AC_SUBST([FNMATCH_H])
102 ])
1 # getline.m4 serial 11
2
3 dnl Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software
4 dnl Foundation, Inc.
5 dnl
6 dnl This file is free software; the Free Software Foundation
7 dnl gives unlimited permission to copy and/or distribute it,
8 dnl with or without modifications, as long as this notice is preserved.
9
10 AC_PREREQ(2.52)
11
12 dnl See if there's a working, system-supplied version of the getline function.
13 dnl We can't just do MU_REPLACE_FUNCS(getline) because some systems
14 dnl have a function by that name in -linet that doesn't have anything
15 dnl to do with the function we need.
16 AC_DEFUN([AM_FUNC_GETLINE],
17 [
18 dnl Persuade glibc <stdio.h> to declare getline() and getdelim().
19 AC_REQUIRE([AC_GNU_SOURCE])
20
21 am_getline_needs_run_time_check=no
22 AC_CHECK_FUNC(getline,
23 dnl Found it in some library. Verify that it works.
24 am_getline_needs_run_time_check=yes,
25 am_cv_func_working_getline=no)
26 if test $am_getline_needs_run_time_check = yes; then
27 AC_CACHE_CHECK([for working getline function], am_cv_func_working_getline,
28 [echo fooN |tr -d '\012'|tr N '\012' > conftest.data
29 AC_TRY_RUN([
30 # include <stdio.h>
31 # include <stdlib.h>
32 # include <string.h>
33 int main ()
34 { /* Based on a test program from Karl Heuer. */
35 char *line = NULL;
36 size_t siz = 0;
37 int len;
38 FILE *in = fopen ("./conftest.data", "r");
39 if (!in)
40 return 1;
41 len = getline (&line, &siz, in);
42 exit ((len == 4 && line && strcmp (line, "foo\n") == 0) ? 0 : 1);
43 }
44 ], am_cv_func_working_getline=yes dnl The library version works.
45 , am_cv_func_working_getline=no dnl The library version does NOT work.
46 , am_cv_func_working_getline=no dnl We're cross compiling.
47 )])
48 fi
49
50 if test $am_cv_func_working_getline = no; then
51 dnl We must choose a different name for our function, since on ELF systems
52 dnl a broken getline() in libc.so would override our getline() in
53 dnl libgettextlib.so.
54 AC_DEFINE([getline], [gnu_getline],
55 [Define to a replacement function name for getline().])
56 MU_LIBOBJ(getline)
57
58 # Avoid multiple inclusions of getndelim2.o into LIBOBJS.
59 # This hack won't be needed after gnulib requires Autoconf 2.58 or later.
60 case " $LIB@&t@OBJS " in
61 *" getndelim2.$ac_objext "* ) ;;
62 *) MU_LIBOBJ(getndelim2);;
63 esac
64
65 gl_PREREQ_GETLINE
66 gl_PREREQ_GETNDELIM2
67 fi
68 ])
69
70 # Prerequisites of lib/getline.c.
71 AC_DEFUN([gl_PREREQ_GETLINE],
72 [
73 AC_CHECK_FUNCS(getdelim)
74 ])
1 # getndelim2.m4 serial 4
2 dnl Copyright (C) 2003 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN([gl_GETNDELIM2],
8 [
9 # Avoid multiple inclusions of getndelim2.o into LIBOBJS.
10 # This hack won't be needed after gnulib requires Autoconf 2.58 or later.
11 case " $LIB@&t@OBJS " in
12 *" getndelim2.$ac_objext "* ) ;;
13 *) MU_LIBOBJ(getndelim2);;
14 esac
15
16 gl_PREREQ_GETNDELIM2
17 ])
18
19 # Prerequisites of lib/getndelim2.h and lib/getndelim2.c.
20 AC_DEFUN([gl_PREREQ_GETNDELIM2],
21 [
22 dnl Prerequisites of lib/getndelim2.h.
23 AC_REQUIRE([gt_TYPE_SSIZE_T])
24 dnl No prerequisites of lib/getndelim2.c.
25 ])
1 # getpass.m4 serial 5
2 dnl Copyright (C) 2002-2003 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 # Provide a getpass() function if the system doesn't have it.
8 AC_DEFUN([gl_FUNC_GETPASS],
9 [
10 AC_REPLACE_FUNCS(getpass)
11 AC_CHECK_DECLS_ONCE(getpass)
12 if test $ac_cv_func_getpass = no; then
13 gl_PREREQ_GETPASS
14 fi
15 ])
16
17 # Provide the GNU getpass() implementation. It supports passwords of
18 # arbitrary length (not just 8 bytes as on HP-UX).
19 AC_DEFUN([gl_FUNC_GETPASS_GNU],
20 [
21 AC_CHECK_DECLS_ONCE(getpass)
22 dnl TODO: Detect when GNU getpass() is already found in glibc.
23 AC_LIBOBJ(getpass)
24 gl_PREREQ_GETPASS
25 dnl We must choose a different name for our function, since on ELF systems
26 dnl an unusable getpass() in libc.so would override our getpass() if it is
27 dnl compiled into a shared library.
28 AC_DEFINE([getpass], [gnu_getpass],
29 [Define to a replacement function name for getpass().])
30 ])
31
32 # Prerequisites of lib/getpass.c.
33 AC_DEFUN([gl_PREREQ_GETPASS], [
34 AC_CHECK_HEADERS_ONCE(stdio_ext.h)
35 AC_CHECK_DECLS_ONCE([fflush_unlocked flockfile fputs_unlocked funlockfile putc_unlocked])
36 :
37 ])
1 # gettext.m4 serial 29
2 dnl Copyright (C) 1995-2003 Free Software Foundation, Inc.
3 dnl This file is free software, distributed under the terms of the GNU
4 dnl General Public License. As a special exception to the GNU General
5 dnl Public License, this file may be distributed as part of a program
6 dnl that contains a configuration script generated by Autoconf, under
7 dnl the same distribution terms as the rest of that program.
8 dnl
9 dnl This file can can be used in projects which are not available under
10 dnl the GNU General Public License or the GNU Library General Public
11 dnl License but which still want to provide support for the GNU gettext
12 dnl functionality.
13 dnl Please note that the actual code of the GNU gettext library is covered
14 dnl by the GNU Library General Public License, and the rest of the GNU
15 dnl gettext package package is covered by the GNU General Public License.
16 dnl They are *not* in the public domain.
17
18 dnl Authors:
19 dnl Ulrich Drepper <drepper@cygnus.com>, 1995-2000.
20 dnl Bruno Haible <haible@clisp.cons.org>, 2000-2003.
21
22 dnl Macro to add for using GNU gettext.
23
24 dnl Usage: AM_GNU_GETTEXT([INTLSYMBOL], [NEEDSYMBOL], [INTLDIR]).
25 dnl INTLSYMBOL can be one of 'external', 'no-libtool', 'use-libtool'. The
26 dnl default (if it is not specified or empty) is 'no-libtool'.
27 dnl INTLSYMBOL should be 'external' for packages with no intl directory,
28 dnl and 'no-libtool' or 'use-libtool' for packages with an intl directory.
29 dnl If INTLSYMBOL is 'use-libtool', then a libtool library
30 dnl $(top_builddir)/intl/libintl.la will be created (shared and/or static,
31 dnl depending on --{enable,disable}-{shared,static} and on the presence of
32 dnl AM-DISABLE-SHARED). If INTLSYMBOL is 'no-libtool', a static library
33 dnl $(top_builddir)/intl/libintl.a will be created.
34 dnl If NEEDSYMBOL is specified and is 'need-ngettext', then GNU gettext
35 dnl implementations (in libc or libintl) without the ngettext() function
36 dnl will be ignored. If NEEDSYMBOL is specified and is
37 dnl 'need-formatstring-macros', then GNU gettext implementations that don't
38 dnl support the ISO C 99 <inttypes.h> formatstring macros will be ignored.
39 dnl INTLDIR is used to find the intl libraries. If empty,
40 dnl the value `$(top_builddir)/intl/' is used.
41 dnl
42 dnl The result of the configuration is one of three cases:
43 dnl 1) GNU gettext, as included in the intl subdirectory, will be compiled
44 dnl and used.
45 dnl Catalog format: GNU --> install in $(datadir)
46 dnl Catalog extension: .mo after installation, .gmo in source tree
47 dnl 2) GNU gettext has been found in the system's C library.
48 dnl Catalog format: GNU --> install in $(datadir)
49 dnl Catalog extension: .mo after installation, .gmo in source tree
50 dnl 3) No internationalization, always use English msgid.
51 dnl Catalog format: none
52 dnl Catalog extension: none
53 dnl If INTLSYMBOL is 'external', only cases 2 and 3 can occur.
54 dnl The use of .gmo is historical (it was needed to avoid overwriting the
55 dnl GNU format catalogs when building on a platform with an X/Open gettext),
56 dnl but we keep it in order not to force irrelevant filename changes on the
57 dnl maintainers.
58 dnl
59 AC_DEFUN([AM_GNU_GETTEXT],
60 [
61 dnl Argument checking.
62 ifelse([$1], [], , [ifelse([$1], [external], , [ifelse([$1], [no-libtool], , [ifelse([$1], [use-libtool], ,
63 [errprint([ERROR: invalid first argument to AM_GNU_GETTEXT
64 ])])])])])
65 ifelse([$2], [], , [ifelse([$2], [need-ngettext], , [ifelse([$2], [need-formatstring-macros], ,
66 [errprint([ERROR: invalid second argument to AM_GNU_GETTEXT
67 ])])])])
68 define(gt_included_intl, ifelse([$1], [external], [no], [yes]))
69 define(gt_libtool_suffix_prefix, ifelse([$1], [use-libtool], [l], []))
70
71 AC_REQUIRE([AM_PO_SUBDIRS])dnl
72 ifelse(gt_included_intl, yes, [
73 AC_REQUIRE([AM_INTL_SUBDIR])dnl
74 ])
75
76 dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
77 AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
78 AC_REQUIRE([AC_LIB_RPATH])
79
80 dnl Sometimes libintl requires libiconv, so first search for libiconv.
81 dnl Ideally we would do this search only after the
82 dnl if test "$USE_NLS" = "yes"; then
83 dnl if test "$gt_cv_func_gnugettext_libc" != "yes"; then
84 dnl tests. But if configure.in invokes AM_ICONV after AM_GNU_GETTEXT
85 dnl the configure script would need to contain the same shell code
86 dnl again, outside any 'if'. There are two solutions:
87 dnl - Invoke AM_ICONV_LINKFLAGS_BODY here, outside any 'if'.
88 dnl - Control the expansions in more detail using AC_PROVIDE_IFELSE.
89 dnl Since AC_PROVIDE_IFELSE is only in autoconf >= 2.52 and not
90 dnl documented, we avoid it.
91 ifelse(gt_included_intl, yes, , [
92 AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY])
93 ])
94
95 dnl Set USE_NLS.
96 AM_NLS
97
98 ifelse(gt_included_intl, yes, [
99 BUILD_INCLUDED_LIBINTL=no
100 USE_INCLUDED_LIBINTL=no
101 ])
102 LIBINTL=
103 LTLIBINTL=
104 POSUB=
105
106 dnl If we use NLS figure out what method
107 if test "$USE_NLS" = "yes"; then
108 gt_use_preinstalled_gnugettext=no
109 ifelse(gt_included_intl, yes, [
110 AC_MSG_CHECKING([whether included gettext is requested])
111 AC_ARG_WITH(included-gettext,
112 [ --with-included-gettext use the GNU gettext library included here],
113 nls_cv_force_use_gnu_gettext=$withval,
114 nls_cv_force_use_gnu_gettext=no)
115 AC_MSG_RESULT($nls_cv_force_use_gnu_gettext)
116
117 nls_cv_use_gnu_gettext="$nls_cv_force_use_gnu_gettext"
118 if test "$nls_cv_force_use_gnu_gettext" != "yes"; then
119 ])
120 dnl User does not insist on using GNU NLS library. Figure out what
121 dnl to use. If GNU gettext is available we use this. Else we have
122 dnl to fall back to GNU NLS library.
123
124 dnl Add a version number to the cache macros.
125 define([gt_api_version], ifelse([$2], [need-formatstring-macros], 3, ifelse([$2], [need-ngettext], 2, 1)))
126 define([gt_cv_func_gnugettext_libc], [gt_cv_func_gnugettext]gt_api_version[_libc])
127 define([gt_cv_func_gnugettext_libintl], [gt_cv_func_gnugettext]gt_api_version[_libintl])
128
129 AC_CACHE_CHECK([for GNU gettext in libc], gt_cv_func_gnugettext_libc,
130 [AC_TRY_LINK([#include <libintl.h>
131 ]ifelse([$2], [need-formatstring-macros],
132 [#ifndef __GNU_GETTEXT_SUPPORTED_REVISION
133 #define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1)
134 #endif
135 changequote(,)dnl
136 typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1];
137 changequote([,])dnl
138 ], [])[extern int _nl_msg_cat_cntr;
139 extern int *_nl_domain_bindings;],
140 [bindtextdomain ("", "");
141 return (int) gettext ("")]ifelse([$2], [need-ngettext], [ + (int) ngettext ("", "", 0)], [])[ + _nl_msg_cat_cntr + *_nl_domain_bindings],
142 gt_cv_func_gnugettext_libc=yes,
143 gt_cv_func_gnugettext_libc=no)])
144
145 if test "$gt_cv_func_gnugettext_libc" != "yes"; then
146 dnl Sometimes libintl requires libiconv, so first search for libiconv.
147 ifelse(gt_included_intl, yes, , [
148 AM_ICONV_LINK
149 ])
150 dnl Search for libintl and define LIBINTL, LTLIBINTL and INCINTL
151 dnl accordingly. Don't use AC_LIB_LINKFLAGS_BODY([intl],[iconv])
152 dnl because that would add "-liconv" to LIBINTL and LTLIBINTL
153 dnl even if libiconv doesn't exist.
154 AC_LIB_LINKFLAGS_BODY([intl])
155 AC_CACHE_CHECK([for GNU gettext in libintl],
156 gt_cv_func_gnugettext_libintl,
157 [gt_save_CPPFLAGS="$CPPFLAGS"
158 CPPFLAGS="$CPPFLAGS $INCINTL"
159 gt_save_LIBS="$LIBS"
160 LIBS="$LIBS $LIBINTL"
161 dnl Now see whether libintl exists and does not depend on libiconv.
162 AC_TRY_LINK([#include <libintl.h>
163 ]ifelse([$2], [need-formatstring-macros],
164 [#ifndef __GNU_GETTEXT_SUPPORTED_REVISION
165 #define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1)
166 #endif
167 changequote(,)dnl
168 typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1];
169 changequote([,])dnl
170 ], [])[extern int _nl_msg_cat_cntr;
171 extern
172 #ifdef __cplusplus
173 "C"
174 #endif
175 const char *_nl_expand_alias ();],
176 [bindtextdomain ("", "");
177 return (int) gettext ("")]ifelse([$2], [need-ngettext], [ + (int) ngettext ("", "", 0)], [])[ + _nl_msg_cat_cntr + *_nl_expand_alias (0)],
178 gt_cv_func_gnugettext_libintl=yes,
179 gt_cv_func_gnugettext_libintl=no)
180 dnl Now see whether libintl exists and depends on libiconv.
181 if test "$gt_cv_func_gnugettext_libintl" != yes && test -n "$LIBICONV"; then
182 LIBS="$LIBS $LIBICONV"
183 AC_TRY_LINK([#include <libintl.h>
184 ]ifelse([$2], [need-formatstring-macros],
185 [#ifndef __GNU_GETTEXT_SUPPORTED_REVISION
186 #define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1)
187 #endif
188 changequote(,)dnl
189 typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1];
190 changequote([,])dnl
191 ], [])[extern int _nl_msg_cat_cntr;
192 extern
193 #ifdef __cplusplus
194 "C"
195 #endif
196 const char *_nl_expand_alias ();],
197 [bindtextdomain ("", "");
198 return (int) gettext ("")]ifelse([$2], [need-ngettext], [ + (int) ngettext ("", "", 0)], [])[ + _nl_msg_cat_cntr + *_nl_expand_alias (0)],
199 [LIBINTL="$LIBINTL $LIBICONV"
200 LTLIBINTL="$LTLIBINTL $LTLIBICONV"
201 gt_cv_func_gnugettext_libintl=yes
202 ])
203 fi
204 CPPFLAGS="$gt_save_CPPFLAGS"
205 LIBS="$gt_save_LIBS"])
206 fi
207
208 dnl If an already present or preinstalled GNU gettext() is found,
209 dnl use it. But if this macro is used in GNU gettext, and GNU
210 dnl gettext is already preinstalled in libintl, we update this
211 dnl libintl. (Cf. the install rule in intl/Makefile.in.)
212 if test "$gt_cv_func_gnugettext_libc" = "yes" \
213 || { test "$gt_cv_func_gnugettext_libintl" = "yes" \
214 && test "$PACKAGE" != gettext-runtime \
215 && test "$PACKAGE" != gettext-tools; }; then
216 gt_use_preinstalled_gnugettext=yes
217 else
218 dnl Reset the values set by searching for libintl.
219 LIBINTL=
220 LTLIBINTL=
221 INCINTL=
222 fi
223
224 ifelse(gt_included_intl, yes, [
225 if test "$gt_use_preinstalled_gnugettext" != "yes"; then
226 dnl GNU gettext is not found in the C library.
227 dnl Fall back on included GNU gettext library.
228 nls_cv_use_gnu_gettext=yes
229 fi
230 fi
231
232 if test "$nls_cv_use_gnu_gettext" = "yes"; then
233 dnl Mark actions used to generate GNU NLS library.
234 BUILD_INCLUDED_LIBINTL=yes
235 USE_INCLUDED_LIBINTL=yes
236 LIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LIBICONV"
237 LTLIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LTLIBICONV"
238 LIBS=`echo " $LIBS " | sed -e 's/ -lintl / /' -e 's/^ //' -e 's/ $//'`
239 fi
240
241 if test "$gt_use_preinstalled_gnugettext" = "yes" \
242 || test "$nls_cv_use_gnu_gettext" = "yes"; then
243 dnl Mark actions to use GNU gettext tools.
244 CATOBJEXT=.gmo
245 fi
246 ])
247
248 if test "$gt_use_preinstalled_gnugettext" = "yes" \
249 || test "$nls_cv_use_gnu_gettext" = "yes"; then
250 AC_DEFINE(ENABLE_NLS, 1,
251 [Define to 1 if translation of program messages to the user's native language
252 is requested.])
253 else
254 USE_NLS=no
255 fi
256 fi
257
258 AC_MSG_CHECKING([whether to use NLS])
259 AC_MSG_RESULT([$USE_NLS])
260 if test "$USE_NLS" = "yes"; then
261 AC_MSG_CHECKING([where the gettext function comes from])
262 if test "$gt_use_preinstalled_gnugettext" = "yes"; then
263 if test "$gt_cv_func_gnugettext_libintl" = "yes"; then
264 gt_source="external libintl"
265 else
266 gt_source="libc"
267 fi
268 else
269 gt_source="included intl directory"
270 fi
271 AC_MSG_RESULT([$gt_source])
272 fi
273
274 if test "$USE_NLS" = "yes"; then
275
276 if test "$gt_use_preinstalled_gnugettext" = "yes"; then
277 if test "$gt_cv_func_gnugettext_libintl" = "yes"; then
278 AC_MSG_CHECKING([how to link with libintl])
279 AC_MSG_RESULT([$LIBINTL])
280 AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCINTL])
281 fi
282
283 dnl For backward compatibility. Some packages may be using this.
284 AC_DEFINE(HAVE_GETTEXT, 1,
285 [Define if the GNU gettext() function is already present or preinstalled.])
286 AC_DEFINE(HAVE_DCGETTEXT, 1,
287 [Define if the GNU dcgettext() function is already present or preinstalled.])
288 fi
289
290 dnl We need to process the po/ directory.
291 POSUB=po
292 fi
293
294 ifelse(gt_included_intl, yes, [
295 dnl If this is used in GNU gettext we have to set BUILD_INCLUDED_LIBINTL
296 dnl to 'yes' because some of the testsuite requires it.
297 if test "$PACKAGE" = gettext-runtime || test "$PACKAGE" = gettext-tools; then
298 BUILD_INCLUDED_LIBINTL=yes
299 fi
300
301 dnl Make all variables we use known to autoconf.
302 AC_SUBST(BUILD_INCLUDED_LIBINTL)
303 AC_SUBST(USE_INCLUDED_LIBINTL)
304 AC_SUBST(CATOBJEXT)
305
306 dnl For backward compatibility. Some configure.ins may be using this.
307 nls_cv_header_intl=
308 nls_cv_header_libgt=
309
310 dnl For backward compatibility. Some Makefiles may be using this.
311 DATADIRNAME=share
312 AC_SUBST(DATADIRNAME)
313
314 dnl For backward compatibility. Some Makefiles may be using this.
315 INSTOBJEXT=.mo
316 AC_SUBST(INSTOBJEXT)
317
318 dnl For backward compatibility. Some Makefiles may be using this.
319 GENCAT=gencat
320 AC_SUBST(GENCAT)
321
322 dnl For backward compatibility. Some Makefiles may be using this.
323 if test "$USE_INCLUDED_LIBINTL" = yes; then
324 INTLOBJS="\$(GETTOBJS)"
325 fi
326 AC_SUBST(INTLOBJS)
327
328 dnl Enable libtool support if the surrounding package wishes it.
329 INTL_LIBTOOL_SUFFIX_PREFIX=gt_libtool_suffix_prefix
330 AC_SUBST(INTL_LIBTOOL_SUFFIX_PREFIX)
331 ])
332
333 dnl For backward compatibility. Some Makefiles may be using this.
334 INTLLIBS="$LIBINTL"
335 AC_SUBST(INTLLIBS)
336
337 dnl Make all documented variables known to autoconf.
338 AC_SUBST(LIBINTL)
339 AC_SUBST(LTLIBINTL)
340 AC_SUBST(POSUB)
341 ])
342
343
344 dnl Checks for all prerequisites of the intl subdirectory,
345 dnl except for INTL_LIBTOOL_SUFFIX_PREFIX (and possibly LIBTOOL), INTLOBJS,
346 dnl USE_INCLUDED_LIBINTL, BUILD_INCLUDED_LIBINTL.
347 AC_DEFUN([AM_INTL_SUBDIR],
348 [
349 AC_REQUIRE([AC_PROG_INSTALL])dnl
350 AC_REQUIRE([AM_MKINSTALLDIRS])dnl
351 AC_REQUIRE([AC_PROG_CC])dnl
352 AC_REQUIRE([AC_CANONICAL_HOST])dnl
353 AC_REQUIRE([AC_PROG_RANLIB])dnl
354 AC_REQUIRE([AC_ISC_POSIX])dnl
355 AC_REQUIRE([AC_HEADER_STDC])dnl
356 AC_REQUIRE([AC_C_CONST])dnl
357 AC_REQUIRE([bh_C_SIGNED])dnl
358 AC_REQUIRE([AC_C_INLINE])dnl
359 AC_REQUIRE([AC_TYPE_OFF_T])dnl
360 AC_REQUIRE([AC_TYPE_SIZE_T])dnl
361 AC_REQUIRE([gl_AC_TYPE_LONG_LONG])dnl
362 AC_REQUIRE([gt_TYPE_LONGDOUBLE])dnl
363 AC_REQUIRE([gt_TYPE_WCHAR_T])dnl
364 AC_REQUIRE([gt_TYPE_WINT_T])dnl
365 AC_REQUIRE([gl_AC_HEADER_INTTYPES_H])
366 AC_REQUIRE([gl_AC_HEADER_STDINT_H])
367 AC_REQUIRE([gt_TYPE_INTMAX_T])
368 AC_REQUIRE([gt_PRINTF_POSIX])
369 AC_REQUIRE([AC_FUNC_ALLOCA])dnl
370 AC_REQUIRE([AC_FUNC_MMAP])dnl
371 AC_REQUIRE([gl_GLIBC21])dnl
372 AC_REQUIRE([gt_INTDIV0])dnl
373 AC_REQUIRE([gl_AC_TYPE_UINTMAX_T])dnl
374 AC_REQUIRE([gt_HEADER_INTTYPES_H])dnl
375 AC_REQUIRE([gt_INTTYPES_PRI])dnl
376 AC_REQUIRE([gl_XSIZE])dnl
377
378 AC_CHECK_TYPE([ptrdiff_t], ,
379 [AC_DEFINE([ptrdiff_t], [long],
380 [Define as the type of the result of subtracting two pointers, if the system doesn't define it.])
381 ])
382 AC_CHECK_HEADERS([argz.h limits.h locale.h nl_types.h malloc.h stddef.h \
383 stdlib.h string.h unistd.h sys/param.h])
384 AC_CHECK_FUNCS([asprintf fwprintf getcwd getegid geteuid getgid getuid \
385 mempcpy munmap putenv setenv setlocale snprintf stpcpy strcasecmp strdup \
386 strtoul tsearch wcslen __argz_count __argz_stringify __argz_next \
387 __fsetlocking])
388
389 dnl Use the _snprintf function only if it is declared (because on NetBSD it
390 dnl is defined as a weak alias of snprintf; we prefer to use the latter).
391 gt_CHECK_DECL(_snprintf, [#include <stdio.h>])
392 gt_CHECK_DECL(_snwprintf, [#include <stdio.h>])
393
394 dnl Use the *_unlocked functions only if they are declared.
395 dnl (because some of them were defined without being declared in Solaris
396 dnl 2.5.1 but were removed in Solaris 2.6, whereas we want binaries built
397 dnl on Solaris 2.5.1 to run on Solaris 2.6).
398 dnl Don't use AC_CHECK_DECLS because it isn't supported in autoconf-2.13.
399 gt_CHECK_DECL(feof_unlocked, [#include <stdio.h>])
400 gt_CHECK_DECL(fgets_unlocked, [#include <stdio.h>])
401 gt_CHECK_DECL(getc_unlocked, [#include <stdio.h>])
402
403 case $gt_cv_func_printf_posix in
404 *yes) HAVE_POSIX_PRINTF=1 ;;
405 *) HAVE_POSIX_PRINTF=0 ;;
406 esac
407 AC_SUBST([HAVE_POSIX_PRINTF])
408 if test "$ac_cv_func_asprintf" = yes; then
409 HAVE_ASPRINTF=1
410 else
411 HAVE_ASPRINTF=0
412 fi
413 AC_SUBST([HAVE_ASPRINTF])
414 if test "$ac_cv_func_snprintf" = yes; then
415 HAVE_SNPRINTF=1
416 else
417 HAVE_SNPRINTF=0
418 fi
419 AC_SUBST([HAVE_SNPRINTF])
420 if test "$ac_cv_func_wprintf" = yes; then
421 HAVE_WPRINTF=1
422 else
423 HAVE_WPRINTF=0
424 fi
425 AC_SUBST([HAVE_WPRINTF])
426
427 AM_ICONV
428 AM_LANGINFO_CODESET
429 if test $ac_cv_header_locale_h = yes; then
430 AM_LC_MESSAGES
431 fi
432
433 dnl intl/plural.c is generated from intl/plural.y. It requires bison,
434 dnl because plural.y uses bison specific features. It requires at least
435 dnl bison-1.26 because earlier versions generate a plural.c that doesn't
436 dnl compile.
437 dnl bison is only needed for the maintainer (who touches plural.y). But in
438 dnl order to avoid separate Makefiles or --enable-maintainer-mode, we put
439 dnl the rule in general Makefile. Now, some people carelessly touch the
440 dnl files or have a broken "make" program, hence the plural.c rule will
441 dnl sometimes fire. To avoid an error, defines BISON to ":" if it is not
442 dnl present or too old.
443 AC_CHECK_PROGS([INTLBISON], [bison])
444 if test -z "$INTLBISON"; then
445 ac_verc_fail=yes
446 else
447 dnl Found it, now check the version.
448 AC_MSG_CHECKING([version of bison])
449 changequote(<<,>>)dnl
450 ac_prog_version=`$INTLBISON --version 2>&1 | sed -n 's/^.*GNU Bison.* \([0-9]*\.[0-9.]*\).*$/\1/p'`
451 case $ac_prog_version in
452 '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;;
453 1.2[6-9]* | 1.[3-9][0-9]* | [2-9].*)
454 changequote([,])dnl
455 ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;;
456 *) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;;
457 esac
458 AC_MSG_RESULT([$ac_prog_version])
459 fi
460 if test $ac_verc_fail = yes; then
461 INTLBISON=:
462 fi
463 ])
464
465
466 dnl gt_CHECK_DECL(FUNC, INCLUDES)
467 dnl Check whether a function is declared.
468 AC_DEFUN([gt_CHECK_DECL],
469 [
470 AC_CACHE_CHECK([whether $1 is declared], ac_cv_have_decl_$1,
471 [AC_TRY_COMPILE([$2], [
472 #ifndef $1
473 char *p = (char *) $1;
474 #endif
475 ], ac_cv_have_decl_$1=yes, ac_cv_have_decl_$1=no)])
476 if test $ac_cv_have_decl_$1 = yes; then
477 gt_value=1
478 else
479 gt_value=0
480 fi
481 AC_DEFINE_UNQUOTED([HAVE_DECL_]translit($1, [a-z], [A-Z]), [$gt_value],
482 [Define to 1 if you have the declaration of `$1', and to 0 if you don't.])
483 ])
484
485
486 dnl Usage: AM_GNU_GETTEXT_VERSION([gettext-version])
487 AC_DEFUN([AM_GNU_GETTEXT_VERSION], [])
1 # glibc21.m4 serial 3
2 dnl Copyright (C) 2000-2002, 2004 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 # Test for the GNU C Library, version 2.1 or newer.
8 # From Bruno Haible.
9
10 AC_DEFUN([gl_GLIBC21],
11 [
12 AC_CACHE_CHECK(whether we are using the GNU C Library 2.1 or newer,
13 ac_cv_gnu_library_2_1,
14 [AC_EGREP_CPP([Lucky GNU user],
15 [
16 #include <features.h>
17 #ifdef __GNU_LIBRARY__
18 #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) || (__GLIBC__ > 2)
19 Lucky GNU user
20 #endif
21 #endif
22 ],
23 ac_cv_gnu_library_2_1=yes,
24 ac_cv_gnu_library_2_1=no)
25 ]
26 )
27 AC_SUBST(GLIBC21)
28 GLIBC21="$ac_cv_gnu_library_2_1"
29 ]
30 )
1 # iconv.m4 serial AM4 (gettext-0.11.3)
2 dnl Copyright (C) 2000-2002 Free Software Foundation, Inc.
3 dnl This file is free software, distributed under the terms of the GNU
4 dnl General Public License. As a special exception to the GNU General
5 dnl Public License, this file may be distributed as part of a program
6 dnl that contains a configuration script generated by Autoconf, under
7 dnl the same distribution terms as the rest of that program.
8
9 dnl From Bruno Haible.
10
11 AC_DEFUN([AM_ICONV_LINKFLAGS_BODY],
12 [
13 dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
14 AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
15 AC_REQUIRE([AC_LIB_RPATH])
16
17 dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV
18 dnl accordingly.
19 AC_LIB_LINKFLAGS_BODY([iconv])
20 ])
21
22 AC_DEFUN([AM_ICONV_LINK],
23 [
24 dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and
25 dnl those with the standalone portable GNU libiconv installed).
26
27 dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV
28 dnl accordingly.
29 AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY])
30
31 dnl Add $INCICONV to CPPFLAGS before performing the following checks,
32 dnl because if the user has installed libiconv and not disabled its use
33 dnl via --without-libiconv-prefix, he wants to use it. The first
34 dnl AC_TRY_LINK will then fail, the second AC_TRY_LINK will succeed.
35 am_save_CPPFLAGS="$CPPFLAGS"
36 AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCICONV])
37
38 AC_CACHE_CHECK(for iconv, am_cv_func_iconv, [
39 am_cv_func_iconv="no, consider installing GNU libiconv"
40 am_cv_lib_iconv=no
41 AC_TRY_LINK([#include <stdlib.h>
42 #include <iconv.h>],
43 [iconv_t cd = iconv_open("","");
44 iconv(cd,NULL,NULL,NULL,NULL);
45 iconv_close(cd);],
46 am_cv_func_iconv=yes)
47 if test "$am_cv_func_iconv" != yes; then
48 am_save_LIBS="$LIBS"
49 LIBS="$LIBS $LIBICONV"
50 AC_TRY_LINK([#include <stdlib.h>
51 #include <iconv.h>],
52 [iconv_t cd = iconv_open("","");
53 iconv(cd,NULL,NULL,NULL,NULL);
54 iconv_close(cd);],
55 am_cv_lib_iconv=yes
56 am_cv_func_iconv=yes)
57 LIBS="$am_save_LIBS"
58 fi
59 ])
60 if test "$am_cv_func_iconv" = yes; then
61 AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.])
62 fi
63 if test "$am_cv_lib_iconv" = yes; then
64 AC_MSG_CHECKING([how to link with libiconv])
65 AC_MSG_RESULT([$LIBICONV])
66 else
67 dnl If $LIBICONV didn't lead to a usable library, we don't need $INCICONV
68 dnl either.
69 CPPFLAGS="$am_save_CPPFLAGS"
70 LIBICONV=
71 LTLIBICONV=
72 fi
73 AC_SUBST(LIBICONV)
74 AC_SUBST(LTLIBICONV)
75 ])
76
77 AC_DEFUN([AM_ICONV],
78 [
79 AM_ICONV_LINK
80 if test "$am_cv_func_iconv" = yes; then
81 AC_MSG_CHECKING([for iconv declaration])
82 AC_CACHE_VAL(am_cv_proto_iconv, [
83 AC_TRY_COMPILE([
84 #include <stdlib.h>
85 #include <iconv.h>
86 extern
87 #ifdef __cplusplus
88 "C"
89 #endif
90 #if defined(__STDC__) || defined(__cplusplus)
91 size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
92 #else
93 size_t iconv();
94 #endif
95 ], [], am_cv_proto_iconv_arg1="", am_cv_proto_iconv_arg1="const")
96 am_cv_proto_iconv="extern size_t iconv (iconv_t cd, $am_cv_proto_iconv_arg1 char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);"])
97 am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'`
98 AC_MSG_RESULT([$]{ac_t:-
99 }[$]am_cv_proto_iconv)
100 AC_DEFINE_UNQUOTED(ICONV_CONST, $am_cv_proto_iconv_arg1,
101 [Define as const if the declaration of iconv() needs const.])
102 fi
103 ])
1 # intmax.m4 serial 1 (gettext-0.12)
2 dnl Copyright (C) 2002-2003 Free Software Foundation, Inc.
3 dnl This file is free software, distributed under the terms of the GNU
4 dnl General Public License. As a special exception to the GNU General
5 dnl Public License, this file may be distributed as part of a program
6 dnl that contains a configuration script generated by Autoconf, under
7 dnl the same distribution terms as the rest of that program.
8
9 dnl From Bruno Haible.
10 dnl Test whether the system has the 'intmax_t' type, but don't attempt to
11 dnl find a replacement if it is lacking.
12
13 AC_DEFUN([gt_TYPE_INTMAX_T],
14 [
15 AC_REQUIRE([jm_AC_HEADER_INTTYPES_H])
16 AC_REQUIRE([jm_AC_HEADER_STDINT_H])
17 AC_CACHE_CHECK(for intmax_t, gt_cv_c_intmax_t,
18 [AC_TRY_COMPILE([
19 #include <stddef.h>
20 #include <stdlib.h>
21 #if HAVE_STDINT_H_WITH_UINTMAX
22 #include <stdint.h>
23 #endif
24 #if HAVE_INTTYPES_H_WITH_UINTMAX
25 #include <inttypes.h>
26 #endif
27 ], [intmax_t x = -1;], gt_cv_c_intmax_t=yes, gt_cv_c_intmax_t=no)])
28 if test $gt_cv_c_intmax_t = yes; then
29 AC_DEFINE(HAVE_INTMAX_T, 1,
30 [Define if you have the 'intmax_t' type in <stdint.h> or <inttypes.h>.])
31 fi
32 ])
1 # intmax_t.m4 serial 4
2 dnl Copyright (C) 1997-2004 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 dnl From Paul Eggert.
8
9 AC_PREREQ(2.13)
10
11 # Define intmax_t to 'long' or 'long long'
12 # if it is not already defined in <stdint.h> or <inttypes.h>.
13
14 AC_DEFUN([gl_AC_TYPE_INTMAX_T],
15 [
16 dnl For simplicity, we assume that a header file defines 'intmax_t' if and
17 dnl only if it defines 'uintmax_t'.
18 AC_REQUIRE([gl_AC_HEADER_INTTYPES_H])
19 AC_REQUIRE([gl_AC_HEADER_STDINT_H])
20 if test $gl_cv_header_inttypes_h = no && test $gl_cv_header_stdint_h = no; then
21 AC_REQUIRE([gl_AC_TYPE_LONG_LONG])
22 test $ac_cv_type_long_long = yes \
23 && ac_type='long long' \
24 || ac_type='long'
25 AC_DEFINE_UNQUOTED(intmax_t, $ac_type,
26 [Define to long or long long if <inttypes.h> and <stdint.h> don't define.])
27 else
28 AC_DEFINE(HAVE_INTMAX_T, 1,
29 [Define if you have the 'intmax_t' type in <stdint.h> or <inttypes.h>.])
30 fi
31 ])
32
33 dnl An alternative would be to explicitly test for 'intmax_t'.
34
35 AC_DEFUN([gt_AC_TYPE_INTMAX_T],
36 [
37 AC_REQUIRE([gl_AC_HEADER_INTTYPES_H])
38 AC_REQUIRE([gl_AC_HEADER_STDINT_H])
39 AC_CACHE_CHECK(for intmax_t, gt_cv_c_intmax_t,
40 [AC_TRY_COMPILE([
41 #include <stddef.h>
42 #include <stdlib.h>
43 #if HAVE_STDINT_H_WITH_UINTMAX
44 #include <stdint.h>
45 #endif
46 #if HAVE_INTTYPES_H_WITH_UINTMAX
47 #include <inttypes.h>
48 #endif
49 ], [intmax_t x = -1;], gt_cv_c_intmax_t=yes, gt_cv_c_intmax_t=no)])
50 if test $gt_cv_c_intmax_t = yes; then
51 AC_DEFINE(HAVE_INTMAX_T, 1,
52 [Define if you have the 'intmax_t' type in <stdint.h> or <inttypes.h>.])
53 else
54 AC_REQUIRE([gl_AC_TYPE_LONG_LONG])
55 test $ac_cv_type_long_long = yes \
56 && ac_type='long long' \
57 || ac_type='long'
58 AC_DEFINE_UNQUOTED(intmax_t, $ac_type,
59 [Define to long or long long if <stdint.h> and <inttypes.h> don't define.])
60 fi
61 ])
1 # inttypes.m4 serial 1 (gettext-0.11.4)
2 dnl Copyright (C) 1997-2002 Free Software Foundation, Inc.
3 dnl This file is free software, distributed under the terms of the GNU
4 dnl General Public License. As a special exception to the GNU General
5 dnl Public License, this file may be distributed as part of a program
6 dnl that contains a configuration script generated by Autoconf, under
7 dnl the same distribution terms as the rest of that program.
8
9 dnl From Paul Eggert.
10
11 # Define HAVE_INTTYPES_H if <inttypes.h> exists and doesn't clash with
12 # <sys/types.h>.
13
14 AC_DEFUN([gt_HEADER_INTTYPES_H],
15 [
16 AC_CACHE_CHECK([for inttypes.h], gt_cv_header_inttypes_h,
17 [
18 AC_TRY_COMPILE(
19 [#include <sys/types.h>
20 #include <inttypes.h>],
21 [], gt_cv_header_inttypes_h=yes, gt_cv_header_inttypes_h=no)
22 ])
23 if test $gt_cv_header_inttypes_h = yes; then
24 AC_DEFINE_UNQUOTED(HAVE_INTTYPES_H, 1,
25 [Define if <inttypes.h> exists and doesn't clash with <sys/types.h>.])
26 fi
27 ])
1 # inttypes_h.m4 serial 6
2 dnl Copyright (C) 1997-2004 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 dnl From Paul Eggert.
8
9 # Define HAVE_INTTYPES_H_WITH_UINTMAX if <inttypes.h> exists,
10 # doesn't clash with <sys/types.h>, and declares uintmax_t.
11
12 AC_DEFUN([gl_AC_HEADER_INTTYPES_H],
13 [
14 AC_CACHE_CHECK([for inttypes.h], gl_cv_header_inttypes_h,
15 [AC_TRY_COMPILE(
16 [#include <sys/types.h>
17 #include <inttypes.h>],
18 [uintmax_t i = (uintmax_t) -1;],
19 gl_cv_header_inttypes_h=yes,
20 gl_cv_header_inttypes_h=no)])
21 if test $gl_cv_header_inttypes_h = yes; then
22 AC_DEFINE_UNQUOTED(HAVE_INTTYPES_H_WITH_UINTMAX, 1,
23 [Define if <inttypes.h> exists, doesn't clash with <sys/types.h>,
24 and declares uintmax_t. ])
25 fi
26 ])
1 # lib-ld.m4 serial 3 (gettext-0.13)
2 dnl Copyright (C) 1996-2003 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 dnl Subroutines of libtool.m4,
8 dnl with replacements s/AC_/AC_LIB/ and s/lt_cv/acl_cv/ to avoid collision
9 dnl with libtool.m4.
10
11 dnl From libtool-1.4. Sets the variable with_gnu_ld to yes or no.
12 AC_DEFUN([AC_LIB_PROG_LD_GNU],
13 [AC_CACHE_CHECK([if the linker ($LD) is GNU ld], acl_cv_prog_gnu_ld,
14 [# I'd rather use --version here, but apparently some GNU ld's only accept -v.
15 case `$LD -v 2>&1 </dev/null` in
16 *GNU* | *'with BFD'*)
17 acl_cv_prog_gnu_ld=yes ;;
18 *)
19 acl_cv_prog_gnu_ld=no ;;
20 esac])
21 with_gnu_ld=$acl_cv_prog_gnu_ld
22 ])
23
24 dnl From libtool-1.4. Sets the variable LD.
25 AC_DEFUN([AC_LIB_PROG_LD],
26 [AC_ARG_WITH(gnu-ld,
27 [ --with-gnu-ld assume the C compiler uses GNU ld [default=no]],
28 test "$withval" = no || with_gnu_ld=yes, with_gnu_ld=no)
29 AC_REQUIRE([AC_PROG_CC])dnl
30 AC_REQUIRE([AC_CANONICAL_HOST])dnl
31 # Prepare PATH_SEPARATOR.
32 # The user is always right.
33 if test "${PATH_SEPARATOR+set}" != set; then
34 echo "#! /bin/sh" >conf$$.sh
35 echo "exit 0" >>conf$$.sh
36 chmod +x conf$$.sh
37 if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then
38 PATH_SEPARATOR=';'
39 else
40 PATH_SEPARATOR=:
41 fi
42 rm -f conf$$.sh
43 fi
44 ac_prog=ld
45 if test "$GCC" = yes; then
46 # Check if gcc -print-prog-name=ld gives a path.
47 AC_MSG_CHECKING([for ld used by GCC])
48 case $host in
49 *-*-mingw*)
50 # gcc leaves a trailing carriage return which upsets mingw
51 ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
52 *)
53 ac_prog=`($CC -print-prog-name=ld) 2>&5` ;;
54 esac
55 case $ac_prog in
56 # Accept absolute paths.
57 [[\\/]* | [A-Za-z]:[\\/]*)]
58 [re_direlt='/[^/][^/]*/\.\./']
59 # Canonicalize the path of ld
60 ac_prog=`echo $ac_prog| sed 's%\\\\%/%g'`
61 while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do
62 ac_prog=`echo $ac_prog| sed "s%$re_direlt%/%"`
63 done
64 test -z "$LD" && LD="$ac_prog"
65 ;;
66 "")
67 # If it fails, then pretend we aren't using GCC.
68 ac_prog=ld
69 ;;
70 *)
71 # If it is relative, then search for the first ld in PATH.
72 with_gnu_ld=unknown
73 ;;
74 esac
75 elif test "$with_gnu_ld" = yes; then
76 AC_MSG_CHECKING([for GNU ld])
77 else
78 AC_MSG_CHECKING([for non-GNU ld])
79 fi
80 AC_CACHE_VAL(acl_cv_path_LD,
81 [if test -z "$LD"; then
82 IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}${PATH_SEPARATOR-:}"
83 for ac_dir in $PATH; do
84 test -z "$ac_dir" && ac_dir=.
85 if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
86 acl_cv_path_LD="$ac_dir/$ac_prog"
87 # Check to see if the program is GNU ld. I'd rather use --version,
88 # but apparently some GNU ld's only accept -v.
89 # Break only if it was the GNU/non-GNU ld that we prefer.
90 case `"$acl_cv_path_LD" -v 2>&1 < /dev/null` in
91 *GNU* | *'with BFD'*)
92 test "$with_gnu_ld" != no && break ;;
93 *)
94 test "$with_gnu_ld" != yes && break ;;
95 esac
96 fi
97 done
98 IFS="$ac_save_ifs"
99 else
100 acl_cv_path_LD="$LD" # Let the user override the test with a path.
101 fi])
102 LD="$acl_cv_path_LD"
103 if test -n "$LD"; then
104 AC_MSG_RESULT($LD)
105 else
106 AC_MSG_RESULT(no)
107 fi
108 test -z "$LD" && AC_MSG_ERROR([no acceptable ld found in \$PATH])
109 AC_LIB_PROG_LD_GNU
110 ])
1 # lib-prefix.m4 serial 3 (gettext-0.13)
2 dnl Copyright (C) 2001-2003 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 dnl From Bruno Haible.
8
9 dnl AC_LIB_ARG_WITH is synonymous to AC_ARG_WITH in autoconf-2.13, and
10 dnl similar to AC_ARG_WITH in autoconf 2.52...2.57 except that is doesn't
11 dnl require excessive bracketing.
12 ifdef([AC_HELP_STRING],
13 [AC_DEFUN([AC_LIB_ARG_WITH], [AC_ARG_WITH([$1],[[$2]],[$3],[$4])])],
14 [AC_DEFUN([AC_][LIB_ARG_WITH], [AC_ARG_WITH([$1],[$2],[$3],[$4])])])
15
16 dnl AC_LIB_PREFIX adds to the CPPFLAGS and LDFLAGS the flags that are needed
17 dnl to access previously installed libraries. The basic assumption is that
18 dnl a user will want packages to use other packages he previously installed
19 dnl with the same --prefix option.
20 dnl This macro is not needed if only AC_LIB_LINKFLAGS is used to locate
21 dnl libraries, but is otherwise very convenient.
22 AC_DEFUN([AC_LIB_PREFIX],
23 [
24 AC_BEFORE([$0], [AC_LIB_LINKFLAGS])
25 AC_REQUIRE([AC_PROG_CC])
26 AC_REQUIRE([AC_CANONICAL_HOST])
27 AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
28 dnl By default, look in $includedir and $libdir.
29 use_additional=yes
30 AC_LIB_WITH_FINAL_PREFIX([
31 eval additional_includedir=\"$includedir\"
32 eval additional_libdir=\"$libdir\"
33 ])
34 AC_LIB_ARG_WITH([lib-prefix],
35 [ --with-lib-prefix[=DIR] search for libraries in DIR/include and DIR/lib
36 --without-lib-prefix don't search for libraries in includedir and libdir],
37 [
38 if test "X$withval" = "Xno"; then
39 use_additional=no
40 else
41 if test "X$withval" = "X"; then
42 AC_LIB_WITH_FINAL_PREFIX([
43 eval additional_includedir=\"$includedir\"
44 eval additional_libdir=\"$libdir\"
45 ])
46 else
47 additional_includedir="$withval/include"
48 additional_libdir="$withval/lib"
49 fi
50 fi
51 ])
52 if test $use_additional = yes; then
53 dnl Potentially add $additional_includedir to $CPPFLAGS.
54 dnl But don't add it
55 dnl 1. if it's the standard /usr/include,
56 dnl 2. if it's already present in $CPPFLAGS,
57 dnl 3. if it's /usr/local/include and we are using GCC on Linux,
58 dnl 4. if it doesn't exist as a directory.
59 if test "X$additional_includedir" != "X/usr/include"; then
60 haveit=
61 for x in $CPPFLAGS; do
62 AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
63 if test "X$x" = "X-I$additional_includedir"; then
64 haveit=yes
65 break
66 fi
67 done
68 if test -z "$haveit"; then
69 if test "X$additional_includedir" = "X/usr/local/include"; then
70 if test -n "$GCC"; then
71 case $host_os in
72 linux*) haveit=yes;;
73 esac
74 fi
75 fi
76 if test -z "$haveit"; then
77 if test -d "$additional_includedir"; then
78 dnl Really add $additional_includedir to $CPPFLAGS.
79 CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }-I$additional_includedir"
80 fi
81 fi
82 fi
83 fi
84 dnl Potentially add $additional_libdir to $LDFLAGS.
85 dnl But don't add it
86 dnl 1. if it's the standard /usr/lib,
87 dnl 2. if it's already present in $LDFLAGS,
88 dnl 3. if it's /usr/local/lib and we are using GCC on Linux,
89 dnl 4. if it doesn't exist as a directory.
90 if test "X$additional_libdir" != "X/usr/lib"; then
91 haveit=
92 for x in $LDFLAGS; do
93 AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
94 if test "X$x" = "X-L$additional_libdir"; then
95 haveit=yes
96 break
97 fi
98 done
99 if test -z "$haveit"; then
100 if test "X$additional_libdir" = "X/usr/local/lib"; then
101 if test -n "$GCC"; then
102 case $host_os in
103 linux*) haveit=yes;;
104 esac
105 fi
106 fi
107 if test -z "$haveit"; then
108 if test -d "$additional_libdir"; then
109 dnl Really add $additional_libdir to $LDFLAGS.
110 LDFLAGS="${LDFLAGS}${LDFLAGS:+ }-L$additional_libdir"
111 fi
112 fi
113 fi
114 fi
115 fi
116 ])
117
118 dnl AC_LIB_PREPARE_PREFIX creates variables acl_final_prefix,
119 dnl acl_final_exec_prefix, containing the values to which $prefix and
120 dnl $exec_prefix will expand at the end of the configure script.
121 AC_DEFUN([AC_LIB_PREPARE_PREFIX],
122 [
123 dnl Unfortunately, prefix and exec_prefix get only finally determined
124 dnl at the end of configure.
125 if test "X$prefix" = "XNONE"; then
126 acl_final_prefix="$ac_default_prefix"
127 else
128 acl_final_prefix="$prefix"
129 fi
130 if test "X$exec_prefix" = "XNONE"; then
131 acl_final_exec_prefix='${prefix}'
132 else
133 acl_final_exec_prefix="$exec_prefix"
134 fi
135 acl_save_prefix="$prefix"
136 prefix="$acl_final_prefix"
137 eval acl_final_exec_prefix=\"$acl_final_exec_prefix\"
138 prefix="$acl_save_prefix"
139 ])
140
141 dnl AC_LIB_WITH_FINAL_PREFIX([statement]) evaluates statement, with the
142 dnl variables prefix and exec_prefix bound to the values they will have
143 dnl at the end of the configure script.
144 AC_DEFUN([AC_LIB_WITH_FINAL_PREFIX],
145 [
146 acl_save_prefix="$prefix"
147 prefix="$acl_final_prefix"
148 acl_save_exec_prefix="$exec_prefix"
149 exec_prefix="$acl_final_exec_prefix"
150 $1
151 exec_prefix="$acl_save_exec_prefix"
152 prefix="$acl_save_prefix"
153 ])
1 # longdouble.m4 serial 1 (gettext-0.12)
2 dnl Copyright (C) 2002-2003 Free Software Foundation, Inc.
3 dnl This file is free software, distributed under the terms of the GNU
4 dnl General Public License. As a special exception to the GNU General
5 dnl Public License, this file may be distributed as part of a program
6 dnl that contains a configuration script generated by Autoconf, under
7 dnl the same distribution terms as the rest of that program.
8
9 dnl From Bruno Haible.
10 dnl Test whether the compiler supports the 'long double' type.
11 dnl Prerequisite: AC_PROG_CC
12
13 AC_DEFUN([gt_TYPE_LONGDOUBLE],
14 [
15 AC_CACHE_CHECK([for long double], gt_cv_c_long_double,
16 [if test "$GCC" = yes; then
17 gt_cv_c_long_double=yes
18 else
19 AC_TRY_COMPILE([
20 /* The Stardent Vistra knows sizeof(long double), but does not support it. */
21 long double foo = 0.0;
22 /* On Ultrix 4.3 cc, long double is 4 and double is 8. */
23 int array [2*(sizeof(long double) >= sizeof(double)) - 1];
24 ], ,
25 gt_cv_c_long_double=yes, gt_cv_c_long_double=no)
26 fi])
27 if test $gt_cv_c_long_double = yes; then
28 AC_DEFINE(HAVE_LONG_DOUBLE, 1, [Define if you have the 'long double' type.])
29 fi
30 ])
1 # longlong.m4 serial 5
2 dnl Copyright (C) 1999-2004 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 dnl From Paul Eggert.
8
9 # Define HAVE_LONG_LONG if 'long long' works.
10
11 AC_DEFUN([gl_AC_TYPE_LONG_LONG],
12 [
13 AC_CACHE_CHECK([for long long], ac_cv_type_long_long,
14 [AC_TRY_LINK([long long ll = 1LL; int i = 63;],
15 [long long llmax = (long long) -1;
16 return ll << i | ll >> i | llmax / ll | llmax % ll;],
17 ac_cv_type_long_long=yes,
18 ac_cv_type_long_long=no)])
19 if test $ac_cv_type_long_long = yes; then
20 AC_DEFINE(HAVE_LONG_LONG, 1,
21 [Define if you have the 'long long' type.])
22 fi
23 ])
1 # lib-link.m4 serial 4 (gettext-0.12)
2 dnl Copyright (C) 2001-2003 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 dnl From Bruno Haible.
8
9 dnl AC_LIB_LINKFLAGS(name [, dependencies]) searches for libname and
10 dnl the libraries corresponding to explicit and implicit dependencies.
11 dnl Sets and AC_SUBSTs the LIB${NAME} and LTLIB${NAME} variables and
12 dnl augments the CPPFLAGS variable.
13 AC_DEFUN([AC_LIB_LINKFLAGS],
14 [
15 AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
16 AC_REQUIRE([AC_LIB_RPATH])
17 define([Name],[translit([$1],[./-], [___])])
18 define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
19 [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
20 AC_CACHE_CHECK([how to link with lib[]$1], [ac_cv_lib[]Name[]_libs], [
21 AC_LIB_LINKFLAGS_BODY([$1], [$2])
22 ac_cv_lib[]Name[]_libs="$LIB[]NAME"
23 ac_cv_lib[]Name[]_ltlibs="$LTLIB[]NAME"
24 ac_cv_lib[]Name[]_cppflags="$INC[]NAME"
25 ])
26 LIB[]NAME="$ac_cv_lib[]Name[]_libs"
27 LTLIB[]NAME="$ac_cv_lib[]Name[]_ltlibs"
28 INC[]NAME="$ac_cv_lib[]Name[]_cppflags"
29 AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME)
30 AC_SUBST([LIB]NAME)
31 AC_SUBST([LTLIB]NAME)
32 dnl Also set HAVE_LIB[]NAME so that AC_LIB_HAVE_LINKFLAGS can reuse the
33 dnl results of this search when this library appears as a dependency.
34 HAVE_LIB[]NAME=yes
35 undefine([Name])
36 undefine([NAME])
37 ])
38
39 dnl AC_LIB_HAVE_LINKFLAGS(name, dependencies, includes, testcode)
40 dnl searches for libname and the libraries corresponding to explicit and
41 dnl implicit dependencies, together with the specified include files and
42 dnl the ability to compile and link the specified testcode. If found, it
43 dnl sets and AC_SUBSTs HAVE_LIB${NAME}=yes and the LIB${NAME} and
44 dnl LTLIB${NAME} variables and augments the CPPFLAGS variable, and
45 dnl #defines HAVE_LIB${NAME} to 1. Otherwise, it sets and AC_SUBSTs
46 dnl HAVE_LIB${NAME}=no and LIB${NAME} and LTLIB${NAME} to empty.
47 AC_DEFUN([AC_LIB_HAVE_LINKFLAGS],
48 [
49 AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
50 AC_REQUIRE([AC_LIB_RPATH])
51 define([Name],[translit([$1],[./-], [___])])
52 define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
53 [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
54
55 dnl Search for lib[]Name and define LIB[]NAME, LTLIB[]NAME and INC[]NAME
56 dnl accordingly.
57 AC_LIB_LINKFLAGS_BODY([$1], [$2])
58
59 dnl Add $INC[]NAME to CPPFLAGS before performing the following checks,
60 dnl because if the user has installed lib[]Name and not disabled its use
61 dnl via --without-lib[]Name-prefix, he wants to use it.
62 ac_save_CPPFLAGS="$CPPFLAGS"
63 AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME)
64
65 AC_CACHE_CHECK([for lib[]$1], [ac_cv_lib[]Name], [
66 ac_save_LIBS="$LIBS"
67 LIBS="$LIBS $LIB[]NAME"
68 AC_TRY_LINK([$3], [$4], [ac_cv_lib[]Name=yes], [ac_cv_lib[]Name=no])
69 LIBS="$ac_save_LIBS"
70 ])
71 if test "$ac_cv_lib[]Name" = yes; then
72 HAVE_LIB[]NAME=yes
73 AC_DEFINE([HAVE_LIB]NAME, 1, [Define if you have the $1 library.])
74 AC_MSG_CHECKING([how to link with lib[]$1])
75 AC_MSG_RESULT([$LIB[]NAME])
76 else
77 HAVE_LIB[]NAME=no
78 dnl If $LIB[]NAME didn't lead to a usable library, we don't need
79 dnl $INC[]NAME either.
80 CPPFLAGS="$ac_save_CPPFLAGS"
81 LIB[]NAME=
82 LTLIB[]NAME=
83 fi
84 AC_SUBST([HAVE_LIB]NAME)
85 AC_SUBST([LIB]NAME)
86 AC_SUBST([LTLIB]NAME)
87 undefine([Name])
88 undefine([NAME])
89 ])
90
91 dnl Determine the platform dependent parameters needed to use rpath:
92 dnl libext, shlibext, hardcode_libdir_flag_spec, hardcode_libdir_separator,
93 dnl hardcode_direct, hardcode_minus_L.
94 AC_DEFUN([AC_LIB_RPATH],
95 [
96 AC_REQUIRE([AC_PROG_CC]) dnl we use $CC, $GCC, $LDFLAGS
97 AC_REQUIRE([AC_LIB_PROG_LD]) dnl we use $LD, $with_gnu_ld
98 AC_REQUIRE([AC_CANONICAL_HOST]) dnl we use $host
99 AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT]) dnl we use $ac_aux_dir
100 AC_CACHE_CHECK([for shared library run path origin], acl_cv_rpath, [
101 CC="$CC" GCC="$GCC" LDFLAGS="$LDFLAGS" LD="$LD" with_gnu_ld="$with_gnu_ld" \
102 ${CONFIG_SHELL-/bin/sh} "$ac_aux_dir/config.rpath" "$host" > conftest.sh
103 . ./conftest.sh
104 rm -f ./conftest.sh
105 acl_cv_rpath=done
106 ])
107 wl="$acl_cv_wl"
108 libext="$acl_cv_libext"
109 shlibext="$acl_cv_shlibext"
110 hardcode_libdir_flag_spec="$acl_cv_hardcode_libdir_flag_spec"
111 hardcode_libdir_separator="$acl_cv_hardcode_libdir_separator"
112 hardcode_direct="$acl_cv_hardcode_direct"
113 hardcode_minus_L="$acl_cv_hardcode_minus_L"
114 dnl Determine whether the user wants rpath handling at all.
115 AC_ARG_ENABLE(rpath,
116 [ --disable-rpath do not hardcode runtime library paths],
117 :, enable_rpath=yes)
118 ])
119
120 dnl AC_LIB_LINKFLAGS_BODY(name [, dependencies]) searches for libname and
121 dnl the libraries corresponding to explicit and implicit dependencies.
122 dnl Sets the LIB${NAME}, LTLIB${NAME} and INC${NAME} variables.
123 AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
124 [
125 define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
126 [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
127 dnl By default, look in $includedir and $libdir.
128 use_additional=yes
129 AC_LIB_WITH_FINAL_PREFIX([
130 eval additional_includedir=\"$includedir\"
131 eval additional_libdir=\"$libdir\"
132 ])
133 AC_LIB_ARG_WITH([lib$1-prefix],
134 [ --with-lib$1-prefix[=DIR] search for lib$1 in DIR/include and DIR/lib
135 --without-lib$1-prefix don't search for lib$1 in includedir and libdir],
136 [
137 if test "X$withval" = "Xno"; then
138 use_additional=no
139 else
140 if test "X$withval" = "X"; then
141 AC_LIB_WITH_FINAL_PREFIX([
142 eval additional_includedir=\"$includedir\"
143 eval additional_libdir=\"$libdir\"
144 ])
145 else
146 additional_includedir="$withval/include"
147 additional_libdir="$withval/lib"
148 fi
149 fi
150 ])
151 dnl Search the library and its dependencies in $additional_libdir and
152 dnl $LDFLAGS. Using breadth-first-seach.
153 LIB[]NAME=
154 LTLIB[]NAME=
155 INC[]NAME=
156 rpathdirs=
157 ltrpathdirs=
158 names_already_handled=
159 names_next_round='$1 $2'
160 while test -n "$names_next_round"; do
161 names_this_round="$names_next_round"
162 names_next_round=
163 for name in $names_this_round; do
164 already_handled=
165 for n in $names_already_handled; do
166 if test "$n" = "$name"; then
167 already_handled=yes
168 break
169 fi
170 done
171 if test -z "$already_handled"; then
172 names_already_handled="$names_already_handled $name"
173 dnl See if it was already located by an earlier AC_LIB_LINKFLAGS
174 dnl or AC_LIB_HAVE_LINKFLAGS call.
175 uppername=`echo "$name" | sed -e 'y|abcdefghijklmnopqrstuvwxyz./-|ABCDEFGHIJKLMNOPQRSTUVWXYZ___|'`
176 eval value=\"\$HAVE_LIB$uppername\"
177 if test -n "$value"; then
178 if test "$value" = yes; then
179 eval value=\"\$LIB$uppername\"
180 test -z "$value" || LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$value"
181 eval value=\"\$LTLIB$uppername\"
182 test -z "$value" || LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$value"
183 else
184 dnl An earlier call to AC_LIB_HAVE_LINKFLAGS has determined
185 dnl that this library doesn't exist. So just drop it.
186 :
187 fi
188 else
189 dnl Search the library lib$name in $additional_libdir and $LDFLAGS
190 dnl and the already constructed $LIBNAME/$LTLIBNAME.
191 found_dir=
192 found_la=
193 found_so=
194 found_a=
195 if test $use_additional = yes; then
196 if test -n "$shlibext" && test -f "$additional_libdir/lib$name.$shlibext"; then
197 found_dir="$additional_libdir"
198 found_so="$additional_libdir/lib$name.$shlibext"
199 if test -f "$additional_libdir/lib$name.la"; then
200 found_la="$additional_libdir/lib$name.la"
201 fi
202 else
203 if test -f "$additional_libdir/lib$name.$libext"; then
204 found_dir="$additional_libdir"
205 found_a="$additional_libdir/lib$name.$libext"
206 if test -f "$additional_libdir/lib$name.la"; then
207 found_la="$additional_libdir/lib$name.la"
208 fi
209 fi
210 fi
211 fi
212 if test "X$found_dir" = "X"; then
213 for x in $LDFLAGS $LTLIB[]NAME; do
214 AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
215 case "$x" in
216 -L*)
217 dir=`echo "X$x" | sed -e 's/^X-L//'`
218 if test -n "$shlibext" && test -f "$dir/lib$name.$shlibext"; then
219 found_dir="$dir"
220 found_so="$dir/lib$name.$shlibext"
221 if test -f "$dir/lib$name.la"; then
222 found_la="$dir/lib$name.la"
223 fi
224 else
225 if test -f "$dir/lib$name.$libext"; then
226 found_dir="$dir"
227 found_a="$dir/lib$name.$libext"
228 if test -f "$dir/lib$name.la"; then
229 found_la="$dir/lib$name.la"
230 fi
231 fi
232 fi
233 ;;
234 esac
235 if test "X$found_dir" != "X"; then
236 break
237 fi
238 done
239 fi
240 if test "X$found_dir" != "X"; then
241 dnl Found the library.
242 LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$found_dir -l$name"
243 if test "X$found_so" != "X"; then
244 dnl Linking with a shared library. We attempt to hardcode its
245 dnl directory into the executable's runpath, unless it's the
246 dnl standard /usr/lib.
247 if test "$enable_rpath" = no || test "X$found_dir" = "X/usr/lib"; then
248 dnl No hardcoding is needed.
249 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
250 else
251 dnl Use an explicit option to hardcode DIR into the resulting
252 dnl binary.
253 dnl Potentially add DIR to ltrpathdirs.
254 dnl The ltrpathdirs will be appended to $LTLIBNAME at the end.
255 haveit=
256 for x in $ltrpathdirs; do
257 if test "X$x" = "X$found_dir"; then
258 haveit=yes
259 break
260 fi
261 done
262 if test -z "$haveit"; then
263 ltrpathdirs="$ltrpathdirs $found_dir"
264 fi
265 dnl The hardcoding into $LIBNAME is system dependent.
266 if test "$hardcode_direct" = yes; then
267 dnl Using DIR/libNAME.so during linking hardcodes DIR into the
268 dnl resulting binary.
269 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
270 else
271 if test -n "$hardcode_libdir_flag_spec" && test "$hardcode_minus_L" = no; then
272 dnl Use an explicit option to hardcode DIR into the resulting
273 dnl binary.
274 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
275 dnl Potentially add DIR to rpathdirs.
276 dnl The rpathdirs will be appended to $LIBNAME at the end.
277 haveit=
278 for x in $rpathdirs; do
279 if test "X$x" = "X$found_dir"; then
280 haveit=yes
281 break
282 fi
283 done
284 if test -z "$haveit"; then
285 rpathdirs="$rpathdirs $found_dir"
286 fi
287 else
288 dnl Rely on "-L$found_dir".
289 dnl But don't add it if it's already contained in the LDFLAGS
290 dnl or the already constructed $LIBNAME
291 haveit=
292 for x in $LDFLAGS $LIB[]NAME; do
293 AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
294 if test "X$x" = "X-L$found_dir"; then
295 haveit=yes
296 break
297 fi
298 done
299 if test -z "$haveit"; then
300 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir"
301 fi
302 if test "$hardcode_minus_L" != no; then
303 dnl FIXME: Not sure whether we should use
304 dnl "-L$found_dir -l$name" or "-L$found_dir $found_so"
305 dnl here.
306 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
307 else
308 dnl We cannot use $hardcode_runpath_var and LD_RUN_PATH
309 dnl here, because this doesn't fit in flags passed to the
310 dnl compiler. So give up. No hardcoding. This affects only
311 dnl very old systems.
312 dnl FIXME: Not sure whether we should use
313 dnl "-L$found_dir -l$name" or "-L$found_dir $found_so"
314 dnl here.
315 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name"
316 fi
317 fi
318 fi
319 fi
320 else
321 if test "X$found_a" != "X"; then
322 dnl Linking with a static library.
323 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_a"
324 else
325 dnl We shouldn't come here, but anyway it's good to have a
326 dnl fallback.
327 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir -l$name"
328 fi
329 fi
330 dnl Assume the include files are nearby.
331 additional_includedir=
332 case "$found_dir" in
333 */lib | */lib/)
334 basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e 's,/lib/*$,,'`
335 additional_includedir="$basedir/include"
336 ;;
337 esac
338 if test "X$additional_includedir" != "X"; then
339 dnl Potentially add $additional_includedir to $INCNAME.
340 dnl But don't add it
341 dnl 1. if it's the standard /usr/include,
342 dnl 2. if it's /usr/local/include and we are using GCC on Linux,
343 dnl 3. if it's already present in $CPPFLAGS or the already
344 dnl constructed $INCNAME,
345 dnl 4. if it doesn't exist as a directory.
346 if test "X$additional_includedir" != "X/usr/include"; then
347 haveit=
348 if test "X$additional_includedir" = "X/usr/local/include"; then
349 if test -n "$GCC"; then
350 case $host_os in
351 linux*) haveit=yes;;
352 esac
353 fi
354 fi
355 if test -z "$haveit"; then
356 for x in $CPPFLAGS $INC[]NAME; do
357 AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
358 if test "X$x" = "X-I$additional_includedir"; then
359 haveit=yes
360 break
361 fi
362 done
363 if test -z "$haveit"; then
364 if test -d "$additional_includedir"; then
365 dnl Really add $additional_includedir to $INCNAME.
366 INC[]NAME="${INC[]NAME}${INC[]NAME:+ }-I$additional_includedir"
367 fi
368 fi
369 fi
370 fi
371 fi
372 dnl Look for dependencies.
373 if test -n "$found_la"; then
374 dnl Read the .la file. It defines the variables
375 dnl dlname, library_names, old_library, dependency_libs, current,
376 dnl age, revision, installed, dlopen, dlpreopen, libdir.
377 save_libdir="$libdir"
378 case "$found_la" in
379 */* | *\\*) . "$found_la" ;;
380 *) . "./$found_la" ;;
381 esac
382 libdir="$save_libdir"
383 dnl We use only dependency_libs.
384 for dep in $dependency_libs; do
385 case "$dep" in
386 -L*)
387 additional_libdir=`echo "X$dep" | sed -e 's/^X-L//'`
388 dnl Potentially add $additional_libdir to $LIBNAME and $LTLIBNAME.
389 dnl But don't add it
390 dnl 1. if it's the standard /usr/lib,
391 dnl 2. if it's /usr/local/lib and we are using GCC on Linux,
392 dnl 3. if it's already present in $LDFLAGS or the already
393 dnl constructed $LIBNAME,
394 dnl 4. if it doesn't exist as a directory.
395 if test "X$additional_libdir" != "X/usr/lib"; then
396 haveit=
397 if test "X$additional_libdir" = "X/usr/local/lib"; then
398 if test -n "$GCC"; then
399 case $host_os in
400 linux*) haveit=yes;;
401 esac
402 fi
403 fi
404 if test -z "$haveit"; then
405 haveit=
406 for x in $LDFLAGS $LIB[]NAME; do
407 AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
408 if test "X$x" = "X-L$additional_libdir"; then
409 haveit=yes
410 break
411 fi
412 done
413 if test -z "$haveit"; then
414 if test -d "$additional_libdir"; then
415 dnl Really add $additional_libdir to $LIBNAME.
416 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$additional_libdir"
417 fi
418 fi
419 haveit=
420 for x in $LDFLAGS $LTLIB[]NAME; do
421 AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
422 if test "X$x" = "X-L$additional_libdir"; then
423 haveit=yes
424 break
425 fi
426 done
427 if test -z "$haveit"; then
428 if test -d "$additional_libdir"; then
429 dnl Really add $additional_libdir to $LTLIBNAME.
430 LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$additional_libdir"
431 fi
432 fi
433 fi
434 fi
435 ;;
436 -R*)
437 dir=`echo "X$dep" | sed -e 's/^X-R//'`
438 if test "$enable_rpath" != no; then
439 dnl Potentially add DIR to rpathdirs.
440 dnl The rpathdirs will be appended to $LIBNAME at the end.
441 haveit=
442 for x in $rpathdirs; do
443 if test "X$x" = "X$dir"; then
444 haveit=yes
445 break
446 fi
447 done
448 if test -z "$haveit"; then
449 rpathdirs="$rpathdirs $dir"
450 fi
451 dnl Potentially add DIR to ltrpathdirs.
452 dnl The ltrpathdirs will be appended to $LTLIBNAME at the end.
453 haveit=
454 for x in $ltrpathdirs; do
455 if test "X$x" = "X$dir"; then
456 haveit=yes
457 break
458 fi
459 done
460 if test -z "$haveit"; then
461 ltrpathdirs="$ltrpathdirs $dir"
462 fi
463 fi
464 ;;
465 -l*)
466 dnl Handle this in the next round.
467 names_next_round="$names_next_round "`echo "X$dep" | sed -e 's/^X-l//'`
468 ;;
469 *.la)
470 dnl Handle this in the next round. Throw away the .la's
471 dnl directory; it is already contained in a preceding -L
472 dnl option.
473 names_next_round="$names_next_round "`echo "X$dep" | sed -e 's,^X.*/,,' -e 's,^lib,,' -e 's,\.la$,,'`
474 ;;
475 *)
476 dnl Most likely an immediate library name.
477 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$dep"
478 LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$dep"
479 ;;
480 esac
481 done
482 fi
483 else
484 dnl Didn't find the library; assume it is in the system directories
485 dnl known to the linker and runtime loader. (All the system
486 dnl directories known to the linker should also be known to the
487 dnl runtime loader, otherwise the system is severely misconfigured.)
488 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name"
489 LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-l$name"
490 fi
491 fi
492 fi
493 done
494 done
495 if test "X$rpathdirs" != "X"; then
496 if test -n "$hardcode_libdir_separator"; then
497 dnl Weird platform: only the last -rpath option counts, the user must
498 dnl pass all path elements in one option. We can arrange that for a
499 dnl single library, but not when more than one $LIBNAMEs are used.
500 alldirs=
501 for found_dir in $rpathdirs; do
502 alldirs="${alldirs}${alldirs:+$hardcode_libdir_separator}$found_dir"
503 done
504 dnl Note: hardcode_libdir_flag_spec uses $libdir and $wl.
505 acl_save_libdir="$libdir"
506 libdir="$alldirs"
507 eval flag=\"$hardcode_libdir_flag_spec\"
508 libdir="$acl_save_libdir"
509 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag"
510 else
511 dnl The -rpath options are cumulative.
512 for found_dir in $rpathdirs; do
513 acl_save_libdir="$libdir"
514 libdir="$found_dir"
515 eval flag=\"$hardcode_libdir_flag_spec\"
516 libdir="$acl_save_libdir"
517 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag"
518 done
519 fi
520 fi
521 if test "X$ltrpathdirs" != "X"; then
522 dnl When using libtool, the option that works for both libraries and
523 dnl executables is -R. The -R options are cumulative.
524 for found_dir in $ltrpathdirs; do
525 LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-R$found_dir"
526 done
527 fi
528 ])
529
530 dnl AC_LIB_APPENDTOVAR(VAR, CONTENTS) appends the elements of CONTENTS to VAR,
531 dnl unless already present in VAR.
532 dnl Works only for CPPFLAGS, not for LIB* variables because that sometimes
533 dnl contains two or three consecutive elements that belong together.
534 AC_DEFUN([AC_LIB_APPENDTOVAR],
535 [
536 for element in [$2]; do
537 haveit=
538 for x in $[$1]; do
539 AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
540 if test "X$x" = "X$element"; then
541 haveit=yes
542 break
543 fi
544 done
545 if test -z "$haveit"; then
546 [$1]="${[$1]}${[$1]:+ }$element"
547 fi
548 done
549 ])
1 # mbstate_t.m4 serial 9
2 dnl Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 # From Paul Eggert.
8
9 # BeOS 5 has <wchar.h> but does not define mbstate_t,
10 # so you can't declare an object of that type.
11 # Check for this incompatibility with Standard C.
12
13 # AC_TYPE_MBSTATE_T
14 # -----------------
15 AC_DEFUN([AC_TYPE_MBSTATE_T],
16 [AC_CACHE_CHECK([for mbstate_t], ac_cv_type_mbstate_t,
17 [AC_COMPILE_IFELSE(
18 [AC_LANG_PROGRAM(
19 [AC_INCLUDES_DEFAULT
20 # include <wchar.h>],
21 [mbstate_t x; return sizeof x;])],
22 [ac_cv_type_mbstate_t=yes],
23 [ac_cv_type_mbstate_t=no])])
24 if test $ac_cv_type_mbstate_t = yes; then
25 AC_DEFINE([HAVE_MBSTATE_T], 1,
26 [Define to 1 if <wchar.h> declares mbstate_t.])
27 else
28 AC_DEFINE([mbstate_t], int,
29 [Define to a type if <wchar.h> does not define.])
30 fi])
1 # md5.m4 serial 6
2 dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN([gl_MD5],
8 [
9 dnl Prerequisites of lib/md5.h.
10 AC_REQUIRE([gl_AC_TYPE_UINT32_T])
11
12 dnl Prerequisites of lib/md5.c.
13 AC_REQUIRE([AC_C_BIGENDIAN])
14 :
15 ])
1 # mempcpy.m4 serial 3
2 dnl Copyright (C) 2003, 2004 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN([gl_FUNC_MEMPCPY],
8 [
9 MU_LIBSOURCES([mempcpy.c, mempcpy.h])
10
11 dnl Persuade glibc <string.h> to declare mempcpy().
12 AC_REQUIRE([AC_GNU_SOURCE])
13
14 MU_REPLACE_FUNCS(mempcpy)
15 if test $ac_cv_func_mempcpy = no; then
16 gl_PREREQ_MEMPCPY
17 fi
18 ])
19
20 # Prerequisites of lib/mempcpy.c.
21 AC_DEFUN([gl_PREREQ_MEMPCPY], [
22 :
23 ])
1 # nls.m4 serial 1 (gettext-0.12)
2 dnl Copyright (C) 1995-2003 Free Software Foundation, Inc.
3 dnl This file is free software, distributed under the terms of the GNU
4 dnl General Public License. As a special exception to the GNU General
5 dnl Public License, this file may be distributed as part of a program
6 dnl that contains a configuration script generated by Autoconf, under
7 dnl the same distribution terms as the rest of that program.
8 dnl
9 dnl This file can can be used in projects which are not available under
10 dnl the GNU General Public License or the GNU Library General Public
11 dnl License but which still want to provide support for the GNU gettext
12 dnl functionality.
13 dnl Please note that the actual code of the GNU gettext library is covered
14 dnl by the GNU Library General Public License, and the rest of the GNU
15 dnl gettext package package is covered by the GNU General Public License.
16 dnl They are *not* in the public domain.
17
18 dnl Authors:
19 dnl Ulrich Drepper <drepper@cygnus.com>, 1995-2000.
20 dnl Bruno Haible <haible@clisp.cons.org>, 2000-2003.
21
22 AC_DEFUN([AM_NLS],
23 [
24 AC_MSG_CHECKING([whether NLS is requested])
25 dnl Default is enabled NLS
26 AC_ARG_ENABLE(nls,
27 [ --disable-nls do not use Native Language Support],
28 USE_NLS=$enableval, USE_NLS=yes)
29 AC_MSG_RESULT($USE_NLS)
30 AC_SUBST(USE_NLS)
31 ])
32
33 AC_DEFUN([AM_MKINSTALLDIRS],
34 [
35 dnl If the AC_CONFIG_AUX_DIR macro for autoconf is used we possibly
36 dnl find the mkinstalldirs script in another subdir but $(top_srcdir).
37 dnl Try to locate it.
38 MKINSTALLDIRS=
39 if test -n "$ac_aux_dir"; then
40 case "$ac_aux_dir" in
41 /*) MKINSTALLDIRS="$ac_aux_dir/mkinstalldirs" ;;
42 *) MKINSTALLDIRS="\$(top_builddir)/$ac_aux_dir/mkinstalldirs" ;;
43 esac
44 fi
45 if test -z "$MKINSTALLDIRS"; then
46 MKINSTALLDIRS="\$(top_srcdir)/mkinstalldirs"
47 fi
48 AC_SUBST(MKINSTALLDIRS)
49 ])
1 # obstack.m4 serial 4
2 dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN([gl_OBSTACK],
8 [
9 AC_FUNC_OBSTACK
10 dnl Note: AC_FUNC_OBSTACK does AC_LIBSOURCES([obstack.h, obstack.c]).
11 if test $ac_cv_func_obstack = no; then
12 gl_PREREQ_OBSTACK
13 fi
14 ])
15
16 # Prerequisites of lib/obstack.c.
17 AC_DEFUN([gl_PREREQ_OBSTACK],
18 [
19 AC_REQUIRE([gl_AC_HEADER_INTTYPES_H])
20 AC_REQUIRE([gl_AC_HEADER_STDINT_H])
21 AC_REQUIRE([gl_AC_TYPE_UINTMAX_T])
22 :
23 ])
1 # onceonly_2_57.m4 serial 3
2 dnl Copyright (C) 2002-2003 Free Software Foundation, Inc.
3 dnl This file is free software, distributed under the terms of the GNU
4 dnl General Public License. As a special exception to the GNU General
5 dnl Public License, this file may be distributed as part of a program
6 dnl that contains a configuration script generated by Autoconf, under
7 dnl the same distribution terms as the rest of that program.
8
9 dnl This file defines some "once only" variants of standard autoconf macros.
10 dnl AC_CHECK_HEADERS_ONCE like AC_CHECK_HEADERS
11 dnl AC_CHECK_FUNCS_ONCE like AC_CHECK_FUNCS
12 dnl AC_CHECK_DECLS_ONCE like AC_CHECK_DECLS
13 dnl AC_REQUIRE([AC_HEADER_STDC]) like AC_HEADER_STDC
14 dnl The advantage is that the check for each of the headers/functions/decls
15 dnl will be put only once into the 'configure' file. It keeps the size of
16 dnl the 'configure' file down, and avoids redundant output when 'configure'
17 dnl is run.
18 dnl The drawback is that the checks cannot be conditionalized. If you write
19 dnl if some_condition; then gl_CHECK_HEADERS(stdlib.h); fi
20 dnl inside an AC_DEFUNed function, the gl_CHECK_HEADERS macro call expands to
21 dnl empty, and the check will be inserted before the body of the AC_DEFUNed
22 dnl function.
23
24 dnl This is like onceonly.m4, except that it uses diversions to named sections
25 dnl DEFAULTS and INIT_PREPARE in order to check all requested headers at once,
26 dnl thus reducing the size of 'configure'. Works with autoconf-2.57. The
27 dnl size reduction is ca. 9%.
28
29 dnl Autoconf version 2.57 or newer is recommended.
30 AC_PREREQ(2.54)
31
32 # AC_CHECK_HEADERS_ONCE(HEADER1 HEADER2 ...) is a once-only variant of
33 # AC_CHECK_HEADERS(HEADER1 HEADER2 ...).
34 AC_DEFUN([AC_CHECK_HEADERS_ONCE], [
35 :
36 AC_FOREACH([gl_HEADER_NAME], [$1], [
37 AC_DEFUN([gl_CHECK_HEADER_]m4_quote(translit(gl_HEADER_NAME,
38 [./-], [___])), [
39 m4_divert_text([INIT_PREPARE],
40 [gl_header_list="$gl_header_list gl_HEADER_NAME"])
41 gl_HEADERS_EXPANSION
42 AH_TEMPLATE(AS_TR_CPP([HAVE_]m4_defn([gl_HEADER_NAME])),
43 [Define to 1 if you have the <]m4_defn([gl_HEADER_NAME])[> header file.])
44 ])
45 AC_REQUIRE([gl_CHECK_HEADER_]m4_quote(translit(gl_HEADER_NAME,
46 [./-], [___])))
47 ])
48 ])
49 m4_define([gl_HEADERS_EXPANSION], [
50 m4_divert_text([DEFAULTS], [gl_header_list=])
51 AC_CHECK_HEADERS([$gl_header_list])
52 m4_define([gl_HEADERS_EXPANSION], [])
53 ])
54
55 # AC_CHECK_FUNCS_ONCE(FUNC1 FUNC2 ...) is a once-only variant of
56 # AC_CHECK_FUNCS(FUNC1 FUNC2 ...).
57 AC_DEFUN([AC_CHECK_FUNCS_ONCE], [
58 :
59 AC_FOREACH([gl_FUNC_NAME], [$1], [
60 AC_DEFUN([gl_CHECK_FUNC_]m4_defn([gl_FUNC_NAME]), [
61 m4_divert_text([INIT_PREPARE],
62 [gl_func_list="$gl_func_list gl_FUNC_NAME"])
63 gl_FUNCS_EXPANSION
64 AH_TEMPLATE(AS_TR_CPP([HAVE_]m4_defn([gl_FUNC_NAME])),
65 [Define to 1 if you have the `]m4_defn([gl_FUNC_NAME])[' function.])
66 ])
67 AC_REQUIRE([gl_CHECK_FUNC_]m4_defn([gl_FUNC_NAME]))
68 ])
69 ])
70 m4_define([gl_FUNCS_EXPANSION], [
71 m4_divert_text([DEFAULTS], [gl_func_list=])
72 AC_CHECK_FUNCS([$gl_func_list])
73 m4_define([gl_FUNCS_EXPANSION], [])
74 ])
75
76 # AC_CHECK_DECLS_ONCE(DECL1 DECL2 ...) is a once-only variant of
77 # AC_CHECK_DECLS(DECL1, DECL2, ...).
78 AC_DEFUN([AC_CHECK_DECLS_ONCE], [
79 :
80 AC_FOREACH([gl_DECL_NAME], [$1], [
81 AC_DEFUN([gl_CHECK_DECL_]m4_defn([gl_DECL_NAME]), [
82 AC_CHECK_DECLS(m4_defn([gl_DECL_NAME]))
83 ])
84 AC_REQUIRE([gl_CHECK_DECL_]m4_defn([gl_DECL_NAME]))
85 ])
86 ])
1 # po.m4 serial 3 (gettext-0.14)
2 dnl Copyright (C) 1995-2003 Free Software Foundation, Inc.
3 dnl This file is free software, distributed under the terms of the GNU
4 dnl General Public License. As a special exception to the GNU General
5 dnl Public License, this file may be distributed as part of a program
6 dnl that contains a configuration script generated by Autoconf, under
7 dnl the same distribution terms as the rest of that program.
8 dnl
9 dnl This file can can be used in projects which are not available under
10 dnl the GNU General Public License or the GNU Library General Public
11 dnl License but which still want to provide support for the GNU gettext
12 dnl functionality.
13 dnl Please note that the actual code of the GNU gettext library is covered
14 dnl by the GNU Library General Public License, and the rest of the GNU
15 dnl gettext package package is covered by the GNU General Public License.
16 dnl They are *not* in the public domain.
17
18 dnl Authors:
19 dnl Ulrich Drepper <drepper@cygnus.com>, 1995-2000.
20 dnl Bruno Haible <haible@clisp.cons.org>, 2000-2003.
21
22 dnl Checks for all prerequisites of the po subdirectory.
23 AC_DEFUN([AM_PO_SUBDIRS],
24 [
25 AC_REQUIRE([AC_PROG_MAKE_SET])dnl
26 AC_REQUIRE([AC_PROG_INSTALL])dnl
27 AC_REQUIRE([AM_MKINSTALLDIRS])dnl
28 AC_REQUIRE([AM_NLS])dnl
29
30 dnl Perform the following tests also if --disable-nls has been given,
31 dnl because they are needed for "make dist" to work.
32
33 dnl Search for GNU msgfmt in the PATH.
34 dnl The first test excludes Solaris msgfmt and early GNU msgfmt versions.
35 dnl The second test excludes FreeBSD msgfmt.
36 AM_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
37 [$ac_dir/$ac_word --statistics /dev/null >/dev/null 2>&1 &&
38 (if $ac_dir/$ac_word --statistics /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi)],
39 :)
40 AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
41
42 dnl Search for GNU xgettext 0.12 or newer in the PATH.
43 dnl The first test excludes Solaris xgettext and early GNU xgettext versions.
44 dnl The second test excludes FreeBSD xgettext.
45 AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
46 [$ac_dir/$ac_word --omit-header --copyright-holder= --msgid-bugs-address= /dev/null >/dev/null 2>&1 &&
47 (if $ac_dir/$ac_word --omit-header --copyright-holder= --msgid-bugs-address= /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi)],
48 :)
49 dnl Remove leftover from FreeBSD xgettext call.
50 rm -f messages.po
51
52 dnl Search for GNU msgmerge 0.11 or newer in the PATH.
53 AM_PATH_PROG_WITH_TEST(MSGMERGE, msgmerge,
54 [$ac_dir/$ac_word --update -q /dev/null /dev/null >/dev/null 2>&1], :)
55
56 dnl This could go away some day; the PATH_PROG_WITH_TEST already does it.
57 dnl Test whether we really found GNU msgfmt.
58 if test "$GMSGFMT" != ":"; then
59 dnl If it is no GNU msgfmt we define it as : so that the
60 dnl Makefiles still can work.
61 if $GMSGFMT --statistics /dev/null >/dev/null 2>&1 &&
62 (if $GMSGFMT --statistics /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi); then
63 : ;
64 else
65 GMSGFMT=`echo "$GMSGFMT" | sed -e 's,^.*/,,'`
66 AC_MSG_RESULT(
67 [found $GMSGFMT program is not GNU msgfmt; ignore it])
68 GMSGFMT=":"
69 fi
70 fi
71
72 dnl This could go away some day; the PATH_PROG_WITH_TEST already does it.
73 dnl Test whether we really found GNU xgettext.
74 if test "$XGETTEXT" != ":"; then
75 dnl If it is no GNU xgettext we define it as : so that the
76 dnl Makefiles still can work.
77 if $XGETTEXT --omit-header --copyright-holder= --msgid-bugs-address= /dev/null >/dev/null 2>&1 &&
78 (if $XGETTEXT --omit-header --copyright-holder= --msgid-bugs-address= /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi); then
79 : ;
80 else
81 AC_MSG_RESULT(
82 [found xgettext program is not GNU xgettext; ignore it])
83 XGETTEXT=":"
84 fi
85 dnl Remove leftover from FreeBSD xgettext call.
86 rm -f messages.po
87 fi
88
89 AC_OUTPUT_COMMANDS([
90 for ac_file in $CONFIG_FILES; do
91 # Support "outfile[:infile[:infile...]]"
92 case "$ac_file" in
93 *:*) ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;;
94 esac
95 # PO directories have a Makefile.in generated from Makefile.in.in.
96 case "$ac_file" in */Makefile.in)
97 # Adjust a relative srcdir.
98 ac_dir=`echo "$ac_file"|sed 's%/[^/][^/]*$%%'`
99 ac_dir_suffix="/`echo "$ac_dir"|sed 's%^\./%%'`"
100 ac_dots=`echo "$ac_dir_suffix"|sed 's%/[^/]*%../%g'`
101 # In autoconf-2.13 it is called $ac_given_srcdir.
102 # In autoconf-2.50 it is called $srcdir.
103 test -n "$ac_given_srcdir" || ac_given_srcdir="$srcdir"
104 case "$ac_given_srcdir" in
105 .) top_srcdir=`echo $ac_dots|sed 's%/$%%'` ;;
106 /*) top_srcdir="$ac_given_srcdir" ;;
107 *) top_srcdir="$ac_dots$ac_given_srcdir" ;;
108 esac
109 if test -f "$ac_given_srcdir/$ac_dir/POTFILES.in"; then
110 rm -f "$ac_dir/POTFILES"
111 test -n "$as_me" && echo "$as_me: creating $ac_dir/POTFILES" || echo "creating $ac_dir/POTFILES"
112 cat "$ac_given_srcdir/$ac_dir/POTFILES.in" | sed -e "/^#/d" -e "/^[ ]*\$/d" -e "s,.*, $top_srcdir/& \\\\," | sed -e "\$s/\(.*\) \\\\/\1/" > "$ac_dir/POTFILES"
113 POMAKEFILEDEPS="POTFILES.in"
114 # ALL_LINGUAS, POFILES, UPDATEPOFILES, DUMMYPOFILES, GMOFILES depend
115 # on $ac_dir but don't depend on user-specified configuration
116 # parameters.
117 if test -f "$ac_given_srcdir/$ac_dir/LINGUAS"; then
118 # The LINGUAS file contains the set of available languages.
119 if test -n "$OBSOLETE_ALL_LINGUAS"; then
120 test -n "$as_me" && echo "$as_me: setting ALL_LINGUAS in configure.in is obsolete" || echo "setting ALL_LINGUAS in configure.in is obsolete"
121 fi
122 ALL_LINGUAS_=`sed -e "/^#/d" "$ac_given_srcdir/$ac_dir/LINGUAS"`
123 # Hide the ALL_LINGUAS assigment from automake.
124 eval 'ALL_LINGUAS''=$ALL_LINGUAS_'
125 POMAKEFILEDEPS="$POMAKEFILEDEPS LINGUAS"
126 else
127 # The set of available languages was given in configure.in.
128 eval 'ALL_LINGUAS''=$OBSOLETE_ALL_LINGUAS'
129 fi
130 # Compute POFILES
131 # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).po)
132 # Compute UPDATEPOFILES
133 # as $(foreach lang, $(ALL_LINGUAS), $(lang).po-update)
134 # Compute DUMMYPOFILES
135 # as $(foreach lang, $(ALL_LINGUAS), $(lang).nop)
136 # Compute GMOFILES
137 # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).gmo)
138 case "$ac_given_srcdir" in
139 .) srcdirpre= ;;
140 *) srcdirpre='$(srcdir)/' ;;
141 esac
142 POFILES=
143 UPDATEPOFILES=
144 DUMMYPOFILES=
145 GMOFILES=
146 for lang in $ALL_LINGUAS; do
147 POFILES="$POFILES $srcdirpre$lang.po"
148 UPDATEPOFILES="$UPDATEPOFILES $lang.po-update"
149 DUMMYPOFILES="$DUMMYPOFILES $lang.nop"
150 GMOFILES="$GMOFILES $srcdirpre$lang.gmo"
151 done
152 # CATALOGS depends on both $ac_dir and the user's LINGUAS
153 # environment variable.
154 INST_LINGUAS=
155 if test -n "$ALL_LINGUAS"; then
156 for presentlang in $ALL_LINGUAS; do
157 useit=no
158 if test "%UNSET%" != "$LINGUAS"; then
159 desiredlanguages="$LINGUAS"
160 else
161 desiredlanguages="$ALL_LINGUAS"
162 fi
163 for desiredlang in $desiredlanguages; do
164 # Use the presentlang catalog if desiredlang is
165 # a. equal to presentlang, or
166 # b. a variant of presentlang (because in this case,
167 # presentlang can be used as a fallback for messages
168 # which are not translated in the desiredlang catalog).
169 case "$desiredlang" in
170 "$presentlang"*) useit=yes;;
171 esac
172 done
173 if test $useit = yes; then
174 INST_LINGUAS="$INST_LINGUAS $presentlang"
175 fi
176 done
177 fi
178 CATALOGS=
179 if test -n "$INST_LINGUAS"; then
180 for lang in $INST_LINGUAS; do
181 CATALOGS="$CATALOGS $lang.gmo"
182 done
183 fi
184 test -n "$as_me" && echo "$as_me: creating $ac_dir/Makefile" || echo "creating $ac_dir/Makefile"
185 sed -e "/^POTFILES =/r $ac_dir/POTFILES" -e "/^# Makevars/r $ac_given_srcdir/$ac_dir/Makevars" -e "s|@POFILES@|$POFILES|g" -e "s|@UPDATEPOFILES@|$UPDATEPOFILES|g" -e "s|@DUMMYPOFILES@|$DUMMYPOFILES|g" -e "s|@GMOFILES@|$GMOFILES|g" -e "s|@CATALOGS@|$CATALOGS|g" -e "s|@POMAKEFILEDEPS@|$POMAKEFILEDEPS|g" "$ac_dir/Makefile.in" > "$ac_dir/Makefile"
186 for f in "$ac_given_srcdir/$ac_dir"/Rules-*; do
187 if test -f "$f"; then
188 case "$f" in
189 *.orig | *.bak | *~) ;;
190 *) cat "$f" >> "$ac_dir/Makefile" ;;
191 esac
192 fi
193 done
194 fi
195 ;;
196 esac
197 done],
198 [# Capture the value of obsolete ALL_LINGUAS because we need it to compute
199 # POFILES, UPDATEPOFILES, DUMMYPOFILES, GMOFILES, CATALOGS. But hide it
200 # from automake.
201 eval 'OBSOLETE_ALL_LINGUAS''="$ALL_LINGUAS"'
202 # Capture the value of LINGUAS because we need it to compute CATALOGS.
203 LINGUAS="${LINGUAS-%UNSET%}"
204 ])
205 ])
206
207 dnl Postprocesses a Makefile in a directory containing PO files.
208 AC_DEFUN([AM_POSTPROCESS_PO_MAKEFILE],
209 [
210 # When this code is run, in config.status, two variables have already been
211 # set:
212 # - OBSOLETE_ALL_LINGUAS is the value of LINGUAS set in configure.in,
213 # - LINGUAS is the value of the environment variable LINGUAS at configure
214 # time.
215
216 changequote(,)dnl
217 # Adjust a relative srcdir.
218 ac_dir=`echo "$ac_file"|sed 's%/[^/][^/]*$%%'`
219 ac_dir_suffix="/`echo "$ac_dir"|sed 's%^\./%%'`"
220 ac_dots=`echo "$ac_dir_suffix"|sed 's%/[^/]*%../%g'`
221 # In autoconf-2.13 it is called $ac_given_srcdir.
222 # In autoconf-2.50 it is called $srcdir.
223 test -n "$ac_given_srcdir" || ac_given_srcdir="$srcdir"
224 case "$ac_given_srcdir" in
225 .) top_srcdir=`echo $ac_dots|sed 's%/$%%'` ;;
226 /*) top_srcdir="$ac_given_srcdir" ;;
227 *) top_srcdir="$ac_dots$ac_given_srcdir" ;;
228 esac
229
230 # Find a way to echo strings without interpreting backslash.
231 if test "X`(echo '\t') 2>/dev/null`" = 'X\t'; then
232 gt_echo='echo'
233 else
234 if test "X`(printf '%s\n' '\t') 2>/dev/null`" = 'X\t'; then
235 gt_echo='printf %s\n'
236 else
237 echo_func () {
238 cat <<EOT
239 $*
240 EOT
241 }
242 gt_echo='echo_func'
243 fi
244 fi
245
246 # A sed script that extracts the value of VARIABLE from a Makefile.
247 sed_x_variable='
248 # Test if the hold space is empty.
249 x
250 s/P/P/
251 x
252 ta
253 # Yes it was empty. Look if we have the expected variable definition.
254 /^[ ]*VARIABLE[ ]*=/{
255 # Seen the first line of the variable definition.
256 s/^[ ]*VARIABLE[ ]*=//
257 ba
258 }
259 bd
260 :a
261 # Here we are processing a line from the variable definition.
262 # Remove comment, more precisely replace it with a space.
263 s/#.*$/ /
264 # See if the line ends in a backslash.
265 tb
266 :b
267 s/\\$//
268 # Print the line, without the trailing backslash.
269 p
270 tc
271 # There was no trailing backslash. The end of the variable definition is
272 # reached. Clear the hold space.
273 s/^.*$//
274 x
275 bd
276 :c
277 # A trailing backslash means that the variable definition continues in the
278 # next line. Put a nonempty string into the hold space to indicate this.
279 s/^.*$/P/
280 x
281 :d
282 '
283 changequote([,])dnl
284
285 # Set POTFILES to the value of the Makefile variable POTFILES.
286 sed_x_POTFILES="`$gt_echo \"$sed_x_variable\" | sed -e '/^ *#/d' -e 's/VARIABLE/POTFILES/g'`"
287 POTFILES=`sed -n -e "$sed_x_POTFILES" < "$ac_file"`
288 # Compute POTFILES_DEPS as
289 # $(foreach file, $(POTFILES), $(top_srcdir)/$(file))
290 POTFILES_DEPS=
291 for file in $POTFILES; do
292 POTFILES_DEPS="$POTFILES_DEPS "'$(top_srcdir)/'"$file"
293 done
294 POMAKEFILEDEPS=""
295
296 if test -n "$OBSOLETE_ALL_LINGUAS"; then
297 test -n "$as_me" && echo "$as_me: setting ALL_LINGUAS in configure.in is obsolete" || echo "setting ALL_LINGUAS in configure.in is obsolete"
298 fi
299 if test -f "$ac_given_srcdir/$ac_dir/LINGUAS"; then
300 # The LINGUAS file contains the set of available languages.
301 ALL_LINGUAS_=`sed -e "/^#/d" "$ac_given_srcdir/$ac_dir/LINGUAS"`
302 POMAKEFILEDEPS="$POMAKEFILEDEPS LINGUAS"
303 else
304 # Set ALL_LINGUAS to the value of the Makefile variable LINGUAS.
305 sed_x_LINGUAS="`$gt_echo \"$sed_x_variable\" | sed -e '/^ *#/d' -e 's/VARIABLE/LINGUAS/g'`"
306 ALL_LINGUAS_=`sed -n -e "$sed_x_LINGUAS" < "$ac_file"`
307 fi
308 # Hide the ALL_LINGUAS assigment from automake.
309 eval 'ALL_LINGUAS''=$ALL_LINGUAS_'
310 # Compute POFILES
311 # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).po)
312 # Compute UPDATEPOFILES
313 # as $(foreach lang, $(ALL_LINGUAS), $(lang).po-update)
314 # Compute DUMMYPOFILES
315 # as $(foreach lang, $(ALL_LINGUAS), $(lang).nop)
316 # Compute GMOFILES
317 # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).gmo)
318 # Compute PROPERTIESFILES
319 # as $(foreach lang, $(ALL_LINGUAS), $(top_srcdir)/$(DOMAIN)_$(lang).properties)
320 # Compute CLASSFILES
321 # as $(foreach lang, $(ALL_LINGUAS), $(top_srcdir)/$(DOMAIN)_$(lang).class)
322 # Compute QMFILES
323 # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).qm)
324 # Compute MSGFILES
325 # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(frob $(lang)).msg)
326 # Compute RESOURCESDLLFILES
327 # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(frob $(lang))/$(DOMAIN).resources.dll)
328 case "$ac_given_srcdir" in
329 .) srcdirpre= ;;
330 *) srcdirpre='$(srcdir)/' ;;
331 esac
332 POFILES=
333 UPDATEPOFILES=
334 DUMMYPOFILES=
335 GMOFILES=
336 PROPERTIESFILES=
337 CLASSFILES=
338 QMFILES=
339 MSGFILES=
340 RESOURCESDLLFILES=
341 for lang in $ALL_LINGUAS; do
342 POFILES="$POFILES $srcdirpre$lang.po"
343 UPDATEPOFILES="$UPDATEPOFILES $lang.po-update"
344 DUMMYPOFILES="$DUMMYPOFILES $lang.nop"
345 GMOFILES="$GMOFILES $srcdirpre$lang.gmo"
346 PROPERTIESFILES="$PROPERTIESFILES \$(top_srcdir)/\$(DOMAIN)_$lang.properties"
347 CLASSFILES="$CLASSFILES \$(top_srcdir)/\$(DOMAIN)_$lang.class"
348 QMFILES="$QMFILES $srcdirpre$lang.qm"
349 frobbedlang=`echo $lang | sed -e 's/\..*$//' -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
350 MSGFILES="$MSGFILES $srcdirpre$frobbedlang.msg"
351 frobbedlang=`echo $lang | sed -e 's/_/-/g'`
352 RESOURCESDLLFILES="$RESOURCESDLLFILES $srcdirpre$frobbedlang/\$(DOMAIN).resources.dll"
353 done
354 # CATALOGS depends on both $ac_dir and the user's LINGUAS
355 # environment variable.
356 INST_LINGUAS=
357 if test -n "$ALL_LINGUAS"; then
358 for presentlang in $ALL_LINGUAS; do
359 useit=no
360 if test "%UNSET%" != "$LINGUAS"; then
361 desiredlanguages="$LINGUAS"
362 else
363 desiredlanguages="$ALL_LINGUAS"
364 fi
365 for desiredlang in $desiredlanguages; do
366 # Use the presentlang catalog if desiredlang is
367 # a. equal to presentlang, or
368 # b. a variant of presentlang (because in this case,
369 # presentlang can be used as a fallback for messages
370 # which are not translated in the desiredlang catalog).
371 case "$desiredlang" in
372 "$presentlang"*) useit=yes;;
373 esac
374 done
375 if test $useit = yes; then
376 INST_LINGUAS="$INST_LINGUAS $presentlang"
377 fi
378 done
379 fi
380 CATALOGS=
381 JAVACATALOGS=
382 QTCATALOGS=
383 TCLCATALOGS=
384 CSHARPCATALOGS=
385 if test -n "$INST_LINGUAS"; then
386 for lang in $INST_LINGUAS; do
387 CATALOGS="$CATALOGS $lang.gmo"
388 JAVACATALOGS="$JAVACATALOGS \$(DOMAIN)_$lang.properties"
389 QTCATALOGS="$QTCATALOGS $lang.qm"
390 frobbedlang=`echo $lang | sed -e 's/\..*$//' -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
391 TCLCATALOGS="$TCLCATALOGS $frobbedlang.msg"
392 frobbedlang=`echo $lang | sed -e 's/_/-/g'`
393 CSHARPCATALOGS="$CSHARPCATALOGS $frobbedlang/\$(DOMAIN).resources.dll"
394 done
395 fi
396
397 sed -e "s|@POTFILES_DEPS@|$POTFILES_DEPS|g" -e "s|@POFILES@|$POFILES|g" -e "s|@UPDATEPOFILES@|$UPDATEPOFILES|g" -e "s|@DUMMYPOFILES@|$DUMMYPOFILES|g" -e "s|@GMOFILES@|$GMOFILES|g" -e "s|@PROPERTIESFILES@|$PROPERTIESFILES|g" -e "s|@CLASSFILES@|$CLASSFILES|g" -e "s|@QMFILES@|$QMFILES|g" -e "s|@MSGFILES@|$MSGFILES|g" -e "s|@RESOURCESDLLFILES@|$RESOURCESDLLFILES|g" -e "s|@CATALOGS@|$CATALOGS|g" -e "s|@JAVACATALOGS@|$JAVACATALOGS|g" -e "s|@QTCATALOGS@|$QTCATALOGS|g" -e "s|@TCLCATALOGS@|$TCLCATALOGS|g" -e "s|@CSHARPCATALOGS@|$CSHARPCATALOGS|g" -e 's,^#distdir:,distdir:,' < "$ac_file" > "$ac_file.tmp"
398 if grep -l '@TCLCATALOGS@' "$ac_file" > /dev/null; then
399 # Add dependencies that cannot be formulated as a simple suffix rule.
400 for lang in $ALL_LINGUAS; do
401 frobbedlang=`echo $lang | sed -e 's/\..*$//' -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
402 cat >> "$ac_file.tmp" <<EOF
403 $frobbedlang.msg: $lang.po
404 @echo "\$(MSGFMT) -c --tcl -d \$(srcdir) -l $lang $srcdirpre$lang.po"; \
405 \$(MSGFMT) -c --tcl -d "\$(srcdir)" -l $lang $srcdirpre$lang.po || { rm -f "\$(srcdir)/$frobbedlang.msg"; exit 1; }
406 EOF
407 done
408 fi
409 if grep -l '@CSHARPCATALOGS@' "$ac_file" > /dev/null; then
410 # Add dependencies that cannot be formulated as a simple suffix rule.
411 for lang in $ALL_LINGUAS; do
412 frobbedlang=`echo $lang | sed -e 's/_/-/g'`
413 cat >> "$ac_file.tmp" <<EOF
414 $frobbedlang/\$(DOMAIN).resources.dll: $lang.po
415 @echo "\$(MSGFMT) -c --csharp -d \$(srcdir) -l $lang $srcdirpre$lang.po -r \$(DOMAIN)"; \
416 \$(MSGFMT) -c --csharp -d "\$(srcdir)" -l $lang $srcdirpre$lang.po -r "\$(DOMAIN)" || { rm -f "\$(srcdir)/$frobbedlang.msg"; exit 1; }
417 EOF
418 done
419 fi
420 if test -n "$POMAKEFILEDEPS"; then
421 cat >> "$ac_file.tmp" <<EOF
422 Makefile: $POMAKEFILEDEPS
423 EOF
424 fi
425 mv "$ac_file.tmp" "$ac_file"
426 ])
1 # printf-posix.m4 serial 2 (gettext-0.13.1)
2 dnl Copyright (C) 2003 Free Software Foundation, Inc.
3 dnl This file is free software, distributed under the terms of the GNU
4 dnl General Public License. As a special exception to the GNU General
5 dnl Public License, this file may be distributed as part of a program
6 dnl that contains a configuration script generated by Autoconf, under
7 dnl the same distribution terms as the rest of that program.
8
9 dnl From Bruno Haible.
10 dnl Test whether the printf() function supports POSIX/XSI format strings with
11 dnl positions.
12
13 AC_DEFUN([gt_PRINTF_POSIX],
14 [
15 AC_REQUIRE([AC_PROG_CC])
16 AC_CACHE_CHECK([whether printf() supports POSIX/XSI format strings],
17 gt_cv_func_printf_posix,
18 [
19 AC_TRY_RUN([
20 #include <stdio.h>
21 #include <string.h>
22 /* The string "%2$d %1$d", with dollar characters protected from the shell's
23 dollar expansion (possibly an autoconf bug). */
24 static char format[] = { '%', '2', '$', 'd', ' ', '%', '1', '$', 'd', '\0' };
25 static char buf[100];
26 int main ()
27 {
28 sprintf (buf, format, 33, 55);
29 return (strcmp (buf, "55 33") != 0);
30 }], gt_cv_func_printf_posix=yes, gt_cv_func_printf_posix=no,
31 [
32 AC_EGREP_CPP(notposix, [
33 #if defined __NetBSD__ || defined _MSC_VER || defined __MINGW32__ || defined __CYGWIN__
34 notposix
35 #endif
36 ], gt_cv_func_printf_posix="guessing no",
37 gt_cv_func_printf_posix="guessing yes")
38 ])
39 ])
40 case $gt_cv_func_printf_posix in
41 *yes)
42 AC_DEFINE(HAVE_POSIX_PRINTF, 1,
43 [Define if your printf() function supports format strings with positions.])
44 ;;
45 esac
46 ])
1 # progtest.m4 serial 3 (gettext-0.12)
2 dnl Copyright (C) 1996-2003 Free Software Foundation, Inc.
3 dnl This file is free software, distributed under the terms of the GNU
4 dnl General Public License. As a special exception to the GNU General
5 dnl Public License, this file may be distributed as part of a program
6 dnl that contains a configuration script generated by Autoconf, under
7 dnl the same distribution terms as the rest of that program.
8 dnl
9 dnl This file can can be used in projects which are not available under
10 dnl the GNU General Public License or the GNU Library General Public
11 dnl License but which still want to provide support for the GNU gettext
12 dnl functionality.
13 dnl Please note that the actual code of the GNU gettext library is covered
14 dnl by the GNU Library General Public License, and the rest of the GNU
15 dnl gettext package package is covered by the GNU General Public License.
16 dnl They are *not* in the public domain.
17
18 dnl Authors:
19 dnl Ulrich Drepper <drepper@cygnus.com>, 1996.
20
21 # Search path for a program which passes the given test.
22
23 dnl AM_PATH_PROG_WITH_TEST(VARIABLE, PROG-TO-CHECK-FOR,
24 dnl TEST-PERFORMED-ON-FOUND_PROGRAM [, VALUE-IF-NOT-FOUND [, PATH]])
25 AC_DEFUN([AM_PATH_PROG_WITH_TEST],
26 [
27 # Prepare PATH_SEPARATOR.
28 # The user is always right.
29 if test "${PATH_SEPARATOR+set}" != set; then
30 echo "#! /bin/sh" >conf$$.sh
31 echo "exit 0" >>conf$$.sh
32 chmod +x conf$$.sh
33 if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then
34 PATH_SEPARATOR=';'
35 else
36 PATH_SEPARATOR=:
37 fi
38 rm -f conf$$.sh
39 fi
40
41 # Find out how to test for executable files. Don't use a zero-byte file,
42 # as systems may use methods other than mode bits to determine executability.
43 cat >conf$$.file <<_ASEOF
44 #! /bin/sh
45 exit 0
46 _ASEOF
47 chmod +x conf$$.file
48 if test -x conf$$.file >/dev/null 2>&1; then
49 ac_executable_p="test -x"
50 else
51 ac_executable_p="test -f"
52 fi
53 rm -f conf$$.file
54
55 # Extract the first word of "$2", so it can be a program name with args.
56 set dummy $2; ac_word=[$]2
57 AC_MSG_CHECKING([for $ac_word])
58 AC_CACHE_VAL(ac_cv_path_$1,
59 [case "[$]$1" in
60 [[\\/]]* | ?:[[\\/]]*)
61 ac_cv_path_$1="[$]$1" # Let the user override the test with a path.
62 ;;
63 *)
64 ac_save_IFS="$IFS"; IFS=$PATH_SEPARATOR
65 for ac_dir in ifelse([$5], , $PATH, [$5]); do
66 IFS="$ac_save_IFS"
67 test -z "$ac_dir" && ac_dir=.
68 for ac_exec_ext in '' $ac_executable_extensions; do
69 if $ac_executable_p "$ac_dir/$ac_word$ac_exec_ext"; then
70 if [$3]; then
71 ac_cv_path_$1="$ac_dir/$ac_word$ac_exec_ext"
72 break 2
73 fi
74 fi
75 done
76 done
77 IFS="$ac_save_IFS"
78 dnl If no 4th arg is given, leave the cache variable unset,
79 dnl so AC_PATH_PROGS will keep looking.
80 ifelse([$4], , , [ test -z "[$]ac_cv_path_$1" && ac_cv_path_$1="$4"
81 ])dnl
82 ;;
83 esac])dnl
84 $1="$ac_cv_path_$1"
85 if test ifelse([$4], , [-n "[$]$1"], ["[$]$1" != "$4"]); then
86 AC_MSG_RESULT([$]$1)
87 else
88 AC_MSG_RESULT(no)
89 fi
90 AC_SUBST($1)dnl
91 ])
1 #serial 1003
2 dnl Copyright (C) 2003 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 # This macro can be removed once we can rely on Autoconf 2.57a or later,
8 # since we can then use its AC_C_RESTRICT.
9
10 # gl_C_RESTRICT
11 # --------------
12 # Determine whether the C/C++ compiler supports the "restrict" keyword
13 # introduced in ANSI C99, or an equivalent. Do nothing if the compiler
14 # accepts it. Otherwise, if the compiler supports an equivalent,
15 # define "restrict" to be that. Here are some variants:
16 # - GCC supports both __restrict and __restrict__
17 # - older DEC Alpha C compilers support only __restrict
18 # - _Restrict is the only spelling accepted by Sun WorkShop 6 update 2 C
19 # Otherwise, define "restrict" to be empty.
20 AC_DEFUN([gl_C_RESTRICT],
21 [AC_CACHE_CHECK([for C/C++ restrict keyword], gl_cv_c_restrict,
22 [gl_cv_c_restrict=no
23 # Try the official restrict keyword, then gcc's __restrict, and
24 # the less common variants.
25 for ac_kw in restrict __restrict __restrict__ _Restrict; do
26 AC_COMPILE_IFELSE([AC_LANG_SOURCE(
27 [float * $ac_kw x;])],
28 [gl_cv_c_restrict=$ac_kw; break])
29 done
30 ])
31 case $gl_cv_c_restrict in
32 restrict) ;;
33 no) AC_DEFINE(restrict,,
34 [Define to equivalent of C99 restrict keyword, or to nothing if this
35 is not supported. Do not define if restrict is supported directly.]) ;;
36 *) AC_DEFINE_UNQUOTED(restrict, $gl_cv_c_restrict) ;;
37 esac
38 ])
1 # setenv.m4 serial 5
2 dnl Copyright (C) 2001-2004 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN([gt_FUNC_SETENV],
8 [
9 AC_REPLACE_FUNCS(setenv unsetenv)
10 if test $ac_cv_func_setenv = no; then
11 gl_PREREQ_SETENV
12 fi
13 if test $ac_cv_func_unsetenv = no; then
14 gl_PREREQ_UNSETENV
15 else
16 AC_CACHE_CHECK([for unsetenv() return type], gt_cv_func_unsetenv_ret,
17 [AC_TRY_COMPILE([#include <stdlib.h>
18 extern
19 #ifdef __cplusplus
20 "C"
21 #endif
22 #if defined(__STDC__) || defined(__cplusplus)
23 int unsetenv (const char *name);
24 #else
25 int unsetenv();
26 #endif
27 ], , gt_cv_func_unsetenv_ret='int', gt_cv_func_unsetenv_ret='void')])
28 if test $gt_cv_func_unsetenv_ret = 'void'; then
29 AC_DEFINE(VOID_UNSETENV, 1, [Define if unsetenv() returns void, not int.])
30 fi
31 fi
32 ])
33
34 # Check if a variable is properly declared.
35 # gt_CHECK_VAR_DECL(includes,variable)
36 AC_DEFUN([gt_CHECK_VAR_DECL],
37 [
38 define([gt_cv_var], [gt_cv_var_]$2[_declaration])
39 AC_MSG_CHECKING([if $2 is properly declared])
40 AC_CACHE_VAL(gt_cv_var, [
41 AC_TRY_COMPILE([$1
42 extern struct { int foo; } $2;],
43 [$2.foo = 1;],
44 gt_cv_var=no,
45 gt_cv_var=yes)])
46 AC_MSG_RESULT($gt_cv_var)
47 if test $gt_cv_var = yes; then
48 AC_DEFINE([HAVE_]translit($2, [a-z], [A-Z])[_DECL], 1,
49 [Define if you have the declaration of $2.])
50 fi
51 ])
52
53 # Prerequisites of lib/setenv.c.
54 AC_DEFUN([gl_PREREQ_SETENV],
55 [
56 AC_REQUIRE([AC_FUNC_ALLOCA])
57 AC_CHECK_HEADERS_ONCE(unistd.h)
58 AC_CHECK_HEADERS(search.h)
59 AC_CHECK_FUNCS(tsearch)
60 gt_CHECK_VAR_DECL([#include <errno.h>], errno)
61 gt_CHECK_VAR_DECL([#include <unistd.h>], environ)
62 ])
63
64 # Prerequisites of lib/unsetenv.c.
65 AC_DEFUN([gl_PREREQ_UNSETENV],
66 [
67 AC_CHECK_HEADERS_ONCE(unistd.h)
68 gt_CHECK_VAR_DECL([#include <errno.h>], errno)
69 gt_CHECK_VAR_DECL([#include <unistd.h>], environ)
70 ])
1 # signed.m4 serial 1 (gettext-0.10.40)
2 dnl Copyright (C) 2001-2002 Free Software Foundation, Inc.
3 dnl This file is free software, distributed under the terms of the GNU
4 dnl General Public License. As a special exception to the GNU General
5 dnl Public License, this file may be distributed as part of a program
6 dnl that contains a configuration script generated by Autoconf, under
7 dnl the same distribution terms as the rest of that program.
8
9 dnl From Bruno Haible.
10
11 AC_DEFUN([bh_C_SIGNED],
12 [
13 AC_CACHE_CHECK([for signed], bh_cv_c_signed,
14 [AC_TRY_COMPILE(, [signed char x;], bh_cv_c_signed=yes, bh_cv_c_signed=no)])
15 if test $bh_cv_c_signed = no; then
16 AC_DEFINE(signed, ,
17 [Define to empty if the C compiler doesn't support this keyword.])
18 fi
19 ])
1 # size_max.m4 serial 2
2 dnl Copyright (C) 2003 Free Software Foundation, Inc.
3 dnl This file is free software, distributed under the terms of the GNU
4 dnl General Public License. As a special exception to the GNU General
5 dnl Public License, this file may be distributed as part of a program
6 dnl that contains a configuration script generated by Autoconf, under
7 dnl the same distribution terms as the rest of that program.
8
9 dnl From Bruno Haible.
10
11 AC_DEFUN([gl_SIZE_MAX],
12 [
13 AC_CHECK_HEADERS(stdint.h)
14 dnl First test whether the system already has SIZE_MAX.
15 AC_MSG_CHECKING([for SIZE_MAX])
16 result=
17 AC_EGREP_CPP([Found it], [
18 #include <limits.h>
19 #if HAVE_STDINT_H
20 #include <stdint.h>
21 #endif
22 #ifdef SIZE_MAX
23 Found it
24 #endif
25 ], result=yes)
26 if test -z "$result"; then
27 dnl Define it ourselves. Here we assume that the type 'size_t' is not wider
28 dnl than the type 'unsigned long'.
29 dnl The _AC_COMPUTE_INT macro works up to LONG_MAX, since it uses 'expr',
30 dnl which is guaranteed to work from LONG_MIN to LONG_MAX.
31 _AC_COMPUTE_INT([~(size_t)0 / 10], res_hi,
32 [#include <stddef.h>], result=?)
33 _AC_COMPUTE_INT([~(size_t)0 % 10], res_lo,
34 [#include <stddef.h>], result=?)
35 _AC_COMPUTE_INT([sizeof (size_t) <= sizeof (unsigned int)], fits_in_uint,
36 [#include <stddef.h>], result=?)
37 if test "$fits_in_uint" = 1; then
38 dnl Even though SIZE_MAX fits in an unsigned int, it must be of type
39 dnl 'unsigned long' if the type 'size_t' is the same as 'unsigned long'.
40 AC_TRY_COMPILE([#include <stddef.h>
41 extern size_t foo;
42 extern unsigned long foo;
43 ], [], fits_in_uint=0)
44 fi
45 if test -z "$result"; then
46 if test "$fits_in_uint" = 1; then
47 result="$res_hi$res_lo"U
48 else
49 result="$res_hi$res_lo"UL
50 fi
51 else
52 dnl Shouldn't happen, but who knows...
53 result='~(size_t)0'
54 fi
55 fi
56 AC_MSG_RESULT([$result])
57 if test "$result" != yes; then
58 AC_DEFINE_UNQUOTED([SIZE_MAX], [$result],
59 [Define as the maximum value of type 'size_t', if the system doesn't define it.])
60 fi
61 ])
1 # snprintf.m4 serial 2
2 dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN([gl_FUNC_SNPRINTF],
8 [
9 AC_REPLACE_FUNCS(snprintf)
10 AC_CHECK_DECLS_ONCE(snprintf)
11 gl_PREREQ_SNPRINTF
12 ])
13
14 # Prerequisites of lib/snprintf.c.
15 AC_DEFUN([gl_PREREQ_SNPRINTF], [:])
1 # ssize_t.m4 serial 3 (gettext-0.13)
2 dnl Copyright (C) 2001-2003 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 dnl From Bruno Haible.
8 dnl Test whether ssize_t is defined.
9
10 AC_DEFUN([gt_TYPE_SSIZE_T],
11 [
12 AC_CACHE_CHECK([for ssize_t], gt_cv_ssize_t,
13 [AC_TRY_COMPILE([#include <sys/types.h>],
14 [int x = sizeof (ssize_t *) + sizeof (ssize_t);],
15 gt_cv_ssize_t=yes, gt_cv_ssize_t=no)])
16 if test $gt_cv_ssize_t = no; then
17 AC_DEFINE(ssize_t, int,
18 [Define as a signed type of the same size as size_t.])
19 fi
20 ])
1 # Check for stdbool.h that conforms to C99.
2
3 dnl Copyright (C) 2002-2004 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
7
8 # Prepare for substituting <stdbool.h> if it is not supported.
9
10 AC_DEFUN([AM_STDBOOL_H],
11 [
12 AC_REQUIRE([AC_HEADER_STDBOOL])
13
14 # Define two additional variables used in the Makefile substitution.
15
16 if test "$ac_cv_header_stdbool_h" = yes; then
17 STDBOOL_H=''
18 else
19 STDBOOL_H='stdbool.h'
20 fi
21 AC_SUBST([STDBOOL_H])
22
23 if test "$ac_cv_type__Bool" = yes; then
24 HAVE__BOOL=1
25 else
26 HAVE__BOOL=0
27 fi
28 AC_SUBST([HAVE__BOOL])
29 ])
30
31 # This macro is only needed in autoconf <= 2.59. Newer versions of autoconf
32 # have this macro built-in.
33
34 AC_DEFUN([AC_HEADER_STDBOOL],
35 [AC_CACHE_CHECK([for stdbool.h that conforms to C99],
36 [ac_cv_header_stdbool_h],
37 [AC_TRY_COMPILE(
38 [
39 #include <stdbool.h>
40 #ifndef bool
41 "error: bool is not defined"
42 #endif
43 #ifndef false
44 "error: false is not defined"
45 #endif
46 #if false
47 "error: false is not 0"
48 #endif
49 #ifndef true
50 "error: true is not defined"
51 #endif
52 #if true != 1
53 "error: true is not 1"
54 #endif
55 #ifndef __bool_true_false_are_defined
56 "error: __bool_true_false_are_defined is not defined"
57 #endif
58
59 struct s { _Bool s: 1; _Bool t; } s;
60
61 char a[true == 1 ? 1 : -1];
62 char b[false == 0 ? 1 : -1];
63 char c[__bool_true_false_are_defined == 1 ? 1 : -1];
64 char d[(bool) -0.5 == true ? 1 : -1];
65 bool e = &s;
66 char f[(_Bool) -0.0 == false ? 1 : -1];
67 char g[true];
68 char h[sizeof (_Bool)];
69 char i[sizeof s.t];
70 enum { j = false, k = true, l = false * true, m = true * 256 };
71 _Bool n[m];
72 char o[sizeof n == m * sizeof n[0] ? 1 : -1];
73 ],
74 [
75 return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !j + !k + !l
76 + !m + !n + !o);
77 ],
78 [ac_cv_header_stdbool_h=yes],
79 [ac_cv_header_stdbool_h=no])])
80 AC_CHECK_TYPES([_Bool])
81 if test $ac_cv_header_stdbool_h = yes; then
82 AC_DEFINE(HAVE_STDBOOL_H, 1, [Define to 1 if stdbool.h conforms to C99.])
83 fi])
1 # stdint_h.m4 serial 5
2 dnl Copyright (C) 1997-2004 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 dnl From Paul Eggert.
8
9 # Define HAVE_STDINT_H_WITH_UINTMAX if <stdint.h> exists,
10 # doesn't clash with <sys/types.h>, and declares uintmax_t.
11
12 AC_DEFUN([gl_AC_HEADER_STDINT_H],
13 [
14 AC_CACHE_CHECK([for stdint.h], gl_cv_header_stdint_h,
15 [AC_TRY_COMPILE(
16 [#include <sys/types.h>
17 #include <stdint.h>],
18 [uintmax_t i = (uintmax_t) -1;],
19 gl_cv_header_stdint_h=yes,
20 gl_cv_header_stdint_h=no)])
21 if test $gl_cv_header_stdint_h = yes; then
22 AC_DEFINE_UNQUOTED(HAVE_STDINT_H_WITH_UINTMAX, 1,
23 [Define if <stdint.h> exists, doesn't clash with <sys/types.h>,
24 and declares uintmax_t. ])
25 fi
26 ])
1 # strcase.m4 serial 1
2 dnl Copyright (C) 2002 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN([gl_STRCASE],
8 [
9 gl_FUNC_STRCASECMP
10 gl_FUNC_STRNCASECMP
11 ])
12
13 AC_DEFUN([gl_FUNC_STRCASECMP],
14 [
15 MU_REPLACE_FUNCS(strcasecmp)
16 if test $ac_cv_func_strcasecmp = no; then
17 gl_PREREQ_STRCASECMP
18 fi
19 ])
20
21 AC_DEFUN([gl_FUNC_STRNCASECMP],
22 [
23 MU_REPLACE_FUNCS(strncasecmp)
24 if test $ac_cv_func_strncasecmp = no; then
25 gl_PREREQ_STRNCASECMP
26 fi
27 ])
28
29 # Prerequisites of lib/strcasecmp.c.
30 AC_DEFUN([gl_PREREQ_STRCASECMP], [
31 :
32 ])
33
34 # Prerequisites of lib/strncasecmp.c.
35 AC_DEFUN([gl_PREREQ_STRNCASECMP], [
36 :
37 ])
1 # strchrnul.m4 serial 3
2 dnl Copyright (C) 2003 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN([gl_FUNC_STRCHRNUL],
8 [
9 dnl Persuade glibc <string.h> to declare strchrnul().
10 AC_REQUIRE([AC_GNU_SOURCE])
11
12 MU_REPLACE_FUNCS(strchrnul)
13 if test $ac_cv_func_strchrnul = no; then
14 gl_PREREQ_STRCHRNUL
15 fi
16 ])
17
18 # Prerequisites of lib/strchrnul.c.
19 AC_DEFUN([gl_PREREQ_STRCHRNUL], [:])
1 #serial 1004
2 # This file is not needed if you can assume Autoconf 2.54 or later.
3 # Experimental replacement for the function in the latest CVS autoconf.
4 # Use with the error.c file in ../lib.
5
6 # Copyright (C) 2001 Free Software Foundation, Inc.
7 # This file is free software; the Free Software Foundation
8 # gives unlimited permission to copy and/or distribute it,
9 # with or without modifications, as long as this notice is preserved.
10
11 undefine([AC_FUNC_STRERROR_R])
12
13 # AC_FUNC_STRERROR_R
14 # ------------------
15 AC_DEFUN([AC_FUNC_STRERROR_R],
16 [AC_CHECK_DECLS([strerror_r])
17 AC_CHECK_FUNCS([strerror_r])
18 AC_CACHE_CHECK([whether strerror_r returns char *],
19 ac_cv_func_strerror_r_char_p,
20 [
21 ac_cv_func_strerror_r_char_p=no
22 if test $ac_cv_have_decl_strerror_r = yes; then
23 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
24 [[
25 char buf[100];
26 char x = *strerror_r (0, buf, sizeof buf);
27 char *p = strerror_r (0, buf, sizeof buf);
28 ]])],
29 ac_cv_func_strerror_r_char_p=yes)
30 else
31 # strerror_r is not declared. Choose between
32 # systems that have relatively inaccessible declarations for the
33 # function. BeOS and DEC UNIX 4.0 fall in this category, but the
34 # former has a strerror_r that returns char*, while the latter
35 # has a strerror_r that returns `int'.
36 # This test should segfault on the DEC system.
37 AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
38 extern char *strerror_r ();],
39 [[char buf[100];
40 char x = *strerror_r (0, buf, sizeof buf);
41 exit (!isalpha (x));]])],
42 ac_cv_func_strerror_r_char_p=yes, , :)
43 fi
44 ])
45 if test $ac_cv_func_strerror_r_char_p = yes; then
46 AC_DEFINE([STRERROR_R_CHAR_P], 1,
47 [Define to 1 if strerror_r returns char *.])
48 fi
49 ])# AC_FUNC_STRERROR_R
1 # strndup.m4 serial 3
2 dnl Copyright (C) 2002, 2003 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN([gl_FUNC_STRNDUP],
8 [
9 dnl Persuade glibc <string.h> to declare strndup().
10 AC_REQUIRE([AC_GNU_SOURCE])
11
12 MU_REPLACE_FUNCS(strndup)
13 if test $ac_cv_func_strndup = no; then
14 gl_PREREQ_STRNDUP
15 fi
16 ])
17
18 # Prerequisites of lib/strndup.c.
19 AC_DEFUN([gl_PREREQ_STRNDUP], [
20 AC_CHECK_DECLS(strnlen)
21 ])
1 # strnlen.m4 serial 4
2 dnl Copyright (C) 2002-2003 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN([gl_FUNC_STRNLEN],
8 [
9 dnl Persuade glibc <string.h> to declare strnlen().
10 AC_REQUIRE([AC_GNU_SOURCE])
11
12 AC_FUNC_STRNLEN
13 if test $ac_cv_func_strnlen_working = no; then
14 # This is necessary because automake-1.6.1 doens't understand
15 # that the above use of AC_FUNC_STRNLEN means we may have to use
16 # lib/strnlen.c.
17 #MU_LIBOBJ(strnlen)
18 AC_DEFINE(strnlen, rpl_strnlen,
19 [Define to rpl_strnlen if the replacement function should be used.])
20 gl_PREREQ_STRNLEN
21 fi
22 ])
23
24 # Prerequisites of lib/strnlen.c.
25 AC_DEFUN([gl_PREREQ_STRNLEN], [:])
1 # strtok_r.m4 serial 2
2 dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN([gl_FUNC_STRTOK_R],
8 [
9 MU_REPLACE_FUNCS(strtok_r)
10 AC_CHECK_DECLS_ONCE(strtok_r)
11 gl_PREREQ_STRTOK_R
12 ])
13
14 # Prerequisites of lib/strtok_r.h and lib/strtok_r.c.
15 AC_DEFUN([gl_PREREQ_STRTOK_R], [
16 AC_REQUIRE([gl_C_RESTRICT])
17 ])
1 # sysexits.m4 serial 2
2 dnl Copyright (C) 2003,2005 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN([gl_SYSEXITS],
8 [
9 AC_CHECK_HEADERS(sysexits.h,
10 [SYSEXITS_H=],
11 [SYSEXITS_H=sysexits.h])
12 AC_SUBST([SYSEXITS_H])
13 ])
1 # uint32_t.m4 serial 4
2
3 # Copyright (C) 2004 Free Software Foundation, Inc.
4 # This file is free software; the Free Software Foundation
5 # gives unlimited permission to copy and/or distribute it,
6 # with or without modifications, as long as this notice is preserved.
7
8 # Written by Paul Eggert.
9
10 AC_DEFUN([gl_AC_TYPE_UINT32_T],
11 [
12 AC_CACHE_CHECK([for uint32_t], gl_cv_c_uint32_t,
13 [gl_cv_c_uint32_t=no
14 for ac_type in "uint32_t" "unsigned int" \
15 "unsigned long int" "unsigned short int"; do
16 AC_COMPILE_IFELSE(
17 [AC_LANG_BOOL_COMPILE_TRY(
18 [AC_INCLUDES_DEFAULT],
19 [[($ac_type) -1 == 4294967295U]])],
20 [gl_cv_c_uint32_t=$ac_type])
21 test "$gl_cv_c_uint32_t" != no && break
22 done])
23 case "$gl_cv_c_uint32_t" in
24 no|uint32_t) ;;
25 *)
26 AC_DEFINE(_UINT32_T, 1,
27 [Define for Solaris 2.5.1 so uint32_t typedef from <sys/synch.h>,
28 <pthread.h>, or <semaphore.h> is not used. If the typedef was
29 allowed, the #define below would cause a syntax error.])
30 AC_DEFINE_UNQUOTED(uint32_t, $gl_cv_c_uint32_t,
31 [Define to the type of a unsigned integer type of width exactly 32 bits
32 if such a type exists and the standard includes do not define it.])
33 ;;
34 esac
35
36 AC_CACHE_CHECK([for UINT32_MAX], gl_cv_c_uint32_max,
37 [AC_COMPILE_IFELSE(
38 [AC_LANG_BOOL_COMPILE_TRY(
39 [AC_INCLUDES_DEFAULT],
40 [[UINT32_MAX == 4294967295U]])],
41 [gl_cv_c_uint32_max=yes],
42 [gl_cv_c_uint32_max=no])])
43 case $gl_cv_c_uint32_max,$gl_cv_c_uint32_t in
44 yes,*) ;;
45 *,no) ;;
46 *)
47 AC_DEFINE(UINT32_MAX, 4294967295U,
48 [Define to its maximum value if an unsigned integer type of width
49 exactly 32 bits exists and the standard includes do not define
50 UINT32_MAX.])
51 ;;
52 esac
53 ])
1 # uintmax_t.m4 serial 9
2 dnl Copyright (C) 1997-2004 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 dnl From Paul Eggert.
8
9 AC_PREREQ(2.13)
10
11 # Define uintmax_t to 'unsigned long' or 'unsigned long long'
12 # if it is not already defined in <stdint.h> or <inttypes.h>.
13
14 AC_DEFUN([gl_AC_TYPE_UINTMAX_T],
15 [
16 AC_REQUIRE([gl_AC_HEADER_INTTYPES_H])
17 AC_REQUIRE([gl_AC_HEADER_STDINT_H])
18 if test $gl_cv_header_inttypes_h = no && test $gl_cv_header_stdint_h = no; then
19 AC_REQUIRE([gl_AC_TYPE_UNSIGNED_LONG_LONG])
20 test $ac_cv_type_unsigned_long_long = yes \
21 && ac_type='unsigned long long' \
22 || ac_type='unsigned long'
23 AC_DEFINE_UNQUOTED(uintmax_t, $ac_type,
24 [Define to unsigned long or unsigned long long
25 if <stdint.h> and <inttypes.h> don't define.])
26 else
27 AC_DEFINE(HAVE_UINTMAX_T, 1,
28 [Define if you have the 'uintmax_t' type in <stdint.h> or <inttypes.h>.])
29 fi
30 ])
1 # ulonglong.m4 serial 4
2 dnl Copyright (C) 1999-2004 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 dnl From Paul Eggert.
8
9 # Define HAVE_UNSIGNED_LONG_LONG if 'unsigned long long' works.
10
11 AC_DEFUN([gl_AC_TYPE_UNSIGNED_LONG_LONG],
12 [
13 AC_CACHE_CHECK([for unsigned long long], ac_cv_type_unsigned_long_long,
14 [AC_TRY_LINK([unsigned long long ull = 1ULL; int i = 63;],
15 [unsigned long long ullmax = (unsigned long long) -1;
16 return ull << i | ull >> i | ullmax / ull | ullmax % ull;],
17 ac_cv_type_unsigned_long_long=yes,
18 ac_cv_type_unsigned_long_long=no)])
19 if test $ac_cv_type_unsigned_long_long = yes; then
20 AC_DEFINE(HAVE_UNSIGNED_LONG_LONG, 1,
21 [Define if you have the 'unsigned long long' type.])
22 fi
23 ])
1 # vasnprintf.m4 serial 5
2 dnl Copyright (C) 2002-2004 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN([gl_FUNC_VASNPRINTF],
8 [
9 AC_REQUIRE([gl_EOVERFLOW])
10 MU_REPLACE_FUNCS(vasnprintf)
11 if test $ac_cv_func_vasnprintf = no; then
12 MU_LIBOBJ(printf-args)
13 MU_LIBOBJ(printf-parse)
14 MU_LIBOBJ(asnprintf)
15 gl_PREREQ_PRINTF_ARGS
16 gl_PREREQ_PRINTF_PARSE
17 gl_PREREQ_VASNPRINTF
18 gl_PREREQ_ASNPRINTF
19 fi
20 ])
21
22 # Prequisites of lib/printf-args.h, lib/printf-args.c.
23 AC_DEFUN([gl_PREREQ_PRINTF_ARGS],
24 [
25 AC_REQUIRE([bh_C_SIGNED])
26 AC_REQUIRE([gl_AC_TYPE_LONG_LONG])
27 AC_REQUIRE([gt_TYPE_LONGDOUBLE])
28 AC_REQUIRE([gt_TYPE_WCHAR_T])
29 AC_REQUIRE([gt_TYPE_WINT_T])
30 ])
31
32 # Prequisites of lib/printf-parse.h, lib/printf-parse.c.
33 AC_DEFUN([gl_PREREQ_PRINTF_PARSE],
34 [
35 AC_REQUIRE([gl_AC_TYPE_LONG_LONG])
36 AC_REQUIRE([gt_TYPE_LONGDOUBLE])
37 AC_REQUIRE([gt_TYPE_WCHAR_T])
38 AC_REQUIRE([gt_TYPE_WINT_T])
39 AC_REQUIRE([AC_TYPE_SIZE_T])
40 AC_CHECK_TYPES(ptrdiff_t)
41 AC_REQUIRE([gt_AC_TYPE_INTMAX_T])
42 ])
43
44 # Prerequisites of lib/vasnprintf.c.
45 AC_DEFUN([gl_PREREQ_VASNPRINTF],
46 [
47 AC_REQUIRE([AC_FUNC_ALLOCA])
48 AC_REQUIRE([gl_AC_TYPE_LONG_LONG])
49 AC_REQUIRE([gt_TYPE_LONGDOUBLE])
50 AC_REQUIRE([gt_TYPE_WCHAR_T])
51 AC_REQUIRE([gt_TYPE_WINT_T])
52 AC_CHECK_FUNCS(snprintf wcslen)
53 ])
54
55 # Prerequisites of lib/asnprintf.c.
56 AC_DEFUN([gl_PREREQ_ASNPRINTF],
57 [
58 ])
1 # vasprintf.m4 serial 1
2 dnl Copyright (C) 2002-2003 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN([gl_FUNC_VASPRINTF],
8 [
9 AC_REPLACE_FUNCS(vasprintf)
10 if test $ac_cv_func_vasprintf = no; then
11 AC_LIBOBJ(asprintf)
12 gl_PREREQ_VASPRINTF
13 gl_PREREQ_ASPRINTF
14 fi
15 ])
16
17 # Prerequisites of lib/vasprintf.c.
18 AC_DEFUN([gl_PREREQ_VASPRINTF],
19 [
20 ])
21
22 # Prerequisites of lib/asprintf.c.
23 AC_DEFUN([gl_PREREQ_ASPRINTF],
24 [
25 ])
1 # vsnprintf.m4 serial 2
2 dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN([gl_FUNC_VSNPRINTF],
8 [
9 MU_REPLACE_FUNCS(vsnprintf)
10 AC_CHECK_DECLS_ONCE(vsnprintf)
11 gl_PREREQ_VSNPRINTF
12 ])
13
14 # Prerequisites of lib/vsnprintf.c.
15 AC_DEFUN([gl_PREREQ_VSNPRINTF], [:])
1 # wchar_t.m4 serial 1 (gettext-0.12)
2 dnl Copyright (C) 2002-2003 Free Software Foundation, Inc.
3 dnl This file is free software, distributed under the terms of the GNU
4 dnl General Public License. As a special exception to the GNU General
5 dnl Public License, this file may be distributed as part of a program
6 dnl that contains a configuration script generated by Autoconf, under
7 dnl the same distribution terms as the rest of that program.
8
9 dnl From Bruno Haible.
10 dnl Test whether <stddef.h> has the 'wchar_t' type.
11 dnl Prerequisite: AC_PROG_CC
12
13 AC_DEFUN([gt_TYPE_WCHAR_T],
14 [
15 AC_CACHE_CHECK([for wchar_t], gt_cv_c_wchar_t,
16 [AC_TRY_COMPILE([#include <stddef.h>
17 wchar_t foo = (wchar_t)'\0';], ,
18 gt_cv_c_wchar_t=yes, gt_cv_c_wchar_t=no)])
19 if test $gt_cv_c_wchar_t = yes; then
20 AC_DEFINE(HAVE_WCHAR_T, 1, [Define if you have the 'wchar_t' type.])
21 fi
22 ])
1 # wint_t.m4 serial 1 (gettext-0.12)
2 dnl Copyright (C) 2003 Free Software Foundation, Inc.
3 dnl This file is free software, distributed under the terms of the GNU
4 dnl General Public License. As a special exception to the GNU General
5 dnl Public License, this file may be distributed as part of a program
6 dnl that contains a configuration script generated by Autoconf, under
7 dnl the same distribution terms as the rest of that program.
8
9 dnl From Bruno Haible.
10 dnl Test whether <wchar.h> has the 'wint_t' type.
11 dnl Prerequisite: AC_PROG_CC
12
13 AC_DEFUN([gt_TYPE_WINT_T],
14 [
15 AC_CACHE_CHECK([for wint_t], gt_cv_c_wint_t,
16 [AC_TRY_COMPILE([#include <wchar.h>
17 wint_t foo = (wchar_t)'\0';], ,
18 gt_cv_c_wint_t=yes, gt_cv_c_wint_t=no)])
19 if test $gt_cv_c_wint_t = yes; then
20 AC_DEFINE(HAVE_WINT_T, 1, [Define if you have the 'wint_t' type.])
21 fi
22 ])
1 # xalloc.m4 serial 11
2 dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN([gl_XALLOC],
8 [
9 gl_PREREQ_XALLOC
10 gl_PREREQ_XMALLOC
11 ])
12
13 # Prerequisites of lib/xalloc.h.
14 AC_DEFUN([gl_PREREQ_XALLOC], [
15 :
16 ])
17
18 # Prerequisites of lib/xmalloc.c.
19 AC_DEFUN([gl_PREREQ_XMALLOC], [
20 AC_REQUIRE([AC_C_INLINE])
21 :
22 ])
1 # xsize.m4 serial 2
2 dnl Copyright (C) 2003 Free Software Foundation, Inc.
3 dnl This file is free software, distributed under the terms of the GNU
4 dnl General Public License. As a special exception to the GNU General
5 dnl Public License, this file may be distributed as part of a program
6 dnl that contains a configuration script generated by Autoconf, under
7 dnl the same distribution terms as the rest of that program.
8
9 AC_DEFUN([gl_XSIZE],
10 [
11 dnl Prerequisites of lib/xsize.h.
12 AC_REQUIRE([gl_SIZE_MAX])
13 AC_CHECK_HEADERS(stdint.h)
14 ])
1 # xstrtol.m4 serial 5
2 dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN([gl_XSTRTOL],
8 [
9 AC_REQUIRE([gl_PREREQ_XSTRTOL])
10 AC_REQUIRE([gl_PREREQ_XSTRTOUL])
11 ])
12
13 # Prerequisites of lib/xstrtol.h.
14 AC_DEFUN([gl_PREREQ_XSTRTOL_H],
15 [
16 AC_REQUIRE([gl_AC_TYPE_INTMAX_T])
17 AC_REQUIRE([gl_AC_TYPE_UINTMAX_T])
18 ])
19
20 # Prerequisites of lib/xstrtol.c.
21 AC_DEFUN([gl_PREREQ_XSTRTOL],
22 [
23 AC_REQUIRE([gl_PREREQ_XSTRTOL_H])
24 AC_REQUIRE([AC_HEADER_STDC])
25 AC_CHECK_FUNCS_ONCE(isascii)
26 AC_CHECK_DECLS([strtoimax, strtoumax])
27 ])
28
29 # Prerequisites of lib/xstrtoul.c.
30 AC_DEFUN([gl_PREREQ_XSTRTOUL],
31 [
32 AC_REQUIRE([gl_PREREQ_XSTRTOL])
33 ])
1 /* alloca.c -- allocate automatically reclaimed memory
2 (Mostly) portable public-domain implementation -- D A Gwyn
3
4 This implementation of the PWB library alloca function,
5 which is used to allocate space off the run-time stack so
6 that it is automatically reclaimed upon procedure exit,
7 was inspired by discussions with J. Q. Johnson of Cornell.
8 J.Otto Tennant <jot@cray.com> contributed the Cray support.
9
10 There are some preprocessor constants that can
11 be defined when compiling for your specific system, for
12 improved efficiency; however, the defaults should be okay.
13
14 The general concept of this implementation is to keep
15 track of all alloca-allocated blocks, and reclaim any
16 that are found to be deeper in the stack than the current
17 invocation. This heuristic does not reclaim storage as
18 soon as it becomes invalid, but it will do so eventually.
19
20 As a special case, alloca(0) reclaims storage without
21 allocating any. It is a good idea to use alloca(0) in
22 your main control loop, etc. to force garbage collection. */
23
24 #ifdef HAVE_CONFIG_H
25 # include <config.h>
26 #endif
27
28 #include <alloca.h>
29
30 #include <string.h>
31 #include <stdlib.h>
32
33 #ifdef emacs
34 # include "lisp.h"
35 # include "blockinput.h"
36 # ifdef EMACS_FREE
37 # undef free
38 # define free EMACS_FREE
39 # endif
40 #else
41 # define memory_full() abort ()
42 #endif
43
44 /* If compiling with GCC 2, this file's not needed. */
45 #if !defined (__GNUC__) || __GNUC__ < 2
46
47 /* If someone has defined alloca as a macro,
48 there must be some other way alloca is supposed to work. */
49 # ifndef alloca
50
51 # ifdef emacs
52 # ifdef static
53 /* actually, only want this if static is defined as ""
54 -- this is for usg, in which emacs must undefine static
55 in order to make unexec workable
56 */
57 # ifndef STACK_DIRECTION
58 you
59 lose
60 -- must know STACK_DIRECTION at compile-time
61 /* Using #error here is not wise since this file should work for
62 old and obscure compilers. */
63 # endif /* STACK_DIRECTION undefined */
64 # endif /* static */
65 # endif /* emacs */
66
67 /* If your stack is a linked list of frames, you have to
68 provide an "address metric" ADDRESS_FUNCTION macro. */
69
70 # if defined (CRAY) && defined (CRAY_STACKSEG_END)
71 long i00afunc ();
72 # define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg))
73 # else
74 # define ADDRESS_FUNCTION(arg) &(arg)
75 # endif
76
77 /* Define STACK_DIRECTION if you know the direction of stack
78 growth for your system; otherwise it will be automatically
79 deduced at run-time.
80
81 STACK_DIRECTION > 0 => grows toward higher addresses
82 STACK_DIRECTION < 0 => grows toward lower addresses
83 STACK_DIRECTION = 0 => direction of growth unknown */
84
85 # ifndef STACK_DIRECTION
86 # define STACK_DIRECTION 0 /* Direction unknown. */
87 # endif
88
89 # if STACK_DIRECTION != 0
90
91 # define STACK_DIR STACK_DIRECTION /* Known at compile-time. */
92
93 # else /* STACK_DIRECTION == 0; need run-time code. */
94
95 static int stack_dir; /* 1 or -1 once known. */
96 # define STACK_DIR stack_dir
97
98 static void
99 find_stack_direction (void)
100 {
101 static char *addr = NULL; /* Address of first `dummy', once known. */
102 auto char dummy; /* To get stack address. */
103
104 if (addr == NULL)
105 { /* Initial entry. */
106 addr = ADDRESS_FUNCTION (dummy);
107
108 find_stack_direction (); /* Recurse once. */
109 }
110 else
111 {
112 /* Second entry. */
113 if (ADDRESS_FUNCTION (dummy) > addr)
114 stack_dir = 1; /* Stack grew upward. */
115 else
116 stack_dir = -1; /* Stack grew downward. */
117 }
118 }
119
120 # endif /* STACK_DIRECTION == 0 */
121
122 /* An "alloca header" is used to:
123 (a) chain together all alloca'ed blocks;
124 (b) keep track of stack depth.
125
126 It is very important that sizeof(header) agree with malloc
127 alignment chunk size. The following default should work okay. */
128
129 # ifndef ALIGN_SIZE
130 # define ALIGN_SIZE sizeof(double)
131 # endif
132
133 typedef union hdr
134 {
135 char align[ALIGN_SIZE]; /* To force sizeof(header). */
136 struct
137 {
138 union hdr *next; /* For chaining headers. */
139 char *deep; /* For stack depth measure. */
140 } h;
141 } header;
142
143 static header *last_alloca_header = NULL; /* -> last alloca header. */
144
145 /* Return a pointer to at least SIZE bytes of storage,
146 which will be automatically reclaimed upon exit from
147 the procedure that called alloca. Originally, this space
148 was supposed to be taken from the current stack frame of the
149 caller, but that method cannot be made to work for some
150 implementations of C, for example under Gould's UTX/32. */
151
152 void *
153 alloca (size_t size)
154 {
155 auto char probe; /* Probes stack depth: */
156 register char *depth = ADDRESS_FUNCTION (probe);
157
158 # if STACK_DIRECTION == 0
159 if (STACK_DIR == 0) /* Unknown growth direction. */
160 find_stack_direction ();
161 # endif
162
163 /* Reclaim garbage, defined as all alloca'd storage that
164 was allocated from deeper in the stack than currently. */
165
166 {
167 register header *hp; /* Traverses linked list. */
168
169 # ifdef emacs
170 BLOCK_INPUT;
171 # endif
172
173 for (hp = last_alloca_header; hp != NULL;)
174 if ((STACK_DIR > 0 && hp->h.deep > depth)
175 || (STACK_DIR < 0 && hp->h.deep < depth))
176 {
177 register header *np = hp->h.next;
178
179 free (hp); /* Collect garbage. */
180
181 hp = np; /* -> next header. */
182 }
183 else
184 break; /* Rest are not deeper. */
185
186 last_alloca_header = hp; /* -> last valid storage. */
187
188 # ifdef emacs
189 UNBLOCK_INPUT;
190 # endif
191 }
192
193 if (size == 0)
194 return NULL; /* No allocation required. */
195
196 /* Allocate combined header + user data storage. */
197
198 {
199 /* Address of header. */
200 register header *new;
201
202 size_t combined_size = sizeof (header) + size;
203 if (combined_size < sizeof (header))
204 memory_full ();
205
206 new = malloc (combined_size);
207
208 if (! new)
209 memory_full ();
210
211 new->h.next = last_alloca_header;
212 new->h.deep = depth;
213
214 last_alloca_header = new;
215
216 /* User storage begins just after header. */
217
218 return (void *) (new + 1);
219 }
220 }
221
222 # if defined (CRAY) && defined (CRAY_STACKSEG_END)
223
224 # ifdef DEBUG_I00AFUNC
225 # include <stdio.h>
226 # endif
227
228 # ifndef CRAY_STACK
229 # define CRAY_STACK
230 # ifndef CRAY2
231 /* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */
232 struct stack_control_header
233 {
234 long shgrow:32; /* Number of times stack has grown. */
235 long shaseg:32; /* Size of increments to stack. */
236 long shhwm:32; /* High water mark of stack. */
237 long shsize:32; /* Current size of stack (all segments). */
238 };
239
240 /* The stack segment linkage control information occurs at
241 the high-address end of a stack segment. (The stack
242 grows from low addresses to high addresses.) The initial
243 part of the stack segment linkage control information is
244 0200 (octal) words. This provides for register storage
245 for the routine which overflows the stack. */
246
247 struct stack_segment_linkage
248 {
249 long ss[0200]; /* 0200 overflow words. */
250 long sssize:32; /* Number of words in this segment. */
251 long ssbase:32; /* Offset to stack base. */
252 long:32;
253 long sspseg:32; /* Offset to linkage control of previous
254 segment of stack. */
255 long:32;
256 long sstcpt:32; /* Pointer to task common address block. */
257 long sscsnm; /* Private control structure number for
258 microtasking. */
259 long ssusr1; /* Reserved for user. */
260 long ssusr2; /* Reserved for user. */
261 long sstpid; /* Process ID for pid based multi-tasking. */
262 long ssgvup; /* Pointer to multitasking thread giveup. */
263 long sscray[7]; /* Reserved for Cray Research. */
264 long ssa0;
265 long ssa1;
266 long ssa2;
267 long ssa3;
268 long ssa4;
269 long ssa5;
270 long ssa6;
271 long ssa7;
272 long sss0;
273 long sss1;
274 long sss2;
275 long sss3;
276 long sss4;
277 long sss5;
278 long sss6;
279 long sss7;
280 };
281
282 # else /* CRAY2 */
283 /* The following structure defines the vector of words
284 returned by the STKSTAT library routine. */
285 struct stk_stat
286 {
287 long now; /* Current total stack size. */
288 long maxc; /* Amount of contiguous space which would
289 be required to satisfy the maximum
290 stack demand to date. */
291 long high_water; /* Stack high-water mark. */
292 long overflows; /* Number of stack overflow ($STKOFEN) calls. */
293 long hits; /* Number of internal buffer hits. */
294 long extends; /* Number of block extensions. */
295 long stko_mallocs; /* Block allocations by $STKOFEN. */
296 long underflows; /* Number of stack underflow calls ($STKRETN). */
297 long stko_free; /* Number of deallocations by $STKRETN. */
298 long stkm_free; /* Number of deallocations by $STKMRET. */
299 long segments; /* Current number of stack segments. */
300 long maxs; /* Maximum number of stack segments so far. */
301 long pad_size; /* Stack pad size. */
302 long current_address; /* Current stack segment address. */
303 long current_size; /* Current stack segment size. This
304 number is actually corrupted by STKSTAT to
305 include the fifteen word trailer area. */
306 long initial_address; /* Address of initial segment. */
307 long initial_size; /* Size of initial segment. */
308 };
309
310 /* The following structure describes the data structure which trails
311 any stack segment. I think that the description in 'asdef' is
312 out of date. I only describe the parts that I am sure about. */
313
314 struct stk_trailer
315 {
316 long this_address; /* Address of this block. */
317 long this_size; /* Size of this block (does not include
318 this trailer). */
319 long unknown2;
320 long unknown3;
321 long link; /* Address of trailer block of previous
322 segment. */
323 long unknown5;
324 long unknown6;
325 long unknown7;
326 long unknown8;
327 long unknown9;
328 long unknown10;
329 long unknown11;
330 long unknown12;
331 long unknown13;
332 long unknown14;
333 };
334
335 # endif /* CRAY2 */
336 # endif /* not CRAY_STACK */
337
338 # ifdef CRAY2
339 /* Determine a "stack measure" for an arbitrary ADDRESS.
340 I doubt that "lint" will like this much. */
341
342 static long
343 i00afunc (long *address)
344 {
345 struct stk_stat status;
346 struct stk_trailer *trailer;
347 long *block, size;
348 long result = 0;
349
350 /* We want to iterate through all of the segments. The first
351 step is to get the stack status structure. We could do this
352 more quickly and more directly, perhaps, by referencing the
353 $LM00 common block, but I know that this works. */
354
355 STKSTAT (&status);
356
357 /* Set up the iteration. */
358
359 trailer = (struct stk_trailer *) (status.current_address
360 + status.current_size
361 - 15);
362
363 /* There must be at least one stack segment. Therefore it is
364 a fatal error if "trailer" is null. */
365
366 if (trailer == 0)
367 abort ();
368
369 /* Discard segments that do not contain our argument address. */
370
371 while (trailer != 0)
372 {
373 block = (long *) trailer->this_address;
374 size = trailer->this_size;
375 if (block == 0 || size == 0)
376 abort ();
377 trailer = (struct stk_trailer *) trailer->link;
378 if ((block <= address) && (address < (block + size)))
379 break;
380 }
381
382 /* Set the result to the offset in this segment and add the sizes
383 of all predecessor segments. */
384
385 result = address - block;
386
387 if (trailer == 0)
388 {
389 return result;
390 }
391
392 do
393 {
394 if (trailer->this_size <= 0)
395 abort ();
396 result += trailer->this_size;
397 trailer = (struct stk_trailer *) trailer->link;
398 }
399 while (trailer != 0);
400
401 /* We are done. Note that if you present a bogus address (one
402 not in any segment), you will get a different number back, formed
403 from subtracting the address of the first block. This is probably
404 not what you want. */
405
406 return (result);
407 }
408
409 # else /* not CRAY2 */
410 /* Stack address function for a CRAY-1, CRAY X-MP, or CRAY Y-MP.
411 Determine the number of the cell within the stack,
412 given the address of the cell. The purpose of this
413 routine is to linearize, in some sense, stack addresses
414 for alloca. */
415
416 static long
417 i00afunc (long address)
418 {
419 long stkl = 0;
420
421 long size, pseg, this_segment, stack;
422 long result = 0;
423
424 struct stack_segment_linkage *ssptr;
425
426 /* Register B67 contains the address of the end of the
427 current stack segment. If you (as a subprogram) store
428 your registers on the stack and find that you are past
429 the contents of B67, you have overflowed the segment.
430
431 B67 also points to the stack segment linkage control
432 area, which is what we are really interested in. */
433
434 stkl = CRAY_STACKSEG_END ();
435 ssptr = (struct stack_segment_linkage *) stkl;
436
437 /* If one subtracts 'size' from the end of the segment,
438 one has the address of the first word of the segment.
439
440 If this is not the first segment, 'pseg' will be
441 nonzero. */
442
443 pseg = ssptr->sspseg;
444 size = ssptr->sssize;
445
446 this_segment = stkl - size;
447
448 /* It is possible that calling this routine itself caused
449 a stack overflow. Discard stack segments which do not
450 contain the target address. */
451
452 while (!(this_segment <= address && address <= stkl))
453 {
454 # ifdef DEBUG_I00AFUNC
455 fprintf (stderr, "%011o %011o %011o\n", this_segment, address, stkl);
456 # endif
457 if (pseg == 0)
458 break;
459 stkl = stkl - pseg;
460 ssptr = (struct stack_segment_linkage *) stkl;
461 size = ssptr->sssize;
462 pseg = ssptr->sspseg;
463 this_segment = stkl - size;
464 }
465
466 result = address - this_segment;
467
468 /* If you subtract pseg from the current end of the stack,
469 you get the address of the previous stack segment's end.
470 This seems a little convoluted to me, but I'll bet you save
471 a cycle somewhere. */
472
473 while (pseg != 0)
474 {
475 # ifdef DEBUG_I00AFUNC
476 fprintf (stderr, "%011o %011o\n", pseg, size);
477 # endif
478 stkl = stkl - pseg;
479 ssptr = (struct stack_segment_linkage *) stkl;
480 size = ssptr->sssize;
481 pseg = ssptr->sspseg;
482 result += size;
483 }
484 return (result);
485 }
486
487 # endif /* not CRAY2 */
488 # endif /* CRAY */
489
490 # endif /* no alloca */
491 #endif /* not GCC version 2 */
1 /* Memory allocation on the stack.
2
3 Copyright (C) 1995, 1999, 2001, 2002, 2003, 2004 Free Software
4 Foundation, Inc.
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published
8 by the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public
17 License along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 USA. */
20
21 /* Avoid using the symbol _ALLOCA_H here, as Bison assumes _ALLOCA_H
22 means there is a real alloca function. */
23 #ifndef _GNULIB_ALLOCA_H
24 # define _GNULIB_ALLOCA_H
25
26 /* alloca (N) returns a pointer to N bytes of memory
27 allocated on the stack, which will last until the function returns.
28 Use of alloca should be avoided:
29 - inside arguments of function calls - undefined behaviour,
30 - in inline functions - the allocation may actually last until the
31 calling function returns,
32 - for huge N (say, N >= 65536) - you never know how large (or small)
33 the stack is, and when the stack cannot fulfill the memory allocation
34 request, the program just crashes.
35 */
36
37 #ifdef __GNUC__
38 # define alloca __builtin_alloca
39 #elif defined _AIX
40 # define alloca __alloca
41 #elif defined _MSC_VER
42 # include <malloc.h>
43 # define alloca _alloca
44 #else
45 # include <stddef.h>
46 # ifdef __cplusplus
47 extern "C"
48 # endif
49 void *alloca (size_t);
50 #endif
51
52 #endif /* _GNULIB_ALLOCA_H */
1 /* Formatted output to strings.
2 Copyright (C) 1999, 2002 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21
22 /* Specification. */
23 #include "vasnprintf.h"
24
25 #include <stdarg.h>
26
27 char *
28 asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...)
29 {
30 va_list args;
31 char *result;
32
33 va_start (args, format);
34 result = vasnprintf (resultbuf, lengthp, format, args);
35 va_end (args);
36 return result;
37 }
1 /* getndelim2 - Read a line from a stream, stopping at one of 2 delimiters,
2 with bounded memory allocation.
3
4 Copyright (C) 1993, 1996, 1997, 1998, 2000, 2003, 2004 Free Software
5 Foundation, Inc.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
21 /* Originally written by Jan Brittenson, bson@gnu.ai.mit.edu. */
22
23 #if HAVE_CONFIG_H
24 # include <config.h>
25 #endif
26
27 #include "getndelim2.h"
28
29 #include <stdlib.h>
30 #include <stddef.h>
31
32 #if USE_UNLOCKED_IO
33 # include "unlocked-io.h"
34 #endif
35
36 #include <limits.h>
37 #if HAVE_INTTYPES_H
38 # include <inttypes.h>
39 #endif
40 #if HAVE_STDINT_H
41 # include <stdint.h>
42 #endif
43 #ifndef PTRDIFF_MAX
44 # define PTRDIFF_MAX ((ptrdiff_t) (SIZE_MAX / 2))
45 #endif
46 #ifndef SIZE_MAX
47 # define SIZE_MAX ((size_t) -1)
48 #endif
49 #ifndef SSIZE_MAX
50 # define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2))
51 #endif
52
53 /* The maximum value that getndelim2 can return without suffering from
54 overflow problems, either internally (because of pointer
55 subtraction overflow) or due to the API (because of ssize_t). */
56 #define GETNDELIM2_MAXIMUM (PTRDIFF_MAX < SSIZE_MAX ? PTRDIFF_MAX : SSIZE_MAX)
57
58 /* Try to add at least this many bytes when extending the buffer.
59 MIN_CHUNK must be no greater than GETNDELIM2_MAXIMUM. */
60 #define MIN_CHUNK 64
61
62 ssize_t
63 getndelim2 (char **lineptr, size_t *linesize, size_t offset, size_t nmax,
64 int delim1, int delim2, FILE *stream)
65 {
66 size_t nbytes_avail; /* Allocated but unused bytes in *LINEPTR. */
67 char *read_pos; /* Where we're reading into *LINEPTR. */
68 ssize_t bytes_stored = -1;
69 char *ptr = *lineptr;
70 size_t size = *linesize;
71
72 if (!ptr)
73 {
74 size = nmax < MIN_CHUNK ? nmax : MIN_CHUNK;
75 ptr = malloc (size);
76 if (!ptr)
77 return -1;
78 }
79
80 if (size < offset)
81 goto done;
82
83 nbytes_avail = size - offset;
84 read_pos = ptr + offset;
85
86 if (nbytes_avail == 0 && nmax <= size)
87 goto done;
88
89 for (;;)
90 {
91 /* Here always ptr + size == read_pos + nbytes_avail. */
92
93 int c;
94
95 /* We always want at least one byte left in the buffer, since we
96 always (unless we get an error while reading the first byte)
97 NUL-terminate the line buffer. */
98
99 if (nbytes_avail < 2 && size < nmax)
100 {
101 size_t newsize = size < MIN_CHUNK ? size + MIN_CHUNK : 2 * size;
102 char *newptr;
103
104 if (! (size < newsize && newsize <= nmax))
105 newsize = nmax;
106
107 if (GETNDELIM2_MAXIMUM < newsize - offset)
108 {
109 size_t newsizemax = offset + GETNDELIM2_MAXIMUM + 1;
110 if (size == newsizemax)
111 goto done;
112 newsize = newsizemax;
113 }
114
115 nbytes_avail = newsize - (read_pos - ptr);
116 newptr = realloc (ptr, newsize);
117 if (!newptr)
118 goto done;
119 ptr = newptr;
120 size = newsize;
121 read_pos = size - nbytes_avail + ptr;
122 }
123
124 c = getc (stream);
125 if (c == EOF)
126 {
127 /* Return partial line, if any. */
128 if (read_pos == ptr)
129 goto done;
130 else
131 break;
132 }
133
134 if (nbytes_avail >= 2)
135 {
136 *read_pos++ = c;
137 nbytes_avail--;
138 }
139
140 if (c == delim1 || c == delim2)
141 /* Return the line. */
142 break;
143 }
144
145 /* Done - NUL terminate and return the number of bytes read.
146 At this point we know that nbytes_avail >= 1. */
147 *read_pos = '\0';
148
149 bytes_stored = read_pos - (ptr + offset);
150
151 done:
152 *lineptr = ptr;
153 *linesize = size;
154 return bytes_stored;
155 }
1 /* getndelim2 - Read a line from a stream, stopping at one of 2 delimiters,
2 with bounded memory allocation.
3
4 Copyright (C) 2003, 2004 Free Software Foundation, Inc.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software Foundation,
18 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19
20 #ifndef GETNDELIM2_H
21 #define GETNDELIM2_H 1
22
23 #include <stdio.h>
24 #include <sys/types.h>
25
26 #define GETNLINE_NO_LIMIT ((size_t) -1)
27
28 /* Read into a buffer *LINEPTR returned from malloc (or NULL),
29 pointing to *LINESIZE bytes of space. Store the input bytes
30 starting at *LINEPTR + OFFSET, and null-terminate them. Reallocate
31 the buffer as necessary, but if NMAX is not GETNLINE_NO_LIMIT
32 then do not allocate more than NMAX bytes; if the line is longer
33 than that, read and discard the extra bytes. Stop reading after
34 after the first occurrence of DELIM1 or DELIM2, whichever comes
35 first; a delimiter equal to EOF stands for no delimiter. Read the
36 input bytes from STREAM.
37 Return the number of bytes read and stored at *LINEPTR + OFFSET (not
38 including the NUL terminator), or -1 on error or EOF. */
39 extern ssize_t getndelim2 (char **lineptr, size_t *linesize, size_t offset,
40 size_t nmax, int delim1, int delim2,
41 FILE *stream);
42
43 #endif /* GETNDELIM2_H */
1 /* Declarations for getopt.
2 Copyright (C) 1989-1994,1996-1999,2001,2003,2004
3 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation,
18 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19
20 #ifndef _GETOPT_H
21
22 #ifndef __need_getopt
23 # define _GETOPT_H 1
24 #endif
25
26 /* Standalone applications should #define __GETOPT_PREFIX to an
27 identifier that prefixes the external functions and variables
28 defined in this header. When this happens, include the
29 headers that might declare getopt so that they will not cause
30 confusion if included after this file. Then systematically rename
31 identifiers so that they do not collide with the system functions
32 and variables. Renaming avoids problems with some compilers and
33 linkers. */
34 #if defined __GETOPT_PREFIX && !defined __need_getopt
35 # include <stdlib.h>
36 # include <stdio.h>
37 # if HAVE_UNISTD_H
38 # include <unistd.h>
39 # endif
40 # undef __need_getopt
41 # undef getopt
42 # undef getopt_long
43 # undef getopt_long_only
44 # undef optarg
45 # undef opterr
46 # undef optind
47 # undef optopt
48 # define __GETOPT_CONCAT(x, y) x ## y
49 # define __GETOPT_XCONCAT(x, y) __GETOPT_CONCAT (x, y)
50 # define __GETOPT_ID(y) __GETOPT_XCONCAT (__GETOPT_PREFIX, y)
51 # define getopt __GETOPT_ID (getopt)
52 # define getopt_long __GETOPT_ID (getopt_long)
53 # define getopt_long_only __GETOPT_ID (getopt_long_only)
54 # define optarg __GETOPT_ID (optarg)
55 # define opterr __GETOPT_ID (opterr)
56 # define optind __GETOPT_ID (optind)
57 # define optopt __GETOPT_ID (optopt)
58 #endif
59
60 /* Standalone applications get correct prototypes for getopt_long and
61 getopt_long_only; they declare "char **argv". libc uses prototypes
62 with "char *const *argv" that are incorrect because getopt_long and
63 getopt_long_only can permute argv; this is required for backward
64 compatibility (e.g., for LSB 2.0.1).
65
66 This used to be `#if defined __GETOPT_PREFIX && !defined __need_getopt',
67 but it caused redefinition warnings if both unistd.h and getopt.h were
68 included, since unistd.h includes getopt.h having previously defined
69 __need_getopt.
70
71 The only place where __getopt_argv_const is used is in definitions
72 of getopt_long and getopt_long_only below, but these are visible
73 only if __need_getopt is not defined, so it is quite safe to rewrite
74 the conditional as follows:
75 */
76 #if !defined __need_getopt
77 # if defined __GETOPT_PREFIX
78 # define __getopt_argv_const /* empty */
79 # else
80 # define __getopt_argv_const const
81 # endif
82 #endif
83
84 /* If __GNU_LIBRARY__ is not already defined, either we are being used
85 standalone, or this is the first header included in the source file.
86 If we are being used with glibc, we need to include <features.h>, but
87 that does not exist if we are standalone. So: if __GNU_LIBRARY__ is
88 not defined, include <ctype.h>, which will pull in <features.h> for us
89 if it's from glibc. (Why ctype.h? It's guaranteed to exist and it
90 doesn't flood the namespace with stuff the way some other headers do.) */
91 #if !defined __GNU_LIBRARY__
92 # include <ctype.h>
93 #endif
94
95 #ifndef __THROW
96 # ifndef __GNUC_PREREQ
97 # define __GNUC_PREREQ(maj, min) (0)
98 # endif
99 # if defined __cplusplus && __GNUC_PREREQ (2,8)
100 # define __THROW throw ()
101 # else
102 # define __THROW
103 # endif
104 #endif
105
106 #ifdef __cplusplus
107 extern "C" {
108 #endif
109
110 /* For communication from `getopt' to the caller.
111 When `getopt' finds an option that takes an argument,
112 the argument value is returned here.
113 Also, when `ordering' is RETURN_IN_ORDER,
114 each non-option ARGV-element is returned here. */
115
116 extern char *optarg;
117
118 /* Index in ARGV of the next element to be scanned.
119 This is used for communication to and from the caller
120 and for communication between successive calls to `getopt'.
121
122 On entry to `getopt', zero means this is the first call; initialize.
123
124 When `getopt' returns -1, this is the index of the first of the
125 non-option elements that the caller should itself scan.
126
127 Otherwise, `optind' communicates from one call to the next
128 how much of ARGV has been scanned so far. */
129
130 extern int optind;
131
132 /* Callers store zero here to inhibit the error message `getopt' prints
133 for unrecognized options. */
134
135 extern int opterr;
136
137 /* Set to an option character which was unrecognized. */
138
139 extern int optopt;
140
141 #ifndef __need_getopt
142 /* Describe the long-named options requested by the application.
143 The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
144 of `struct option' terminated by an element containing a name which is
145 zero.
146
147 The field `has_arg' is:
148 no_argument (or 0) if the option does not take an argument,
149 required_argument (or 1) if the option requires an argument,
150 optional_argument (or 2) if the option takes an optional argument.
151
152 If the field `flag' is not NULL, it points to a variable that is set
153 to the value given in the field `val' when the option is found, but
154 left unchanged if the option is not found.
155
156 To have a long-named option do something other than set an `int' to
157 a compiled-in constant, such as set a value from `optarg', set the
158 option's `flag' field to zero and its `val' field to a nonzero
159 value (the equivalent single-letter option character, if there is
160 one). For long options that have a zero `flag' field, `getopt'
161 returns the contents of the `val' field. */
162
163 struct option
164 {
165 const char *name;
166 /* has_arg can't be an enum because some compilers complain about
167 type mismatches in all the code that assumes it is an int. */
168 int has_arg;
169 int *flag;
170 int val;
171 };
172
173 /* Names for the values of the `has_arg' field of `struct option'. */
174
175 # define no_argument 0
176 # define required_argument 1
177 # define optional_argument 2
178 #endif /* need getopt */
179
180
181 /* Get definitions and prototypes for functions to process the
182 arguments in ARGV (ARGC of them, minus the program name) for
183 options given in OPTS.
184
185 Return the option character from OPTS just read. Return -1 when
186 there are no more options. For unrecognized options, or options
187 missing arguments, `optopt' is set to the option letter, and '?' is
188 returned.
189
190 The OPTS string is a list of characters which are recognized option
191 letters, optionally followed by colons, specifying that that letter
192 takes an argument, to be placed in `optarg'.
193
194 If a letter in OPTS is followed by two colons, its argument is
195 optional. This behavior is specific to the GNU `getopt'.
196
197 The argument `--' causes premature termination of argument
198 scanning, explicitly telling `getopt' that there are no more
199 options.
200
201 If OPTS begins with `--', then non-option arguments are treated as
202 arguments to the option '\0'. This behavior is specific to the GNU
203 `getopt'. */
204
205 extern int getopt (int ___argc, char *const *___argv, const char *__shortopts)
206 __THROW;
207
208 #ifndef __need_getopt
209 extern int getopt_long (int ___argc, char *__getopt_argv_const *___argv,
210 const char *__shortopts,
211 const struct option *__longopts, int *__longind)
212 __THROW;
213 extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv,
214 const char *__shortopts,
215 const struct option *__longopts, int *__longind)
216 __THROW;
217
218 #endif
219
220 #ifdef __cplusplus
221 }
222 #endif
223
224 /* Make sure we later can get all the definitions and declarations. */
225 #undef __need_getopt
226
227 #endif /* getopt.h */
1 /* Internal declarations for getopt.
2 Copyright (C) 1989-1994,1996-1999,2001,2003,2004
3 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation,
18 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19
20 #ifndef _GETOPT_INT_H
21 #define _GETOPT_INT_H 1
22
23 extern int _getopt_internal (int ___argc, char **___argv,
24 const char *__shortopts,
25 const struct option *__longopts, int *__longind,
26 int __long_only, int __posixly_correct);
27
28
29 /* Reentrant versions which can handle parsing multiple argument
30 vectors at the same time. */
31
32 /* Data type for reentrant functions. */
33 struct _getopt_data
34 {
35 /* These have exactly the same meaning as the corresponding global
36 variables, except that they are used for the reentrant
37 versions of getopt. */
38 int optind;
39 int opterr;
40 int optopt;
41 char *optarg;
42
43 /* Internal members. */
44
45 /* True if the internal members have been initialized. */
46 int __initialized;
47
48 /* The next char to be scanned in the option-element
49 in which the last option character we returned was found.
50 This allows us to pick up the scan where we left off.
51
52 If this is zero, or a null string, it means resume the scan
53 by advancing to the next ARGV-element. */
54 char *__nextchar;
55
56 /* Describe how to deal with options that follow non-option ARGV-elements.
57
58 If the caller did not specify anything,
59 the default is REQUIRE_ORDER if the environment variable
60 POSIXLY_CORRECT is defined, PERMUTE otherwise.
61
62 REQUIRE_ORDER means don't recognize them as options;
63 stop option processing when the first non-option is seen.
64 This is what Unix does.
65 This mode of operation is selected by either setting the environment
66 variable POSIXLY_CORRECT, or using `+' as the first character
67 of the list of option characters, or by calling getopt.
68
69 PERMUTE is the default. We permute the contents of ARGV as we
70 scan, so that eventually all the non-options are at the end.
71 This allows options to be given in any order, even with programs
72 that were not written to expect this.
73
74 RETURN_IN_ORDER is an option available to programs that were
75 written to expect options and other ARGV-elements in any order
76 and that care about the ordering of the two. We describe each
77 non-option ARGV-element as if it were the argument of an option
78 with character code 1. Using `-' as the first character of the
79 list of option characters selects this mode of operation.
80
81 The special argument `--' forces an end of option-scanning regardless
82 of the value of `ordering'. In the case of RETURN_IN_ORDER, only
83 `--' can cause `getopt' to return -1 with `optind' != ARGC. */
84
85 enum
86 {
87 REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
88 } __ordering;
89
90 /* If the POSIXLY_CORRECT environment variable is set
91 or getopt was called. */
92 int __posixly_correct;
93
94
95 /* Handle permutation of arguments. */
96
97 /* Describe the part of ARGV that contains non-options that have
98 been skipped. `first_nonopt' is the index in ARGV of the first
99 of them; `last_nonopt' is the index after the last of them. */
100
101 int __first_nonopt;
102 int __last_nonopt;
103
104 #if defined _LIBC && defined USE_NONOPTION_FLAGS
105 int __nonoption_flags_max_len;
106 int __nonoption_flags_len;
107 # endif
108 };
109
110 /* The initializer is necessary to set OPTIND and OPTERR to their
111 default values and to clear the initialization flag. */
112 #define _GETOPT_DATA_INITIALIZER { 1, 1 }
113
114 extern int _getopt_internal_r (int ___argc, char **___argv,
115 const char *__shortopts,
116 const struct option *__longopts, int *__longind,
117 int __long_only, int __posixly_correct,
118 struct _getopt_data *__data);
119
120 extern int _getopt_long_r (int ___argc, char **___argv,
121 const char *__shortopts,
122 const struct option *__longopts, int *__longind,
123 struct _getopt_data *__data);
124
125 extern int _getopt_long_only_r (int ___argc, char **___argv,
126 const char *__shortopts,
127 const struct option *__longopts,
128 int *__longind,
129 struct _getopt_data *__data);
130
131 #endif /* getopt_int.h */
1 /* Convenience header for conditional use of GNU <libintl.h>.
2 Copyright (C) 1995-1998, 2000-2002 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17
18 #ifndef _LIBGETTEXT_H
19 #define _LIBGETTEXT_H 1
20
21 /* NLS can be disabled through the configure --disable-nls option. */
22 #if ENABLE_NLS
23
24 /* Get declarations of GNU message catalog functions. */
25 # include <libintl.h>
26
27 #else
28
29 /* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which
30 chokes if dcgettext is defined as a macro. So include it now, to make
31 later inclusions of <locale.h> a NOP. We don't include <libintl.h>
32 as well because people using "gettext.h" will not include <libintl.h>,
33 and also including <libintl.h> would fail on SunOS 4, whereas <locale.h>
34 is OK. */
35 #if defined(__sun)
36 # include <locale.h>
37 #endif
38
39 /* Disabled NLS.
40 The casts to 'const char *' serve the purpose of producing warnings
41 for invalid uses of the value returned from these functions.
42 On pre-ANSI systems without 'const', the config.h file is supposed to
43 contain "#define const". */
44 # define gettext(Msgid) ((const char *) (Msgid))
45 # define dgettext(Domainname, Msgid) ((const char *) (Msgid))
46 # define dcgettext(Domainname, Msgid, Category) ((const char *) (Msgid))
47 # define ngettext(Msgid1, Msgid2, N) \
48 ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
49 # define dngettext(Domainname, Msgid1, Msgid2, N) \
50 ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
51 # define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
52 ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
53 # define textdomain(Domainname) ((const char *) (Domainname))
54 # define bindtextdomain(Domainname, Dirname) ((const char *) (Dirname))
55 # define bind_textdomain_codeset(Domainname, Codeset) ((const char *) (Codeset))
56
57 #endif
58
59 /* A pseudo function call that serves as a marker for the automated
60 extraction of messages, but does not call gettext(). The run-time
61 translation is done at a different place in the code.
62 The argument, String, should be a literal string. Concatenated strings
63 and other string expressions won't work.
64 The macro's expansion is not parenthesized, so that it is suitable as
65 initializer for static 'char[]' or 'const char[]' variables. */
66 #define gettext_noop(String) String
67
68 #endif /* _LIBGETTEXT_H */
1 /* Copy memory area and return pointer after last written byte.
2 Copyright (C) 2003 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17
18 /* Specification. */
19 #include "mempcpy.h"
20
21 #include <string.h>
22
23 /* Copy N bytes of SRC to DEST, return pointer to bytes after the
24 last written byte. */
25 void *
26 mempcpy (void *dest, const void *src, size_t n)
27 {
28 return (char *) memcpy (dest, src, n) + n;
29 }
1 /* Copy memory area and return pointer after last written byte.
2 Copyright (C) 2003, 2004 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17
18 #ifndef mempcpy
19
20 # if HAVE_MEMPCPY
21
22 /* Get mempcpy() declaration. */
23 # include <string.h>
24
25 # else
26
27 /* Get size_t */
28 # include <stddef.h>
29
30 /* Copy N bytes of SRC to DEST, return pointer to bytes after the
31 last written byte. */
32 extern void *mempcpy (void *dest, const void *src, size_t n);
33
34 # endif
35
36 #endif
1 /* MIN, MAX macros.
2 Copyright (C) 1995, 1998, 2001, 2003 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17
18 #ifndef _MINMAX_H
19 #define _MINMAX_H
20
21 /* Note: MIN, MAX are also defined in <sys/param.h> on some systems
22 (glibc, IRIX, HP-UX, OSF/1). Therefore you might get warnings about
23 MIN, MAX macro redefinitions on some systems; the workaround is to
24 #include this file as the last one among the #include list. */
25
26 /* Before we define the following symbols we get the <limits.h> file
27 since otherwise we get redefinitions on some systems. */
28 #include <limits.h>
29
30 /* Note: MIN and MAX should be used with two arguments of the
31 same type. They might not return the minimum and maximum of their two
32 arguments, if the arguments have different types or have unusual
33 floating-point values. For example, on a typical host with 32-bit 'int',
34 64-bit 'long long', and 64-bit IEEE 754 'double' types:
35
36 MAX (-1, 2147483648) returns 4294967295.
37 MAX (9007199254740992.0, 9007199254740993) returns 9007199254740992.0.
38 MAX (NaN, 0.0) returns 0.0.
39 MAX (+0.0, -0.0) returns -0.0.
40
41 and in each case the answer is in some sense bogus. */
42
43 /* MAX(a,b) returns the maximum of A and B. */
44 #ifndef MAX
45 # define MAX(a,b) ((a) > (b) ? (a) : (b))
46 #endif
47
48 /* MIN(a,b) returns the minimum of A and B. */
49 #ifndef MIN
50 # define MIN(a,b) ((a) < (b) ? (a) : (b))
51 #endif
52
53 #endif /* _MINMAX_H */
1 /* Decomposed printf argument list.
2 Copyright (C) 1999, 2002-2003 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21
22 /* Specification. */
23 #include "printf-args.h"
24
25 #ifdef STATIC
26 STATIC
27 #endif
28 int
29 printf_fetchargs (va_list args, arguments *a)
30 {
31 size_t i;
32 argument *ap;
33
34 for (i = 0, ap = &a->arg[0]; i < a->count; i++, ap++)
35 switch (ap->type)
36 {
37 case TYPE_SCHAR:
38 ap->a.a_schar = va_arg (args, /*signed char*/ int);
39 break;
40 case TYPE_UCHAR:
41 ap->a.a_uchar = va_arg (args, /*unsigned char*/ int);
42 break;
43 case TYPE_SHORT:
44 ap->a.a_short = va_arg (args, /*short*/ int);
45 break;
46 case TYPE_USHORT:
47 ap->a.a_ushort = va_arg (args, /*unsigned short*/ int);
48 break;
49 case TYPE_INT:
50 ap->a.a_int = va_arg (args, int);
51 break;
52 case TYPE_UINT:
53 ap->a.a_uint = va_arg (args, unsigned int);
54 break;
55 case TYPE_LONGINT:
56 ap->a.a_longint = va_arg (args, long int);
57 break;
58 case TYPE_ULONGINT:
59 ap->a.a_ulongint = va_arg (args, unsigned long int);
60 break;
61 #ifdef HAVE_LONG_LONG
62 case TYPE_LONGLONGINT:
63 ap->a.a_longlongint = va_arg (args, long long int);
64 break;
65 case TYPE_ULONGLONGINT:
66 ap->a.a_ulonglongint = va_arg (args, unsigned long long int);
67 break;
68 #endif
69 case TYPE_DOUBLE:
70 ap->a.a_double = va_arg (args, double);
71 break;
72 #ifdef HAVE_LONG_DOUBLE
73 case TYPE_LONGDOUBLE:
74 ap->a.a_longdouble = va_arg (args, long double);
75 break;
76 #endif
77 case TYPE_CHAR:
78 ap->a.a_char = va_arg (args, int);
79 break;
80 #ifdef HAVE_WINT_T
81 case TYPE_WIDE_CHAR:
82 ap->a.a_wide_char = va_arg (args, wint_t);
83 break;
84 #endif
85 case TYPE_STRING:
86 ap->a.a_string = va_arg (args, const char *);
87 break;
88 #ifdef HAVE_WCHAR_T
89 case TYPE_WIDE_STRING:
90 ap->a.a_wide_string = va_arg (args, const wchar_t *);
91 break;
92 #endif
93 case TYPE_POINTER:
94 ap->a.a_pointer = va_arg (args, void *);
95 break;
96 case TYPE_COUNT_SCHAR_POINTER:
97 ap->a.a_count_schar_pointer = va_arg (args, signed char *);
98 break;
99 case TYPE_COUNT_SHORT_POINTER:
100 ap->a.a_count_short_pointer = va_arg (args, short *);
101 break;
102 case TYPE_COUNT_INT_POINTER:
103 ap->a.a_count_int_pointer = va_arg (args, int *);
104 break;
105 case TYPE_COUNT_LONGINT_POINTER:
106 ap->a.a_count_longint_pointer = va_arg (args, long int *);
107 break;
108 #ifdef HAVE_LONG_LONG
109 case TYPE_COUNT_LONGLONGINT_POINTER:
110 ap->a.a_count_longlongint_pointer = va_arg (args, long long int *);
111 break;
112 #endif
113 default:
114 /* Unknown type. */
115 return -1;
116 }
117 return 0;
118 }
1 /* Decomposed printf argument list.
2 Copyright (C) 1999, 2002-2003 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17
18 #ifndef _PRINTF_ARGS_H
19 #define _PRINTF_ARGS_H
20
21 /* Get size_t. */
22 #include <stddef.h>
23
24 /* Get wchar_t. */
25 #ifdef HAVE_WCHAR_T
26 # include <stddef.h>
27 #endif
28
29 /* Get wint_t. */
30 #ifdef HAVE_WINT_T
31 # include <wchar.h>
32 #endif
33
34 /* Get va_list. */
35 #include <stdarg.h>
36
37
38 /* Argument types */
39 typedef enum
40 {
41 TYPE_NONE,
42 TYPE_SCHAR,
43 TYPE_UCHAR,
44 TYPE_SHORT,
45 TYPE_USHORT,
46 TYPE_INT,
47 TYPE_UINT,
48 TYPE_LONGINT,
49 TYPE_ULONGINT,
50 #ifdef HAVE_LONG_LONG
51 TYPE_LONGLONGINT,
52 TYPE_ULONGLONGINT,
53 #endif
54 TYPE_DOUBLE,
55 #ifdef HAVE_LONG_DOUBLE
56 TYPE_LONGDOUBLE,
57 #endif
58 TYPE_CHAR,
59 #ifdef HAVE_WINT_T
60 TYPE_WIDE_CHAR,
61 #endif
62 TYPE_STRING,
63 #ifdef HAVE_WCHAR_T
64 TYPE_WIDE_STRING,
65 #endif
66 TYPE_POINTER,
67 TYPE_COUNT_SCHAR_POINTER,
68 TYPE_COUNT_SHORT_POINTER,
69 TYPE_COUNT_INT_POINTER,
70 TYPE_COUNT_LONGINT_POINTER
71 #ifdef HAVE_LONG_LONG
72 , TYPE_COUNT_LONGLONGINT_POINTER
73 #endif
74 } arg_type;
75
76 /* Polymorphic argument */
77 typedef struct
78 {
79 arg_type type;
80 union
81 {
82 signed char a_schar;
83 unsigned char a_uchar;
84 short a_short;
85 unsigned short a_ushort;
86 int a_int;
87 unsigned int a_uint;
88 long int a_longint;
89 unsigned long int a_ulongint;
90 #ifdef HAVE_LONG_LONG
91 long long int a_longlongint;
92 unsigned long long int a_ulonglongint;
93 #endif
94 float a_float;
95 double a_double;
96 #ifdef HAVE_LONG_DOUBLE
97 long double a_longdouble;
98 #endif
99 int a_char;
100 #ifdef HAVE_WINT_T
101 wint_t a_wide_char;
102 #endif
103 const char* a_string;
104 #ifdef HAVE_WCHAR_T
105 const wchar_t* a_wide_string;
106 #endif
107 void* a_pointer;
108 signed char * a_count_schar_pointer;
109 short * a_count_short_pointer;
110 int * a_count_int_pointer;
111 long int * a_count_longint_pointer;
112 #ifdef HAVE_LONG_LONG
113 long long int * a_count_longlongint_pointer;
114 #endif
115 }
116 a;
117 }
118 argument;
119
120 typedef struct
121 {
122 size_t count;
123 argument *arg;
124 }
125 arguments;
126
127
128 /* Fetch the arguments, putting them into a. */
129 #ifdef STATIC
130 STATIC
131 #else
132 extern
133 #endif
134 int printf_fetchargs (va_list args, arguments *a);
135
136 #endif /* _PRINTF_ARGS_H */
1 /* Formatted output to strings.
2 Copyright (C) 1999-2000, 2002-2003 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21
22 /* Specification. */
23 #if WIDE_CHAR_VERSION
24 # include "wprintf-parse.h"
25 #else
26 # include "printf-parse.h"
27 #endif
28
29 /* Get size_t, NULL. */
30 #include <stddef.h>
31
32 /* Get intmax_t. */
33 #if HAVE_STDINT_H_WITH_UINTMAX
34 # include <stdint.h>
35 #endif
36 #if HAVE_INTTYPES_H_WITH_UINTMAX
37 # include <inttypes.h>
38 #endif
39
40 /* malloc(), realloc(), free(). */
41 #include <stdlib.h>
42
43 /* Checked size_t computations. */
44 #include "xsize.h"
45
46 #if WIDE_CHAR_VERSION
47 # define PRINTF_PARSE wprintf_parse
48 # define CHAR_T wchar_t
49 # define DIRECTIVE wchar_t_directive
50 # define DIRECTIVES wchar_t_directives
51 #else
52 # define PRINTF_PARSE printf_parse
53 # define CHAR_T char
54 # define DIRECTIVE char_directive
55 # define DIRECTIVES char_directives
56 #endif
57
58 #ifdef STATIC
59 STATIC
60 #endif
61 int
62 PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
63 {
64 const CHAR_T *cp = format; /* pointer into format */
65 size_t arg_posn = 0; /* number of regular arguments consumed */
66 size_t d_allocated; /* allocated elements of d->dir */
67 size_t a_allocated; /* allocated elements of a->arg */
68 size_t max_width_length = 0;
69 size_t max_precision_length = 0;
70
71 d->count = 0;
72 d_allocated = 1;
73 d->dir = malloc (d_allocated * sizeof (DIRECTIVE));
74 if (d->dir == NULL)
75 /* Out of memory. */
76 return -1;
77
78 a->count = 0;
79 a_allocated = 0;
80 a->arg = NULL;
81
82 #define REGISTER_ARG(_index_,_type_) \
83 { \
84 size_t n = (_index_); \
85 if (n >= a_allocated) \
86 { \
87 size_t memory_size; \
88 argument *memory; \
89 \
90 a_allocated = xtimes (a_allocated, 2); \
91 if (a_allocated <= n) \
92 a_allocated = xsum (n, 1); \
93 memory_size = xtimes (a_allocated, sizeof (argument)); \
94 if (size_overflow_p (memory_size)) \
95 /* Overflow, would lead to out of memory. */ \
96 goto error; \
97 memory = (a->arg \
98 ? realloc (a->arg, memory_size) \
99 : malloc (memory_size)); \
100 if (memory == NULL) \
101 /* Out of memory. */ \
102 goto error; \
103 a->arg = memory; \
104 } \
105 while (a->count <= n) \
106 a->arg[a->count++].type = TYPE_NONE; \
107 if (a->arg[n].type == TYPE_NONE) \
108 a->arg[n].type = (_type_); \
109 else if (a->arg[n].type != (_type_)) \
110 /* Ambiguous type for positional argument. */ \
111 goto error; \
112 }
113
114 while (*cp != '\0')
115 {
116 CHAR_T c = *cp++;
117 if (c == '%')
118 {
119 size_t arg_index = ARG_NONE;
120 DIRECTIVE *dp = &d->dir[d->count];/* pointer to next directive */
121
122 /* Initialize the next directive. */
123 dp->dir_start = cp - 1;
124 dp->flags = 0;
125 dp->width_start = NULL;
126 dp->width_end = NULL;
127 dp->width_arg_index = ARG_NONE;
128 dp->precision_start = NULL;
129 dp->precision_end = NULL;
130 dp->precision_arg_index = ARG_NONE;
131 dp->arg_index = ARG_NONE;
132
133 /* Test for positional argument. */
134 if (*cp >= '0' && *cp <= '9')
135 {
136 const CHAR_T *np;
137
138 for (np = cp; *np >= '0' && *np <= '9'; np++)
139 ;
140 if (*np == '$')
141 {
142 size_t n = 0;
143
144 for (np = cp; *np >= '0' && *np <= '9'; np++)
145 n = xsum (xtimes (n, 10), *np - '0');
146 if (n == 0)
147 /* Positional argument 0. */
148 goto error;
149 if (size_overflow_p (n))
150 /* n too large, would lead to out of memory later. */
151 goto error;
152 arg_index = n - 1;
153 cp = np + 1;
154 }
155 }
156
157 /* Read the flags. */
158 for (;;)
159 {
160 if (*cp == '\'')
161 {
162 dp->flags |= FLAG_GROUP;
163 cp++;
164 }
165 else if (*cp == '-')
166 {
167 dp->flags |= FLAG_LEFT;
168 cp++;
169 }
170 else if (*cp == '+')
171 {
172 dp->flags |= FLAG_SHOWSIGN;
173 cp++;
174 }
175 else if (*cp == ' ')
176 {
177 dp->flags |= FLAG_SPACE;
178 cp++;
179 }
180 else if (*cp == '#')
181 {
182 dp->flags |= FLAG_ALT;
183 cp++;
184 }
185 else if (*cp == '0')
186 {
187 dp->flags |= FLAG_ZERO;
188 cp++;
189 }
190 else
191 break;
192 }
193
194 /* Parse the field width. */
195 if (*cp == '*')
196 {
197 dp->width_start = cp;
198 cp++;
199 dp->width_end = cp;
200 if (max_width_length < 1)
201 max_width_length = 1;
202
203 /* Test for positional argument. */
204 if (*cp >= '0' && *cp <= '9')
205 {
206 const CHAR_T *np;
207
208 for (np = cp; *np >= '0' && *np <= '9'; np++)
209 ;
210 if (*np == '$')
211 {
212 size_t n = 0;
213
214 for (np = cp; *np >= '0' && *np <= '9'; np++)
215 n = xsum (xtimes (n, 10), *np - '0');
216 if (n == 0)
217 /* Positional argument 0. */
218 goto error;
219 if (size_overflow_p (n))
220 /* n too large, would lead to out of memory later. */
221 goto error;
222 dp->width_arg_index = n - 1;
223 cp = np + 1;
224 }
225 }
226 if (dp->width_arg_index == ARG_NONE)
227 {
228 dp->width_arg_index = arg_posn++;
229 if (dp->width_arg_index == ARG_NONE)
230 /* arg_posn wrapped around. */
231 goto error;
232 }
233 REGISTER_ARG (dp->width_arg_index, TYPE_INT);
234 }
235 else if (*cp >= '0' && *cp <= '9')
236 {
237 size_t width_length;
238
239 dp->width_start = cp;
240 for (; *cp >= '0' && *cp <= '9'; cp++)
241 ;
242 dp->width_end = cp;
243 width_length = dp->width_end - dp->width_start;
244 if (max_width_length < width_length)
245 max_width_length = width_length;
246 }
247
248 /* Parse the precision. */
249 if (*cp == '.')
250 {
251 cp++;
252 if (*cp == '*')
253 {
254 dp->precision_start = cp - 1;
255 cp++;
256 dp->precision_end = cp;
257 if (max_precision_length < 2)
258 max_precision_length = 2;
259
260 /* Test for positional argument. */
261 if (*cp >= '0' && *cp <= '9')
262 {
263 const CHAR_T *np;
264
265 for (np = cp; *np >= '0' && *np <= '9'; np++)
266 ;
267 if (*np == '$')
268 {
269 size_t n = 0;
270
271 for (np = cp; *np >= '0' && *np <= '9'; np++)
272 n = xsum (xtimes (n, 10), *np - '0');
273 if (n == 0)
274 /* Positional argument 0. */
275 goto error;
276 if (size_overflow_p (n))
277 /* n too large, would lead to out of memory
278 later. */
279 goto error;
280 dp->precision_arg_index = n - 1;
281 cp = np + 1;
282 }
283 }
284 if (dp->precision_arg_index == ARG_NONE)
285 {
286 dp->precision_arg_index = arg_posn++;
287 if (dp->precision_arg_index == ARG_NONE)
288 /* arg_posn wrapped around. */
289 goto error;
290 }
291 REGISTER_ARG (dp->precision_arg_index, TYPE_INT);
292 }
293 else
294 {
295 size_t precision_length;
296
297 dp->precision_start = cp - 1;
298 for (; *cp >= '0' && *cp <= '9'; cp++)
299 ;
300 dp->precision_end = cp;
301 precision_length = dp->precision_end - dp->precision_start;
302 if (max_precision_length < precision_length)
303 max_precision_length = precision_length;
304 }
305 }
306
307 {
308 arg_type type;
309
310 /* Parse argument type/size specifiers. */
311 {
312 int flags = 0;
313
314 for (;;)
315 {
316 if (*cp == 'h')
317 {
318 flags |= (1 << (flags & 1));
319 cp++;
320 }
321 else if (*cp == 'L')
322 {
323 flags |= 4;
324 cp++;
325 }
326 else if (*cp == 'l')
327 {
328 flags += 8;
329 cp++;
330 }
331 #ifdef HAVE_INTMAX_T
332 else if (*cp == 'j')
333 {
334 if (sizeof (intmax_t) > sizeof (long))
335 {
336 /* intmax_t = long long */
337 flags += 16;
338 }
339 else if (sizeof (intmax_t) > sizeof (int))
340 {
341 /* intmax_t = long */
342 flags += 8;
343 }
344 cp++;
345 }
346 #endif
347 else if (*cp == 'z' || *cp == 'Z')
348 {
349 /* 'z' is standardized in ISO C 99, but glibc uses 'Z'
350 because the warning facility in gcc-2.95.2 understands
351 only 'Z' (see gcc-2.95.2/gcc/c-common.c:1784). */
352 if (sizeof (size_t) > sizeof (long))
353 {
354 /* size_t = long long */
355 flags += 16;
356 }
357 else if (sizeof (size_t) > sizeof (int))
358 {
359 /* size_t = long */
360 flags += 8;
361 }
362 cp++;
363 }
364 else if (*cp == 't')
365 {
366 if (sizeof (ptrdiff_t) > sizeof (long))
367 {
368 /* ptrdiff_t = long long */
369 flags += 16;
370 }
371 else if (sizeof (ptrdiff_t) > sizeof (int))
372 {
373 /* ptrdiff_t = long */
374 flags += 8;
375 }
376 cp++;
377 }
378 else
379 break;
380 }
381
382 /* Read the conversion character. */
383 c = *cp++;
384 switch (c)
385 {
386 case 'd': case 'i':
387 #ifdef HAVE_LONG_LONG
388 if (flags >= 16 || (flags & 4))
389 type = TYPE_LONGLONGINT;
390 else
391 #endif
392 if (flags >= 8)
393 type = TYPE_LONGINT;
394 else if (flags & 2)
395 type = TYPE_SCHAR;
396 else if (flags & 1)
397 type = TYPE_SHORT;
398 else
399 type = TYPE_INT;
400 break;
401 case 'o': case 'u': case 'x': case 'X':
402 #ifdef HAVE_LONG_LONG
403 if (flags >= 16 || (flags & 4))
404 type = TYPE_ULONGLONGINT;
405 else
406 #endif
407 if (flags >= 8)
408 type = TYPE_ULONGINT;
409 else if (flags & 2)
410 type = TYPE_UCHAR;
411 else if (flags & 1)
412 type = TYPE_USHORT;
413 else
414 type = TYPE_UINT;
415 break;
416 case 'f': case 'F': case 'e': case 'E': case 'g': case 'G':
417 case 'a': case 'A':
418 #ifdef HAVE_LONG_DOUBLE
419 if (flags >= 16 || (flags & 4))
420 type = TYPE_LONGDOUBLE;
421 else
422 #endif
423 type = TYPE_DOUBLE;
424 break;
425 case 'c':
426 if (flags >= 8)
427 #ifdef HAVE_WINT_T
428 type = TYPE_WIDE_CHAR;
429 #else
430 goto error;
431 #endif
432 else
433 type = TYPE_CHAR;
434 break;
435 #ifdef HAVE_WINT_T
436 case 'C':
437 type = TYPE_WIDE_CHAR;
438 c = 'c';
439 break;
440 #endif
441 case 's':
442 if (flags >= 8)
443 #ifdef HAVE_WCHAR_T
444 type = TYPE_WIDE_STRING;
445 #else
446 goto error;
447 #endif
448 else
449 type = TYPE_STRING;
450 break;
451 #ifdef HAVE_WCHAR_T
452 case 'S':
453 type = TYPE_WIDE_STRING;
454 c = 's';
455 break;
456 #endif
457 case 'p':
458 type = TYPE_POINTER;
459 break;
460 case 'n':
461 #ifdef HAVE_LONG_LONG
462 if (flags >= 16 || (flags & 4))
463 type = TYPE_COUNT_LONGLONGINT_POINTER;
464 else
465 #endif
466 if (flags >= 8)
467 type = TYPE_COUNT_LONGINT_POINTER;
468 else if (flags & 2)
469 type = TYPE_COUNT_SCHAR_POINTER;
470 else if (flags & 1)
471 type = TYPE_COUNT_SHORT_POINTER;
472 else
473 type = TYPE_COUNT_INT_POINTER;
474 break;
475 case '%':
476 type = TYPE_NONE;
477 break;
478 default:
479 /* Unknown conversion character. */
480 goto error;
481 }
482 }
483
484 if (type != TYPE_NONE)
485 {
486 dp->arg_index = arg_index;
487 if (dp->arg_index == ARG_NONE)
488 {
489 dp->arg_index = arg_posn++;
490 if (dp->arg_index == ARG_NONE)
491 /* arg_posn wrapped around. */
492 goto error;
493 }
494 REGISTER_ARG (dp->arg_index, type);
495 }
496 dp->conversion = c;
497 dp->dir_end = cp;
498 }
499
500 d->count++;
501 if (d->count >= d_allocated)
502 {
503 size_t memory_size;
504 DIRECTIVE *memory;
505
506 d_allocated = xtimes (d_allocated, 2);
507 memory_size = xtimes (d_allocated, sizeof (DIRECTIVE));
508 if (size_overflow_p (memory_size))
509 /* Overflow, would lead to out of memory. */
510 goto error;
511 memory = realloc (d->dir, memory_size);
512 if (memory == NULL)
513 /* Out of memory. */
514 goto error;
515 d->dir = memory;
516 }
517 }
518 }
519 d->dir[d->count].dir_start = cp;
520
521 d->max_width_length = max_width_length;
522 d->max_precision_length = max_precision_length;
523 return 0;
524
525 error:
526 if (a->arg)
527 free (a->arg);
528 if (d->dir)
529 free (d->dir);
530 return -1;
531 }
532
533 #undef DIRECTIVES
534 #undef DIRECTIVE
535 #undef CHAR_T
536 #undef PRINTF_PARSE
1 /* Parse printf format string.
2 Copyright (C) 1999, 2002-2003 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17
18 #ifndef _PRINTF_PARSE_H
19 #define _PRINTF_PARSE_H
20
21 #include "printf-args.h"
22
23
24 /* Flags */
25 #define FLAG_GROUP 1 /* ' flag */
26 #define FLAG_LEFT 2 /* - flag */
27 #define FLAG_SHOWSIGN 4 /* + flag */
28 #define FLAG_SPACE 8 /* space flag */
29 #define FLAG_ALT 16 /* # flag */
30 #define FLAG_ZERO 32
31
32 /* arg_index value indicating that no argument is consumed. */
33 #define ARG_NONE (~(size_t)0)
34
35 /* A parsed directive. */
36 typedef struct
37 {
38 const char* dir_start;
39 const char* dir_end;
40 int flags;
41 const char* width_start;
42 const char* width_end;
43 size_t width_arg_index;
44 const char* precision_start;
45 const char* precision_end;
46 size_t precision_arg_index;
47 char conversion; /* d i o u x X f e E g G c s p n U % but not C S */
48 size_t arg_index;
49 }
50 char_directive;
51
52 /* A parsed format string. */
53 typedef struct
54 {
55 size_t count;
56 char_directive *dir;
57 size_t max_width_length;
58 size_t max_precision_length;
59 }
60 char_directives;
61
62
63 /* Parses the format string. Fills in the number N of directives, and fills
64 in directives[0], ..., directives[N-1], and sets directives[N].dir_start
65 to the end of the format string. Also fills in the arg_type fields of the
66 arguments and the needed count of arguments. */
67 #ifdef STATIC
68 STATIC
69 #else
70 extern
71 #endif
72 int printf_parse (const char *format, char_directives *d, arguments *a);
73
74 #endif /* _PRINTF_PARSE_H */
1 /* Definitions for data structures and routines for the regular
2 expression library.
3 Copyright (C) 1985,1989-93,1995-98,2000,2001,2002,2003
4 Free Software Foundation, Inc.
5 This file is part of the GNU C Library.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation,
19 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
21 #ifndef _REGEX_H
22 #define _REGEX_H 1
23
24 #include <sys/types.h>
25
26 /* Allow the use in C++ code. */
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 /* POSIX says that <sys/types.h> must be included (by the caller) before
32 <regex.h>. */
33
34 #if !defined _POSIX_C_SOURCE && !defined _POSIX_SOURCE && defined VMS
35 /* VMS doesn't have `size_t' in <sys/types.h>, even though POSIX says it
36 should be there. */
37 # include <stddef.h>
38 #endif
39
40 /* The following two types have to be signed and unsigned integer type
41 wide enough to hold a value of a pointer. For most ANSI compilers
42 ptrdiff_t and size_t should be likely OK. Still size of these two
43 types is 2 for Microsoft C. Ugh... */
44 typedef long int s_reg_t;
45 typedef unsigned long int active_reg_t;
46
47 /* The following bits are used to determine the regexp syntax we
48 recognize. The set/not-set meanings are chosen so that Emacs syntax
49 remains the value 0. The bits are given in alphabetical order, and
50 the definitions shifted by one from the previous bit; thus, when we
51 add or remove a bit, only one other definition need change. */
52 typedef unsigned long int reg_syntax_t;
53
54 /* If this bit is not set, then \ inside a bracket expression is literal.
55 If set, then such a \ quotes the following character. */
56 #define RE_BACKSLASH_ESCAPE_IN_LISTS ((unsigned long int) 1)
57
58 /* If this bit is not set, then + and ? are operators, and \+ and \? are
59 literals.
60 If set, then \+ and \? are operators and + and ? are literals. */
61 #define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1)
62
63 /* If this bit is set, then character classes are supported. They are:
64 [:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:],
65 [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:].
66 If not set, then character classes are not supported. */
67 #define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1)
68
69 /* If this bit is set, then ^ and $ are always anchors (outside bracket
70 expressions, of course).
71 If this bit is not set, then it depends:
72 ^ is an anchor if it is at the beginning of a regular
73 expression or after an open-group or an alternation operator;
74 $ is an anchor if it is at the end of a regular expression, or
75 before a close-group or an alternation operator.
76
77 This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because
78 POSIX draft 11.2 says that * etc. in leading positions is undefined.
79 We already implemented a previous draft which made those constructs
80 invalid, though, so we haven't changed the code back. */
81 #define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1)
82
83 /* If this bit is set, then special characters are always special
84 regardless of where they are in the pattern.
85 If this bit is not set, then special characters are special only in
86 some contexts; otherwise they are ordinary. Specifically,
87 * + ? and intervals are only special when not after the beginning,
88 open-group, or alternation operator. */
89 #define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1)
90
91 /* If this bit is set, then *, +, ?, and { cannot be first in an re or
92 immediately after an alternation or begin-group operator. */
93 #define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1)
94
95 /* If this bit is set, then . matches newline.
96 If not set, then it doesn't. */
97 #define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1)
98
99 /* If this bit is set, then . doesn't match NUL.
100 If not set, then it does. */
101 #define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1)
102
103 /* If this bit is set, nonmatching lists [^...] do not match newline.
104 If not set, they do. */
105 #define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1)
106
107 /* If this bit is set, either \{...\} or {...} defines an
108 interval, depending on RE_NO_BK_BRACES.
109 If not set, \{, \}, {, and } are literals. */
110 #define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1)
111
112 /* If this bit is set, +, ? and | aren't recognized as operators.
113 If not set, they are. */
114 #define RE_LIMITED_OPS (RE_INTERVALS << 1)
115
116 /* If this bit is set, newline is an alternation operator.
117 If not set, newline is literal. */
118 #define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1)
119
120 /* If this bit is set, then `{...}' defines an interval, and \{ and \}
121 are literals.
122 If not set, then `\{...\}' defines an interval. */
123 #define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1)
124
125 /* If this bit is set, (...) defines a group, and \( and \) are literals.
126 If not set, \(...\) defines a group, and ( and ) are literals. */
127 #define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1)
128
129 /* If this bit is set, then \<digit> matches <digit>.
130 If not set, then \<digit> is a back-reference. */
131 #define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1)
132
133 /* If this bit is set, then | is an alternation operator, and \| is literal.
134 If not set, then \| is an alternation operator, and | is literal. */
135 #define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1)
136
137 /* If this bit is set, then an ending range point collating higher
138 than the starting range point, as in [z-a], is invalid.
139 If not set, then when ending range point collates higher than the
140 starting range point, the range is ignored. */
141 #define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1)
142
143 /* If this bit is set, then an unmatched ) is ordinary.
144 If not set, then an unmatched ) is invalid. */
145 #define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1)
146
147 /* If this bit is set, succeed as soon as we match the whole pattern,
148 without further backtracking. */
149 #define RE_NO_POSIX_BACKTRACKING (RE_UNMATCHED_RIGHT_PAREN_ORD << 1)
150
151 /* If this bit is set, do not process the GNU regex operators.
152 If not set, then the GNU regex operators are recognized. */
153 #define RE_NO_GNU_OPS (RE_NO_POSIX_BACKTRACKING << 1)
154
155 /* If this bit is set, turn on internal regex debugging.
156 If not set, and debugging was on, turn it off.
157 This only works if regex.c is compiled -DDEBUG.
158 We define this bit always, so that all that's needed to turn on
159 debugging is to recompile regex.c; the calling code can always have
160 this bit set, and it won't affect anything in the normal case. */
161 #define RE_DEBUG (RE_NO_GNU_OPS << 1)
162
163 /* If this bit is set, a syntactically invalid interval is treated as
164 a string of ordinary characters. For example, the ERE 'a{1' is
165 treated as 'a\{1'. */
166 #define RE_INVALID_INTERVAL_ORD (RE_DEBUG << 1)
167
168 /* If this bit is set, then ignore case when matching.
169 If not set, then case is significant. */
170 #define RE_ICASE (RE_INVALID_INTERVAL_ORD << 1)
171
172 /* This global variable defines the particular regexp syntax to use (for
173 some interfaces). When a regexp is compiled, the syntax used is
174 stored in the pattern buffer, so changing this does not affect
175 already-compiled regexps. */
176 extern reg_syntax_t re_syntax_options;
177
178 /* Define combinations of the above bits for the standard possibilities.
179 (The [[[ comments delimit what gets put into the Texinfo file, so
180 don't delete them!) */
181 /* [[[begin syntaxes]]] */
182 #define RE_SYNTAX_EMACS 0
183
184 #define RE_SYNTAX_AWK \
185 (RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL \
186 | RE_NO_BK_PARENS | RE_NO_BK_REFS \
187 | RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES \
188 | RE_DOT_NEWLINE | RE_CONTEXT_INDEP_ANCHORS \
189 | RE_UNMATCHED_RIGHT_PAREN_ORD | RE_NO_GNU_OPS)
190
191 #define RE_SYNTAX_GNU_AWK \
192 ((RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DEBUG) \
193 & ~(RE_DOT_NOT_NULL | RE_INTERVALS | RE_CONTEXT_INDEP_OPS \
194 | RE_CONTEXT_INVALID_OPS ))
195
196 #define RE_SYNTAX_POSIX_AWK \
197 (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS \
198 | RE_INTERVALS | RE_NO_GNU_OPS)
199
200 #define RE_SYNTAX_GREP \
201 (RE_BK_PLUS_QM | RE_CHAR_CLASSES \
202 | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS \
203 | RE_NEWLINE_ALT)
204
205 #define RE_SYNTAX_EGREP \
206 (RE_CHAR_CLASSES | RE_CONTEXT_INDEP_ANCHORS \
207 | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE \
208 | RE_NEWLINE_ALT | RE_NO_BK_PARENS \
209 | RE_NO_BK_VBAR)
210
211 #define RE_SYNTAX_POSIX_EGREP \
212 (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES \
213 | RE_INVALID_INTERVAL_ORD)
214
215 /* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */
216 #define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC
217
218 #define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC
219
220 /* Syntax bits common to both basic and extended POSIX regex syntax. */
221 #define _RE_SYNTAX_POSIX_COMMON \
222 (RE_CHAR_CLASSES | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \
223 | RE_INTERVALS | RE_NO_EMPTY_RANGES)
224
225 #define RE_SYNTAX_POSIX_BASIC \
226 (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM)
227
228 /* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes
229 RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this
230 isn't minimal, since other operators, such as \`, aren't disabled. */
231 #define RE_SYNTAX_POSIX_MINIMAL_BASIC \
232 (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS)
233
234 #define RE_SYNTAX_POSIX_EXTENDED \
235 (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \
236 | RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES \
237 | RE_NO_BK_PARENS | RE_NO_BK_VBAR \
238 | RE_CONTEXT_INVALID_OPS | RE_UNMATCHED_RIGHT_PAREN_ORD)
239
240 /* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INDEP_OPS is
241 removed and RE_NO_BK_REFS is added. */
242 #define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \
243 (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \
244 | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \
245 | RE_NO_BK_PARENS | RE_NO_BK_REFS \
246 | RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD)
247 /* [[[end syntaxes]]] */
248
249 /* Maximum number of duplicates an interval can allow. Some systems
250 (erroneously) define this in other header files, but we want our
251 value, so remove any previous define. */
252 #ifdef RE_DUP_MAX
253 # undef RE_DUP_MAX
254 #endif
255 /* If sizeof(int) == 2, then ((1 << 15) - 1) overflows. */
256 #define RE_DUP_MAX (0x7fff)
257
258
259 /* POSIX `cflags' bits (i.e., information for `regcomp'). */
260
261 /* If this bit is set, then use extended regular expression syntax.
262 If not set, then use basic regular expression syntax. */
263 #define REG_EXTENDED 1
264
265 /* If this bit is set, then ignore case when matching.
266 If not set, then case is significant. */
267 #define REG_ICASE (REG_EXTENDED << 1)
268
269 /* If this bit is set, then anchors do not match at newline
270 characters in the string.
271 If not set, then anchors do match at newlines. */
272 #define REG_NEWLINE (REG_ICASE << 1)
273
274 /* If this bit is set, then report only success or fail in regexec.
275 If not set, then returns differ between not matching and errors. */
276 #define REG_NOSUB (REG_NEWLINE << 1)
277
278
279 /* POSIX `eflags' bits (i.e., information for regexec). */
280
281 /* If this bit is set, then the beginning-of-line operator doesn't match
282 the beginning of the string (presumably because it's not the
283 beginning of a line).
284 If not set, then the beginning-of-line operator does match the
285 beginning of the string. */
286 #define REG_NOTBOL 1
287
288 /* Like REG_NOTBOL, except for the end-of-line. */
289 #define REG_NOTEOL (1 << 1)
290
291
292 /* If any error codes are removed, changed, or added, update the
293 `re_error_msg' table in regex.c. */
294 typedef enum
295 {
296 #ifdef _XOPEN_SOURCE
297 REG_ENOSYS = -1, /* This will never happen for this implementation. */
298 #endif
299
300 REG_NOERROR = 0, /* Success. */
301 REG_NOMATCH, /* Didn't find a match (for regexec). */
302
303 /* POSIX regcomp return error codes. (In the order listed in the
304 standard.) */
305 REG_BADPAT, /* Invalid pattern. */
306 REG_ECOLLATE, /* Not implemented. */
307 REG_ECTYPE, /* Invalid character class name. */
308 REG_EESCAPE, /* Trailing backslash. */
309 REG_ESUBREG, /* Invalid back reference. */
310 REG_EBRACK, /* Unmatched left bracket. */
311 REG_EPAREN, /* Parenthesis imbalance. */
312 REG_EBRACE, /* Unmatched \{. */
313 REG_BADBR, /* Invalid contents of \{\}. */
314 REG_ERANGE, /* Invalid range end. */
315 REG_ESPACE, /* Ran out of memory. */
316 REG_BADRPT, /* No preceding re for repetition op. */
317
318 /* Error codes we've added. */
319 REG_EEND, /* Premature end. */
320 REG_ESIZE, /* Compiled pattern bigger than 2^16 bytes. */
321 REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */
322 } reg_errcode_t;
323
324 /* This data structure represents a compiled pattern. Before calling
325 the pattern compiler, the fields `buffer', `allocated', `fastmap',
326 `translate', and `no_sub' can be set. After the pattern has been
327 compiled, the `re_nsub' field is available. All other fields are
328 private to the regex routines. */
329
330 #ifndef RE_TRANSLATE_TYPE
331 # define RE_TRANSLATE_TYPE char *
332 #endif
333
334 struct re_pattern_buffer
335 {
336 /* [[[begin pattern_buffer]]] */
337 /* Space that holds the compiled pattern. It is declared as
338 `unsigned char *' because its elements are
339 sometimes used as array indexes. */
340 unsigned char *buffer;
341
342 /* Number of bytes to which `buffer' points. */
343 unsigned long int allocated;
344
345 /* Number of bytes actually used in `buffer'. */
346 unsigned long int used;
347
348 /* Syntax setting with which the pattern was compiled. */
349 reg_syntax_t syntax;
350
351 /* Pointer to a fastmap, if any, otherwise zero. re_search uses
352 the fastmap, if there is one, to skip over impossible
353 starting points for matches. */
354 char *fastmap;
355
356 /* Either a translate table to apply to all characters before
357 comparing them, or zero for no translation. The translation
358 is applied to a pattern when it is compiled and to a string
359 when it is matched. */
360 RE_TRANSLATE_TYPE translate;
361
362 /* Number of subexpressions found by the compiler. */
363 size_t re_nsub;
364
365 /* Zero if this pattern cannot match the empty string, one else.
366 Well, in truth it's used only in `re_search_2', to see
367 whether or not we should use the fastmap, so we don't set
368 this absolutely perfectly; see `re_compile_fastmap' (the
369 `duplicate' case). */
370 unsigned can_be_null : 1;
371
372 /* If REGS_UNALLOCATED, allocate space in the `regs' structure
373 for `max (RE_NREGS, re_nsub + 1)' groups.
374 If REGS_REALLOCATE, reallocate space if necessary.
375 If REGS_FIXED, use what's there. */
376 #define REGS_UNALLOCATED 0
377 #define REGS_REALLOCATE 1
378 #define REGS_FIXED 2
379 unsigned regs_allocated : 2;
380
381 /* Set to zero when `regex_compile' compiles a pattern; set to one
382 by `re_compile_fastmap' if it updates the fastmap. */
383 unsigned fastmap_accurate : 1;
384
385 /* If set, `re_match_2' does not return information about
386 subexpressions. */
387 unsigned no_sub : 1;
388
389 /* If set, a beginning-of-line anchor doesn't match at the
390 beginning of the string. */
391 unsigned not_bol : 1;
392
393 /* Similarly for an end-of-line anchor. */
394 unsigned not_eol : 1;
395
396 /* If true, an anchor at a newline matches. */
397 unsigned newline_anchor : 1;
398
399 /* [[[end pattern_buffer]]] */
400 };
401
402 typedef struct re_pattern_buffer regex_t;
403
404 /* Type for byte offsets within the string. POSIX mandates this. */
405 typedef int regoff_t;
406
407
408 /* This is the structure we store register match data in. See
409 regex.texinfo for a full description of what registers match. */
410 struct re_registers
411 {
412 unsigned num_regs;
413 regoff_t *start;
414 regoff_t *end;
415 };
416
417
418 /* If `regs_allocated' is REGS_UNALLOCATED in the pattern buffer,
419 `re_match_2' returns information about at least this many registers
420 the first time a `regs' structure is passed. */
421 #ifndef RE_NREGS
422 # define RE_NREGS 30
423 #endif
424
425
426 /* POSIX specification for registers. Aside from the different names than
427 `re_registers', POSIX uses an array of structures, instead of a
428 structure of arrays. */
429 typedef struct
430 {
431 regoff_t rm_so; /* Byte offset from string's start to substring's start. */
432 regoff_t rm_eo; /* Byte offset from string's start to substring's end. */
433 } regmatch_t;
434
435 /* Declarations for routines. */
436
437 /* Sets the current default syntax to SYNTAX, and return the old syntax.
438 You can also simply assign to the `re_syntax_options' variable. */
439 extern reg_syntax_t re_set_syntax (reg_syntax_t syntax);
440
441 /* Compile the regular expression PATTERN, with length LENGTH
442 and syntax given by the global `re_syntax_options', into the buffer
443 BUFFER. Return NULL if successful, and an error string if not. */
444 extern const char *re_compile_pattern (const char *pattern, size_t length,
445 struct re_pattern_buffer *buffer);
446
447
448 /* Compile a fastmap for the compiled pattern in BUFFER; used to
449 accelerate searches. Return 0 if successful and -2 if was an
450 internal error. */
451 extern int re_compile_fastmap (struct re_pattern_buffer *buffer);
452
453
454 /* Search in the string STRING (with length LENGTH) for the pattern
455 compiled into BUFFER. Start searching at position START, for RANGE
456 characters. Return the starting position of the match, -1 for no
457 match, or -2 for an internal error. Also return register
458 information in REGS (if REGS and BUFFER->no_sub are nonzero). */
459 extern int re_search (struct re_pattern_buffer *buffer, const char *string,
460 int length, int start, int range,
461 struct re_registers *regs);
462
463
464 /* Like `re_search', but search in the concatenation of STRING1 and
465 STRING2. Also, stop searching at index START + STOP. */
466 extern int re_search_2 (struct re_pattern_buffer *buffer, const char *string1,
467 int length1, const char *string2, int length2,
468 int start, int range, struct re_registers *regs,
469 int stop);
470
471
472 /* Like `re_search', but return how many characters in STRING the regexp
473 in BUFFER matched, starting at position START. */
474 extern int re_match (struct re_pattern_buffer *buffer, const char *string,
475 int length, int start, struct re_registers *regs);
476
477
478 /* Relates to `re_match' as `re_search_2' relates to `re_search'. */
479 extern int re_match_2 (struct re_pattern_buffer *buffer, const char *string1,
480 int length1, const char *string2, int length2,
481 int start, struct re_registers *regs, int stop);
482
483
484 /* Set REGS to hold NUM_REGS registers, storing them in STARTS and
485 ENDS. Subsequent matches using BUFFER and REGS will use this memory
486 for recording register information. STARTS and ENDS must be
487 allocated with malloc, and must each be at least `NUM_REGS * sizeof
488 (regoff_t)' bytes long.
489
490 If NUM_REGS == 0, then subsequent matches should allocate their own
491 register data.
492
493 Unless this function is called, the first search or match using
494 PATTERN_BUFFER will allocate its own register data, without
495 freeing the old data. */
496 extern void re_set_registers (struct re_pattern_buffer *buffer,
497 struct re_registers *regs, unsigned num_regs,
498 regoff_t *starts, regoff_t *ends);
499
500 #if defined _REGEX_RE_COMP || defined _LIBC
501 # ifndef _CRAY
502 /* 4.2 bsd compatibility. */
503 extern char *re_comp (const char *);
504 extern int re_exec (const char *);
505 # endif
506 #endif
507
508 /* GCC 2.95 and later have "__restrict"; C99 compilers have
509 "restrict", and "configure" may have defined "restrict". */
510 #ifndef __restrict
511 # if ! (2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__))
512 # if defined restrict || 199901L <= __STDC_VERSION__
513 # define __restrict restrict
514 # else
515 # define __restrict
516 # endif
517 # endif
518 #endif
519 /* gcc 3.1 and up support the [restrict] syntax. */
520 #ifndef __restrict_arr
521 # if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
522 # define __restrict_arr __restrict
523 # else
524 # define __restrict_arr
525 # endif
526 #endif
527
528 /* POSIX compatibility. */
529 extern int regcomp (regex_t *__restrict __preg,
530 const char *__restrict __pattern,
531 int __cflags);
532
533 extern int regexec (const regex_t *__restrict __preg,
534 const char *__restrict __string, size_t __nmatch,
535 regmatch_t __pmatch[__restrict_arr],
536 int __eflags);
537
538 extern size_t regerror (int __errcode, const regex_t *__preg,
539 char *__errbuf, size_t __errbuf_size);
540
541 extern void regfree (regex_t *__preg);
542
543
544 #ifdef __cplusplus
545 }
546 #endif /* C++ */
547
548 #endif /* regex.h */
549
550 /*
551 Local variables:
552 make-backup-files: t
553 version-control: t
554 trim-versions-without-asking: nil
555 End:
556 */
1 /* Case-insensitive string comparison functions.
2 Copyright (C) 1995-1996, 2001, 2003 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17
18 #ifndef _STRCASE_H
19 #define _STRCASE_H
20
21 #include <stddef.h>
22
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28
29 /* Compare strings S1 and S2, ignoring case, returning less than, equal to or
30 greater than zero if S1 is lexicographically less than, equal to or greater
31 than S2.
32 Note: This function does not work correctly in multibyte locales. */
33 extern int strcasecmp (const char *s1, const char *s2);
34
35 /* Compare no more than N characters of strings S1 and S2, ignoring case,
36 returning less than, equal to or greater than zero if S1 is
37 lexicographically less than, equal to or greater than S2.
38 Note: This function can not work correctly in multibyte locales. */
39 extern int strncasecmp (const char *s1, const char *s2, size_t n);
40
41
42 #ifdef __cplusplus
43 }
44 #endif
45
46
47 #endif /* _STRCASE_H */
1 /* strcasecmp.c -- case insensitive string comparator
2 Copyright (C) 1998, 1999 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17
18 #if HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21
22 #ifdef LENGTH_LIMIT
23 # define STRXCASECMP_FUNCTION strncasecmp
24 # define STRXCASECMP_DECLARE_N , size_t n
25 # define LENGTH_LIMIT_EXPR(Expr) Expr
26 #else
27 # define STRXCASECMP_FUNCTION strcasecmp
28 # define STRXCASECMP_DECLARE_N /* empty */
29 # define LENGTH_LIMIT_EXPR(Expr) 0
30 #endif
31
32 #include <stddef.h>
33 #include <ctype.h>
34
35 #define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch))
36
37 /* Compare {{no more than N characters of }}strings S1 and S2,
38 ignoring case, returning less than, equal to or
39 greater than zero if S1 is lexicographically less
40 than, equal to or greater than S2. */
41
42 int
43 STRXCASECMP_FUNCTION (const char *s1, const char *s2 STRXCASECMP_DECLARE_N)
44 {
45 register const unsigned char *p1 = (const unsigned char *) s1;
46 register const unsigned char *p2 = (const unsigned char *) s2;
47 unsigned char c1, c2;
48
49 if (p1 == p2 || LENGTH_LIMIT_EXPR (n == 0))
50 return 0;
51
52 do
53 {
54 c1 = TOLOWER (*p1);
55 c2 = TOLOWER (*p2);
56
57 if (LENGTH_LIMIT_EXPR (--n == 0) || c1 == '\0')
58 break;
59
60 ++p1;
61 ++p2;
62 }
63 while (c1 == c2);
64
65 return c1 - c2;
66 }
1 /* Searching in a string.
2 Copyright (C) 2003 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17
18 #if HAVE_STRCHRNUL
19
20 /* Get strchrnul() declaration. */
21 #include <string.h>
22
23 #else
24
25 /* Find the first occurrence of C in S or the final NUL byte. */
26 extern char *strchrnul (const char *s, int c_in);
27
28 #endif
1 #define LENGTH_LIMIT
2 #include "strcasecmp.c"
1 /* Duplicate a size-bounded string.
2 Copyright (C) 2003 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17
18 #if HAVE_STRNDUP
19
20 /* Get strndup() declaration. */
21 #include <string.h>
22
23 #else
24
25 #include <stddef.h>
26
27 /* Return a newly allocated copy of at most N bytes of STRING. */
28 extern char *strndup (const char *string, size_t n);
29
30 #endif
1 /* Split string into tokens
2 Copyright (C) 2004 Free Software Foundation, Inc.
3 Written by Simon Josefsson.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation,
17 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18
19 #ifndef STRTOK_R_H
20 #define STRTOK_R_H
21
22 /* Get strtok_r declaration, if available. */
23 #include <string.h>
24
25 /* Parse S into tokens separated by characters in DELIM.
26 If S is NULL, the saved pointer in SAVE_PTR is used as
27 the next starting point. For example:
28 char s[] = "-abc-=-def";
29 char *sp;
30 x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def"
31 x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL
32 x = strtok_r(NULL, "=", &sp); // x = NULL
33 // s = "abc\0-def\0"
34
35 This is a variant of strtok() that is multithread-safe.
36
37 For the POSIX documentation for this function, see:
38 http://www.opengroup.org/onlinepubs/009695399/functions/strtok.html
39
40 Caveat: It modifies the original string.
41 Caveat: These functions cannot be used on constant strings.
42 Caveat: The identity of the delimiting character is lost.
43 Caveat: It doesn't work with multibyte strings unless all of the delimiter
44 characters are ASCII characters < 0x30.
45
46 See also strsep().
47 */
48 #if defined HAVE_DECL_STRTOK_R && !HAVE_DECL_STRTOK_R
49 extern char *strtok_r(char *restrict s, const char *restrict sep,
50 char **restrict lasts);
51 #endif
52
53 #endif /* STRTOK_R_H */
1 /* exit() exit codes for some BSD system programs.
2 Copyright (C) 2003 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17
18 /* Written by Simon Josefsson based on sysexits(3) man page */
19
20 #ifndef _SYSEXITS_H
21 #define _SYSEXITS_H
22
23 #define EX_USAGE 64
24 #define EX_DATAERR 65
25 #define EX_NOINPUT 66
26 #define EX_NOUSER 67
27 #define EX_NOHOST 68
28 #define EX_UNAVAILABLE 69
29 #define EX_SOFTWARE 70
30 #define EX_OSERR 71
31 #define EX_OSFILE 72
32 #define EX_CANTCREAT 73
33 #define EX_IOERR 74
34 #define EX_TEMPFAIL 75
35 #define EX_PROTOCOL 76
36 #define EX_NOPERM 77
37 #define EX_CONFIG 78
38
39 #endif /* _SYSEXITS_H */
1 /* vsprintf with automatic memory allocation.
2 Copyright (C) 1999, 2002-2004 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17
18 /* Tell glibc's <stdio.h> to provide a prototype for snprintf().
19 This must come before <config.h> because <config.h> may include
20 <features.h>, and once <features.h> has been included, it's too late. */
21 #ifndef _GNU_SOURCE
22 # define _GNU_SOURCE 1
23 #endif
24
25 #ifdef HAVE_CONFIG_H
26 # include <config.h>
27 #endif
28 #ifndef IN_LIBINTL
29 # include <alloca.h>
30 #endif
31
32 /* Specification. */
33 #if WIDE_CHAR_VERSION
34 # include "vasnwprintf.h"
35 #else
36 # include "vasnprintf.h"
37 #endif
38
39 #include <stdio.h> /* snprintf(), sprintf() */
40 #include <stdlib.h> /* abort(), malloc(), realloc(), free() */
41 #include <string.h> /* memcpy(), strlen() */
42 #include <errno.h> /* errno */
43 #include <limits.h> /* CHAR_BIT, INT_MAX */
44 #include <float.h> /* DBL_MAX_EXP, LDBL_MAX_EXP */
45 #if WIDE_CHAR_VERSION
46 # include "wprintf-parse.h"
47 #else
48 # include "printf-parse.h"
49 #endif
50
51 /* Checked size_t computations. */
52 #include "xsize.h"
53
54 #ifdef HAVE_WCHAR_T
55 # ifdef HAVE_WCSLEN
56 # define local_wcslen wcslen
57 # else
58 /* Solaris 2.5.1 has wcslen() in a separate library libw.so. To avoid
59 a dependency towards this library, here is a local substitute.
60 Define this substitute only once, even if this file is included
61 twice in the same compilation unit. */
62 # ifndef local_wcslen_defined
63 # define local_wcslen_defined 1
64 static size_t
65 local_wcslen (const wchar_t *s)
66 {
67 const wchar_t *ptr;
68
69 for (ptr = s; *ptr != (wchar_t) 0; ptr++)
70 ;
71 return ptr - s;
72 }
73 # endif
74 # endif
75 #endif
76
77 #if WIDE_CHAR_VERSION
78 # define VASNPRINTF vasnwprintf
79 # define CHAR_T wchar_t
80 # define DIRECTIVE wchar_t_directive
81 # define DIRECTIVES wchar_t_directives
82 # define PRINTF_PARSE wprintf_parse
83 # define USE_SNPRINTF 1
84 # if HAVE_DECL__SNWPRINTF
85 /* On Windows, the function swprintf() has a different signature than
86 on Unix; we use the _snwprintf() function instead. */
87 # define SNPRINTF _snwprintf
88 # else
89 /* Unix. */
90 # define SNPRINTF swprintf
91 # endif
92 #else
93 # define VASNPRINTF vasnprintf
94 # define CHAR_T char
95 # define DIRECTIVE char_directive
96 # define DIRECTIVES char_directives
97 # define PRINTF_PARSE printf_parse
98 # define USE_SNPRINTF (HAVE_DECL__SNPRINTF || HAVE_SNPRINTF)
99 # if HAVE_DECL__SNPRINTF
100 /* Windows. */
101 # define SNPRINTF _snprintf
102 # else
103 /* Unix. */
104 # define SNPRINTF snprintf
105 # endif
106 #endif
107
108 CHAR_T *
109 VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list args)
110 {
111 DIRECTIVES d;
112 arguments a;
113
114 if (PRINTF_PARSE (format, &d, &a) < 0)
115 {
116 errno = EINVAL;
117 return NULL;
118 }
119
120 #define CLEANUP() \
121 free (d.dir); \
122 if (a.arg) \
123 free (a.arg);
124
125 if (printf_fetchargs (args, &a) < 0)
126 {
127 CLEANUP ();
128 errno = EINVAL;
129 return NULL;
130 }
131
132 {
133 size_t buf_neededlength;
134 CHAR_T *buf;
135 CHAR_T *buf_malloced;
136 const CHAR_T *cp;
137 size_t i;
138 DIRECTIVE *dp;
139 /* Output string accumulator. */
140 CHAR_T *result;
141 size_t allocated;
142 size_t length;
143
144 /* Allocate a small buffer that will hold a directive passed to
145 sprintf or snprintf. */
146 buf_neededlength =
147 xsum4 (7, d.max_width_length, d.max_precision_length, 6);
148 #if HAVE_ALLOCA
149 if (buf_neededlength < 4000 / sizeof (CHAR_T))
150 {
151 buf = (CHAR_T *) alloca (buf_neededlength * sizeof (CHAR_T));
152 buf_malloced = NULL;
153 }
154 else
155 #endif
156 {
157 size_t buf_memsize = xtimes (buf_neededlength, sizeof (CHAR_T));
158 if (size_overflow_p (buf_memsize))
159 goto out_of_memory_1;
160 buf = (CHAR_T *) malloc (buf_memsize);
161 if (buf == NULL)
162 goto out_of_memory_1;
163 buf_malloced = buf;
164 }
165
166 if (resultbuf != NULL)
167 {
168 result = resultbuf;
169 allocated = *lengthp;
170 }
171 else
172 {
173 result = NULL;
174 allocated = 0;
175 }
176 length = 0;
177 /* Invariants:
178 result is either == resultbuf or == NULL or malloc-allocated.
179 If length > 0, then result != NULL. */
180
181 /* Ensures that allocated >= needed. Aborts through a jump to
182 out_of_memory if needed is SIZE_MAX or otherwise too big. */
183 #define ENSURE_ALLOCATION(needed) \
184 if ((needed) > allocated) \
185 { \
186 size_t memory_size; \
187 CHAR_T *memory; \
188 \
189 allocated = (allocated > 0 ? xtimes (allocated, 2) : 12); \
190 if ((needed) > allocated) \
191 allocated = (needed); \
192 memory_size = xtimes (allocated, sizeof (CHAR_T)); \
193 if (size_overflow_p (memory_size)) \
194 goto out_of_memory; \
195 if (result == resultbuf || result == NULL) \
196 memory = (CHAR_T *) malloc (memory_size); \
197 else \
198 memory = (CHAR_T *) realloc (result, memory_size); \
199 if (memory == NULL) \
200 goto out_of_memory; \
201 if (result == resultbuf && length > 0) \
202 memcpy (memory, result, length * sizeof (CHAR_T)); \
203 result = memory; \
204 }
205
206 for (cp = format, i = 0, dp = &d.dir[0]; ; cp = dp->dir_end, i++, dp++)
207 {
208 if (cp != dp->dir_start)
209 {
210 size_t n = dp->dir_start - cp;
211 size_t augmented_length = xsum (length, n);
212
213 ENSURE_ALLOCATION (augmented_length);
214 memcpy (result + length, cp, n * sizeof (CHAR_T));
215 length = augmented_length;
216 }
217 if (i == d.count)
218 break;
219
220 /* Execute a single directive. */
221 if (dp->conversion == '%')
222 {
223 size_t augmented_length;
224
225 if (!(dp->arg_index == ARG_NONE))
226 abort ();
227 augmented_length = xsum (length, 1);
228 ENSURE_ALLOCATION (augmented_length);
229 result[length] = '%';
230 length = augmented_length;
231 }
232 else
233 {
234 if (!(dp->arg_index != ARG_NONE))
235 abort ();
236
237 if (dp->conversion == 'n')
238 {
239 switch (a.arg[dp->arg_index].type)
240 {
241 case TYPE_COUNT_SCHAR_POINTER:
242 *a.arg[dp->arg_index].a.a_count_schar_pointer = length;
243 break;
244 case TYPE_COUNT_SHORT_POINTER:
245 *a.arg[dp->arg_index].a.a_count_short_pointer = length;
246 break;
247 case TYPE_COUNT_INT_POINTER:
248 *a.arg[dp->arg_index].a.a_count_int_pointer = length;
249 break;
250 case TYPE_COUNT_LONGINT_POINTER:
251 *a.arg[dp->arg_index].a.a_count_longint_pointer = length;
252 break;
253 #ifdef HAVE_LONG_LONG
254 case TYPE_COUNT_LONGLONGINT_POINTER:
255 *a.arg[dp->arg_index].a.a_count_longlongint_pointer = length;
256 break;
257 #endif
258 default:
259 abort ();
260 }
261 }
262 else
263 {
264 arg_type type = a.arg[dp->arg_index].type;
265 CHAR_T *p;
266 unsigned int prefix_count;
267 int prefixes[2];
268 #if !USE_SNPRINTF
269 size_t tmp_length;
270 CHAR_T tmpbuf[700];
271 CHAR_T *tmp;
272
273 /* Allocate a temporary buffer of sufficient size for calling
274 sprintf. */
275 {
276 size_t width;
277 size_t precision;
278
279 width = 0;
280 if (dp->width_start != dp->width_end)
281 {
282 if (dp->width_arg_index != ARG_NONE)
283 {
284 int arg;
285
286 if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
287 abort ();
288 arg = a.arg[dp->width_arg_index].a.a_int;
289 width = (arg < 0 ? (unsigned int) (-arg) : arg);
290 }
291 else
292 {
293 const CHAR_T *digitp = dp->width_start;
294
295 do
296 width = xsum (xtimes (width, 10), *digitp++ - '0');
297 while (digitp != dp->width_end);
298 }
299 }
300
301 precision = 6;
302 if (dp->precision_start != dp->precision_end)
303 {
304 if (dp->precision_arg_index != ARG_NONE)
305 {
306 int arg;
307
308 if (!(a.arg[dp->precision_arg_index].type == TYPE_INT))
309 abort ();
310 arg = a.arg[dp->precision_arg_index].a.a_int;
311 precision = (arg < 0 ? 0 : arg);
312 }
313 else
314 {
315 const CHAR_T *digitp = dp->precision_start + 1;
316
317 precision = 0;
318 while (digitp != dp->precision_end)
319 precision = xsum (xtimes (precision, 10), *digitp++ - '0');
320 }
321 }
322
323 switch (dp->conversion)
324 {
325
326 case 'd': case 'i': case 'u':
327 # ifdef HAVE_LONG_LONG
328 if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT)
329 tmp_length =
330 (unsigned int) (sizeof (unsigned long long) * CHAR_BIT
331 * 0.30103 /* binary -> decimal */
332 * 2 /* estimate for FLAG_GROUP */
333 )
334 + 1 /* turn floor into ceil */
335 + 1; /* account for leading sign */
336 else
337 # endif
338 if (type == TYPE_LONGINT || type == TYPE_ULONGINT)
339 tmp_length =
340 (unsigned int) (sizeof (unsigned long) * CHAR_BIT
341 * 0.30103 /* binary -> decimal */
342 * 2 /* estimate for FLAG_GROUP */
343 )
344 + 1 /* turn floor into ceil */
345 + 1; /* account for leading sign */
346 else
347 tmp_length =
348 (unsigned int) (sizeof (unsigned int) * CHAR_BIT
349 * 0.30103 /* binary -> decimal */
350 * 2 /* estimate for FLAG_GROUP */
351 )
352 + 1 /* turn floor into ceil */
353 + 1; /* account for leading sign */
354 break;
355
356 case 'o':
357 # ifdef HAVE_LONG_LONG
358 if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT)
359 tmp_length =
360 (unsigned int) (sizeof (unsigned long long) * CHAR_BIT
361 * 0.333334 /* binary -> octal */
362 )
363 + 1 /* turn floor into ceil */
364 + 1; /* account for leading sign */
365 else
366 # endif
367 if (type == TYPE_LONGINT || type == TYPE_ULONGINT)
368 tmp_length =
369 (unsigned int) (sizeof (unsigned long) * CHAR_BIT
370 * 0.333334 /* binary -> octal */
371 )
372 + 1 /* turn floor into ceil */
373 + 1; /* account for leading sign */
374 else
375 tmp_length =
376 (unsigned int) (sizeof (unsigned int) * CHAR_BIT
377 * 0.333334 /* binary -> octal */
378 )
379 + 1 /* turn floor into ceil */
380 + 1; /* account for leading sign */
381 break;
382
383 case 'x': case 'X':
384 # ifdef HAVE_LONG_LONG
385 if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT)
386 tmp_length =
387 (unsigned int) (sizeof (unsigned long long) * CHAR_BIT
388 * 0.25 /* binary -> hexadecimal */
389 )
390 + 1 /* turn floor into ceil */
391 + 2; /* account for leading sign or alternate form */
392 else
393 # endif
394 if (type == TYPE_LONGINT || type == TYPE_ULONGINT)
395 tmp_length =
396 (unsigned int) (sizeof (unsigned long) * CHAR_BIT
397 * 0.25 /* binary -> hexadecimal */
398 )
399 + 1 /* turn floor into ceil */
400 + 2; /* account for leading sign or alternate form */
401 else
402 tmp_length =
403 (unsigned int) (sizeof (unsigned int) * CHAR_BIT
404 * 0.25 /* binary -> hexadecimal */
405 )
406 + 1 /* turn floor into ceil */
407 + 2; /* account for leading sign or alternate form */
408 break;
409
410 case 'f': case 'F':
411 # ifdef HAVE_LONG_DOUBLE
412 if (type == TYPE_LONGDOUBLE)
413 tmp_length =
414 (unsigned int) (LDBL_MAX_EXP
415 * 0.30103 /* binary -> decimal */
416 * 2 /* estimate for FLAG_GROUP */
417 )
418 + 1 /* turn floor into ceil */
419 + 10; /* sign, decimal point etc. */
420 else
421 # endif
422 tmp_length =
423 (unsigned int) (DBL_MAX_EXP
424 * 0.30103 /* binary -> decimal */
425 * 2 /* estimate for FLAG_GROUP */
426 )
427 + 1 /* turn floor into ceil */
428 + 10; /* sign, decimal point etc. */
429 tmp_length = xsum (tmp_length, precision);
430 break;
431
432 case 'e': case 'E': case 'g': case 'G':
433 case 'a': case 'A':
434 tmp_length =
435 12; /* sign, decimal point, exponent etc. */
436 tmp_length = xsum (tmp_length, precision);
437 break;
438
439 case 'c':
440 # if defined HAVE_WINT_T && !WIDE_CHAR_VERSION
441 if (type == TYPE_WIDE_CHAR)
442 tmp_length = MB_CUR_MAX;
443 else
444 # endif
445 tmp_length = 1;
446 break;
447
448 case 's':
449 # ifdef HAVE_WCHAR_T
450 if (type == TYPE_WIDE_STRING)
451 {
452 tmp_length =
453 local_wcslen (a.arg[dp->arg_index].a.a_wide_string);
454
455 # if !WIDE_CHAR_VERSION
456 tmp_length = xtimes (tmp_length, MB_CUR_MAX);
457 # endif
458 }
459 else
460 # endif
461 tmp_length = strlen (a.arg[dp->arg_index].a.a_string);
462 break;
463
464 case 'p':
465 tmp_length =
466 (unsigned int) (sizeof (void *) * CHAR_BIT
467 * 0.25 /* binary -> hexadecimal */
468 )
469 + 1 /* turn floor into ceil */
470 + 2; /* account for leading 0x */
471 break;
472
473 default:
474 abort ();
475 }
476
477 if (tmp_length < width)
478 tmp_length = width;
479
480 tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */
481 }
482
483 if (tmp_length <= sizeof (tmpbuf) / sizeof (CHAR_T))
484 tmp = tmpbuf;
485 else
486 {
487 size_t tmp_memsize = xtimes (tmp_length, sizeof (CHAR_T));
488
489 if (size_overflow_p (tmp_memsize))
490 /* Overflow, would lead to out of memory. */
491 goto out_of_memory;
492 tmp = (CHAR_T *) malloc (tmp_memsize);
493 if (tmp == NULL)
494 /* Out of memory. */
495 goto out_of_memory;
496 }
497 #endif
498
499 /* Construct the format string for calling snprintf or
500 sprintf. */
501 p = buf;
502 *p++ = '%';
503 if (dp->flags & FLAG_GROUP)
504 *p++ = '\'';
505 if (dp->flags & FLAG_LEFT)
506 *p++ = '-';
507 if (dp->flags & FLAG_SHOWSIGN)
508 *p++ = '+';
509 if (dp->flags & FLAG_SPACE)
510 *p++ = ' ';
511 if (dp->flags & FLAG_ALT)
512 *p++ = '#';
513 if (dp->flags & FLAG_ZERO)
514 *p++ = '0';
515 if (dp->width_start != dp->width_end)
516 {
517 size_t n = dp->width_end - dp->width_start;
518 memcpy (p, dp->width_start, n * sizeof (CHAR_T));
519 p += n;
520 }
521 if (dp->precision_start != dp->precision_end)
522 {
523 size_t n = dp->precision_end - dp->precision_start;
524 memcpy (p, dp->precision_start, n * sizeof (CHAR_T));
525 p += n;
526 }
527
528 switch (type)
529 {
530 #ifdef HAVE_LONG_LONG
531 case TYPE_LONGLONGINT:
532 case TYPE_ULONGLONGINT:
533 *p++ = 'l';
534 /*FALLTHROUGH*/
535 #endif
536 case TYPE_LONGINT:
537 case TYPE_ULONGINT:
538 #ifdef HAVE_WINT_T
539 case TYPE_WIDE_CHAR:
540 #endif
541 #ifdef HAVE_WCHAR_T
542 case TYPE_WIDE_STRING:
543 #endif
544 *p++ = 'l';
545 break;
546 #ifdef HAVE_LONG_DOUBLE
547 case TYPE_LONGDOUBLE:
548 *p++ = 'L';
549 break;
550 #endif
551 default:
552 break;
553 }
554 *p = dp->conversion;
555 #if USE_SNPRINTF
556 p[1] = '%';
557 p[2] = 'n';
558 p[3] = '\0';
559 #else
560 p[1] = '\0';
561 #endif
562
563 /* Construct the arguments for calling snprintf or sprintf. */
564 prefix_count = 0;
565 if (dp->width_arg_index != ARG_NONE)
566 {
567 if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
568 abort ();
569 prefixes[prefix_count++] = a.arg[dp->width_arg_index].a.a_int;
570 }
571 if (dp->precision_arg_index != ARG_NONE)
572 {
573 if (!(a.arg[dp->precision_arg_index].type == TYPE_INT))
574 abort ();
575 prefixes[prefix_count++] = a.arg[dp->precision_arg_index].a.a_int;
576 }
577
578 #if USE_SNPRINTF
579 /* Prepare checking whether snprintf returns the count
580 via %n. */
581 ENSURE_ALLOCATION (xsum (length, 1));
582 result[length] = '\0';
583 #endif
584
585 for (;;)
586 {
587 size_t maxlen;
588 int count;
589 int retcount;
590
591 maxlen = allocated - length;
592 count = -1;
593 retcount = 0;
594
595 #if USE_SNPRINTF
596 # define SNPRINTF_BUF(arg) \
597 switch (prefix_count) \
598 { \
599 case 0: \
600 retcount = SNPRINTF (result + length, maxlen, buf, \
601 arg, &count); \
602 break; \
603 case 1: \
604 retcount = SNPRINTF (result + length, maxlen, buf, \
605 prefixes[0], arg, &count); \
606 break; \
607 case 2: \
608 retcount = SNPRINTF (result + length, maxlen, buf, \
609 prefixes[0], prefixes[1], arg, \
610 &count); \
611 break; \
612 default: \
613 abort (); \
614 }
615 #else
616 # define SNPRINTF_BUF(arg) \
617 switch (prefix_count) \
618 { \
619 case 0: \
620 count = sprintf (tmp, buf, arg); \
621 break; \
622 case 1: \
623 count = sprintf (tmp, buf, prefixes[0], arg); \
624 break; \
625 case 2: \
626 count = sprintf (tmp, buf, prefixes[0], prefixes[1],\
627 arg); \
628 break; \
629 default: \
630 abort (); \
631 }
632 #endif
633
634 switch (type)
635 {
636 case TYPE_SCHAR:
637 {
638 int arg = a.arg[dp->arg_index].a.a_schar;
639 SNPRINTF_BUF (arg);
640 }
641 break;
642 case TYPE_UCHAR:
643 {
644 unsigned int arg = a.arg[dp->arg_index].a.a_uchar;
645 SNPRINTF_BUF (arg);
646 }
647 break;
648 case TYPE_SHORT:
649 {
650 int arg = a.arg[dp->arg_index].a.a_short;
651 SNPRINTF_BUF (arg);
652 }
653 break;
654 case TYPE_USHORT:
655 {
656 unsigned int arg = a.arg[dp->arg_index].a.a_ushort;
657 SNPRINTF_BUF (arg);
658 }
659 break;
660 case TYPE_INT:
661 {
662 int arg = a.arg[dp->arg_index].a.a_int;
663 SNPRINTF_BUF (arg);
664 }
665 break;
666 case TYPE_UINT:
667 {
668 unsigned int arg = a.arg[dp->arg_index].a.a_uint;
669 SNPRINTF_BUF (arg);
670 }
671 break;
672 case TYPE_LONGINT:
673 {
674 long int arg = a.arg[dp->arg_index].a.a_longint;
675 SNPRINTF_BUF (arg);
676 }
677 break;
678 case TYPE_ULONGINT:
679 {
680 unsigned long int arg = a.arg[dp->arg_index].a.a_ulongint;
681 SNPRINTF_BUF (arg);
682 }
683 break;
684 #ifdef HAVE_LONG_LONG
685 case TYPE_LONGLONGINT:
686 {
687 long long int arg = a.arg[dp->arg_index].a.a_longlongint;
688 SNPRINTF_BUF (arg);
689 }
690 break;
691 case TYPE_ULONGLONGINT:
692 {
693 unsigned long long int arg = a.arg[dp->arg_index].a.a_ulonglongint;
694 SNPRINTF_BUF (arg);
695 }
696 break;
697 #endif
698 case TYPE_DOUBLE:
699 {
700 double arg = a.arg[dp->arg_index].a.a_double;
701 SNPRINTF_BUF (arg);
702 }
703 break;
704 #ifdef HAVE_LONG_DOUBLE
705 case TYPE_LONGDOUBLE:
706 {
707 long double arg = a.arg[dp->arg_index].a.a_longdouble;
708 SNPRINTF_BUF (arg);
709 }
710 break;
711 #endif
712 case TYPE_CHAR:
713 {
714 int arg = a.arg[dp->arg_index].a.a_char;
715 SNPRINTF_BUF (arg);
716 }
717 break;
718 #ifdef HAVE_WINT_T
719 case TYPE_WIDE_CHAR:
720 {
721 wint_t arg = a.arg[dp->arg_index].a.a_wide_char;
722 SNPRINTF_BUF (arg);
723 }
724 break;
725 #endif
726 case TYPE_STRING:
727 {
728 const char *arg = a.arg[dp->arg_index].a.a_string;
729 SNPRINTF_BUF (arg);
730 }
731 break;
732 #ifdef HAVE_WCHAR_T
733 case TYPE_WIDE_STRING:
734 {
735 const wchar_t *arg = a.arg[dp->arg_index].a.a_wide_string;
736 SNPRINTF_BUF (arg);
737 }
738 break;
739 #endif
740 case TYPE_POINTER:
741 {
742 void *arg = a.arg[dp->arg_index].a.a_pointer;
743 SNPRINTF_BUF (arg);
744 }
745 break;
746 default:
747 abort ();
748 }
749
750 #if USE_SNPRINTF
751 /* Portability: Not all implementations of snprintf()
752 are ISO C 99 compliant. Determine the number of
753 bytes that snprintf() has produced or would have
754 produced. */
755 if (count >= 0)
756 {
757 /* Verify that snprintf() has NUL-terminated its
758 result. */
759 if (count < maxlen && result[length + count] != '\0')
760 abort ();
761 /* Portability hack. */
762 if (retcount > count)
763 count = retcount;
764 }
765 else
766 {
767 /* snprintf() doesn't understand the '%n'
768 directive. */
769 if (p[1] != '\0')
770 {
771 /* Don't use the '%n' directive; instead, look
772 at the snprintf() return value. */
773 p[1] = '\0';
774 continue;
775 }
776 else
777 {
778 /* Look at the snprintf() return value. */
779 if (retcount < 0)
780 {
781 /* HP-UX 10.20 snprintf() is doubly deficient:
782 It doesn't understand the '%n' directive,
783 *and* it returns -1 (rather than the length
784 that would have been required) when the
785 buffer is too small. */
786 size_t bigger_need =
787 xsum (xtimes (allocated, 2), 12);
788 ENSURE_ALLOCATION (bigger_need);
789 continue;
790 }
791 else
792 count = retcount;
793 }
794 }
795 #endif
796
797 /* Attempt to handle failure. */
798 if (count < 0)
799 {
800 if (!(result == resultbuf || result == NULL))
801 free (result);
802 if (buf_malloced != NULL)
803 free (buf_malloced);
804 CLEANUP ();
805 errno = EINVAL;
806 return NULL;
807 }
808
809 #if !USE_SNPRINTF
810 if (count >= tmp_length)
811 /* tmp_length was incorrectly calculated - fix the
812 code above! */
813 abort ();
814 #endif
815
816 /* Make room for the result. */
817 if (count >= maxlen)
818 {
819 /* Need at least count bytes. But allocate
820 proportionally, to avoid looping eternally if
821 snprintf() reports a too small count. */
822 size_t n =
823 xmax (xsum (length, count), xtimes (allocated, 2));
824
825 ENSURE_ALLOCATION (n);
826 #if USE_SNPRINTF
827 continue;
828 #endif
829 }
830
831 #if USE_SNPRINTF
832 /* The snprintf() result did fit. */
833 #else
834 /* Append the sprintf() result. */
835 memcpy (result + length, tmp, count * sizeof (CHAR_T));
836 if (tmp != tmpbuf)
837 free (tmp);
838 #endif
839
840 length += count;
841 break;
842 }
843 }
844 }
845 }
846
847 /* Add the final NUL. */
848 ENSURE_ALLOCATION (xsum (length, 1));
849 result[length] = '\0';
850
851 if (result != resultbuf && length + 1 < allocated)
852 {
853 /* Shrink the allocated memory if possible. */
854 CHAR_T *memory;
855
856 memory = (CHAR_T *) realloc (result, (length + 1) * sizeof (CHAR_T));
857 if (memory != NULL)
858 result = memory;
859 }
860
861 if (buf_malloced != NULL)
862 free (buf_malloced);
863 CLEANUP ();
864 *lengthp = length;
865 if (length > INT_MAX)
866 goto length_overflow;
867 return result;
868
869 length_overflow:
870 /* We could produce such a big string, but its length doesn't fit into
871 an 'int'. POSIX says that snprintf() fails with errno = EOVERFLOW in
872 this case. */
873 if (result != resultbuf)
874 free (result);
875 errno = EOVERFLOW;
876 return NULL;
877
878 out_of_memory:
879 if (!(result == resultbuf || result == NULL))
880 free (result);
881 if (buf_malloced != NULL)
882 free (buf_malloced);
883 out_of_memory_1:
884 CLEANUP ();
885 errno = ENOMEM;
886 return NULL;
887 }
888 }
889
890 #undef SNPRINTF
891 #undef USE_SNPRINTF
892 #undef PRINTF_PARSE
893 #undef DIRECTIVES
894 #undef DIRECTIVE
895 #undef CHAR_T
896 #undef VASNPRINTF
1 /* vsprintf with automatic memory allocation.
2 Copyright (C) 2002-2004 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17
18 #ifndef _VASNPRINTF_H
19 #define _VASNPRINTF_H
20
21 /* Get va_list. */
22 #include <stdarg.h>
23
24 /* Get size_t. */
25 #include <stddef.h>
26
27 #ifndef __attribute__
28 /* This feature is available in gcc versions 2.5 and later. */
29 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
30 # define __attribute__(Spec) /* empty */
31 # endif
32 /* The __-protected variants of `format' and `printf' attributes
33 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
34 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
35 # define __format__ format
36 # define __printf__ printf
37 # endif
38 #endif
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44 /* Write formatted output to a string dynamically allocated with malloc().
45 You can pass a preallocated buffer for the result in RESULTBUF and its
46 size in *LENGTHP; otherwise you pass RESULTBUF = NULL.
47 If successful, return the address of the string (this may be = RESULTBUF
48 if no dynamic memory allocation was necessary) and set *LENGTHP to the
49 number of resulting bytes, excluding the trailing NUL. Upon error, set
50 errno and return NULL.
51
52 When dynamic memory allocation occurs, the preallocated buffer is left
53 alone (with possibly modified contents). This makes it possible to use
54 a statically allocated or stack-allocated buffer, like this:
55
56 char buf[100];
57 size_t len = sizeof (buf);
58 char *output = vasnprintf (buf, &len, format, args);
59 if (output == NULL)
60 ... error handling ...;
61 else
62 {
63 ... use the output string ...;
64 if (output != buf)
65 free (output);
66 }
67 */
68 extern char * asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...)
69 __attribute__ ((__format__ (__printf__, 3, 4)));
70 extern char * vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args)
71 __attribute__ ((__format__ (__printf__, 3, 0)));
72
73 #ifdef __cplusplus
74 }
75 #endif
76
77 #endif /* _VASNPRINTF_H */
1 /* Formatted output to strings.
2 Copyright (C) 2004 Free Software Foundation, Inc.
3 Written by Simon Josefsson and Yoann Vandoorselaere <yoann@prelude-ids.org>.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation,
17 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18
19 #ifdef HAVE_CONFIG_H
20 # include <config.h>
21 #endif
22
23 /* Specification. */
24 #include "vsnprintf.h"
25
26 #include <stdarg.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30
31 #include "vasnprintf.h"
32
33 /* Print formatted output to string STR. Similar to vsprintf, but
34 additional length SIZE limit how much is written into STR. Returns
35 string length of formatted string (which may be larger than SIZE).
36 STR may be NULL, in which case nothing will be written. On error,
37 return a negative value. */
38 int
39 vsnprintf (char *str, size_t size, const char *format, va_list args)
40 {
41 char *output;
42 size_t len;
43
44 len = size;
45 output = vasnprintf (str, &len, format, args);
46
47 if (!output)
48 return -1;
49
50 if (str != NULL)
51 if (len > size - 1) /* equivalent to: (size > 0 && len >= size) */
52 str[size - 1] = '\0';
53
54 if (output != str)
55 free (output);
56
57 return len;
58 }
1 /* Formatted output to strings.
2 Copyright (C) 2004 Free Software Foundation, Inc.
3 Written by Simon Josefsson and Yoann Vandoorselaere <yoann@prelude-ids.org>.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation,
17 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18
19 #ifndef VSNPRINTF_H
20 #define VSNPRINTF_H
21
22 #include <stdarg.h>
23
24 /* Get vsnprintf declaration, if available. */
25 #include <stdio.h>
26
27 #if defined HAVE_DECL_VSNPRINTF && !HAVE_DECL_VSNPRINTF
28 int vsnprintf (char *str, size_t size, const char *format, va_list args);
29 #endif
30
31 #endif /* VSNPRINTF_H */
1 /* xsize.h -- Checked size_t computations.
2
3 Copyright (C) 2003 Free Software Foundation, Inc.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18
19 #ifndef _XSIZE_H
20 #define _XSIZE_H
21
22 /* Get size_t. */
23 #include <stddef.h>
24
25 /* Get SIZE_MAX. */
26 #include <limits.h>
27 #if HAVE_STDINT_H
28 # include <stdint.h>
29 #endif
30
31 /* The size of memory objects is often computed through expressions of
32 type size_t. Example:
33 void* p = malloc (header_size + n * element_size).
34 These computations can lead to overflow. When this happens, malloc()
35 returns a piece of memory that is way too small, and the program then
36 crashes while attempting to fill the memory.
37 To avoid this, the functions and macros in this file check for overflow.
38 The convention is that SIZE_MAX represents overflow.
39 malloc (SIZE_MAX) is not guaranteed to fail -- think of a malloc
40 implementation that uses mmap --, it's recommended to use size_overflow_p()
41 or size_in_bounds_p() before invoking malloc().
42 The example thus becomes:
43 size_t size = xsum (header_size, xtimes (n, element_size));
44 void *p = (size_in_bounds_p (size) ? malloc (size) : NULL);
45 */
46
47 /* Convert an arbitrary value >= 0 to type size_t. */
48 #define xcast_size_t(N) \
49 ((N) <= SIZE_MAX ? (size_t) (N) : SIZE_MAX)
50
51 /* Sum of two sizes, with overflow check. */
52 static inline size_t
53 #if __GNUC__ >= 3
54 __attribute__ ((__pure__))
55 #endif
56 xsum (size_t size1, size_t size2)
57 {
58 size_t sum = size1 + size2;
59 return (sum >= size1 ? sum : SIZE_MAX);
60 }
61
62 /* Sum of three sizes, with overflow check. */
63 static inline size_t
64 #if __GNUC__ >= 3
65 __attribute__ ((__pure__))
66 #endif
67 xsum3 (size_t size1, size_t size2, size_t size3)
68 {
69 return xsum (xsum (size1, size2), size3);
70 }
71
72 /* Sum of four sizes, with overflow check. */
73 static inline size_t
74 #if __GNUC__ >= 3
75 __attribute__ ((__pure__))
76 #endif
77 xsum4 (size_t size1, size_t size2, size_t size3, size_t size4)
78 {
79 return xsum (xsum (xsum (size1, size2), size3), size4);
80 }
81
82 /* Maximum of two sizes, with overflow check. */
83 static inline size_t
84 #if __GNUC__ >= 3
85 __attribute__ ((__pure__))
86 #endif
87 xmax (size_t size1, size_t size2)
88 {
89 /* No explicit check is needed here, because for any n:
90 max (SIZE_MAX, n) == SIZE_MAX and max (n, SIZE_MAX) == SIZE_MAX. */
91 return (size1 >= size2 ? size1 : size2);
92 }
93
94 /* Multiplication of a count with an element size, with overflow check.
95 The count must be >= 0 and the element size must be > 0.
96 This is a macro, not an inline function, so that it works correctly even
97 when N is of a wider tupe and N > SIZE_MAX. */
98 #define xtimes(N, ELSIZE) \
99 ((N) <= SIZE_MAX / (ELSIZE) ? (size_t) (N) * (ELSIZE) : SIZE_MAX)
100
101 /* Check for overflow. */
102 #define size_overflow_p(SIZE) \
103 ((SIZE) == SIZE_MAX)
104 /* Check against overflow. */
105 #define size_in_bounds_p(SIZE) \
106 ((SIZE) != SIZE_MAX)
107
108 #endif /* _XSIZE_H */
1 #! /bin/sh
2 # Output a system dependent set of variables, describing how to set the
3 # run time search path of shared libraries in an executable.
4 #
5 # Copyright 1996-2003 Free Software Foundation, Inc.
6 # Taken from GNU libtool, 2001
7 # Originally by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
8 #
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #
23 # As a special exception to the GNU General Public License, if you
24 # distribute this file as part of a program that contains a
25 # configuration script generated by Autoconf, you may include it under
26 # the same distribution terms that you use for the rest of that program.
27 #
28 # The first argument passed to this file is the canonical host specification,
29 # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
30 # or
31 # CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
32 # The environment variables CC, GCC, LDFLAGS, LD, with_gnu_ld
33 # should be set by the caller.
34 #
35 # The set of defined variables is at the end of this script.
36
37 # Known limitations:
38 # - On IRIX 6.5 with CC="cc", the run time search patch must not be longer
39 # than 256 bytes, otherwise the compiler driver will dump core. The only
40 # known workaround is to choose shorter directory names for the build
41 # directory and/or the installation directory.
42
43 # All known linkers require a `.a' archive for static linking (except M$VC,
44 # which needs '.lib').
45 libext=a
46 shrext=.so
47
48 host="$1"
49 host_cpu=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
50 host_vendor=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'`
51 host_os=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
52
53 # Code taken from libtool.m4's AC_LIBTOOL_PROG_COMPILER_PIC.
54
55 wl=
56 if test "$GCC" = yes; then
57 wl='-Wl,'
58 else
59 case "$host_os" in
60 aix*)
61 wl='-Wl,'
62 ;;
63 mingw* | pw32* | os2*)
64 ;;
65 hpux9* | hpux10* | hpux11*)
66 wl='-Wl,'
67 ;;
68 irix5* | irix6* | nonstopux*)
69 wl='-Wl,'
70 ;;
71 newsos6)
72 ;;
73 linux*)
74 case $CC in
75 icc|ecc)
76 wl='-Wl,'
77 ;;
78 ccc)
79 wl='-Wl,'
80 ;;
81 esac
82 ;;
83 osf3* | osf4* | osf5*)
84 wl='-Wl,'
85 ;;
86 sco3.2v5*)
87 ;;
88 solaris*)
89 wl='-Wl,'
90 ;;
91 sunos4*)
92 wl='-Qoption ld '
93 ;;
94 sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*)
95 wl='-Wl,'
96 ;;
97 sysv4*MP*)
98 ;;
99 uts4*)
100 ;;
101 esac
102 fi
103
104 # Code taken from libtool.m4's AC_LIBTOOL_PROG_LD_SHLIBS.
105
106 hardcode_libdir_flag_spec=
107 hardcode_libdir_separator=
108 hardcode_direct=no
109 hardcode_minus_L=no
110
111 case "$host_os" in
112 cygwin* | mingw* | pw32*)
113 # FIXME: the MSVC++ port hasn't been tested in a loooong time
114 # When not using gcc, we currently assume that we are using
115 # Microsoft Visual C++.
116 if test "$GCC" != yes; then
117 with_gnu_ld=no
118 fi
119 ;;
120 openbsd*)
121 with_gnu_ld=no
122 ;;
123 esac
124
125 ld_shlibs=yes
126 if test "$with_gnu_ld" = yes; then
127 case "$host_os" in
128 aix3* | aix4* | aix5*)
129 # On AIX/PPC, the GNU linker is very broken
130 if test "$host_cpu" != ia64; then
131 ld_shlibs=no
132 fi
133 ;;
134 amigaos*)
135 hardcode_libdir_flag_spec='-L$libdir'
136 hardcode_minus_L=yes
137 # Samuel A. Falvo II <kc5tja@dolphin.openprojects.net> reports
138 # that the semantics of dynamic libraries on AmigaOS, at least up
139 # to version 4, is to share data among multiple programs linked
140 # with the same dynamic library. Since this doesn't match the
141 # behavior of shared libraries on other platforms, we can use
142 # them.
143 ld_shlibs=no
144 ;;
145 beos*)
146 if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
147 :
148 else
149 ld_shlibs=no
150 fi
151 ;;
152 cygwin* | mingw* | pw32*)
153 # hardcode_libdir_flag_spec is actually meaningless, as there is
154 # no search path for DLLs.
155 hardcode_libdir_flag_spec='-L$libdir'
156 if $LD --help 2>&1 | grep 'auto-import' > /dev/null; then
157 :
158 else
159 ld_shlibs=no
160 fi
161 ;;
162 netbsd*)
163 ;;
164 solaris* | sysv5*)
165 if $LD -v 2>&1 | grep 'BFD 2\.8' > /dev/null; then
166 ld_shlibs=no
167 elif $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
168 :
169 else
170 ld_shlibs=no
171 fi
172 ;;
173 sunos4*)
174 hardcode_direct=yes
175 ;;
176 *)
177 if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
178 :
179 else
180 ld_shlibs=no
181 fi
182 ;;
183 esac
184 if test "$ld_shlibs" = yes; then
185 # Unlike libtool, we use -rpath here, not --rpath, since the documented
186 # option of GNU ld is called -rpath, not --rpath.
187 hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
188 fi
189 else
190 case "$host_os" in
191 aix3*)
192 # Note: this linker hardcodes the directories in LIBPATH if there
193 # are no directories specified by -L.
194 hardcode_minus_L=yes
195 if test "$GCC" = yes; then
196 # Neither direct hardcoding nor static linking is supported with a
197 # broken collect2.
198 hardcode_direct=unsupported
199 fi
200 ;;
201 aix4* | aix5*)
202 if test "$host_cpu" = ia64; then
203 # On IA64, the linker does run time linking by default, so we don't
204 # have to do anything special.
205 aix_use_runtimelinking=no
206 else
207 aix_use_runtimelinking=no
208 # Test if we are trying to use run time linking or normal
209 # AIX style linking. If -brtl is somewhere in LDFLAGS, we
210 # need to do runtime linking.
211 case $host_os in aix4.[23]|aix4.[23].*|aix5*)
212 for ld_flag in $LDFLAGS; do
213 if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then
214 aix_use_runtimelinking=yes
215 break
216 fi
217 done
218 esac
219 fi
220 hardcode_direct=yes
221 hardcode_libdir_separator=':'
222 if test "$GCC" = yes; then
223 case $host_os in aix4.[012]|aix4.[012].*)
224 collect2name=`${CC} -print-prog-name=collect2`
225 if test -f "$collect2name" && \
226 strings "$collect2name" | grep resolve_lib_name >/dev/null
227 then
228 # We have reworked collect2
229 hardcode_direct=yes
230 else
231 # We have old collect2
232 hardcode_direct=unsupported
233 hardcode_minus_L=yes
234 hardcode_libdir_flag_spec='-L$libdir'
235 hardcode_libdir_separator=
236 fi
237 esac
238 fi
239 # Begin _LT_AC_SYS_LIBPATH_AIX.
240 echo 'int main () { return 0; }' > conftest.c
241 ${CC} ${LDFLAGS} conftest.c -o conftest
242 aix_libpath=`dump -H conftest 2>/dev/null | sed -n -e '/Import File Strings/,/^$/ { /^0/ { s/^0 *\(.*\)$/\1/; p; }
243 }'`
244 if test -z "$aix_libpath"; then
245 aix_libpath=`dump -HX64 conftest 2>/dev/null | sed -n -e '/Import File Strings/,/^$/ { /^0/ { s/^0 *\(.*\)$/\1/; p; }
246 }'`
247 fi
248 if test -z "$aix_libpath"; then
249 aix_libpath="/usr/lib:/lib"
250 fi
251 rm -f conftest.c conftest
252 # End _LT_AC_SYS_LIBPATH_AIX.
253 if test "$aix_use_runtimelinking" = yes; then
254 hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:'"$aix_libpath"
255 else
256 if test "$host_cpu" = ia64; then
257 hardcode_libdir_flag_spec='${wl}-R $libdir:/usr/lib:/lib'
258 else
259 hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:'"$aix_libpath"
260 fi
261 fi
262 ;;
263 amigaos*)
264 hardcode_libdir_flag_spec='-L$libdir'
265 hardcode_minus_L=yes
266 # see comment about different semantics on the GNU ld section
267 ld_shlibs=no
268 ;;
269 bsdi4*)
270 ;;
271 cygwin* | mingw* | pw32*)
272 # When not using gcc, we currently assume that we are using
273 # Microsoft Visual C++.
274 # hardcode_libdir_flag_spec is actually meaningless, as there is
275 # no search path for DLLs.
276 hardcode_libdir_flag_spec=' '
277 libext=lib
278 ;;
279 darwin* | rhapsody*)
280 if $CC -v 2>&1 | grep 'Apple' >/dev/null ; then
281 hardcode_direct=no
282 fi
283 ;;
284 dgux*)
285 hardcode_libdir_flag_spec='-L$libdir'
286 ;;
287 freebsd1*)
288 ld_shlibs=no
289 ;;
290 freebsd2.2*)
291 hardcode_libdir_flag_spec='-R$libdir'
292 hardcode_direct=yes
293 ;;
294 freebsd2*)
295 hardcode_direct=yes
296 hardcode_minus_L=yes
297 ;;
298 freebsd*)
299 hardcode_libdir_flag_spec='-R$libdir'
300 hardcode_direct=yes
301 ;;
302 hpux9*)
303 hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
304 hardcode_libdir_separator=:
305 hardcode_direct=yes
306 # hardcode_minus_L: Not really in the search PATH,
307 # but as the default location of the library.
308 hardcode_minus_L=yes
309 ;;
310 hpux10* | hpux11*)
311 if test "$with_gnu_ld" = no; then
312 case "$host_cpu" in
313 hppa*64*)
314 hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
315 hardcode_libdir_separator=:
316 hardcode_direct=no
317 ;;
318 ia64*)
319 hardcode_libdir_flag_spec='-L$libdir'
320 hardcode_direct=no
321 # hardcode_minus_L: Not really in the search PATH,
322 # but as the default location of the library.
323 hardcode_minus_L=yes
324 ;;
325 *)
326 hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
327 hardcode_libdir_separator=:
328 hardcode_direct=yes
329 # hardcode_minus_L: Not really in the search PATH,
330 # but as the default location of the library.
331 hardcode_minus_L=yes
332 ;;
333 esac
334 fi
335 ;;
336 irix5* | irix6* | nonstopux*)
337 hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
338 hardcode_libdir_separator=:
339 ;;
340 netbsd*)
341 hardcode_libdir_flag_spec='-R$libdir'
342 hardcode_direct=yes
343 ;;
344 newsos6)
345 hardcode_direct=yes
346 hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
347 hardcode_libdir_separator=:
348 ;;
349 openbsd*)
350 hardcode_direct=yes
351 if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
352 hardcode_libdir_flag_spec='${wl}-rpath,$libdir'
353 else
354 case "$host_os" in
355 openbsd[01].* | openbsd2.[0-7] | openbsd2.[0-7].*)
356 hardcode_libdir_flag_spec='-R$libdir'
357 ;;
358 *)
359 hardcode_libdir_flag_spec='${wl}-rpath,$libdir'
360 ;;
361 esac
362 fi
363 ;;
364 os2*)
365 hardcode_libdir_flag_spec='-L$libdir'
366 hardcode_minus_L=yes
367 ;;
368 osf3*)
369 hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
370 hardcode_libdir_separator=:
371 ;;
372 osf4* | osf5*)
373 if test "$GCC" = yes; then
374 hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
375 else
376 # Both cc and cxx compiler support -rpath directly
377 hardcode_libdir_flag_spec='-rpath $libdir'
378 fi
379 hardcode_libdir_separator=:
380 ;;
381 sco3.2v5*)
382 ;;
383 solaris*)
384 hardcode_libdir_flag_spec='-R$libdir'
385 ;;
386 sunos4*)
387 hardcode_libdir_flag_spec='-L$libdir'
388 hardcode_direct=yes
389 hardcode_minus_L=yes
390 ;;
391 sysv4)
392 case $host_vendor in
393 sni)
394 hardcode_direct=yes # is this really true???
395 ;;
396 siemens)
397 hardcode_direct=no
398 ;;
399 motorola)
400 hardcode_direct=no #Motorola manual says yes, but my tests say they lie
401 ;;
402 esac
403 ;;
404 sysv4.3*)
405 ;;
406 sysv4*MP*)
407 if test -d /usr/nec; then
408 ld_shlibs=yes
409 fi
410 ;;
411 sysv4.2uw2*)
412 hardcode_direct=yes
413 hardcode_minus_L=no
414 ;;
415 sysv5OpenUNIX8* | sysv5UnixWare7* | sysv5uw[78]* | unixware7*)
416 ;;
417 sysv5*)
418 hardcode_libdir_flag_spec=
419 ;;
420 uts4*)
421 hardcode_libdir_flag_spec='-L$libdir'
422 ;;
423 *)
424 ld_shlibs=no
425 ;;
426 esac
427 fi
428
429 # Check dynamic linker characteristics
430 # Code taken from libtool.m4's AC_LIBTOOL_SYS_DYNAMIC_LINKER.
431 libname_spec='lib$name'
432 case "$host_os" in
433 aix3*)
434 ;;
435 aix4* | aix5*)
436 ;;
437 amigaos*)
438 ;;
439 beos*)
440 ;;
441 bsdi4*)
442 ;;
443 cygwin* | mingw* | pw32*)
444 shrext=.dll
445 ;;
446 darwin* | rhapsody*)
447 shrext=.dylib
448 ;;
449 dgux*)
450 ;;
451 freebsd1*)
452 ;;
453 freebsd*)
454 ;;
455 gnu*)
456 ;;
457 hpux9* | hpux10* | hpux11*)
458 case "$host_cpu" in
459 ia64*)
460 shrext=.so
461 ;;
462 hppa*64*)
463 shrext=.sl
464 ;;
465 *)
466 shrext=.sl
467 ;;
468 esac
469 ;;
470 irix5* | irix6* | nonstopux*)
471 case "$host_os" in
472 irix5* | nonstopux*)
473 libsuff= shlibsuff=
474 ;;
475 *)
476 case $LD in
477 *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ") libsuff= shlibsuff= ;;
478 *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ") libsuff=32 shlibsuff=N32 ;;
479 *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ") libsuff=64 shlibsuff=64 ;;
480 *) libsuff= shlibsuff= ;;
481 esac
482 ;;
483 esac
484 ;;
485 linux*oldld* | linux*aout* | linux*coff*)
486 ;;
487 linux*)
488 ;;
489 netbsd*)
490 ;;
491 newsos6)
492 ;;
493 nto-qnx)
494 ;;
495 openbsd*)
496 ;;
497 os2*)
498 libname_spec='$name'
499 shrext=.dll
500 ;;
501 osf3* | osf4* | osf5*)
502 ;;
503 sco3.2v5*)
504 ;;
505 solaris*)
506 ;;
507 sunos4*)
508 ;;
509 sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*)
510 ;;
511 sysv4*MP*)
512 ;;
513 uts4*)
514 ;;
515 esac
516
517 sed_quote_subst='s/\(["`$\\]\)/\\\1/g'
518 escaped_wl=`echo "X$wl" | sed -e 's/^X//' -e "$sed_quote_subst"`
519 shlibext=`echo "$shrext" | sed -e 's,^\.,,'`
520 escaped_hardcode_libdir_flag_spec=`echo "X$hardcode_libdir_flag_spec" | sed -e 's/^X//' -e "$sed_quote_subst"`
521
522 sed -e 's/^\([a-zA-Z0-9_]*\)=/acl_cv_\1=/' <<EOF
523
524 # How to pass a linker flag through the compiler.
525 wl="$escaped_wl"
526
527 # Static library suffix (normally "a").
528 libext="$libext"
529
530 # Shared library suffix (normally "so").
531 shlibext="$shlibext"
532
533 # Flag to hardcode \$libdir into a binary during linking.
534 # This must work even if \$libdir does not exist.
535 hardcode_libdir_flag_spec="$escaped_hardcode_libdir_flag_spec"
536
537 # Whether we need a single -rpath flag with a separated argument.
538 hardcode_libdir_separator="$hardcode_libdir_separator"
539
540 # Set to yes if using DIR/libNAME.so during linking hardcodes DIR into the
541 # resulting binary.
542 hardcode_direct="$hardcode_direct"
543
544 # Set to yes if using the -LDIR flag during linking hardcodes DIR into the
545 # resulting binary.
546 hardcode_minus_L="$hardcode_minus_L"
547
548 EOF