diff options
author | Michael Jennings <mej@kainx.org> | 2002-08-05 00:22:09 +0000 |
---|---|---|
committer | Michael Jennings <mej@kainx.org> | 2002-08-05 00:22:09 +0000 |
commit | a11477d57aedc98201f3637c4df08822716583d3 (patch) | |
tree | 3012fb6e5f7b4525521859cd1be52b684a8dda87 | |
parent | cef81c964e3a9cbaf1cff0842b191ba9adf42a06 (diff) | |
download | libast-a11477d57aedc98201f3637c4df08822716583d3.tar.gz |
Sun Aug 4 20:11:38 2002 Michael Jennings (mej)
Did a complete overhaul of the configure.in script. Moved everything
to macros in libast.m4, which is now installed by the package. That
will facilitate easier development of libast-based programs.
Also added the beginnings of a regexp class with support for PCRE,
POSIX-, and BSD-style regular expressions.
SVN revision: 6356
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | Makefile.am | 11 | ||||
-rw-r--r-- | acconfig.h | 6 | ||||
-rw-r--r-- | acinclude.m4 | 263 | ||||
-rw-r--r-- | configure.in | 228 | ||||
-rw-r--r-- | include/libast.h | 1 | ||||
-rw-r--r-- | include/libast/Makefile.am | 4 | ||||
-rw-r--r-- | include/libast/regexp.h | 98 | ||||
-rw-r--r-- | include/libast/str.h | 16 | ||||
-rw-r--r-- | libast-config.in | 3 | ||||
-rw-r--r-- | libast.m4 | 619 | ||||
-rw-r--r-- | libast.spec | 5 | ||||
-rw-r--r-- | src/Makefile.am | 4 | ||||
-rw-r--r-- | src/regexp.c | 140 |
14 files changed, 918 insertions, 489 deletions
@@ -278,3 +278,12 @@ I create a listening socket and a sending socket for a TCP/IP and a UNIX socket. Then I send/receive data across the socket and compare what I received with what I sent. Self-contained is better. :-) ---------------------------------------------------------------------- +Sun Aug 4 20:11:38 2002 Michael Jennings (mej) + +Did a complete overhaul of the configure.in script. Moved everything +to macros in libast.m4, which is now installed by the package. That +will facilitate easier development of libast-based programs. + +Also added the beginnings of a regexp class with support for PCRE, +POSIX-, and BSD-style regular expressions. +---------------------------------------------------------------------- diff --git a/Makefile.am b/Makefile.am index 272f78c..2532ecd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -5,7 +5,10 @@ SUBDIRS = include src test bin_SCRIPTS = libast-config -EXTRA_DIST = README +MACROS = libast.m4 +macrodir = $(datadir)/aclocal + +EXTRA_DIST = README $(MACROS) test: all cd test && $(MAKE) test @@ -13,4 +16,10 @@ test: all perf: all cd test && $(MAKE) perf +install-data-hook: + $(mkinstalldirs) $(DESTDIR)$(macrodir) + for i in $(MACROS) ; do \ + $(INSTALL_DATA) $(srcdir)/$$i $(DESTDIR)$(macrodir)/ ; \ + done + .PHONY: test @@ -7,4 +7,10 @@ #undef LIBAST_X11_SUPPORT #undef LIBAST_IMLIB2_SUPPORT #undef LIBAST_MMX_SUPPORT +#undef LIBAST_REGEXP_SUPPORT #undef ALLOW_BACKQUOTE_EXEC +#undef HAVE_RLIMIT_MEMLOCK +#undef HAVE_RLIMIT_NPROC +#undef HAVE_SYMLINK_OPEN_ERRNO_BUG +#undef HAVE_SYMLINK_OPEN_SECURITY_HOLE +#undef HAVE_VSNPRINTF_BUG diff --git a/acinclude.m4 b/acinclude.m4 deleted file mode 100644 index b25d7dd..0000000 --- a/acinclude.m4 +++ /dev/null @@ -1,263 +0,0 @@ -dnl -AC_DEFUN(AST_SIZE_TYPE, -[BIT_SIZE=[$1] -BYTE_SIZE=`expr $BIT_SIZE '/' 8` -case $BYTE_SIZE in - $ac_cv_sizeof_char) eval INT_${BIT_SIZE}_TYPE=char ;; - $ac_cv_sizeof_short) eval INT_${BIT_SIZE}_TYPE=short ;; - $ac_cv_sizeof_int) eval INT_${BIT_SIZE}_TYPE=int ;; - $ac_cv_sizeof_long) eval INT_${BIT_SIZE}_TYPE=long ;; - $ac_cv_sizeof_long_long) eval INT_${BIT_SIZE}_TYPE="'long long'" ;; -esac -test -z "`eval echo '$'INT_${BIT_SIZE}_TYPE`" && eval INT_${BIT_SIZE}_TYPE=long -]) - -dnl acl.m4 -- Written by Duncan Simpson <dps@io.stargate.co.uk> -dnl Posted to BUGTRAQ on 17 June 1999 -dnl Used by encouragement. :-) - -dnl Check snprintf for overrun potential -AC_DEFUN(dps_snprintf_oflow, -[AC_MSG_CHECKING(whether snprintf ignores n) -AC_CACHE_VAL(dps_cv_snprintf_bug, -[AC_TRY_RUN( -changequote(<<, >>)dnl -<<#include <stdio.h> - -#ifndef HAVE_SNPRINTF -#ifdef HAVE_VSNPRINTF -#include "vsnprintf.h" -#else /* not HAVE_VSNPRINTF */ -#include "vsnprintf.c" -#endif /* HAVE_VSNPRINTF */ -#endif /* HAVE_SNPRINTF */ - -int main(void) -{ -char ovbuf[7]; -int i; -for (i=0; i<7; i++) ovbuf[i]='x'; -snprintf(ovbuf, 4,"foo%s", "bar"); -if (ovbuf[5]!='x') exit(1); -snprintf(ovbuf, 4,"foo%d", 666); -if (ovbuf[5]!='x') exit(1); -exit(0); -} >> -changequote([, ]), dps_cv_snprintf_bug=0, dps_cv_snprintf_bug=1, -dps_cv_snprintf_bug=2)]) -if test $dps_cv_snprintf_bug -eq 0; then - AC_MSG_RESULT([no, snprintf is ok]) -else if test $dps_cv_snprint_bug -eq 1; then - AC_MSG_RESULT([yes, snprintf is broken]) - AC_DEFINE(HAVE_SNPRINTF_BUG,1) -else - AC_MSG_RESULT([unknown, assuming yes]) - AC_DEFINE(HAVE_SNPRINTF_BUG,1) -fi; fi]) - -dnl Check vsnprintf for overrun potential -AC_DEFUN(dps_vsnprintf_oflow, -[AC_MSG_CHECKING(whether vsnprintf ignores n) -AC_CACHE_VAL(dps_cv_vsnprintf_bug, -[AC_TRY_RUN( -changequote(<<, >>)dnl -<<#include <stdio.h> -#include <stdarg.h> - -#ifndef HAVE_VSNPRINTF -#include "vsnprintf.c" -#endif /* HAVE_VSNPRINTF */ - -int prnt(char *s, const char *fmt, ...) -{ - va_list argp; - va_start(argp, fmt); - vsnprintf(s, 4, fmt, argp); - va_end(argp); -} - -int main(void) -{ - char ovbuf[7]; - int i; - for (i=0; i<7; i++) ovbuf[i]='x'; - prnt(ovbuf, "foo%s", "bar"); - if (ovbuf[5]!='x') exit(1); - prnt(ovbuf, "foo%d", 666); - if (ovbuf[5]!='x') exit(1); - exit(0); -} >> -changequote([, ]), dps_cv_vsnprintf_bug=0, dps_cv_vsnprintf_bug=1, -dps_cv_vsnprintf_bug=2)]) - -if test $dps_cv_vsnprintf_bug -eq 0; then - AC_MSG_RESULT([no, vsnprintf is ok]) -else if test $dps_cv_vsnprint_bug -eq 1; then - AC_MSG_RESULT([yes, vsnprintf is broken]) - AC_DEFINE(HAVE_VSNPRINTF_BUG,1) -else - AC_MSG_RESULT([unknown, assuming yes]) - AC_DEFINE(HAVE_VSNPRINTF_BUG,1) -fi; fi]) - -dnl open and symlink interaction bug test -AC_DEFUN(dps_symlink_open_bug, -[AC_MSG_CHECKING(security of interaction between symlink and open) -AC_CACHE_VAL(dps_cv_symlink_open_bug, -[mkdir conftest.d -AC_TRY_RUN( -changequote(<<, >>)dnl -<<#include <stdio.h> -#ifdef HAVE_STDLIB_H -#include <stdlib.h> -#endif -#ifdef HAVE_SYS_TYPES_H -#include <sys/types.h> -#endif -#ifdef HAVE_SYS_STAT_H -#include <sys/stat.h> -#endif -#ifdef HAVE_FCNTL_H -#include <fcntl.h> -#endif -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif -#ifdef HAVE_ERRNO_H -#include <errno.h> -#else -extern int errno; -#endif - -int main(void) -{ - int fd; - if (chdir("conftest.d")!=0) - exit(1); - if (symlink("foo","bar")!=0) - exit(1); - if ((fd=open("bar", O_CREAT | O_EXCL | O_WRONLY, 0700))==0) - { - write(fd, "If the symlink was to .rhosts you would be unhappy", 50); - close(fd); - exit(1); - } - if (errno!=EEXIST) - exit(1); - exit(0); -} >> -changequote([, ]), cps_cv_symlink_open_bug=0, -[if test -r conftest.d/foo; then - cps_cv_symlink_open_bug=2 -else - cps_cv_symlink_open_bug=1 -fi], cps_cv_symlink_open_buf=3) -rm -rf conftest.d]) -case "$cps_cv_symlink_open_bug" in -0) AC_MSG_RESULT(secure) ;; -1) AC_MSG_RESULT(errno wrong but ok) - AC_DEFINE(HAVE_SYMLINK_OPEN_ERRNO_BUG) ;; -2) AC_MSG_RESULT(insecure) - AC_DEFINE(HAVE_SYMLINK_OPEN_SECURITY_HOLE) - AC_DEFINE(HAVE_SYMLINK_OPEN_ERRNO_BUG) ;; -3) AC_MSG_RESULT(assuming insecure) - AC_DEFINE(HAVE_SYMLINK_OPEN_SECURITY_HOLE) - AC_DEFINE(HAVE_SYMLINK_OPEN_ERRNO_BUG) ;; -*) AC_MSG_RESULT($cps_cv_symlink_open_bug) - AC_MSG_ERROR(Impossible value of cps_cv_symlink_open_bug) ;; -esac]) - -dnl Check to RLIMIT_NPROC resource limit -AC_DEFUN(dps_rlimit_nproc, -[AC_MSG_CHECKING(for working RLIMIT_NPROC resource limit) -AC_CACHE_VAL(dps_cv_rlimit_nproc, -[AC_TRY_RUN( -changequote(<<, >>)dnl -<< -#ifndef HAVE_STDLIB_H -#include <stdlib.h> -#endif /* HAVE_STDLIB_H */ -#ifndef HAVE_SIGNAL_H -#include <signal.h> -#endif /* HAVE_SIGNAL_H */ -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif /* HAVE_UNISTD_H */ -#ifdef HAVE_SYS_RESOURCE_H -#include <sys/resource.h> -#endif /* HAVE_SYS_RESOURCE_H */ - -int main(void) -{ -#ifdef RLIMIT_NPROC - static const struct rlimit pid_lim={RLIMIT_NPROC, 1}; - pid_t f; - - signal(SIGCHLD, SIG_IGN); - setrlimit(RLIMIT_NPROC, (struct rlimit *) &pid_lim); - if ((f=fork())==0) - exit(0); - if (f==-1) - exit(0); /* The fork() failed (the right thing) */ -#endif - exit(1); -} >> -changequote([, ]), cps_cv_rlimit_nproc=0, cps_cv_rlimit_nproc=1, -cps_cv_rlimit_nproc=2)]) -if test $cps_cv_rlimit_nproc -eq 0; then - AC_MSG_RESULT([yes]) - AC_DEFINE(HAVE_RLIMIT_NPROC,1) -else if test $cps_cv_rlimit_nproc -eq 1; then - AC_MSG_RESULT([no]) -else - AC_MSG_RESULT([unknown, assuming none]) -fi; fi]) - -dnl Check to RLIMIT_MEMLOCK resource limit -AC_DEFUN(cps_rlimit_memlock, -[AC_MSG_CHECKING(for RLIMIT_MEMLOCK resource limit) -AC_CACHE_VAL(cps_cv_rlimit_memlock, -[AC_TRY_RUN( -changequote(<<, >>)dnl -<< -#ifndef HAVE_STDLIB_H -#include <stdlib.h> -#endif /* HAVE_STDLIB_H */ -#ifndef HAVE_SIGNAL_H -#include <signal.h> -#endif /* HAVE_SIGNAL_H */ -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif /* HAVE_UNISTD_H */ -#ifdef HAVE_SYS_RESOURCE_H -#include <sys/resource.h> -#endif /* HAVE_SYS_RESOURCE_H */ -#ifdef HAVE_SYS_MMAN -#include <sys/mman.h> -#endif /* HAVE_SYS_MMAN */ -#ifdef HAVE_ERRNO_H -#include <errno.h> -#endif /* HAVE_ERRNO_H */ - -int main(void) -{ -#ifdef RLIMIT_MEMLOCK - static const struct rlimit mlock_lim={RLIMIT_MEMLOCK, 0}; - void *memory; - - if (setrlimit(RLIMIT_MEMLOCK, (struct rlimit *) &mlock_lim)!=-1) - exit(0); -#endif -exit(1); -} >> -changequote([, ]), cps_cv_rlimit_memlock=0, cps_cv_rlimit_memlock=1, -cps_cv_rlimit_memlock=2)]) -if test $cps_cv_rlimit_memlock -eq 0; then - AC_MSG_RESULT([yes]) - AC_DEFINE(HAVE_RLIMIT_MEMLOCK,1) -else if test $cps_cv_rlimit_memlock -eq 1; then - AC_MSG_RESULT([no]) -else - AC_MSG_RESULT([unknown, assuming none]) -fi; fi]) - diff --git a/configure.in b/configure.in index 1a00910..b6ab062 100644 --- a/configure.in +++ b/configure.in @@ -9,203 +9,26 @@ AUTHORS="Michael Jennings (mej@eterm.org)" AC_SUBST(AUTHORS) AC_DEFINE_UNQUOTED(AUTHORS, "$AUTHORS") -AC_PROG_CC -AC_PROG_CPP - -dnl# These must be run after AC_PROG_CC but before any other macros that use -dnl# the C compiler -AC_AIX -AC_ISC_POSIX -AC_MINIX - -dnl# At least make the attempt to support CygWin32 -AC_CYGWIN -AC_ARG_PROGRAM - -AM_PROG_LIBTOOL - -AC_GCC_TRADITIONAL - -AC_PROG_INSTALL - -ASFLAGS="$ASFLAGS -I../" -AS=$CC -AC_SUBST(ASFLAGS) -AC_SUBST(AS) - -dnl# Check for host system type -AC_CANONICAL_HOST - -dnl# Check the sanity of what we've done so far -AM_SANITY_CHECK - -dnl# Most people don't want the developer-only clutter -AM_MAINTAINER_MODE - -dnl# If it's there, what the hell? -AM_WITH_DMALLOC - -dnl# Look for needed programs -AC_CHECK_PROG(SED, sed, sed, false) -AC_CHECK_PROG(RM, rm, rm, true) -AC_CHECK_PROG(CP, cp, cp, false) -AC_CHECK_PROG(CHMOD, chmod, chmod, true) -AC_CHECK_PROG(TAR, tar, tar, tar) -AC_CHECK_PROG(MKDIR, mkdir, mkdir, false) -AC_CHECK_PROG(CTAGS, ctags, ctags, true) -AC_CHECK_PROG(AR, ar, ar, false) -AC_CHECK_PROG(MV, mv, mv, true) -AC_LN_S - -AC_CHECK_SIZEOF(char, 1) -AC_CHECK_SIZEOF(short, 2) -AC_CHECK_SIZEOF(int, 4) -AC_CHECK_SIZEOF(long, 4) -AC_CHECK_SIZEOF(long long, 8) -AC_C_BIGENDIAN - -AST_SIZE_TYPE(8) -AC_SUBST(INT_8_TYPE) -AST_SIZE_TYPE(16) -AC_SUBST(INT_16_TYPE) -AST_SIZE_TYPE(32) -AC_SUBST(INT_32_TYPE) -AST_SIZE_TYPE(64) -AC_SUBST(INT_64_TYPE) - -AC_C_CONST -AC_C_INLINE -AC_PATH_XTRA - -if test ! -z "$X_CFLAGS"; then - if test -z "$CPPFLAGS"; then - CPPFLAGS="$X_CFLAGS" - else - CPPFLAGS="$CPPFLAGS $X_CFLAGS" - fi -fi -if test ! -z "$X_LIBS"; then - if test -z "$LDFLAGS"; then - LDFLAGS="$X_LIBS" - else - LDFLAGS="$LDFLAGS $X_LIBS" - fi +AST_STD_CHECKS() +AST_PROG_CHECKS() +AST_VAR_CHECKS() +AST_HEADER_CHECKS() +AST_TYPE_CHECKS() +AST_FUNC_CHECKS() + +AST_ARG_DEBUG(DEBUG) +if test $DEBUG -eq 0 ; then + AC_WARN(*** Debugging support disabled. Client programs will ***) + AC_WARN(*** not have access to any libast debugging routines! ***) fi -dnl# -dnl# X LIBRARIES -dnl# -LIBAST_X11_SUPPORT="" -if test "x$no_x" != "xyes"; then - AC_CHECK_LIB(X11, XOpenDisplay, LIBAST_X11_SUPPORT="X11" ; GRLIBS="-lX11" ; AC_DEFINE(LIBAST_X11_SUPPORT)) -fi -AC_SUBST(LIBAST_X11_SUPPORT) - -dnl# Checks for header files. -AC_HEADER_SYS_WAIT -AC_CHECK_HEADERS(fcntl.h termios.h sys/ioctl.h sys/select.h sys/time.h sys/sockio.h sys/byteorder.h malloc.h \ -utmpx.h unistd.h bsd/signal.h regex.h regexp.h stdarg.h) -AC_HEADER_TIME - -dnl# Missing typedefs and replacements -AC_TYPE_MODE_T -AC_CHECK_TYPE(off_t, long) -AC_TYPE_PID_T -AC_TYPE_UID_T - -dnl# Checks for library functions. -AC_TYPE_SIGNAL -AC_CHECK_FUNCS(memmove putenv strsep memmem usleep snprintf strcasestr strcasechr strcasepbrk strrev strnlen) -dps_snprintf_oflow() - -dnl# Did they want debugging? -AC_MSG_CHECKING(for debugging level) -AC_ARG_WITH(debugging, [ --with-debugging[=num] compile in debugging support. num >= 0], [ - if test "$withval" = "yes"; then - withval=4 - else - : - fi - if test "$withval" != "no"; then - AC_MSG_RESULT($withval) - AC_DEFINE_UNQUOTED(DEBUG, $withval) - else - AC_MSG_RESULT(no, disabling all debugging support) - AC_DEFINE_UNQUOTED(DEBUG, 0) - AC_WARN(*** Debugging support disabled. Client programs will ***) - AC_WARN(*** not have access to any libast debugging routines! ***) - fi], [AC_MSG_RESULT(4) - AC_DEFINE_UNQUOTED(DEBUG, 4) -]) - -AC_ARG_WITH(imlib, -[ --with-imlib[=DIR] compile with Imlib support (Imlib residing in DIR/lib) (default)], [ - if test "$withval" != "no"; then - if test "$withval" != "yes"; then - CPPFLAGS="$CPPFLAGS -I${withval}/include" - LDFLAGS="$LDFLAGS -L${withval}/lib" - fi - USE_IMLIB=1 - else - USE_IMLIB=0 - fi], [USE_IMLIB=1 -]) -LIBAST_IMLIB2_SUPPORT="" -if test $USE_IMLIB -eq 1 ; then - AC_CHECK_LIB(m, pow, LIBS="-lm $LIBS") - AC_CHECK_LIB(dl, dlopen, LIBS="-ldl $LIBS") - AC_CHECK_LIB(ttf, TT_Init_FreeType, GRLIBS="-lttf $GRLIBS", , $GRLIBS) - AC_CHECK_LIB(Imlib2, imlib_create_image, [ - GRLIBS="-lImlib2 $GRLIBS" - AC_DEFINE(LIBAST_IMLIB2_SUPPORT) - LIBAST_IMLIB2_SUPPORT="Imlib2" - ], [ - AC_WARN(*** Imlib2 support has been disabled because Imlib2 ***) - AC_WARN(*** was not found or could not be linked. ***) - ], $GRLIBS) -fi -AC_SUBST(LIBAST_IMLIB2_SUPPORT) - -AC_MSG_CHECKING(for MMX support) -HAVE_MMX="" -AC_ARG_ENABLE(mmx, [ --enable-mmx enable MMX assembly routines], [ - test x$enableval = xyes && HAVE_MMX="yes" - ], [ - if test x$build_os = xlinux-gnu; then - grep mmx /proc/cpuinfo >/dev/null 2>&1 && HAVE_MMX="yes" - fi -]) -LIBAST_MMX_SUPPORT="" -if test -n "$HAVE_MMX"; then - AC_MSG_RESULT(yes) - AC_DEFINE(LIBAST_MMX_SUPPORT) - LIBAST_MMX_SUPPORT="MMX" -else - AC_MSG_RESULT(no) -fi -AC_SUBST(LIBAST_MMX_SUPPORT) - -AC_MSG_CHECKING(if backquote execution support should be enabled) -AC_ARG_WITH(backquote-exec, -[ --without-backquote-exec - disables the execution of commands from inside config files], [ - if test "$withval" = "no"; then - AC_MSG_RESULT(no) - else - AC_MSG_RESULT(yes) - AC_DEFINE(ALLOW_BACKQUOTE_EXEC) - fi], [ - AC_MSG_RESULT(yes) - AC_DEFINE(ALLOW_BACKQUOTE_EXEC) -]) - -CPPFLAGS=`eval eval eval eval eval echo "-I$includedir -I$prefix/include $CPPFLAGS"` -CPPFLAGS=`echo $CPPFLAGS | tr ' ' '\n' | uniq | grep -v NONE | tr '\n' ' '` -CFLAGS=${CFLAGS--O} -LDFLAGS=`eval eval eval eval eval echo "-L$libdir -L$prefix/lib ${LDFLAGS--O}"` -LDFLAGS=`echo $LDFLAGS | tr ' ' '\n' | uniq | grep -v NONE | tr '\n' ' '` -LIBS="$GRLIBS $X_PRE_LIBS $LIBS $X_EXTRA_LIBS" +AST_X11_SUPPORT() +AST_IMLIB2_SUPPORT() +AST_MMX_SUPPORT() +AST_ARG_REGEXP(REGEXP) +AST_ARG_BACKQUOTE_EXEC(ALLOW_BACKQUOTE_EXEC) +AST_FLAGS() AC_SUBST(CC) AC_SUBST(CFLAGS) AC_SUBST(CPPFLAGS) @@ -213,25 +36,10 @@ AC_SUBST(LDFLAGS) AC_SUBST(LIBS) basedir=. - AM_CONFIG_HEADER(config.h) - AC_OUTPUT(${srcdir}/include/libast/types.h Makefile include/Makefile \ include/libast/Makefile src/Makefile test/Makefile \ libast-config) test -f libast-config && chmod 755 libast-config -echo " -$PACKAGE $VERSION -Configuration: --------------- - - Source code location: $srcdir - Host System Type: $host - Preprocessor: $CC $CPPFLAGS - Compiler: $CC $CFLAGS - Linker: $CC $LDFLAGS $LIBS - Install path: $prefix - - Now type 'make' to build $PACKAGE $VERSION. -" +AST_STATUS() diff --git a/include/libast.h b/include/libast.h index bd125f3..a5d174c 100644 --- a/include/libast.h +++ b/include/libast.h @@ -83,6 +83,7 @@ #include <libast/types.h> #include <libast/obj.h> +#include <libast/regexp.h> #include <libast/socket.h> #include <libast/str.h> #include <libast/tok.h> diff --git a/include/libast/Makefile.am b/include/libast/Makefile.am index 212475c..61c17f9 100644 --- a/include/libast/Makefile.am +++ b/include/libast/Makefile.am @@ -1,8 +1,8 @@ # $Id: Makefile.am,v 1.6 2001/09/22 16:25:29 mej Exp $ EXTRA_HEADERS = \ - array.h dlinked_list.h linked_list.h list_if.h obj.h socket.h str.h \ - tok.h types.h url.h + array.h dlinked_list.h linked_list.h list_if.h obj.h regexp.h \ + socket.h str.h tok.h types.h url.h install-exec-hook: $(mkinstalldirs) $(DESTDIR)$(includedir)/$(PACKAGE) diff --git a/include/libast/regexp.h b/include/libast/regexp.h new file mode 100644 index 0000000..097d532 --- /dev/null +++ b/include/libast/regexp.h @@ -0,0 +1,98 @@ +/* + * Copyright (C) 1997-2002, Michael Jennings + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies of the Software, its documentation and marketing & publicity + * materials, and acknowledgment shall be given in the documentation, materials + * and software packages that this Software was used. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef _LIBAST_REGEXP_H_ +#define _LIBAST_REGEXP_H_ + +/* Cast an arbitrary object pointer to a regexp. */ +#define SPIF_REGEXP(obj) ((spif_regexp_t) (obj)) + +/* Check to see if a pointer references a regexping object. */ +#define SPIF_OBJ_IS_REGEXP(obj) (SPIF_OBJ_IS_TYPE(obj, regexp)) + +/* Check for NULL regexp object */ +#define SPIF_REGEXP_ISNULL(s) SPIF_OBJ_ISNULL(SPIF_OBJ(s)) + +#define SPIF_REGEXP_NEW(type) SPIF_REGEXP((SPIF_CLASS(SPIF_CLASS_VAR(type)))->noo()) +#define SPIF_REGEXP_INIT(obj) SPIF_OBJ_INIT(obj) +#define SPIF_REGEXP_DONE(obj) SPIF_OBJ_DONE(obj) +#define SPIF_REGEXP_DEL(obj) SPIF_OBJ_DEL(obj) +#define SPIF_REGEXP_SHOW(obj, b, i) SPIF_OBJ_SHOW(obj, b, i) +#define SPIF_REGEXP_COMP(o1, o2) SPIF_OBJ_COMP(o1, o2) +#define SPIF_REGEXP_DUP(obj) SPIF_OBJ_DUP(obj) +#define SPIF_REGEXP_TYPE(obj) SPIF_OBJ_TYPE(obj) + +SPIF_DEFINE_OBJ(regexp) { + spif_const_obj_t parent; + spif_charptr_t s; + size_t mem, len; +}; + +extern spif_class_t SPIF_CLASS_VAR(regexp); +extern spif_regexp_t spif_regexp_new(void); +extern spif_regexp_t spif_regexp_new_from_ptr(spif_charptr_t); +extern spif_regexp_t spif_regexp_new_from_buff(spif_charptr_t, size_t); +extern spif_regexp_t spif_regexp_new_from_fp(FILE *); +extern spif_regexp_t spif_regexp_new_from_fd(int); +extern spif_regexp_t spif_regexp_new_from_num(long); +extern spif_bool_t spif_regexp_del(spif_regexp_t); +extern spif_bool_t spif_regexp_init(spif_regexp_t); +extern spif_bool_t spif_regexp_init_from_ptr(spif_regexp_t, spif_charptr_t); +extern spif_bool_t spif_regexp_init_from_buff(spif_regexp_t, spif_charptr_t, size_t); +extern spif_bool_t spif_regexp_init_from_fp(spif_regexp_t, FILE *); +extern spif_bool_t spif_regexp_init_from_fd(spif_regexp_t, int); +extern spif_bool_t spif_regexp_init_from_num(spif_regexp_t, long); +extern spif_bool_t spif_regexp_done(spif_regexp_t); +extern spif_regexp_t spif_regexp_dup(spif_regexp_t); +extern spif_cmp_t spif_regexp_cmp(spif_regexp_t, spif_regexp_t); +extern spif_cmp_t spif_regexp_cmp_with_ptr(spif_regexp_t, spif_charptr_t); +extern spif_cmp_t spif_regexp_casecmp(spif_regexp_t, spif_regexp_t); +extern spif_cmp_t spif_regexp_casecmp_with_ptr(spif_regexp_t, spif_charptr_t); +extern spif_cmp_t spif_regexp_ncmp(spif_regexp_t, spif_regexp_t, size_t); +extern spif_cmp_t spif_regexp_ncmp_with_ptr(spif_regexp_t, spif_charptr_t, size_t); +extern spif_cmp_t spif_regexp_ncasecmp(spif_regexp_t, spif_regexp_t, size_t); +extern spif_cmp_t spif_regexp_ncasecmp_with_ptr(spif_regexp_t, spif_charptr_t, size_t); +extern size_t spif_regexp_index(spif_regexp_t, spif_char_t); +extern size_t spif_regexp_rindex(spif_regexp_t, spif_char_t); +extern size_t spif_regexp_find(spif_regexp_t, spif_regexp_t); +extern size_t spif_regexp_find_from_ptr(spif_regexp_t, spif_charptr_t); +extern spif_regexp_t spif_regexp_subregexp(spif_regexp_t, spif_int32_t, spif_int32_t); +extern spif_charptr_t spif_regexp_subregexp_to_ptr(spif_regexp_t, spif_int32_t, spif_int32_t); +extern size_t spif_regexp_to_num(spif_regexp_t, int); +extern double spif_regexp_to_float(spif_regexp_t); +extern spif_bool_t spif_regexp_append(spif_regexp_t, spif_regexp_t); +extern spif_bool_t spif_regexp_append_char(spif_regexp_t, spif_char_t); +extern spif_bool_t spif_regexp_append_from_ptr(spif_regexp_t, spif_charptr_t); +extern spif_bool_t spif_regexp_clear(spif_regexp_t, spif_char_t); +extern spif_bool_t spif_regexp_trim(spif_regexp_t); +extern spif_bool_t spif_regexp_splice(spif_regexp_t, size_t, size_t, spif_regexp_t); +extern spif_bool_t spif_regexp_splice_from_ptr(spif_regexp_t, size_t, size_t, spif_charptr_t); +extern spif_bool_t spif_regexp_reverse(spif_regexp_t); +extern size_t spif_regexp_get_size(spif_regexp_t); +extern spif_bool_t spif_regexp_set_size(spif_regexp_t, size_t); +extern size_t spif_regexp_get_len(spif_regexp_t); +extern spif_bool_t spif_regexp_set_len(spif_regexp_t, size_t); +extern spif_regexp_t spif_regexp_show(spif_regexp_t, spif_charptr_t, spif_regexp_t, size_t); +extern spif_classname_t spif_regexp_type(spif_regexp_t); + +#endif /* _LIBAST_REGEXP_H_ */ diff --git a/include/libast/str.h b/include/libast/str.h index 82e5252..b916771 100644 --- a/include/libast/str.h +++ b/include/libast/str.h @@ -65,14 +65,14 @@ extern spif_bool_t spif_str_init_from_fd(spif_str_t, int); extern spif_bool_t spif_str_init_from_num(spif_str_t, long); extern spif_bool_t spif_str_done(spif_str_t); extern spif_str_t spif_str_dup(spif_str_t); -extern int spif_str_cmp(spif_str_t, spif_str_t); -extern int spif_str_cmp_with_ptr(spif_str_t, spif_charptr_t); -extern int spif_str_casecmp(spif_str_t, spif_str_t); -extern int spif_str_casecmp_with_ptr(spif_str_t, spif_charptr_t); -extern int spif_str_ncmp(spif_str_t, spif_str_t, size_t); -extern int spif_str_ncmp_with_ptr(spif_str_t, spif_charptr_t, size_t); -extern int spif_str_ncasecmp(spif_str_t, spif_str_t, size_t); -extern int spif_str_ncasecmp_with_ptr(spif_str_t, spif_charptr_t, size_t); +extern spif_cmp_t spif_str_cmp(spif_str_t, spif_str_t); +extern spif_cmp_t spif_str_cmp_with_ptr(spif_str_t, spif_charptr_t); +extern spif_cmp_t spif_str_casecmp(spif_str_t, spif_str_t); +extern spif_cmp_t spif_str_casecmp_with_ptr(spif_str_t, spif_charptr_t); +extern spif_cmp_t spif_str_ncmp(spif_str_t, spif_str_t, size_t); +extern spif_cmp_t spif_str_ncmp_with_ptr(spif_str_t, spif_charptr_t, size_t); +extern spif_cmp_t spif_str_ncasecmp(spif_str_t, spif_str_t, size_t); +extern spif_cmp_t spif_str_ncasecmp_with_ptr(spif_str_t, spif_charptr_t, size_t); extern size_t spif_str_index(spif_str_t, spif_char_t); extern size_t spif_str_rindex(spif_str_t, spif_char_t); extern size_t spif_str_find(spif_str_t, spif_str_t); diff --git a/libast-config.in b/libast-config.in index 9c9d027..72296e4 100644 --- a/libast-config.in +++ b/libast-config.in @@ -15,11 +15,12 @@ LDFLAGS="@LDFLAGS@" X11_SUPPORT=@LIBAST_X11_SUPPORT@ IMLIB2_SUPPORT=@LIBAST_IMLIB2_SUPPORT@ MMX_SUPPORT=@LIBAST_MMX_SUPPORT@ +REGEXP_SUPPORT=@LIBAST_REGEXP_SUPPORT@ VERSION=@VERSION@ case $1 in -h | --help | -help) - echo "Usage: libast-config [--version] [--prefix] [--exec-prefix] [--cppflags] [--ldflags]" + echo "Usage: libast-config [--version] [--prefix] [--exec-prefix] [--cppflags] [--ldflags] [--support]" ;; -v | --version | -version) echo "Libary of Assorted Spiffy Things: libast $VERSION" diff --git a/libast.m4 b/libast.m4 new file mode 100644 index 0000000..73d4996 --- /dev/null +++ b/libast.m4 @@ -0,0 +1,619 @@ +dnl##################################################################### +dnl# Autoconf m4 macros for LibAST +dnl# $Id$ +dnl##################################################################### + +dnl# +dnl# LibAST macro for determining integer types by size +dnl# +AC_DEFUN(AST_SIZE_TYPE, + [BIT_SIZE=[$1] + BYTE_SIZE=`expr $BIT_SIZE '/' 8` + case $BYTE_SIZE in + $ac_cv_sizeof_char) eval INT_${BIT_SIZE}_TYPE=char ;; + $ac_cv_sizeof_short) eval INT_${BIT_SIZE}_TYPE=short ;; + $ac_cv_sizeof_int) eval INT_${BIT_SIZE}_TYPE=int ;; + $ac_cv_sizeof_long) eval INT_${BIT_SIZE}_TYPE=long ;; + $ac_cv_sizeof_long_long) eval INT_${BIT_SIZE}_TYPE="'long long'" ;; + esac + test -z "`eval echo '$'INT_${BIT_SIZE}_TYPE`" && eval INT_${BIT_SIZE}_TYPE=long +]) + +dnl# +dnl# LibAST macro for determining regexp support +dnl# - arg 1 is the name of the env var to use +dnl# +AC_DEFUN(AST_REGEXP_SUPPORT, [ + if test "${$1}" != "no"; then + if test "${$1}" = "pcre" -o "${$1}" = "yes" ; then + GOT_PCRE_HEADER=0 + GOT_PCRE_LIB=0 + AC_CHECK_HEADERS(pcre.h pcre/pcre.h, [ + GOT_PCRE_HEADER=1 + break + ]) + AC_SEARCH_LIBS(pcre_compile, pcre, [GOT_PCRE_LIB=1]) + if test $GOT_PCRE_HEADER -eq 1 -a $GOT_PCRE_LIB -eq 1 ; then + AC_DEFINE_UNQUOTED(LIBAST_REGEXP_SUPPORT, "pcre") + LIBAST_REGEXP_SUPPORT="regexp-pcre" + $1="pcre" + else + $1="yes" + fi + fi + if test "${$1}" = "posix" -o "${$1}" = "yes" ; then + GOT_POSIXREGEXP_HEADER=0 + GOT_POSIXREGEXP_LIB=0 + AC_CHECK_HEADERS(regex.h, [ + GOT_POSIXREGEXP_HEADER=1 + break + ]) + AC_SEARCH_LIBS(regcomp, posix regexp regex re, [GOT_POSIXREGEXP_LIB=1]) + if test $GOT_POSIXREGEXP_HEADER -eq 1 -a $GOT_POSIXREGEXP_LIB -eq 1 ; then + AC_DEFINE_UNQUOTED(LIBAST_REGEXP_SUPPORT, "posix") + LIBAST_REGEXP_SUPPORT="regexp-posix" + $1="posix" + else + $1="yes" + fi + fi + if test "${$1}" = "bsd" -o "${$1}" = "yes" ; then + GOT_BSD_HEADER=0 + GOT_BSD_LIB=0 + AC_CHECK_HEADERS(regex.h, [ + GOT_BSD_HEADER=1 + break + ]) + AC_SEARCH_LIBS(re_comp, bsd ucb regexp regex re, [GOT_BSD_LIB=1]) + if test $GOT_BSD_HEADER -eq 1 -a $GOT_BSD_LIB -eq 1 ; then + AC_DEFINE_UNQUOTED(LIBAST_REGEXP_SUPPORT, "bsd") + LIBAST_REGEXP_SUPPORT="regexp-bsd" + $1="bsd" + else + $1="yes" + fi + fi + if test "${$1}" = "yes" ; then + LIBAST_REGEXP_SUPPORT="" + $1="no" + fi + else + LIBAST_REGEXP_SUPPORT="" + $1="no" + fi + AC_SUBST(LIBAST_REGEXP_SUPPORT) +]) + +dnl# +dnl# LibAST macro for X11 support +dnl# +AC_DEFUN(AST_X11_SUPPORT, [ + AC_PATH_XTRA + if test ! -z "$X_CFLAGS"; then + if test -z "$CPPFLAGS"; then + CPPFLAGS="$X_CFLAGS" + else + CPPFLAGS="$CPPFLAGS $X_CFLAGS" + fi + fi + if test ! -z "$X_LIBS"; then + if test -z "$LDFLAGS"; then + LDFLAGS="$X_LIBS" + else + LDFLAGS="$LDFLAGS $X_LIBS" + fi + fi + LIBAST_X11_SUPPORT="" + if test "x$no_x" != "xyes"; then + AC_CHECK_LIB(X11, XOpenDisplay, [ + LIBAST_X11_SUPPORT="X11" + GRLIBS="-lX11" + AC_DEFINE(LIBAST_X11_SUPPORT) + ]) + fi + AC_SUBST(LIBAST_X11_SUPPORT) +]) + +dnl# +dnl# LibAST macro for Imlib2 support +dnl# +AC_DEFUN(AST_IMLIB2_SUPPORT, [ + AC_ARG_WITH(imlib, + [ --with-imlib[=DIR] compile with Imlib support (Imlib residing in DIR/lib) (default)], + [ + if test "$withval" != "no"; then + if test "$withval" != "yes"; then + CPPFLAGS="$CPPFLAGS -I${withval}/include" + LDFLAGS="$LDFLAGS -L${withval}/lib" + fi + USE_IMLIB=1 + else + USE_IMLIB=0 + fi + ], [ + USE_IMLIB=1 + ]) + LIBAST_IMLIB2_SUPPORT="" + if test $USE_IMLIB -eq 1 ; then + AC_CHECK_LIB(m, pow, LIBS="-lm $LIBS") + AC_CHECK_LIB(dl, dlopen, LIBS="-ldl $LIBS") + AC_CHECK_LIB(ttf, TT_Init_FreeType, GRLIBS="-lttf $GRLIBS", , $GRLIBS) + AC_CHECK_LIB(Imlib2, imlib_create_image, [ + GRLIBS="-lImlib2 $GRLIBS" + AC_DEFINE(LIBAST_IMLIB2_SUPPORT) + LIBAST_IMLIB2_SUPPORT="Imlib2" + ], [ + AC_WARN(*** Imlib2 support has been disabled because Imlib2 ***) + AC_WARN(*** was not found or could not be linked. ***) + ], $GRLIBS) + fi + AC_SUBST(LIBAST_IMLIB2_SUPPORT) +]) + +dnl# +dnl# LibAST macro for MMX support +dnl# +AC_DEFUN(AST_MMX_SUPPORT, [ + AC_MSG_CHECKING(for MMX support) + HAVE_MMX="" + AC_ARG_ENABLE(mmx, [ --enable-mmx enable MMX assembly routines], [ + test x$enableval = xyes && HAVE_MMX="yes" + ], [ + if test x$build_os = xlinux-gnu; then + grep mmx /proc/cpuinfo >/dev/null 2>&1 && HAVE_MMX="yes" + fi + ]) + LIBAST_MMX_SUPPORT="" + if test -n "$HAVE_MMX"; then + AC_MSG_RESULT(yes) + AC_DEFINE(LIBAST_MMX_SUPPORT) + LIBAST_MMX_SUPPORT="MMX" + else + AC_MSG_RESULT(no) + fi + AC_SUBST(LIBAST_MMX_SUPPORT) +]) + +dnl# +dnl# LibAST macros for standard checks +dnl# +AC_DEFUN(AST_STD_CHECKS, [ + AC_PROG_CC + AC_PROG_CPP + + dnl# These must be run after AC_PROG_CC but before any other macros that use + dnl# the C compiler + AC_AIX + AC_ISC_POSIX + AC_MINIX + + dnl# At least make the attempt to support CygWin32 + AC_CYGWIN + AC_ARG_PROGRAM + + AM_PROG_LIBTOOL + + AC_GCC_TRADITIONAL + + AC_PROG_INSTALL + + ASFLAGS="$ASFLAGS -I../" + AS=$CC + AC_SUBST(ASFLAGS) + AC_SUBST(AS) + + dnl# Check for host system type + AC_CANONICAL_HOST + + dnl# Check the sanity of what we've done so far + AM_SANITY_CHECK + + dnl# Most people don't want the developer-only clutter + AM_MAINTAINER_MODE + + dnl# If it's there, what the hell? + AM_WITH_DMALLOC +]) +AC_DEFUN(AST_PROG_CHECKS, [ + AC_CHECK_PROG(SED, sed, sed, false) + AC_CHECK_PROG(RM, rm, rm, true) + AC_CHECK_PROG(CP, cp, cp, false) + AC_CHECK_PROG(CHMOD, chmod, chmod, true) + AC_CHECK_PROG(TAR, tar, tar, tar) + AC_CHECK_PROG(MKDIR, mkdir, mkdir, false) + AC_CHECK_PROG(CTAGS, ctags, ctags, true) + AC_CHECK_PROG(AR, ar, ar, false) + AC_CHECK_PROG(MV, mv, mv, true) + AC_LN_S +]) +AC_DEFUN(AST_VAR_CHECKS, [ + AC_CHECK_SIZEOF(char, 1) + AC_CHECK_SIZEOF(short, 2) + AC_CHECK_SIZEOF(int, 4) + AC_CHECK_SIZEOF(long, 4) + AC_CHECK_SIZEOF(long long, 8) + AC_C_BIGENDIAN + + AST_SIZE_TYPE(8) + AC_SUBST(INT_8_TYPE) + AST_SIZE_TYPE(16) + AC_SUBST(INT_16_TYPE) + AST_SIZE_TYPE(32) + AC_SUBST(INT_32_TYPE) + AST_SIZE_TYPE(64) + AC_SUBST(INT_64_TYPE) + + AC_C_CONST + AC_C_INLINE +]) +AC_DEFUN(AST_HEADER_CHECKS, [ + AC_HEADER_SYS_WAIT + AC_CHECK_HEADERS(fcntl.h termios.h sys/ioctl.h sys/select.h sys/time.h \ + sys/sockio.h sys/byteorder.h malloc.h utmpx.h unistd.h \ + bsd/signal.h stdarg.h errno.h) + AC_HEADER_TIME +]) +AC_DEFUN(AST_FUNC_CHECKS, [ + AC_TYPE_SIGNAL + AC_CHECK_FUNCS(memmove putenv strsep memmem usleep snprintf vsnprintf \ + strcasestr strcasechr strcasepbrk strrev strnlen) + dps_snprintf_oflow() + dps_vsnprintf_oflow() + dps_symlink_open_bug() + dps_rlimit_nproc() + dps_rlimit_memlock() +]) +AC_DEFUN(AST_TYPE_CHECKS, [ + AC_TYPE_MODE_T + AC_CHECK_TYPE(off_t, long) + AC_TYPE_PID_T + AC_TYPE_UID_T +]) + +dnl# +dnl# LibAST argument macros +dnl# - arg 1 is the name of the env var to use +dnl# +AC_DEFUN(AST_ARG_DEBUG, [ + AC_MSG_CHECKING(for debugging level) + AC_ARG_WITH(debugging, [ --with-debugging[=num] compile in debugging support. num >= 0], [ + if test "$withval" = "yes"; then + withval=4 + fi + if test "$withval" != "no"; then + AC_MSG_RESULT($withval) + AC_DEFINE_UNQUOTED($1, $withval) + $1=$withval + else + AC_MSG_RESULT(no, disabling all debugging support) + AC_DEFINE_UNQUOTED($1, 0) + $1=0 + fi + ], [ + AC_MSG_RESULT(4) + AC_DEFINE_UNQUOTED($1, 4) + $1=4 + ]) +]) +AC_DEFUN(AST_ARG_REGEXP, [ + AC_ARG_WITH(regexp, + [ --with-regexp[=TYPE] specify the type of regular expression support (bsd, posix, pcre)], + [$1=$withval], [$1=yes]) + AST_REGEXP_SUPPORT($1) + AC_MSG_CHECKING(for regular expression support) + AC_MSG_RESULT(${$1}) +]) +AC_DEFUN(AST_ARG_BACKQUOTE_EXEC, [ + AC_MSG_CHECKING(if backquote execution support should be enabled) + AC_ARG_WITH(backquote-exec, + [ --without-backquote-exec disables the execution of commands from inside config files], + [ + if test "$withval" = "no"; then + AC_MSG_RESULT(no) + $1=no + else + AC_MSG_RESULT(yes) + AC_DEFINE($1) + $1=yes + fi + ], [ + AC_MSG_RESULT(yes) + AC_DEFINE($1) + $1=yes + ]) +]) + +dnl# +dnl# LibAST macro for flag post-processing +dnl# +AC_DEFUN(AST_FLAGS, [ + CPPFLAGS=`eval eval eval eval eval echo "-I$includedir -I$prefix/include $CPPFLAGS"` + CPPFLAGS=`echo $CPPFLAGS | tr ' ' '\n' | uniq | grep -v NONE | tr '\n' ' '` + CFLAGS=${CFLAGS--O} + LDFLAGS=`eval eval eval eval eval echo "-L$libdir -L$prefix/lib ${LDFLAGS--O}"` + LDFLAGS=`echo $LDFLAGS | tr ' ' '\n' | uniq | grep -v NONE | tr '\n' ' '` + LIBS="$GRLIBS $X_PRE_LIBS $LIBS $X_EXTRA_LIBS" +]) + +dnl# +dnl# LibAST macro for final status report +dnl# +AC_DEFUN(AST_STATUS, [ + echo "" + echo "$PACKAGE $VERSION" + echo "Configuration:" + echo "--------------" + echo "" + echo " Source code location: $srcdir" + echo " Host System Type: $host" + echo " Preprocessor: $CC $CPPFLAGS" + echo " Compiler: $CC $CFLAGS" + echo " Linker: $CC $LDFLAGS $LIBS" + echo " Install path: $prefix" + echo "" + echo "Now type 'make' to build $PACKAGE $VERSION." + echo "" +]) + +dnl########################################################################### + +dnl# +dnl# acl.m4 -- Written by Duncan Simpson <dps@io.stargate.co.uk> +dnl# Posted to BUGTRAQ on 17 June 1999 +dnl# Used by encouragement. :-) +dnl# + +dnl Check snprintf for overrun potential +AC_DEFUN(dps_snprintf_oflow, [ + AC_MSG_CHECKING(whether snprintf ignores n) + AC_CACHE_VAL(dps_cv_snprintf_bug, [ + AC_TRY_RUN( + changequote(<<, >>)dnl +<<#include <stdio.h> + +#ifndef HAVE_SNPRINTF +#include "src/snprintf.c" +#endif /* HAVE_SNPRINTF */ + +int main(void) +{ +char ovbuf[7]; +int i; +for (i=0; i<7; i++) ovbuf[i]='x'; +snprintf(ovbuf, 4,"foo%s", "bar"); +if (ovbuf[5]!='x') exit(1); +snprintf(ovbuf, 4,"foo%d", 666); +if (ovbuf[5]!='x') exit(1); +exit(0); +} >> + changequote([, ]) + , dps_cv_snprintf_bug=0, dps_cv_snprintf_bug=1, dps_cv_snprintf_bug=2) + ]) + if test $dps_cv_snprintf_bug -eq 0; then + AC_MSG_RESULT([no, snprintf is ok]) + elif test $dps_cv_snprint_bug -eq 1; then + AC_MSG_RESULT([yes, snprintf is broken]) + AC_DEFINE(HAVE_SNPRINTF_BUG, 1) + else + AC_MSG_RESULT([unknown, assuming yes]) + AC_DEFINE(HAVE_SNPRINTF_BUG, 1) + fi +]) + +dnl Check vsnprintf for overrun potential +AC_DEFUN(dps_vsnprintf_oflow, [ + AC_MSG_CHECKING(whether vsnprintf ignores n) + AC_CACHE_VAL(dps_cv_vsnprintf_bug, [ + AC_TRY_RUN( + changequote(<<, >>)dnl +<<#include <stdio.h> +#include <stdarg.h> + +#ifndef HAVE_VSNPRINTF +#include "src/snprintf.c" +#endif /* HAVE_VSNPRINTF */ + +int prnt(char *s, const char *fmt, ...) +{ + va_list argp; + va_start(argp, fmt); + vsnprintf(s, 4, fmt, argp); + va_end(argp); +} + +int main(void) +{ + char ovbuf[8] = "xxxxxxx"; + int i; + prnt(ovbuf, "foo%s", "bar"); + if (ovbuf[5]!='x') {fprintf(stderr, "buffer: %s\n", ovbuf); exit(1);} + prnt(ovbuf, "foo%d", 666); + if (ovbuf[5]!='x') {fprintf(stderr, "buffer: %s\n", ovbuf); exit(1);} + exit(0); +} >> + changequote([, ]) + , dps_cv_vsnprintf_bug=0, dps_cv_vsnprintf_bug=1, dps_cv_vsnprintf_bug=2) + ]) + + if test $dps_cv_vsnprintf_bug -eq 0; then + AC_MSG_RESULT([no, vsnprintf is ok]) + elif test $dps_cv_vsnprintf_bug -eq 1; then + AC_MSG_RESULT([yes, vsnprintf is broken]) + AC_DEFINE(HAVE_VSNPRINTF_BUG,1) + else + AC_MSG_RESULT([unknown, assuming yes]) + AC_DEFINE(HAVE_VSNPRINTF_BUG,1) + fi +]) + +dnl open and symlink interaction bug test +AC_DEFUN(dps_symlink_open_bug, [ + AC_MSG_CHECKING(security of interaction between symlink and open) + AC_CACHE_VAL(dps_cv_symlink_open_bug, [ + mkdir conftest.d + AC_TRY_RUN( + changequote(<<, >>)dnl +<<#include <stdio.h> +#ifdef HAVE_STDLIB_H +#include <stdlib.h> +#endif +#ifdef HAVE_SYS_TYPES_H +#include <sys/types.h> +#endif +#ifdef HAVE_SYS_STAT_H +#include <sys/stat.h> +#endif +#ifdef HAVE_FCNTL_H +#include <fcntl.h> +#endif +#ifdef HAVE_UNISTD_H +#include <unistd.h> +#endif +#ifdef HAVE_ERRNO_H +#include <errno.h> +#else +extern int errno; +#endif + +int main(void) +{ + int fd; + if (chdir("conftest.d")!=0) + exit(1); + if (symlink("foo","bar")!=0) + exit(1); + if ((fd=open("bar", O_CREAT | O_EXCL | O_WRONLY, 0700))==0) + { + write(fd, "If the symlink was to .rhosts you would be unhappy", 50); + close(fd); + exit(1); + } + if (errno!=EEXIST) + exit(1); + exit(0); +} >> + changequote([, ]) + , + cps_cv_symlink_open_bug=0, + [ + if test -r conftest.d/foo; then + cps_cv_symlink_open_bug=2 + else + cps_cv_symlink_open_bug=1 + fi + ], + cps_cv_symlink_open_buf=3) + rm -rf conftest.d + ]) + case "$cps_cv_symlink_open_bug" in + 0) AC_MSG_RESULT(secure) ;; + 1) AC_MSG_RESULT(errno wrong but ok) + AC_DEFINE(HAVE_SYMLINK_OPEN_ERRNO_BUG) ;; + 2) AC_MSG_RESULT(insecure) + AC_DEFINE(HAVE_SYMLINK_OPEN_SECURITY_HOLE) + AC_DEFINE(HAVE_SYMLINK_OPEN_ERRNO_BUG) ;; + 3) AC_MSG_RESULT(assuming insecure) + AC_DEFINE(HAVE_SYMLINK_OPEN_SECURITY_HOLE) + AC_DEFINE(HAVE_SYMLINK_OPEN_ERRNO_BUG) ;; + *) AC_MSG_RESULT($cps_cv_symlink_open_bug) + AC_MSG_ERROR(Impossible value of cps_cv_symlink_open_bug) ;; + esac +]) + +dnl Check to RLIMIT_NPROC resource limit +AC_DEFUN(dps_rlimit_nproc, [ + AC_MSG_CHECKING(for working RLIMIT_NPROC resource limit) + AC_CACHE_VAL(dps_cv_rlimit_nproc, [ + AC_TRY_RUN( + changequote(<<, >>)dnl +<< +#ifndef HAVE_STDLIB_H +#include <stdlib.h> +#endif /* HAVE_STDLIB_H */ +#ifndef HAVE_SIGNAL_H +#include <signal.h> +#endif /* HAVE_SIGNAL_H */ +#ifdef HAVE_UNISTD_H +#include <unistd.h> +#endif /* HAVE_UNISTD_H */ +#ifdef HAVE_SYS_RESOURCE_H +#include <sys/resource.h> +#endif /* HAVE_SYS_RESOURCE_H */ + +int main(void) +{ +#ifdef RLIMIT_NPROC + static const struct rlimit pid_lim={RLIMIT_NPROC, 1}; + pid_t f; + + signal(SIGCHLD, SIG_IGN); + setrlimit(RLIMIT_NPROC, (struct rlimit *) &pid_lim); + if ((f=fork())==0) + exit(0); + if (f==-1) + exit(0); /* The fork() failed (the right thing) */ +#endif + exit(1); +} >> + changequote([, ]) + , dps_cv_rlimit_nproc=0, dps_cv_rlimit_nproc=1, dps_cv_rlimit_nproc=2) + ]) + if test $dps_cv_rlimit_nproc -eq 0; then + AC_MSG_RESULT([yes]) + AC_DEFINE(HAVE_RLIMIT_NPROC,1) + elif test $dps_cv_rlimit_nproc -eq 1; then + AC_MSG_RESULT([no]) + else + AC_MSG_RESULT([unknown, assuming none]) + fi +]) + +dnl Check to RLIMIT_MEMLOCK resource limit +AC_DEFUN(dps_rlimit_memlock, [ + AC_MSG_CHECKING(for working RLIMIT_MEMLOCK resource limit) + AC_CACHE_VAL(dps_cv_rlimit_memlock, [ + AC_TRY_RUN( + changequote(<<, >>)dnl +<< +#ifndef HAVE_STDLIB_H +#include <stdlib.h> +#endif /* HAVE_STDLIB_H */ +#ifndef HAVE_SIGNAL_H +#include <signal.h> +#endif /* HAVE_SIGNAL_H */ +#ifdef HAVE_UNISTD_H +#include <unistd.h> +#endif /* HAVE_UNISTD_H */ +#ifdef HAVE_SYS_RESOURCE_H +#include <sys/resource.h> +#endif /* HAVE_SYS_RESOURCE_H */ +#ifdef HAVE_SYS_MMAN +#include <sys/mman.h> +#endif /* HAVE_SYS_MMAN */ +#ifdef HAVE_ERRNO_H +#include <errno.h> +#endif /* HAVE_ERRNO_H */ + +int main(void) +{ +#ifdef RLIMIT_MEMLOCK + static const struct rlimit mlock_lim={RLIMIT_MEMLOCK, 0}; + void *memory; + + if (setrlimit(RLIMIT_MEMLOCK, (struct rlimit *) &mlock_lim)!=-1) + exit(0); +#endif +exit(1); +} >> + changequote([, ]) + , dps_cv_rlimit_memlock=0, dps_cv_rlimit_memlock=1, dps_cv_rlimit_memlock=2) + ]) + if test $dps_cv_rlimit_memlock -eq 0; then + AC_MSG_RESULT([yes]) + AC_DEFINE(HAVE_RLIMIT_MEMLOCK,1) + elif test $dps_cv_rlimit_memlock -eq 1; then + AC_MSG_RESULT([no]) + else + AC_MSG_RESULT([unknown, assuming none]) + fi +]) diff --git a/libast.spec b/libast.spec index 5ed3177..45bc89a 100644 --- a/libast.spec +++ b/libast.spec @@ -25,9 +25,9 @@ version number that begins with 0. %build if [ -e ./configure ] then - %configure --prefix=%{_prefix} --bindir=%{_bindir} --libdir=%{_libdir} --includedir=%{_includedir} + %configure --prefix=%{_prefix} --bindir=%{_bindir} --libdir=%{_libdir} --includedir=%{_includedir} --datadir=%{_datadir} else - ./autogen.sh --prefix=%{_prefix} --bindir=%{_bindir} --libdir=%{_libdir} --includedir=%{_includedir} + ./autogen.sh --prefix=%{_prefix} --bindir=%{_bindir} --libdir=%{_libdir} --includedir=%{_includedir} --datadir=%{_datadir} fi make @@ -47,3 +47,4 @@ rm -rf $RPM_BUILD_ROOT %{_bindir}/* %{_libdir}/* %{_includedir}/* +%{_datadir}/* diff --git a/src/Makefile.am b/src/Makefile.am index e9267df..abc3de3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -6,7 +6,7 @@ INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/include/$(PACKAGE) libast_la_SOURCES = \ array.c conf.c debug.c dlinked_list.c file.c linked_list.c \ - mem.c msgs.c obj.c options.c socket.c str.c strings.c \ - snprintf.c tok.c url.c + mem.c msgs.c obj.c options.c regexp.c socket.c str.c \ + strings.c snprintf.c tok.c url.c libast_la_LDFLAGS = -version-info 2:0:1 diff --git a/src/regexp.c b/src/regexp.c new file mode 100644 index 0000000..b725f66 --- /dev/null +++ b/src/regexp.c @@ -0,0 +1,140 @@ +/* + * Copyright (C) 1997-2002, Michael Jennings + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies of the Software, its documentation and marketing & publicity + * materials, and acknowledgment shall be given in the documentation, materials + * and software packages that this Software was used. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +static const char cvs_ident[] = "$Id$"; + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <libast_internal.h> + +/* *INDENT-OFF* */ +static SPIF_CONST_TYPE(class) r_class = { + SPIF_DECL_CLASSNAME(regexp), + (spif_func_t) spif_regexp_new, + (spif_func_t) spif_regexp_init, + (spif_func_t) spif_regexp_done, + (spif_func_t) spif_regexp_del, + (spif_func_t) spif_regexp_show, + (spif_func_t) spif_regexp_cmp, + (spif_func_t) spif_regexp_dup, + (spif_func_t) spif_regexp_type +}; +SPIF_TYPE(class) SPIF_CLASS_VAR(regexp) = &r_class; +/* *INDENT-ON* */ + +spif_regexp_t +spif_regexp_new(void) +{ + spif_regexp_t self; + + self = SPIF_ALLOC(regexp); + spif_regexp_init(self); + return self; +} + +spif_regexp_t +spif_regexp_new_from_ptr(spif_charptr_t old) +{ + spif_regexp_t self; + + self = SPIF_ALLOC(regexp); + spif_regexp_init_from_ptr(self, old); + return self; +} + +spif_bool_t +spif_regexp_del(spif_regexp_t self) +{ + spif_regexp_done(self); + SPIF_DEALLOC(self); + return TRUE; +} + +spif_bool_t +spif_regexp_init(spif_regexp_t self) +{ + spif_obj_init(SPIF_OBJ(self)); + spif_obj_set_class(SPIF_OBJ(self), SPIF_CLASS_VAR(regexp)); + return TRUE; +} + +spif_bool_t +spif_regexp_init_from_ptr(spif_regexp_t self, spif_charptr_t old) +{ + spif_obj_init(SPIF_OBJ(self)); + spif_obj_set_class(SPIF_OBJ(self), SPIF_CLASS_VAR(regexp)); + return TRUE; +} + +spif_bool_t +spif_regexp_done(spif_regexp_t self) +{ + REQUIRE_RVAL(!SPIF_REGEXP_ISNULL(self), FALSE); + return TRUE; +} + +spif_regexp_t +spif_regexp_dup(spif_regexp_t orig) +{ + spif_regexp_t self; + + REQUIRE_RVAL(!SPIF_REGEXP_ISNULL(orig), FALSE); + return self; +} + +spif_cmp_t +spif_regexp_cmp(spif_regexp_t self, spif_regexp_t other) +{ + +} + +spif_regexp_t +spif_regexp_show(spif_regexp_t self, spif_charptr_t name, spif_regexp_t buff, size_t indent) +{ + char tmp[4096]; + + if (SPIF_REGEXP_ISNULL(self)) { + SPIF_OBJ_SHOW_NULL(regexp, name, buff, indent); + return buff; + } + + memset(tmp, ' ', indent); + snprintf(tmp + indent, sizeof(tmp) - indent, "(spif_regexp_t) %s: %8p {\n", name, self); + if (SPIF_REGEXP_ISNULL(buff)) { + buff = spif_regexp_new_from_ptr(tmp); + } else { + spif_regexp_append_from_ptr(buff, tmp); + } + + snprintf(tmp, sizeof(tmp), "}\n"); + spif_regexp_append_from_ptr(buff, tmp); + return buff; +} + +spif_classname_t +spif_regexp_type(spif_regexp_t self) +{ + return SPIF_OBJ_CLASSNAME(self); +} |