sinclude(config.ax_check_sign.m4)
sinclude(config.psi.m4)
+ sinclude(config.psi_type.m4)
+ sinclude(config.psi_const.m4)
+ sinclude(config.psi_decl.m4)
+ sinclude(config.psi_macro.m4)
+ sinclude(config.psi_struct.m4)
+
sinclude(config.psi_errno.m4)
sinclude(config.psi_glob.m4)
sinclude(config.psi_stddef.m4)
+ sinclude(config.psi_stdio.m4)
sinclude(config.psi_stdint.m4)
sinclude(config.psi_sys_types.m4)
- sinclude(config.psi_type.m4)
PSI_LEMON
PSI_CHECK_LIBJIT
PSI_CHECK_SYS_TYPES
PSI_CHECK_ERRNO
PSI_CHECK_GLOB
+ PSI_CHECK_STDIO
echo PSI_TYPES=$PSI_TYPES
echo PSI_MACROS=$PSI_MACROS
- echo PSI_REDIR=$PSI_REDIR
+ echo PSI_REDIRS=$PSI_REDIRS
echo PSI_DECLS=$PSI_DECLS
+ echo PSI_STRUCTS=$PSI_STRUCTS
PHP_SUBST(PSI_SHARED_LIBADD)
EOF
}
-AC_DEFUN(PSI_INCLUDES, [AC_INCLUDES_DEFAULT([`psi_includes`])])
+AC_DEFUN(PSI_INCLUDES, [AC_INCLUDES_DEFAULT()
+`psi_includes`])
AC_DEFUN(PSI_LEMON, [
AC_ARG_VAR(LEMON, The lemon parser generator of the SQLite project)
--- /dev/null
+PSI_CONSTS=""
+# add_str_const(name, value)
+add_str_const() {
+ PSI_CONSTS="{PSI_T_STRING, \"string\", \"psi\\\\$1\", $2, PSI_T_QUOTED_STRING}, $PSI_CONSTS"
+}
+# add_int_const(name, value)
+add_int_const() {
+ PSI_CONSTS="{PSI_T_INT, \"int\", \"psi\\\\$1\", \"$2\", PSI_T_NUMBER}, $PSI_CONSTS"
+}
+dnl PSI_CONST(const name, type)
+AC_DEFUN(PSI_CONST, [
+ AC_CACHE_CHECK(value of $1, psi_cv_const_$1, [
+ psi_const_val=
+ case $2 in
+ str*)
+ if test "$cross_compiling" = "yes"
+ then
+ AC_TRY_CPP(PSI_INCLUDES $1, psi_const_val=`eval "$ac_try|tail -n1"`, psi_const_val=)
+ else
+ PSI_COMPUTE_STR(psi_const_val, $1, PSI_INCLUDES)
+ fi
+ ;;
+ int)
+ AC_COMPUTE_INT(psi_const_val, $1, PSI_INCLUDES)
+ ;;
+ esac
+ psi_cv_const_$1=$psi_const_val
+ ])
+ if test "$psi_cv_const_$1"
+ then
+ case $2 in
+ str*)
+ add_str_const "$1" "$psi_cv_const_$1"
+ ;;
+ int)
+ add_int_const "$1" "$psi_cv_const_$1"
+ ;;
+ esac
+ fi
+])
--- /dev/null
+PSI_REDIRS=
+AC_DEFUN(PSI_REDIR, [psi_symbol=ifelse([$2],[],[$1],[$2])
+ PSI_REDIRS="{\"$1\", (void(*)(void))$psi_symbol}, $PSI_REDIRS"])
+
+dnl PSI_FUNC(fn, action-if-yes, action-if-no)
+AC_DEFUN(PSI_FUNC, [
+ AC_REQUIRE([AC_PROG_NM])
+ AC_REQUIRE([AC_PROG_AWK])
+ psi_symbol=$1
+ AC_CACHE_CHECK(for $1, psi_cv_fn_$1, [
+ psi_symbol_redirect=
+ AC_TRY_LINK(PSI_INCLUDES, [
+ void (*fn)(void) = (void (*)(void)) $psi_symbol;
+ ], [
+ psi_symbol_redirect=`$NM -g conftest$ac_exeext | $AWK -F" *|@" '/ U .*$1.*/ {print$[]3; exit}'`
+ ])
+ psi_cv_fn_$1=$psi_symbol_redirect
+ ])
+ case "$psi_cv_fn_$1" in
+ "")
+ $3
+ ;;
+ "$psi_symbol"|"_$psi_symbol")
+ $2
+ ;;
+ *)
+ $2
+ PSI_REDIR($1)
+ ;;
+ esac
+])
+
+AC_DEFUN(PSI_DECL_ARG, [
+ m4_define([member_name], PSI_VAR_NAME($1))
+ m4_define([member_type], PSI_TYPE_NAME($1))
+ m4_define([pointer_level], m4_len(m4_bpatsubst($1, [[^*]])))
+ m4_define([array_size], m4_bregexp($1, [\[\([0-9]+\)\]], [\1]))
+ ifelse(array_size, [],
+ [m4_define([array_size], 0)],
+ [m4_define([pointer_level], m4_incr(pointer_level))]
+ )
+ if test -n "$psi_decl_args"; then
+ psi_decl_args="$psi_decl_args, "
+ fi
+ psi_decl_args="[$psi_decl_args{]PSI_TYPE_PAIR(member_type)[, \"]member_name[\",] pointer_level, array_size[}]"
+])
+
+dnl PSI_DECL(type func, args)
+AC_DEFUN(PSI_DECL, [
+ psi_decl_args=
+ PSI_DECL_ARG($1)
+ m4_case([$2],
+ [(void)], [],
+ [()], [],
+ [m4_map_args_sep([PSI_DECL_ARG(], [)], [], m4_bregexp($2, [(\(.*\))], [\1]))])
+ PSI_FUNC(PSI_VAR_NAME($1), [
+ PSI_DECLS="{$psi_decl_args}, $PSI_DECLS"
+ ], [
+ PSI_MACRO(PSI_VAR_NAME($1), $3, [
+ add_macro "PSI_TYPE_NAME($1)" "PSI_VAR_NAME($1)" "$3"
+ PSI_DECLS="{$psi_decl_args}, $PSI_DECLS"
+ ])
+ ])
+])
size_t gl_offs,
int gl_flags,
char **gl_pathv])
- PSI_DECL(int, glob, [(char *path, int flags, void *err, glob_t *buf)])
- PSI_DECL(void, globfree, [(glob_t *buf)])
+
+ PSI_DECL(int glob, [(char *path, int flags, void *err, glob_t *buf)])
+ PSI_DECL(void globfree, [(glob_t *buf)])
+
PSI_CONST(GLOB_APPEND, int)
PSI_CONST(GLOB_BRACE, int)
PSI_CONST(GLOB_DOOFFS, int)
--- /dev/null
+# arg_names(typed args)
+arg_names() {
+ AS_ECHO_N([$1]) \
+ | tr -cd '()' \
+ | $AWK -F, '{for (i=1;i<NF;++i) print $i ","; print $NF}' \
+ | $AWK '{print $NF}' \
+ | xargs
+}
+PSI_MACROS=
+# gen_macro(ret type, symbol, args)
+gen_macro() {
+ local dargs="$3"
+ test -z "$3" && dargs="()"
+ AS_ECHO_N(["static $1 psi_macro_$2$dargs {"])
+ if test "$1" != "void"; then
+ AS_ECHO_N(["return "])
+ fi
+ arg_names "$3"
+ AS_ECHO_N(["$2`arg_names \"$3\"`;}"])
+}
+# add_macro(ret type, symbol, args)
+add_macro() {
+ local psi_macro
+ psi_macro=`gen_macro "$1" "$2" "$3"`
+ PSI_MACROS="$psi_macro $PSI_MACROS"
+ PSI_REDIR([$2], [psi_macro_$2])
+}
+
+dnl PSI_MACRO(macro, decl args, action-if-true)
+AC_DEFUN(PSI_MACRO, [
+ AC_CHECK_DECL($1$2, $3, [], PSI_INCLUDES)
+])
+
+dnl PSI_EXTVAR(var, type)
+AC_DEFUN(PSI_EXTVAR, [
+ AC_CHECK_DECL($1, [
+ add_macro "$2" "$1"
+ ], [], PSI_INCLUDES)
+])
--- /dev/null
+AC_DEFUN(PSI_CHECK_STDIO, [
+ AC_CHECK_HEADER(stdio.h)
+
+ PSI_STRUCT(FILE)
+ PSI_STRUCT(fpos_t)
+
+ PSI_CONST(BUFSIZ, int)
+ PSI_CONST(_IOFBF, int)
+ PSI_CONST(_IOLBF, int)
+ PSI_CONST(_IONBF, int)
+ PSI_CONST(SEEK_CUR, int)
+ PSI_CONST(SEEK_END, int)
+ PSI_CONST(SEEK_SET, int)
+ PSI_CONST(FILENAME_MAX, int)
+ PSI_CONST(FOPEN_MAX, int)
+ PSI_CONST(TMP_MAX, int)
+ PSI_CONST(EOF, int)
+ PSI_CONST(P_tmpdir, string)
+ PSI_CONST(L_ctermid, int)
+ PSI_CONST(L_tmpnam, int)
+
+ PSI_DECL(void clearerr, [(FILE *stream)])
+ PSI_DECL(char *ctermid, [(char *s)])
+ PSI_DECL(int fclose, [(FILE *stream)])
+ PSI_DECL(FILE *fdopen, [(int fd, char *mode)])
+ PSI_DECL(int feof, [(FILE *stream)])
+ PSI_DECL(int ferror, [(FILE *stream)])
+ PSI_DECL(int fflush, [(FILE *stream)])
+ PSI_DECL(int fgetc, [(FILE *stream)])
+ PSI_DECL(int fgetpos, [(FILE *stream, fpos_t *pos)])
+ PSI_DECL(char *fgets, [(char *buf, int len, FILE *stream)])
+ PSI_DECL(int fileno, [(FILE *stream)])
+ PSI_DECL(void flockfile, [(FILE *stream)])
+ PSI_DECL(FILE *fmemopen, [(void *buf, size_t len, char *mode)])
+ PSI_DECL(FILE *fopen, [(char *path, char *mode)])
+ PSI_DECL(int fputc, [(int c, FILE *stream)])
+ PSI_DECL(int fputs, [(char *s, FILE *stream)])
+ PSI_DECL(size_t fread, [(void *buf, size_t len, size_t n, FILE *stream)])
+ PSI_DECL(FILE *freopen, [(char *path, char *mode, FILE *stream)])
+ PSI_DECL(int fseek, [(FILE *stream, long offset, int whence)])
+ PSI_DECL(int fseeko, [(FILE *stream, off_t offset, int whence)])
+ PSI_DECL(int fsetpos, [(FILE *stream, fpos_t *pos)])
+ PSI_DECL(long ftell, [(FILE *stream)])
+ PSI_DECL(off_t ftello, [(FILE *stream)])
+ PSI_DECL(int ftrylockfile, [(FILE *stream)])
+ PSI_DECL(void funlockfile, [(FILE *stream)])
+ PSI_DECL(size_t fwrite, [(void *buf, size_t len, size_t n, FILE *stream)])
+ PSI_DECL(int getc, [(FILE *stream)])
+ PSI_DECL(int getchar, [(void)])
+ PSI_DECL(int getc_unlocked, [(FILE *stream)])
+ PSI_DECL(int getchar_unlocked, [(void)])
+ PSI_DECL(ssize_t getdelim, [(char **lineptr, size_t *n, int delim, FILE *stream)])
+ PSI_DECL(ssize_t getline, [(char **lineptr, size_t *n, FILE *stream)])
+ PSI_DECL(char *gets, [(char *buf)])
+ PSI_DECL(FILE *open_memstream, [(char **ptr, size_t *sizeloc)])
+ PSI_DECL(int pclose, [(FILE *stream)])
+ PSI_DECL(void perror, [(char *s)])
+ PSI_DECL(FILE *popen, [(char *command, char *type)])
+ PSI_DECL(int putc, [(int c, FILE *stream)])
+ PSI_DECL(int putchar, [(int c)])
+ PSI_DECL(int putc_unlocked, [(int c, FILE *stream)])
+ PSI_DECL(int putchar_unlocked, [(int c)])
+ PSI_DECL(int puts, [(char *s)])
+ PSI_DECL(int remove, [(char *path)])
+ PSI_DECL(int rename, [(char *old, char *new)])
+ PSI_DECL(int renameat, [(int oldfd, char *oldpath, int newfd, char *newpath)])
+ PSI_DECL(void rewind, [(FILE *stream)])
+ PSI_DECL(void setbuf, [(FILE *stream, char *buf)])
+ PSI_DECL(int setvbuf, [(FILE *stream, char *buf, int mode, size_t size)])
+ PSI_DECL(char *tempnam, [(char *dir, char *prefix)])
+ PSI_DECL(FILE *tmpfile, [(void)])
+ PSI_DECL(char *tmpnam, [(char *s)])
+ PSI_DECL(int ungetc, [(int c, FILE *stream)])
+
+])
--- /dev/null
+PSI_STRUCTS=
+# add_struct(name, size, members)
+add_struct() {
+ local members="$3"
+ if test -z "$members"; then
+ members="{0}"
+ else
+ members="$members, {0}"
+ fi
+ PSI_STRUCTS="{\"$1\", $2, {$members}}, $PSI_STRUCTS"
+}
+
+AC_DEFUN(PSI_STRUCT_MEMBER, [
+ m4_define([member_name], PSI_VAR_NAME($2))
+ m4_define([member_type], PSI_TYPE_NAME($2))
+ AC_CHECK_SIZEOF(AS_TR_SH($1)[_]member_name, [], PSI_INCLUDES
+ [#define ]AS_TR_SH($1)[_]member_name (($1 *)0)->member_name
+ )
+ PSI_CHECK_OFFSETOF($1, member_name)
+ m4_define([pointer_level], m4_len(m4_bpatsubst($2, [[^*]])))
+ m4_define([array_size], m4_bregexp($2, [\[\([0-9]+\)\]], [\1]))
+ ifelse(array_size, [],
+ [m4_define([array_size], 0)],
+ [m4_define([pointer_level], m4_incr(pointer_level))]
+ )
+ m4_define([member_size], PSI_TYPE_SIZE(member_type, pointer_level, array_size))
+ if test -n "$psi_struct_members"; then
+ psi_struct_members="$psi_struct_members, "
+ fi
+ psi_struct_members="[$psi_struct_members{]PSI_TYPE_PAIR(member_type)[, \"]member_name[\", $]AS_TR_SH([ac_cv_offsetof_]$1[_]member_name)[, ]member_size, pointer_level, array_size[}]"
+])
+
+AC_DEFUN(PSI_STRUCT, [
+ AC_CHECK_SIZEOF($1, [], PSI_INCLUDES)
+ psi_struct_members=
+ ifelse([$2],[],[],[m4_map_args_sep([PSI_STRUCT_MEMBER($1,], [)], [], $2)])
+ add_struct "$1" $AS_TR_SH([ac_cv_sizeof_]$1) "$psi_struct_members"
+])
-psi_type_pair() { # (type, size)
- local psi_type_name=`tr -cd A-Za-z <<<$1`
+# psi_type_pair(type, size)
+psi_type_pair() {
+ local psi_type_name=`tr -cd A-Za-z0-9_ <<<$1`
local psi_type_lower=`tr A-Z a-z <<<$psi_type_name`
case $psi_type_lower in
int*|uint*)
local psi_type_upper=`tr a-z A-Z <<<$psi_type_name`
local psi_type_bits=`expr $2 \* 8`
+ echo psi_type_bits=$psi_type_bits "expr $2 \* 8" "$@" >&2
echo "PSI_T_${psi_type_upper}${psi_type_bits}, \"${psi_type_lower}${psi_type_bits}_t\""
+ eval AS_TR_SH([psi_standard_type_]$1)="${psi_type_lower}${psi_type_bits}_t"
;;
struct*)
echo "PSI_T_STRUCT, \"$2\""
psi_basic_type=int
;;
esac
- if test "$2" && test "$ac_cv_sizeof_[]$1" -gt 0; then
+ if test "$2" && test "$AS_TR_SH([ac_cv_sizeof_]$1)" -gt 0; then
AS_TR_SH(psi_basic_type_$1)=$psi_basic_type
- PSI_TYPES="{`psi_type_pair $psi_basic_type $ac_cv_sizeof_[]$1`, \""$1"\"}, $PSI_TYPES"
+ PSI_TYPES="{`psi_type_pair $psi_basic_type $AS_TR_SH([ac_cv_sizeof_]$1)`, \"$1\"}, $PSI_TYPES"
fi
])
-PSI_CONSTS=""
-# add_str_const(name, value)
-add_str_const() {
- PSI_CONSTS="{PSI_T_STRING, \"string\", \"psi\\\\$1\", $2, PSI_T_QUOTED_STRING}, $PSI_CONSTS"
-}
-# add_int_const(name, value)
-add_int_const() {
- PSI_CONSTS="{PSI_T_INT, \"int\", \"psi\\\\$1\", \"$2\", PSI_T_NUMBER}, $PSI_CONSTS"
-}
-dnl PSI_CONST(const name, type)
-AC_DEFUN(PSI_CONST, [
- AC_CACHE_CHECK(value of $1, psi_cv_const_$1, [
- psi_const_val=
- case $2 in
- str*)
- if test "$cross_compiling" = "yes"
- then
- AC_TRY_CPP(PSI_INCLUDES $1, psi_const_val=`eval "$ac_try|tail -n1"`, psi_const_val=)
- else
- PSI_COMPUTE_STR(psi_const_val, $1, PSI_INCLUDES)
- fi
- ;;
- int)
- AC_COMPUTE_INT(psi_const_val, $1, PSI_INCLUDES)
- ;;
- esac
- psi_cv_const_$1=$psi_const_val
- ])
- if test "$psi_cv_const_$1"
- then
- case $2 in
- str*)
- add_str_const "$1" "$psi_cv_const_$1"
- ;;
- int)
- add_int_const "$1" "$psi_cv_const_$1"
- ;;
- esac
- fi
-])
-
-PSI_DECLS=
-# add_decl(ret type, symbol, args)
-add_decl() {
- local size
- eval size=\$ac_cv_sizeof_$1
- PSI_DECLS="{`psi_type_pair \"$1\" \"$size\"`, \"$2\"}, $PSI_DECLS"
-}
-PSI_REDIR=
-# add_redir(symbol, macro=symbol)
-add_redir() {
- local sym=$2
- test -z "$sym" && sym=$1
- PSI_REDIR="{\"$1\", (void (*)(void)) $sym}, $PSI_REDIR"
-}
-# arg_names(typed args)
-arg_names() {
- AS_ECHO_N([$1]) \
- | tr -cd '()' \
- | $AWK -F, '{for (i=1;i<NF;++i) print $i ","; print $NF}' \
- | $AWK '{print $NF}' \
- | xargs
-}
-PSI_MACROS=
-# gen_macro(ret type, symbol, args)
-gen_macro() {
- local dargs="$3"
- test -z "$3" && dargs="()"
- AS_ECHO_N(["static $1 psi_macro_$2$dargs {"])
- if test "$1" != "void"; then
- AS_ECHO_N(["return "])
- fi
- arg_names "$3"
- AS_ECHO_N(["$2`arg_names \"$3\"`;}"])
-}
-# add_macro(ret type, symbol, args)
-add_macro() {
- PSI_MACROS="`gen_macro \"$1\" \"$2\" \"$3\"` $PSI_MACROS"
- add_redir "$2" "psi_macro_$2"
-}
-
-dnl PSI_MACRO(macro, decl args, action-if-true)
-AC_DEFUN(PSI_MACRO, [
- AC_CHECK_DECL($1$2, $3, [], PSI_INCLUDES)
-])
+dnl unsigned char* buf[16] -> char
+AC_DEFUN(PSI_TYPE_NAME, [m4_bregexp([$1], [\(\(struct \)?[^ ]+\)[ *]+[^ ]+$], [\1])])
+dnl unsigned char* buf[16] -> buf
+AC_DEFUN(PSI_VAR_NAME, [m4_bregexp(m4_bregexp([$1], [[^ ]+$], [\&]), [\w+], [\&])])
+dnl PSI_TYPE_SIZE(type, pointer level, array size)
+AC_DEFUN(PSI_TYPE_SIZE, [ifelse(
+ [$3], 0,
+ [ifelse([$2], 0, $AS_TR_SH([ac_cv_sizeof_]$1), $ac_cv_sizeof_void_p)],
+ [ifelse([$2], 1, [`expr $3 \* $AS_TR_SH([ac_cv_sizeof_]$1)`], $ac_cv_sizeof_void_p)]
+)])
+dnl PSI_TYPE_BITS(type)
+AC_DEFUN(PSI_TYPE_BITS, [`expr 8 \* $AS_TR_SH([ac_cv_sizeof_]$1)`])
-dnl PSI_FUNC(fn, action-if-yes, action-if-no)
-AC_DEFUN(PSI_FUNC, [
- AC_REQUIRE([AC_PROG_NM])
- AC_REQUIRE([AC_PROG_AWK])
- psi_symbol=$1
- AC_CACHE_CHECK(for $1, psi_cv_fn_$1, [
- psi_symbol_redirect=
- AC_TRY_LINK(PSI_INCLUDES, [
- void (*fn)(void) = (void (*)(void)) $psi_symbol;
- ], [
- psi_symbol_redirect=`$NM -g conftest$ac_exeext | $AWK -F" *|@" '/ U .*$1.*/ {print$[]3; exit}'`
- ])
- psi_cv_fn_$1=$psi_symbol_redirect
- ])
- case "$psi_cv_fn_$1" in
- "") $3 ;;
- "$psi_symbol"|"_$psi_symbol") $2 ;;
- *) add_redir "$psi_symbol"; $2 ;;
- esac
-])
-
-dnl PSI_EXTVAR(var, type)
-AC_DEFUN(PSI_EXTVAR, [
- AC_CHECK_DECL($1, [
- add_macro "$2" "$1"
- ], [], PSI_INCLUDES)
-])
-
-
-dnl PSI_DECL(ret type, func, args)
-AC_DEFUN(PSI_DECL, [
- PSI_FUNC($2, [
- add_decl "$1" "$2" "$3"
- ], [
- PSI_MACRO($2, $3, [
- add_macro "$1" "$2" "$3"
- add_decl "$1" "$2" "$3"
- ])
- ])
-])
-
-AC_DEFUN(PSI_STRUCT_MEMBER, [
- psi_member_name=
- psi_member_type=
- m4_map_args_w([$1], [
- psi_member_type="$psi_member_type $psi_member_name"
- psi_member_name=], [
- ])
- AC_MSG_RESULT([member=$psi_member_name - $psi_member_type])
-])
-
-AC_DEFUN(PSI_STRUCT, [
- AC_CHECK_SIZEOF($1, [], PSI_INCLUDES)
- m4_map_args([PSI_STRUCT_MEMBER], $2)
- exit
-])
+AC_DEFUN(PSI_TYPE_PAIR, [m4_case(m4_bregexp([$1], [^\w+], [\&]),
+ [void], [PSI_T_VOID, \"void\"],
+ [struct], [PSI_T_STRUCT, \"m4_bregexp($1, [^struct \(\w+\)], [\1])\"],
+ [PSI_T_NAME, \"$1\"]
+)])
AC_DEFUN(PSI_CHECK_STD_TYPES, [
AC_CHECK_HEADERS(stdint.h)
AC_CHECK_ALIGNOF(void *)
PSI_TYPE(char, int)
+ PSI_TYPE(unsigned char, uint)
PSI_TYPE(short, int)
+ PSI_TYPE(unsigned short, uint)
PSI_TYPE(int, int)
+ PSI_TYPE(unsigned int, uint)
+ PSI_TYPE(unsigned, uint)
PSI_TYPE(long, int)
+ PSI_TYPE(unsigned long, uint)
])