1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
#!/bin/sh
set -eu
# enum name checklist, for libreswan
#
# Copyright (C) 2023-2024 Andrew Cagney
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version. See <https://www.gnu.org/licenses/gpl2.txt>.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
names=$1 ; shift
list()
{
# The special comment /* #ifdef MACRO */, at the end of a
# declaration is used to flag that the declaration should be
# wrapped in #ifdef MACRO. Just the macro name is included.
{
sed -n \
-e "s/^extern ${names} \([a-z0-9_]*\);.* #ifdef \([A-Z0-9_]*\).*$/\1 \2/p" \
-e "s/^extern ${names} \([a-z0-9_]*\);.*$/\1/p" \
-e "s/^extern const struct ${names} \([a-z0-9_]*\);.* #ifdef \([A-Z0-9_]*\).*$/\1 \2/p" \
-e "s/^extern const struct ${names} \([a-z0-9_]*\);.*$/\1/p" \
"$@"
} | {
sort
}
}
echo $(list "$@") 1>&2
cat <<EOF
/* enum name checklist, for libreswan
*
* Copyright (C) 2023-2024 Andrew Cagney
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <https://www.gnu.org/licenses/gpl2.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
EOF
echo
echo '#include "constants.h" /* for typedef ${names} */'
echo '#include "enum_names.h"'
echo
grep -e "^extern ${names} " -e "^extern const struct ${names} " "$@" | \
cut -d: -f1 | \
cut -d/ -f4- | \
sort -u | \
while read h ; do
echo '#include "'${h}'"'
done
echo
echo "const struct ${names}_check ${names}_checklist[] = {"
list "$@" | while read name ifdef ; do
test -z "${ifdef}" || echo "#ifdef ${ifdef}"
echo " { \"${name}\", &${name}, },"
test -z "${ifdef}" || echo "#endif"
done
echo " { NULL, NULL, }"
echo "};"
|