OSDN Git Service

Replace valid memory checks with new myfault class "exception handling", almost
[pf3gnuchains/pf3gnuchains4x.git] / winsup / cygwin / cygmagic
1 #!/bin/sh
2 # cygmagic - Generate "magic numbers" from a structure.
3 #
4 #   Copyright 2001, 2002 Red Hat, Inc.
5 #
6 # This file is part of Cygwin.
7 #
8 # This software is a copyrighted work licensed under the terms of the
9 # Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
10 # details.
11
12 file_magic=$1; shift
13 gcc=$1; shift
14 file=$1; shift
15 trap "rm -f /tmp/$$.magic" 0 1 2 15
16 cat <<EOF > $file_magic
17 /* autogenerated - do not edit */
18 #include "$file"
19 EOF
20 sumit() {
21     cksum $*
22 }
23
24 while [ -n "$1" ]; do
25     define=$1; shift
26     struct=$1; shift
27     sum=`$gcc -E $file | sed -n "/^$struct/,/^};/p" | sed -e 's/[       ]//g' -e '/^$/d' | sumit | awk '{printf "0x%xU", $1}'`
28     echo "#define $define $sum"
29     curr=`sed -n "s/^#[         ]*define CURR_$define[  ][      ]*\([^  ][^     ]*\)/\1/p" $file`
30     [ "$curr" != "$sum" ] && echo "*** WARNING WARNING WARNING WARNING WARNING ***
31 *** $file: magic number for $define changed old $curr != new $sum
32 *** WARNING WARNING WARNING WARNING WARNING ***" 1>&2
33 done >> $file_magic
34 exit 0