home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-11-28 | 31.0 KB | 1,229 lines |
- Newsgroups: comp.sources.unix
- From: panos@anchor.cs.colorado.edu (Panos Tsirigotis)
- Subject: v27i119: clc - C Libraries Collection, Part13/20
- References: <1.754527080.23891@gw.home.vix.com>
- Sender: unix-sources-moderator@gw.home.vix.com
- Approved: vixie@gw.home.vix.com
-
- Submitted-By: panos@anchor.cs.colorado.edu (Panos Tsirigotis)
- Posting-Number: Volume 27, Issue 119
- Archive-Name: clc/part13
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of archive 13 (of 20)."
- # Contents: libconf libs/src/sio/sio.h libs/src/str/strs.c
- # libs/src/xlog/xlog.3
- # Wrapped by panos@eclipse on Sun Nov 28 14:48:17 1993
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'libconf' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'libconf'\"
- else
- echo shar: Extracting \"'libconf'\" \(7097 characters\)
- sed "s/^X//" >'libconf' <<'END_OF_FILE'
- X#!/bin/sh
- X
- X#
- X# Copyright (c) 1993 by Panagiotis Tsirigotis
- X#
- X
- X#
- X# $Id: libconf,v 1.1 93/11/26 10:42:45 panos Exp $
- X#
- X
- X#
- X# XXX: a lot of the autoconfiguration stuff would be much less verbose
- X# if we could assume that /bin/sh supports functions. In a future
- X# version we may choose to make that assumption, or assume that
- X# there is also some other shell available (for example, ksh)
- X# that supports functions.
- X#
- X
- Xscript_name=`basename $0`
- Xusage="Usage: $script_name [-libc pathname] [-v]"
- X
- X#
- X# The $echo variable should have the pathname for an 'echo' command
- X# that understands the -n option.
- X#
- Xecho=echo
- X
- Xinc=/usr/include
- Xnm_defined_var=D
- Xnm_defined_func=T
- X
- X#
- X# Get the options, if any
- X#
- Xwhile test $# -gt 0
- Xdo
- X case "$1" in
- X -*) option=$1 ; shift ;;
- X *) echo $usage ; exit 1
- X esac
- X
- X case "$option" in
- X -libc)
- X if test $# -eq 0 ; then
- X $echo "$script_name: Argument missing. Exiting..."
- X exit 1
- X fi
- X libc="$1"
- X shift
- X if test ! -r "$libc" ; then
- X $echo "$script_name: File is not readable: $libc"
- X exit 1
- X fi
- X ;;
- X
- X -v) verbose=yes
- X ;;
- X
- X -*) echo $usage ; exit 1
- X esac
- Xdone
- X
- X
- X#######################################################################
- X# Get namelist of C library
- X#######################################################################
- X$echo "Obtaining name list of C library for autoconfiguration"
- X
- Xif test "$libc" = "" ; then
- X if test -r /lib/libc.a ; then
- X libc=/lib/libc.a
- X else
- X if test -r /usr/lib/libc.a ; then
- X libc=/usr/lib/libc.a
- X else
- X $echo -n "Please enter the pathname of the C library -> "
- X read libc
- X if test "$libc" = "" -o ! -r "$libc" ; then
- X $echo "$script_name: bad pathname. Exiting..."
- X exit 1
- X fi
- X fi
- X fi
- Xfi
- Xnmfile=/tmp/libc.nm.$$
- Xnm $libc > $nmfile 2>/dev/null
- Xif test $? -ne 0 ; then
- X if test ! -s $nmfile ; then
- X $echo "Couldn't get the namelist of C library. Exiting..."
- X rm -f $nmfile
- X exit 1
- X else # name list file is not empty
- X $echo "WARNING: The 'nm' command returned a non-zero exit status"
- X $echo "WARNING: so the namelist obtained from the C library may be inco
- Xmplete"
- X $echo "Continuing with determination of configuration flags"
- X fi
- Xfi
- X
- X
- X#######################################################################
- X#
- X# TIMER library configuration.
- X#
- X#######################################################################
- X
- X#
- X# Determine supported signal handing
- X#
- Xlookfor=sigaction
- Xif test "$verbose" ; then $echo "Looking for $lookfor" ; fi
- Xfound=`grep $lookfor $nmfile | egrep "$nm_defined_func"`
- Xif test "$found" ; then
- X signal_handling=posix
- Xelse
- X lookfor=sigvec
- X if test "$verbose" ; then $echo "Looking for $lookfor" ; fi
- X found=`grep $lookfor $nmfile | egrep "$nm_defined_func"`
- X if test "$found" ; then
- X signal_handling=bsd
- X else
- X signal_handling=simple
- X fi
- Xfi
- X
- X
- X#
- X# Check for setitimer(2)
- X#
- Xlookfor=setitimer
- Xif test "$verbose" ; then $echo "Looking for $lookfor" ; fi
- Xfound=`grep $lookfor $nmfile | egrep "$nm_defined_func"`
- Xif test "$found" ; then
- X case "$signal_handling" in
- X posix) timer_defs= ;;
- X bsd) timer_defs=-DNO_POSIX_SIGS ;;
- X simple) no_timers=yes
- X esac
- Xelse
- X no_timers=yes
- Xfi
- X
- X
- X#######################################################################
- X#
- X# XLOG library configuration.
- X#
- X#######################################################################
- X
- X#
- X# Check for syslog(3)
- X#
- Xlookfor=syslog
- Xif test "$verbose" ; then $echo "Looking for $lookfor" ; fi
- Xfound=`grep $lookfor $nmfile | egrep "$nm_defined_func"`
- Xif test "$found" = "" ; then v=-DNO_SYSLOG ; else v= ; fi
- Xxlog_defs="$xlog_defs $v"
- X
- X#
- X# Look for syslog.h
- X#
- Xv=
- Xif test -r $inc/sys/syslog.h ; then
- X v=-DSYSLOG_IN_SYS
- X if test -r $inc/syslog.h ; then
- X cmp -s $inc/syslog.h $inc/sys/syslog.h
- X if test $? -eq 0 ; then v= ; fi
- X fi
- Xfi
- Xxlog_defs="$xlog_defs $v"
- X
- X
- X#######################################################################
- X#
- X# MISC library configuration.
- X#
- X#######################################################################
- X
- X#
- X# Check for new directory types
- X#
- Xif test -r $inc/dirent.h ; then v= ; else v=-DOLD_DIR ; fi
- Xmisc_defs="$misc_defs $v"
- X
- X#
- X# Check for ftw(3)
- X#
- Xif test -r $inc/ftw.h ; then v= ; else v=-D__FTWX_NO_FTW ; fi
- Xmisc_defs="$misc_defs $v"
- X
- X
- X#######################################################################
- X#
- X# SIO library configuration.
- X#
- X# Note that we do not try to find out if the system actually supports
- X# a generic mmap system call (i.e. an mmap capable of mapping regular
- X# files).
- X#
- X#######################################################################
- X
- Xlookfor=on_exit
- Xif test "$verbose" ; then $echo "Looking for $lookfor" ; fi
- Xfound=`grep $lookfor $nmfile | egrep "$nm_defined_func"`
- Xif test "$found" ; then v=-DHAS_ONEXIT ; else v= ; fi
- Xsio_defs="$sio_defs $v"
- X
- Xlookfor=atexit
- Xif test "$verbose" ; then $echo "Looking for $lookfor" ; fi
- Xfound=`grep $lookfor $nmfile | egrep "$nm_defined_func"`
- Xif test "$found" ; then v=-DHAS_ATEXIT ; else v= ; fi
- Xsio_defs="$sio_defs $v"
- X
- Xlookfor=memcpy
- Xif test "$verbose" ; then $echo "Looking for $lookfor" ; fi
- Xfound=`grep $lookfor $nmfile | egrep "$nm_defined_func"`
- Xif test "$found" ; then v=-DHAS_MEMOPS ; else v= ; fi
- Xsio_defs="$sio_defs $v"
- X
- Xlookfor=bcopy
- Xif test "$verbose" ; then $echo "Looking for $lookfor" ; fi
- Xfound=`grep $lookfor $nmfile | egrep "$nm_defined_func"`
- Xif test "$found" ; then v=-DHAS_BCOPY ; else v= ; fi
- Xsio_defs="$sio_defs $v"
- X
- Xlookfor=isatty
- Xif test "$verbose" ; then $echo "Looking for $lookfor" ; fi
- Xfound=`grep $lookfor $nmfile | egrep "$nm_defined_func"`
- Xif test "$found" ; then has_isatty=-DHAS_ISATTY ; else has_isatty= ; fi
- Xsio_defs="$sio_defs $has_isatty"
- X
- Xrm -f $nmfile
- X
- X#
- X# Inform the user about our findings.
- X#
- Xsio_defs=`echo $sio_defs`
- Xif test "$sio_defs" ; then
- X echo
- X $echo "For the SIO library, set the following preprocessor flags:"
- X $echo "$sio_defs"
- X if test "$has_isatty" = "" ; then
- X echo "Your system does not have the isatty(3) function which is"
- X echo "required by the SIO library. A replacement can be provided"
- X echo "by determining if your system supports BSD or System V tty"
- X echo "handling. In the former case, use the flag -DHAS_BSDTTY, and"
- X echo "in the latter, use the flag -DHAS_SYSVTTY"
- X fi
- Xfi
- X
- Xxlog_defs=`echo $xlog_defs`
- Xecho
- Xif test "$xlog_defs" ; then
- X $echo "For the XLOG library, set the following preprocessor flags:"
- X $echo "$xlog_defs"
- Xelse
- X echo "No flags need to be set for the XLOG library"
- Xfi
- X
- Xmisc_defs=`echo $misc_defs`
- Xecho
- Xif test "$misc_defs" ; then
- X $echo "For the MISC library, set the following preprocessor flags:"
- X $echo "$misc_defs"
- Xelse
- X echo "No flags need to be set for the MISC library"
- Xfi
- X
- Xif test "$no_times" = "" ; then
- X timer_defs=`echo $timer_defs`
- X echo
- X if test "$timer_defs" ; then
- X $echo "For the TIMER library, set the following preprocessor flags:"
- X $echo "$timer_defs"
- X else
- X echo "No flags need to be set for the TIMER library"
- X fi
- Xelse
- X echo "Your system does not support the necessary facilities needed"
- X echo "by the timer library, so that library cannot be compiled"
- Xfi
- END_OF_FILE
- if test 7097 -ne `wc -c <'libconf'`; then
- echo shar: \"'libconf'\" unpacked with wrong size!
- fi
- chmod +x 'libconf'
- # end of 'libconf'
- fi
- if test -f 'libs/src/sio/sio.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'libs/src/sio/sio.h'\"
- else
- echo shar: Extracting \"'libs/src/sio/sio.h'\" \(6642 characters\)
- sed "s/^X//" >'libs/src/sio/sio.h' <<'END_OF_FILE'
- X/*
- X * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
- X * All rights reserved. The file named COPYRIGHT specifies the terms
- X * and conditions for redistribution.
- X */
- X
- X/*
- X * $Id: sio.h,v 8.1 1993/03/13 01:13:58 panos Exp $
- X */
- X
- X#ifndef __SIO_H
- X#define __SIO_H
- X
- X#include <errno.h>
- X#include <varargs.h>
- X
- X/*
- X * Naming conventions:
- X * 1) SIO functions and macros have names starting with a capital S
- X * 2) SIO constants meant to be used by user programs have
- X * names starting with SIO_
- X * 3) Internal functions, struct identifiers, enum identifiers
- X * etc. have names starting with __sio
- X * 4) Internal constants and macros have names starting with __SIO
- X */
- X
- X
- X/*
- X * external constants
- X *
- X * SIO_FLUSH_ALL: flush all output streams
- X * SIO_EOF: eof on stream
- X * SIO_ERR: operation failed
- X */
- X#define SIO_FLUSH_ALL (-1)
- X#define SIO_EOF (-2)
- X#define SIO_ERR (-1)
- X
- X/*
- X * Undo types
- X */
- X#define SIO_UNDO_LINE 0
- X#define SIO_UNDO_CHAR 1
- X
- X/*
- X * Buffering types
- X */
- X#define SIO_FULLBUF 0
- X#define SIO_LINEBUF 1
- X#define SIO_NOBUF 2
- X
- X/*
- X * Descriptor for an input stream
- X */
- Xstruct __sio_input_descriptor
- X{
- X /*
- X * buf: points to the buffer area.
- X * When doing memory mapping, it is equal to the unit
- X * from which we are reading. When doing buffered I/O
- X * it points to the primary buffer.
- X */
- X char *buf ;
- X unsigned buffer_size ;
- X
- X char *start ; /* start of valid buffer contents */
- X char *end ; /* end of valid buffer contents + 1 */
- X char *nextb ; /* pointer to next byte to read/write */
- X /* Always: start <= nextb < end */
- X
- X unsigned line_length ;
- X int max_line_length ;
- X int tied_fd ;
- X
- X int memory_mapped ; /* flag to denote if we use */
- X /* memory mapping */
- X} ;
- X
- Xtypedef struct __sio_input_descriptor __sio_id_t ;
- X
- X
- X/*
- X * Descriptor for an output stream
- X */
- Xstruct __sio_output_descriptor
- X{
- X /*
- X * buf: points to the buffer area.
- X * buf_end: is equal to buf + buffer_size
- X */
- X char *buf ;
- X char *buf_end ;
- X
- X unsigned buffer_size ;
- X
- X char *start ; /* start of valid buffer contents */
- X /* (used by the R and W functions) */
- X char *nextb ; /* pointer to next byte to read/write */
- X /* Always: start <= nextb < buf_end */
- X int buftype ; /* type of buffering */
- X} ;
- X
- Xtypedef struct __sio_output_descriptor __sio_od_t ;
- X
- X
- X
- X/*
- X * Stream types
- X */
- Xenum __sio_stream { __SIO_INPUT_STREAM, __SIO_OUTPUT_STREAM } ;
- X
- X
- X/*
- X * General descriptor
- X */
- Xstruct __sio_descriptor
- X{
- X union
- X {
- X __sio_id_t input_descriptor ;
- X __sio_od_t output_descriptor ;
- X } descriptor ;
- X enum __sio_stream stream_type ;
- X int initialized ;
- X} ;
- X
- Xtypedef struct __sio_descriptor __sio_descriptor_t ;
- X
- X
- X/*
- X * The array of descriptors (as many as available file descriptors)
- X */
- Xextern __sio_descriptor_t *__sio_descriptors ;
- X
- Xextern int errno ;
- X
- X
- X/*
- X * Internally used macros
- X */
- X#define __SIO_FD_INITIALIZED( fd ) (__sio_descriptors[ fd ].initialized)
- X#define __SIO_ID( fd ) (__sio_descriptors[ fd ].descriptor.input_descriptor)
- X#define __SIO_OD( fd ) (__sio_descriptors[ fd ].descriptor.output_descriptor)
- X#define __SIO_MUST_FLUSH( od, ch ) \
- X ( (od).buftype != SIO_FULLBUF && \
- X ( (od).buftype == SIO_NOBUF || ch == '\n' ) )
- X
- X
- X/*
- X * SIO Macros:
- X *
- X * SIOLINELEN( fd )
- X * SIOMAXLINELEN( fd )
- X * Sputchar( fd, c )
- X * Sgetchar( fd )
- X *
- X * NOTE: The maximum line size depends on whether the descriptor
- X * was originally memory mapped. If it was, then the maximum
- X * line size will be the map_unit_size (a function of the system
- X * page size and PAGES_MAPPED). Otherwise, it will be either the
- X * optimal block size as reported by stat(2) or SIO_BUFFER_SIZE.
- X */
- X
- X#define SIOLINELEN( fd ) __SIO_ID( fd ).line_length
- X#define SIOMAXLINELEN( fd ) \
- X ( \
- X __SIO_FD_INITIALIZED( fd ) \
- X ? ( \
- X (__sio_descriptors[ fd ].stream_type == __SIO_INPUT_STREAM) \
- X ? __SIO_ID( fd ).max_line_length \
- X : ( errno = EBADF, SIO_ERR ) \
- X ) \
- X : ( /* not initialized; initialize it for input */ \
- X (__sio_init( &__sio_descriptors[ fd ], fd, __SIO_INPUT_STREAM ) \
- X == SIO_ERR) \
- X ? SIO_ERR \
- X : __SIO_ID( fd ).max_line_length \
- X ) \
- X )
- X
- X
- X
- X/*
- X * Adds a character to a buffer, returns the character or SIO_ERR
- X */
- X#define __SIO_ADDCHAR( od, fd, c ) \
- X ( od.buftype == SIO_FULLBUF ) \
- X ? (int) ( *(od.nextb)++ = (unsigned char) (c) ) \
- X : ( od.buftype == SIO_LINEBUF ) \
- X ? ( ( *(od.nextb) = (unsigned char) (c) ) != '\n' ) \
- X ? (int) *(od.nextb)++ \
- X : Sputc( fd, *(od.nextb) ) \
- X : Sputc( fd, c )
- X
- X
- X/*
- X * The Sgetchar/Sputchar macros depend on the fact that the fields
- X * nextb, buf_end, end
- X * are 0 if a stream descriptor is not being used or has not yet been
- X * initialized.
- X * This is true initially because of the static allocation of the
- X * descriptor array, and Sdone must make sure that it is true
- X * after I/O on a descriptor is over.
- X */
- X#define Sputchar( fd, c ) \
- X ( \
- X ( __SIO_OD( fd ).nextb < __SIO_OD( fd ).buf_end ) \
- X ? ( __SIO_ADDCHAR( __SIO_OD( fd ), fd, c ) ) \
- X : Sputc( fd, c ) \
- X )
- X
- X#define Sgetchar( fd ) \
- X ( \
- X ( __SIO_ID( fd ).nextb < __SIO_ID( fd ).end ) \
- X ? (int) *__SIO_ID( fd ).nextb++ \
- X : Sgetc( fd ) \
- X )
- X
- X
- X#ifdef __ARGS
- X#undef __ARGS
- X#endif
- X
- X#ifdef PROTOTYPES
- X# define __ARGS( s ) s
- X#else
- X# define __ARGS( s ) ()
- X#endif
- X
- X/*
- X * The Read functions
- X */
- Xint Sread __ARGS( ( int fd, char *buf, int nbytes ) ) ;
- Xint Sgetc __ARGS( ( int fd ) ) ;
- Xchar *Srdline __ARGS( ( int fd ) ) ;
- Xchar *Sfetch __ARGS( ( int fd, long *length ) ) ;
- X
- X/*
- X * The Write functions
- X */
- Xint Swrite __ARGS( ( int fd, char *buf, int nbytes ) ) ;
- Xint Sputc __ARGS( ( int fd, char c ) ) ;
- Xint Sprint __ARGS( ( int fd, char *format, ... ) ) ;
- Xint Sprintv __ARGS( ( int fd, char *format, va_list ) ) ;
- X
- X/*
- X * other functions
- X */
- Xint Sdone __ARGS( ( int fd ) ) ;
- Xint Sundo __ARGS( ( int fd, int type ) ) ;
- Xint Sflush __ARGS( ( int fd ) ) ;
- Xint Sclose __ARGS( ( int fd ) ) ;
- Xint Sbuftype __ARGS( ( int fd, int type ) ) ;
- X
- X#endif /* __SIO_H */
- X
- END_OF_FILE
- if test 6642 -ne `wc -c <'libs/src/sio/sio.h'`; then
- echo shar: \"'libs/src/sio/sio.h'\" unpacked with wrong size!
- fi
- # end of 'libs/src/sio/sio.h'
- fi
- if test -f 'libs/src/str/strs.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'libs/src/str/strs.c'\"
- else
- echo shar: Extracting \"'libs/src/str/strs.c'\" \(6391 characters\)
- sed "s/^X//" >'libs/src/str/strs.c' <<'END_OF_FILE'
- X/*
- X * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
- X * All rights reserved. The file named COPYRIGHT specifies the terms
- X * and conditions for redistribution.
- X */
- X
- Xstatic char RCSid[] = "$Id: strs.c,v 3.1 1993/06/13 02:50:39 panos Exp $" ;
- X
- X#include <ctype.h>
- X#include <memory.h>
- X#include <varargs.h>
- X
- Xchar *malloc() ;
- X
- X#include "ss_impl.h"
- X
- X/*
- X * NOTE: The brute force method (with the __strs_bfops) must be always
- X * available so that we can switch to it if another method fails.
- X */
- Xextern struct ss_ops __strs_bfops ;
- Xextern struct ss_ops __strs_rkops ;
- Xextern struct ss_ops __strs_kmpops ;
- Xextern struct ss_ops __strs_sbmops ;
- Xextern struct ss_ops __strs_bmhops ;
- Xextern struct ss_ops __strs_soops ;
- X
- X/*
- X * NOTE: This table is arranged according to increasing method number.
- X * This allows quick indexing into it using the user-provided
- X * method as a hint:
- X * if ( selection_table[ user_method ].method == user_method )
- X * FOUND
- X * else
- X * DO SEQUENTIAL SEARCH
- X * This allows both quick access and a change of method numbers
- X * in the future without requiring recompilation of programs in
- X * order to work with new versions of the library.
- X */
- Xstatic struct ss_select selection_table[] =
- X {
- X { STRS_BF, &__strs_bfops },
- X { STRS_RK, &__strs_rkops },
- X { STRS_KMP, &__strs_kmpops },
- X { STRS_SBM, &__strs_sbmops },
- X { STRS_BMH, &__strs_bmhops },
- X { STRS_SO, &__strs_soops },
- X { 0, 0 }
- X } ;
- X
- Xstatic char identity_map[ ALPHABET_SIZE ] ;
- Xstatic char upper_to_lower_map[ ALPHABET_SIZE ] ;
- X
- Xstatic int tables_initialized ;
- X
- X/*
- X * This header is returned when an empty pattern is given to strs_setup.
- X * The rest of the functions check ss_patlen and do nothing if that is zero.
- X * ss_patlen in this header will be initialized to zero.
- X */
- Xstatic header_s empty_pattern_header ;
- X
- X
- XPRIVATE void initialize_tables()
- X{
- X int i ;
- X
- X for ( i = 0 ; i < sizeof( upper_to_lower_map ) ; i++ )
- X {
- X if ( isascii( i ) && isupper( i ) )
- X upper_to_lower_map[ i ] = i + 'a' - 'A' ;
- X else
- X upper_to_lower_map[ i ] = i ;
- X identity_map[ i ] = i ;
- X }
- X}
- X
- X
- X/*
- X * Initializes header
- X *
- X * Note that 'pattern' does not need to be a NUL-terminated string.
- X */
- XPRIVATE int init( hp, flags, pattern, patlen )
- X register header_s *hp ;
- X int flags ;
- X char *pattern ;
- X int patlen ;
- X{
- X int requested_method = SS_GETMETHOD( flags ) ;
- X register struct ss_select *selp ;
- X
- X if ( ! tables_initialized )
- X {
- X initialize_tables() ;
- X tables_initialized = TRUE ;
- X }
- X
- X /*
- X * Initialize header fields
- X */
- X SS_FLAGS( hp ) = SS_GETFLAGS( flags ) ;
- X SS_PATLEN( hp ) = patlen ;
- X if ( SS_SWITCH( hp ) && patlen < 4 )
- X SS_OPS( hp ) = &__strs_bfops ; /* brute force */
- X else
- X {
- X /*
- X * Determine ops
- X */
- X if ( selection_table[ requested_method ].sel_method == requested_method )
- X selp = &selection_table[ requested_method ] ;
- X else
- X for ( selp = &selection_table[ 0 ] ; selp->sel_ops ; selp++ )
- X if ( requested_method == selp->sel_method )
- X break ;
- X if ( selp->sel_ops )
- X SS_OPS( hp ) = selp->sel_ops ;
- X else if ( SS_SWITCH( hp ) )
- X SS_OPS( hp ) = &__strs_bfops ; /* brute force */
- X else
- X return( SS_ERR ) ;
- X }
- X
- X if ( SS_MALLOC( hp ) )
- X {
- X SS_PATTERN( hp ) = malloc( (unsigned)SS_PATLEN( hp ) ) ;
- X if ( SS_PATTERN( hp ) == CHAR_NULL )
- X {
- X (void) free( (char *)hp ) ;
- X return( SS_ERR ) ;
- X }
- X (void) memcpy( SS_PATTERN( hp ), pattern, (int)SS_PATLEN( hp ) ) ;
- X }
- X else
- X SS_PATTERN( hp ) = pattern ;
- X
- X /*
- X * If the user asked for case-insensitive search, we create our own
- X * copy of the pattern in lower case. If the pattern is malloc'ed
- X * we overwrite, otherwise we malloc some memory and clear the
- X * STRS_NOMALLOC flag.
- X */
- X if ( SS_IGNCASE( hp ) )
- X {
- X char *new_pattern ;
- X register int i ;
- X
- X SS_SETMAP( hp, upper_to_lower_map ) ;
- X
- X if ( SS_MALLOC( hp ) )
- X new_pattern = SS_PATTERN( hp ) ;
- X else
- X {
- X new_pattern = malloc( (unsigned)SS_PATLEN( hp ) + 1 ) ;
- X if ( new_pattern == CHAR_NULL )
- X return( SS_ERR ) ;
- X SS_SETMALLOC( hp ) ; /* clears the STRS_NOMALLOC flag */
- X }
- X for ( i = 0 ; i < SS_PATLEN( hp ) ; i++ )
- X new_pattern[ i ] = SS_MAP( hp, SS_PATTERN( hp )[ i ] ) ;
- X SS_PATTERN( hp ) = new_pattern ;
- X }
- X else
- X SS_SETMAP( hp, identity_map ) ;
- X
- X for ( ;; )
- X {
- X if ( SS_SETUP( hp ) == SS_OK )
- X return( SS_OK ) ;
- X else
- X {
- X if ( ! SS_SWITCH( hp ) || SS_OPS( hp ) == &__strs_bfops )
- X {
- X if ( SS_MALLOC( hp ) )
- X (void) free( (char *)hp ) ;
- X return( SS_ERR ) ;
- X }
- X SS_OPS( hp ) = &__strs_bfops ;
- X }
- X }
- X}
- X
- X
- X/*
- X * Finalize header
- X */
- XPRIVATE void fini( hp )
- X header_s *hp ;
- X{
- X SS_DONE( hp ) ;
- X if ( SS_MALLOC( hp ) )
- X (void) free( SS_PATTERN( hp ) ) ;
- X}
- X
- X
- X/*
- X * Create a search handle
- X */
- Xstrs_h strs_setup( flags, pattern, va_alist )
- X int flags ;
- X char *pattern ;
- X va_dcl
- X{
- X header_s *hp ;
- X int patlen ;
- X va_list ap ;
- X
- X hp = HP( malloc( sizeof( *hp ) ) ) ;
- X if ( hp == NULL )
- X return( NULL_HANDLE ) ;
- X
- X if ( flags & STRS_PATLEN )
- X {
- X va_start( ap ) ;
- X patlen = va_arg( ap, int ) ;
- X va_end( ap ) ;
- X }
- X else
- X patlen = strlen( pattern ) ;
- X
- X if ( patlen == 0 )
- X return( (strs_h) &empty_pattern_header ) ;
- X
- X if ( init( hp, flags, pattern, patlen ) == SS_OK )
- X return( (strs_h)hp ) ;
- X else
- X {
- X free( (char *)hp ) ;
- X return( NULL_HANDLE ) ;
- X }
- X}
- X
- X
- X/*
- X * Destroy a search handle
- X */
- Xvoid strs_done( handle )
- X strs_h handle ;
- X{
- X header_s *hp = HP( handle ) ;
- X
- X if ( SS_PATLEN( hp ) != 0 )
- X {
- X fini( hp ) ;
- X (void) free( (char *) handle ) ;
- X }
- X}
- X
- X
- Xchar *strs_match( handle, str, len )
- X strs_h handle ;
- X char *str ;
- X int len ;
- X{
- X register header_s *hp = HP( handle ) ;
- X
- X if ( SS_PATLEN( hp ) == 0 )
- X return( str ) ;
- X if ( SS_PATLEN( hp ) > len )
- X return( CHAR_NULL ) ;
- X return( SS_MATCH( hp, str, len ) ) ;
- X}
- X
- X
- X
- Xchar *strs_search( flags, str, len, pattern, va_alist )
- X int flags ;
- X char *str ;
- X int len ;
- X char *pattern ; /* NUL-terminated */
- X va_dcl
- X{
- X header_s t_header ;
- X char *p ;
- X int patlen ;
- X va_list ap ;
- X
- X if ( flags & STRS_PATLEN )
- X {
- X va_start( ap ) ;
- X patlen = va_arg( ap, int ) ;
- X va_end( ap ) ;
- X }
- X else
- X patlen = strlen( pattern ) ;
- X
- X if ( patlen == 0 )
- X return( str ) ;
- X
- X if ( patlen > len )
- X return( CHAR_NULL ) ;
- X
- X if ( init( &t_header, flags | STRS_NOMALLOC, pattern, patlen ) == SS_OK )
- X {
- X p = SS_MATCH( &t_header, str, len ) ;
- X fini( &t_header ) ;
- X return( p ) ;
- X }
- X else
- X return( CHAR_NULL ) ;
- X}
- X
- X
- END_OF_FILE
- if test 6391 -ne `wc -c <'libs/src/str/strs.c'`; then
- echo shar: \"'libs/src/str/strs.c'\" unpacked with wrong size!
- fi
- # end of 'libs/src/str/strs.c'
- fi
- if test -f 'libs/src/xlog/xlog.3' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'libs/src/xlog/xlog.3'\"
- else
- echo shar: Extracting \"'libs/src/xlog/xlog.3'\" \(7434 characters\)
- sed "s/^X//" >'libs/src/xlog/xlog.3' <<'END_OF_FILE'
- X.\"(c) Copyright 1992, 1993 by Panagiotis Tsirigotis
- X.\"All rights reserved. The file named COPYRIGHT specifies the terms
- X.\"and conditions for redistribution.
- X.\"
- X.\" $Id: xlog.3,v 2.4 1993/10/28 01:36:29 panos Exp $
- X.TH XLOG 3X "15 June 1993"
- Xxlog_parms, xlog_create, xlog_destroy, xlog_write, xlog_control -- general purpose logging facility
- X.SH SYNOPSIS
- X.LP
- X.nf
- X.ft B
- X#include "xlog.h"
- X.LP
- X.ft B
- Xxlog_h xlog_create( type, id, flags, ... )
- Xxlog_e type ;
- Xchar *id ;
- Xint flags ;
- X.LP
- X.ft B
- Xint xlog_parms( type, ... )
- Xxlog_e type ;
- X.LP
- X.ft B
- Xvoid xlog_destroy( xlog )
- Xxlog_h xlog ;
- X.LP
- X.ft B
- Xvoid xlog_write( xlog, buf, len, flags, ... )
- Xxlog_h xlog ;
- Xchar buf[] ;
- Xint len ;
- Xint flags ;
- X.LP
- X.ft B
- Xint xlog_control( xlog, cmd, ... )
- Xxlog_h xlog ;
- Xxlog_cmd_e cmd ;
- X.SH DESCRIPTION
- XThe purpose of this library is to provide a general purpose logging facility
- Xby providing
- X.I xlogs,
- Xlogging objects that may be connected to various existent logging facilities.
- XCurrently, the only logging facilities supported are
- X.I "syslog(3)"
- Xand logging to files.
- XLog entries are timestamped lines which may contain arbitrary information.
- X.\" ********************* xlog_create ***********************
- X.LP
- X.B xlog_create()
- Xcreates a new xlog of the specified
- X.I type.
- XPossible type values are:
- X.RS
- X.TP 20
- X.SB XLOG_SYSLOG
- XVarargs: \fIint facility, int priority\fP.
- XThe xlog will be connected to
- X.I "syslog(3)."
- X.I facility
- Xdetermines the syslog facility to use for logged messages and
- X.I priority
- Xis the default message priority.
- X.TP
- X.SB XLOG_FILELOG
- XVarargs: \fIchar *pathname, int flags [, int flags]\fP.
- XThe xlog will be connected to the file identified by
- X.I pathname.
- XThe variable part of the argument list has the same semantics as the
- Xargument list of the
- X.I "open(2)"
- Xsystem call.
- X.RE
- X.LP
- XAll xlogs have an id, specified by the
- X.I id
- Xargument. The
- X.I flags
- Xargument is formed by ORing one or more of the following constants:
- X.RS
- X.TP 20
- X.SB XLOG_NO_ERRNO
- Xdo not replace
- X.I "%m"
- Xwith an explanation of the current value of errno.
- X.TP
- X.SB XLOG_NO_SIZECHECK
- X.I "(XLOG_FILELOG only)"
- Xdo not perform size checks on the file.
- X.TP
- X.SB XLOG_PRINT_ID
- Xprecede each log entry with the xlog id
- X.TP
- X.SB XLOG_PRINT_PID
- Xprecede each log entry with the process id
- X(the process id will follow the xlog id)
- X.RE
- X.LP
- XFlags that do not apply to the xlog are ignored.
- XThe contant
- X.SM XLOG_NOFLAGS
- Xcan be used if you don't want to specify any flags.
- X.\" ********************* xlog_parms ***********************
- X.LP
- X.B xlog_parms()
- Xsets default parameters for the specified xlog
- X.I type:
- X.RS
- X.TP 20
- X.SB XLOG_SYSLOG
- X3 arguments are expected which correspond one-to-one to the arguments of
- X.I "openlog(3)."
- XThe defaults, in case this function is not used, are:
- X"XLOG", LOG_PID + LOG_NOWAIT, LOG_USER
- X.TP
- X.SB XLOG_FILELOG
- XNo action.
- X.RE
- X.LP
- X.B xlog_parms()
- Xshould be invoked before any xlogs of the specified type
- Xare created.
- X.\" ********************* xlog_destroy ***********************
- X.LP
- X.B xlog_destroy()
- Xdestroys an xlog. The action taken depends on the type of the xlog:
- X.RS
- X.TP 20
- X.SB XLOG_SYSLOG
- Xif this is the last xlog using syslog, then
- X.I "closelog(3)"
- Xis invoked.
- X.TP
- X.SB XLOG_FILELOG
- XThe file is closed.
- X.RE
- X.\" ********************* xlog_control ***********************
- X.LP
- X.B xlog_control()
- Xapplies control operations to an xlog. Certain operations are common to
- Xall xlogs while others are type-specific. The common ones are:
- X.RS
- X.TP 15
- X.SB XLOG_LINK
- XArgument list: \fIxlog_h link_to\fP.
- XLink the specified xlog to the one provided as argument.
- X(if the argument is
- X.SM NULL
- Xany existent link is severed).
- XLinking xlogs has the effect that if one finds an error it uses the
- Xother to report it.
- X.TP
- X.SB XLOG_CALLBACK
- XArgument list: \fIvoid (*callback)(), void *arg\fP.
- XThis function will be invoked in case of error while writing a log
- Xentry. It will be given
- X3 arguments: the xlog handle, an integer that indicates the type
- Xof error and the
- X.I arg
- Xspecified in this call. Possible errors include:
- X.RS
- X.TP 15
- X.SB XLOG_ENOMEM
- Xlack of memory
- X.TP
- X.SB XLOG_EOPEN
- X.I "open(2)"
- Xfailed
- X.TP
- X.SB XLOG_EFSTAT
- X.I "fstat(2)"
- Xfailed
- X.TP
- X.SB XLOG_ESIZE
- Xhard limit exceeded
- X.RE
- X.TP
- X.SB XLOG_SETFLAG
- XArgument list: \fIint flag, int *value\fP.
- XThe value of
- X.I flag
- X(one of those listed before) is set according to
- X.I "*value"
- Xwhich should be either 0 or 1.
- XThe old flag value is placed in
- X.I "*value."
- X.TP
- X.SB XLOG_GETFLAG
- XArgument list: \fIint flag, int *value\fP.
- XThe value of
- X.I flag
- X(one of those listed before) is placed in
- X.I "*value."
- X.RE
- X.LP
- XThe type-specific operations have the following semantics when the
- Xoperation is applied to an incompatible xlog: if the operation returns
- Xa result to the caller (for example, check \fPXLOG_GETFD\fP), the
- Xoperation will be considered to have failed, otherwise the operation
- Xwill be considered successful.
- X.LP
- XXlogs of type
- X.B XLOG_SYSLOG
- Xalso support the following operations:
- X.RS
- X.TP 15
- X.SB XLOG_FACILITY
- XArgument list: \fIint facility\fP.
- XSets the syslog facility to the specified value.
- X.TP
- X.SB XLOG_LEVEL
- XArgument list: \fIint level\fP.
- XSets the default syslog level for this xlog to the specified value.
- X.TP
- X.SB XLOG_PREEXEC
- XArgument list: \fIvoid\fP.
- XPrepares the xlog for an impending exec operation
- X.TP
- X.SB XLOG_POSTEXEC
- XArgument list: \fIvoid\fP.
- XInforms the xlog that the exec failed
- X.RE
- X.LP
- XXlogs of type
- X.B XLOG_FILELOG
- Xalso support the following operations:
- X.RS
- X.TP 15
- X.SB XLOG_LIMITS
- XArgument list: \fIunsigned soft_limit, unsigned hard_limit\fP.
- XSets soft and hard limits on the size of the file.
- XWhen any of the limits is exceeded a message is sent to the linked xlog.
- X(if there is no linked xlog, no message is sent)
- XWhen the soft limit is exceeded a warning message is sent to the linked xlog
- X(if the linked xlog is of the
- X.SB XLOG_SYSLOG
- Xtype, the message will be sent at the
- X.I LOG_ALERT
- Xlevel).
- XIf the exceeded limit is the hard limit, logging is terminated.
- XThe actual file size is checked every time this operation is applied to
- Xthe file.
- XIf logging was terminated because the hard limit was exceeded and
- Xthis operation increases the hard limit beyond the actual file size,
- Xlogging will be resumed.
- X.TP
- X.SB XLOG_SIZECHECK
- XArgument list: \fIvoid\fP.
- XChecks the actual file size.
- X.TP
- X.SB XLOG_GETFD
- XArgument list: \fIint *value\fP.
- XPlaces in
- X.I "*value"
- Xthe file descriptor of the log file.
- X.RE
- X.\" ********************* xlog_write ***********************
- X.LP
- X.B xlog_write()
- Xwrites a message to the specified xlog. A
- X.SM NEWLINE
- Xis always appended to the message.
- XThe first occurrence of "%m" in
- X.I buf
- Xis replaced by a string explaining the current value of
- X.I errno.
- XThe
- X.I flags
- Xargument is formed in the same way as in
- X.B xlog_create().
- XOne additional constant is available:
- X.RS
- X.TP 20
- X.SB XLOG_SET_LEVEL
- X.I "(XLOG_SYSLOG only)"
- Xthe next argument is an integer that should be used as the syslog level
- Xfor this message instead of the default level of the xlog.
- X.RE
- X.SH "RETURN VALUES"
- X.B xlog_create()
- Xreturns an xlog handle or
- X.SM NULL
- Xif it fails.
- X.LP
- X.B xlog_control()
- Xreturns an error code (it returns
- X.SM XLOG_ENOERROR
- Xif it is successful).
- X.LP
- X.B xlog_parms()
- Xreturns an error code (it returns
- X.SM XLOG_ENOERROR
- Xif it is successful).
- X.SH "SEE ALSO"
- Xopenlog(3), syslog(3), closelog(3)
- X.SH BUGS
- X.LP
- XOnly the first occurrence of
- X.I "%m"
- Xis replaced by an errno explanation.
- X.LP
- XThere is no check for cycles when linking xlogs. In particular it is
- Xpossible to link a xlog to itself.
- END_OF_FILE
- if test 7434 -ne `wc -c <'libs/src/xlog/xlog.3'`; then
- echo shar: \"'libs/src/xlog/xlog.3'\" unpacked with wrong size!
- fi
- # end of 'libs/src/xlog/xlog.3'
- fi
- echo shar: End of archive 13 \(of 20\).
- cp /dev/null ark13isdone
- MISSING=""
- for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked all 20 archives.
- rm -f ark[1-9]isdone ark[1-9][0-9]isdone
- else
- echo You still need to unpack the following archives:
- echo " " ${MISSING}
- fi
- ## End of shell archive.
- exit 0
-