home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-11-28 | 29.9 KB | 1,185 lines |
- Newsgroups: comp.sources.unix
- From: panos@anchor.cs.colorado.edu (Panos Tsirigotis)
- Subject: v27i113: clc - C Libraries Collection, Part07/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 113
- Archive-Name: clc/part07
-
- #! /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 7 (of 20)."
- # Contents: libs/src/dict/README libs/src/dict/dict.c
- # libs/src/misc/Makefile libs/src/pq/Makefile libs/src/str/str.h
- # libs/src/str/strprint.c libs/src/str/strutil.c
- # 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/README' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'libs/src/dict/README'\"
- else
- echo shar: Extracting \"'libs/src/dict/README'\" \(3537 characters\)
- sed "s/^X//" >'libs/src/dict/README' <<'END_OF_FILE'
- X---------------------------------------------------------------------------
- XNote: All files will appear properly indented if you set your tabstop to 3.
- X---------------------------------------------------------------------------
- X
- XThis library includes support for the following types of data structures:
- X
- X double linked lists
- X hash tables
- X binary search trees (balanced trees are also supported)
- X
- XThe data structures are designed to support dictionary operations.
- XDictionary operations are the operations of insertion, location and
- Xdeletion of objects from a set. The data structures also include
- Xoperations for the location of the maximum/minimum element of a set and
- Xoperations for set enumeration.
- X
- XThe code should work on any system with a reasonable C compiler.
- XI have compiled it on SunOS 4.1 and Ultrix 4.2 using the bundled C
- Xcompiler of those systems. It also compiles with no warnings using gcc 2.1
- X
- XIn order to use this library in your programs, you will need to add
- Xthe following linker options to the cc command line:
- X -ldict -lfsma
- XThe former identifies the library with all the dictionary operations,
- Xcalled "dict", and the latter identifies a support library, called "fsma",
- Xwhich is used by the "dict" library. The distribution includes both
- Xlibraries, and the installation procedure makes sure that both libraries
- Xare compiled and installed.
- X
- XPlease send all comments/bug-reports to panos@cs.colorado.edu.
- X
- X----------------------------------------------------------------------
- X
- XTesting the code
- X
- XI have included 3 sample programs that test this library:
- X dlltest : tests the double linked list implementation
- X htest : tests the hash tables implementation
- X bsttest : tests the binary search tree implementation (note: this
- X program requires that the library be compiled with the
- X BST_DEBUG preprocessor flag; check the Makefile for more
- X details)
- X
- XIn order to do the test, follow these steps (we will assume that the hash
- Xtable implementation is to be tested):
- X
- X 1. Make the program:
- X make LIBDIR=../../lib INCLUDEDIR=../../include htest
- X This assumes that you have not modified the values of LIBDIR and
- X INCLUDEDIR in the top level Makefile.
- X 2. Run the program:
- X htest > HTEST.OUTPUT
- X 3. Compare the output with the standard output which is part of the
- X distribution (this is the file "htest.out", and there are similar
- X files for the rest of the test programs).
- X cmp HTEST.OUTPUT htest.out
- X These two files should be the same.
- X
- XFor the binary search tree implementation, the test program, "bsttest",
- Xcan be invoked in 2 ways: without arguments, and with a single argument "b".
- XThe latter form will make the tree be balanced; however, the
- Xoutput of the program should be the same as when the tree is not
- Xbalanced, so you can use the same output file to do the comparison.
- X
- XTo illustrate the advantage of the balanced search tree implementation,
- Xyou can run the program "bstcomp" (which you can compile by typing
- X"make bstcomp"). This program will create a binary tree and then
- Xtry to find an element in it.
- XFor example,
- X bstcomp 20000
- Xwill do 20000 searches for an element in a binary search tree. The tree
- Xhas 1000 nodes, and it is artificially created to make sure that it is skewed
- X(i.e. the maximum depth is 1000). The search is made for the node which
- Xis at depth 1000.
- XBy invoking the program as:
- X bstcomp b 20000
- Xthe same 1000-node tree will be balanced, and the time to make the 20000
- Xsearches for the same node will be a fraction of the time when the tree
- Xwas not balanced.
- X
- END_OF_FILE
- if test 3537 -ne `wc -c <'libs/src/dict/README'`; then
- echo shar: \"'libs/src/dict/README'\" unpacked with wrong size!
- fi
- # end of 'libs/src/dict/README'
- fi
- if test -f 'libs/src/dict/dict.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'libs/src/dict/dict.c'\"
- else
- echo shar: Extracting \"'libs/src/dict/dict.c'\" \(3586 characters\)
- sed "s/^X//" >'libs/src/dict/dict.c' <<'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
- Xstatic char RCSid[] = "$Id: dict.c,v 3.3 93/11/14 22:24:54 panos Exp $" ;
- Xstatic char version[] = VERSION ;
- X
- X#include "dictimpl.h"
- X
- Xint dict_errno ;
- X
- Xstruct name_value
- X{
- X int nv_value ;
- X char *nv_name ;
- X} ;
- X
- X
- Xstatic struct name_value error_codes[] =
- X {
- X { DICT_ENOMEM, "out of memory" },
- X { DICT_ENOTFOUND, "object not found" },
- X { DICT_ENOOOCOMP, "object-object comparison function is missing" },
- X { DICT_ENOKOCOMP, "key-object comparison function is missing" },
- X { DICT_ENULLOBJECT, "object is NULL" },
- X { DICT_EEXISTS, "object exists" },
- X { DICT_ENOHVFUNC, "hashvalue extraction function is missing" },
- X { DICT_EBADOBJECT, "object does not exist" },
- X { DICT_EBADORDER, "bad order flag" },
- X { DICT_EORDER, "specified order not supported" },
- X { DICT_ENOERROR, NULL }
- X } ;
- X
- X
- Xvoid __dict_terminate( prefix, msg )
- X char *prefix ;
- X char *msg ;
- X{
- X static char buf[ 80 ] ;
- X char *strcat() ;
- X char *strcpy() ;
- X
- X (void) strcpy( buf, "DICT " ) ;
- X (void) strcat( buf, prefix ) ;
- X (void) strcat( buf, ": " ) ;
- X (void) strcat( buf, msg ) ;
- X (void) strcat( buf, "\n" ) ;
- X (void) write( 2, buf, strlen( buf ) ) ;
- X abort() ;
- X _exit( 1 ) ;
- X /* NOTREACHED */
- X}
- X
- X
- Xvoid __dict_fatal_error( caller, error_code )
- X char *caller ;
- X int error_code ;
- X{
- X struct name_value *nvp ;
- X char *msg ;
- X
- X /*
- X * Lookup error message
- X */
- X msg = "unknown error" ;
- X for ( nvp = error_codes ; nvp->nv_name ; nvp++ )
- X if ( nvp->nv_value == error_code )
- X {
- X msg = nvp->nv_name ;
- X break ;
- X }
- X __dict_terminate( caller, msg ) ;
- X}
- X
- X
- Xdict_h __dict_create_error( caller, flags, errp, error_code )
- X char *caller ;
- X int flags ;
- X int *errp ;
- X int error_code ;
- X{
- X dheader_s dh ;
- X
- X dh.flags = flags ;
- X dh.errnop = ( errp == INT_NULL ) ? &dict_errno : errp ;
- X HANDLE_ERROR( &dh, caller, error_code, NULL_HANDLE ) ;
- X /* NOTREACHED */
- X}
- X
- X
- Xint __dict_args_ok( caller, flags, errp, oo_comp, ko_comp, allowed_orders )
- X char *caller ;
- X int flags ;
- X int *errp ;
- X dict_function oo_comp ;
- X dict_function ko_comp ;
- X int allowed_orders ;
- X{
- X int requested_order ;
- X
- X if ( BAD_ORDER( flags ) )
- X {
- X (void) __dict_create_error( caller, flags, errp, DICT_EBADORDER ) ;
- X return( FALSE ) ;
- X }
- X
- X /*
- X * If the user provided an object-object comparator, we can pretend
- X * that the library supports the DICT_UNORDERED flag.
- X */
- X if ( oo_comp )
- X allowed_orders |= DICT_UNORDERED ;
- X
- X requested_order = ( flags & ORDER_FLAGS ) ;
- X if ( requested_order && ! ( allowed_orders & requested_order ) )
- X {
- X (void) __dict_create_error( caller, flags, errp, DICT_EORDER ) ;
- X return( FALSE ) ;
- X }
- X
- X /*
- X * An object-object comparator is required if
- X * order is requested,
- X * or
- X * key uniqueness is requested
- X * or
- X * the library requires it.
- X */
- X if ( oo_comp == NULL_FUNC && ( flags & (DICT_ORDERED | DICT_UNIQUE_KEYS) ) )
- X {
- X (void) __dict_create_error( caller, flags, errp, DICT_ENOOOCOMP ) ;
- X return( FALSE ) ;
- X }
- X
- X#ifdef notdef
- X if ( ko_comp == NULL )
- X {
- X (void) __dict_create_error( caller, flags, errp, DICT_ENOKOCOMP ) ;
- X return( FALSE ) ;
- X }
- X#endif
- X
- X return( TRUE ) ;
- X}
- X
- X
- Xvoid __dict_init_header( dhp, oo_comp, ko_comp, flags, errnop )
- X dheader_s *dhp ;
- X dict_function oo_comp, ko_comp ;
- X int flags, *errnop ;
- X{
- X dhp->oo_comp = oo_comp ;
- X dhp->ko_comp = ko_comp ;
- X dhp->flags = flags ;
- X dhp->errnop = ( errnop == INT_NULL ) ? &dict_errno : errnop ;
- X}
- X
- END_OF_FILE
- if test 3586 -ne `wc -c <'libs/src/dict/dict.c'`; then
- echo shar: \"'libs/src/dict/dict.c'\" unpacked with wrong size!
- fi
- # end of 'libs/src/dict/dict.c'
- fi
- if test -f 'libs/src/misc/Makefile' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'libs/src/misc/Makefile'\"
- else
- echo shar: Extracting \"'libs/src/misc/Makefile'\" \(3674 characters\)
- sed "s/^X//" >'libs/src/misc/Makefile' <<'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#
- X# $Id: Makefile,v 2.9 1992/11/06 02:20:41 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 = misc
- XVERSION = 1.2.2
- X
- XHEADERS = misc.h ftwx.h env.h
- XSOURCES = misc.c ftwx.c env.c
- XOBJECTS = misc.o ftwx.o env.o
- X
- XMANFILES = misc.3 ftwx.3 env.3
- XINCLUDEFILES = $(HEADERS)
- 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# Possible flags:
- X# -DOLD_DIR : must include <sys/dir.h> instead of <dirent.h>
- X# -D__FTWX_NO_FTW : does not have <ftw.h>
- X#
- XDEFS = # used for command line defined flags
- X
- XDEBUG = -g # -g or -O
- XVERSION_DEF = -DVERSION=\"MISC\ 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 lib
- X mv $(LIBNAME) $(LIBDIR)/optimized
- X
- 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
- 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#
- Xmisc.o: misc.h
- Xftwx.o: ftwx.h misc.h
- Xenv.o: env.h misc.h
- X
- X
- X#
- X# Test program
- X#
- Xtt: tt.c $(LIBNAME)
- X $(CC) -g tt.c -o $@ $(LIBNAME) -L$(LIBDIR) -ltest
- X
- END_OF_FILE
- if test 3674 -ne `wc -c <'libs/src/misc/Makefile'`; then
- echo shar: \"'libs/src/misc/Makefile'\" unpacked with wrong size!
- fi
- # end of 'libs/src/misc/Makefile'
- fi
- if test -f 'libs/src/pq/Makefile' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'libs/src/pq/Makefile'\"
- else
- echo shar: Extracting \"'libs/src/pq/Makefile'\" \(3498 characters\)
- sed "s/^X//" >'libs/src/pq/Makefile' <<'END_OF_FILE'
- 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# $Id: Makefile,v 2.2 1993/05/06 07:50:44 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 = pq
- XVERSION = 1.0.2
- X
- XHEADERS = hpq.h hpqimpl.h pq.h
- XSOURCES = hpq.c pq.c
- XOBJECTS = hpq.o pq.o
- X
- XMANFILES = pq.3
- XINCLUDEFILES = hpq.h pq.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
- XDEFS = # used for command line defined flags
- XDEBUG = -g # -g or -O
- XVERSION_DEF = -DVERSION=\"HPQ\ 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) COPYRIGHT
- 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#
- Xhpq.o: hpq.h hpqimpl.h pq.h
- X
- X#
- X# Simple test program
- X#
- Xpqtest: pqtest.c $(LIBNAME)
- X cc $(DEBUG) -o $@ pqtest.c $(LIBNAME)
- X
- END_OF_FILE
- if test 3498 -ne `wc -c <'libs/src/pq/Makefile'`; then
- echo shar: \"'libs/src/pq/Makefile'\" unpacked with wrong size!
- fi
- # end of 'libs/src/pq/Makefile'
- fi
- if test -f 'libs/src/str/str.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'libs/src/str/str.h'\"
- else
- echo shar: Extracting \"'libs/src/str/str.h'\" \(3551 characters\)
- sed "s/^X//" >'libs/src/str/str.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#ifndef __STR_H
- X#define __STR_H
- X
- X/*
- X * $Id: str.h,v 3.1 1993/06/13 02:47:14 panos Exp $
- X */
- X
- X#include <varargs.h>
- 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/*
- X * strprint(3) functions
- X */
- Xchar *str_sprint __ARGS( ( char *buf, char *fmt, ... ) ) ;
- Xint str_nprint __ARGS( ( char *buf, char *fmt, ... ) ) ;
- Xvoid str_print __ARGS( ( int *count, char *buf, char *fmt, ... ) ) ;
- X
- Xchar *str_sprintv __ARGS( ( char *buf, char *fmt, va_list ) ) ;
- Xint str_nprintv __ARGS( ( char *buf, char *fmt, va_list ) ) ;
- Xvoid str_printv __ARGS( ( int *count, char *buf, char *fmt, va_list ) ) ;
- X
- Xchar *strx_sprint __ARGS( ( char *buf, int len, char *fmt, ... ) ) ;
- Xint strx_nprint __ARGS( ( char *buf, int len, char *fmt, ... ) ) ;
- Xvoid strx_print __ARGS( ( int *count, char *buf, int len, char *fmt, ... ) ) ;
- X
- Xchar *strx_sprintv __ARGS( ( char *buf, int len, char *fmt, va_list ) ) ;
- Xint strx_nprintv __ARGS( ( char *buf, int len, char *fmt, va_list ) ) ;
- Xvoid strx_printv __ARGS(( int *cnt, char *buf, int len, char *fmt, va_list )) ;
- X
- X
- X/*
- X * strparse(3) functions
- X */
- X
- X/*
- X * Return values
- X */
- X#define STR_OK 0
- X#define STR_ERR (-1)
- X
- X
- X/*
- X * Flags for the string parsing functions
- X */
- X#define STR_NOFLAGS 0x0
- X#define STR_RETURN_ERROR 0x1
- X#define STR_NULL_START 0x2
- X#define STR_NULL_END 0x4
- X#define STR_MALLOC 0x8
- X
- Xextern int str_errno ;
- X
- X/*
- X * Error values
- X */
- X#define STR_ENULLSEPAR 1
- X#define STR_ENULLSTRING 2
- X#define STR_ENOMEM 3
- X
- Xtypedef void *str_h ;
- X
- Xstr_h str_parse __ARGS( ( char *str, char *separ, int flags, int *errnop ) ) ;
- Xvoid str_endparse __ARGS( ( str_h handle ) ) ;
- Xchar *str_component __ARGS( ( str_h handle ) ) ;
- Xint str_setstr __ARGS( ( str_h handle, char *newstr ) ) ;
- Xint str_separator __ARGS( ( str_h handle, char *separ ) ) ;
- Xchar *str_nextpos __ARGS( ( str_h handle ) ) ;
- X
- X/*
- X * For backwards compatibility
- X */
- X#define str_process( s, sep, flags ) str_parse( s, sep, flags, (int *)0 )
- X#define str_endprocess( handle ) str_endparse( handle )
- X
- X
- X/*
- X * strutil(3) functions
- X */
- Xchar *str_find __ARGS( ( char *s1, char *s2 ) ) ;
- Xchar *str_casefind __ARGS( ( char *s1, char *s2 ) ) ;
- Xvoid str_fill __ARGS( ( char *s, char c ) ) ;
- Xchar *str_lower __ARGS( ( char *s ) ) ;
- Xchar *str_upper __ARGS( ( char *s ) ) ;
- X
- X
- X/*
- X * strsearch(3) functions
- X */
- X
- X/*
- X * Methods
- X */
- X#define STRS_BF 0 /* brute force */
- X#define STRS_RK 1 /* Rabin-Karp */
- X#define STRS_KMP 2 /* Knuth-Morris-Pratt */
- X#define STRS_SBM 3 /* Simple Boyer-Moore */
- X#define STRS_BMH 4 /* Boyer-Moore-Horspool */
- X#define STRS_SO 5 /* Shift-Or */
- X
- X#define __STRS_METHOD_BITS 5
- X#define STRS_METHODS_MAX ( 1 << __STRS_METHOD_BITS )
- X
- X/*
- X * Flags
- X */
- X#define __STRS_MAKEFLAG( v ) ( (v) << __STRS_METHOD_BITS )
- X#define STRS_IGNCASE __STRS_MAKEFLAG( 0x1 )
- X#define STRS_NOMALLOC __STRS_MAKEFLAG( 0x2 )
- X#define STRS_NOSWITCH __STRS_MAKEFLAG( 0x4 )
- X#define STRS_PATLEN __STRS_MAKEFLAG( 0x8 )
- X
- X
- Xtypedef void *strs_h ;
- X
- Xchar *strs_search __ARGS( ( int flags, char *str, int len, char *pat, ... ) ) ;
- Xstrs_h strs_setup __ARGS( ( int flags, char *pattern, ... ) ) ;
- Xchar *strs_match __ARGS( ( strs_h handle, char *str, int len ) ) ;
- Xvoid strs_done __ARGS( ( strs_h handle ) ) ;
- X
- X#endif /* __STR_H */
- X
- END_OF_FILE
- if test 3551 -ne `wc -c <'libs/src/str/str.h'`; then
- echo shar: \"'libs/src/str/str.h'\" unpacked with wrong size!
- fi
- # end of 'libs/src/str/str.h'
- fi
- if test -f 'libs/src/str/strprint.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'libs/src/str/strprint.c'\"
- else
- echo shar: Extracting \"'libs/src/str/strprint.c'\" \(3569 characters\)
- sed "s/^X//" >'libs/src/str/strprint.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: strprint.c,v 3.1 1993/06/13 02:50:11 panos Exp $" ;
- X
- X#ifndef NO_SIO
- X#include "sio.h"
- X#endif
- X
- X#include "str.h"
- X
- X#define INT_NULL ((int *)0)
- X
- X/*
- X * The strx_* functions will never overwrite the buffer
- X * The str_* functions may overwrite the buffer
- X */
- X
- X/*
- X * Group 1: the strx_* functions
- X */
- X
- X/*
- X * This is the general purpose conversion function. It is invoked
- X * by all the other str[x]_* functions
- X */
- Xvoid strx_printv( ccp, buf, len, format, ap )
- X int *ccp ;
- X char *buf ;
- X int len ;
- X char *format ;
- X va_list ap ;
- X{
- X#ifndef NO_SIO
- X __sio_od_t od ;
- X int cc ;
- X
- X /*
- X * First initialize the descriptor
- X * Notice that if no length is given, we initialize buf_end to the
- X * highest possible address.
- X */
- X od.buf = buf ; /* NOT NEEDED */
- X od.buf_end = len ? &buf[ len ] : (char *) ~0 ; /* NEEDED */
- X od.buffer_size = 0 ; /* NOT NEEDED */
- X od.start = buf ; /* NOT NEEDED */
- X od.nextb = buf ; /* NEEDED */
- X od.buftype = 0 ; /* NOT NEEDED */
- X
- X /*
- X * Do the conversion
- X */
- X cc = __sio_converter( &od, -1, format, ap ) ;
- X if ( len == 0 || od.nextb < od.buf_end )
- X *(od.nextb) = '\0' ;
- X if ( ccp )
- X *ccp = cc ;
- X#endif /* ! NO_SIO */
- X}
- X
- X
- Xvoid strx_print( ccp, buf, len, format, va_alist )
- X int *ccp ;
- X char *buf ;
- X int len ;
- X char *format ;
- X va_dcl
- X{
- X va_list ap ;
- X
- X va_start( ap ) ;
- X strx_printv( ccp, buf, len, format, ap ) ;
- X va_end( ap ) ;
- X}
- X
- X
- Xchar *strx_sprint( buf, len, format, va_alist )
- X char *buf ;
- X int len ;
- X char *format ;
- X va_dcl
- X{
- X va_list ap ;
- X
- X va_start( ap ) ;
- X strx_printv( INT_NULL, buf, len, format, ap ) ;
- X va_end( ap ) ;
- X return( buf ) ;
- X}
- X
- X
- Xchar *strx_sprintv( buf, len, format, ap )
- X char *buf ;
- X int len ;
- X char *format ;
- X va_list ap ;
- X{
- X strx_printv( INT_NULL, buf, len, format, ap ) ;
- X return( buf ) ;
- X}
- X
- X
- Xint strx_nprint( buf, len, format, va_alist )
- X char *buf ;
- X int len ;
- X char *format ;
- X va_dcl
- X{
- X int cc ;
- X va_list ap ;
- X
- X va_start( ap ) ;
- X strx_printv( &cc, buf, len, format, ap ) ;
- X va_end( ap ) ;
- X return( cc ) ;
- X}
- X
- X
- Xint strx_nprintv( buf, len, format, ap )
- X char *buf ;
- X int len ;
- X char *format ;
- X va_list ap ;
- X{
- X int cc ;
- X
- X strx_printv( &cc, buf, len, format, ap ) ;
- X return( cc ) ;
- X}
- X
- X
- X
- X/*
- X * Group 2: the str_* functions
- X */
- X
- Xvoid str_print( ccp, buf, format, va_alist )
- X int *ccp ;
- X char *buf ;
- X char *format ;
- X va_dcl
- X{
- X va_list ap ;
- X
- X va_start( ap ) ;
- X strx_printv( ccp, buf, 0, format, ap ) ;
- X va_end( ap ) ;
- X}
- X
- X
- Xvoid str_printv( ccp, buf, format, ap )
- X int *ccp ;
- X char *buf ;
- X char *format ;
- X va_list ap ;
- X{
- X strx_printv( ccp, buf, 0, format, ap ) ;
- X}
- X
- X
- Xchar *str_sprint( buf, format, va_alist )
- X char *buf ;
- X char *format ;
- X va_dcl
- X{
- X va_list ap ;
- X
- X va_start( ap ) ;
- X strx_printv( INT_NULL, buf, 0, format, ap ) ;
- X va_end( ap ) ;
- X return( buf ) ;
- X}
- X
- X
- Xchar *str_sprintv( buf, format, ap )
- X char *buf ;
- X char *format ;
- X va_list ap ;
- X{
- X strx_printv( INT_NULL, buf, 0, format, ap ) ;
- X return( buf ) ;
- X}
- X
- X
- Xint str_nprint( buf, format, va_alist )
- X char *buf ;
- X char *format ;
- X va_dcl
- X{
- X int cc ;
- X va_list ap ;
- X
- X va_start( ap ) ;
- X strx_printv( &cc, buf, 0, format, ap ) ;
- X va_end( ap ) ;
- X return( cc ) ;
- X}
- X
- X
- X
- Xint str_nprintv( buf, format, ap )
- X char *buf ;
- X char *format ;
- X va_list ap ;
- X{
- X int cc ;
- X
- X strx_printv( &cc, buf, 0, format, ap ) ;
- X return( cc ) ;
- X}
- X
- X
- END_OF_FILE
- if test 3569 -ne `wc -c <'libs/src/str/strprint.c'`; then
- echo shar: \"'libs/src/str/strprint.c'\" unpacked with wrong size!
- fi
- # end of 'libs/src/str/strprint.c'
- fi
- if test -f 'libs/src/str/strutil.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'libs/src/str/strutil.c'\"
- else
- echo shar: Extracting \"'libs/src/str/strutil.c'\" \(3554 characters\)
- sed "s/^X//" >'libs/src/str/strutil.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: strutil.c,v 3.1 1993/06/13 02:50:22 panos Exp $" ;
- X
- X
- X#include <ctype.h>
- X
- X#define NULL 0
- X
- X
- X#ifndef TRIVIAL_STR_FIND
- X
- X/*
- X * look for an instance of s2 in s1
- X * Returns a pointer to the beginning of s2 in s1
- X */
- Xchar *str_find( str, sstr )
- X register char *str ;
- X register char *sstr ;
- X{
- X register int ssfc = *sstr++ ; /* sub-string first char */
- X
- X if ( ssfc == 0 ) /* empty string is always a match */
- X return( str ) ;
- X
- X while ( *str )
- X {
- X char *current = str ;
- X register int strc = *str++ ;
- X register char *sp ; /* string pointer */
- X register char *ssp ; /* sub-string pointer */
- X
- X if ( strc != ssfc )
- X continue ;
- X
- X /*
- X * We don't need to make the end of str a special case since
- X * the comparison of *sp against *ssp is guaranteed to fail
- X */
- X for ( sp = str, ssp = sstr ;; sp++, ssp++ )
- X {
- X if ( *ssp == 0 )
- X return( current ) ;
- X if ( *sp != *ssp )
- X break ;
- X }
- X }
- X
- X return( 0 ) ;
- X}
- X
- X
- X#define LOWER_CASE( c ) ( (c) + 'a' - 'A' )
- X
- X/*
- X * str_casefind is similar to str_find except that it ignores the
- X * case of the alphabetic characters
- X */
- Xchar *str_casefind( str, sstr )
- X register char *str ;
- X char *sstr ;
- X{
- X register int ssfc = *sstr++ ; /* sub-string first char */
- X
- X if ( ssfc == 0 )
- X return( str ) ;
- X
- X if ( isalpha( ssfc ) && isupper( ssfc ) )
- X ssfc = LOWER_CASE( ssfc ) ;
- X
- X while ( *str )
- X {
- X char *current = str ;
- X register int strc = *str++ ;
- X char *sp ; /* string pointer */
- X char *ssp ; /* sub-string pointer */
- X
- X if ( isalpha( strc ) && isupper( strc ) )
- X strc = LOWER_CASE( strc ) ;
- X if ( strc != ssfc )
- X continue ;
- X
- X for ( sp = str, ssp = sstr ;; sp++, ssp++ )
- X {
- X register int sc = *sp ; /* string char */
- X register int ssc = *ssp ; /* substring char */
- X
- X /*
- X * End-of-substring means we got a match
- X */
- X if ( ssc == 0 )
- X return( current ) ;
- X
- X /*
- X * Convert to lower case if alphanumeric
- X */
- X if ( isalpha( sc ) && isupper( sc ) )
- X sc = LOWER_CASE( sc ) ;
- X if ( isalpha( ssc ) && isupper( ssc ) )
- X ssc = LOWER_CASE( ssc ) ;
- X if ( sc != ssc )
- X break ;
- X }
- X }
- X
- X return( 0 ) ;
- X}
- X
- X
- X#else /* defined( TRIVIAL_STR_FIND ) */
- X
- X/*
- X * look for an instance of s2 in s1
- X * Returns a pointer to the beginning of s2 in s1
- X */
- Xchar *str_find( s1, s2 )
- X char *s1 ;
- X char *s2 ;
- X{
- X int i ;
- X int l1 = strlen( s1 ) ;
- X int l2 = strlen( s2 ) ;
- X
- X for ( i = 0 ; i < l1 - l2 + 1 ; i++ )
- X if ( strncmp( &s1[ i ], s2, l2 ) == 0 )
- X return( &s1[ i ] ) ;
- X return( NULL ) ;
- X}
- X
- X
- Xchar *str_casefind( s1, s2 )
- X char *s1 ;
- X char *s2 ;
- X{
- X int i ;
- X int l1 = strlen( s1 ) ;
- X int l2 = strlen( s2 ) ;
- X
- X for ( i = 0 ; i < l1 - l2 + 1 ; i++ )
- X if ( strncasecmp( &s1[ i ], s2, l2 ) == 0 )
- X return( &s1[ i ] ) ;
- X return( NULL ) ;
- X}
- X
- X#endif /* TRIVIAL_STR_FIND */
- X
- X
- X/*
- X * Fill string s with character c
- X */
- Xvoid str_fill( s, c )
- X register char *s ;
- X register char c ;
- X{
- X while ( *s ) *s++ = c ;
- X}
- X
- X
- Xchar *str_lower( s )
- X char *s ;
- X{
- X register char *p ;
- X register int offset = 'a' - 'A' ;
- X
- X for ( p = s ; *p ; p++ )
- X if ( isascii( *p ) && isupper( *p ) )
- X *p += offset ;
- X return( s ) ;
- X}
- X
- X
- Xchar *str_upper( s )
- X char *s ;
- X{
- X register char *p ;
- X register int offset = 'a' - 'A' ;
- X
- X for ( p = s ; *p ; p++ )
- X if ( isascii( *p ) && islower( *p ) )
- X *p -= offset ;
- X return( s ) ;
- X}
- X
- X
- END_OF_FILE
- if test 3554 -ne `wc -c <'libs/src/str/strutil.c'`; then
- echo shar: \"'libs/src/str/strutil.c'\" unpacked with wrong size!
- fi
- # end of 'libs/src/str/strutil.c'
- fi
- echo shar: End of archive 7 \(of 20\).
- cp /dev/null ark7isdone
- 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
-