From 690ddf3e4ef9900f777f2476decc5f8e3aac401c Mon Sep 17 00:00:00 2001 From: Per Bothner Date: Mon, 9 Aug 1993 18:56:14 -0700 Subject: [PATCH] Initial revision From-SVN: r5124 --- gcc/scan-types.sh | 149 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100755 gcc/scan-types.sh diff --git a/gcc/scan-types.sh b/gcc/scan-types.sh new file mode 100755 index 00000000000..be02123a6e2 --- /dev/null +++ b/gcc/scan-types.sh @@ -0,0 +1,149 @@ +#! /bin/sh +# Deduce values of standard ANSI and POSIX types (e.g. size_t, pid_t). +# Emits macros definitions for these, and some other types. +# Intended to be used to massage the sys-protos.h file. + +CC=${CC-./xgcc} +CPP=${CPP-`echo ${CC} -E`} +SED=sed + +# Generate definitions for the standard types (such as mode_t) +# compatible with those in the standard C header files. +# It works by a dummy program through the C pre-processor, and then +# using sed to search for typedefs in the output. + +cat >dummy.c < +#include +#include +#include +#include +#include +#ifdef size_t +typedef size_t Xsize_t; +#elif defined(__SIZE_TYPE__) +typedef __SIZE_TYPE__ Xsize_t; +#endif +#ifdef ptrdiff_t +typedef ptrdiff_t Xptrdiff_t; +#elif defined(__PTRDIFF_TYPE__) +typedef __PTRDIFF_TYPE__ Xptrdiff_t; +#endif +#ifdef wchar_t +typedef wchar_t Xwchar_t; +#elif defined(__WCHAR_TYPE__) +typedef __WCHAR_TYPE__ Xwchar_t; +#endif +#ifdef va_list +typedef va_list XXXva_list; +#endif +!EOF! + +if ${CPP} dummy.c >TMP ; then true +else + echo "gen-params: could not invoke ${CPP} on dummy.c" 1>&2 ; exit 1 +fi +tr ' ' ' ' dummy.out + +for TYPE in dev_t clock_t fpos_t gid_t ino_t mode_t nlink_t off_t pid_t ptrdiff_t sigset_t size_t ssize_t time_t uid_t va_list wchar_t int32_t uint_32_t ; do + IMPORTED=`eval 'echo $'"$TYPE"` + if [ -n "${IMPORTED}" ] ; then + eval "$TYPE='$IMPORTED" + else + # Search dummy.out for a typedef for $TYPE, and write it out + # to TMP in #define syntax. + rm -f TMP + ${SED} -n -e "s|.*typedef *\(.*\) X*$TYPE *;.*|\1|w TMP" /dev/null + # Now select the first definition. + if [ -s TMP ]; then + # VALUE is now the typedef'd definition of $TYPE. + eval "VALUE='`${SED} -e 's| *$||' -e '2,$d' /dev/null ; then true + else + rm -f TMP + ${SED} -n -e "s|.*typedef[ ][ ]*\(.*[^a-zA-Z0-9_]\)${VALUE}[ ]*;.*|\1|w TMP" /dev/null + if [ -s TMP ]; then + eval "VALUE='`${SED} -e '2,$d' -e 's|[ ]*$||' + echo "#include + extern $tmp read();" >dummy.c + ${CC} -c dummy.c >/dev/null 2>&1 || tmp=int + fi + echo "#define ${macro_prefix}ssize_t $tmp /* default */" +fi + +# va_list can cause problems (e.g. some systems have va_list as a struct). +# Check to see if ${va_list-char*} really is compatible with stdarg.h. +cat >dummy.c < +long foo(X_va_list ap) { return va_arg(ap, long); } +long bar(int i, ...) +{ va_list ap; long j; va_start(ap, i); j = foo(ap); va_end(ap); return j; } +!EOF! +if ${CC} -c dummy.c >/dev/null 2>&1 ; then + # Ok: We have something that works. + echo "#define ${macro_prefix}va_list ${va_list-char* /* default */}" +else + # No, it breaks. Indicate that must be included. + echo "#define ${macro_prefix}NEED_STDARG_H +#define ${macro_prefix}va_list va_list" +fi + +# stuff needed for curses.h + +# This isn't correct for SVR4 (for example). However, we only +# use this when adding a missing prototype, so it shouldn't matter. +echo "#define chtype int" +# sys-protos.h uses non-standard names (due to the CHTYPE argument problem). +echo "#define box32 box" +echo "#define initscr32 initscr" +echo "#define w32addch waddch" +echo "#define w32insch winsch" + +rm -f dummy.c dummy.o TMP dummy.out -- 2.30.2