1#!/bin/sh
2
3cat > lhash_macros.h << EOF
4/* Copyright (c) 2014, Google Inc.
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
13 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
15 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
16 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
17
18#if !defined(IN_LHASH_H)
19#error "Don't include this file directly. Include lhash.h"
20#endif
21
22EOF
23
24output_lhash () {
25  type=$1
26
27  cat >> lhash_macros.h << EOF
28/* ${type} */
29#define lh_${type}_new(hash, comp)\\
30((LHASH_OF(${type})*) lh_new(CHECKED_CAST(lhash_hash_func, uint32_t (*) (const ${type} *), hash), CHECKED_CAST(lhash_cmp_func, int (*) (const ${type} *a, const ${type} *b), comp)))
31
32#define lh_${type}_free(lh)\\
33  lh_free(CHECKED_CAST(_LHASH*, LHASH_OF(${type})*, lh));
34
35#define lh_${type}_num_items(lh)\\
36  lh_num_items(CHECKED_CAST(_LHASH*, LHASH_OF(${type})*, lh))
37
38#define lh_${type}_retrieve(lh, data)\\
39  ((${type}*) lh_retrieve(CHECKED_CAST(_LHASH*, LHASH_OF(${type})*, lh), CHECKED_CAST(void*, ${type}*, data)))
40
41#define lh_${type}_insert(lh, old_data, data)\\
42  lh_insert(CHECKED_CAST(_LHASH*, LHASH_OF(${type})*, lh), CHECKED_CAST(void**, ${type}**, old_data), CHECKED_CAST(void*, ${type}*, data))
43
44#define lh_${type}_delete(lh, data)\\
45  ((${type}*) lh_delete(CHECKED_CAST(_LHASH*, LHASH_OF(${type})*, lh), CHECKED_CAST(void*, ${type}*, data)))
46
47#define lh_${type}_doall(lh, func)\\
48  lh_doall(CHECKED_CAST(_LHASH*, LHASH_OF(${type})*, lh), CHECKED_CAST(void (*)(void*), void (*) (${type}*), func));
49
50#define lh_${type}_doall_arg(lh, func, arg)\\
51  lh_doall_arg(CHECKED_CAST(_LHASH*, LHASH_OF(${type})*, lh), CHECKED_CAST(void (*)(void*, void*), void (*) (${type}*, void*), func), arg);
52
53
54EOF
55}
56
57lhash_types=$(cat lhash.h | grep '^ \* LHASH_OF:' | sed -e 's/.*LHASH_OF://' -e 's/ .*//')
58
59for type in $lhash_types; do
60  echo Hash of ${type}
61  output_lhash "${type}"
62done
63
64clang-format -i lhash_macros.h
65