diff options
Diffstat (limited to 'src/cmd/ksh93/features')
-rw-r--r-- | src/cmd/ksh93/features/cmds | 4 | ||||
-rw-r--r-- | src/cmd/ksh93/features/dynamic | 12 | ||||
-rw-r--r-- | src/cmd/ksh93/features/externs | 13 | ||||
-rw-r--r-- | src/cmd/ksh93/features/locale | 27 | ||||
-rw-r--r-- | src/cmd/ksh93/features/math.sh | 305 | ||||
-rwxr-xr-x | src/cmd/ksh93/features/options | 47 | ||||
-rw-r--r-- | src/cmd/ksh93/features/poll | 157 | ||||
-rw-r--r-- | src/cmd/ksh93/features/rlimits | 3 | ||||
-rw-r--r-- | src/cmd/ksh93/features/setjmp | 18 | ||||
-rw-r--r-- | src/cmd/ksh93/features/sigfeatures | 49 | ||||
-rw-r--r-- | src/cmd/ksh93/features/time | 35 | ||||
-rw-r--r-- | src/cmd/ksh93/features/ttys | 3 |
12 files changed, 673 insertions, 0 deletions
diff --git a/src/cmd/ksh93/features/cmds b/src/cmd/ksh93/features/cmds new file mode 100644 index 0000000..c759068 --- /dev/null +++ b/src/cmd/ksh93/features/cmds @@ -0,0 +1,4 @@ +cmd newgrp,test,id,wc,cut,logname,universe,pfexec,tput +pth ed fail{ + echo '#define _pth_ed "ed" /* ed not found on standard PATH */' +}end diff --git a/src/cmd/ksh93/features/dynamic b/src/cmd/ksh93/features/dynamic new file mode 100644 index 0000000..33f2d13 --- /dev/null +++ b/src/cmd/ksh93/features/dynamic @@ -0,0 +1,12 @@ +cat{ + #if SHOPT_DYNAMIC + #include <dlldefs.h> + #endif + #if !defined(SHOPT_FS_3D) && SHOPT_DYNAMIC + # define SHOPT_FS_3D 1 + #endif /* !SHOPT_FS_3D */ + #if SHOPT_FS_3D + # undef mount + # include <fs3d.h> + #endif /* SHOPT_FS_3D */ +}end diff --git a/src/cmd/ksh93/features/externs b/src/cmd/ksh93/features/externs new file mode 100644 index 0000000..bc26759 --- /dev/null +++ b/src/cmd/ksh93/features/externs @@ -0,0 +1,13 @@ +set prototyped +hdr nc,exec_attr +mem exception.name,_exception.name math.h +lib setreuid,setregid,nice,fork,spawnveg,fchdir +lib pathnative,pathposix,uwin_path,uwin_unpath,fts_notify +lib memcntl sys/mman.h +lib getexecuser,free_execattr exec_attr.h -lsecdb + +reference unistd.h + +extern nice int (int) +extern setreuid int (uid_t,uid_t) +extern setregid int (gid_t,gid_t) diff --git a/src/cmd/ksh93/features/locale b/src/cmd/ksh93/features/locale new file mode 100644 index 0000000..4155b53 --- /dev/null +++ b/src/cmd/ksh93/features/locale @@ -0,0 +1,27 @@ +hdr locale,wchar,wctype +lib locale,localeconv,wctype,iswctype,iswblank +lib wctrans,towctrans wctype.h +typ wctrans_t wctype.h +cat{ + #if _PACKAGE_ast + # undef _hdr_locale + # define _hdr_locale 1 + #else + # ifdef _hdr_locale + # include <locale.h> + # ifndef LC_MESSAGES + # define LC_MESSAGES LC_ALL + # endif /* LC_MESSAGES */ + # endif /* _hdr_locale */ + #endif /* _PACKAGE_ast */ + #ifdef _hdr_locale + # ifdef _lib_localeconv + static struct lconv *lp; + # define GETDECIMAL(x) (((lp=localeconv()) && lp->decimal_point && *lp->decimal_point) ? *lp->decimal_point : '.' ) + # else + # define GETDECIMAL(x) ('.') + # endif /* _lib_localeconv */ + #else + # define GETDECIMAL(x) ('.') + #endif /* _hdr_locale */ +}end diff --git a/src/cmd/ksh93/features/math.sh b/src/cmd/ksh93/features/math.sh new file mode 100644 index 0000000..c2b6b3b --- /dev/null +++ b/src/cmd/ksh93/features/math.sh @@ -0,0 +1,305 @@ +######################################################################## +# # +# This software is part of the ast package # +# Copyright (c) 1982-2011 AT&T Intellectual Property # +# and is licensed under the # +# Eclipse Public License, Version 1.0 # +# by AT&T Intellectual Property # +# # +# A copy of the License is available at # +# http://www.eclipse.org/org/documents/epl-v10.html # +# (with md5 checksum b35adb5213ca9657e911e9befb180842) # +# # +# Information and Software Systems Research # +# AT&T Research # +# Florham Park NJ # +# # +# David Korn <dgk@research.att.com> # +# # +######################################################################## +: generate the ksh math builtin table +: include math.tab + +# @(#)math.sh (AT&T Research) 2010-10-26 + +command=$0 +iffeflags="-n -v" +iffehdrs="math.h" +iffelibs="-lm" +table=/dev/null + +eval $1 +shift +table=$1 + +: check long double + +eval `iffe $iffeflags -c "$cc" - typ long.double 2>&$stderr` + +: 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 <math.h>' '#ifndef isgreater' '#define isgreater(a,b) 0' '#endif' 'int main() { return isgreater(0.0,1.0); }' '}end'` +case $_use_ast_standards in +1) iffeflags="$iffeflags -F ast_standards.h" ;; +esac +eval `iffe $iffeflags -c "$cc" - tst use_ieeefp -lm 'note{' 'ieeefp.h plays nice' '}end' 'link{' '#include <math.h>' '#include <ieeefp.h>' 'int main() { return 0; }' '}end'` +case $_use_ieeefp in +1) iffehdrs="$iffehdrs ieeefp.h" ;; +esac + +: read the table + +exec < $table +ifs=$IFS +libs= +names= +nums= +while read type args name aka +do case $type in + [fix]) names="$names $name" + libs="$libs,$name" + case $_typ_long_double in + 1) libs="$libs,${name}l" ;; + esac + for a in $aka + do case $a in + '{'*) break + ;; + *=*) IFS='=|' + set $a + IFS=$ifs + case ",$libs" in + *,$1,*) ;; + *) names="$names $1" + libs="$libs,$1" + case $_typ_long_double in + 1) libs="$libs,${1}l" ;; + esac + ;; + esac + shift + while : + do case $# in + 0) break ;; + esac + case ",$nums" in + *,$1,*) ;; + *) nums="$nums,$1" ;; + esac + shift + done + ;; + esac + done + eval TYPE_$name='$type' ARGS_$name='$args' AKA_$name='$aka' + ;; + esac +done + +: check the math library + +eval `iffe $iffeflags -c "$cc" - lib $libs $iffehdrs $iffelibs 2>&$stderr` +lib= +for name in $names +do eval x='$'_lib_${name}l y='$'_lib_${name} + case $x in + 1) lib="$lib,${name}l" ;; + esac + case $y in + 1) case $x in + '') lib="$lib,${name}" ;; + esac + ;; + esac +done +eval `iffe $iffeflags -c "$cc" - dat,npt,mac $lib $iffehdrs $iffelibs 2>&$stderr` +eval `iffe $iffeflags -c "$cc" - num $nums $iffehdrs $iffelibs 2>&$stderr` + +cat <<! +#pragma prototyped + +/* : : generated by $command from $table : : */ + +typedef Sfdouble_t (*Math_f)(Sfdouble_t,...); + +! +case $_use_ast_standards in +1) echo "#include <ast_standards.h>" ;; +esac +echo "#include <math.h>" +case $_hdr_ieeefp in +1) echo "#include <ieeefp.h>" ;; +esac +echo + +: generate the intercept functions and table entries + +nl=' +' +ht=' ' +tab= +for name in $names +do eval x='$'_lib_${name}l y='$'_lib_${name} r='$'TYPE_${name} a='$'ARGS_${name} aka='$'AKA_${name} + case $r in + i) L=int R=1 ;; + x) L=Sfdouble_t R=4 ;; + *) L=Sfdouble_t R=0 ;; + esac + F=local_$name + case $x:$y in + 1:*) f=${name}l + t=Sfdouble_t + local= + ;; + *:1) f=${name} + t=double + local=$_typ_long_double + ;; + *) body= + for k in $aka + do case $body in + ?*) body="$body $k" + continue + ;; + esac + case $k in + '{'*) body=$k + ;; + *=*) IFS='=|' + set $k + IFS=$ifs + f=$1 + shift + v=$* + eval x='$'_lib_${f}l y='$'_lib_${f} + case $x:$y in + 1:*) f=${f}l + ;; + *:1) ;; + *) continue + ;; + esac + y= + while : + do case $# in + 0) break ;; + esac + eval x='$'_num_$1 + case $x in + 1) case $y in + ?*) y="$y || " ;; + esac + y="${y}q == $1" + ;; + esac + shift + done + case $y in + '') ;; + *) r=int R=1 + echo "static $r $F(Sfdouble_t a1) { $r q = $f(a1); return $y; }" + tab="$tab$nl$ht\"\\0${R}${a}${name}\",$ht(Math_f)${F}," + break + ;; + esac + ;; + esac + done + case $body in + ?*) code="static $L $F(" + sep= + ta= + tc= + td= + for p in 1 2 3 4 5 6 7 8 9 + do case $R:$p in + 4:2) T=int ;; + *) T=Sfdouble_t ;; + esac + code="$code${sep}$T a$p" + ta="$ta${sep}a$p" + tc="$tc${sep}0" + td="${td}$T a$p;" + case $a in + $p) break ;; + esac + sep="," + done + _it_links_=0 + eval `iffe $iffeflags -c "$cc" - tst it_links_ note{ $F function links }end link{ "static $L $F($ta)$td${body}int main(){return $F($tc)!=0;}" }end sfio.h $iffehdrs $iffelibs 2>&$stderr` + case $_it_links_ in + 1) code="$code)$body" + echo "$code" + tab="$tab$nl$ht\"\\0${R}${a}${name}\",$ht(Math_f)${F}," + ;; + esac + ;; + esac + continue + ;; + esac + case $r in + i) r=int ;; + *) r=$t ;; + esac + eval n='$'_npt_$f m='$'_mac_$f d='$'_dat_$f + case $d:$m:$n in + 1:*:*|*:1:*) + ;; + *:*:1) code="extern $r $f(" + sep= + for p in 1 2 3 4 5 6 7 + do code="$code${sep}$t" + case $a in + $p) break ;; + esac + sep="," + done + code="$code);" + echo "$code" + ;; + esac + case $local:$m:$n:$d in + 1:*:*:*|*:1:*:*|*:*:1:) + args= + code="static $L local_$f(" + sep= + for p in 1 2 3 4 5 6 7 8 9 + do args="$args${sep}a$p" + case $R:$p in + 4:2) T=int ;; + *) T=Sfdouble_t ;; + esac + code="$code${sep}$T a$p" + case $a in + $p) break ;; + esac + sep="," + done + code="$code){return $f($args);}" + echo "$code" + f=local_$f + ;; + esac + for x in $name $aka + do case $x in + '{'*) break + ;; + *=*) continue + ;; + esac + tab="$tab$nl$ht\"\\0${R}${a}${x}\",$ht(Math_f)$f," + done +done +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 +}; +! diff --git a/src/cmd/ksh93/features/options b/src/cmd/ksh93/features/options new file mode 100755 index 0000000..c3f48b6 --- /dev/null +++ b/src/cmd/ksh93/features/options @@ -0,0 +1,47 @@ +# SHOPT_* option probe + +tst cross{ + : check for shell magic #! + cat > /tmp/file$$ <<! + #! /bin/echo + exit 1 + ! + chmod 755 /tmp/file$$ + if /tmp/file$$ > /dev/null + then echo "#define SHELLMAGIC 1" + fi + rm -f /tmp/file$$ + + option() # name value + { + case $2 in + 0) echo "#ifndef SHOPT_$1" + echo "# define SHOPT_$1 1" + echo "#endif" + ;; + *) echo "#undef SHOPT_$1" + ;; + esac + } + + ls /dev/fd/9 9<&0 >/dev/null 2>&1 + option DEVFD $? + exec 9<&- + case `echo a | tr a '\012' | wc -l` in + *1*) option MULTIBYTE 0 ;; + esac + test -x /bin/pfexec -o -x /usr/bin/pfexec + option PFSH $? + /bin/test ! -l . 2> /dev/null + option TEST_L $? + test -f /etc/ksh.kshrc -o -f /etc/bash.bashrc && + option SYSRC 0 + test -f /bin/universe && univ=`/bin/universe` > /dev/null 2>&1 -a ucb = "$univ" + option UCB $? +}end + +cat{ + #if !_PACKAGE_ast && ( (MB_LEN_MAX-1)<=0 || !defined(_lib_mbtowc) ) + # undef SHOPT_MULTIBYTE + #endif +}end diff --git a/src/cmd/ksh93/features/poll b/src/cmd/ksh93/features/poll new file mode 100644 index 0000000..da21990 --- /dev/null +++ b/src/cmd/ksh93/features/poll @@ -0,0 +1,157 @@ +ref -lsocket -lnsl +hdr,sys poll,socket,netinet/in +lib select,poll,socket +lib htons,htonl sys/types.h sys/socket.h netinet/in.h +lib getaddrinfo sys/types.h sys/socket.h netdb.h +typ fd_set sys/socket.h sys/select.h +typ socklen_t unistd.h sys/socket.h = unsigned int +tst pipe_socketpair note{ use socketpair() for peekable pipe() }end execute{ + #include <ast.h> + #include <signal.h> + #include <sys/types.h> + #include <sys/socket.h> + #ifndef SHUT_RD + #define SHUT_RD 0 + #endif + #ifndef SHUT_WR + #define SHUT_WR 1 + #endif + static void handler(sig) + int sig; + { + _exit(0); + } + int main() + { + int n; + int pfd[2]; + int sfd[2]; + char buf[256]; + pid_t pid; + static char msg[] = "hello world\n"; + close(0); + if (pipe(pfd) < 0 || + socketpair(AF_UNIX, SOCK_STREAM, 0, sfd) < 0 || + shutdown(sfd[1], SHUT_RD) < 0 || + shutdown(sfd[0], SHUT_WR) < 0) + return(1); + if ((pid = fork()) < 0) + return(1); + if (pid) + { + close(pfd[1]); + close(sfd[1]); + wait(&n); + if (sfpkrd(pfd[0], buf, sizeof(buf), '\n', -1, 1) >= 0 || + sfpkrd(sfd[0], buf, sizeof(buf), '\n', -1, 1) < 0) + return(1); + } + else + { + close(pfd[0]); + close(sfd[0]); + write(pfd[1], msg, sizeof(msg) - 1); + write(sfd[1], msg, sizeof(msg) - 1); + return(0); + } + close(pfd[0]); + close(sfd[0]); + signal(SIGPIPE, handler); + if (socketpair(AF_UNIX, SOCK_STREAM, 0, sfd) < 0 || + shutdown(sfd[1], SHUT_RD) < 0 || + shutdown(sfd[0], SHUT_WR) < 0) + return(1); + close(sfd[0]); + write(sfd[1], msg, sizeof(msg) - 1); + return(1); + } +}end +tst socketpair_devfd note{ /dev/fd/N handles socketpair() }end execute{ + #include <ast.h> + #include <fs3d.h> + #include <sys/types.h> + #include <sys/socket.h> + int main() + { + int devfd; + int n; + int sfd[2]; + fs3d(FS3D_OFF); + close(0); + open("/dev/null", O_RDONLY); + if ((n = open("/dev/fd/0", O_RDONLY)) < 0) + return(1); + close(n); + if (socketpair(AF_UNIX, SOCK_STREAM, 0, sfd) < 0 || + shutdown(sfd[0], 1) < 0 || + shutdown(sfd[1], 0) < 0) + return(1); + close(0); + dup(sfd[0]); + close(sfd[0]); + if ((n = open("/dev/fd/0", O_RDONLY)) < 0) + return(1); + return(0); + } +}end +tst socketpair_shutdown_mode note{ fchmod() after socketpair() shutdown() }end execute{ + #include <ast.h> + #include <sys/types.h> + #include <sys/stat.h> + #include <sys/socket.h> + int main() + { + int sfd[2]; + struct stat st0; + struct stat st1; + if (socketpair(AF_UNIX, SOCK_STREAM, 0, sfd) < 0 || + shutdown(sfd[0], 1) < 0 || + shutdown(sfd[1], 0) < 0) + return(1); + if (fstat(sfd[0], &st0) < 0 || fstat(sfd[1], &st1) < 0) + return(1); + if ((st0.st_mode & (S_IRUSR|S_IWUSR)) == S_IRUSR && + (st1.st_mode & (S_IRUSR|S_IWUSR)) == S_IWUSR) + return(1); + if (fchmod(sfd[0], S_IRUSR) < 0 || + fstat(sfd[0], &st0) < 0 || + (st0.st_mode & (S_IRUSR|S_IWUSR)) != S_IRUSR) + return(1); + if (fchmod(sfd[1], S_IWUSR) < 0 || + fstat(sfd[1], &st1) < 0 || + (st1.st_mode & (S_IRUSR|S_IWUSR)) != S_IWUSR) + return(1); + return(0); + } +}end +cat{ + #pragma prototyped + #ifdef _lib_poll + # define poll _SYS_poll + #else + # undef _hdr_poll + # undef _sys_poll + #endif /* _lib_poll */ + #ifdef _hdr_poll + # include <poll.h> + #else + # ifdef _sys_poll + # include <sys/poll.h> + # endif /* _sys_poll */ + #endif /* _hdr_poll */ + #ifdef _lib_poll + # undef poll + extern int poll(struct pollfd*,unsigned long,int); + #endif /* _lib_poll */ + #ifdef _lib_select + # ifndef FD_ZERO + # define FD_ZERO(x) (*(x)=0) + # endif /* FD_ZERO */ + # ifndef FD_SET + # define FD_SET(n,x) (*(x)|=(1L<<(n))) + # endif /* FD_SET */ + # ifndef _typ_fd_set + typedef long fd_set; + # endif /*_typ_fd_set */ + #endif /* _lib_select */ +}end diff --git a/src/cmd/ksh93/features/rlimits b/src/cmd/ksh93/features/rlimits new file mode 100644 index 0000000..ad7d2e1 --- /dev/null +++ b/src/cmd/ksh93/features/rlimits @@ -0,0 +1,3 @@ +hdr,sys resource,vlimit sys/time.h +lib getrlimit,ulimit,vlimit +typ rlim_t sys/types.h sys/time.h sys/resource.h diff --git a/src/cmd/ksh93/features/setjmp b/src/cmd/ksh93/features/setjmp new file mode 100644 index 0000000..a3504ee --- /dev/null +++ b/src/cmd/ksh93/features/setjmp @@ -0,0 +1,18 @@ +lib sigsetjmp,_setjmp,_longjmp +typ sigjmp_buf setjmp.h +cat{ + #undef sigsetjmp + #undef siglongjmp + #undef sigjmp_buf + #define sigjmp_buf jmp_buf + #ifdef _lib__setjmp + # define sigsetjmp(a,b) _setjmp(a) + #else + # define sigsetjmp(a,b) setjmp(a) + #endif /* _lib__setjmp */ + #ifdef _lib__longjmp + # define siglongjmp(a,b) _longjmp(a,b) + #else + # define siglongjmp(a,b) longjmp(a,b) + #endif /* _lib__longjmp */ +}end diff --git a/src/cmd/ksh93/features/sigfeatures b/src/cmd/ksh93/features/sigfeatures new file mode 100644 index 0000000..58beaf8 --- /dev/null +++ b/src/cmd/ksh93/features/sigfeatures @@ -0,0 +1,49 @@ +lib sigblock,sigrelse,sigsetmask,sigprocmask,sigvec +typ sigset_t ast.h signal.h +mem sigvec.sv_mask signal.h +cat{ + #ifndef _mem_sigvec_sv_mask + # undef _lib_sigvec + #endif + #ifdef _lib_sigprocmask + # define sh_sigaction(s,action) do { sigset_t ss;\ + sigemptyset(&ss); \ + if(s) sigaddset(&ss,(s)); \ + sigprocmask(action,&ss,0); \ + }while(0) + # define sigrelease(s) sh_sigaction(s,SIG_UNBLOCK) + # define sigblock(s) sh_sigaction(s,SIG_BLOCK) + # define sig_begin() sh_sigaction(0,SIG_SETMASK) + #else + # ifndef _lib_sigblock + # define sigblock(s) + # endif + # ifdef _lib_sigsetmask + # define sigrelease(s) sigsetmask(0) + # define sig_begin() sigsetmask(0) + # else + # ifdef _lib_sigrelse + # define sigrelease sigrelse + # define sig_begin() + # else + # define sig_begin() (0) + # define sigrelease(s) (0) + # endif /* _lib_sigrelse */ + # endif /* _lib_sigsetmask */ + #endif /* _lib_sigprocmask */ +}end +tst output{ + #include <signal.h> + int main() + { + #ifdef SIGRTMIN + printf("#undef _SIGRTMIN\n"); + printf("#define _SIGRTMIN %d\n", SIGRTMIN); + #endif + #ifdef SIGRTMAX + printf("#undef _SIGRTMAX\n"); + printf("#define _SIGRTMAX %d\n", SIGRTMAX); + #endif + return 0; + } +}end diff --git a/src/cmd/ksh93/features/time b/src/cmd/ksh93/features/time new file mode 100644 index 0000000..f8d2129 --- /dev/null +++ b/src/cmd/ksh93/features/time @@ -0,0 +1,35 @@ +hdr utime +lib gettimeofday,setitimer +mem timeval.tv_usec sys/time.h +tst lib_2_timeofday note{ 2 arg gettimeofday() }end link{ + #include <sys/types.h> + #include <sys/time.h> + int main() + { + struct timeval tv; + struct timezone tz; + return gettimeofday(&tv, &tz); + } +}end +tst lib_1_timeofday note{ 1 arg gettimeofday() }end link{ + #include <sys/types.h> + #include <sys/time.h> + int main() + { + struct timeval tv; + return gettimeofday(&tv); + } +}end +cat{ + #undef _def_time + #include <times.h> + #define _def_time 1 + #undef timeofday + #if _lib_2_timeofday + #define timeofday(p) gettimeofday(p,(struct timezone*)0) + #else + #if _lib_1_timeofday + #define timeofday(p) gettimeofday(p) + #endif + #endif +}end diff --git a/src/cmd/ksh93/features/ttys b/src/cmd/ksh93/features/ttys new file mode 100644 index 0000000..693dbd1 --- /dev/null +++ b/src/cmd/ksh93/features/ttys @@ -0,0 +1,3 @@ +hdr termios,termio,sgtty +sys termios,termio,ioctl,bsdtty,nttyio,filio +lib tcgetattr,tcgetpgrp termios.h |