diff options
-rw-r--r-- | aclocal.m4 | 14 | ||||
-rw-r--r-- | configure.in | 11 | ||||
-rw-r--r-- | misc/Makefile.am | 17 | ||||
-rw-r--r-- | misc/Makefile.in | 33 | ||||
-rw-r--r-- | misc/error.c | 248 | ||||
-rw-r--r-- | misc/error.h | 78 | ||||
-rw-r--r-- | misc/misc-fnmatch.h | 67 | ||||
-rw-r--r-- | misc/misc-glob.h | 97 | ||||
-rw-r--r-- | misc/stpcpy.c | 51 | ||||
-rw-r--r-- | misc/stpncpy.c | 101 | ||||
-rw-r--r-- | misc/strcasecmp.c | 77 | ||||
-rw-r--r-- | misc/strcspn.c | 52 | ||||
-rw-r--r-- | misc/strncasecmp.c | 80 | ||||
-rw-r--r-- | tools/.cvsignore | 2 | ||||
-rw-r--r-- | tools/Makefile.am | 2 | ||||
-rw-r--r-- | tools/Makefile.in | 2 | ||||
-rw-r--r-- | tools/rpmgettext.c | 10 |
17 files changed, 752 insertions, 190 deletions
diff --git a/aclocal.m4 b/aclocal.m4 index 3a6b95298..4a6d871ba 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -244,6 +244,20 @@ case "x$am_cv_prog_cc_stdc" in esac ]) +dnl From Jim Meyering. Use this if you use the GNU error.[ch]. +dnl FIXME: Migrate into libit + +AC_DEFUN(AM_FUNC_ERROR_AT_LINE, +[AC_CACHE_CHECK([for error_at_line], am_cv_lib_error_at_line, + [AC_TRY_LINK([],[error_at_line(0, 0, "", 0, "");], + am_cv_lib_error_at_line=yes, + am_cv_lib_error_at_line=no)]) + if test $am_cv_lib_error_at_line = no; then + LIBOBJS="$LIBOBJS error.o" + fi + AC_SUBST(LIBOBJS)dnl +]) + # Macro to add for using GNU gettext. # Ulrich Drepper <drepper@cygnus.com>, 1995. # diff --git a/configure.in b/configure.in index 8a4021d4d..b96718d83 100644 --- a/configure.in +++ b/configure.in @@ -323,6 +323,9 @@ for zlib in z gz ; do ) done +dnl XXX these are needed only by rpmgettext right now +AM_FUNC_ERROR_AT_LINE + dnl ==> AM_GNU_GETTEXT does this (and more) dnl AC_CHECK_HEADERS(unistd.h limits.h locale.h malloc.h string.h sys/param.h) @@ -395,6 +398,7 @@ AC_TYPE_PID_T dnl Checks for library functions. AC_FUNC_ALLOCA +AC_FUNC_VPRINTF AC_FUNC_FNMATCH if test $ac_cv_func_fnmatch_works = no; then @@ -409,10 +413,13 @@ dnl XXX AC_FUNC_STRCOLL dnl XXX AC_FUNC_STRFTIME dnl XXX AC_FUNC_UTIME_NULL dnl XXX AC_FUNC_VFORK -dnl XXX AC_FUNC_VPRINTF dnl XXX AC_CHECK_FUNCS(gethostname lchown mkdir mkfifo rmdir select uname) -AC_REPLACE_FUNCS(getcwd getwd glob inet_aton putenv realpath strdup strerror strtol strtoul strspn strstr) +AC_REPLACE_FUNCS(getcwd getwd glob inet_aton putenv realpath) +AC_REPLACE_FUNCS(strdup strerror strtol strtoul strspn strstr) + +dnl XXX stpcpy/stpncpy needed by rpmgettext +AC_REPLACE_FUNCS(stpcpy stpncpy strcasecmp strncasecmp strcspn) AC_CHECK_FUNCS(setlocale) diff --git a/misc/Makefile.am b/misc/Makefile.am index 2b7dec4f4..04ff934b1 100644 --- a/misc/Makefile.am +++ b/misc/Makefile.am @@ -3,14 +3,19 @@ AUTOMAKE_OPTIONS = 1.3 foreign EXTRA_DIST = \ - alloca.c fakefork.c fnmatch.c getcwd.c \ - getmntent.c getwd.c glob.c inet_aton.c \ - memcmp.c mktime.c myrealloc.c putenv.c \ - realpath.c strdup.c strerror.c strftime.c \ - strspn.c strstr.c strtol.c strtoul.c + alloca.c error.c fakefork.c fnmatch.c \ + getcwd.c getmntent.c getwd.c glob.c \ + inet_aton.c memcmp.c mktime.c myrealloc.c \ + putenv.c realpath.c stpcpy.c stpncpy.c \ + strcasecmp.c strncasecmp.c strcspn.c strdup.c \ + strerror.c strftime.c strcspn.c strstr.c \ + strtol.c strtoul.c noinst_HEADERS = \ - inet_aton.h fnmatch.h glob.h + error.h fnmatch.h glob.h inet_aton.h \ + libgettext.h message.h po-lex.h str-list.h \ + fstrcmp.h + noinst_LIBRARIES = libmisc.a libmisc_a_SOURCES = diff --git a/misc/Makefile.in b/misc/Makefile.in index e9a1828be..042bd39e0 100644 --- a/misc/Makefile.in +++ b/misc/Makefile.in @@ -116,14 +116,19 @@ varprefix = @varprefix@ AUTOMAKE_OPTIONS = 1.3 foreign EXTRA_DIST = \ - alloca.c fakefork.c fnmatch.c getcwd.c \ - getmntent.c getwd.c glob.c inet_aton.c \ - memcmp.c mktime.c myrealloc.c putenv.c \ - realpath.c strdup.c strerror.c strftime.c \ - strspn.c strstr.c strtol.c strtoul.c + alloca.c error.c fakefork.c fnmatch.c \ + getcwd.c getmntent.c getwd.c glob.c \ + inet_aton.c memcmp.c mktime.c myrealloc.c \ + putenv.c realpath.c stpcpy.c stpncpy.c \ + strcasecmp.c strncasecmp.c strcspn.c strdup.c \ + strerror.c strftime.c strcspn.c strstr.c \ + strtol.c strtoul.c noinst_HEADERS = \ - inet_aton.h fnmatch.h glob.h + error.h fnmatch.h glob.h inet_aton.h \ + libgettext.h message.h po-lex.h str-list.h \ + fstrcmp.h + noinst_LIBRARIES = libmisc.a libmisc_a_SOURCES = @@ -145,20 +150,22 @@ COMPILE = $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) LINK = $(CC) $(CFLAGS) $(LDFLAGS) -o $@ HEADERS = $(noinst_HEADERS) -DIST_COMMON = Makefile.am Makefile.in alloca.c fnmatch.c getcwd.c \ -getmntent.c getwd.c glob.c inet_aton.c myrealloc.c putenv.c realpath.c \ -strdup.c strerror.c strspn.c strstr.c strtol.c strtoul.c +DIST_COMMON = Makefile.am Makefile.in alloca.c error.c error.h \ +fnmatch.c getcwd.c getmntent.c getwd.c glob.c inet_aton.c myrealloc.c \ +putenv.c realpath.c stpcpy.c stpncpy.c strcasecmp.c strcspn.c strdup.c \ +strerror.c strncasecmp.c strspn.c strstr.c strtol.c strtoul.c DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) TAR = tar GZIP = --best -DEP_FILES = .deps/alloca.P .deps/fnmatch.P .deps/getcwd.P \ +DEP_FILES = .deps/alloca.P .deps/error.P .deps/fnmatch.P .deps/getcwd.P \ .deps/getmntent.P .deps/getwd.P .deps/glob.P .deps/inet_aton.P \ -.deps/myrealloc.P .deps/putenv.P .deps/realpath.P .deps/strdup.P \ -.deps/strerror.P .deps/strspn.P .deps/strstr.P .deps/strtol.P \ -.deps/strtoul.P +.deps/myrealloc.P .deps/putenv.P .deps/realpath.P .deps/stpcpy.P \ +.deps/stpncpy.P .deps/strcasecmp.P .deps/strcspn.P .deps/strdup.P \ +.deps/strerror.P .deps/strncasecmp.P .deps/strspn.P .deps/strstr.P \ +.deps/strtol.P .deps/strtoul.P SOURCES = $(libmisc_a_SOURCES) OBJECTS = $(libmisc_a_OBJECTS) diff --git a/misc/error.c b/misc/error.c new file mode 100644 index 000000000..140fa77ac --- /dev/null +++ b/misc/error.c @@ -0,0 +1,248 @@ +/* Error handler for noninteractive utilities + Copyright (C) 1990,91,92,93,94,95,96,97,98 Free Software Foundation, Inc. + + + NOTE: The canonical source of this file is maintained with the GNU C Library. + Bugs can be reported to bug-glibc@prep.ai.mit.edu. + + 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. */ + +/* Written by David MacKenzie <djm@gnu.ai.mit.edu>. */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <stdio.h> + +#if HAVE_VPRINTF || HAVE_DOPRNT || _LIBC +# if __STDC__ +# include <stdarg.h> +# define VA_START(args, lastarg) va_start(args, lastarg) +# else +# include <varargs.h> +# define VA_START(args, lastarg) va_start(args) +# endif +#else +# define va_alist a1, a2, a3, a4, a5, a6, a7, a8 +# define va_dcl char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8; +#endif + +#if STDC_HEADERS || _LIBC +# include <stdlib.h> +# include <string.h> +#else +void exit (); +#endif + +#include "error.h" + +#ifndef _ +# define _(String) String +#endif + +/* If NULL, error will flush stdout, then print on stderr the program + name, a colon and a space. Otherwise, error will call this + function without parameters instead. */ +void (*error_print_progname) ( +#if __STDC__ - 0 + void +#endif + ); + +/* This variable is incremented each time `error' is called. */ +unsigned int error_message_count; + +#ifdef _LIBC +/* In the GNU C library, there is a predefined variable for this. */ + +# define program_name program_invocation_name +# include <errno.h> + +/* In GNU libc we want do not want to use the common name `error' directly. + Instead make it a weak alias. */ +# define error __error +# define error_at_line __error_at_line + +#else /* not _LIBC */ + +/* The calling program should define program_name and set it to the + name of the executing program. */ +extern char *program_name; + +# ifdef HAVE_STRERROR_R +# define __strerror_r strerror_r +# else +# if HAVE_STRERROR +# ifndef strerror /* On some systems, strerror is a macro */ +char *strerror (); +# endif +# else +static char * +private_strerror (errnum) + int errnum; +{ + extern char *sys_errlist[]; + extern int sys_nerr; + + if (errnum > 0 && errnum <= sys_nerr) + return _(sys_errlist[errnum]); + return _("Unknown system error"); +} +# define strerror private_strerror +# endif /* HAVE_STRERROR */ +# endif /* HAVE_STRERROR_R */ +#endif /* not _LIBC */ + +/* Print the program name and error message MESSAGE, which is a printf-style + format string with optional args. + If ERRNUM is nonzero, print its corresponding system error message. + Exit with status STATUS if it is nonzero. */ +/* VARARGS */ + +void +#if defined VA_START && __STDC__ +error (int status, int errnum, const char *message, ...) +#else +error (status, errnum, message, va_alist) + int status; + int errnum; + char *message; + va_dcl +#endif +{ +#ifdef VA_START + va_list args; +#endif + + if (error_print_progname) + (*error_print_progname) (); + else + { + fflush (stdout); + fprintf (stderr, "%s: ", program_name); + } + +#ifdef VA_START + VA_START (args, message); +# if HAVE_VPRINTF || _LIBC + vfprintf (stderr, message, args); +# else + _doprnt (message, args, stderr); +# endif + va_end (args); +#else + fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8); +#endif + + ++error_message_count; + if (errnum) + { +#if defined HAVE_STRERROR_R || defined _LIBC + char errbuf[1024]; + fprintf (stderr, ": %s", __strerror_r (errnum, errbuf, sizeof errbuf)); +#else + fprintf (stderr, ": %s", strerror (errnum)); +#endif + } + putc ('\n', stderr); + fflush (stderr); + if (status) + exit (status); +} + +/* Sometimes we want to have at most one error per line. This + variable controls whether this mode is selected or not. */ +int error_one_per_line; + +void +#if defined VA_START && __STDC__ +error_at_line (int status, int errnum, const char *file_name, + unsigned int line_number, const char *message, ...) +#else +error_at_line (status, errnum, file_name, line_number, message, va_alist) + int status; + int errnum; + const char *file_name; + unsigned int line_number; + char *message; + va_dcl +#endif +{ +#ifdef VA_START + va_list args; +#endif + + if (error_one_per_line) + { + static const char *old_file_name; + static unsigned int old_line_number; + + if (old_line_number == line_number && + (file_name == old_file_name || !strcmp (old_file_name, file_name))) + /* Simply return and print nothing. */ + return; + + old_file_name = file_name; + old_line_number = line_number; + } + + if (error_print_progname) + (*error_print_progname) (); + else + { + fflush (stdout); + fprintf (stderr, "%s:", program_name); + } + + if (file_name != NULL) + fprintf (stderr, "%s:%d: ", file_name, line_number); + +#ifdef VA_START + VA_START (args, message); +# if HAVE_VPRINTF || _LIBC + vfprintf (stderr, message, args); +# else + _doprnt (message, args, stderr); +# endif + va_end (args); +#else + fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8); +#endif + + ++error_message_count; + if (errnum) + { +#if defined HAVE_STRERROR_R || defined _LIBC + char errbuf[1024]; + fprintf (stderr, ": %s", __strerror_r (errnum, errbuf, sizeof errbuf)); +#else + fprintf (stderr, ": %s", strerror (errnum)); +#endif + } + putc ('\n', stderr); + fflush (stderr); + if (status) + exit (status); +} + +#ifdef _LIBC +/* Make the weak alias. */ +# undef error +# undef error_at_line +weak_alias (__error, error) +weak_alias (__error_at_line, error_at_line) +#endif diff --git a/misc/error.h b/misc/error.h new file mode 100644 index 000000000..20f75824d --- /dev/null +++ b/misc/error.h @@ -0,0 +1,78 @@ +/* Declaration for error-reporting function + Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. + + + NOTE: The canonical source of this file is maintained with the GNU C Library. + Bugs can be reported to bug-glibc@prep.ai.mit.edu. + + 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 _ERROR_H +#define _ERROR_H 1 + +#ifndef __attribute__ +/* This feature is available in gcc versions 2.5 and later. */ +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__ +# define __attribute__(Spec) /* empty */ +# endif +/* The __-protected variants of `format' and `printf' attributes + are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) +# define __format__ format +# define __printf__ printf +# endif +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined (__STDC__) && __STDC__ + +/* Print a message with `fprintf (stderr, FORMAT, ...)'; + if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM). + If STATUS is nonzero, terminate the program with `exit (STATUS)'. */ + +extern void error (int status, int errnum, const char *format, ...) + __attribute__ ((__format__ (__printf__, 3, 4))); + +extern void error_at_line (int status, int errnum, const char *fname, + unsigned int lineno, const char *format, ...) + __attribute__ ((__format__ (__printf__, 5, 6))); + +/* If NULL, error will flush stdout, then print on stderr the program + name, a colon and a space. Otherwise, error will call this + function without parameters instead. */ +extern void (*error_print_progname) (void); + +#else +void error (); +void error_at_line (); +extern void (*error_print_progname) (); +#endif + +/* This variable is incremented each time `error' is called. */ +extern unsigned int error_message_count; + +/* Sometimes we want to have at most one error per line. This + variable controls whether this mode is selected or not. */ +extern int error_one_per_line; + +#ifdef __cplusplus +} +#endif + +#endif /* error.h */ diff --git a/misc/misc-fnmatch.h b/misc/misc-fnmatch.h deleted file mode 100644 index d9d73b3d8..000000000 --- a/misc/misc-fnmatch.h +++ /dev/null @@ -1,67 +0,0 @@ -/* Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc. - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Library General Public License as -published by the Free Software Foundation; either version 2 of the -License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Library General Public License for more details. - -You should have received a copy of the GNU Library General Public -License along with this library; see the file COPYING.LIB. If -not, write to the Free Software Foundation, Inc., 675 Mass Ave, -Cambridge, MA 02139, USA. */ - -#ifndef _FNMATCH_H - -#define _FNMATCH_H 1 - -#ifdef __cplusplus -extern "C" { -#endif - -#if defined (__cplusplus) || (defined (__STDC__) && __STDC__) -#undef __P -#define __P(protos) protos -#else /* Not C++ or ANSI C. */ -#undef __P -#define __P(protos) () -/* We can get away without defining `const' here only because in this file - it is used only inside the prototype for `fnmatch', which is elided in - non-ANSI C where `const' is problematical. */ -#endif /* C++ or ANSI C. */ - - -/* We #undef these before defining them because some losing systems - (HP-UX A.08.07 for example) define these in <unistd.h>. */ -#undef FNM_PATHNAME -#undef FNM_NOESCAPE -#undef FNM_PERIOD - -/* Bits set in the FLAGS argument to `fnmatch'. */ -#define FNM_PATHNAME (1 << 0) /* No wildcard can ever match `/'. */ -#define FNM_NOESCAPE (1 << 1) /* Backslashes don't quote special chars. */ -#define FNM_PERIOD (1 << 2) /* Leading `.' is matched only explicitly. */ - -#if !defined (_POSIX_C_SOURCE) || _POSIX_C_SOURCE < 2 || defined (_GNU_SOURCE) -#define FNM_FILE_NAME FNM_PATHNAME /* Preferred GNU name. */ -#define FNM_LEADING_DIR (1 << 3) /* Ignore `/...' after a match. */ -#define FNM_CASEFOLD (1 << 4) /* Compare without regard to case. */ -#endif - -/* Value returned by `fnmatch' if STRING does not match PATTERN. */ -#define FNM_NOMATCH 1 - -/* Match STRING against the filename pattern PATTERN, - returning zero if it matches, FNM_NOMATCH if not. */ -extern int fnmatch __P ((const char *__pattern, const char *__string, - int __flags)); - -#ifdef __cplusplus -} -#endif - -#endif /* fnmatch.h */ diff --git a/misc/misc-glob.h b/misc/misc-glob.h deleted file mode 100644 index 05ad47f05..000000000 --- a/misc/misc-glob.h +++ /dev/null @@ -1,97 +0,0 @@ -/* Copyright (C) 1991, 1992 Free Software Foundation, Inc. - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Library General Public License as -published by the Free Software Foundation; either version 2 of the -License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Library General Public License for more details. - -You should have received a copy of the GNU Library General Public -License along with this library; see the file COPYING.LIB. If -not, write to the Free Software Foundation, Inc., 675 Mass Ave, -Cambridge, MA 02139, USA. */ - -#ifndef _GLOB_H - -#define _GLOB_H 1 - -#ifdef __cplusplus -extern "C" -{ -#endif - -#undef __ptr_t -#if defined (__cplusplus) || (defined (__STDC__) && __STDC__) -#undef __P -#define __P(protos) protos -#define __ptr_t void * -#else /* Not C++ or ANSI C. */ -#undef __P -#define __P(protos) () -#undef const -#define const -#define __ptr_t char * -#endif /* C++ or ANSI C. */ - -/* Bits set in the FLAGS argument to `glob'. */ -#define GLOB_ERR (1 << 0)/* Return on read errors. */ -#define GLOB_MARK (1 << 1)/* Append a slash to each name. */ -#define GLOB_NOSORT (1 << 2)/* Don't sort the names. */ -#define GLOB_DOOFFS (1 << 3)/* Insert PGLOB->gl_offs NULLs. */ -#define GLOB_NOCHECK (1 << 4)/* If nothing matches, return the pattern. */ -#define GLOB_APPEND (1 << 5)/* Append to results of a previous call. */ -#define GLOB_NOESCAPE (1 << 6)/* Backslashes don't quote metacharacters. */ -#define GLOB_PERIOD (1 << 7)/* Leading `.' can be matched by metachars. */ -#define __GLOB_FLAGS (GLOB_ERR|GLOB_MARK|GLOB_NOSORT|GLOB_DOOFFS| \ - GLOB_NOESCAPE|GLOB_NOCHECK|GLOB_APPEND|GLOB_PERIOD) - -#if !defined (_POSIX_C_SOURCE) || _POSIX_C_SOURCE < 2 || defined (_BSD_SOURCE) -#define GLOB_MAGCHAR (1 << 8)/* Set in gl_flags if any metachars seen. */ -#endif - -/* Error returns from `glob'. */ -#define GLOB_NOSPACE 1 /* Ran out of memory. */ -#define GLOB_ABEND 2 /* Read error. */ -#define GLOB_NOMATCH 3 /* No matches found. */ - -/* Structure describing a globbing run. */ -typedef struct - { - int gl_pathc; /* Count of paths matched by the pattern. */ - char **gl_pathv; /* List of matched pathnames. */ - int gl_offs; /* Slots to reserve in `gl_pathv'. */ - int gl_flags; /* Set to FLAGS, maybe | GLOB_MAGCHAR. */ - } glob_t; - -/* Do glob searching for PATTERN, placing results in PGLOB. - The bits defined above may be set in FLAGS. - If a directory cannot be opened or read and ERRFUNC is not nil, - it is called with the pathname that caused the error, and the - `errno' value from the failing call; if it returns non-zero - `glob' returns GLOB_ABEND; if it returns zero, the error is ignored. - If memory cannot be allocated for PGLOB, GLOB_NOSPACE is returned. - Otherwise, `glob' returns zero. */ -extern int glob __P ((const char *__pattern, int __flags, - int (*__errfunc) __P ((const char *, int)), - glob_t *__pglob)); - -/* Free storage allocated in PGLOB by a previous `glob' call. */ -extern void globfree __P ((glob_t *__pglob)); - - -#if !defined (_POSIX_C_SOURCE) || _POSIX_C_SOURCE < 2 || defined (_GNU_SOURCE) -/* If they are not NULL, `glob' uses these functions to read directories. */ -extern __ptr_t (*__glob_opendir_hook) __P ((const char *__directory)); -extern const char *(*__glob_readdir_hook) __P ((__ptr_t __stream)); -extern void (*__glob_closedir_hook) __P ((__ptr_t __stream)); -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* glob.h */ diff --git a/misc/stpcpy.c b/misc/stpcpy.c new file mode 100644 index 000000000..0ad8863cd --- /dev/null +++ b/misc/stpcpy.c @@ -0,0 +1,51 @@ +/* Copyright (C) 1992, 1995, 1997 Free Software Foundation, Inc. + + NOTE: The canonical source of this file is maintained with the GNU C Library. + Bugs can be reported to bug-glibc@prep.ai.mit.edu. + + 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. */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <string.h> + +#undef __stpcpy +#undef stpcpy + +#ifndef weak_alias +# define __stpcpy stpcpy +#endif + +/* Copy SRC to DEST, returning the address of the terminating '\0' in DEST. */ +char * +__stpcpy (dest, src) + char *dest; + const char *src; +{ + register char *d = dest; + register const char *s = src; + + do + *d++ = *s; + while (*s++ != '\0'); + + return d - 1; +} +#ifdef weak_alias +weak_alias (__stpcpy, stpcpy) +#endif diff --git a/misc/stpncpy.c b/misc/stpncpy.c new file mode 100644 index 000000000..fcbdfe505 --- /dev/null +++ b/misc/stpncpy.c @@ -0,0 +1,101 @@ +/* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc. + + NOTE: The canonical source of this file is maintained with the GNU C Library. + Bugs can be reported to bug-glibc@prep.ai.mit.edu. + + 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. */ + +/* This is almost copied from strncpy.c, written by Torbjorn Granlund. */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#ifdef _LIBC +# include <string.h> +#else +# include <sys/types.h> +#endif + +#ifndef weak_alias +# define __stpncpy stpncpy +#endif + +/* Copy no more than N characters of SRC to DEST, returning the address of + the terminating '\0' in DEST, if any, or else DEST + N. */ +char * +__stpncpy (dest, src, n) + char *dest; + const char *src; + size_t n; +{ + char c; + char *s = dest; + + if (n >= 4) + { + size_t n4 = n >> 2; + + for (;;) + { + c = *src++; + *dest++ = c; + if (c == '\0') + break; + c = *src++; + *dest++ = c; + if (c == '\0') + break; + c = *src++; + *dest++ = c; + if (c == '\0') + break; + c = *src++; + *dest++ = c; + if (c == '\0') + break; + if (--n4 == 0) + goto last_chars; + } + n -= dest - s; + goto zero_fill; + } + + last_chars: + n &= 3; + if (n == 0) + return dest; + + for (;;) + { + c = *src++; + --n; + *dest++ = c; + if (c == '\0') + break; + if (n == 0) + return dest; + } + + zero_fill: + while (n-- > 0) + dest[n] = '\0'; + + return dest - 1; +} +#ifdef weak_alias +weak_alias (__stpncpy, stpncpy) +#endif diff --git a/misc/strcasecmp.c b/misc/strcasecmp.c new file mode 100644 index 000000000..776d62ada --- /dev/null +++ b/misc/strcasecmp.c @@ -0,0 +1,77 @@ +/* Copyright (C) 1991, 1992, 1995, 1996, 1997 Free Software Foundation, Inc. + + NOTE: The canonical source of this file is maintained with the GNU C Library. + Bugs can be reported to bug-glibc@prep.ai.mit.edu. + + 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. */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <ctype.h> +#include <string.h> + +#ifndef weak_alias +# define __strcasecmp strcasecmp +# define TOLOWER(Ch) tolower (Ch) +#else +# ifdef USE_IN_EXTENDED_LOCALE_MODEL +# define __strcasecmp __strcasecmp_l +# define TOLOWER(Ch) __tolower_l ((Ch), loc) +# else +# define TOLOWER(Ch) tolower (Ch) +# endif +#endif + +#ifdef USE_IN_EXTENDED_LOCALE_MODEL +# define LOCALE_PARAM , loc +# define LOCALE_PARAM_DECL __locale_t loc; +#else +# define LOCALE_PARAM +# define LOCALE_PARAM_DECL +#endif + +/* Compare S1 and S2, ignoring case, returning less than, equal to or + greater than zero if S1 is lexicographically less than, + equal to or greater than S2. */ +int +__strcasecmp (s1, s2 LOCALE_PARAM) + const char *s1; + const char *s2; + LOCALE_PARAM_DECL +{ + const unsigned char *p1 = (const unsigned char *) s1; + const unsigned char *p2 = (const unsigned char *) s2; + unsigned char c1, c2; + + if (p1 == p2) + return 0; + + do + { + c1 = TOLOWER (*p1++); + c2 = TOLOWER (*p2++); + if (c1 == '\0') + break; + } + while (c1 == c2); + + return c1 - c2; +} +#ifndef __strcasecmp +weak_alias (__strcasecmp, strcasecmp) +#endif diff --git a/misc/strcspn.c b/misc/strcspn.c new file mode 100644 index 000000000..6c2e0b8a8 --- /dev/null +++ b/misc/strcspn.c @@ -0,0 +1,52 @@ +/* Copyright (C) 1991, 1994, 1996, 1997 Free Software Foundation, Inc. + + NOTE: The canonical source of this file is maintained with the GNU C Library. + Bugs can be reported to bug-glibc@prep.ai.mit.edu. + + 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. */ + +#if HAVE_CONFIG_H +# include <config.h> +#endif + +#if defined _LIBC || HAVE_STRING_H +# include <string.h> +#else +# include <strings.h> +# ifndef strchr +# define strchr index +# endif +#endif + +#undef strcspn + +/* Return the length of the maximum initial segment of S + which contains no characters from REJECT. */ +size_t +strcspn (s, reject) + const char *s; + const char *reject; +{ + size_t count = 0; + + while (*s != '\0') + if (strchr (reject, *s++) == NULL) + ++count; + else + return count; + + return count; +} diff --git a/misc/strncasecmp.c b/misc/strncasecmp.c new file mode 100644 index 000000000..52af434b1 --- /dev/null +++ b/misc/strncasecmp.c @@ -0,0 +1,80 @@ +/* Compare at most N characters of two strings without taking care for + the case. + Copyright (C) 1992, 1996, 1997 Free Software Foundation, Inc. + + NOTE: The canonical source of this file is maintained with the GNU C Library. + Bugs can be reported to bug-glibc@prep.ai.mit.edu. + + 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. */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <string.h> +#include <ctype.h> + +#ifndef weak_alias +# define __strncasecmp strncasecmp +# define TOLOWER(Ch) tolower (Ch) +#else +# ifdef USE_IN_EXTENDED_LOCALE_MODEL +# define __strncasecmp __strncasecmp_l +# define TOLOWER(Ch) __tolower_l ((Ch), loc) +# else +# define TOLOWER(Ch) tolower (Ch) +# endif +#endif + +#ifdef USE_IN_EXTENDED_LOCALE_MODEL +# define LOCALE_PARAM , loc +# define LOCALE_PARAM_DECL __locale_t loc; +#else +# define LOCALE_PARAM +# define LOCALE_PARAM_DECL +#endif + +/* Compare no more than N characters of S1 and S2, + ignoring case, returning less than, equal to or + greater than zero if S1 is lexicographically less + than, equal to or greater than S2. */ +int +__strncasecmp (s1, s2, n LOCALE_PARAM) + const char *s1; + const char *s2; + size_t n; + LOCALE_PARAM_DECL +{ + const unsigned char *p1 = (const unsigned char *) s1; + const unsigned char *p2 = (const unsigned char *) s2; + unsigned char c1, c2; + + if (p1 == p2 || n == 0) + return 0; + + do + { + c1 = TOLOWER (*p1++); + c2 = TOLOWER (*p2++); + if (c1 == '\0' || c1 != c2) + return c1 - c2; + } while (--n > 0); + + return c1 - c2; +} +#ifndef __strncasecmp +weak_alias (__strncasecmp, strncasecmp) +#endif diff --git a/tools/.cvsignore b/tools/.cvsignore index ba1f40dae..441682b34 100644 --- a/tools/.cvsignore +++ b/tools/.cvsignore @@ -7,3 +7,5 @@ rpmheader rpmarchive rpmsignature dumpdb +rpmgettext +rpmputtext diff --git a/tools/Makefile.am b/tools/Makefile.am index da16b3e4e..9cedc5476 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -7,6 +7,8 @@ INCLUDES = -I../build -I../lib -I../intl -I../misc @INCPATH@ LDFLAGS = -L../popt -L../build -L../lib -L../misc LDADD = -lrpm +EXTRA_DIST = fstrcmp.c message.c str-list.c + noinst_PROGRAMS = rpmlead rpmheader rpmarchive rpmsignature dump dumpdb \ rpmgettext rpmputtext diff --git a/tools/Makefile.in b/tools/Makefile.in index 6d87a7cbf..270468916 100644 --- a/tools/Makefile.in +++ b/tools/Makefile.in @@ -120,6 +120,8 @@ INCLUDES = -I../build -I../lib -I../intl -I../misc @INCPATH@ LDFLAGS = -L../popt -L../build -L../lib -L../misc LDADD = -lrpm +EXTRA_DIST = fstrcmp.c message.c str-list.c + noinst_PROGRAMS = rpmlead rpmheader rpmarchive rpmsignature dump dumpdb \ rpmgettext rpmputtext diff --git a/tools/rpmgettext.c b/tools/rpmgettext.c index e95f9250c..3c2ecfbf8 100644 --- a/tools/rpmgettext.c +++ b/tools/rpmgettext.c @@ -28,7 +28,7 @@ static void dpf(char *format, ...) #define DPRINTF(_lvl, _fmt) #endif -const char *progname = NULL; +const char *program_name = NULL; int debug = MYDEBUG; int verbose = 0; char *inputdir = "/mnt/redhat/comps/dist/5.2"; @@ -963,7 +963,7 @@ main(int argc, char **argv) extern int optind; int errflg = 0; - progname = basename(argv[0]); + program_name = basename(argv[0]); while((c = getopt(argc, argv, "deEl:I:O:Tv")) != EOF) switch (c) { @@ -1003,7 +1003,7 @@ main(int argc, char **argv) /* XXX I don't want to read rpmrc yet */ rpmSetVar(RPMVAR_TMPPATH, "/tmp"); - if (!strcmp(progname, RPMGETTEXT)) { + if (!strcmp(program_name, RPMGETTEXT)) { if (optind == argc) { rc = rpmgettext(0, STDINFN, stdout); } else { @@ -1012,7 +1012,7 @@ main(int argc, char **argv) break; } } - } else if (!strcmp(progname, RPMPUTTEXT)) { + } else if (!strcmp(program_name, RPMPUTTEXT)) { if (optind == argc) { rc = rpmputtext(0, STDINFN, stdout); } else { @@ -1021,7 +1021,7 @@ main(int argc, char **argv) break; } } - } else if (!strcmp(progname, RPMCHKTEXT)) { + } else if (!strcmp(program_name, RPMCHKTEXT)) { if (optind == argc) { rc = rpmchktext(0, STDINFN, stdout); } else { |