You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

make_macros.sh 4.1 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/bin/sh
  2. include_dir=../../include/openssl
  3. cat > "${include_dir}/stack_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. #if !defined(IN_STACK_H)
  18. #error "Don't include this file directly. Include stack.h."
  19. #endif
  20. EOF
  21. output_stack () {
  22. type=$1
  23. ptrtype=$2
  24. cat >> "${include_dir}/stack_macros.h" << EOF
  25. /* ${type} */
  26. #define sk_${type}_new(comp)\\
  27. ((STACK_OF(${type})*) sk_new(CHECKED_CAST(stack_cmp_func, int (*) (const ${ptrtype} *a, const ${ptrtype} *b), comp)))
  28. #define sk_${type}_new_null()\\
  29. ((STACK_OF(${type})*) sk_new_null())
  30. #define sk_${type}_num(sk)\\
  31. sk_num(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk))
  32. #define sk_${type}_zero(sk)\\
  33. sk_zero(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk));
  34. #define sk_${type}_value(sk, i)\\
  35. ((${ptrtype}) sk_value(CHECKED_CAST(_STACK*, const STACK_OF(${type})*, sk), (i)))
  36. #define sk_${type}_set(sk, i, p)\\
  37. ((${ptrtype}) sk_set(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk), (i), CHECKED_CAST(void*, ${ptrtype}, p)))
  38. #define sk_${type}_free(sk)\\
  39. sk_free(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk))
  40. #define sk_${type}_pop_free(sk, free_func)\\
  41. sk_pop_free(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk), CHECKED_CAST(void (*) (void*), void (*) (${ptrtype}), free_func))
  42. #define sk_${type}_insert(sk, p, where)\\
  43. sk_insert(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk), CHECKED_CAST(void*, ${ptrtype}, p), (where))
  44. #define sk_${type}_delete(sk, where)\\
  45. ((${ptrtype}) sk_delete(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk), (where)))
  46. #define sk_${type}_delete_ptr(sk, p)\\
  47. ((${ptrtype}) sk_delete_ptr(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk), CHECKED_CAST(void*, ${ptrtype}, p)))
  48. #define sk_${type}_find(sk, out_index, p)\\
  49. sk_find(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk), (out_index), CHECKED_CAST(void*, ${ptrtype}, p))
  50. #define sk_${type}_shift(sk)\\
  51. ((${ptrtype}) sk_shift(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk)))
  52. #define sk_${type}_push(sk, p)\\
  53. sk_push(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk), CHECKED_CAST(void*, ${ptrtype}, p))
  54. #define sk_${type}_pop(sk)\\
  55. ((${ptrtype}) sk_pop(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk)))
  56. #define sk_${type}_dup(sk)\\
  57. ((STACK_OF(${type})*) sk_dup(CHECKED_CAST(_STACK*, const STACK_OF(${type})*, sk)))
  58. #define sk_${type}_sort(sk)\\
  59. sk_sort(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk))
  60. #define sk_${type}_is_sorted(sk)\\
  61. sk_is_sorted(CHECKED_CAST(_STACK*, const STACK_OF(${type})*, sk))
  62. #define sk_${type}_set_cmp_func(sk, comp)\\
  63. ((int (*) (const ${type} **a, const ${type} **b)) sk_set_cmp_func(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk), CHECKED_CAST(stack_cmp_func, int (*) (const ${type} **a, const ${type} **b), comp)))
  64. EOF
  65. }
  66. stack_types=$(cat "${include_dir}/stack.h" | grep '^ \* STACK_OF:' | sed -e 's/.*STACK_OF://' -e 's/ .*//')
  67. const_stack_types=$(cat "${include_dir}/stack.h" | grep '^ \* CONST_STACK_OF:' | sed -e 's/.*CONST_STACK_OF://' -e 's/ .*//')
  68. special_stack_types=$(cat "${include_dir}/stack.h" | grep '^ \* SPECIAL_STACK_OF:' | sed -e 's/.*SPECIAL_STACK_OF://' -e 's/ .*//')
  69. for type in $stack_types; do
  70. echo Stack of ${type}
  71. output_stack "${type}" "${type} *"
  72. done
  73. for type in $const_stack_types; do
  74. echo Stack of ${type}
  75. output_stack "${type}" "const ${type} *"
  76. done
  77. for type in $special_stack_types; do
  78. echo Stack of ${type}
  79. output_stack "${type}" "${type}"
  80. done
  81. clang-format -i "${include_dir}/stack_macros.h"