list-identifiers.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #!/bin/bash
  2. #
  3. # Create a file named identifiers containing identifiers from internal header
  4. # files or all header files, based on --internal flag.
  5. # Outputs the line count of the file to stdout.
  6. #
  7. # Usage: list-identifiers.sh [ -i | --internal ]
  8. #
  9. # Copyright The Mbed TLS Contributors
  10. # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
  11. #
  12. # This file is provided under the Apache License 2.0, or the
  13. # GNU General Public License v2.0 or later.
  14. #
  15. # **********
  16. # Apache License 2.0:
  17. #
  18. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  19. # not use this file except in compliance with the License.
  20. # You may obtain a copy of the License at
  21. #
  22. # http://www.apache.org/licenses/LICENSE-2.0
  23. #
  24. # Unless required by applicable law or agreed to in writing, software
  25. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  26. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  27. # See the License for the specific language governing permissions and
  28. # limitations under the License.
  29. #
  30. # **********
  31. #
  32. # **********
  33. # GNU General Public License v2.0 or later:
  34. #
  35. # This program is free software; you can redistribute it and/or modify
  36. # it under the terms of the GNU General Public License as published by
  37. # the Free Software Foundation; either version 2 of the License, or
  38. # (at your option) any later version.
  39. #
  40. # This program is distributed in the hope that it will be useful,
  41. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  42. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  43. # GNU General Public License for more details.
  44. #
  45. # You should have received a copy of the GNU General Public License along
  46. # with this program; if not, write to the Free Software Foundation, Inc.,
  47. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  48. #
  49. # **********
  50. set -eu
  51. if [ -d include/mbedtls ]; then :; else
  52. echo "$0: must be run from root" >&2
  53. exit 1
  54. fi
  55. INTERNAL=""
  56. until [ -z "${1-}" ]
  57. do
  58. case "$1" in
  59. -i|--internal)
  60. INTERNAL="1"
  61. ;;
  62. *)
  63. # print error
  64. echo "Unknown argument: '$1'"
  65. exit 1
  66. ;;
  67. esac
  68. shift
  69. done
  70. if [ $INTERNAL ]
  71. then
  72. HEADERS=$( ls include/mbedtls/*_internal.h | egrep -v 'compat-1\.3\.h|bn_mul' )
  73. else
  74. HEADERS=$( ls include/mbedtls/*.h | egrep -v 'compat-1\.3\.h|bn_mul' )
  75. fi
  76. rm -f identifiers
  77. grep '^[^ /#{]' $HEADERS | \
  78. sed -e 's/^[^:]*://' | \
  79. egrep -v '^(extern "C"|(typedef )?(struct|enum)( {)?$|};?$)' \
  80. > _decls
  81. if true; then
  82. sed -n -e 's/.* \**\([a-zA-Z_][a-zA-Z0-9_]*\)(.*/\1/p' \
  83. -e 's/.*(\*\(.*\))(.*/\1/p' _decls
  84. grep -v '(' _decls | sed -e 's/\([a-zA-Z0-9_]*\)[;[].*/\1/' -e 's/.* \**//'
  85. fi > _identifiers
  86. if [ $( wc -l < _identifiers ) -eq $( wc -l < _decls ) ]; then
  87. rm _decls
  88. egrep -v '^(u?int(16|32|64)_t)$' _identifiers | sort > identifiers
  89. rm _identifiers
  90. else
  91. echo "$0: oops, lost some identifiers" 2>&1
  92. exit 1
  93. fi
  94. wc -l identifiers