14887Schin######################################################################## 24887Schin# # 34887Schin# This software is part of the ast package # 4*8462SApril.Chin@Sun.COM# Copyright (c) 1982-2008 AT&T Intellectual Property # 54887Schin# and is licensed under the # 64887Schin# Common Public License, Version 1.0 # 7*8462SApril.Chin@Sun.COM# by AT&T Intellectual Property # 84887Schin# # 94887Schin# A copy of the License is available at # 104887Schin# http://www.opensource.org/licenses/cpl1.0.txt # 114887Schin# (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) # 124887Schin# # 134887Schin# Information and Software Systems Research # 144887Schin# AT&T Research # 154887Schin# Florham Park NJ # 164887Schin# # 174887Schin# David Korn <dgk@research.att.com> # 184887Schin# # 194887Schin######################################################################## 204887Schin: generate the ksh math builtin table 214887Schin: include math.tab 224887Schin 23*8462SApril.Chin@Sun.COM# @(#)math.sh (AT&T Research) 2008-08-29 244887Schin 254887Schincommand=$0 264887Schiniffeflags="-n -v -F ast_standards.h" 274887Schiniffehdrs="math.h ieeefp.h" 284887Schiniffelibs="-lm" 294887Schintable=/dev/null 304887Schin 314887Schineval $1 324887Schinshift 334887Schintable=$1 344887Schin 354887Schinnames= 364887Schintests= 374887Schin 38*8462SApril.Chin@Sun.COM: check long double 39*8462SApril.Chin@Sun.COM 40*8462SApril.Chin@Sun.COMeval `iffe $iffeflags -c "$cc" - typ long.double 2>&$stderr` 41*8462SApril.Chin@Sun.COM 424887Schin: read the table 434887Schin 444887Schinexec < $table 454887Schinwhile read type args name aka comment 464887Schindo case $type in 474887Schin [fi]) names="$names $name" 48*8462SApril.Chin@Sun.COM tests="$tests,$name" 49*8462SApril.Chin@Sun.COM case $_typ_long_double in 50*8462SApril.Chin@Sun.COM 1) tests="$tests,${name}l" ;; 51*8462SApril.Chin@Sun.COM esac 524887Schin eval TYPE_$name=$type ARGS_$name=$args AKA_$name=$aka 534887Schin ;; 544887Schin esac 554887Schindone 564887Schin 574887Schin: check the math library 584887Schin 59*8462SApril.Chin@Sun.COMeval `iffe $iffeflags -c "$cc" - lib $tests $iffehdrs $iffelibs 2>&$stderr` 604887Schinlib= 614887Schinfor name in $names 624887Schindo eval x='$'_lib_${name}l y='$'_lib_${name} 634887Schin case $x in 644887Schin 1) lib="$lib,${name}l" ;; 654887Schin esac 664887Schin case $y in 674887Schin 1) case $x in 684887Schin '') lib="$lib,${name}" ;; 694887Schin esac 704887Schin ;; 714887Schin esac 724887Schindone 734887Schineval `iffe $iffeflags -c "$cc" - dat,npt,mac $lib $iffehdrs $iffelibs 2>&$stderr` 744887Schin 754887Schincat <<! 764887Schin#pragma prototyped 774887Schin 784887Schin/* : : generated by $command from $table : : */ 794887Schin 804887Schintypedef Sfdouble_t (*Math_f)(Sfdouble_t,...); 814887Schin 824887Schin! 834887Schinecho "#include <ast_standards.h>" 844887Schinecho "#include <math.h>" 854887Schincase $_hdr_ieeefp in 864887Schin1) echo "#include <ieeefp.h>" 874887Schin echo 884887Schin ;; 894887Schinesac 904887Schin 914887Schin: generate the intercept functions and table entries 924887Schin 934887Schinnl=' 944887Schin' 954887Schinht=' ' 964887Schintab= 974887Schinfor name in $names 984887Schindo eval x='$'_lib_${name}l y='$'_lib_${name} r='$'TYPE_${name} a='$'ARGS_${name} aka='$'AKA_${name} 994887Schin case $x:$y in 1004887Schin 1:*) f=${name}l 1014887Schin t=Sfdouble_t 1024887Schin local= 1034887Schin ;; 1044887Schin *:1) f=${name} 1054887Schin t=double 1064887Schin local=$_typ_long_double 1074887Schin ;; 1084887Schin *) continue 1094887Schin ;; 1104887Schin esac 1114887Schin eval n='$'_npt_$f m='$'_mac_$f d='$'_dat_$f 1124887Schin case $r in 1134887Schin i) L=int r=int R=1 ;; 1144887Schin *) L=Sfdouble_t r=$t R=0 ;; 1154887Schin esac 1164887Schin case $d:$m:$n in 1174887Schin 1:*:*|*:1:*) 1184887Schin ;; 1194887Schin *:*:1) code="extern $r $f(" 1204887Schin sep= 1214887Schin for p in 1 2 3 4 5 6 7 1224887Schin do code="$code${sep}$t" 1234887Schin case $a in 1244887Schin $p) break ;; 1254887Schin esac 1264887Schin sep="," 1274887Schin done 1284887Schin code="$code);" 1294887Schin echo "$code" 1304887Schin ;; 1314887Schin esac 1324887Schin case $local:$m:$n:$d in 133*8462SApril.Chin@Sun.COM 1:*:*:*|*:1:*:*|*:*:1:) 1344887Schin args= 1354887Schin code="static $L local_$f(" 1364887Schin sep= 1374887Schin for p in 1 2 3 4 5 6 7 8 9 1384887Schin do args="$args${sep}a$p" 1394887Schin code="$code${sep}Sfdouble_t a$p" 1404887Schin case $a in 1414887Schin $p) break ;; 1424887Schin esac 1434887Schin sep="," 1444887Schin done 1454887Schin code="$code){return $f($args);}" 1464887Schin echo "$code" 1474887Schin f=local_$f 1484887Schin ;; 1494887Schin esac 1504887Schin for x in $name $aka 1514887Schin do tab="$tab$nl$ht\"\\0${R}${a}${x}\",$ht(Math_f)$f," 1524887Schin done 1534887Schindone 1544887Schintab="$tab$nl$ht\"\",$ht$ht(Math_f)0" 1554887Schin 1564887Schincat <<! 1574887Schin 1584887Schin/* 1594887Schin * first byte is two-digit octal number. Last digit is number of args 1604887Schin * first digit is 0 if return value is double, 1 for integer 1614887Schin */ 1624887Schinconst struct mathtab shtab_math[] = 1634887Schin{$tab 1644887Schin}; 1654887Schin! 166