home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk1.iso
/
altsrc
/
articles
/
7000-7999
/
7939
< prev
next >
Wrap
Text File
|
1993-05-10
|
34KB
|
1,403 lines
Newsgroups: alt.sources
Path: wupost!darwin.sura.net!howland.reston.ans.net!noc.near.net!uunet!boulder!news
From: panos@burton.cs.colorado.edu (Panos Tsirigotis)
Subject: optgen: a generator of option recognition code (part 5 of 12)
Message-ID: <1993May10.070401.14329@colorado.edu>
Sender: news@colorado.edu (The Daily Planet)
Nntp-Posting-Host: burton.cs.colorado.edu
Organization: University of Colorado, Boulder
Date: Mon, 10 May 1993 07:04:01 GMT
Lines: 1391
Submitted-by: Panos Tsirigotis (panos@cs.colorado.edu)
Archive-name: optgen/part05
Part: 05 of 12
------------------------------ Cut here ------------------------------
#! /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 12)."
# Contents: libs/src/misc/Makefile libs/src/misc/ftwx.c
# libs/src/sio/Makefile libs/src/sio/suite/copytest.c
# libs/src/sio/suite/tester libs/src/str/strparse.3
# libs/src/str/strs.3
# Wrapped by panos@mystique on Sat May 8 13:28:31 1993
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
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/misc/ftwx.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'libs/src/misc/ftwx.c'\"
else
echo shar: Extracting \"'libs/src/misc/ftwx.c'\" \(3822 characters\)
sed "s/^X//" >'libs/src/misc/ftwx.c' <<'END_OF_FILE'
X/*
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
Xstatic char RCSid[] = "$Id: ftwx.c,v 2.1 1992/10/01 00:41:02 panos Exp $" ;
X
X#include <sys/types.h>
X#include <sys/stat.h>
X#include <sys/file.h>
X#ifndef OLD_DIR
X#include <dirent.h>
X#else
X#include <sys/dir.h>
X#define dirent direct
X#endif
X
Xextern int errno ;
X
X#include "misc.h"
X#include "ftwx.h"
X
X#define PRIVATE static
X
X#define NUL '\0'
X
X
Xtypedef enum { NO, YES } boolean_e ;
X
Xstatic struct
X{
X int (*stat_func)() ;
X int (*user_func)() ;
X} ftwx_data ;
X
X/*
X * ftwx is an extension to ftw, that optionally follows symlinks (the
X * default is NOT to follow them).
X *
X * Possible flag values:
X * FTWX_FOLLOW: follow symlinks
X *
X * Possible depth values:
X * 0 : means only the specified path
X * positive : means go as deep as specified
X * FTWX_ALL : no depth limitation
X *
X * User function return value:
X * negative : means an error occured and the traversal should stop
X * 0 : OK
X * positive : means that if the current object is a directory it
X * should not be traversed.
X *
X * Return value:
X * -1 : if an error occurs
X * frv : frv is the function return value if it is negative (it
X * should not be -1).
X * 0 : if successful
X */
Xint ftwx( path, func, depth, flags )
X char *path ;
X int (*func)() ;
X int depth ;
X int flags ;
X{
X int stat(), lstat() ;
X
X /*
X * Initialize the data structure
X */
X ftwx_data.stat_func = ( flags & FTWX_FOLLOW ) ? stat : lstat ;
X ftwx_data.user_func = func ;
X
X return( ftwx_traverse( path, depth ) ) ;
X}
X
X
X
X
X/*
X * ftwx_traverse works in two phases:
X *
X * Phase 1: process the current path
X *
X * Phase 2: if the current path is a directory, it invokes ftwx_traverse
X * for each directory entry
X */
XPRIVATE int ftwx_traverse( path, depth )
X char *path ;
X int depth ;
X{
X DIR *dirp ;
X struct stat st ;
X int ftw_flag = 0 ;
X boolean_e traverse = YES ;
X int retval ;
X int save_errno ;
X
X if ( (*ftwx_data.stat_func)( path, &st ) == -1 )
X ftw_flag = FTW_NS ;
X else
X {
X /*
X * If it is a directory and determine if it is readable
X * (if it is not readable, we don't traverse it
X */
X if ( S_ISDIR( st.st_mode ) )
X if ( access( path, R_OK ) == 0 )
X ftw_flag = FTW_D ;
X else
X ftw_flag = FTW_DNR ;
X else
X ftw_flag = FTW_F ;
X }
X retval = (*ftwx_data.user_func)( path, &st, ftw_flag ) ;
X if ( retval < 0 )
X return( retval ) ;
X else if ( retval > 0 && ftw_flag == FTW_D )
X traverse = NO ;
X
X /*
X * Stop traversal if:
X * a. depth reached 0
X * b. the current path is not a readable directory
X * c. the user doesn't want us to traverse this directory tree
X */
X if ( depth == 0 || ftw_flag != FTW_D || traverse == NO )
X return( 0 ) ;
X
X if ( depth != FTWX_ALL )
X depth-- ;
X
X if ( ( dirp = opendir( path ) ) == NULL )
X return( -1 ) ;
X
X for ( ;; )
X {
X struct dirent *dp ;
X char *filename ;
X
X errno = 0 ; /* to detect readdir errors */
X dp = readdir( dirp ) ;
X if ( dp == NULL )
X {
X retval = ( errno == 0 ) ? 0 : -1 ;
X break ;
X }
X
X /*
X * The special names: "." and ".." are skipped
X */
X if ( dp->d_name[ 0 ] == '.' )
X if ( dp->d_name[ 1 ] == NUL ||
X dp->d_name[ 1 ] == '.' && dp->d_name[ 2 ] == NUL )
X continue ;
X
X filename = make_pathname( 2, path, dp->d_name ) ;
X if ( filename == NULL )
X {
X retval = -1 ;
X break ;
X }
X
X retval = ftwx_traverse( filename, depth ) ;
X free( filename ) ;
X
X /*
X * Check for a negative value instead of -1 because the
X * user function may use any negative value
X */
X if ( retval < 0 )
X break ;
X }
X /*
X * Make sure we don't trash errno; we should only do this if
X * retval is negative, but we are lazy...
X */
X save_errno = errno ;
X (void) closedir( dirp ) ;
X errno = save_errno ;
X return( retval ) ;
X}
X
END_OF_FILE
if test 3822 -ne `wc -c <'libs/src/misc/ftwx.c'`; then
echo shar: \"'libs/src/misc/ftwx.c'\" unpacked with wrong size!
fi
# end of 'libs/src/misc/ftwx.c'
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'\" \(4227 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.6 1993/03/30 21:34:09 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.2
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)
XMANDIR = $(HOME)/.links/includes
XINCLUDEDIR = $(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 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 4227 -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'\" \(4262 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.1 1993/03/13 01:21:48 panos Exp $" ;
X
X#include "sio.h"
X#include <stdio.h>
X#include <syscall.h>
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 4262 -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/sio/suite/tester' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'libs/src/sio/suite/tester'\"
else
echo shar: Extracting \"'libs/src/sio/suite/tester'\" \(3971 characters\)
sed "s/^X//" >'libs/src/sio/suite/tester' <<'END_OF_FILE'
X#!/bin/sh
X
X# (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
X# All rights reserved. The file named COPYRIGHT specifies the terms
X# and conditions for redistribution.
X
X
X#
X# $Id: tester,v 8.2 1993/03/17 18:53:40 panos Exp $
X#
X
X#
X# Usage:
X# tester [all] [function-name function-name ...]
X#
X# function-name is the name of a sio function (or macro)
X#
X# If "all" is used, functions after it will *not* be tested.
X#
X
Xscript_name=`basename $0`
X
Xcopy_file=/usr/dict/words
Xtemp_file=/tmp/w
Xmake_log=MAKE.LOG
X
Xif test ! -f $copy_file ; then
X echo "The file '$copy_file' is not available."
X echo "Please edit the '$script_name' script and change set the"
X echo "variable 'copy_file' to the name of a publicly readable file"
X echo "with at least a few tens of thousands of lines."
X exit 1
Xfi
X
Xtrap_function()
X{
X rm -f $temp_file $make_log
X echo
X exit 1
X}
X
X
Xmake_program()
X{
X target=$1
X cflags="$2"
X if test -f $1 -a ! -x $1 ; then rm -f $1 ; fi
X if test "$cflags"
X then
X make -s "$cflags" $target >$make_log 2>&1
X else
X make -s $target >$make_log 2>&1
X fi
X exit_code=$?
X if test $exit_code -eq 0 -a -x $1
X then
X rm -f $make_log
X else
X echo "FAILED"
X echo " The make failed. Check the make log file << $make_log >>"
X exit
X fi
X}
X
X
X
X#
X# test_function expects a single argument, the name of the function
X# it will test.
X# It creates a program that has the name of the function by invoking
X# make with the symbol -DTEST_<function_name>
X#
Xtest_function()
X{
X expression="echo $"$1
X var=`eval $expression`
X if test "$var" = "no" -o "$var" = "" -a "$all" = "no" ; then return ; fi
X
X echo -n "TESTING $1 "
X make_program $1 "CFLAGS=-g -DTEST_$1"
X
X ./$1 < $copy_file >$temp_file
X exit_code=$?
X if test $exit_code -ne 0
X then
X echo "FAILED"
X echo " Test program exited with exit code $exit_code"
X echo " Temporary file << $temp_file >> not deleted"
X exit
X fi
X cmp -s $copy_file $temp_file
X if test $? -ne 0
X then
X echo "FAILED"
X echo " The files << $copy_file >> and << $temp_file >> are not the same"
X exit
X else
X echo PASSED
X fi
X rm -f $temp_file
X}
X
X
Xtest_sprint()
X{
X var=$Sprint
X program=Sprint
X if test "$var" = "no" -o "$var" = "" -a "$all" = "no" ; then return ; fi
X
X echo TESTING Sprint
X make_program $program ""
X $TESTSHELL sprint_test
X}
X
X
Xtest_smorefds()
X{
X var=$Smorefds
X program=fdtest
X if test "$var" = "no" -o "$var" = "" -a "$all" = "no" ; then return ; fi
X
X echo -n "TESTING Smorefds "
X make_program $program "CFLAGS=-g"
X v=`fdtest 2>&1`
X if test $? -eq 0 ; then
X echo PASSED
X else
X echo "FAILED: $v"
X fi
X}
X
X
Xtrap trap_function 1 2 3 15
X
X#
X# There is a variable for every function to be tested. That variable
X# can have the values "yes", "no" or "".
X# When a function is specified, it takes the value of $run. Initially $run
X# is "yes", so a specified function has its variable set to "yes".
X# If "all" is specified, $run becomes "no", so subsequently specified
X# functions, have their variables set to "no".
X#
X# We test a function iff:
X# its variable is "yes" OR its variable is "" and $all is "yes"
X# We don't test a function iff:
X# its variable is "no" OR its variable is "" and $all is "no"
X#
X# Therefore, all functions specified after "all" will NOT be tested.
X#
Xrun=yes
Xall=no
X
Xwhile test $# -gt 0
Xdo
X case $1 in
X Sputchar) Sputchar=$run ;;
X Sgetchar) Sgetchar=$run ;;
X Srdline) Srdline=$run ;;
X Sfetch) Sfetch=$run ;;
X Sread) Sread=$run ;;
X Swrite) Swrite=$run ;;
X Sgetc) Sgetc=$run ;;
X Sputc) Sputc=$run ;;
X Sflush) Sflush=$run ;;
X Sundo) Sundo=$run ;;
X Sprint) Sprint=$run ;;
X switch) switch=$run ;;
X switch2) switch2=$run ;;
X Smorefds) Smorefds=$run ;;
X all) all=yes ; run="no" ;;
X *) echo Bad argument: $1
X esac
X shift
Xdone
X
Xtest_function Sgetchar
Xtest_function Sputchar
Xtest_function Sread
Xtest_function Swrite
Xtest_function Srdline
Xtest_function Sfetch
Xtest_function Sgetc
Xtest_function Sputc
Xtest_function Sflush
Xtest_function Sundo
Xtest_function switch
Xtest_function switch2
Xtest_smorefds
Xtest_sprint
X
END_OF_FILE
if test 3971 -ne `wc -c <'libs/src/sio/suite/tester'`; then
echo shar: \"'libs/src/sio/suite/tester'\" unpacked with wrong size!
fi
# end of 'libs/src/sio/suite/tester'
fi
if test -f 'libs/src/str/strparse.3' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'libs/src/str/strparse.3'\"
else
echo shar: Extracting \"'libs/src/str/strparse.3'\" \(4131 characters\)
sed "s/^X//" >'libs/src/str/strparse.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: strparse.3,v 2.1 1993/01/13 22:37:58 panos Exp $
X.TH STRPARSE 3X "30 September 1992"
X.SH NAME
Xstr_parse, str_endparse, str_component, str_separator, str_nextpos
X.SH SYNOPSIS
X.LP
X.nf
X.ft B
X#include "str.h"
X.LP
X.ft B
Xstr_h str_parse( str, separ, flags, errnop )
Xchar *str ;
Xchar *separ ;
Xint flags ;
Xint *errnop ;
X.LP
X.ft B
Xvoid str_endparse( handle )
Xstr_h handle ;
X.LP
X.ft B
Xchar *str_component( handle )
Xstr_h handle ;
X.LP
X.ft B
Xint str_setstr( handle, newstr )
Xstr_h handle ;
Xchar *newstr ;
X.LP
X.ft B
Xint str_separator( handle, separ )
Xstr_h handle ;
Xchar *separ ;
X.LP
X.ft B
Xchar *str_nextpos( handle )
Xstr_h handle ;
X.LP
Xextern int str_errno ;
X.SH DESCRIPTION
X.LP
XThese functions are useful for parsing strings.
XIn this context parsing means breaking
Xthe string into substrings. The substrings are separated by a list
Xof possible separator characters.
X.LP
X.B str_component()
Xreturns successive substrings of the string.
X.B str_parse()
Xcreates and initializes a string parser with the string
Xthat will be processed, \fIstr\fR, the list of possible separator
Xcharacters, \fIsepar\fR, and flags that control how the parser
Xworks. The \fIflags\fR argument is formed by ORing one or more of
Xthe following constants:
X.TP 20
X.SB STR_RETURN_ERROR
XIf something goes wrong return a value that indicates that an error occured
X(e.g. out of memory). The default is for the program to be terminated
Xwith an appropriate error message.
X.TP
X.SB STR_NULL_START
XIf \fIstr\fR starts with a separator then a zero-length string will be returned
Xthe first time \fBstr_component()\fR is called.
X.TP
X.SB STR_NULL_END
XIf \fIstr\fR starts with a separator then a zero-length string will be returned
Xby \fBstr_component()\fR when the substrings of \fIstr\fR are exhausted.
X.TP
X.SB STR_MALLOC
XThe strings returned by \fBstr_component()\fR will be in malloc'ed memory.
XBy default the substrings are part of \fIstr\fR.
XIf this option is not used \fIstr\fR will be modified
Xby \fBstr_component()\fR.
X.LP
XFinally, \fBSTR_NOFLAGS\fR may be used to specify no flags.
XThe \fIerrnop\fR argument points to an integer where the string processing
Xfunctions will deposit an error code if an error occurs.
XIf \fIerrnop\fR
Xis
X.SM NULL
Xthe error codes will be placed in \fIstr_errno\fR.
XThis is useful only if \fBSTR_RETURN_ERROR\fR is used in \fIflags\fR.
XIt is possible that \fIstr\fP is
X.SM NULL.
XIn this case, a subsequent
X.B str_setstr()
Xshould be used to specify the string to be processed.
X.LP
X.B str_component()
Xreturns successive substrings from the string associated with the
Xparser specified by \fIhandle\fR.
X.LP
X.B str_endparse()
Xdestroys the parser specified by \fIhandle\fR.
X.LP
X.B str_setstr()
Xchanges the processed string to \fInewstr\fP.
X.LP
X.B str_separator()
Xreplaces the list of separator characters with \fIsepar\fR.
XProcessing continues from the current position.
X.LP
X.B str_nextpos()
Xreturns a pointer to the rest of the string. The previous character
Xis a separator character (if \fBSTR_MALLOC\fR is not set, then the
Xprevious character is
X.SM NUL
X).
X.SH "RETURN VALUES"
X.LP
X.B str_parse()
Xreturns a parser handle or
X.SM NULL
Xif something goes wrong and \fIflags\fR & \fBSTR_RETURN_ERROR\fR is true.
XPossible \fIstr_errno\fR values:
X.RS
X.TP 20
X.SB STR_ENULLSEPAR
X\fIsepar\fR is
X.SM NULL
X.TP
X.SB STR_ENOMEM
Xthe program ran out of memory
X.RE
X.LP
X.B str_component()
Xreturns a pointer to the next substring or
X.SM NULL
Xif something goes wrong and \fIflags\fR & \fBSTR_RETURN_ERROR\fR is true.
X.LP
X.B str_setstr()
Xreturns
X.SB STR_OK
Xon success or
X.SB STR_ERR
Xon failure.
X.LP
X.B str_separator()
Xreturns
X.SB STR_OK
Xon success or
X.SB STR_ERR
Xon failure.
X.LP
X.B str_nextpos()
Xreturns a pointer or
X.SM NULL
Xif the end of string has been reached.
X.SH BUGS
X.B str_component()
Xmodifies the string unless \fBSTR_MALLOC\fR is
Xset in the parser.
X.LP
XThere should be only one parser active on a specific string. If there
Xis more than
Xone, they all must use the \fBSTR_MALLOC\fR option.
X
END_OF_FILE
if test 4131 -ne `wc -c <'libs/src/str/strparse.3'`; then
echo shar: \"'libs/src/str/strparse.3'\" unpacked with wrong size!
fi
# end of 'libs/src/str/strparse.3'
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'\" \(3633 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 2.2 1993/04/01 23:01:41 panos Exp $
X.TH STRS 3X "10 January 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 )
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 )
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.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.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
XThomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest.
XIntroduction to Algorithms.
XMcGraw-Hill 1990.
END_OF_FILE
if test 3633 -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 5 \(of 12\).
cp /dev/null ark5isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 10 11 12 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have unpacked all 12 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
------------------------------ Cut here ------------------------------
--
Panos Tsirigotis, CS grad
Pmail: Computer Science Dept., U. of Colorado @ Boulder, Boulder, CO 80309-0430
Email: panos@cs.colorado.edu