######################################################################## # # # This software is part of the ast package # # Copyright (c) 1982-2010 AT&T Intellectual Property # # and is licensed under the # # Common Public License, Version 1.0 # # by AT&T Intellectual Property # # # # A copy of the License is available at # # http://www.opensource.org/licenses/cpl1.0.txt # # (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) # # # # Information and Software Systems Research # # AT&T Research # # Florham Park NJ # # # # David Korn # # # ######################################################################## : generate the ksh math builtin table : include math.tab # @(#)math.sh (AT&T Research) 2009-08-18 setvar command = "$0" setvar iffeflags = ""-n -v"" setvar iffehdrs = ""math.h ieeefp.h"" setvar iffelibs = ""-lm"" setvar table = '/dev/null' eval $1 shift setvar table = "$1" setvar names = '' setvar tests = '' : check long double eval $(iffe $iffeflags -c $cc - typ long.double ) : check ast_standards.h eval $(iffe $iffeflags -F ast_standards.h -c $cc - tst use_ast_standards -lm 'note{' 'math.h needs ast_standards.h' '}end' 'link{' '#include ' '#ifndef isgreater' '#define isgreater(a,b) 0' '#endif' 'int main() { return isgreater(0.0,1.0); }' '}end) match $_use_ast_standards { with 1 setvar iffeflags = ""$iffeflags -F ast_standards.h"" } : read the table exec < $table while read type args name aka comment { match $type { with [fi] setvar names = ""$names $name"" setvar tests = ""$tests,$name"" match $_typ_long_double { with 1 setvar tests = ""$tests,${name}l"" } eval TYPE_$name=$type ARGS_$name=$args AKA_$name=$aka } } : check the math library eval $(iffe $iffeflags -c $cc - lib $tests $iffehdrs $iffelibs ) setvar lib = '' for name in [$names] { eval x='$'_lib_${name}l y='$'_lib_${name} match $x { with 1 setvar lib = ""$lib,${name}l"" } match $y { with 1 match $x { with '' setvar lib = ""$lib,${name}"" } } } eval $(iffe $iffeflags -c $cc - dat,npt,mac $lib $iffehdrs $iffelibs ) cat <<< """ #pragma prototyped /* : : generated by $command from $table : : */ typedef Sfdouble_t (*Math_f)(Sfdouble_t,...); """ match $_use_ast_standards { with 1 echo "#include " } echo "#include " match $_hdr_ieeefp { with 1 echo "#include " } echo : generate the intercept functions and table entries setvar nl = '' '' setvar ht = '' '' setvar tab = '' for name in [$names] { eval x='$'_lib_${name}l y='$'_lib_${name} r='$'TYPE_${name} a='$'ARGS_${name} aka='$'AKA_${name} match $x:$y { with 1:* setvar f = "${name}l" setvar t = 'Sfdouble_t' setvar local = '' with *:1 setvar f = ${name} setvar t = 'double' setvar local = "$_typ_long_double" with * match $aka { with *=* setvar f = ${aka%%=*} setvar v = ${aka#*=} eval x='$'_lib_${f}l y='$'_lib_${f} match $x:$y { with 1:* setvar f = "${f}l" with *:1 with * continue } setvar L = "local_$name", r = 'int', R = '1' echo "#ifdef $v${nl}static $r $L(Sfdouble_t x) { return $f(x) == $v; }${nl}#endif" setvar tab = ""$tab$nl#ifdef $v$nl$ht\"\\0${R}${a}${name}\",$ht(Math_f)${L},${nl}#endif"" } continue } eval n='$'_npt_$f m='$'_mac_$f d='$'_dat_$f match $r { with i setvar L = 'int', r = 'int', R = '1' with * setvar L = 'Sfdouble_t', r = "$t", R = '0' } match $d:$m:$n { with 1:*:*|*:1:* with *:*:1 setvar code = ""extern $r $f("" setvar sep = '' for p in [1 2 3 4 5 6 7] { setvar code = ""$code${sep}$t"" match $a { with $p break } setvar sep = "","" } setvar code = ""$code);"" echo $code } match $local:$m:$n:$d { with 1:*:*:*|*:1:*:*|*:*:1: setvar args = '' setvar code = ""static $L local_$f("" setvar sep = '' for p in [1 2 3 4 5 6 7 8 9] { setvar args = ""$args${sep}a$p"" setvar code = ""$code${sep}Sfdouble_t a$p"" match $a { with $p break } setvar sep = "","" } setvar code = ""$code){return $f($args);}"" echo $code setvar f = "local_$f" } for x in [$name $aka] { setvar tab = ""$tab$nl$ht\"\\0${R}${a}${x}\",$ht(Math_f)$f,"" } } setvar tab = ""$tab$nl$ht\"\",$ht$ht(Math_f)0"" cat <<< """ /* * first byte is two-digit octal number. Last digit is number of args * first digit is 0 if return value is double, 1 for integer */ const struct mathtab shtab_math[] = {$tab }; """