"Error" in libPW

Doug Gwyn gwyn at brl-smoke.ARPA
Thu Jun 9 11:27:38 AEST 1988


In article <2319 at quacky.mips.COM> dce at mips.COM (David Elliott) writes:
>One of the programmers here was using the regular expression stuff
>in libPW ...

This doesn't directly answer your specific question, but:
libPW exists merely to support old code from PWB/UNIX.
It should NOT be used for new applications!
In particular, use the regexp(5) stuff for regular expressions.
If you need a BSD-like interface, try something like the
following (taken from the BRL Bourne shell; you need to use
"cc -DHISTORY" when compiling):

#!/bin/sh
# Self-unpacking archive format.  To unbundle, sh this file.
echo 'regex.c' 1>&2
cat >'regex.c' <<'END OF regex.c'
/*
	BSD-style regular expression interface for UNIX System V shell

	last edit:	04-Nov-1987	D A Gwyn
*/

#if !defined(HISTORY) || defined(BSD)
#ifndef lint
char	regex_dummy;      /* some systems can't handle empty object modules */
#endif
#else

extern struct re_msg
	{
	int	number;
	char	*message;
	}	re_msgtab[];

static char	*re_err;		/* sneak path to error string */

/*	Handle error from <regexp.h>	*/

static void
re_error( n )
	register int		n;	/* error number */
	{
	register struct re_msg	*mp;

	for ( mp = re_msgtab; mp->number > 0; ++mp )
		if ( mp->number == n )
			break;

	re_err = mp->message;
	}

/* macros for <regexp.h> */
#define INIT		register char	*re_str = instring;
#define GETC()		(*re_str == '\0' ? '\0' : (int)*re_str++)
#define UNGETC( c )	--re_str
#define PEEKC()		((int)*re_str)
#define RETURN( c )	return (char *)0
#define ERROR( n )	re_error( n )

/* following for safety's sake */
#define	sed	re_sed
#define	nbra	re_nbra
#define	loc1	re_loc1
#define	loc2	re_loc2
#define	locs	re_locs
#define	circf	re_circf
#define	compile	re_cmpl			/* avoid truncated name collision! */
#define	step	re_step
#define	advance	re_advance

#include	<regexp.h>

#define	ESIZE	512
static char	re_buf[ESIZE];		/* compiled r.e. */

/*	Compile regular expression	*/

char	*
re_comp( s )				/* returns 0 or ptr to error message */
	char	*s;
	{
	re_err = (char *)0;

	if ( s != (char *)0 && *s != '\0' )
		(void)compile( s, re_buf, &re_buf[ESIZE], '\0' );
	else if ( re_buf[0] == '\0' )
		ERROR( 41 );		/* no remembered search string */
	/* else use remembered search string from previous call */

	return re_err;
	}

/*	Test for match against compiled expression	*/

int
re_exec( s )				/* returns 1 if s matches, else 0 */
	char	*s;
	{
	locs = 0;			/* ??? */
	return step( s, re_buf );
	}
#endif
END OF regex.c
echo 'redata.c' 1>&2
cat >'redata.c' <<'END OF redata.c'
/*
	messages for BSD-style regular expression interface for UNIX System V shell

	last edit:	04-Nov-1987	D A Gwyn
*/

#if !defined(HISTORY) || defined(BSD)
#ifndef lint
char	redata_dummy;      /* some systems can't handle empty object modules */
#endif
#else

struct	{
	int	number;
	char	*message;
	}	re_msgtab[] =
	{
	{	11,	"range endpoint too large"	},
	{	16,	"bad number"	},
	{	25,	"`\\digit' out of range"	},
	{	35,	"no match"	},
	{	36,	"illegal or missing delimiter"	},
	{	41,	"no remembered search string"	},
	{	42,	"'\\( \\)' imbalance"	},
	{	43,	"too many `\\(' s"	},
	{	44,	"more than 2 numbers given"	},
	{	45,	"'\\}' expected"	},
	{	46,	"first number exceeds second"	},
	{	49,	"'[ ]' imbalance"	},
	{	50,	"regular expression overflow"	},
	{	51,	"regular expression error"	},
	{	0,	"unknown r.e. error"	}
	};

#endif
END OF redata.c



More information about the Comp.unix.questions mailing list