+2004-02-04 Hrvoje Niksic <hniksic@xemacs.org>
+
+ * hash.c: Make the file compilable outside Wget source tree when
+ -DSTANDALONE is used.
+
2004-01-29 Hrvoje Niksic <hniksic@xemacs.org>
* utils.c (determine_screen_width): Return 0 if not running on
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 <config.h>
-#endif
+/* With -DSTANDALONE, this file can be compiled outside Wget source
+ tree. To test, also use -DTEST. */
-#ifdef HAVE_STRING_H
-# include <string.h>
+#ifndef STANDALONE
+# include <config.h>
+# ifdef HAVE_STRING_H
+# include <string.h>
+# else
+# include <strings.h>
+# endif
+# ifdef HAVE_LIMITS_H
+# include <limits.h>
+# endif
#else
-# include <strings.h>
-#endif
-#ifdef HAVE_LIMITS_H
+/* If running without Autoconf, go ahead and assume presence of
+ standard C89 headers. */
+# include <string.h>
# include <limits.h>
#endif
+
#include <stdlib.h>
#include <assert.h>
-#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
/*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));
return ptr1 == ptr2;
}
\f
-#ifdef STANDALONE
+#ifdef TEST
#include <stdio.h>
#include <string.h>
#endif
return 0;
}
-#endif
+#endif /* TEST */