37 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			37 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
#!/bin/sh
 | 
						|
# cygmagic - Generate "magic numbers" from a structure.
 | 
						|
#
 | 
						|
#   Copyright 2001, 2002 Red Hat, Inc.
 | 
						|
#
 | 
						|
# 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.
 | 
						|
 | 
						|
file_magic=$1; shift
 | 
						|
gcc=$1; shift
 | 
						|
file=$1; shift
 | 
						|
trap "rm -f /tmp/$$.magic" 0 1 2 15
 | 
						|
cat <<EOF > $file_magic
 | 
						|
/* autogenerated - do not edit */
 | 
						|
#include "$file"
 | 
						|
EOF
 | 
						|
if sum -r /dev/null >/dev/null 2>&1; then
 | 
						|
  sumit(){ sum -r $*; }
 | 
						|
else
 | 
						|
  sumit(){ sum $*; }
 | 
						|
fi
 | 
						|
 | 
						|
while [ -n "$1" ]; do
 | 
						|
    define=$1; shift
 | 
						|
    struct=$1; shift
 | 
						|
    sum=`$gcc -E $file | sed -n "/^$struct/,/^};/p" | sed -e 's/[ 	]//g' -e '/^$/d' | sumit | awk '{printf "0x%x", $1}'`
 | 
						|
    echo "#define $define $sum"
 | 
						|
    curr=`sed -n "s/^#[ 	]*define CURR_$define[ 	][ 	]*\([^ 	][^ 	]*\)/\1/p" $file`
 | 
						|
    [ "$curr" != "$sum" ] && echo "*** WARNING WARNING WARNING WARNING WARNING ***
 | 
						|
*** $file: magic number for $define changed old $curr != new $sum
 | 
						|
*** WARNING WARNING WARNING WARNING WARNING ***" 1>&2
 | 
						|
done >> $file_magic
 | 
						|
exit 0
 |