2020-11-13 01:58:58 +08:00
|
|
|
#!/bin/bash
|
2002-01-14 04:03:03 +08:00
|
|
|
# cygmagic - Generate "magic numbers" from a structure.
|
|
|
|
#
|
|
|
|
# This file is part of Cygwin.
|
|
|
|
#
|
|
|
|
# This software is a copyrighted work licensed under the terms of the
|
|
|
|
# Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
# details.
|
|
|
|
|
2020-11-13 01:58:58 +08:00
|
|
|
set -e
|
|
|
|
shopt -s -o pipefail
|
|
|
|
shopt -s inherit_errexit
|
|
|
|
|
2001-12-26 12:53:34 +08:00
|
|
|
file_magic=$1; shift
|
|
|
|
gcc=$1; shift
|
|
|
|
file=$1; shift
|
2020-11-13 01:58:58 +08:00
|
|
|
|
|
|
|
tmpfile=/tmp/$$.magic
|
2001-12-26 12:53:34 +08:00
|
|
|
trap "rm -f /tmp/$$.magic" 0 1 2 15
|
2020-11-13 01:58:58 +08:00
|
|
|
|
|
|
|
cat <<EOF > $tmpfile
|
2001-12-26 12:53:34 +08:00
|
|
|
/* autogenerated - do not edit */
|
|
|
|
#include "$file"
|
|
|
|
EOF
|
2020-11-13 01:58:58 +08:00
|
|
|
|
2002-08-27 12:10:54 +08:00
|
|
|
sumit() {
|
|
|
|
cksum $*
|
|
|
|
}
|
2002-01-22 11:02:00 +08:00
|
|
|
|
2001-12-26 12:53:34 +08:00
|
|
|
while [ -n "$1" ]; do
|
|
|
|
define=$1; shift
|
|
|
|
struct=$1; shift
|
2016-02-13 06:02:13 +08:00
|
|
|
sum=`$gcc -D__CYGMAGIC__ -E -P $file | sed -n "/^$struct/,/^};/p" | sed -e 's/[ ]//g' -e '/^$/d' | sumit | awk '{printf "0x%xU", $1}'`
|
2001-12-26 12:53:34 +08:00
|
|
|
echo "#define $define $sum"
|
|
|
|
curr=`sed -n "s/^#[ ]*define CURR_$define[ ][ ]*\([^ ][^ ]*\)/\1/p" $file`
|
2002-01-05 07:29:58 +08:00
|
|
|
[ "$curr" != "$sum" ] && echo "*** WARNING WARNING WARNING WARNING WARNING ***
|
2001-12-27 05:35:16 +08:00
|
|
|
*** $file: magic number for $define changed old $curr != new $sum
|
2001-12-26 12:53:34 +08:00
|
|
|
*** WARNING WARNING WARNING WARNING WARNING ***" 1>&2
|
2020-11-13 01:58:58 +08:00
|
|
|
done >> $tmpfile
|
|
|
|
|
|
|
|
mv $tmpfile $file_magic
|
|
|
|
|
2001-12-26 12:53:34 +08:00
|
|
|
exit 0
|