From 91ebe986e41bae373fb367b06dc16162691f7a34 Mon Sep 17 00:00:00 2001 From: hniksic Date: Wed, 4 Feb 2004 04:32:46 -0800 Subject: [PATCH] [svn] Make hash.c compilable outside the source tree. --- src/ChangeLog | 5 +++++ src/hash.c | 57 +++++++++++++++++++++++++++++---------------------- 2 files changed, 38 insertions(+), 24 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index dacb4e7e..993f05bf 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2004-02-04 Hrvoje Niksic + + * hash.c: Make the file compilable outside Wget source tree when + -DSTANDALONE is used. + 2004-01-29 Hrvoje Niksic * utils.c (determine_screen_width): Return 0 if not running on diff --git a/src/hash.c b/src/hash.c index f86c6726..f3ebb0f3 100644 --- a/src/hash.c +++ b/src/hash.c @@ -27,39 +27,47 @@ modify this file, you may extend this exception to your version of the file, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ -#ifdef HAVE_CONFIG_H -# include -#endif +/* With -DSTANDALONE, this file can be compiled outside Wget source + tree. To test, also use -DTEST. */ -#ifdef HAVE_STRING_H -# include +#ifndef STANDALONE +# include +# ifdef HAVE_STRING_H +# include +# else +# include +# endif +# ifdef HAVE_LIMITS_H +# include +# endif #else -# include -#endif -#ifdef HAVE_LIMITS_H +/* If running without Autoconf, go ahead and assume presence of + standard C89 headers. */ +# include # include #endif + #include #include -#include "wget.h" -#include "utils.h" - -#include "hash.h" - -#ifdef STANDALONE -# undef xmalloc -# undef xrealloc -# undef xfree - -# define xmalloc malloc -# define xrealloc realloc +#ifndef STANDALONE +/* Get Wget's utility headers. */ +# include "wget.h" +# include "utils.h" +#else +/* Make do without them. */ +# define xnew(x) xmalloc (sizeof (x)) +# define xnew_array(type, x) xmalloc (sizeof (type) * (x)) +# define xmalloc malloc /* or something that exits + if not enough memory */ # define xfree free - -# undef TOLOWER +# define countof(x) (sizeof (x) / sizeof ((x)[0])) # define TOLOWER(x) ('A' <= (x) && (x) <= 'Z' ? (x) - 32 : (x)) +# define PARAMS(x) x #endif +#include "hash.h" + /* INTERFACE: Hash tables are a technique used to implement mapping between @@ -286,6 +294,7 @@ hash_table_new (int items, /*assert (ht->resize_threshold >= items);*/ ht->mappings = xnew_array (struct mapping, ht->size); + /* Mark mappings as empty. We use 0xff rather than 0 to mark empty keys because it allows us to use NULL/0 as keys. */ memset (ht->mappings, INVALID_PTR_BYTE, size * sizeof (struct mapping)); @@ -692,7 +701,7 @@ ptrcmp (const void *ptr1, const void *ptr2) return ptr1 == ptr2; } -#ifdef STANDALONE +#ifdef TEST #include #include @@ -746,4 +755,4 @@ main (void) #endif return 0; } -#endif +#endif /* TEST */ -- 2.39.2