home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-11-28 | 31.0 KB | 1,240 lines |
- Newsgroups: comp.sources.unix
- From: panos@anchor.cs.colorado.edu (Panos Tsirigotis)
- Subject: v27i115: clc - C Libraries Collection, Part09/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 115
- Archive-Name: clc/part09
-
- #! /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 9 (of 20)."
- # Contents: libs/src/dict/bstimpl.h libs/src/sio/Makefile
- # libs/src/sio/suite/copytest.c libs/src/str/Makefile
- # libs/src/str/strparse.c libs/src/str/strs.3
- # Wrapped by panos@eclipse on Sun Nov 28 14:48:16 1993
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'libs/src/dict/bstimpl.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'libs/src/dict/bstimpl.h'\"
- else
- echo shar: Extracting \"'libs/src/dict/bstimpl.h'\" \(4198 characters\)
- sed "s/^X//" >'libs/src/dict/bstimpl.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: bstimpl.h,v 3.4 93/11/19 20:03:23 panos Exp $
- X */
- X
- X#include "dictimpl.h"
- X#include "bst.h"
- X
- X/*
- X * We allocate a tree_node or a balanced_tree_node depending on the type
- X * of tree. The code requires that both node types have the same memory
- X * representation (except for the extra field(s) at the end of the
- X * balanced_tree_node).
- X */
- Xstruct tree_node
- X{
- X struct tree_node *left ;
- X struct tree_node *right ;
- X struct tree_node *parent ;
- X dict_obj obj ;
- X} ;
- X
- Xtypedef struct tree_node tnode_s ;
- X
- X#define TNP( p ) ((tnode_s *)(p))
- X#define NULL_NODE TNP( NULL )
- X
- X#define LEFT( p ) (p)->left
- X#define RIGHT( p ) (p)->right
- X#define PARENT( p ) (p)->parent
- X#define OBJ( p ) (p)->obj
- X
- Xenum node_color { RED, BLACK } ;
- X
- Xstruct balanced_tree_node
- X{
- X tnode_s node ;
- X enum node_color color ;
- X} ;
- X
- Xtypedef struct balanced_tree_node btnode_s ;
- X
- X#define BTNP( p ) ((btnode_s *)(p))
- X
- X#define COLOR( p ) BTNP(p)->color
- X
- X
- X/*
- X * ABOUT HINTS:
- X * a. We keep hints to avoid searches of the tree.
- X * b. A hint is either correct or non-existent.
- X * c. To avoid bad hints, bst_delete clears all hints
- X * d. 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 tnode_s *last_search ;
- X tnode_s *last_successor ;
- X tnode_s *last_predecessor ;
- X} ;
- X
- X
- X#define HINT_GET( hp, hintname ) (hp)->hint.hintname
- X#define HINT_SET( hp, hintname, v ) (hp)->hint.hintname = v
- X#define HINT_CLEAR( hp, hintname ) HINT_SET( hp, hintname, NIL( hp ) )
- X#define HINT_MATCH( hp, hintname, v ) ( OBJ( (hp)->hint.hintname ) == v )
- X
- X
- X#include "fsma.h"
- X
- Xstruct tree_iterator
- X{
- X enum dict_direction direction ;
- X tnode_s *next ;
- X} ;
- X
- X
- X/*
- X * The 'nil' field is used instead of NULL, to indicate the absence of
- X * a node. This allows us to avoid explicit tests against NULL in case
- X * of boundary conditions.
- X *
- X * The only unusual thing in this implementation is the 'anchor' field
- X * which is used as the actual root of the tree. The user-visible root of
- X * the tree is always the *left* child of the anchor. The TREE_EMPTY macro
- X * below tests this condition.
- X */
- Xstruct tree_header
- X{
- X dheader_s dh ;
- X struct hints hint ;
- X fsma_h alloc ;
- X btnode_s anchor ;
- X btnode_s nil ;
- X struct tree_iterator iter ;
- X} ;
- X
- Xtypedef struct tree_header header_s ;
- X
- X#define THP( p ) ((header_s *)(p))
- X#define DHP( hp ) (&(hp->dh))
- X#define NULL_HEADER THP( NULL )
- X
- X#define ANCHOR( hp ) TNP( (&(hp)->anchor) )
- X#define ROOT( hp ) LEFT( ANCHOR( hp ) )
- X#define NIL( hp ) TNP( (&(hp)->nil) )
- X
- X#define TREE_EMPTY( hp ) ( ROOT( hp ) == NIL( hp ) )
- X
- X#define NODE_ALLOC( hp ) TNP( fsm_alloc( (hp)->alloc ) )
- X#define NODE_FREE( hp, np ) fsm_free( (hp)->alloc, (char *)(np) )
- X
- Xvoid __dict_rbt_insfix() ;
- Xvoid __dict_rbt_delfix() ;
- X
- END_OF_FILE
- if test 4198 -ne `wc -c <'libs/src/dict/bstimpl.h'`; then
- echo shar: \"'libs/src/dict/bstimpl.h'\" unpacked with wrong size!
- fi
- # end of 'libs/src/dict/bstimpl.h'
- fi
- if test -f 'libs/src/sio/Makefile' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'libs/src/sio/Makefile'\"
- else
- echo shar: Extracting \"'libs/src/sio/Makefile'\" \(4242 characters\)
- sed "s/^X//" >'libs/src/sio/Makefile' <<'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#
- X# $Id: Makefile,v 8.7 1993/09/08 05:57:40 panos Exp $
- X#
- X# Based on Library makefile template: *Revision: 1.15 *
- X#
- X
- X#
- X# Available entries:
- X# lib --> creates the library
- X# install --> installs the library (archive, man page(s), header(s))
- X# uninstall --> uninstall the library
- X# clean --> removes all .o and .a files
- X# spotless --> clean + uninstall
- X# lint --> lints a file (usage: make lint MODULE=foo.c)
- X# tags --> creates a tags file (from the SOURCES and HEADERS)
- X# checkout --> checkout all files
- X# dist --> distribution support
- X#
- X
- XNAME = sio
- XVERSION = 1.6.3
- X
- XHEADERS = sio.h impl.h events.h sioconf.h
- XSOURCES = sprint.c sio.c siosup.c
- XOBJECTS = sprint.o sio.o siosup.o
- X
- XMANFILES = sio.3 Sprint.3
- XINCLUDEFILES = sio.h
- X
- X# The following variables are used by the 'install' entry and
- X# should be customized:
- X# LIBDIR: where the library will be placed
- X# INCUDEDIR: where the include files will be placed
- X# MANDIR: where the man pages will be placed
- X#
- XLIBDIR = $(HOME)/.links/libraries/$(ARCH)
- XINCLUDEDIR = $(HOME)/.links/includes
- XMANDIR = $(HOME)/.links/manpages/man3
- X
- X#
- X# Available flags:
- X# -DDEBUG : enables assertions in the code. A failed assertion
- X# terminates the program
- X# -DEVENTS : enables code that records events (currently limited
- X# to which functions have been called on a given fd)
- X# and code that accesses the event buffers.
- X# -DLITTLE_ENDIAN : says that the machine is a little endian. This is
- X# needed if you enable EVENTS and your machine is a
- X# little endian (big endian is the default).
- X#
- X
- X#
- X# DEFS should be set from the command line; the current group of defs
- X# is for SunOS 4.x
- X#
- XDEFS = -DHAS_MMAP -DHAS_ONEXIT -DHAS_MEMOPS -DHAS_ISATTY
- X
- XDEBUG = -g # -g or -O
- XVERSION_DEF = -DVERSION=\"SIO\ Version\ $(VERSION)\"
- X
- XCPP_DEFS = $(VERSION_DEF) $(DEFS)
- X
- X#
- X# The following variables shouldn't need to be changed
- X#
- XLINT_FLAGS = -hbux
- XCPP_FLAGS = $(CPP_DEFS)
- XCC_FLAGS = $(DEBUG)
- XCFLAGS = $(CPP_FLAGS) $(CC_FLAGS)
- X
- XINSTALL = install -c
- XFMODE = -m 640 # used by install
- XRANLIB = ranlib
- X
- XPAGER = less
- X
- X
- XLIBNAME = lib$(NAME).a
- X
- Xlib: $(LIBNAME)
- X
- Xlibopt: clean
- X make DEBUG=-O "DEFS=$(DEFS)" lib
- X $(INSTALL) $(FMODE) $(LIBNAME) $(LIBDIR)/optimized
- X
- X$(LIBNAME): $(OBJECTS)
- X ar r $@ $?
- X $(RANLIB) $@
- X
- Xlint:
- X lint $(CPP_FLAGS) $(LINT_FLAGS) $(MODULE) 2>&1 | $(PAGER)
- X
- Xinstall: $(LIBNAME)
- X @if test "$(LIBDIR)" -a "$(INCLUDEDIR)" -a "$(MANDIR)" ;\
- X then \
- X $(INSTALL) $(FMODE) $(LIBNAME) $(LIBDIR) ;\
- X echo "Installed $(LIBNAME) to $(LIBDIR)" ;\
- X for i in $(INCLUDEFILES); do $(INSTALL) $(FMODE) $$i $(INCLUDEDIR) ; done ;\
- X echo Installed $(INCLUDEFILES) to $(INCLUDEDIR) ;\
- X for i in $(MANFILES) ; do $(INSTALL) $(FMODE) $$i $(MANDIR) ; done ;\
- X echo Installed $(MANFILES) to $(MANDIR) ;\
- X else \
- X echo "You forgot to set one of the following variables: LIBDIR,INCLUDEDIR,MANDIR" ;\
- X fi
- X
- Xuninstall:
- X a=`pwd` ; cd $(INCLUDEDIR) ;\
- X if test $$a != `pwd` ; then rm -f $(INCLUDEFILES) ; fi
- X a=`pwd` ; cd $(LIBDIR) ;\
- X if test $$a != `pwd` ; then rm -f $(LIBNAME) ; fi
- X a=`pwd` ; cd $(MANDIR) ;\
- X if test $$a != `pwd` ; then rm -f $(MANFILES) ; fi
- X
- Xclean:
- X rm -f $(OBJECTS) $(LIBNAME) core
- X
- Xspotless: clean uninstall
- X
- Xtags: $(SOURCES) $(HEADERS)
- X ctags -w $(SOURCES) $(HEADERS)
- X
- Xcheckout:
- X co $(SOURCES) $(HEADERS) $(MANFILES)
- X
- X#
- X# Distribution section
- X# This section contains the 2 targets for distribution support: dist, dirs
- X# "dist" checks out all files to be distributed
- X# "dirs" prints a list of directories to be included in the distribution.
- X# These directories should have a Makefile with a "dist" target
- X#
- XDISTRIBUTION_FILES = $(HEADERS) $(SOURCES) $(MANFILES) README COPYRIGHT
- XDIRS = suite
- X
- Xdist:
- X -co -q $(DISTRIBUTION_FILES)
- X
- Xdirs:
- X @echo $(DIRS)
- X
- X#
- X# PUT HERE THE RULES TO MAKE THE OBJECT FILES
- X#
- Xsprint.o: sio.h impl.h sioconf.h
- Xsio.o: sio.h impl.h sioconf.h events.h
- Xsiosup.o: sio.h impl.h sioconf.h events.h
- X
- END_OF_FILE
- if test 4242 -ne `wc -c <'libs/src/sio/Makefile'`; then
- echo shar: \"'libs/src/sio/Makefile'\" unpacked with wrong size!
- fi
- # end of 'libs/src/sio/Makefile'
- fi
- if test -f 'libs/src/sio/suite/copytest.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'libs/src/sio/suite/copytest.c'\"
- else
- echo shar: Extracting \"'libs/src/sio/suite/copytest.c'\" \(4308 characters\)
- sed "s/^X//" >'libs/src/sio/suite/copytest.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: copytest.c,v 8.2 1993/09/08 05:59:46 panos Exp $" ;
- X
- X#include "sio.h"
- X#include <stdio.h>
- X#include <syscall.h>
- X
- X#ifndef RANDOM
- X#define RANDOM random
- X#endif
- X
- X
- X/*************************************************************/
- X
- X#ifdef TEST_Sread
- X
- X#define BUFFER_SIZE 4096
- X
- Xmain()
- X{
- X char buf[ BUFFER_SIZE ] ;
- X int cc ;
- X int nbytes ;
- X
- X for ( ;; )
- X {
- X nbytes = RANDOM() & ( BUFFER_SIZE - 1 ) ;
- X if ( nbytes == 0 )
- X nbytes = 1 ;
- X cc = Sread( 0, buf, nbytes ) ;
- X if ( cc == 0 )
- X break ;
- X if ( cc == SIO_ERR )
- X exit( 1 ) ;
- X write( 1, buf, cc ) ;
- X }
- X exit( 0 ) ;
- X}
- X#endif /* TEST_Sread */
- X
- X/*************************************************************/
- X
- X#ifdef TEST_Swrite
- X
- X#define BUFFER_SIZE 4096
- X
- Xmain()
- X{
- X char buf[ BUFFER_SIZE ] ;
- X int cc ;
- X int nbytes ;
- X
- X for ( ;; )
- X {
- X nbytes = RANDOM() & ( BUFFER_SIZE - 1 ) ;
- X if ( nbytes == 0 )
- X nbytes = 1 ;
- X cc = read( 0, buf, nbytes ) ;
- X if ( cc == 0 )
- X break ;
- X if ( Swrite( 1, buf, cc ) != cc )
- X exit( 1 ) ;
- X }
- X exit( 0 ) ;
- X}
- X#endif /* TEST_Swrite */
- X
- X/*************************************************************/
- X
- X#ifdef TEST_Srdline
- X
- Xmain()
- X{
- X char *s ;
- X int count=0 ;
- X
- X while ( s = Srdline( 0 ) )
- X {
- X puts( s ) ;
- X count++ ;
- X }
- X Sdone( 0 ) ;
- X exit( 0 ) ;
- X}
- X
- X#endif /* TEST_Srdline */
- X
- X/*************************************************************/
- X
- X#ifdef TEST_Sputchar
- X
- Xmain()
- X{
- X int c ;
- X
- X while ( ( c = getchar() ) != EOF )
- X if ( Sputchar( 1, c ) != c )
- X exit( 1 ) ;
- X exit( 0 ) ;
- X}
- X
- X#endif /* TEST_Sputchar */
- X
- X/*************************************************************/
- X
- X#ifdef TEST_Sgetchar
- X
- Xmain()
- X{
- X int c ;
- X
- X while ( ( c = Sgetchar( 0 ) ) != SIO_EOF )
- X putchar( c ) ;
- X exit( 0 ) ;
- X}
- X
- X#endif /* TEST_Sgetchar */
- X
- X/*************************************************************/
- X
- X#ifdef TEST_Sputc
- X
- Xmain()
- X{
- X int c ;
- X
- X while ( ( c = getchar() ) != EOF )
- X if ( Sputc( 1, c ) != c )
- X exit( 1 ) ;
- X exit( 0 ) ;
- X}
- X
- X#endif /* TEST_Sputc */
- X
- X/*************************************************************/
- X
- X#ifdef TEST_Sgetc
- X
- Xmain()
- X{
- X int c ;
- X
- X while ( ( c = Sgetc( 0 ) ) != SIO_EOF )
- X putchar( c ) ;
- X exit( 0 ) ;
- X}
- X
- X#endif /* TEST_Sgetc */
- X
- X/*************************************************************/
- X
- X#ifdef TEST_Sfetch
- X
- Xmain()
- X{
- X char *s ;
- X int len ;
- X
- X while ( s = Sfetch( 0, &len ) )
- X fwrite( s, 1, len, stdout ) ;
- X exit( 0 ) ;
- X}
- X
- X#endif /* TEST_Sfetch */
- X
- X/*************************************************************/
- X
- X#ifdef TEST_Sflush
- X
- X#define MAX_COUNT 100
- X
- Xmain()
- X{
- X int c ;
- X int errval ;
- X int count = 0 ;
- X int max_count = RANDOM() % MAX_COUNT + 1 ;
- X
- X while ( ( c = getchar() ) != EOF )
- X if ( Sputchar( 1, c ) != c )
- X exit( errval ) ;
- X else
- X {
- X count++ ;
- X if ( count >= max_count )
- X {
- X errval = Sflush( 1 ) ;
- X if ( errval != 0 )
- X exit( 1 ) ;
- X max_count = RANDOM() % MAX_COUNT + 1 ;
- X count = 0 ;
- X }
- X }
- X exit( 0 ) ;
- X}
- X
- X#endif /* TEST_Sflush */
- X
- X/*************************************************************/
- X
- X#ifdef TEST_Sundo
- X
- Xmain()
- X{
- X int c ;
- X char *s ;
- X int errval ;
- X
- X for ( ;; )
- X {
- X if ( RANDOM() % 1 )
- X {
- X s = Srdline( 0 ) ;
- X if ( s == NULL )
- X break ;
- X if ( RANDOM() % 16 < 5 )
- X {
- X errval = Sundo( 0, SIO_UNDO_LINE ) ;
- X if ( errval == SIO_ERR )
- X exit( 1 ) ;
- X }
- X else
- X puts( s ) ;
- X }
- X else
- X {
- X c = Sgetchar( 0 ) ;
- X if ( c == SIO_EOF )
- X break ;
- X if ( RANDOM() % 16 < 5 )
- X {
- X errval = Sundo( 0, SIO_UNDO_CHAR ) ;
- X if ( errval == SIO_ERR )
- X exit( 2 ) ;
- X }
- X else
- X putchar( c ) ;
- X }
- X }
- X exit( 0 ) ;
- X}
- X
- X#endif /* TEST_Sundo */
- X
- X
- X#if defined( TEST_switch ) || defined( TEST_switch2 )
- X
- Xmain()
- X{
- X int c ;
- X char *s ;
- X int lines = 4000 ;
- X
- X for ( ;; )
- X {
- X c = Sgetchar( 0 ) ;
- X if ( c == SIO_EOF )
- X exit( 0 ) ;
- X if ( c == SIO_ERR )
- X exit( 1 ) ;
- X putchar( c ) ;
- X if ( c == '\n' )
- X {
- X lines-- ;
- X if ( lines == 0 )
- X break ;
- X }
- X }
- X while ( s = Srdline( 0 ) )
- X puts( s ) ;
- X exit( 0 ) ;
- X}
- X
- X#ifdef TEST_switch2
- X
- Xchar *mmap( addr, len, prot, type, fd, off )
- X char *addr ;
- X int len, prot, type, fd, off ;
- X{
- X return( (char *)-1 ) ;
- X}
- X
- X#endif /* TEST_switch2 */
- X
- X#endif /* TEST_switch */
- X
- X
- X
- END_OF_FILE
- if test 4308 -ne `wc -c <'libs/src/sio/suite/copytest.c'`; then
- echo shar: \"'libs/src/sio/suite/copytest.c'\" unpacked with wrong size!
- fi
- # end of 'libs/src/sio/suite/copytest.c'
- fi
- if test -f 'libs/src/str/Makefile' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'libs/src/str/Makefile'\"
- else
- echo shar: Extracting \"'libs/src/str/Makefile'\" \(4534 characters\)
- sed "s/^X//" >'libs/src/str/Makefile' <<'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#
- X# $Id: Makefile,v 3.3 1993/11/12 20:15:25 panos Exp $
- X#
- X# Based on Library makefile template: *Revision: 1.15 *
- X#
- X
- X#
- X# Available entries:
- X# lib --> creates the library
- X# install --> installs the library (archive, man page(s), header(s))
- X# uninstall --> uninstall the library
- X# clean --> removes all .o and .a files
- X# spotless --> clean + uninstall
- X# lint --> lints a file (usage: make lint MODULE=foo.c)
- X# tags --> creates a tags file (from the SOURCES and HEADERS)
- X# checkout --> checkout all files
- X# dist --> distribution support
- X#
- X
- XNAME = str
- XVERSION = 1.4.2
- X
- XHEADERS = str.h strparse.h \
- X ss_impl.h ss_rk.h ss_kmp.h ss_sbm.h ss_bmh.h ss_so.h
- XSOURCES = strutil.c strprint.c strparse.c strs.c \
- X ss_rk.c ss_kmp.c ss_bf.c ss_sbm.c ss_bmh.c ss_so.c
- XOBJECTS = strutil.o strprint.o strparse.o strs.o \
- X ss_rk.o ss_kmp.o ss_bf.o ss_sbm.o ss_bmh.o ss_so.o
- X
- XMANFILES = strparse.3 strprint.3 strutil.3 strs.3
- XINCLUDEFILES = str.h
- X
- X# The following variables are used by the 'install' entry and
- X# should be customized:
- X# LIBDIR: where the library will be placed
- X# INCUDEDIR: where the include files will be placed
- X# MANDIR: where the man pages will be placed
- X#
- XLIBDIR = $(HOME)/.links/libraries/$(ARCH)
- XMANDIR = $(HOME)/.links/manpages/man3
- XINCLUDEDIR = $(HOME)/.links/includes
- X
- X#
- X# Available flags
- X# NBIC : number of bits in a character variable (defaults to 8)
- X# WIDE_INT : widest integer supported by the CPU/compiler
- X# (defaults to 'long')
- X# WIDE_INT_SIZE : size of the WIDE_INT type in bits (defaults to 32);
- X# effective (and required) only when WIDE_INT is defined
- X# NO_SIO : if the SIO library is not available (results in turning
- X# all the string printing functions to no-ops)
- X#
- XDEFS = # for example, -DNO_SIO
- XDEBUG = -g # -g or -O
- XVERSION_DEF = -DVERSION=\"STR\ Version\ $(VERSION)\"
- X
- XCPP_DEFS = $(VERSION_DEF) $(DEFS)
- X
- X#
- X# The following variables shouldn't need to be changed
- X#
- XLINT_FLAGS = -hbux
- XCPP_FLAGS = $(CPP_DEFS) -I$(INCLUDEDIR)
- XCC_FLAGS = $(DEBUG)
- XCFLAGS = $(CPP_FLAGS) $(CC_FLAGS)
- X
- XINSTALL = install -c
- XFMODE = -m 640 # used by install
- XRANLIB = ranlib
- X
- XPAGER = less
- X
- X
- XLIBNAME = lib$(NAME).a
- X
- Xlib: $(LIBNAME)
- X
- Xlibopt: clean
- X make DEBUG=-O "DEFS=$(DEFS)" lib
- X $(INSTALL) $(FMODE) $(LIBNAME) $(LIBDIR)-O
- X
- X$(LIBNAME): $(OBJECTS)
- X ar r $@ $?
- X $(RANLIB) $@
- X
- XLINT_IGNORE=possible pointer alignment|RCSid unused
- X
- Xlint:
- X lint $(CPP_FLAGS) $(LINT_FLAGS) $(MODULE) 2>&1 | egrep -v '$(LINT_IGNORE)' | $(PAGER)
- X
- Xinstall: $(LIBNAME)
- X @if test "$(LIBDIR)" -a "$(INCLUDEDIR)" -a "$(MANDIR)" ;\
- X then \
- X $(INSTALL) $(FMODE) $(LIBNAME) $(LIBDIR) ;\
- X echo "Installed $(LIBNAME) to $(LIBDIR)" ;\
- X for i in $(INCLUDEFILES); do $(INSTALL) $(FMODE) $$i $(INCLUDEDIR) ; done ;\
- X echo Installed $(INCLUDEFILES) to $(INCLUDEDIR) ;\
- X for i in $(MANFILES) ; do $(INSTALL) $(FMODE) $$i $(MANDIR) ; done ;\
- X echo Installed $(MANFILES) to $(MANDIR) ;\
- X else \
- X echo "You forgot to set one of the following variables: LIBDIR,INCLUDEDIR,MANDIR" ;\
- X fi
- X
- Xuninstall:
- X a=`pwd` ; cd $(INCLUDEDIR) ;\
- X if test $$a != `pwd` ; then rm -f $(INCLUDEFILES) ; fi
- X a=`pwd` ; cd $(LIBDIR) ;\
- X if test $$a != `pwd` ; then rm -f $(LIBNAME) ; fi
- X a=`pwd` ; cd $(MANDIR) ;\
- X if test $$a != `pwd` ; then rm -f $(MANFILES) ; fi
- X
- Xclean:
- X rm -f $(OBJECTS) $(LIBNAME) core
- X
- Xspotless: clean uninstall
- X
- Xtags: $(SOURCES) $(HEADERS)
- X ctags -w $(SOURCES) $(HEADERS)
- X
- Xcheckout:
- X co $(SOURCES) $(HEADERS) $(MANFILES)
- X
- X#
- X# Distribution section
- X# This section contains the 2 targets for distribution support: dist, dirs
- X# "dist" checks out all files to be distributed
- X# "dirs" prints a list of directories to be included in the distribution.
- X# These directories should have a Makefile with a "dist" target
- X#
- XDISTRIBUTION_FILES = $(SOURCES) $(HEADERS) $(MANFILES) COPYRIGHT README
- XDIRS =
- X
- Xdist:
- X -co -q $(DISTRIBUTION_FILES)
- X
- Xdirs:
- X @echo $(DIRS)
- X
- X#
- X# PUT HERE THE RULES TO MAKE THE OBJECT FILES
- X#
- Xstrparse.o: strparse.h str.h
- Xstrprint.o: str.h
- Xstrutil.o: str.h
- Xstrs.o: ss_impl.h str.h
- Xss_bf.o: ss_impl.h
- Xss_rk.o: ss_impl.h ss_rk.h
- Xss_kmp.o: ss_impl.h ss_kmp.h
- Xss_sbm.o: ss_impl.h ss_sbm.h
- Xss_bmh.o: ss_impl.h ss_bmh.h
- Xss_so.o: ss_impl.h ss_so.h
- X
- X
- X#
- X# Test program
- X#
- Xtt: tt.c $(LIBNAME)
- X $(CC) -I$(INCDIR) -g -o $@ tt.c $(LIBNAME) -L$(LIBDIR) -lsio -lmisc
- X
- END_OF_FILE
- if test 4534 -ne `wc -c <'libs/src/str/Makefile'`; then
- echo shar: \"'libs/src/str/Makefile'\" unpacked with wrong size!
- fi
- # end of 'libs/src/str/Makefile'
- fi
- if test -f 'libs/src/str/strparse.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'libs/src/str/strparse.c'\"
- else
- echo shar: Extracting \"'libs/src/str/strparse.c'\" \(4683 characters\)
- sed "s/^X//" >'libs/src/str/strparse.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: strparse.c,v 3.1 1993/06/13 02:48:19 panos Exp $" ;
- Xstatic char version[] = VERSION ;
- X
- X#include "str.h"
- X#include "strparse.h"
- X
- Xchar *strcpy() ;
- Xchar *strncpy() ;
- Xchar *strpbrk() ;
- X
- Xchar *malloc() ;
- X
- Xint str_errno ;
- X
- X
- XPRIVATE char *new_string( s )
- X register char *s ;
- X{
- X register char *p = malloc( (unsigned)strlen( s ) + 1 ) ;
- X
- X return( p ? strcpy( p, s ) : p ) ;
- X}
- X
- X
- Xstr_h str_parse( str, separ, flags, errnop )
- X register char *str ;
- X char *separ ;
- X int flags ;
- X int *errnop ;
- X{
- X register struct str_handle *hp ;
- X int *errp = ( errnop == NULL ) ? &str_errno : errnop ;
- X
- X if ( separ == NULL )
- X HANDLE_ERROR( flags, NULL, errp, STR_ENULLSEPAR,
- X "STR str_parse: NULL separator\n" ) ;
- X
- X hp = (struct str_handle *) malloc( sizeof( struct str_handle ) ) ;
- X if ( hp == NULL )
- X HANDLE_ERROR( flags, NULL, errp, STR_ENOMEM,
- X "STR str_parse: malloc failed\n" ) ;
- X
- X hp->string = str ;
- X hp->pos = str ;
- X hp->separator = new_string( separ ) ;
- X if ( hp->separator == NULL )
- X if ( flags & STR_RETURN_ERROR )
- X {
- X free( (char *) hp ) ;
- X *errp = STR_ENOMEM ;
- X return( NULL ) ;
- X }
- X else
- X TERMINATE( "STR str_parse: malloc failed\n" ) ;
- X
- X hp->flags = flags ;
- X hp->errnop = errp ;
- X hp->no_more = ( str == NULL ) ;
- X return( (str_h) hp ) ;
- X}
- X
- X
- Xvoid str_endparse( handle )
- X str_h handle ;
- X{
- X register struct str_handle *hp = (struct str_handle *) handle ;
- X
- X free( hp->separator ) ;
- X free( (char *) handle ) ;
- X}
- X
- X
- X/*
- X * Change the string
- X */
- Xint str_setstr( handle, newstr )
- X str_h handle ;
- X char *newstr ;
- X{
- X register struct str_handle *hp = (struct str_handle *) handle ;
- X
- X if ( newstr == NULL )
- X HANDLE_ERROR( hp->flags, STR_ERR, hp->errnop, STR_ENULLSTRING,
- X "STR str_setstr: NULL string\n" ) ;
- X
- X hp->string = newstr ;
- X hp->pos = newstr ;
- X hp->no_more = FALSE ;
- X return( STR_OK ) ;
- X}
- X
- X
- X
- X/*
- X * Change the separator
- X */
- Xint str_separator( handle, separator )
- X str_h handle ;
- X char *separator ;
- X{
- X register struct str_handle *hp = (struct str_handle *) handle ;
- X char *new_separator ;
- X
- X if ( separator == NULL )
- X HANDLE_ERROR( hp->flags, STR_ERR, hp->errnop, STR_ENULLSEPAR,
- X "STR str_separator: NULL separator\n" ) ;
- X new_separator = new_string( separator ) ;
- X if ( new_separator == NULL )
- X HANDLE_ERROR( hp->flags, STR_ERR, hp->errnop, STR_ENOMEM,
- X "STR str_separator: malloc failed\n" ) ;
- X
- X free( hp->separator ) ;
- X hp->separator = new_separator ;
- X return( STR_OK ) ;
- X}
- X
- X
- Xchar *str_nextpos( handle )
- X str_h handle ;
- X{
- X struct str_handle *hp = (struct str_handle *) handle ;
- X
- X if ( hp->no_more || *hp->pos == '\0' )
- X return( NULL ) ;
- X else
- X return( hp->pos ) ;
- X}
- X
- X
- Xchar *str_component( handle )
- X str_h handle ;
- X{
- X register char *start ;
- X register char *last ;
- X register int sep_count ;
- X char *retval ;
- X int last_char ;
- X register struct str_handle *hp = (struct str_handle *) handle ;
- X register int first_call = ( hp->pos == hp->string ) ;
- X
- X if ( hp->no_more )
- X return( NULL ) ;
- X
- X /*
- X * Get number of separator characters.
- X * Find beginning of component.
- X */
- X sep_count = strspn( hp->pos, hp->separator ) ;
- X
- X /*
- X * If this is the first call, and there are separator characters
- X * at the beginning of the string and the STR_NULL_START flag is set
- X * we return a 0-length string.
- X */
- X if ( first_call && sep_count > 0 && ( hp->flags & STR_NULL_START ) )
- X {
- X start = hp->pos ;
- X last = hp->pos ;
- X }
- X else
- X {
- X start = hp->pos + sep_count ;
- X
- X if ( *start == '\0' )
- X {
- X last = start ;
- X hp->no_more = TRUE ;
- X if ( ! ( hp->flags & STR_NULL_END ) )
- X return( NULL ) ;
- X }
- X else
- X {
- X last = strpbrk( start, hp->separator ) ;
- X if ( last == NULL )
- X last = start + strlen( start ) ;
- X }
- X }
- X
- X /*
- X * At this point, the following variables must be set:
- X * start: beginning of component
- X * last: end of component + 1
- X *
- X * If STR_MALLOC is set, allocate space for the new string.
- X *
- X * NOTE: If STR_MALLOC is not set, the processed string is trashed.
- X */
- X last_char = *last ;
- X if ( hp->flags & STR_MALLOC )
- X {
- X int len = last - start ;
- X
- X retval = malloc( (unsigned)len + 1 ) ;
- X if ( retval == NULL )
- X HANDLE_ERROR( hp->flags, NULL, hp->errnop, STR_ENOMEM,
- X "STR str_component: malloc failed\n" ) ;
- X strncpy( retval, start, len )[ len ] = '\0' ;
- X }
- X else
- X {
- X retval = start ;
- X *last = '\0' ;
- X }
- X
- X /*
- X * Check if last_char is NUL to avoid setting hp->pos past the
- X * end of the string
- X */
- X hp->pos = ( last_char == '\0' ) ? last : last+1 ;
- X return( retval ) ;
- X}
- X
- X
- END_OF_FILE
- if test 4683 -ne `wc -c <'libs/src/str/strparse.c'`; then
- echo shar: \"'libs/src/str/strparse.c'\" unpacked with wrong size!
- fi
- # end of 'libs/src/str/strparse.c'
- fi
- if test -f 'libs/src/str/strs.3' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'libs/src/str/strs.3'\"
- else
- echo shar: Extracting \"'libs/src/str/strs.3'\" \(4394 characters\)
- sed "s/^X//" >'libs/src/str/strs.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: strs.3,v 3.1 1993/06/13 02:49:50 panos Exp $
- X.TH STRS 3X "12 June 1993"
- X.SH NAME
- Xstrs_setup, strs_match, strs_done, strs_search - string matching functions
- X.SH SYNOPSIS
- X.LP
- X.nf
- X.ft B
- X#include "str.h"
- X.LP
- X.ft B
- Xstrs_h strs_setup( flags, pattern [, patlen] )
- Xint flags ;
- Xchar *pattern ;
- X.LP
- X.ft B
- Xchar *strs_match( handle, str, len )
- Xstrs_h handle ;
- Xchar *str ;
- Xint len ;
- X.LP
- X.ft B
- Xvoid strs_done( handle )
- Xstrs_h handle ;
- X.LP
- X.ft B
- Xchar *strs_search( flags, str, len, pattern [, patlen] )
- Xint flags ;
- Xchar *str ;
- Xint len ;
- Xchar *pattern ;
- X.SH DESCRIPTION
- X.LP
- XThese functions perform string matching. They have been designed with
- Xthe assumption that one needs to find a certain pattern in a set of
- Xstrings. It is also possible to use them to find if a pattern occurs
- Xin a specific string.
- X.LP
- X.B strs_setup()
- Xis used to specify the pattern to look for. It returns a
- X.I handle
- Xwhich is used in subsequent string matching operations against
- Xthe specified
- X.I pattern.
- XThe
- X.I flags
- Xargument has two parts: a search method and generic flags.
- XThe available search methods include the following algorithms:
- X.RS
- X.TP 15
- X.SB STRS_BF
- Xbrute force algorithm (also called naive in the literature).
- X.TP
- X.SB STRS_RK
- XRabin-Karp algorithm (probabilistic).
- X.TP
- X.SB STRS_KMP
- XKnuth-Morris-Pratt algorithm.
- X.TP
- X.SB STRS_SBM
- XSimple Boyer-Moore (uses only the last occurrence heuristic).
- X.TP
- X.SB STRS_BMH
- XThis is the Boyer-Moore algorithm using the last occurrence heuristic
- Xas modified by Horspool (this is faster than the simple Boyer-Moore).
- X.TP
- X.SB STRS_SO
- XShift-Or algorithm (this algorithm works only for patterns whose length
- Xdoes not exceed the number of bits in a word).
- X.RE
- X.LP
- XThe default algorithm is the brute force method.
- XIn practice, the fastest algorithm is the
- XBoyer-Moore-Horspool one.
- X.LP
- XThe flags that can be specified include:
- X.RS
- X.TP 15
- X.SB STRS_NOMALLOC
- Xdo not allocate space for the pattern. This can be specified if
- Xthe pattern space will be available during the matching phase
- X(i.e. do not use this flag if the pattern space was malloc'ed and
- Xyou free it before doing any matching).
- X.TP
- X.SB STRS_IGNCASE
- Xperform case-insensitive string matching
- X(the default is case-sensitive matching).
- X.TP
- X.SB STRS_NOSWITCH
- Xdisallows switching to another search method; a switch to the brute
- Xforce algorithm happens if the length of the pattern is less than 4
- Xor if the initialization of the specified search algorithm fails (for
- Xexample, when using the shift-or algorithm with a very long pattern).
- XWhen this flag is used, no switch happens.
- X.TP
- X.SB STRS_PATLEN
- Xis used to explicitly specify the length of the pattern
- X(with the
- X.I patlen
- Xargument); normally the pattern is assumed to be NUL-terminated.
- X.RE
- X.LP
- X.B strs_match()
- Xtries to match the string specified by
- X.I str
- Xagainst the pattern identified by
- X.I handle.
- XSince the length of the string is given by the
- X.I len
- Xargument the string does not need to be NUL-terminated.
- X.B strs_done()
- Xshould be invoked after all matching against the pattern identified by
- X.I handle
- Xis done.
- X.LP
- X.B strs_search()
- Xis equivalent to:
- X.LP
- X.PD .1v
- X.nf
- X.RS
- Xh = strs_setup( flags, pattern ) ;
- Xp = strs_match( h, str, len ) ;
- Xstrs_done( h ) ;
- Xreturn( p ) ;
- X.RE
- X.PD
- X.SH "RETURN VALUES"
- X.LP
- X.B strs_setup()
- Xreturns a search handle on success or
- X.SM NULL
- Xon failure.
- X.LP
- X.B strs_match()
- Xand
- X.B strs_search()
- Xreturn a pointer to the first occurrence of the pattern in the string or
- X.SM NULL
- Xif the pattern does not occur in the string.
- X.SH "SEE ALSO"
- XDonald E. Knuth, James H. Morris, Vaughan R. Pratt.
- XFast pattern matching in strings.
- XSIAM Journal on Computing, 6(2):323-350, 1977.
- X.LP
- XRichard M. Karp, Michael O. Rabin.
- XEfficient randomized pattern-matching algorithms.
- XTechnical Report TR-31-81,
- XAiken Computation Laboratory, Harvard University, 1981.
- X.LP
- XRobert S. Boyer, J. Strother Moore.
- XA fast string-searching algorithm.
- XCommunications of the ACM, 20(10):762-772, 1977.
- X.LP
- XN. Horspool.
- XPractical fast searching in strings.
- XSoftware - Practice and Experience, 10:501-506, 1980.
- X.LP
- XR. Baeza-Yates, G.H. Gonnet.
- XA new approach to text searching.
- XProceedings of 12th SIGIR, June 1989.
- X.LP
- XThomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest.
- XIntroduction to Algorithms.
- XMcGraw-Hill 1990.
- END_OF_FILE
- if test 4394 -ne `wc -c <'libs/src/str/strs.3'`; then
- echo shar: \"'libs/src/str/strs.3'\" unpacked with wrong size!
- fi
- # end of 'libs/src/str/strs.3'
- fi
- echo shar: End of archive 9 \(of 20\).
- cp /dev/null ark9isdone
- 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
-