1*4887Schin######################################################################## 2*4887Schin# # 3*4887Schin# This software is part of the ast package # 4*4887Schin# Copyright (c) 1982-2007 AT&T Knowledge Ventures # 5*4887Schin# and is licensed under the # 6*4887Schin# Common Public License, Version 1.0 # 7*4887Schin# by AT&T Knowledge Ventures # 8*4887Schin# # 9*4887Schin# A copy of the License is available at # 10*4887Schin# http://www.opensource.org/licenses/cpl1.0.txt # 11*4887Schin# (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) # 12*4887Schin# # 13*4887Schin# Information and Software Systems Research # 14*4887Schin# AT&T Research # 15*4887Schin# Florham Park NJ # 16*4887Schin# # 17*4887Schin# David Korn <dgk@research.att.com> # 18*4887Schin# # 19*4887Schin######################################################################## 20*4887Schin: generate the ksh math builtin table 21*4887Schin: include math.tab 22*4887Schin 23*4887Schin# @(#)math.sh (AT&T Research) 2007-02-02 24*4887Schin 25*4887Schincommand=$0 26*4887Schiniffeflags="-n -v -F ast_standards.h" 27*4887Schiniffehdrs="math.h ieeefp.h" 28*4887Schiniffelibs="-lm" 29*4887Schintable=/dev/null 30*4887Schin 31*4887Schineval $1 32*4887Schinshift 33*4887Schintable=$1 34*4887Schin 35*4887Schinnames= 36*4887Schintests= 37*4887Schin 38*4887Schin: read the table 39*4887Schin 40*4887Schinexec < $table 41*4887Schinwhile read type args name aka comment 42*4887Schindo case $type in 43*4887Schin [fi]) names="$names $name" 44*4887Schin tests="$tests,$name,${name}l" 45*4887Schin eval TYPE_$name=$type ARGS_$name=$args AKA_$name=$aka 46*4887Schin ;; 47*4887Schin esac 48*4887Schindone 49*4887Schin 50*4887Schin: check the math library 51*4887Schin 52*4887Schineval `iffe $iffeflags -c "$cc" - typ long.double : lib $tests $iffehdrs $iffelibs 2>&$stderr` 53*4887Schinlib= 54*4887Schinfor name in $names 55*4887Schindo eval x='$'_lib_${name}l y='$'_lib_${name} 56*4887Schin case $x in 57*4887Schin 1) lib="$lib,${name}l" ;; 58*4887Schin esac 59*4887Schin case $y in 60*4887Schin 1) case $x in 61*4887Schin '') lib="$lib,${name}" ;; 62*4887Schin esac 63*4887Schin ;; 64*4887Schin esac 65*4887Schindone 66*4887Schineval `iffe $iffeflags -c "$cc" - dat,npt,mac $lib $iffehdrs $iffelibs 2>&$stderr` 67*4887Schin 68*4887Schincat <<! 69*4887Schin#pragma prototyped 70*4887Schin 71*4887Schin/* : : generated by $command from $table : : */ 72*4887Schin 73*4887Schintypedef Sfdouble_t (*Math_f)(Sfdouble_t,...); 74*4887Schin 75*4887Schin! 76*4887Schinecho "#include <ast_standards.h>" 77*4887Schinecho "#include <math.h>" 78*4887Schincase $_hdr_ieeefp in 79*4887Schin1) echo "#include <ieeefp.h>" 80*4887Schin echo 81*4887Schin ;; 82*4887Schinesac 83*4887Schin 84*4887Schin: generate the intercept functions and table entries 85*4887Schin 86*4887Schinnl=' 87*4887Schin' 88*4887Schinht=' ' 89*4887Schintab= 90*4887Schinfor name in $names 91*4887Schindo eval x='$'_lib_${name}l y='$'_lib_${name} r='$'TYPE_${name} a='$'ARGS_${name} aka='$'AKA_${name} 92*4887Schin case $x:$y in 93*4887Schin 1:*) f=${name}l 94*4887Schin t=Sfdouble_t 95*4887Schin local= 96*4887Schin ;; 97*4887Schin *:1) f=${name} 98*4887Schin t=double 99*4887Schin local=$_typ_long_double 100*4887Schin ;; 101*4887Schin *) continue 102*4887Schin ;; 103*4887Schin esac 104*4887Schin eval n='$'_npt_$f m='$'_mac_$f d='$'_dat_$f 105*4887Schin case $r in 106*4887Schin i) L=int r=int R=1 ;; 107*4887Schin *) L=Sfdouble_t r=$t R=0 ;; 108*4887Schin esac 109*4887Schin case $d:$m:$n in 110*4887Schin 1:*:*|*:1:*) 111*4887Schin ;; 112*4887Schin *:*:1) code="extern $r $f(" 113*4887Schin sep= 114*4887Schin for p in 1 2 3 4 5 6 7 115*4887Schin do code="$code${sep}$t" 116*4887Schin case $a in 117*4887Schin $p) break ;; 118*4887Schin esac 119*4887Schin sep="," 120*4887Schin done 121*4887Schin code="$code);" 122*4887Schin echo "$code" 123*4887Schin ;; 124*4887Schin esac 125*4887Schin case $local:$m:$n:$d in 126*4887Schin 1:*:*:*|*:1:*:*|*:*::) 127*4887Schin args= 128*4887Schin code="static $L local_$f(" 129*4887Schin sep= 130*4887Schin for p in 1 2 3 4 5 6 7 8 9 131*4887Schin do args="$args${sep}a$p" 132*4887Schin code="$code${sep}Sfdouble_t a$p" 133*4887Schin case $a in 134*4887Schin $p) break ;; 135*4887Schin esac 136*4887Schin sep="," 137*4887Schin done 138*4887Schin code="$code){return $f($args);}" 139*4887Schin echo "$code" 140*4887Schin f=local_$f 141*4887Schin ;; 142*4887Schin esac 143*4887Schin for x in $name $aka 144*4887Schin do tab="$tab$nl$ht\"\\0${R}${a}${x}\",$ht(Math_f)$f," 145*4887Schin done 146*4887Schindone 147*4887Schintab="$tab$nl$ht\"\",$ht$ht(Math_f)0" 148*4887Schin 149*4887Schincat <<! 150*4887Schin 151*4887Schin/* 152*4887Schin * first byte is two-digit octal number. Last digit is number of args 153*4887Schin * first digit is 0 if return value is double, 1 for integer 154*4887Schin */ 155*4887Schinconst struct mathtab shtab_math[] = 156*4887Schin{$tab 157*4887Schin}; 158*4887Schin! 159