2001-09-17 04:12:20 +00:00
|
|
|
/* $IdPath$
|
2001-11-03 05:17:51 +00:00
|
|
|
* Includes standard headers and defines prototypes for replacement functions
|
|
|
|
|
* if needed. This is the *only* header file which should include other
|
|
|
|
|
* header files!
|
2001-06-13 05:24:50 +00:00
|
|
|
*
|
|
|
|
|
* Copyright (C) 2001 Peter Johnson
|
|
|
|
|
*
|
2002-10-22 19:46:27 +00:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
|
* are met:
|
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2001-06-13 05:24:50 +00:00
|
|
|
*
|
2002-10-22 19:46:27 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS''
|
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE
|
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
2001-06-13 05:24:50 +00:00
|
|
|
*/
|
2001-06-28 21:22:01 +00:00
|
|
|
#ifndef YASM_UTIL_H
|
|
|
|
|
#define YASM_UTIL_H
|
2001-06-13 05:24:50 +00:00
|
|
|
|
2003-03-15 05:07:49 +00:00
|
|
|
#ifdef YASM_LIB_INTERNAL
|
|
|
|
|
# define YASM_INTERNAL
|
|
|
|
|
# define YASM_AUTOCONF_INTERNAL
|
|
|
|
|
# define YASM_LIB_AC_INTERNAL
|
|
|
|
|
# define YASM_GETTEXT_INTERNAL
|
2001-11-03 05:17:51 +00:00
|
|
|
#endif
|
|
|
|
|
|
2003-03-15 05:07:49 +00:00
|
|
|
#ifdef YASM_INTERNAL
|
|
|
|
|
|
|
|
|
|
#if defined(YASM_LIB_AC_INTERNAL) && defined(HAVE_CONFIG_H)
|
2003-03-26 05:07:57 +00:00
|
|
|
# include <libyasm/config.h>
|
2003-05-03 08:02:15 +00:00
|
|
|
|
|
|
|
|
/* Work around glibc's non-defining of certain things when using gcc -ansi */
|
|
|
|
|
# if defined(HAVE_GNU_C_LIBRARY) && defined(__STRICT_ANSI__)
|
|
|
|
|
# undef __STRICT_ANSI__
|
|
|
|
|
# endif
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
#ifdef YASM_INTERNAL
|
|
|
|
|
|
|
|
|
|
#if defined(YASM_LIB_AC_INTERNAL) && defined(HAVE_CONFIG_H)
|
|
|
|
|
# include <stdarg.h>
|
2003-03-15 05:07:49 +00:00
|
|
|
#endif
|
2001-11-03 05:17:51 +00:00
|
|
|
|
2003-03-16 00:17:08 +00:00
|
|
|
#if !defined(lint) && !defined(NDEBUG)
|
2001-12-03 03:05:51 +00:00
|
|
|
# define NDEBUG
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-03-15 05:07:49 +00:00
|
|
|
#ifdef YASM_AUTOCONF_INTERNAL
|
2001-09-20 06:43:19 +00:00
|
|
|
|
2003-03-15 05:07:49 +00:00
|
|
|
# ifdef STDC_HEADERS
|
|
|
|
|
# include <stddef.h>
|
|
|
|
|
# include <stdlib.h>
|
|
|
|
|
# include <string.h>
|
|
|
|
|
# include <assert.h>
|
2001-12-02 06:40:17 +00:00
|
|
|
# endif
|
|
|
|
|
|
2003-03-15 05:07:49 +00:00
|
|
|
# ifdef YASM_GETTEXT_INTERNAL
|
|
|
|
|
# if defined(lint)
|
|
|
|
|
# define _(String) String
|
|
|
|
|
# else
|
|
|
|
|
# ifdef HAVE_LOCALE_H
|
|
|
|
|
# include <locale.h>
|
|
|
|
|
# endif
|
|
|
|
|
|
|
|
|
|
# ifdef ENABLE_NLS
|
|
|
|
|
# include <libintl.h>
|
|
|
|
|
# define _(String) gettext(String)
|
|
|
|
|
# else
|
|
|
|
|
# define gettext(Msgid) (Msgid)
|
|
|
|
|
# define dgettext(Domainname, Msgid) (Msgid)
|
|
|
|
|
# define dcgettext(Domainname, Msgid, Category) (Msgid)
|
|
|
|
|
# define textdomain(Domainname) while (0) /* nothing */
|
|
|
|
|
# define bindtextdomain(Domainname, Dirname) while (0) /* nothing */
|
|
|
|
|
# define _(String) (String)
|
|
|
|
|
# endif
|
|
|
|
|
# endif
|
2001-12-02 06:40:17 +00:00
|
|
|
|
2003-03-15 05:07:49 +00:00
|
|
|
# ifdef gettext_noop
|
|
|
|
|
# define N_(String) gettext_noop(String)
|
|
|
|
|
# else
|
|
|
|
|
# define N_(String) (String)
|
|
|
|
|
# endif
|
2001-11-03 05:17:51 +00:00
|
|
|
|
2003-03-15 05:07:49 +00:00
|
|
|
# endif /*YASM_GETTEXT_INTERNAL*/
|
|
|
|
|
|
|
|
|
|
#endif /*YASM_AUTOCONF_INTERNAL*/
|
|
|
|
|
|
|
|
|
|
int yasm__mergesort(void *base, size_t nmemb, size_t size,
|
|
|
|
|
int (*compar)(const void *, const void *));
|
2001-10-26 04:32:18 +00:00
|
|
|
|
2003-03-15 05:07:49 +00:00
|
|
|
#if defined(YASM_AUTOCONF_INTERNAL) && defined(HAVE_MERGESORT)
|
|
|
|
|
#define yasm__mergesort(a, b, c, d) mergesort(a, b, c, d)
|
2001-09-24 05:57:28 +00:00
|
|
|
#endif
|
|
|
|
|
|
2003-03-15 05:07:49 +00:00
|
|
|
/*@null@*/ char *yasm__strsep(char **stringp, const char *delim);
|
|
|
|
|
|
|
|
|
|
#if defined(YASM_AUTOCONF_INTERNAL) && defined(HAVE_STRSEP)
|
|
|
|
|
#define yasm__strsep(a, b) strsep(a, b)
|
2001-09-20 06:25:05 +00:00
|
|
|
#endif
|
|
|
|
|
|
2003-03-08 20:35:36 +00:00
|
|
|
int yasm__strcasecmp(const char *s1, const char *s2);
|
|
|
|
|
int yasm__strncasecmp(const char *s1, const char *s2, size_t n);
|
2003-03-15 05:07:49 +00:00
|
|
|
|
|
|
|
|
#ifdef YASM_AUTOCONF_INTERNAL
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_STRCASECMP
|
|
|
|
|
# define yasm__strcasecmp(x, y) strcasecmp(x, y)
|
|
|
|
|
# define yasm__strncasecmp(x, y, n) strncasecmp(x, y, n)
|
|
|
|
|
#elif HAVE_STRICMP
|
|
|
|
|
# define yasm__strcasecmp(x, y) stricmp(x, y)
|
|
|
|
|
# define yasm__strncasecmp(x, y, n) strnicmp(x, y, n)
|
|
|
|
|
#elif HAVE_STRCMPI
|
|
|
|
|
# define yasm__strcasecmp(x, y) strcmpi(x, y)
|
|
|
|
|
# define yasm__strncasecmp(x, y, n) strncmpi(x, y, n)
|
|
|
|
|
#else
|
|
|
|
|
# define USE_OUR_OWN_STRCASECMP
|
2001-09-16 09:13:00 +00:00
|
|
|
#endif
|
|
|
|
|
|
2001-12-24 18:01:12 +00:00
|
|
|
#if !defined(HAVE_TOASCII) || defined(lint)
|
2001-06-29 02:11:36 +00:00
|
|
|
# define toascii(c) ((c) & 0x7F)
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-03-15 05:07:49 +00:00
|
|
|
#endif /*YASM_AUTOCONF_INTERNAL*/
|
2001-08-19 07:32:39 +00:00
|
|
|
|
2003-03-26 05:07:57 +00:00
|
|
|
#include <libyasm/compat-queue.h>
|
2003-03-15 05:07:49 +00:00
|
|
|
|
|
|
|
|
#if defined(YASM_AUTOCONF_INTERNAL) && defined(HAVE_SYS_CDEFS_H)
|
2001-08-19 07:32:39 +00:00
|
|
|
# include <sys/cdefs.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef __RCSID
|
|
|
|
|
# define RCSID(s) __RCSID(s)
|
|
|
|
|
#else
|
2001-09-19 09:06:54 +00:00
|
|
|
# ifdef __GNUC__
|
|
|
|
|
# ifdef __ELF__
|
|
|
|
|
# define RCSID(s) __asm__(".ident\t\"" s "\"")
|
|
|
|
|
# else
|
2001-10-21 00:13:24 +00:00
|
|
|
# define RCSID(s) static const char rcsid[] = s
|
2001-09-19 09:06:54 +00:00
|
|
|
# endif
|
|
|
|
|
# else
|
|
|
|
|
# define RCSID(s) static const char rcsid[] = s
|
|
|
|
|
# endif
|
2001-08-19 04:32:02 +00:00
|
|
|
#endif
|
|
|
|
|
|
2001-11-03 05:17:51 +00:00
|
|
|
/* strdup() implementation with error checking (using xmalloc). */
|
2003-03-12 06:08:43 +00:00
|
|
|
/*@only@*/ char *yasm__xstrdup(const char *str);
|
2003-03-15 05:07:49 +00:00
|
|
|
/*@only@*/ char *yasm__xstrndup(const char *str, size_t len);
|
|
|
|
|
|
|
|
|
|
#endif /*YASM_INTERNAL*/
|
2001-11-03 05:17:51 +00:00
|
|
|
|
2003-03-12 06:08:43 +00:00
|
|
|
/* Error-checking memory allocation routines. Default implementations in
|
|
|
|
|
* xmalloc.c.
|
|
|
|
|
*/
|
|
|
|
|
extern /*@only@*/ /*@out@*/ void * (*yasm_xmalloc) (size_t size);
|
|
|
|
|
extern /*@only@*/ void * (*yasm_xcalloc) (size_t nelem, size_t elsize);
|
|
|
|
|
extern /*@only@*/ void * (*yasm_xrealloc)
|
|
|
|
|
(/*@only@*/ /*@out@*/ /*@returned@*/ /*@null@*/ void *oldmem, size_t size)
|
|
|
|
|
/*@modifies oldmem@*/;
|
|
|
|
|
extern void (*yasm_xfree) (/*@only@*/ /*@out@*/ /*@null@*/ void *p)
|
|
|
|
|
/*@modifies p@*/;
|
2002-10-22 07:45:45 +00:00
|
|
|
|
2003-03-15 05:07:49 +00:00
|
|
|
#ifdef YASM_INTERNAL
|
2001-11-03 05:17:51 +00:00
|
|
|
|
2003-03-15 05:07:49 +00:00
|
|
|
#if defined(YASM_AUTOCONF_INTERNAL) && defined(WITH_DMALLOC)
|
|
|
|
|
# include <dmalloc.h>
|
|
|
|
|
|
|
|
|
|
#define yasm__xstrdup(str) xstrdup(str)
|
|
|
|
|
#define yasm_xmalloc(size) xmalloc(size)
|
|
|
|
|
#define yasm_xcalloc(count, size) xcalloc(count, size)
|
|
|
|
|
#define yasm_xrealloc(ptr, size) xrealloc(ptr, size)
|
|
|
|
|
#define yasm_xfree(ptr) xfree(ptr)
|
|
|
|
|
#endif
|
2002-08-07 01:04:34 +00:00
|
|
|
|
2002-03-10 20:21:50 +00:00
|
|
|
/* Bit-counting: used primarily by HAMT but also in a few other places. */
|
|
|
|
|
#define SK5 0x55555555
|
|
|
|
|
#define SK3 0x33333333
|
|
|
|
|
#define SKF0 0x0F0F0F0F
|
|
|
|
|
#define BitCount(d, s) do { \
|
|
|
|
|
d = s; \
|
|
|
|
|
d -= (d>>1) & SK5; \
|
|
|
|
|
d = (d & SK3) + ((d>>2) & SK3); \
|
|
|
|
|
d = (d & SKF0) + ((d>>4) & SKF0); \
|
|
|
|
|
d += d>>16; \
|
|
|
|
|
d += d>>8; \
|
|
|
|
|
} while (0)
|
|
|
|
|
|
2002-04-21 18:55:19 +00:00
|
|
|
/* Get the number of elements in an array. */
|
|
|
|
|
#ifndef NELEMS
|
|
|
|
|
#define NELEMS(array) (sizeof(array) / sizeof(array[0]))
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-03-15 05:07:49 +00:00
|
|
|
#endif /*YASM_INTERNAL*/
|
|
|
|
|
|
2003-03-26 05:07:57 +00:00
|
|
|
#include <libyasm/coretype.h>
|
2001-11-03 05:17:51 +00:00
|
|
|
|
2003-03-26 05:07:57 +00:00
|
|
|
#include <libyasm/valparam.h>
|
2001-11-18 18:44:26 +00:00
|
|
|
|
2001-06-13 05:24:50 +00:00
|
|
|
#endif
|