home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-11-28 | 32.3 KB | 1,297 lines |
- Newsgroups: comp.sources.unix
- From: panos@anchor.cs.colorado.edu (Panos Tsirigotis)
- Subject: v27i111: clc - C Libraries Collection, Part05/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 111
- Archive-Name: clc/part05
-
- #! /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 5 (of 20)."
- # Contents: libs/src/dict/dllimpl.h libs/src/misc/env.3
- # libs/src/pset/pset.h libs/src/str/ss_impl.h libs/src/str/ss_kmp.c
- # libs/src/str/ss_rk.c libs/src/str/ss_so.c libs/src/str/strprint.3
- # libs/src/xlog/impl.h
- # Wrapped by panos@eclipse on Sun Nov 28 14:48:15 1993
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'libs/src/dict/dllimpl.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'libs/src/dict/dllimpl.h'\"
- else
- echo shar: Extracting \"'libs/src/dict/dllimpl.h'\" \(3016 characters\)
- sed "s/^X//" >'libs/src/dict/dllimpl.h' <<'END_OF_FILE'
- X/*
- X * (c) Copyright 1993 by Panagiotis Tsirigotis
- X * All rights reserved. The file named COPYRIGHT specifies the terms
- X * and conditions for redistribution.
- X */
- X
- X
- X/*
- X * $Id: dllimpl.h,v 3.1 93/04/23 17:50:15 panos Exp $
- X */
- X
- X#include "dictimpl.h"
- X#include "dll.h"
- X
- Xstruct list_node
- X{
- X struct list_node *next ;
- X struct list_node *prev ;
- X dict_obj obj ;
- X} ;
- X
- Xtypedef struct list_node node_s ;
- X
- X
- X/*
- X * Macros for list_node's
- X */
- X#define NEXT( n ) (n)->next
- X#define PREV( n ) (n)->prev
- X#define OBJ( n ) (n)->obj
- X
- X
- X/*
- X * The oo_compare function is used for insertions and deletions.
- X * The ko_compare function is used in searches.
- X * These functions are expected to return:
- X * a negative value if key(o1) < key(o2)
- X * 0 if key(o1) = key(o2)
- X * a positive value if key(o1) > key(o2)
- X *
- X *
- X * The list is sorted according to some key. The package does not
- X * care what the key is. The order is defined by the two comparison
- X * functions (which, of course, should be consistent).
- X *
- X * We assume that key values get larger when we follow the _next_ chain
- X * and they get smaller when we follow the _prev_ chain.
- X *
- X *
- X * ABOUT HINTS:
- X * a. We keep hints to avoid linear searches of the linked list.
- X * b. A hint is either correct or non-existent.
- X * c. To avoid bad hints, dll_delete sets the DATA field of a
- X * list_node to NULL.
- X * d. We do not allow insertions of NULL.
- X * e. An operation that uses/consults a hint always clears it or resets it.
- X *
- X * --------------------------------------------------------------------
- X * | OPERATIONS | HINTS |
- X * |------------|-------------------------------------------------------|
- X * | | SEARCH | SUCCESSOR | PREDECESSOR |
- X * |------------|--------------|--------------------|-------------------|
- X * | insert | X | X | X |
- X * | delete | USE & CLEAR | CLEAR | CLEAR |
- X * | search | SET | X | X |
- X * | minimum | X | SET | X |
- X * | maximum | X | X | SET |
- X * | successor | X | USE & SET | X |
- X * | predecessor| X | X | USE & SET |
- X * --------------------------------------------------------------------
- X *
- X */
- X
- X
- Xstruct hints
- X{
- X node_s *last_search ;
- X node_s *last_successor ;
- X node_s *last_predecessor ;
- X} ;
- X
- X#include "fsma.h"
- X
- Xstruct dll_iterator
- X{
- X node_s *next ;
- X enum dict_direction direction ;
- X} ;
- X
- Xstruct dll_header
- X{
- X struct dict_header dh ;
- X struct hints hint ;
- X fsma_h alloc ; /* FSM allocator */
- X node_s *head ;
- X struct dll_iterator iter ;
- X} ;
- X
- Xtypedef struct dll_header header_s ;
- X
- X#define DHP( hp ) (&(hp->dh))
- X#define LHP( p ) ((struct dll_header *) (p))
- X
- X#define HINT_CLEAR( hp, hint_name ) hp->hint.hint_name = hp->head
- X
- X
- END_OF_FILE
- if test 3016 -ne `wc -c <'libs/src/dict/dllimpl.h'`; then
- echo shar: \"'libs/src/dict/dllimpl.h'\" unpacked with wrong size!
- fi
- # end of 'libs/src/dict/dllimpl.h'
- fi
- if test -f 'libs/src/misc/env.3' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'libs/src/misc/env.3'\"
- else
- echo shar: Extracting \"'libs/src/misc/env.3'\" \(2942 characters\)
- sed "s/^X//" >'libs/src/misc/env.3' <<'END_OF_FILE'
- X.\"(c) Copyright 1992 by Panagiotis Tsirigotis
- X.\"All rights reserved. The file named COPYRIGHT specifies the terms
- X.\"and conditions for redistribution.
- X.\"
- X.\" $Id: env.3,v 1.1 1992/10/20 20:44:30 panos Exp $
- X.TH ENV 3L "20 October 1992"
- X.SH NAME
- Xenv_create, env_destroy, env_make, env_addvar, env_addstr, env_remvar, env_lookup, env_getvars -- environment manipulation functions
- X.SH SYNOPSIS
- X.LP
- X.nf
- X.ft B
- X#include "env.h"
- X.LP
- X.ft B
- Xenv_h env_create( env )
- Xenv_h env ;
- X.LP
- X.ft B
- Xvoid env_destroy( env )
- Xenv_h env ;
- X.LP
- X.ft B
- Xenv_h env_make( env_strings )
- Xchar **env_strings ;
- X.LP
- X.ft B
- Xint env_addvar( env, from_env, var )
- Xenv_h env ;
- Xenv_h from_env ;
- Xchar *var ;
- X.LP
- X.ft B
- Xint env_addstr( env, str )
- Xenv_h env ;
- Xchar *str ;
- X.LP
- X.ft B
- Xint env_remvar( env, var )
- Xenv_h env ;
- Xchar *var ;
- X.LP
- X.ft B
- Xchar **env_getvars( env )
- Xenv_h env ;
- X.SH DESCRIPTION
- XThis library handles environments. An environment is a set of strings
- Xof the form
- X.I "name=value".
- XIn the following, we will use the term string as a synonym of
- XNUL-terminated array of
- X.I char.
- X.LP
- X.B env_create()
- Xcreates a new environment. The new environment will be empty unless
- Xthe argument
- X.I env
- Xis not
- X.SB ENV_NULL.
- XIn that case, the new environment will be a duplicate of
- X.I env
- X(i.e. they will contain the same strings).
- X.LP
- X.B env_destroy()
- Xdestroys the specified environment.
- X.LP
- X.B env_make()
- Xcreates a new environment which includes the
- X.I env_strings.
- X.I env_strings
- Xshould be a NULL-terminated array of strings.
- X.LP
- X.B env_addvar()
- Xadds the specified variable
- X.I var
- Xto
- X.I env.
- XThe variable value is obtained from the environment
- X.I from_env.
- XIf the variable exists already in
- X.I env
- Xthe old value is replaced with the new value.
- X.LP
- X.B env_addstr()
- Xadds a string of the form
- X.I "name=value"
- Xto
- X.I env.
- X.LP
- X.B env_remvar()
- Xremoves the specified variable
- X.I var
- Xfrom the environment
- X.I env.
- X.LP
- X.B env_lookup()
- Xsearches
- X.I env
- Xfor variable
- X.I var.
- XIt returns a string of the form
- X.I "name=value"
- Xwhere
- X.I name
- Xis the name of the variable
- X(i.e. it is equal to
- X.I var).
- X.LP
- X.B env_getvars
- Xreturns a NULL-terminated array of strings of the form
- X.I "name=value".
- X.SH "RETURN VALUES"
- XIn case of error, all calls will place an error code in the global variable
- X.I env_errno.
- XPossible error codes:
- X.TP 15
- X.SB ENV_ENOMEM
- Xout of memory
- X.TP
- X.SB ENV_EBADVAR
- Xvariable is not in environment
- X.TP
- X.SB ENV_EBADSTRING
- Xstring is not well-formed (i.e. is not of the form \fIname=value\fR).
- X.LP
- X.B env_create()
- Xreturns a handle or
- X.SM ENV_NULL
- Xif it fails.
- X.LP
- X.B env_make()
- Xreturns a handle or
- X.SM ENV_NULL
- Xif it fails.
- X.LP
- X.B env_addvar()
- Xreturns
- X.SM ENV_OK
- Xon success or
- X.SM ENV_ERR
- Xon failure.
- X.LP
- X.B env_addstr()
- Xreturns
- X.SM ENV_OK
- Xon success or
- X.SM ENV_ERR
- Xon failure.
- X.LP
- X.B env_remvar()
- Xreturns
- X.SM ENV_OK
- Xon success or
- X.SM ENV_ERR
- Xif the variable is not part of the environment.
- X.LP
- X.B env_loopkup()
- Xreturns a string on success or
- X.SM NULL
- Xon failure.
- X.SH "SEE ALSO"
- Xenviron(5)
- END_OF_FILE
- if test 2942 -ne `wc -c <'libs/src/misc/env.3'`; then
- echo shar: \"'libs/src/misc/env.3'\" unpacked with wrong size!
- fi
- # end of 'libs/src/misc/env.3'
- fi
- if test -f 'libs/src/pset/pset.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'libs/src/pset/pset.h'\"
- else
- echo shar: Extracting \"'libs/src/pset/pset.h'\" \(3129 characters\)
- sed "s/^X//" >'libs/src/pset/pset.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#ifndef __PSET_H
- X#define __PSET_H
- X
- X/*
- X * $Id: pset.h,v 3.2 93/11/23 19:46:33 panos Exp $
- X */
- X
- Xtypedef void *__pset_pointer ;
- X
- Xstruct __pset
- X{
- X unsigned alloc_step ;
- X __pset_pointer *ptrs ;
- X unsigned max ;
- X unsigned count ;
- X} ;
- X
- X
- X/*
- X * INTERFACE
- 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
- Xtypedef struct __pset *pset_h ;
- X
- Xpset_h pset_create __ARGS( ( unsigned start, unsigned step ) ) ;
- Xvoid pset_destroy __ARGS( ( pset_h ) ) ;
- X
- X__pset_pointer pset_insert __ARGS( ( pset_h, __pset_pointer ) ) ;
- Xvoid pset_delete __ARGS( ( pset_h, __pset_pointer ) ) ;
- X
- Xvoid pset_compact __ARGS( ( pset_h ) ) ;
- Xvoid pset_uniq __ARGS( ( pset_h, void (*func)(), void *arg ) ) ;
- Xvoid pset_apply __ARGS( ( pset_h, void (*func)(), void *arg ) ) ;
- X
- X/*
- X * Macros
- X */
- X#define pset_add( pset, ptr ) \
- X ( \
- X ( (pset)->count < (pset)->max ) \
- X ? (pset)->ptrs[ (pset)->count++ ] = (__pset_pointer) ptr \
- X : pset_insert( (pset), (__pset_pointer) ptr ) \
- X )
- X
- X#define pset_remove( pset, ptr ) pset_delete( pset, (__pset_pointer)ptr )
- X
- X#define pset_remove_index( pset, i ) \
- X { \
- X if ( (i) < (pset)->count ) \
- X (pset)->ptrs[ i ] = (pset)->ptrs[ --(pset)->count ] ; \
- X }
- X
- X#define pset_clear( pset ) (pset)->count = 0
- X#define pset_count( pset ) (pset)->count
- X#define pset_pointer( pset, i ) (pset)->ptrs[ i ]
- X
- X#define pset_sort( pset, compfunc ) \
- X (void) qsort( (char *) &pset_pointer( pset, 0 ), \
- X pset_count( pset ), sizeof( __pset_pointer ), compfunc )
- X
- X/*
- X * PSET iterators
- X *
- X * Note that the iterators do NOT use any knowledge about the internals
- X * of pset's.
- X */
- Xstruct __pset_iterator
- X{
- X pset_h pset ;
- X unsigned current ;
- X int step ;
- X} ;
- X
- Xtypedef struct __pset_iterator *psi_h ;
- X
- X
- X#define __psi_current( iter ) \
- X ( (iter)->current < pset_count( (iter)->pset ) \
- X ? pset_pointer( (iter)->pset, (iter)->current ) \
- X : NULL )
- X
- X#define psi_start( iter ) \
- X ( (iter)->current = 0, (iter)->step = 1, \
- X __psi_current( iter ) )
- X
- X#define psi_next( iter ) \
- X ( (iter)->current += (iter)->step, (iter)->step = 1, \
- X __psi_current( iter ) )
- X
- X#define psi_remove( iter ) \
- X { \
- X if ( (iter)->current < pset_count( (iter)->pset ) ) \
- X { \
- X pset_remove_index( (iter)->pset, (iter)->current ) ; \
- X (iter)->step = 0 ; \
- X } \
- X }
- X
- X#define psi_reset( iter, newpset ) (iter)->pset = (newpset)
- X
- X#define psi_destroy( iter ) free( (char *) iter )
- X
- Xpsi_h psi_create __ARGS( ( pset_h ) ) ;
- X
- X#endif /* __PSET_H */
- X
- END_OF_FILE
- if test 3129 -ne `wc -c <'libs/src/pset/pset.h'`; then
- echo shar: \"'libs/src/pset/pset.h'\" unpacked with wrong size!
- fi
- # end of 'libs/src/pset/pset.h'
- fi
- if test -f 'libs/src/str/ss_impl.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'libs/src/str/ss_impl.h'\"
- else
- echo shar: Extracting \"'libs/src/str/ss_impl.h'\" \(2969 characters\)
- sed "s/^X//" >'libs/src/str/ss_impl.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#ifndef SS_IMPL_H
- X#define SS_IMPL_H
- X
- X/*
- X * $Id: ss_impl.h,v 3.2 1993/06/16 00:06:34 panos Exp $
- X */
- X
- X/*
- X * NBIC is the Number-of-Bits-In-a-Char
- X */
- X#ifndef NBIC
- X#define NBIC 8
- X#endif
- X
- X#define ALPHABET_SIZE ( 1 << NBIC )
- X
- X#ifndef WIDE_INT
- X#define WIDE_INT long
- X#define WIDE_INT_SIZE 32 /* bits */
- X#endif
- X
- Xtypedef WIDE_INT wide_int ;
- Xtypedef unsigned WIDE_INT u_wide_int ;
- X
- X
- X#include "ss_rk.h"
- X#include "ss_kmp.h"
- X#include "ss_sbm.h"
- X#include "ss_bmh.h"
- X#include "ss_so.h"
- X
- X#include "str.h"
- X
- Xstruct ss_ops
- X{
- X int (*so_setup)() ;
- X char *(*so_match)() ;
- X void (*so_done)() ;
- X} ;
- X
- X
- Xstruct ss_header
- X{
- X char *ss_pattern ;
- X int ss_patlen ;
- X int ss_flags ;
- X char *ss_map ; /* either identity or upper->lower */
- X struct ss_ops *ss_ops ;
- X union ss_headers
- X {
- X struct rk_header rkh ;
- X struct kmp_header kmph ;
- X struct sbm_header sbmh ;
- X struct bmh_header bmhh ;
- X struct so_header soh ;
- X } ss_h ;
- X} ;
- X
- Xtypedef struct ss_header header_s ;
- X
- X#define HP( p ) ((header_s *)(p))
- X
- X/*
- X * Structure field access
- X */
- X#define SS_PATTERN( hp ) (hp)->ss_pattern
- X#define SS_PATLEN( hp ) (hp)->ss_patlen
- X#define SS_FLAGS( hp ) (hp)->ss_flags
- X#define SS_OPS( hp ) (hp)->ss_ops
- X#define SS_SETMAP( hp, map ) (hp)->ss_map = map
- X#define SS_MAP( hp, c ) (hp)->ss_map[ (unsigned char) (c) ]
- X
- X/*
- X * Predicates
- X */
- X#define SS_MALLOC( hp ) ( ! ( SS_FLAGS( hp ) & STRS_NOMALLOC ) )
- X#define SS_IGNCASE( hp ) ( SS_FLAGS( hp ) & STRS_IGNCASE )
- X#define SS_SWITCH( hp ) ( ! ( SS_FLAGS( hp ) & STRS_NOSWITCH ) )
- X#define SS_SETMALLOC( hp ) SS_FLAGS( hp ) &= ~ STRS_NOMALLOC
- X
- X/*
- X * Indirect op invocation
- X */
- X#define SS_SETUP( hp ) (*SS_OPS( hp )->so_setup)( hp )
- X#define SS_MATCH( hp, str, len ) (*SS_OPS( hp )->so_match)( hp, str, len )
- X#define SS_DONE( hp ) (*SS_OPS( hp )->so_done)( hp )
- X
- X/*
- X * Header extraction
- X */
- X#define RK_HEADER( hp ) (&(hp)->ss_h.rkh)
- X#define KMP_HEADER( hp ) (&(hp)->ss_h.kmph)
- X#define SBM_HEADER( hp ) (&(hp)->ss_h.sbmh)
- X#define BMH_HEADER( hp ) (&(hp)->ss_h.bmhh)
- X#define SO_HEADER( hp ) (&(hp)->ss_h.soh)
- X
- X/*
- X * Macros to extract method and flags from the 'flags' argument
- X */
- X#define METHOD_BITS 5 /* flag bits devoted to methods */
- X#define METHOD_MASK ( ( 1 << METHOD_BITS ) - 1 )
- X#define SS_GETMETHOD( x ) ( (x) & METHOD_MASK )
- X#define SS_GETFLAGS( x ) ( (x) & ~METHOD_MASK )
- X
- X
- Xstruct ss_select
- X{
- X int sel_method ;
- X struct ss_ops *sel_ops ;
- X} ;
- X
- X
- X#ifndef NULL
- X#define NULL 0
- X#endif
- X
- X#ifndef FALSE
- X#define FALSE 0
- X#define TRUE 1
- X#endif
- X
- X#define CHAR_NULL ((char *)0)
- X#define NULL_HANDLE ((strs_h)0)
- X
- X#define PRIVATE static
- X
- X
- X/*
- X * Return values
- X */
- X#define SS_OK 0
- X#define SS_ERR (-1)
- X
- X#endif /* SS_IMPL_H */
- X
- END_OF_FILE
- if test 2969 -ne `wc -c <'libs/src/str/ss_impl.h'`; then
- echo shar: \"'libs/src/str/ss_impl.h'\" unpacked with wrong size!
- fi
- # end of 'libs/src/str/ss_impl.h'
- fi
- if test -f 'libs/src/str/ss_kmp.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'libs/src/str/ss_kmp.c'\"
- else
- echo shar: Extracting \"'libs/src/str/ss_kmp.c'\" \(2827 characters\)
- sed "s/^X//" >'libs/src/str/ss_kmp.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: ss_kmp.c,v 3.1 1993/06/13 02:44:39 panos Exp $" ;
- X
- Xchar *malloc() ;
- X
- X#include "ss_impl.h"
- X
- XPRIVATE int kmp_setup() ;
- XPRIVATE char *kmp_match() ;
- XPRIVATE void kmp_done() ;
- X
- Xstruct ss_ops __strs_kmpops = { kmp_setup, kmp_match, kmp_done } ;
- X
- X
- XPRIVATE void compute_next( hp )
- X header_s *hp ;
- X{
- X char *pattern = SS_PATTERN( hp ) ;
- X int patlen = SS_PATLEN( hp ) ;
- X next_int *next = KMP_HEADER( hp )->next ;
- X int q ;
- X next_int k ;
- X
- X k = next[ 0 ] = -1 ;
- X
- X for ( q = 0 ; q < patlen-1 ; )
- X {
- X /*
- X * The invariant of the following loop is:
- X * if k>=0, then
- X * pattern[ 0..k-1 ] SUFFIX pattern[ 0..q-1 ] ( <==> next[ q ] = k )
- X * This condition is true on entry to the loop.
- X */
- X while ( k >= 0 && pattern[ k ] != pattern[ q ] )
- X k = next[ k ] ;
- X
- X /*
- X * Case 1: k == -1
- X * Setting next[ q+1 ] = 0 is ok since it implies that the next
- X * position in the pattern to check is position 0 (i.e. start
- X * from the beginning).
- X * Case 2: k >= 0.
- X * Since we exited the loop, pattern[ k ] == pattern[ q ].
- X * Therefore,
- X * pattern[ 0..k ] SUFFIX pattern[ 0..q ] ==> next[ q+1 ] = k+1
- X */
- X k++, q++ ;
- X#ifdef PATH_COMPRESSION
- X if ( pattern[ k ] == pattern[ q ] )
- X next[ q ] = next[ k ] ;
- X#endif
- X next[ q ] = k ;
- X }
- X}
- X
- X
- XPRIVATE int kmp_setup( hp )
- X register header_s *hp ;
- X{
- X register next_int *next ;
- X
- X next = (next_int *) malloc( (unsigned)SS_PATLEN( hp )*sizeof( next_int ) ) ;
- X if ( next == (next_int *)0 )
- X return( SS_ERR ) ;
- X
- X KMP_HEADER( hp )->next = next ;
- X
- X compute_next( hp ) ;
- X
- X return( SS_OK ) ;
- X}
- X
- X
- XPRIVATE char *kmp_match( hp, str, len )
- X header_s *hp ;
- X char *str ;
- X int len ;
- X{
- X register int i ;
- X register next_int q ;
- X next_int *next = KMP_HEADER( hp )->next ;
- X char *pattern = SS_PATTERN( hp ) ;
- X register int patlen = SS_PATLEN( hp ) ;
- X
- X /*
- X * As a special case, we consider pattern[ -1..0 ] to be the empty string.
- X */
- X for ( q = 0, i = 0 ; i < len ; i++ )
- X {
- X register char current_char = SS_MAP( hp, str[ i ] ) ;
- X
- Xagain:
- X /*
- X * At this point:
- X * pattern[ 0..q-1 ] is a suffix of str[ 0..i-1 ]
- X */
- X if ( pattern[ q ] == current_char )
- X {
- X q++ ;
- X if ( q == patlen )
- X return( &str[ i - patlen + 1 ] ) ;
- X }
- X else
- X {
- X /*
- X * Let q' = next[ q ]. If q' >= 0, then
- X * pattern[ 0..q'-1 ] SUFFIX pattern[ 0..q-1 ]
- X * which implies that
- X * pattern[ 0..q'-1 ] SUFFIX str[ 0..i-1 ]
- X * Therefore, it is ok to set q = q'.
- X */
- X q = next[ q ] ;
- X if ( q >= 0 )
- X goto again ;
- X q++ ;
- X }
- X }
- X
- X return( CHAR_NULL ) ;
- X}
- X
- X
- XPRIVATE void kmp_done( hp )
- X header_s *hp ;
- X{
- X (void) free( (char *)KMP_HEADER( hp )->next ) ;
- X}
- X
- END_OF_FILE
- if test 2827 -ne `wc -c <'libs/src/str/ss_kmp.c'`; then
- echo shar: \"'libs/src/str/ss_kmp.c'\" unpacked with wrong size!
- fi
- # end of 'libs/src/str/ss_kmp.c'
- fi
- if test -f 'libs/src/str/ss_rk.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'libs/src/str/ss_rk.c'\"
- else
- echo shar: Extracting \"'libs/src/str/ss_rk.c'\" \(2625 characters\)
- sed "s/^X//" >'libs/src/str/ss_rk.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: ss_rk.c,v 3.1 1993/06/13 02:45:04 panos Exp $" ;
- X
- X#include "ss_impl.h"
- X
- X/*
- X * Multiply a number by the radix we are using
- X */
- X#define RADIX_MULT( n ) ( (n) << NBIC )
- X
- X#define UCHAR( c ) ((unsigned char)(c))
- X
- X
- XPRIVATE int rk_setup() ;
- XPRIVATE char *rk_match() ;
- XPRIVATE void rk_done() ;
- X
- Xstruct ss_ops __strs_rkops = { rk_setup, rk_match, rk_done } ;
- X
- X
- XPRIVATE int rk_setup( hp )
- X register header_s *hp ;
- X{
- X register int i ;
- X struct rk_header *rkp = RK_HEADER( hp ) ;
- X u_wide_int patval = 0 ;
- X u_wide_int digit_1 = 1 ;
- X
- X /*
- X * Compute pattern value
- X */
- X for ( i = 0 ; i < SS_PATLEN( hp ) ; i++ )
- X patval = ( RADIX_MULT( patval ) + UCHAR( SS_PATTERN( hp )[i] ) ) % PRIME ;
- X
- X for ( i = 0 ; i < SS_PATLEN( hp )-1 ; i++ )
- X digit_1 = RADIX_MULT( digit_1 ) % PRIME ;
- X
- X rkp->rk_patval = patval ;
- X rkp->rk_digit1 = digit_1 ;
- X return( SS_OK ) ;
- X}
- X
- X
- XPRIVATE void rk_done( hp )
- X header_s *hp ;
- X{
- X#ifdef lint
- X hp = hp ;
- X#endif
- X}
- X
- X
- XPRIVATE char *rk_match( hp, str, len )
- X register header_s *hp ;
- X char *str ;
- X int len ;
- X{
- X register int i ;
- X register unsigned char uc ;
- X register u_wide_int strval = 0 ;
- X register u_wide_int patval = RK_HEADER( hp )->rk_patval ;
- X register u_wide_int digit_1 = RK_HEADER( hp )->rk_digit1 ;
- X int patlen = SS_PATLEN( hp ) ;
- X char *endpat = &SS_PATTERN( hp )[ patlen ] ;
- X
- X /*
- X * Calculate initial value of 'str'
- X * Note that we are guaranteed that len >= pattern length
- X */
- X for ( i = 0 ; i < patlen ; i++ )
- X {
- X uc = UCHAR( SS_MAP( hp, str[i] ) ) ;
- X strval = ( RADIX_MULT( strval ) + uc ) % PRIME ;
- X }
- X
- X for ( i = 0 ;; i++ )
- X {
- X register u_wide_int t1 ;
- X
- X if ( strval == patval )
- X {
- X char *pp, *sp ;
- X
- X for ( pp = SS_PATTERN( hp ), sp = &str[i] ;; sp++, pp++ )
- X {
- X if ( pp == endpat )
- X return( &str[i] ) ;
- X if ( *pp != SS_MAP( hp, *sp ) )
- X break ;
- X }
- X }
- X
- X if ( i == len-patlen+1 )
- X break ;
- X
- X /*
- X * The formula we evaluate is:
- X *
- X * strval = ( RADIX_MULT( ( strval - UCHAR( str[i] )*digit_1 ) ) +
- X * UCHAR( str[i+patlen] ) ) % PRIME ;
- X *
- X * We have to make sure that the subtraction does not produce
- X * a negative number since that causes strval to be wrong.
- X */
- X uc = UCHAR( SS_MAP( hp, str[i] ) ) ;
- X t1 = ( uc * digit_1 ) % PRIME ;
- X if ( t1 > strval )
- X strval += PRIME ;
- X uc = UCHAR( SS_MAP( hp, str[i+patlen] ) ) ;
- X strval = ( RADIX_MULT( strval - t1 ) + uc ) % PRIME ;
- X }
- X return( NULL ) ;
- X}
- X
- X
- END_OF_FILE
- if test 2625 -ne `wc -c <'libs/src/str/ss_rk.c'`; then
- echo shar: \"'libs/src/str/ss_rk.c'\" unpacked with wrong size!
- fi
- # end of 'libs/src/str/ss_rk.c'
- fi
- if test -f 'libs/src/str/ss_so.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'libs/src/str/ss_so.c'\"
- else
- echo shar: Extracting \"'libs/src/str/ss_so.c'\" \(2898 characters\)
- sed "s/^X//" >'libs/src/str/ss_so.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: ss_so.c,v 3.1 1993/06/13 02:46:12 panos Exp $" ;
- X
- Xchar *malloc() ;
- X
- X#include "ss_impl.h"
- X
- XPRIVATE int so_setup() ;
- XPRIVATE char *so_match() ;
- XPRIVATE void so_done() ;
- X
- Xstruct ss_ops __strs_soops = { so_setup, so_match, so_done } ;
- X
- X/*
- X * There is a single twist in this implementation of the shift-or algorithm:
- X * To make the check for complete match faster, we are using the sign-bit
- X * of the word. This means that everything is shifted to the left by
- X * (word_size - pattern_length)
- X */
- X
- XPRIVATE int so_setup( hp )
- X header_s *hp ;
- X{
- X register wide_int *maskbuf ;
- X register wide_int mask ;
- X register wide_int offset_mask ;
- X register int i ;
- X int offset ;
- X register int patlen = SS_PATLEN( hp ) ;
- X register char *pattern = SS_PATTERN( hp ) ;
- X
- X if ( patlen > WIDE_INT_SIZE )
- X return( SS_ERR ) ;
- X
- X maskbuf = (wide_int *) malloc( ALPHABET_SIZE * sizeof( wide_int ) ) ;
- X if ( maskbuf == (wide_int *)NULL )
- X return( SS_ERR ) ;
- X
- X offset = WIDE_INT_SIZE - patlen ;
- X offset_mask = ( (~0) << offset ) ;
- X
- X /*
- X * The bits of each word that won't be used must be set to 0
- X */
- X for ( i = 0 ; i < ALPHABET_SIZE ; i++ )
- X maskbuf[ i ] = offset_mask ;
- X
- X for ( i = 0, mask = 1 << offset ; i < patlen ; i++, mask <<= 1 )
- X maskbuf[ (unsigned char) pattern[ i ] ] &= ~mask ;
- X
- X SO_HEADER( hp )->mask = maskbuf ;
- X SO_HEADER( hp )->offset_mask = offset_mask ;
- X return( SS_OK ) ;
- X}
- X
- X
- XPRIVATE char *so_match( hp, str, len )
- X register header_s *hp ;
- X char *str ;
- X int len ;
- X{
- X register char *p ;
- X register char pfc = SS_PATTERN( hp )[ 0 ] ;
- X register wide_int *mask = SO_HEADER( hp )->mask ;
- X register char *endmatch = &str[ len - SS_PATLEN( hp ) + 1 ] ;
- X char *endstr = &str[ len ] ;
- X wide_int no_match_state = ~0 & SO_HEADER( hp )->offset_mask ;
- X
- X /*
- X * The shift-or algorithm can be described by the following for-loop:
- X *
- X * for ( p = str ; p < endstr ; p++ )
- X * {
- X * state = ( state << 1 ) | mask[ (unsigned char) SS_MAP( hp, *p ) ] ;
- X * if ( state >= 0 )
- X * return( &p[ -SS_PATLEN( hp ) + 1 ] ) ;
- X * }
- X *
- X * For efficiency reasons, the algorithm is used only after the first
- X * character of the pattern is matched against a character of the string.
- X */
- X
- X for ( p = str ; p < endmatch ; p++ )
- X {
- X register wide_int state ;
- X
- X if ( SS_MAP( hp, *p ) != pfc )
- X continue ;
- X
- X for ( state = no_match_state ; p < endstr ; p++ )
- X {
- X state = ( state << 1 ) | mask[ (unsigned char) SS_MAP( hp, *p ) ] ;
- X if ( state >= 0 )
- X return( &p[ -SS_PATLEN( hp ) + 1 ] ) ;
- X if ( state == no_match_state )
- X break ;
- X }
- X }
- X return( CHAR_NULL ) ;
- X}
- X
- X
- XPRIVATE void so_done( hp )
- X header_s *hp ;
- X{
- X (void) free( (char *) SO_HEADER( hp )->mask ) ;
- X}
- X
- END_OF_FILE
- if test 2898 -ne `wc -c <'libs/src/str/ss_so.c'`; then
- echo shar: \"'libs/src/str/ss_so.c'\" unpacked with wrong size!
- fi
- # end of 'libs/src/str/ss_so.c'
- fi
- if test -f 'libs/src/str/strprint.3' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'libs/src/str/strprint.3'\"
- else
- echo shar: Extracting \"'libs/src/str/strprint.3'\" \(3148 characters\)
- sed "s/^X//" >'libs/src/str/strprint.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: strprint.3,v 3.1 1993/06/13 02:48:55 panos Exp $
- X.TH STRPRINT 3X "30 September 1992"
- X.SH NAME
- Xstr_sprint, tr_sprintv, str_nprint, str_nprintv, str_print, str_printv, strx_sprint, strx_sprintv, strx_nprint, strx_nprintv, strx_print, strx_printv -- formatted conversion to string
- X.SH SYNOPSIS
- X.LP
- X.nf
- X.ft B
- X#include "str.h"
- X.LP
- X.ft B
- Xchar *str_sprint( buf, format, ... )
- Xchar *buf ;
- Xchar *format ;
- X.LP
- X.ft B
- Xchar *str_sprintv( buf, format, ap )
- Xchar *buf ;
- Xchar *format ;
- Xva_list ap ;
- X.LP
- X.ft B
- Xint str_nprint( buf, format, ... )
- Xchar *buf ;
- Xchar *format ;
- X.LP
- X.ft B
- Xint str_nprintv( buf, format, ap )
- Xchar *buf ;
- Xchar *format ;
- Xva_list ap ;
- X.LP
- X.ft B
- Xvoid str_print( countp, buf, format, ... )
- Xint *countp ;
- Xchar *buf ;
- Xchar *format ;
- X.LP
- X.ft B
- Xvoid str_printv( countp, buf, format, ap )
- Xint *countp ;
- Xchar *buf ;
- Xchar *format ;
- Xva_list ap ;
- X.LP
- X.ft B
- Xchar *strx_sprint( buf, len, format, ... )
- Xchar *buf ;
- Xint len ;
- Xchar *format ;
- X.LP
- X.ft B
- Xchar *strx_sprintv( buf, len, format, ap )
- Xchar *buf ;
- Xint len ;
- Xchar *format ;
- Xva_list ap ;
- X.LP
- X.ft B
- Xint strx_nprint( buf, len, format, ... )
- Xchar *buf ;
- Xint len ;
- Xchar *format ;
- X.LP
- X.ft B
- Xint strx_nprintv( buf, len, format, ap )
- Xchar *buf ;
- Xint len ;
- Xchar *format ;
- Xva_list ap ;
- X.LP
- X.ft B
- Xvoid strx_print( countp, buf, len, format, ... )
- Xint *countp ;
- Xchar *buf ;
- Xint len ;
- Xchar *format ;
- X.LP
- X.ft B
- Xvoid strx_printv( countp, buf, len, format, ap )
- Xint *countp ;
- Xchar *buf ;
- Xint len ;
- Xchar *format ;
- Xva_list ap ;
- X.SH DESCRIPTION
- X.LP
- XAll functions are similar in functionality to \fIsprintf()\fR.
- XTheir only difference is in their return values. For information about their
- Xconversion capabilities, check \fISprint(3)\fR.
- X.LP
- XThe difference between the \fIstr_*\fR and the \fIstrx_*\fR functions
- Xis that the latter take an extra argument, the size of the buffer, so
- Xthat they will never write beyond the end of the buffer. Writing
- Xbeyond the end of the buffer is possible with the \fIstr_*\fR functions.
- XInvoking any of the \fIstrx_*\fR functions with the
- X.I len
- Xargument set to 0
- Xis the same as calling the equivalent \fIstr_*\fR function.
- X.LP
- XAll functions will append a
- X.SM NUL
- Xat the end of
- X.I buf
- X(the \fIstrx_*\fR functions will not do this if it would cause
- Xa buffer overrun).
- X.LP
- X.B str_print(),
- X.B str_printv(),
- X.B strx_print(),
- Xand
- X.B strx_printv()
- Xwill put in
- X.I "*countp"
- Xthe number of characters placed in
- X.I buf
- Xexcluding the ending
- X.SM NUL
- X(this happens only if
- X.I "*countp"
- Xis not
- X.SM NULL
- X).
- X.LP
- XThe functions that have a name ending in 'v' are similar to those without
- Xthe 'v' at the end of their name
- Xexcept that instead of accepting a variable number of arguments, they
- Xexpect a \fIvarargs(3)\fR argument list.
- X.SH "RETURN VALUES"
- X.LP
- X.B str_sprint(),
- X.B str_sprintv(),
- X.B strx_sprint(),
- Xand
- X.B strx_sprintv()
- Xreturn
- X.I buf.
- X.LP
- X.B str_nprint(),
- X.B str_nprintv(),
- X.B strx_nprint(),
- Xand
- X.B strx_nprintv()
- Xreturn the number of characters placed in
- X.I buf
- Xexcluding the ending
- X.SM NUL.
- X.SH "SEE ALSO"
- XSprint(3)
- END_OF_FILE
- if test 3148 -ne `wc -c <'libs/src/str/strprint.3'`; then
- echo shar: \"'libs/src/str/strprint.3'\" unpacked with wrong size!
- fi
- # end of 'libs/src/str/strprint.3'
- fi
- if test -f 'libs/src/xlog/impl.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'libs/src/xlog/impl.h'\"
- else
- echo shar: Extracting \"'libs/src/xlog/impl.h'\" \(2862 characters\)
- sed "s/^X//" >'libs/src/xlog/impl.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/*
- X * $Id: impl.h,v 2.1 1993/05/06 07:40:05 panos Exp $
- X */
- X
- X
- X#define DEFINE_LINK_TYPE( type, name ) struct { type *next, *prev ; } name
- X
- X
- X#define NEXT( obj, field ) (obj)->field.next
- X#define PREV( obj, field ) (obj)->field.prev
- X
- X#define INIT_LINKS( obj, field ) \
- X { \
- X NEXT( obj, field ) = obj ; \
- X PREV( obj, field ) = obj ; \
- X }
- X
- X/*
- X * Link new object after object using the specified field
- X */
- X#define LINK( obj, new_obj, field ) \
- X { \
- X NEXT( new_obj, field ) = NEXT( obj, field ) ; \
- X PREV( new_obj, field ) = obj ; \
- X NEXT( obj, field ) = new_obj ; \
- X PREV( NEXT( obj, field ), field ) = new_obj ; \
- X }
- X
- X#define UNLINK( obj, field ) \
- X { \
- X NEXT( PREV( obj, field ), field ) = NEXT( obj, field ) ; \
- X PREV( NEXT( obj, field ), field ) = PREV( obj, field ) ; \
- X }
- X
- X
- X/*
- X * xlog linking:
- X * When xlog1 is linked to xlog2 (i.e. errors on xlog1 are reported to
- X * xlog2) we use the xl_clients field on xlog2 and the xl_other_users
- X * field on xlog1
- X */
- Xstruct xlog
- X{
- X xlog_e xl_type ;
- X char *xl_id ;
- X int xl_flags ;
- X void (*xl_callback)() ;
- X void *xl_callback_arg ;
- X struct xlog *xl_use ; /* xlog we report errors to */
- X struct xlog *xl_clients ; /* linked list of xlogs that use */
- X /* this xlog to report errors */
- X DEFINE_LINK_TYPE( struct xlog, xl_other_users ) ;
- X struct xlog_ops
- X {
- X int (*init) __ARGS( ( struct xlog *, va_list ) ) ;
- X void (*fini) __ARGS( ( struct xlog * ) ) ;
- X int (*write) __ARGS( ( struct xlog *, char *, int, int, va_list ) ) ;
- X int (*control) __ARGS( ( struct xlog *, xlog_cmd_e, va_list ) ) ;
- X int (*parms) __ARGS( ( va_list ) ) ;
- X } *xl_ops ;
- X void *xl_data ;
- X} ;
- X
- X#define XL_INIT( xp, ap ) (*(xp)->xl_ops->init)( (xp), (ap) )
- X#define XL_FINI( xp ) (*(xp)->xl_ops->fini)( xp )
- X#define XL_WRITE( xp, buf, size, flags, ap ) \
- X (*(xp)->xl_ops->write)( (xp), (buf), (size), (flags), (ap ) )
- X#define XL_CONTROL( xp, cmd, ap ) \
- X (*(xp)->xl_ops->control)( (xp), (cmd), (ap) )
- X
- Xtypedef struct xlog xlog_s ;
- X
- Xtypedef void (*voidfunc)() ;
- Xtypedef int bool_int ;
- X
- X#define XP( p ) ((struct xlog *)(p))
- X
- X#define XLOG_NULL XP( NULL )
- X
- X#ifndef FALSE
- X#define FALSE 0
- X#define TRUE 1
- X#endif
- X
- X#ifndef NULL
- X#define NULL 0
- X#endif
- X
- X#define NEW( type ) (type *) malloc( sizeof( type ) )
- X#define FREE( p ) (void) free( (char *)p )
- X
- X#define PRIVATE static
- X
- Xchar *__xlog_add_errno() ;
- Xchar *__xlog_explain_errno() ;
- Xchar *__xlog_new_string() ;
- X
- Xchar *malloc() ;
- X
- END_OF_FILE
- if test 2862 -ne `wc -c <'libs/src/xlog/impl.h'`; then
- echo shar: \"'libs/src/xlog/impl.h'\" unpacked with wrong size!
- fi
- # end of 'libs/src/xlog/impl.h'
- fi
- echo shar: End of archive 5 \(of 20\).
- cp /dev/null ark5isdone
- 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
-