?RCS: $Id: Typedef.U,v 3.0.1.3 1995/07/25 13:42:07 ram Exp $ ?RCS: ?RCS: Copyright (c) 1991-1993, Raphael Manfredi ?RCS: ?RCS: You may redistribute only under the terms of the Artistic License, ?RCS: as specified in the README file that comes with the distribution. ?RCS: You may reuse parts of this distribution only within the terms of ?RCS: that same Artistic License; a copy of which may be found at the root ?RCS: of the source tree for dist 3.0. ?RCS: ?RCS: $Log: Typedef.U,v $ ?RCS: Revision 3.0.1.3 1995/07/25 13:42:07 ram ?RCS: patch56: added backslash escapes within evals to prevent space problems ?RCS: ?RCS: Revision 3.0.1.2 1994/10/29 16:01:16 ram ?RCS: patch36: don't clobber visible 'val' variable, use 'varval' instead ?RCS: ?RCS: Revision 3.0.1.1 1994/08/29 16:05:14 ram ?RCS: patch32: created ?RCS: ?X: ?X: This unit checks for the definition of a given typedef. ?X: ?X: To use it, say: ?X: set typedef val_t default [includes] ?X: eval $typedef ?X: ?MAKE:Typedef: cppstdin cppminus cppflags rm sed contains Oldconfig Myread ?MAKE: -pick add $@ %< ?LINT:define typedef ?LINT:define typedef_ask ?V:typedef typedef_ask ?S:typedef: ?S: This shell variable is used internally by Configure to check ?S: whether a given typedef is defined or not. A typical use is: ?S: set typedef val_t default [includes] ?S: eval $typedef ?S: That will return val_t set to default if the typedef was not found, ?S: to typedef otherwise. If no includes are specified, look in sys/types.h. ?S:. ?S:typedef_ask: ?S: This shell variable is used internally by Configure to check ?S: whether a given typedef is defined or not. If it is not defined, ?S: this will call the ./myread script to prompt for an answer. ?S: It is intended to be used to avoid unnecessary prompts. ?S: A typical use is ?S: rp="What is the type for file position used by fsetpos()?" ?S: set fpos_t fpostype long stdio.h sys/types.h ?S: eval $typedef_ask ?S: This will set fpostype=fpos_t, if fpos_t is available. Otherwise ?S: it will call myread with a default of 'long', and a prompt of $rp. ?S:. ?T:type var def inclist varval inc ?F:!temp.c : define an is-a-typedef? function typedef='type=$1; var=$2; def=$3; shift; shift; shift; inclist=$@; case "$inclist" in "") inclist="sys/types.h";; esac; eval "varval=\$$var"; case "$varval" in "") $rm -f temp.c; for inc in $inclist; do echo "#include <$inc>" >>temp.c; done; ?X: Maybe it's a #define instead of a typedef. echo "#ifdef $type" >> temp.c; echo "printf(\"We have $type\");" >> temp.c; echo "#endif" >> temp.c; $cppstdin $cppflags $cppminus < temp.c >temp.E 2>/dev/null; if $contains $type temp.E >/dev/null 2>&1; then eval "$var=\$type"; else eval "$var=\$def"; fi; $rm -f temp.?;; *) eval "$var=\$varval";; esac' ?X: Originally, I eval'd $typedef and then checked the results against ?X: $type. Unfortunately, it then became complicated to check ?X: whether you are re-using an old config.sh value, and the logic got ?X: so convoluted it became easier to just copy the function above ?X: and alter it slightly. A.D. 3/1998 : define an is-a-typedef? function that prompts if the type is not available. typedef_ask='type=$1; var=$2; def=$3; shift; shift; shift; inclist=$@; case "$inclist" in "") inclist="sys/types.h";; esac; eval "varval=\$$var"; case "$varval" in "") $rm -f temp.c; for inc in $inclist; do echo "#include <$inc>" >>temp.c; done; ?X: Maybe it's a #define instead of a typedef. echo "#ifdef $type" >> temp.c; echo "printf(\"We have $type\");" >> temp.c; echo "#endif" >> temp.c; $cppstdin $cppflags $cppminus < temp.c >temp.E 2>/dev/null; echo " " ; echo "$rp" | $sed -e "s/What is/Looking for/" -e "s/?/./"; if $contains $type temp.E >/dev/null 2>&1; then echo "$type found." >&4; eval "$var=\$type"; else echo "$type NOT found." >&4; dflt="$def"; . ./myread ; eval "$var=\$ans"; fi; $rm -f temp.?;; *) eval "$var=\$varval";; esac'