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