+2001-09-09 Bruno Haible <haible@clisp.cons.org>
+
+ * xmalloc.h: New file.
+ * strstr.h: New file.
+ * system.h (xmalloc, xrealloc, xstrdup): Remove declarations, now in
+ xmalloc.h.
+ (parse_printf_format, asprintf): Remove declarations.
+ (strstr): Remove declaration, now in strstr.h.
+ * xmalloc.c: Include xmalloc.h. Modernize. Assume <stdlib.h> exists.
+ * xstrdup.c: Include xmalloc.h. Modernize. Assume <string.h> exists.
+ * concatpath.c: Include xmalloc.h.
+ * findprog.c: Likewise.
+ * fstrcmp.c: Include xmalloc.h instead of system.h.
+ * javacomp.c: Likewise.
+ * javaexec.c: Likewise.
+ * sh-quote.c: Likewise.
+ * hash.c: Include xmalloc.h. Don't declare xmalloc, xcalloc.
+ * xgetcwd.c: Include stdlib.h and xmalloc.h. Don't declare xmalloc,
+ xstrdup, free.
+ * Makefile.am (libnlsut_a_HEADER): Add xmalloc.h.
+ (LIBADD_HEADER): Add strstr.h.
+
+ * Makefile.am (INCLUDES): Add -I$(top_srcdir)/intl. Needed because
+ some files include "libgettext.h", in the case $builddir != $srcdir.
+
2001-09-25 Bruno Haible <haible@clisp.cons.org>
* javacomp.c (compile_java_class): Recognize javac exit code 2.
libnlsut_a_HEADER = c-ctype.h execute.h findprog.h fstrcmp.h full-write.h \
gcd.h getopt.h hash.h javacomp.h javaexec.h lbrkprop.h linebreak.h mbswidth.h \
obstack.h pathmax.h pipe.h progname.h sh-quote.h system.h tmpdir.h \
-utf8-ucs4.h utf16-ucs4.h wait-process.h xerror.h
+utf8-ucs4.h utf16-ucs4.h wait-process.h xerror.h xmalloc.h
# Sources that are compiled only on platforms that lack the functions.
stpcpy.c stpncpy.c strcasecmp.c strcspn.c strncasecmp.c strpbrk.c strstr.c \
strtol.c strtoul.c vasprintf.c
-LIBADD_HEADER = error.h getline.h mkdtemp.h setenv.h strpbrk.h
+LIBADD_HEADER = error.h getline.h mkdtemp.h setenv.h strpbrk.h strstr.h
# Unused sources.
gen-lbrkprop.c 3level.h
DEFS = -DLIBDIR=\"$(libdir)\" @DEFS@
-INCLUDES = -I. -I$(srcdir) -I.. -I../intl
+INCLUDES = -I. -I$(srcdir) -I.. -I../intl -I$(top_srcdir)/intl
all-local: @STDBOOL_H@
/* Specification. */
#include "system.h"
+#include "xmalloc.h"
+
/* Concatenate a directory pathname, a relative pathname and an optional
suffix. The directory may end with the directory separator. The second
argument may not start with the directory separator (it is relative).
# include <unistd.h>
#endif
+#include "xmalloc.h"
#include "system.h"
#include <stdio.h>
#include <limits.h>
-#include "system.h"
+#include "xmalloc.h"
/*
((number of chars in common) / (average length of the strings)).
This is admittedly biased towards finding that the strings are
similar, however it does produce meaningful results. */
- return ((double) (string[0].data_length + string[1].data_length -
- string[1].edit_count - string[0].edit_count) / (string[0].data_length
- + string[1].data_length));
+ return ((double) (string[0].data_length + string[1].data_length
+ - string[1].edit_count - string[0].edit_count)
+ / (string[0].data_length + string[1].data_length));
}
# include <values.h>
#endif
+#include "xmalloc.h"
+
#define obstack_chunk_alloc xmalloc
#define obstack_chunk_free free
# define bcopy(S, D, N) memcpy ((D), (S), (N))
#endif
-extern void *xmalloc PARAMS ((size_t __n));
-extern void *xcalloc PARAMS ((size_t __n, size_t __m));
-
typedef struct hash_entry
{
unsigned long used;
#include "execute.h"
#include "setenv.h"
#include "sh-quote.h"
-#include "system.h"
+#include "xmalloc.h"
#include "error.h"
#include "libgettext.h"
#include "execute.h"
#include "setenv.h"
#include "sh-quote.h"
-#include "system.h"
+#include "xmalloc.h"
#include "error.h"
#include "libgettext.h"
#include <string.h>
#include "strpbrk.h"
-#include "system.h"
+#include "xmalloc.h"
#define SHELL_SPECIAL_CHARS "\t\n !\"#$&'()*;<=>?[\\]`{|}~"
--- /dev/null
+/* Searching in a string.
+ Copyright (C) 2001 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+#ifndef PARAMS
+# if defined (__GNUC__) || __STDC__
+# define PARAMS(Args) Args
+# else
+# define PARAMS(Args) ()
+# endif
+#endif
+
+#if HAVE_STRSTR
+
+/* Get strstr() declaration. */
+#include <string.h>
+
+#else
+
+/* Find the first occurrence of NEEDLE in HAYSTACK. */
+extern char *strstr PARAMS ((const char *haystack, const char *needle));
+
+#endif
/* Wrapper functions with error checking for standard functions. */
extern char *xgetcwd PARAMS ((void));
-extern void *xmalloc PARAMS ((size_t __n));
-extern void *xrealloc PARAMS ((void *__p, size_t __n));
-extern char *xstrdup PARAMS ((const char *__string));
extern char *stpcpy PARAMS ((char *__dst, const char *__src));
extern char *stpncpy PARAMS ((char *__dst, const char *__src, size_t __n));
-extern size_t parse_printf_format PARAMS ((const char *__fmt, size_t __n,
- int *__argtypes));
-extern int asprintf PARAMS ((char **, const char *, ...));
extern int strcasecmp PARAMS ((const char *__s1, const char *__s2));
extern int strncasecmp PARAMS ((const char *__s1, const char *__s2,
size_t __n));
-extern char *strstr PARAMS ((const char *__str, const char *__sub));
#include <string.h>
#if !STDC_HEADERS && HAVE_MEMORY_H
# include <config.h>
#endif
+#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#ifndef errno
# define getcwd(Buf, Max) getwd (Buf)
#endif
-extern void *xmalloc ();
-extern char *xstrdup ();
-extern void free ();
+#include "xmalloc.h"
/* Return the current directory, newly allocated, arbitrarily long.
Return NULL and set errno on error. */
# include <config.h>
#endif
-#if __STDC__
-# define VOID void
-#else
-# define VOID char
-#endif
-
-#include <sys/types.h>
+/* Specification. */
+#include "xmalloc.h"
-#if HAVE_STDLIB_H
-# include <stdlib.h>
-#else
-VOID *calloc ();
-VOID *malloc ();
-VOID *realloc ();
-void free ();
-#endif
-
-#if ENABLE_NLS
-# include <libintl.h>
-# define _(Text) gettext (Text)
-#else
-# define textdomain(Domain)
-# define _(Text) Text
-#endif
+#include <stdlib.h>
#include "error.h"
+#include "libgettext.h"
#ifndef EXIT_FAILURE
# define EXIT_FAILURE 1
#endif
-#ifndef NULL
-# define NULL ((VOID *) 0)
-#endif
+#define _(str) gettext (str)
-/* Prototypes for functions defined here. */
-#if defined (__GNUC__) || (defined (__STDC__) && __STDC__)
-static VOID *fixup_null_alloc (size_t n);
-VOID *xmalloc (size_t n);
-VOID *xcalloc (size_t n, size_t s);
-VOID *xrealloc (VOID *p, size_t n);
-#endif
+
+/* Prototypes for local functions. Needed to ensure compiler checking of
+ function argument counts despite of K&R C function definition syntax. */
+static void *fixup_null_alloc PARAMS ((size_t n));
/* Exit value when the requested amount of memory is not available.
The caller may set it to some other value. */
int xmalloc_exit_failure = EXIT_FAILURE;
-#if __STDC__ && (HAVE_VPRINTF || HAVE_DOPRNT)
-extern void error (int, int, const char *, ...);
-#else
-extern void error ();
-#endif
-
-static VOID *
+static void *
fixup_null_alloc (n)
size_t n;
{
- VOID *p;
+ void *p;
p = 0;
if (n == 0)
/* Allocate N bytes of memory dynamically, with error checking. */
-VOID *
+void *
xmalloc (n)
size_t n;
{
- VOID *p;
+ void *p;
p = malloc (n);
if (p == NULL)
/* Allocate memory for N elements of S bytes, with error checking. */
-VOID *
+void *
xcalloc (n, s)
size_t n, s;
{
- VOID *p;
+ void *p;
p = calloc (n, s);
if (p == NULL)
with error checking.
If P is NULL, run xmalloc. */
-VOID *
+void *
xrealloc (p, n)
- VOID *p;
+ void *p;
size_t n;
{
if (p == NULL)
--- /dev/null
+/* malloc with out of memory checking.
+ Copyright (C) 2001 Free Software Foundation, Inc.
+ Written by Bruno Haible <haible@clisp.cons.org>, 2001.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+#ifndef _XMALLOC_H
+#define _XMALLOC_H
+
+#include <stddef.h>
+
+
+/* Defined in xmalloc.c. */
+
+/* Allocate SIZE bytes of memory dynamically, with error checking. */
+extern void *xmalloc PARAMS ((size_t size));
+
+/* Allocate memory for NMEMB elements of SIZE bytes, with error checking. */
+extern void *xcalloc PARAMS ((size_t nmemb, size_t size));
+
+/* Change the size of an allocated block of memory PTR to SIZE bytes,
+ with error checking. If PTR is NULL, run xmalloc. */
+extern void *xrealloc PARAMS ((void *ptr, size_t size));
+
+
+/* Defined in xstrdup.c. */
+
+/* Return a newly allocated copy of STRING. */
+extern char *xstrdup PARAMS ((const char *string));
+
+
+#endif /* _XMALLOC_H */
/* xstrdup.c -- copy a string with out of memory checking
- Copyright (C) 1990, 1996, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1990, 1996, 2000, 2001 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
# include <config.h>
#endif
-#if HAVE_STRING_H
-# include <string.h>
-#else
-# include <strings.h>
-#endif
+/* Specification. */
+#include "xmalloc.h"
-#if defined (__GNUC__) || (defined (__STDC__) && __STDC__)
-extern char *xmalloc (size_t);
-#else
-extern char *xmalloc ();
-#endif
+#include <string.h>
/* Return a newly allocated copy of STRING. */
+2001-09-09 Bruno Haible <haible@clisp.cons.org>
+
+ * file-list.c: Include system.h.
+ * format-c.c: Include xmalloc.h instead of system.h.
+ * format-ycp.c: Likewise.
+ * read-po.c: Likewise.
+ * x-po.c: Likewise.
+ * format-java.c: Include xmalloc.h.
+ * format-lisp.c: Likewise.
+ * format-python.c: Likewise.
+ * gettext.c: Likewise.
+ * msgen.c: Likewise.
+ * msgexec.c: Likewise.
+ * msggrep.c: Likewise.
+ * ngettext.c: Likewise.
+ * po-lex.c: Likewise.
+ * read-mo.c: Likewise.
+ * x-c.c: Likewise.
+ * message.c: Include xmalloc.h and strstr.h.
+ * msgfmt.c: Likewise.
+ * write-po.c: Likewise.
+ * msgl-cat.c: Include string.h, xmalloc.h and strstr.h.
+ * msgl-iconv.c: Likewise.
+ * msgl-charset.c: Include strstr.h.
+ * po-charset.c: Likewise.
+ * po-gram-gen.y: Include stdlib.h, xmalloc.h instead of system.h.
+ * po-hash-gen.y: Likewise.
+ * str-list.c: Likewise.
+ * po.c: Include string.h, xmalloc.h instead of system.h.
+ * write-java.c: Include string.h, xmalloc.h.
+ * x-java.l: Include stdlib.h, xmalloc.h, strstr.h instead of system.h.
+ * xgettext.c: Include xmalloc.h, strstr.h, xerror.h.
+ (main, construct_header): Use xasprintf instead of asprintf.
+
2001-09-24 Bruno Haible <haible@clisp.cons.org>
* po-lex.c (mb_iseq): Compare the byte sequence, not the Unicode
#include "str-list.h"
#include "error.h"
+#include "system.h"
#include "getline.h"
#include "libgettext.h"
#include <stdlib.h>
#include "format.h"
-#include "system.h"
+#include "xmalloc.h"
#include "error.h"
#include "progname.h"
#include "libgettext.h"
#include "format.h"
#include "c-ctype.h"
+#include "xmalloc.h"
#include "system.h"
#include "error.h"
#include "progname.h"
#include "format.h"
#include "c-ctype.h"
#include "gcd.h"
+#include "xmalloc.h"
#include "system.h"
#include "error.h"
#include "progname.h"
#include <string.h>
#include "format.h"
+#include "xmalloc.h"
#include "system.h"
#include "error.h"
#include "progname.h"
#include <stdlib.h>
#include "format.h"
-#include "system.h"
+#include "xmalloc.h"
#include "error.h"
#include "progname.h"
#include "libgettext.h"
#include <locale.h>
#include "error.h"
+#include "xmalloc.h"
#include "system.h"
#ifdef TESTS
#include <string.h>
#include "fstrcmp.h"
+#include "xmalloc.h"
+#include "strstr.h"
#include "system.h"
#include "error.h"
#include "progname.h"
#include "message.h"
-#include <system.h>
+#include "system.h"
#include "libgettext.h"
#include "po.h"
#include "str-list.h"
#include "message.h"
#include "read-po.h"
#include "write-po.h"
+#include "xmalloc.h"
#include "system.h"
#include "libgettext.h"
#include "write-po.h"
#include "str-list.h"
#include "msgl-charset.h"
+#include "xmalloc.h"
#include "system.h"
#include "findprog.h"
#include "pipe.h"
#include "xerror.h"
#include "getline.h"
#include "format.h"
+#include "xmalloc.h"
+#include "strstr.h"
#include "system.h"
#include "msgfmt.h"
#include "write-mo.h"
#include "write-po.h"
#include "str-list.h"
#include "msgl-charset.h"
+#include "xmalloc.h"
#include "system.h"
#include "full-write.h"
#include "findprog.h"
#include "msgl-cat.h"
#include <stdlib.h>
+#include <string.h>
#include "error.h"
#include "xerror.h"
#include "po-charset.h"
#include "msgl-ascii.h"
#include "msgl-iconv.h"
+#include "xmalloc.h"
+#include "strstr.h"
#include "system.h"
#include "libgettext.h"
#include "progname.h"
#include "xerror.h"
#include "message.h"
+#include "strstr.h"
#include "system.h"
#include "libgettext.h"
#include <errno.h>
#include <stdlib.h>
+#include <string.h>
#if HAVE_ICONV
# include <iconv.h>
#include "message.h"
#include "po-charset.h"
#include "msgl-ascii.h"
+#include "xmalloc.h"
+#include "strstr.h"
#include "system.h"
#include "libgettext.h"
#include <errno.h>
#include "error.h"
+#include "xmalloc.h"
#include "system.h"
#include "libgettext.h"
#include "error.h"
#include "xerror.h"
+#include "strstr.h"
#include "system.h"
#include "libgettext.h"
#include "po-gram.h"
#include <stdio.h>
+#include <stdlib.h>
#include "str-list.h"
#include "po-lex.h"
#include "error.h"
-#include "system.h"
+#include "xmalloc.h"
#include "libgettext.h"
#include "po.h"
#include "po-hash.h"
#include <stdio.h>
+#include <stdlib.h>
-#include "system.h"
+#include "xmalloc.h"
#include "po.h"
/* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
#include "str-list.h"
#include "po-charset.h"
+#include "xmalloc.h"
#include "system.h"
#include "error.h"
#include "open-po.h"
#include "po.h"
#include <stdlib.h>
+#include <string.h>
#include "po-charset.h"
#include "po-hash.h"
-#include "system.h"
+#include "xmalloc.h"
/* Prototypes for local functions. Needed to ensure compiler checking of
function argument counts despite of K&R C function definition syntax. */
#include "gettext.h"
#include "error.h"
+#include "xmalloc.h"
#include "system.h"
#include "message.h"
#include "libgettext.h"
#include <string.h>
#include "po.h"
-#include "system.h"
+#include "xmalloc.h"
#include "libgettext.h"
#define _(str) gettext (str)
#include "str-list.h"
#include <stdio.h>
+#include <stdlib.h>
-#include "system.h"
+#include "xmalloc.h"
/* Initialize an empty list of strings. */
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
+#include <string.h>
#include <signal.h>
#include <sys/stat.h>
#include "pathmax.h"
#include "plural-exp.h"
#include "po-charset.h"
+#include "xmalloc.h"
#include "system.h"
#include "tmpdir.h"
#include "utf8-ucs4.h"
#include "c-ctype.h"
#include "linebreak.h"
#include "msgl-ascii.h"
+#include "xmalloc.h"
+#include "strstr.h"
#include "system.h"
#include "error.h"
#include "xerror.h"
#include "xgettext.h"
#include "error.h"
#include "progname.h"
+#include "xmalloc.h"
#include "system.h"
#include "hash.h"
#include "libgettext.h"
#endif
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include "message.h"
#include "x-java.h"
#include "xgettext.h"
-#include "system.h"
+#include "xmalloc.h"
+#include "strstr.h"
typedef enum
{
#include "message.h"
#include "x-po.h"
#include "xgettext.h"
-#include "system.h"
+#include "xmalloc.h"
#include "po.h"
#include "po-lex.h"
#include "libgettext.h"
#include "progname.h"
#include "xerror.h"
#include "getline.h"
+#include "xmalloc.h"
+#include "strstr.h"
+#include "xerror.h"
#include "system.h"
#include "po.h"
#include "message.h"
if (optarg[len - 1] == '/')
output_dir = xstrdup (optarg);
else
- {
- asprintf (&output_dir, "%s/", optarg);
- if (output_dir == NULL)
- /* We are about to construct the absolute path to the
- directory for the output files but asprintf failed. */
- error (EXIT_FAILURE, errno, _("while preparing output"));
- }
+ output_dir = xasprintf ("%s/", optarg);
}
break;
case 's':
tz_sign = '-';
}
- asprintf (&msgstr, "\
+ msgstr = xasprintf ("\
Project-Id-Version: PACKAGE VERSION\n\
POT-Creation-Date: %d-%02d-%02d %02d:%02d%c%02ld%02ld\n\
PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n\
local_time.tm_min,
tz_sign, tz_min / 60, tz_min % 60);
- if (msgstr == NULL)
- error (EXIT_FAILURE, errno, _("while preparing output"));
-
mp = message_alloc ("", NULL, msgstr, strlen (msgstr) + 1, &pos);
if (foreign_user)