1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-06 07:49:08 +03:00

Postgres95 1.01 Distribution - Virgin Sources

This commit is contained in:
Marc G. Fournier
1996-07-09 06:22:35 +00:00
commit d31084e9d1
868 changed files with 242656 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
#-------------------------------------------------------------------------
#
# Makefile.inc--
# Makefile for port/BSD44_derived (for OSs derived from 4.4-lite BSD)
#
# Copyright (c) 1994, Regents of the University of California
#
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/backend/port/BSD44_derived/Attic/Makefile.inc,v 1.1.1.1 1996/07/09 06:21:41 scrappy Exp $
#
#-------------------------------------------------------------------------
CFLAGS+= -DUSE_POSIX_TIME
#
# 4.4-lite BSD-derived OSs require that the lex library be included,
# in case yywrap is defined
#
LDADD+= -ll
#
# 4.4-lite BSD-derived OSs have a little trouble with partially-implemented
# dynamic loading soutines. See the comments in port-protos.h.
#
SUBSRCS= dl.c
HEADERS+= float.h machine.h port-protos.h

View File

@@ -0,0 +1,4 @@
The NetBSD port was done by Alistair G. Crooks (agc@uts.amdahl.com).
It was extended to cover Operating Systems derived from the 4.4-lite
BSD release by Alistair G. Crooks.

View File

@@ -0,0 +1,88 @@
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)dl.c 5.4 (Berkeley) 2/23/91";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#include <nlist.h>
#include <link.h>
#include <stdio.h>
#include <stdlib.h>
static char error_message[BUFSIZ];
char *
BSD44_derived_dlerror(void)
{
static char ret[BUFSIZ];
(void) strcpy(ret, error_message);
error_message[0] = 0;
return((ret[0] == 0) ? (char *) NULL : ret);
}
void *
BSD44_derived_dlopen(char *file, int num)
{
void *vp;
if ((vp = dlopen(file, num)) == (void *) NULL) {
(void) sprintf(error_message, "dlopen (%s) failed", file);
}
return(vp);
}
void *
BSD44_derived_dlsym(void *handle, char *name)
{
void *vp;
char buf[BUFSIZ];
if (*name != '_') {
(void) sprintf(buf, "_%s", name);
name = buf;
}
if ((vp = dlsym(handle, name)) == (void *) NULL) {
(void) sprintf(error_message, "dlsym (%s) failed", name);
}
return(vp);
}
void
BSD44_derived_dlclose(void *handle)
{
dlclose(handle);
}

View File

@@ -0,0 +1,30 @@
/*-------------------------------------------------------------------------
*
* float.h--
* definitions for ANSI floating point
*
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: float.h,v 1.1.1.1 1996/07/09 06:21:42 scrappy Exp $
*
* NOTES
* These come straight out of ANSI X3.159-1989 (p.18) and
* would be unnecessary if SunOS 4 were ANSI-compliant.
*
* This is only a partial listing because I'm lazy to type
* the whole thing in.
*
*-------------------------------------------------------------------------
*/
#ifndef FLOAT_H
#define FLOAT_H
#define FLT_DIG 6
#define FLT_MIN ((float) 1.17549435e-38)
#define FLT_MAX ((float) 3.40282347e+38)
#define DBL_DIG 15
#define DBL_MIN 2.2250738585072014e-308
#define DBL_MAX 1.7976931348623157e+308
#endif /* FLOAT_H */

View File

@@ -0,0 +1,19 @@
/*-------------------------------------------------------------------------
*
* machine.h--
*
*
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: machine.h,v 1.1.1.1 1996/07/09 06:21:42 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef MACHINE_H
#define MACHINE_H
#define BLCKSZ 8192
#endif

View File

@@ -0,0 +1,41 @@
/*-------------------------------------------------------------------------
*
* port-protos.h--
* port-specific prototypes for NetBSD 1.0
*
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: port-protos.h,v 1.1.1.1 1996/07/09 06:21:42 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef PORT_PROTOS_H
#define PORT_PROTOS_H
#include <sys/types.h>
#include <nlist.h>
#include <link.h>
#include "fmgr.h" /* for func_ptr */
#include "utils/dynamic_loader.h"
/* dynloader.c */
/*
* Dynamic Loader on NetBSD 1.0.
*
* this dynamic loader uses the system dynamic loading interface for shared
* libraries (ie. dlopen/dlsym/dlclose). The user must specify a shared
* library as the file to be dynamically loaded.
*
* agc - I know this is all a bit crufty, but it does work, is fairly
* portable, and works (the stipulation that the d.l. function must
* begin with an underscore is fairly tricky, and some versions of
* NetBSD (like 1.0, and 1.0A pre June 1995) have no dlerror.)
*/
#define pg_dlopen(f) BSD44_derived_dlopen(f, 1)
#define pg_dlsym BSD44_derived_dlsym
#define pg_dlclose BSD44_derived_dlclose
#define pg_dlerror BSD44_derived_dlerror
#endif /* PORT_PROTOS_H */

View File

@@ -0,0 +1,21 @@
#-------------------------------------------------------------------------
#
# Makefile.inc--
# Makefile for the port module (for code specific to various UNIX
# platforms)
#
# Copyright (c) 1994, Regents of the University of California
#
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/backend/port/Attic/Makefile.inc,v 1.1.1.1 1996/07/09 06:21:41 scrappy Exp $
#
#-------------------------------------------------------------------------
portdir= $(CURDIR)/port/$(PORTNAME)
VPATH:= $(VPATH):$(portdir)
SUBSRCS=
include $(portdir)/Makefile.inc
SRCS_PORT:= $(SUBSRCS)

View File

@@ -0,0 +1,40 @@
#-------------------------------------------------------------------------
#
# Makefile.inc--
# Makefile for port/aix (AIX specific stuff)
#
# Copyright (c) 1994, Regents of the University of California
#
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/backend/port/aix/Attic/Makefile.inc,v 1.1.1.1 1996/07/09 06:21:41 scrappy Exp $
#
#-------------------------------------------------------------------------
#
# aix has fast linkers and don't need the BIGOBJ stuff.
#
BIGOBJS=false
CFLAGS+= -DCLASS_CONFLICT -DDISABLE_XOPEN_NLS -DNEED_ISINF
LDFLAGS+= -bE:$(objdir)/$(PROG).exp
LDADD+= -ll -lld
HEADERS+= dlfcn.h machine.h port-protos.h
SUBSRCS+= dlfcn.c
${PROG}.exp: ${PROG}.noexp
mv -f $(objdir)/${PROG}.noexp $(objdir)/${PROG}
$(CURDIR)/port/aix/mkldexport.sh $(objdir)/${PROG} ${BINDIR} > $(objdir)/${PROG}.exp
mv -f $(objdir)/${PROG} $(objdir)/${PROG}.noexp
${PROG}.noexp: ${OBJS}
touch -f $(objdir)/${PROG}.exp
${CC} ${LDFLAGS} -o $(objdir)/${PROG}.noexp ${OBJS} ${LDADD}
EXPORTS= ${PROG}.exp
CLEANFILES+= ${PROG}.noexp ${PROG}.exp

View File

@@ -0,0 +1,167 @@
Copyright (c) 1992,1993,1995, Jens-Uwe Mager, Helios Software GmbH
Not derived from licensed software.
Permission is granted to freely use, copy, modify, and redistribute
this software, provided that no attempt is made to gain profit from it,
the author is not construed to be liable for any results of using the
software, alterations are clearly marked as such, and this notice is
not modified.
libdl.a
-------
This is an emulation library to emulate the SunOS/System V.4 functions
to access the runtime linker. The functions are emulated by using the
AIX load() function and by reading the .loader section of the loaded
module to find the exports. The to be loaded module should be linked as
follows (if using AIX 3):
cc -o module.so -bM:SRE -bE:module.exp -e _nostart $(OBJS)
For AIX 4:
cc -o module.so -bM:SRE -bE:module.exp -bnoentry $(OBJS)
The module export file contains the symbols to be exported. Because
this library uses the loader section, the final module.so file can be
stripped. C++ users should build their shared objects using the script
makeC++SharedLib (part of the IBM C++ compiler), this will make sure
that constructors and destructors for static and global objects will be
called upon loading and unloading the module.
Usage
-----
void *dlopen(const char *path, int mode);
This routine loads the module pointed to by path and reads its export
table. If the path does not contain a '/' character, dlopen will search
for the module using the LIBPATH environment variable. It returns an
opaque handle to the module or NULL on error. The mode parameter can be
either RTLD_LAZY (for lazy function binding) or RTLD_NOW for immediate
function binding. The AIX implementation currently does treat RTLD_NOW
the same as RTLD_LAZY. The flag RTLD_GLOBAL might be or'ed into the
mode parameter to allow loaded modules to bind to global variables or
functions in other loaded modules loaded by dlopen(). If RTLD_GLOBAL is
not specified, only globals from the main part of the executable or
shared libraries are used to look for undefined symbols in loaded
modules.
void *dlsym(void *handle, const char *symbol);
This routine searches for the symbol in the module referred to by
handle and returns its address. If the symbol could not be found, the
function returns NULL. The return value must be casted to a proper
function pointer before it can be used. SunOS/System V.4 allow handle
to be a NULL pointer to refer to the module the call is made from, this
is not implemented.
int dlclose(void *handle);
This routine unloads the module referred to by the handle and disposes
of any local storage. this function returns -1 on failure.
char *dlerror(void);
This routine can be used to retrieve a text message describing the most
recent error that occured on on of the above routines. This function
returns NULL if there is not error information.
Initialization and termination handlers
---------------------------------------
The emulation provides for an initialization and a termination
handler. The dlfcn.h file contains a structure declaration named
dl_info with following members:
void (*init)(void);
void (*fini)(void);
The init function is called upon first referencing the library. The
fini function is called at dlclose() time or when the process exits.
The module should declare a variable named dl_info that contains this
structure which must be exported. These functions correspond to the
documented _init() and _fini() functions of SunOS 4.x, but these are
appearently not implemented in SunOS. When using SunOS 5.0, these
correspond to #pragma init and #pragma fini respectively. At the same
time any static or global C++ object's constructors or destructors will
be called.
Jens-Uwe Mager
HELIOS Software GmbH
Lavesstr. 80
30159 Hannover
Germany
Phone: +49 511 36482-0
FAX: +49 511 36482-69
AppleLink: helios.de Attn: Jens-Uwe Mager
Internet: jum@helios.de
Revison History
---------------
SCCS/s.dlfcn.h:
D 1.4 95/04/25 09:36:52 jum 4 3 00018/00004/00028
MRs:
COMMENTS:
added RTLD_GLOBAL, include and C++ guards
D 1.3 92/12/27 20:58:32 jum 3 2 00001/00001/00031
MRs:
COMMENTS:
we always have prototypes on RS/6000
D 1.2 92/08/16 17:45:11 jum 2 1 00009/00000/00023
MRs:
COMMENTS:
added dl_info structure to implement initialize and terminate functions
D 1.1 92/08/02 18:08:45 jum 1 0 00023/00000/00000
MRs:
COMMENTS:
Erstellungsdatum und -uhrzeit 92/08/02 18:08:45 von jum
SCCS/s.dlfcn.c:
D 1.7 95/08/14 19:08:38 jum 8 6 00026/00004/00502
MRs:
COMMENTS:
Integrated the fixes from Kirk Benell (kirk@rsinc.com) to allow loading of
shared objects generated under AIX 4. Fixed bug that symbols with exactly
8 characters would use garbage characters from the following symbol value.
D 1.6 95/04/25 09:38:03 jum 6 5 00046/00006/00460
MRs:
COMMENTS:
added handling of C++ static constructors and destructors, added RTLD_GLOBAL to bind against other loaded modules
D 1.5 93/02/14 20:14:17 jum 5 4 00002/00000/00464
MRs:
COMMENTS:
added path to dlopen error message to make clear where there error occured.
D 1.4 93/01/03 19:13:56 jum 4 3 00061/00005/00403
MRs:
COMMENTS:
to allow calling symbols in the main module call load with L_NOAUTODEFER and
do a loadbind later with the main module.
D 1.3 92/12/27 20:59:55 jum 3 2 00066/00008/00342
MRs:
COMMENTS:
added search by L_GETINFO if module got loaded by LIBPATH
D 1.2 92/08/16 17:45:43 jum 2 1 00074/00006/00276
MRs:
COMMENTS:
implemented initialize and terminate functions, added reference counting to avoid multiple loads of the same library
D 1.1 92/08/02 18:08:45 jum 1 0 00282/00000/00000
MRs:
COMMENTS:
Erstellungsdatum und -uhrzeit 92/08/02 18:08:45 von jum

View File

@@ -0,0 +1,528 @@
/*
* @(#)dlfcn.c 1.7 revision of 95/08/14 19:08:38
* This is an unpublished work copyright (c) 1992 HELIOS Software GmbH
* 30159 Hannover, Germany
*/
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/ldr.h>
#include <a.out.h>
#include <ldfcn.h>
#include "dlfcn.h"
/*
* We simulate dlopen() et al. through a call to load. Because AIX has
* no call to find an exported symbol we read the loader section of the
* loaded module and build a list of exported symbols and their virtual
* address.
*/
typedef struct {
char *name; /* the symbols's name */
void *addr; /* its relocated virtual address */
} Export, *ExportPtr;
/*
* xlC uses the following structure to list its constructors and
* destructors. This is gleaned from the output of munch.
*/
typedef struct {
void (*init)(void); /* call static constructors */
void (*term)(void); /* call static destructors */
} Cdtor, *CdtorPtr;
/*
* The void * handle returned from dlopen is actually a ModulePtr.
*/
typedef struct Module {
struct Module *next;
char *name; /* module name for refcounting */
int refCnt; /* the number of references */
void *entry; /* entry point from load */
struct dl_info *info; /* optional init/terminate functions */
CdtorPtr cdtors; /* optional C++ constructors */
int nExports; /* the number of exports found */
ExportPtr exports; /* the array of exports */
} Module, *ModulePtr;
/*
* We keep a list of all loaded modules to be able to call the fini
* handlers and destructors at atexit() time.
*/
static ModulePtr modList;
/*
* The last error from one of the dl* routines is kept in static
* variables here. Each error is returned only once to the caller.
*/
static char errbuf[BUFSIZ];
static int errvalid;
extern char *strdup(const char *);
static void caterr(char *);
static int readExports(ModulePtr);
static void terminate(void);
static void *findMain(void);
void *dlopen(const char *path, int mode)
{
register ModulePtr mp;
static void *mainModule;
/*
* Upon the first call register a terminate handler that will
* close all libraries. Also get a reference to the main module
* for use with loadbind.
*/
if (!mainModule) {
if ((mainModule = findMain()) == NULL)
return NULL;
atexit(terminate);
}
/*
* Scan the list of modules if we have the module already loaded.
*/
for (mp = modList; mp; mp = mp->next)
if (strcmp(mp->name, path) == 0) {
mp->refCnt++;
return mp;
}
if ((mp = (ModulePtr)calloc(1, sizeof(*mp))) == NULL) {
errvalid++;
strcpy(errbuf, "calloc: ");
strcat(errbuf, strerror(errno));
return NULL;
}
if ((mp->name = strdup(path)) == NULL) {
errvalid++;
strcpy(errbuf, "strdup: ");
strcat(errbuf, strerror(errno));
free(mp);
return NULL;
}
/*
* load should be declared load(const char *...). Thus we
* cast the path to a normal char *. Ugly.
*/
if ((mp->entry = (void *)load((char *)path, L_NOAUTODEFER, NULL)) == NULL) {
free(mp->name);
free(mp);
errvalid++;
strcpy(errbuf, "dlopen: ");
strcat(errbuf, path);
strcat(errbuf, ": ");
/*
* If AIX says the file is not executable, the error
* can be further described by querying the loader about
* the last error.
*/
if (errno == ENOEXEC) {
char *tmp[BUFSIZ/sizeof(char *)];
if (loadquery(L_GETMESSAGES, tmp, sizeof(tmp)) == -1)
strcpy(errbuf, strerror(errno));
else {
char **p;
for (p = tmp; *p; p++)
caterr(*p);
}
} else
strcat(errbuf, strerror(errno));
return NULL;
}
mp->refCnt = 1;
mp->next = modList;
modList = mp;
if (loadbind(0, mainModule, mp->entry) == -1) {
dlclose(mp);
errvalid++;
strcpy(errbuf, "loadbind: ");
strcat(errbuf, strerror(errno));
return NULL;
}
/*
* If the user wants global binding, loadbind against all other
* loaded modules.
*/
if (mode & RTLD_GLOBAL) {
register ModulePtr mp1;
for (mp1 = mp->next; mp1; mp1 = mp1->next)
if (loadbind(0, mp1->entry, mp->entry) == -1) {
dlclose(mp);
errvalid++;
strcpy(errbuf, "loadbind: ");
strcat(errbuf, strerror(errno));
return NULL;
}
}
if (readExports(mp) == -1) {
dlclose(mp);
return NULL;
}
/*
* If there is a dl_info structure, call the init function.
*/
if (mp->info = (struct dl_info *)dlsym(mp, "dl_info")) {
if (mp->info->init)
(*mp->info->init)();
} else
errvalid = 0;
/*
* If the shared object was compiled using xlC we will need
* to call static constructors (and later on dlclose destructors).
*/
if (mp->cdtors = (CdtorPtr)dlsym(mp, "__cdtors")) {
while (mp->cdtors->init) {
(*mp->cdtors->init)();
mp->cdtors++;
}
} else
errvalid = 0;
return mp;
}
/*
* Attempt to decipher an AIX loader error message and append it
* to our static error message buffer.
*/
static void caterr(char *s)
{
register char *p = s;
while (*p >= '0' && *p <= '9')
p++;
switch(atoi(s)) {
case L_ERROR_TOOMANY:
strcat(errbuf, "to many errors");
break;
case L_ERROR_NOLIB:
strcat(errbuf, "can't load library");
strcat(errbuf, p);
break;
case L_ERROR_UNDEF:
strcat(errbuf, "can't find symbol");
strcat(errbuf, p);
break;
case L_ERROR_RLDBAD:
strcat(errbuf, "bad RLD");
strcat(errbuf, p);
break;
case L_ERROR_FORMAT:
strcat(errbuf, "bad exec format in");
strcat(errbuf, p);
break;
case L_ERROR_ERRNO:
strcat(errbuf, strerror(atoi(++p)));
break;
default:
strcat(errbuf, s);
break;
}
}
void *dlsym(void *handle, const char *symbol)
{
register ModulePtr mp = (ModulePtr)handle;
register ExportPtr ep;
register int i;
/*
* Could speed up the search, but I assume that one assigns
* the result to function pointers anyways.
*/
for (ep = mp->exports, i = mp->nExports; i; i--, ep++)
if (strcmp(ep->name, symbol) == 0)
return ep->addr;
errvalid++;
strcpy(errbuf, "dlsym: undefined symbol ");
strcat(errbuf, symbol);
return NULL;
}
char *dlerror(void)
{
if (errvalid) {
errvalid = 0;
return errbuf;
}
return NULL;
}
int dlclose(void *handle)
{
register ModulePtr mp = (ModulePtr)handle;
int result;
register ModulePtr mp1;
if (--mp->refCnt > 0)
return 0;
if (mp->info && mp->info->fini)
(*mp->info->fini)();
if (mp->cdtors)
while (mp->cdtors->term) {
(*mp->cdtors->term)();
mp->cdtors++;
}
result = unload(mp->entry);
if (result == -1) {
errvalid++;
strcpy(errbuf, strerror(errno));
}
if (mp->exports) {
register ExportPtr ep;
register int i;
for (ep = mp->exports, i = mp->nExports; i; i--, ep++)
if (ep->name)
free(ep->name);
free(mp->exports);
}
if (mp == modList)
modList = mp->next;
else {
for (mp1 = modList; mp1; mp1 = mp1->next)
if (mp1->next == mp) {
mp1->next = mp->next;
break;
}
}
free(mp->name);
free(mp);
return result;
}
static void terminate(void)
{
while (modList)
dlclose(modList);
}
/*
* Build the export table from the XCOFF .loader section.
*/
static int readExports(ModulePtr mp)
{
LDFILE *ldp = NULL;
SCNHDR sh, shdata;
LDHDR *lhp;
char *ldbuf;
LDSYM *ls;
int i;
ExportPtr ep;
if ((ldp = ldopen(mp->name, ldp)) == NULL) {
struct ld_info *lp;
char *buf;
int size = 4*1024;
if (errno != ENOENT) {
errvalid++;
strcpy(errbuf, "readExports: ");
strcat(errbuf, strerror(errno));
return -1;
}
/*
* The module might be loaded due to the LIBPATH
* environment variable. Search for the loaded
* module using L_GETINFO.
*/
if ((buf = malloc(size)) == NULL) {
errvalid++;
strcpy(errbuf, "readExports: ");
strcat(errbuf, strerror(errno));
return -1;
}
while ((i = loadquery(L_GETINFO, buf, size)) == -1 && errno == ENOMEM) {
free(buf);
size += 4*1024;
if ((buf = malloc(size)) == NULL) {
errvalid++;
strcpy(errbuf, "readExports: ");
strcat(errbuf, strerror(errno));
return -1;
}
}
if (i == -1) {
errvalid++;
strcpy(errbuf, "readExports: ");
strcat(errbuf, strerror(errno));
free(buf);
return -1;
}
/*
* Traverse the list of loaded modules. The entry point
* returned by load() does actually point to the data
* segment origin.
*/
lp = (struct ld_info *)buf;
while (lp) {
if (lp->ldinfo_dataorg == mp->entry) {
ldp = ldopen(lp->ldinfo_filename, ldp);
break;
}
if (lp->ldinfo_next == 0)
lp = NULL;
else
lp = (struct ld_info *)((char *)lp + lp->ldinfo_next);
}
free(buf);
if (!ldp) {
errvalid++;
strcpy(errbuf, "readExports: ");
strcat(errbuf, strerror(errno));
return -1;
}
}
if (TYPE(ldp) != U802TOCMAGIC) {
errvalid++;
strcpy(errbuf, "readExports: bad magic");
while(ldclose(ldp) == FAILURE)
;
return -1;
}
/*
* Get the padding for the data section. This is needed for
* AIX 4.1 compilers. This is used when building the final
* function pointer to the exported symbol.
*/
if (ldnshread(ldp, _DATA, &shdata) != SUCCESS) {
errvalid++;
strcpy(errbuf, "readExports: cannot read data section header");
while(ldclose(ldp) == FAILURE)
;
return -1;
}
if (ldnshread(ldp, _LOADER, &sh) != SUCCESS) {
errvalid++;
strcpy(errbuf, "readExports: cannot read loader section header");
while(ldclose(ldp) == FAILURE)
;
return -1;
}
/*
* We read the complete loader section in one chunk, this makes
* finding long symbol names residing in the string table easier.
*/
if ((ldbuf = (char *)malloc(sh.s_size)) == NULL) {
errvalid++;
strcpy(errbuf, "readExports: ");
strcat(errbuf, strerror(errno));
while(ldclose(ldp) == FAILURE)
;
return -1;
}
if (FSEEK(ldp, sh.s_scnptr, BEGINNING) != OKFSEEK) {
errvalid++;
strcpy(errbuf, "readExports: cannot seek to loader section");
free(ldbuf);
while(ldclose(ldp) == FAILURE)
;
return -1;
}
if (FREAD(ldbuf, sh.s_size, 1, ldp) != 1) {
errvalid++;
strcpy(errbuf, "readExports: cannot read loader section");
free(ldbuf);
while(ldclose(ldp) == FAILURE)
;
return -1;
}
lhp = (LDHDR *)ldbuf;
ls = (LDSYM *)(ldbuf+LDHDRSZ);
/*
* Count the number of exports to include in our export table.
*/
for (i = lhp->l_nsyms; i; i--, ls++) {
if (!LDR_EXPORT(*ls))
continue;
mp->nExports++;
}
if ((mp->exports = (ExportPtr)calloc(mp->nExports, sizeof(*mp->exports))) == NULL) {
errvalid++;
strcpy(errbuf, "readExports: ");
strcat(errbuf, strerror(errno));
free(ldbuf);
while(ldclose(ldp) == FAILURE)
;
return -1;
}
/*
* Fill in the export table. All entries are relative to
* the entry point we got from load.
*/
ep = mp->exports;
ls = (LDSYM *)(ldbuf+LDHDRSZ);
for (i = lhp->l_nsyms; i; i--, ls++) {
char *symname;
char tmpsym[SYMNMLEN+1];
if (!LDR_EXPORT(*ls))
continue;
if (ls->l_zeroes == 0)
symname = ls->l_offset+lhp->l_stoff+ldbuf;
else {
/*
* The l_name member is not zero terminated, we
* must copy the first SYMNMLEN chars and make
* sure we have a zero byte at the end.
*/
strncpy(tmpsym, ls->l_name, SYMNMLEN);
tmpsym[SYMNMLEN] = '\0';
symname = tmpsym;
}
ep->name = strdup(symname);
ep->addr = (void *)((unsigned long)mp->entry +
ls->l_value - shdata.s_vaddr);
ep++;
}
free(ldbuf);
while(ldclose(ldp) == FAILURE)
;
return 0;
}
/*
* Find the main modules entry point. This is used as export pointer
* for loadbind() to be able to resolve references to the main part.
*/
static void * findMain(void)
{
struct ld_info *lp;
char *buf;
int size = 4*1024;
int i;
void *ret;
if ((buf = malloc(size)) == NULL) {
errvalid++;
strcpy(errbuf, "findMain: ");
strcat(errbuf, strerror(errno));
return NULL;
}
while ((i = loadquery(L_GETINFO, buf, size)) == -1 && errno == ENOMEM) {
free(buf);
size += 4*1024;
if ((buf = malloc(size)) == NULL) {
errvalid++;
strcpy(errbuf, "findMain: ");
strcat(errbuf, strerror(errno));
return NULL;
}
}
if (i == -1) {
errvalid++;
strcpy(errbuf, "findMain: ");
strcat(errbuf, strerror(errno));
free(buf);
return NULL;
}
/*
* The first entry is the main module. The entry point
* returned by load() does actually point to the data
* segment origin.
*/
lp = (struct ld_info *)buf;
ret = lp->ldinfo_dataorg;
free(buf);
return ret;
}

View File

@@ -0,0 +1,46 @@
/*
* @(#)dlfcn.h 1.4 revision of 95/04/25 09:36:52
* This is an unpublished work copyright (c) 1992 HELIOS Software GmbH
* 30159 Hannover, Germany
*/
#ifndef __dlfcn_h__
#define __dlfcn_h__
#ifdef __cplusplus
extern "C" {
#endif
/*
* Mode flags for the dlopen routine.
*/
#define RTLD_LAZY 1 /* lazy function call binding */
#define RTLD_NOW 2 /* immediate function call binding */
#define RTLD_GLOBAL 0x100 /* allow symbols to be global */
/*
* To be able to intialize, a library may provide a dl_info structure
* that contains functions to be called to initialize and terminate.
*/
struct dl_info {
void (*init)(void);
void (*fini)(void);
};
#if __STDC__ || defined(_IBMR2)
void *dlopen(const char *path, int mode);
void *dlsym(void *handle, const char *symbol);
char *dlerror(void);
int dlclose(void *handle);
#else
void *dlopen();
void *dlsym();
char *dlerror();
int dlclose();
#endif
#ifdef __cplusplus
}
#endif
#endif /* __dlfcn_h__ */

View File

@@ -0,0 +1,19 @@
/*-------------------------------------------------------------------------
*
* machine.h--
*
*
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: machine.h,v 1.1.1.1 1996/07/09 06:21:41 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef MACHINE_H
#define MACHINE_H
#define BLCKSZ 8192
#endif

View File

@@ -0,0 +1,42 @@
#!/bin/sh
#
# mkldexport
# create an AIX exports file from an object file
#
# Usage:
# mkldexport objectfile [location]
# where
# objectfile is the current location of the object file.
# location is the eventual (installed) location of the
# object file (if different from the current
# working directory).
#
# [This file comes from the Postgres 4.2 distribution. - ay 7/95]
#
# Header: /usr/local/devel/postgres/src/tools/mkldexport/RCS/mkldexport.sh,v 1.2 1994/03/13 04:59:12 aoki Exp
#
# setting this to nm -B might be better
NM = /usr/ucb/nm
CMDNAME=`basename $0`
if [ -z "$1" ]; then
echo "Usage: $CMDNAME object [location]"
exit 1
fi
OBJNAME=`basename $1`
if [ "`basename $OBJNAME`" != "`basename $OBJNAME .o`" ]; then
OBJNAME=`basename $OBJNAME .o`.so
fi
if [ -z "$2" ]; then
echo '#!'
else
echo '#!' $2/$OBJNAME
fi
$NM -g $1 | \
egrep ' [TD] ' | \
sed -e 's/.* //' | \
egrep -v '\$' | \
sed -e 's/^[.]//' | \
sort | \
uniq

View File

@@ -0,0 +1,25 @@
/*-------------------------------------------------------------------------
*
* port-protos.h--
* port-specific prototypes for AIX
*
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: port-protos.h,v 1.1.1.1 1996/07/09 06:21:41 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef PORT_PROTOS_H
#define PORT_PROTOS_H
#include "dlfcn.h" /* this is from jum's libdl package */
/* dynloader.c */
#define pg_dlopen(f) dlopen(filename, RTLD_LAZY)
#define pg_dlsym(h,f) dlsym(h, f)
#define pg_dlclose(h) dlclose(h)
#define pg_dlerror() dlerror()
#endif /* PORT_PROTOS_H */

View File

@@ -0,0 +1,27 @@
#-------------------------------------------------------------------------
#
# Makefile.inc--
# Makefile for port/alpha (Alpha OSF/1 specific stuff)
#
# Copyright (c) 1994, Regents of the University of California
#
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/backend/port/alpha/Attic/Makefile.inc,v 1.1.1.1 1996/07/09 06:21:42 scrappy Exp $
#
#-------------------------------------------------------------------------
CFLAGS+= -DUSE_POSIX_TIME -DDISABLE_XOPEN_NLS -DNEED_ISINF -DHAS_LONG_LONG
LDADD+= -lln
#
# The YACC grammar is too big..
#
#.if !defined(CDEBUG)
##CFLAGS+= -Olimit 2000
#.endif
HEADERS+= machine.h port-protos.h
SUBSRCS= port.c

View File

@@ -0,0 +1,19 @@
/*-------------------------------------------------------------------------
*
* machine.h--
*
*
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: machine.h,v 1.1.1.1 1996/07/09 06:21:42 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef MACHINE_H
#define MACHINE_H
#define BLCKSZ 8192
#endif

View File

@@ -0,0 +1,39 @@
/*-------------------------------------------------------------------------
*
* port-protos.h--
* prototypes for OSF/1-specific routines
*
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: port-protos.h,v 1.1.1.1 1996/07/09 06:21:42 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef PORT_PROTOS_H
#define PORT_PROTOS_H
#include <dlfcn.h>
#include "utils/dynamic_loader.h"
/* dynloader.c */
/*
* Dynamic Loader on Alpha OSF/1.x
*
* this dynamic loader uses the system dynamic loading interface for shared
* libraries (ie. dlopen/dlsym/dlclose). The user must specify a shared
* library as the file to be dynamically loaded.
*
*/
#define pg_dlopen(f) dlopen(f, RTLD_LAZY)
#define pg_dlsym(h, f) ((func_ptr)dlsym(h, f))
#define pg_dlclose(h) dlclose(h)
#define pg_dlerror() dlerror()
/* port.c */
extern void init_address_fixup(void);
#endif /* PORT_PROTOS_H */

View File

@@ -0,0 +1,34 @@
/*-------------------------------------------------------------------------
*
* port.c--
* OSF/1-specific routines
*
* Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/port/alpha/Attic/port.c,v 1.1.1.1 1996/07/09 06:21:42 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
#include <sys/types.h>
#include <sys/sysinfo.h>
#include <sys/proc.h>
#include "c.h"
#include "utils/elog.h"
void
init_address_fixup()
{
#ifdef NOFIXADE
int buffer[] = { SSIN_UACPROC, UAC_SIGBUS };
#endif /* NOFIXADE */
#ifdef NOPRINTADE
int buffer[] = { SSIN_UACPROC, UAC_NOPRINT };
#endif /* NOPRINTADE */
if (setsysinfo(SSI_NVPAIRS, buffer, 1, (caddr_t) NULL,
(unsigned long) NULL) < 0) {
elog(NOTICE, "setsysinfo failed: %d\n", errno);
}
}

View File

@@ -0,0 +1,15 @@
#-------------------------------------------------------------------------
#
# Makefile.inc--
# Makefile for port/bsdi
#
# NOTES
# The BSD/OS port is included here by courtesy of Kurt Lidl.
#
# (5) 1994, Kurt Lidl, lidl@pix.com
#
#-------------------------------------------------------------------------
CFLAGS+=-DUSE_POSIX_TIME -DNEED_CBRT
LDADD+= -ldld -lipc
SUBSRCS= dynloader.c

View File

@@ -0,0 +1,93 @@
/*-------------------------------------------------------------------------
*
* dynloader.c--
* Dynamic Loader for Postgres for Linux, generated from those for
* Ultrix.
*
* You need to install the dld library on your Linux system!
*
* Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* /usr/local/devel/pglite/cvs/src/backend/port/linux/dynloader.c,v 1.1.1.1 1994/11/07 05:19:37 andrew Exp
*
*-------------------------------------------------------------------------
*/
#include <stdio.h>
#include <dld.h>
#include "postgres.h"
#include "port-protos.h"
#include "utils/elog.h"
#include "fmgr.h"
extern char pg_pathname[];
void *
pg_dlopen(char *filename)
{
static int dl_initialized= 0;
/*
* initializes the dynamic loader with the executable's pathname.
* (only needs to do this the first time pg_dlopen is called.)
*/
if (!dl_initialized) {
if (dld_init (dld_find_executable (pg_pathname))) {
return NULL;
}
/*
* if there are undefined symbols, we want dl to search from the
* following libraries also.
*/
dl_initialized= 1;
}
/*
* link the file, then check for undefined symbols!
*/
if (dld_link(filename)) {
return NULL;
}
/*
* If undefined symbols: try to link with the C and math libraries!
* This could be smarter, if the dynamic linker was able to handle
* shared libs!
*/
if(dld_undefined_sym_count > 0) {
if (dld_link("/usr/lib/libc.a")) {
elog(NOTICE, "dld: Cannot link C library!");
return NULL;
}
if(dld_undefined_sym_count > 0) {
if (dld_link("/usr/lib/libm.a")) {
elog(NOTICE, "dld: Cannot link math library!");
return NULL;
}
if(dld_undefined_sym_count > 0) {
int count = dld_undefined_sym_count;
char **list= dld_list_undefined_sym();
/* list the undefined symbols, if any */
elog(NOTICE, "dld: Undefined:");
do {
elog(NOTICE, " %s", *list);
list++;
count--;
} while(count > 0);
dld_unlink_by_file(filename, 1);
return NULL;
}
}
}
return (void *) strdup(filename);
}
char *
pg_dlerror()
{
return dld_strerror(dld_errno);
}

View File

@@ -0,0 +1,18 @@
/*-------------------------------------------------------------------------
*
* machine.h--
*
*
*
* Copyright (c) 1994, Regents of the University of California
*
* machine.h,v 1.1.1.1 1994/11/07 05:19:37 andrew Exp
*
*-------------------------------------------------------------------------
*/
#ifndef MACHINE_H
#define MACHINE_H
#define BLCKSZ 8192
#endif

View File

@@ -0,0 +1,33 @@
/*-------------------------------------------------------------------------
*
* port-protos.h--
* port-specific prototypes for SunOS 4
*
*
* Copyright (c) 1994, Regents of the University of California
*
* port-protos.h,v 1.2 1995/05/25 22:51:03 andrew Exp
*
*-------------------------------------------------------------------------
*/
#ifndef PORT_PROTOS_H
#define PORT_PROTOS_H
#include "fmgr.h" /* for func_ptr */
#include "utils/dynamic_loader.h"
/* dynloader.c */
#ifndef LINUX_ELF
#define pg_dlsym(handle, funcname) ((func_ptr) dld_get_func((funcname)))
#define pg_dlclose(handle) ({ dld_unlink_by_file(handle, 1); free(handle); })
#else
#define pg_dlopen(f) dlopen(f, 1)
#define pg_dlsym dlsym
#define pg_dlclose dlclose
#define pg_dlerror dlerror
#endif
/* port.c */
#endif /* PORT_PROTOS_H */

View File

@@ -0,0 +1,13 @@
/*-------------------------------------------------------------------------
*
* port.c--
* Linux-specific routines
*
* Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* /usr/local/devel/pglite/cvs/src/backend/port/linux/port.c,v 1.1.1.1 1994/11/07 05:19:38 andrew Exp
*
*-------------------------------------------------------------------------
*/

View File

@@ -0,0 +1,68 @@
#-------------------------------------------------------------------------
#
# Makefile.inc--
# Makefile for port/hpux (HP-UX specific stuff)
#
# Copyright (c) 1994, Regents of the University of California
#
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/backend/port/hpux/Attic/Makefile.inc,v 1.1.1.1 1996/07/09 06:21:43 scrappy Exp $
#
#-------------------------------------------------------------------------
#
# HP-UX needs:
# -W l,-E export symbols for linking with the shared libraries
# dynamic loader
# -W p,-H400000 expand cpp #define table size so the Nodes files don't
# break it
#
# -W p,-H400000
ifeq ($(CC), cc)
CFLAGS+= -W l,-E
LDFLAGS+= -W l,-E
LDADD+= -ll -ldld
else
ifeq ($(CC), gcc)
LDADD+= -ll /usr/lib/libdld.sl
endif
endif
CFLAGS+= -DUSE_POSIX_TIME
#
# cbrt(3m) and rint(3m) are missing from 8.07.
# cbrt(3m) and rint(3m) are broken in 9.01.
# cbrt(3m) seems to be missing on 9.00 even though it is documented.
#
CFLAGS+= -DNEED_RINT -DNEED_CBRT
#
# The #pragma trick required on 8.07 no longer works -- the #pragma
# is thoroughly broken. However, the +u flag has been extended to
# handle alignment requirement arguments (defaulting to 2) for things
# other than struct references, so the #pragma is no longer needed.
#
#
# (1) The YACC grammar is too big..
# (HP-UX 9.0x, x<2, added basic block limits for +O2; 9.0x, x>=2, changed
# the syntax to something else.)
#
# (2) The 9.00 optimizer chokes on some of our source.
#
#.if (${HPUX_MAJOR} == "09")
#. if !defined(CDEBUG)
#. if (${HPUX_MINOR} == "00" || ${HPUX_MINOR} == "01")
#CFLAGS+= +Obb600
#CFLAGS+= -DWEAK_C_OPTIMIZER
#. else
#CFLAGS+= +Onolimit
#. endif
#. endif
#.endif
HEADERS+= fixade.h machine.h port-protos.h
SUBSRCS+= dynloader.c port.c tas.s

View File

@@ -0,0 +1,57 @@
/*-------------------------------------------------------------------------
*
* dynloader.c--
* dynamic loader for HP-UX using the shared library mechanism
*
* Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/port/hpux/Attic/dynloader.c,v 1.1.1.1 1996/07/09 06:21:43 scrappy Exp $
*
* NOTES
* all functions are defined here -- it's impossible to trace the
* shl_* routines from the bundled HP-UX debugger.
*
*-------------------------------------------------------------------------
*/
/* System includes */
#include <stdio.h>
#include <a.out.h>
#include <dl.h>
#include "c.h"
#include "fmgr.h"
#include "utils/dynamic_loader.h"
#include "port-protos.h"
void *
pg_dlopen(char *filename)
{
shl_t handle = shl_load(filename, BIND_DEFERRED, 0);
return((void *) handle);
}
func_ptr
pg_dlsym(void *handle, char *funcname)
{
func_ptr f;
if (shl_findsym((shl_t *) &handle, funcname, TYPE_PROCEDURE, &f) == -1) {
f = (func_ptr) NULL;
}
return(f);
}
void
pg_dlclose(void *handle)
{
shl_unload((shl_t) handle);
}
char *
pg_dlerror()
{
static char errmsg[]= "shl_load failed";
return errmsg;
}

View File

@@ -0,0 +1,63 @@
/*-------------------------------------------------------------------------
*
* fixade.h--
* compiler tricks to make things work while POSTGRES does non-native
* dereferences on PA-RISC.
*
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: fixade.h,v 1.1.1.1 1996/07/09 06:21:43 scrappy Exp $
*
* NOTES
* This must be included in EVERY source file.
*
*-------------------------------------------------------------------------
*/
#ifndef FIXADE_H
#define FIXADE_H
#if !defined(NOFIXADE)
#if defined(HP_S500_ALIGN)
/* ----------------
* This cheesy hack turns ON unaligned-access fixup on H-P PA-RISC;
* the resulting object files contain code that explicitly handles
* realignment on reference, so it slows memory access down by a
* considerable factor. It must be used in conjunction with the +u
* flag to cc. The #pragma is included in c.h to be safe since EVERY
* source file that performs unaligned access must contain the #pragma.
* ----------------
*/
#pragma HP_ALIGN HPUX_NATURAL_S500
#if defined(BROKEN_STRUCT_INIT)
/* ----------------
* This is so bogus. The HP-UX 9.01 compiler has totally broken
* struct initialization code. It actually length-checks ALL
* array initializations within structs against the FIRST one that
* it sees (when #pragma HP_ALIGN HPUX_NATURAL_S500 is defined)..
* we have to throw in this unused structure before struct varlena
* is defined.
*
* XXX guess you don't need the #pragma anymore after all :-)
* since no one looks at this except me i think i'll just leave
* this here for now..
* ----------------
*/
struct HP_WAY_BOGUS {
char hpwb_bogus[8192];
};
struct HP_TOO_BOGUS {
int hptb_bogus[8192];
};
#endif /* BROKEN_STRUCT_INIT */
#endif /* HP_S500_ALIGN */
#if defined(WEAK_C_OPTIMIZER)
#pragma OPT_LEVEL 1
#endif /* WEAK_C_OPTIMIZER */
#endif /* !NOFIXADE */
#endif /* FIXADE_H */

View File

@@ -0,0 +1,18 @@
/*-------------------------------------------------------------------------
*
* machine.h--
*
*
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: machine.h,v 1.1.1.1 1996/07/09 06:21:43 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef MACHINE_H
#define MACHINE_H
#define BLCKSZ 8192
#endif

View File

@@ -0,0 +1,34 @@
/*-------------------------------------------------------------------------
*
* port-protos.h--
* port-specific prototypes for HP-UX
*
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: port-protos.h,v 1.1.1.1 1996/07/09 06:21:43 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef PORT_PROTOS_H
#define PORT_PROTOS_H
#include <sys/resource.h> /* for struct rusage */
#include <dl.h> /* for shl_t */
#include "utils/dynamic_loader.h"
/* dynloader.c */
/* pg_dl{open,close,sym} prototypes are in utils/dynamic_loader.h */
/* port.c */
extern int init_address_fixup(void);
extern double rint(double x);
extern double cbrt(double x);
extern long random(void);
extern void srandom(int seed);
extern int getrusage(int who, struct rusage *ru);
#endif /* PORT_PROTOS_H */

View File

@@ -0,0 +1,47 @@
/*-------------------------------------------------------------------------
*
* port.c--
* port-specific routines for HP-UX
*
* Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/port/hpux/Attic/port.c,v 1.1.1.1 1996/07/09 06:21:43 scrappy Exp $
*
* NOTES
* For the most part, this file gets around some non-POSIX calls
* in POSTGRES.
*
*-------------------------------------------------------------------------
*/
#include <unistd.h> /* for rand()/srand() prototypes */
#include <math.h> /* for pow() prototype */
#include <sys/syscall.h> /* for syscall #defines */
#include "c.h"
void
init_address_fixup()
{
/*
* On PA-RISC, unaligned access fixup is handled by the compiler,
* not by the kernel.
*/
}
long
random()
{
return(lrand48());
}
void srandom(int seed)
{
srand48((long int) seed);
}
getrusage(int who, struct rusage *ru)
{
return(syscall(SYS_GETRUSAGE, who, ru));
}

View File

@@ -0,0 +1,36 @@
/*
* To generate tas.s using this template:
* 1. cc +O2 -S -c tas.c
* 2. edit tas.s:
* - replace the LDW with LDCWX
* For details about the LDCWX instruction, see the "Precision
* Architecture and Instruction Reference Manual" (09740-90014 of June
* 1987), p. 5-38.
*/
int
tas(lock)
int *lock; /* LDCWX is a word instruction */
{
/*
* LDCWX requires that we align the "semaphore" to a 16-byte
* boundary. The actual datum is a single word (4 bytes).
*/
lock = ((long) lock + 15) & ~15;
/*
* The LDCWX instruction atomically clears the target word and
* returns the previous value. Hence, if the instruction returns
* 0, someone else has already acquired the lock before we tested
* it (i.e., we have failed).
*
* Notice that this means that we actually clear the word to set
* the lock and set the word to clear the lock. This is the
* opposite behavior from the SPARC LDSTUB instruction. For some
* reason everything that H-P does is rather baroque...
*/
if (*lock) { /* this generates the LDW */
return(0); /* success */
}
return(1); /* failure */
}

View File

@@ -0,0 +1,28 @@
.SPACE $TEXT$,SORT=8
.SUBSPA $CODE$,QUAD=0,ALIGN=4,ACCESS=44,CODE_ONLY,SORT=24
tas
.PROC
.CALLINFO CALLER,FRAME=0,ENTRY_SR=3
.ENTRY
LDO 15(%r26),%r31 ;offset 0x0
DEPI 0,31,4,%r31 ;offset 0x4
LDCWX 0(0,%r31),%r23 ;offset 0x8
COMICLR,= 0,%r23,%r0 ;offset 0xc
DEP,TR %r0,31,32,%r28 ;offset 0x10
$00000001
LDI 1,%r28 ;offset 0x14
$L0
.EXIT
BV,N %r0(%r2) ;offset 0x18
.PROCEND ;in=26;out=28;
.SPACE $TEXT$
.SUBSPA $CODE$
.SPACE $PRIVATE$,SORT=16
.SUBSPA $DATA$,QUAD=1,ALIGN=8,ACCESS=31,SORT=16
.SPACE $TEXT$
.SUBSPA $CODE$
.EXPORT tas,ENTRY,PRIV_LEV=3,ARGW0=GR,RTNVAL=GR
.END

View File

@@ -0,0 +1,20 @@
#-------------------------------------------------------------------------
#
# Makefile.inc--
# Makefile for port/irix5 (IRIX 5 specific stuff)
#
# Copyright (c) 1994, Regents of the University of California
#
#
# IDENTIFICATION
# /usr/local/devel/pglite/cvs/src/backend/port/sparc_solaris/Makefile.inc,v 1.3 1995/03/21 06:51:21 andrew Exp
#
#-------------------------------------------------------------------------
CFLAGS+= -DUSE_POSIX_TIME -DNEED_ISINF -DNO_EMPTY_STMTS
LDADD+= -ll
SUBSRCS+= port.c
HEADERS+= machine.h port-protos.h

View File

@@ -0,0 +1,2 @@
The IRIX 5 port was contributed by
Paul 'Shag' Walmsley <ccshag@everest.cclabs.missouri.edu>

View File

@@ -0,0 +1,19 @@
/*-------------------------------------------------------------------------
*
* machine.h--
*
*
*
* Copyright (c) 1994, Regents of the University of California
*
* machine.h,v 1.1.1.1 1994/11/07 05:19:38 andrew Exp
*
*-------------------------------------------------------------------------
*/
#ifndef MACHINE_H
#define MACHINE_H
#define BLCKSZ 8192
#endif

View File

@@ -0,0 +1,36 @@
/*-------------------------------------------------------------------------
*
* port-protos.h--
* port-specific prototypes for Irix 5
*
*
* Copyright (c) 1994, Regents of the University of California
*
* port-protos.h,v 1.2 1995/03/17 06:40:18 andrew Exp
*
*-------------------------------------------------------------------------
*/
#ifndef PORT_PROTOS_H
#define PORT_PROTOS_H
#include "fmgr.h" /* for func_ptr */
#include "utils/dynamic_loader.h"
/* dynloader.c */
/*
* Dynamic Loader on SunOS 4.
*
* this dynamic loader uses the system dynamic loading interface for shared
* libraries (ie. dlopen/dlsym/dlclose). The user must specify a shared
* library as the file to be dynamically loaded.
*
*/
#define pg_dlopen(f) dlopen(f,1)
#define pg_dlsym dlsym
#define pg_dlclose dlclose
#define pg_dlerror dlerror
/* port.c */
extern long random(void);
#endif /* PORT_PROTOS_H */

View File

@@ -0,0 +1,16 @@
/*-------------------------------------------------------------------------
*
* port.c--
* Irix5-specific routines
*
* Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* /usr/local/devel/pglite/cvs/src/backend/port/sparc_solaris/port.c,v 1.2 1995/03/17 06:40:19 andrew Exp
*
*-------------------------------------------------------------------------
*/
#include <math.h> /* for pow() prototype */
#include <errno.h>

View File

@@ -0,0 +1,36 @@
#-------------------------------------------------------------------------
#
# Makefile.inc--
# Makefile for port/linux (Linux specific stuff)
#
# Copyright (c) 1994, Regents of the University of California
#
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/backend/port/linux/Attic/Makefile.inc,v 1.1.1.1 1996/07/09 06:21:44 scrappy Exp $
#
# NOTES
# The Linux port is included here by courtesy of Kai Petzke.
#
# (C) 1994, Kai Petzke, wpp@marie.physik.tu-berlin.de
#
#-------------------------------------------------------------------------
#
# linux has fast linkers and don't need the BIGOBJ stuff.
#
BIGOBJS= false
ifdef LINUX_ELF
CC=gcc
LDADD+= -ldl
CFLAGS+= -DLINUX_ELF
else
LDADD+= -ldld
SUBSRCS+= dynloader.c
endif
HEADERS+= machine.h port-protos.h
CFLAGS+= -DNEED_CBRT

View File

@@ -0,0 +1,93 @@
/*-------------------------------------------------------------------------
*
* dynloader.c--
* Dynamic Loader for Postgres for Linux, generated from those for
* Ultrix.
*
* You need to install the dld library on your Linux system!
*
* Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/port/linux/Attic/dynloader.c,v 1.1.1.1 1996/07/09 06:21:44 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
#include <stdio.h>
#include <dld.h>
#include "postgres.h"
#include "port-protos.h"
#include "utils/elog.h"
#include "fmgr.h"
extern char pg_pathname[];
void *
pg_dlopen(char *filename)
{
static int dl_initialized= 0;
/*
* initializes the dynamic loader with the executable's pathname.
* (only needs to do this the first time pg_dlopen is called.)
*/
if (!dl_initialized) {
if (dld_init (dld_find_executable (pg_pathname))) {
return NULL;
}
/*
* if there are undefined symbols, we want dl to search from the
* following libraries also.
*/
dl_initialized= 1;
}
/*
* link the file, then check for undefined symbols!
*/
if (dld_link(filename)) {
return NULL;
}
/*
* If undefined symbols: try to link with the C and math libraries!
* This could be smarter, if the dynamic linker was able to handle
* shared libs!
*/
if(dld_undefined_sym_count > 0) {
if (dld_link("/usr/lib/libc.a")) {
elog(NOTICE, "dld: Cannot link C library!");
return NULL;
}
if(dld_undefined_sym_count > 0) {
if (dld_link("/usr/lib/libm.a")) {
elog(NOTICE, "dld: Cannot link math library!");
return NULL;
}
if(dld_undefined_sym_count > 0) {
int count = dld_undefined_sym_count;
char **list= dld_list_undefined_sym();
/* list the undefined symbols, if any */
elog(NOTICE, "dld: Undefined:");
do {
elog(NOTICE, " %s", *list);
list++;
count--;
} while(count > 0);
dld_unlink_by_file(filename, 1);
return NULL;
}
}
}
return (void *) strdup(filename);
}
char *
pg_dlerror()
{
return dld_strerror(dld_errno);
}

View File

@@ -0,0 +1,18 @@
/*-------------------------------------------------------------------------
*
* machine.h--
*
*
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: machine.h,v 1.1.1.1 1996/07/09 06:21:44 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef MACHINE_H
#define MACHINE_H
#define BLCKSZ 8192
#endif

View File

@@ -0,0 +1,37 @@
/*-------------------------------------------------------------------------
*
* port-protos.h--
* port-specific prototypes for SunOS 4
*
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: port-protos.h,v 1.1.1.1 1996/07/09 06:21:44 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef PORT_PROTOS_H
#define PORT_PROTOS_H
#include "fmgr.h" /* for func_ptr */
#include "utils/dynamic_loader.h"
#ifdef LINUX_ELF
#include "dlfcn.h"
#endif
/* dynloader.c */
#ifndef LINUX_ELF
#define pg_dlsym(handle, funcname) ((func_ptr) dld_get_func((funcname)))
#define pg_dlclose(handle) ({ dld_unlink_by_file(handle, 1); free(handle); })
#else
/* #define pg_dlopen(f) dlopen(f, 1) */
#define pg_dlopen(f) dlopen(f, 2)
#define pg_dlsym dlsym
#define pg_dlclose dlclose
#define pg_dlerror dlerror
#endif
/* port.c */
#endif /* PORT_PROTOS_H */

View File

@@ -0,0 +1,13 @@
/*-------------------------------------------------------------------------
*
* port.c--
* Linux-specific routines
*
* Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/port/linux/Attic/port.c,v 1.1.1.1 1996/07/09 06:21:44 scrappy Exp $
*
*-------------------------------------------------------------------------
*/

View File

@@ -0,0 +1,23 @@
#-------------------------------------------------------------------------
#
# Makefile.inc--
# Makefile for port/sparc (SPARC/SunOS 4 specific stuff)
#
# Copyright (c) 1994, Regents of the University of California
#
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/backend/port/sparc/Attic/Makefile.inc,v 1.1.1.1 1996/07/09 06:21:44 scrappy Exp $
#
#-------------------------------------------------------------------------
CFLAGS+= -DUSE_POSIX_TIME
LDADD+= -lln -ldl
#
# SunOS 4 strtol is broken -- doesn't report overflow using errno.
#
SUBSRCS= strtol.c
HEADERS+= float.h machine.h port-protos.h

View File

@@ -0,0 +1,30 @@
/*-------------------------------------------------------------------------
*
* float.h--
* definitions for ANSI floating point
*
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: float.h,v 1.1.1.1 1996/07/09 06:21:44 scrappy Exp $
*
* NOTES
* These come straight out of ANSI X3.159-1989 (p.18) and
* would be unnecessary if SunOS 4 were ANSI-compliant.
*
* This is only a partial listing because I'm lazy to type
* the whole thing in.
*
*-------------------------------------------------------------------------
*/
#ifndef FLOAT_H
#define FLOAT_H
#define FLT_DIG 6
#define FLT_MIN ((float) 1.17549435e-38)
#define FLT_MAX ((float) 3.40282347e+38)
#define DBL_DIG 15
#define DBL_MIN 2.2250738585072014e-308
#define DBL_MAX 1.7976931348623157e+308
#endif /* FLOAT_H */

View File

@@ -0,0 +1,19 @@
/*-------------------------------------------------------------------------
*
* machine.h--
*
*
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: machine.h,v 1.1.1.1 1996/07/09 06:21:44 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef MACHINE_H
#define MACHINE_H
#define BLCKSZ 8192
#endif

View File

@@ -0,0 +1,34 @@
/*-------------------------------------------------------------------------
*
* port-protos.h--
* port-specific prototypes for SunOS 4
*
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: port-protos.h,v 1.1.1.1 1996/07/09 06:21:44 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef PORT_PROTOS_H
#define PORT_PROTOS_H
#include <dlfcn.h>
#include "fmgr.h" /* for func_ptr */
#include "utils/dynamic_loader.h"
/* dynloader.c */
/*
* Dynamic Loader on SunOS 4.
*
* this dynamic loader uses the system dynamic loading interface for shared
* libraries (ie. dlopen/dlsym/dlclose). The user must specify a shared
* library as the file to be dynamically loaded.
*
*/
#define pg_dlopen(f) dlopen(f, 1)
#define pg_dlsym dlsym
#define pg_dlclose dlclose
#define pg_dlerror dlerror
#endif /* PORT_PROTOS_H */

View File

@@ -0,0 +1,130 @@
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)strtol.c 5.4 (Berkeley) 2/23/91";
#endif /* LIBC_SCCS and not lint */
#include <limits.h>
#include <ctype.h>
#include <errno.h>
#include <stdlib.h>
#define const
/*
* Convert a string to a long integer.
*
* Ignores `locale' stuff. Assumes that the upper and lower case
* alphabets and digits are each contiguous.
*/
long
strtol(nptr, endptr, base)
const char *nptr;
char **endptr;
register int base;
{
register const char *s = nptr;
register unsigned long acc;
register int c;
register unsigned long cutoff;
register int neg = 0, any, cutlim;
/*
* Skip white space and pick up leading +/- sign if any.
* If base is 0, allow 0x for hex and 0 for octal, else
* assume decimal; if base is already 16, allow 0x.
*/
do {
c = *s++;
} while (isspace(c));
if (c == '-') {
neg = 1;
c = *s++;
} else if (c == '+')
c = *s++;
if ((base == 0 || base == 16) &&
c == '0' && (*s == 'x' || *s == 'X')) {
c = s[1];
s += 2;
base = 16;
}
if (base == 0)
base = c == '0' ? 8 : 10;
/*
* Compute the cutoff value between legal numbers and illegal
* numbers. That is the largest legal value, divided by the
* base. An input number that is greater than this value, if
* followed by a legal input character, is too big. One that
* is equal to this value may be valid or not; the limit
* between valid and invalid numbers is then based on the last
* digit. For instance, if the range for longs is
* [-2147483648..2147483647] and the input base is 10,
* cutoff will be set to 214748364 and cutlim to either
* 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated
* a value > 214748364, or equal but the next digit is > 7 (or 8),
* the number is too big, and we will return a range error.
*
* Set any if any `digits' consumed; make it negative to indicate
* overflow.
*/
cutoff = neg ? -(unsigned long)LONG_MIN : LONG_MAX;
cutlim = cutoff % (unsigned long)base;
cutoff /= (unsigned long)base;
for (acc = 0, any = 0;; c = *s++) {
if (isdigit(c))
c -= '0';
else if (isalpha(c))
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
else
break;
if (c >= base)
break;
if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim)
any = -1;
else {
any = 1;
acc *= base;
acc += c;
}
}
if (any < 0) {
acc = neg ? LONG_MIN : LONG_MAX;
errno = ERANGE;
} else if (neg)
acc = -acc;
if (endptr != 0)
*endptr = any ? s - 1 : (char *)nptr;
return (acc);
}

View File

@@ -0,0 +1,20 @@
#-------------------------------------------------------------------------
#
# Makefile.inc--
# Makefile for port/sparc_solaris (SPARC/Solaris 2.x specific stuff)
#
# Copyright (c) 1994, Regents of the University of California
#
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/backend/port/sparc_solaris/Attic/Makefile.inc,v 1.1.1.1 1996/07/09 06:21:45 scrappy Exp $
#
#-------------------------------------------------------------------------
CFLAGS+= -DUSE_POSIX_TIME -DNEED_ISINF -DNEED_RUSAGE -DNO_EMPTY_STMTS
LDADD+= -ll -ldl
SUBSRCS+= port.c tas.s
HEADERS+= machine.h port-protos.h rusagestub.h

View File

@@ -0,0 +1,19 @@
/*-------------------------------------------------------------------------
*
* machine.h--
*
*
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: machine.h,v 1.1.1.1 1996/07/09 06:21:45 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef MACHINE_H
#define MACHINE_H
#define BLCKSZ 8192
#endif

View File

@@ -0,0 +1,38 @@
/*-------------------------------------------------------------------------
*
* port-protos.h--
* port-specific prototypes for SunOS 4
*
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: port-protos.h,v 1.1.1.1 1996/07/09 06:21:45 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef PORT_PROTOS_H
#define PORT_PROTOS_H
#include <dlfcn.h>
#include "fmgr.h" /* for func_ptr */
#include "utils/dynamic_loader.h"
/* dynloader.c */
/*
* Dynamic Loader on SunOS 4.
*
* this dynamic loader uses the system dynamic loading interface for shared
* libraries (ie. dlopen/dlsym/dlclose). The user must specify a shared
* library as the file to be dynamically loaded.
*
*/
#define pg_dlopen(f) dlopen(f,1)
#define pg_dlsym dlsym
#define pg_dlclose dlclose
#define pg_dlerror dlerror
/* port.c */
extern long random(void);
extern void srandom(int seed);
#endif /* PORT_PROTOS_H */

View File

@@ -0,0 +1,66 @@
/*-------------------------------------------------------------------------
*
* port.c--
* SunOS5-specific routines
*
* Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/port/sparc_solaris/Attic/port.c,v 1.1.1.1 1996/07/09 06:21:45 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
#include <math.h> /* for pow() prototype */
#include <errno.h>
#include "rusagestub.h"
long
random()
{
return(lrand48());
}
void
srandom(int seed)
{
srand48((long int) seed);
}
int
getrusage(int who, struct rusage *rusage)
{
struct tms tms;
register int tick_rate = CLK_TCK; /* ticks per second */
clock_t u, s;
if (rusage == (struct rusage *) NULL) {
errno = EFAULT;
return(-1);
}
if (times(&tms) < 0) {
/* errno set by times */
return(-1);
}
switch (who) {
case RUSAGE_SELF:
u = tms.tms_utime;
s = tms.tms_stime;
break;
case RUSAGE_CHILDREN:
u = tms.tms_cutime;
s = tms.tms_cstime;
break;
default:
errno = EINVAL;
return(-1);
}
#define TICK_TO_SEC(T, RATE) ((T)/(RATE))
#define TICK_TO_USEC(T,RATE) (((T)%(RATE)*1000000)/RATE)
rusage->ru_utime.tv_sec = TICK_TO_SEC(u, tick_rate);
rusage->ru_utime.tv_usec = TICK_TO_USEC(u, tick_rate);
rusage->ru_stime.tv_sec = TICK_TO_SEC(s, tick_rate);
rusage->ru_stime.tv_usec = TICK_TO_USEC(u, tick_rate);
return(0);
}

View File

@@ -0,0 +1,30 @@
/*-------------------------------------------------------------------------
*
* rusagestub.h--
* Stubs for getrusage(3).
*
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: rusagestub.h,v 1.1.1.1 1996/07/09 06:21:45 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef RUSAGESTUB_H
#define RUSAGESTUB_H
#include <sys/time.h> /* for struct timeval */
#include <sys/times.h> /* for struct tms */
#include <limits.h> /* for CLK_TCK */
#define RUSAGE_SELF 0
#define RUSAGE_CHILDREN -1
struct rusage {
struct timeval ru_utime; /* user time used */
struct timeval ru_stime; /* system time used */
};
extern int getrusage(int who, struct rusage *rusage);
#endif /* RUSAGESTUB_H */

View File

@@ -0,0 +1,50 @@
!!
!! $Header: /cvsroot/pgsql/src/backend/port/sparc_solaris/Attic/tas.s,v 1.1.1.1 1996/07/09 06:21:45 scrappy Exp $
!!
!! this would be a piece of inlined assembler but it appears
!! to be easier to just write the assembler than to try to
!! figure out how to make sure that in/out registers are kept
!! straight in the asm's.
!!
.file "tas.c"
.section ".text"
.align 4
.global tas
.type tas,#function
.proc 04
tas:
!!
!! this is a leaf procedure - no need to save windows and
!! diddle the CWP.
!!
!#PROLOGUE# 0
!#PROLOGUE# 1
!!
!! write 0xFF into the lock address, saving the old value in %o0.
!! this is an atomic action, even on multiprocessors.
!!
ldstub [%o0],%o0
!!
!! if it was already set when we set it, somebody else already
!! owned the lock -- return 1.
!!
cmp %o0,0
bne .LL2
mov 1,%o0
!!
!! otherwise, it was clear and we now own the lock -- return 0.
!!
mov 0,%o0
.LL2:
!!
!! this is a leaf procedure - no need to restore windows and
!! diddle the CWP.
!!
retl
nop
.LLfe1:
.size tas,.LLfe1-tas
.ident "GCC: (GNU) 2.5.8"

View File

@@ -0,0 +1,27 @@
#-------------------------------------------------------------------------
#
# Makefile.inc--
# Makefile for port/ultrix (Ultrix4.x specific stuff)
#
# Copyright (c) 1994, Regents of the University of California
#
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/backend/port/ultrix4/Attic/Makefile.inc,v 1.1.1.1 1996/07/09 06:21:45 scrappy Exp $
#
#-------------------------------------------------------------------------
CFLAGS+= -DNEED_ISINF -DUSE_POSIX_TIME
LDADD+= -ldl -lln
#
# The YACC grammar is too big..
#
#.if !defined(CDEBUG)
#CFLAGS+= -Olimit 2000
#.endif
HEADERS+= dl.h machine.h port-protos.h
SUBSRCS+= dynloader.c port.c strdup.c

View File

@@ -0,0 +1,117 @@
/*-------------------------------------------------------------------------
*
* dl.h--
*
*
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: dl.h,v 1.1.1.1 1996/07/09 06:21:45 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
/*
* Ultrix 4.x Dynamic Loader Library Version 1.0
*
* dl.h--
* header file for the Dynamic Loader Library
*
*
* Copyright (c) 1993 Andrew K. Yu, University of California at Berkeley
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for educational, research, and non-profit purposes and
* without fee is hereby granted, provided that the above copyright
* notice appear in all copies and that both that copyright notice and
* this permission notice appear in supporting documentation. Permission
* to incorporate this software into commercial products can be obtained
* from the author. The University of California and the author make
* no representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*/
#ifndef _DL_HEADER_
#define _DL_HEADER_
#include <filehdr.h>
#include <syms.h>
#include <ldfcn.h>
#include <reloc.h>
#include <scnhdr.h>
typedef long CoreAddr;
typedef struct ScnInfo {
CoreAddr addr; /* starting address of the section */
SCNHDR hdr; /* section header */
RELOC *relocEntries; /* relocation entries */
} ScnInfo;
typedef enum {
DL_NEEDRELOC, /* still need relocation */
DL_RELOCATED, /* no relocation necessary */
DL_INPROG /* relocation in progress */
} dlRStatus;
typedef struct JmpTbl {
char *block; /* the jump table memory block */
struct JmpTbl *next; /* next block */
} JmpTbl;
typedef struct dlFile {
char *filename; /* file name of the object file */
int textSize; /* used by mprotect */
CoreAddr textAddress; /* start addr of text section */
long textVaddr; /* vaddr of text section in obj file */
CoreAddr rdataAddress; /* start addr of rdata section */
long rdataVaddr; /* vaddr of text section in obj file */
CoreAddr dataAddress; /* start addr of data section */
long dataVaddr; /* vaddr of text section in obj file */
CoreAddr bssAddress; /* start addr of bss section */
long bssVaddr; /* vaddr of text section in obj file */
int nsect; /* number of sections */
ScnInfo *sect; /* details of each section (array) */
int issExtMax; /* size of string space */
char *extss; /* extern sym string space (in core) */
int iextMax; /* maximum number of Symbols */
pEXTR extsyms; /* extern syms */
dlRStatus relocStatus; /* what relocation needed? */
int needReloc;
JmpTbl *jmptable; /* the jump table for R_JMPADDR */
struct dlFile *next; /* next member of the archive */
} dlFile;
typedef struct dlSymbol {
char *name; /* name of the symbol */
long addr; /* address of the symbol */
dlFile *objFile; /* from which file */
} dlSymbol;
/*
* prototypes for the dl* interface
*/
extern void *dl_open(/* char *filename, int mode */);
extern void *dl_sym(/* void *handle, char *name */);
extern void dl_close(/* void *handle */);
extern char *dl_error(/* void */);
#define DL_LAZY 0 /* lazy resolution */
#define DL_NOW 1 /* immediate resolution */
/*
* Miscellaneous utility routines:
*/
extern char **dl_undefinedSymbols(/* int *count */);
extern void dl_printAllSymbols(/* void *handle */);
extern void dl_setLibraries(/* char *libs */);
#endif _DL_HEADER_

View File

@@ -0,0 +1,68 @@
/*-------------------------------------------------------------------------
*
* dynloader.c--
* This dynamic loader uses Andrew Yu's libdl-1.0 package for Ultrix 4.x.
* (Note that pg_dlsym and pg_dlclose are actually macros defined in
* "port-protos.h".)
*
* Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/port/ultrix4/Attic/dynloader.c,v 1.1.1.1 1996/07/09 06:21:45 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
#include <stdio.h>
#include "dl.h"
#include "c.h"
#include "fmgr.h"
#include "port-protos.h"
#include "utils/elog.h"
extern char pg_pathname[];
void *
pg_dlopen(char *filename)
{
static int dl_initialized= 0;
void *handle;
/*
* initializes the dynamic loader with the executable's pathname.
* (only needs to do this the first time pg_dlopen is called.)
*/
if (!dl_initialized) {
if (!dl_init(pg_pathname)) {
return NULL;
}
/*
* if there are undefined symbols, we want dl to search from the
* following libraries also.
*/
dl_setLibraries("/usr/lib/libm_G0.a:/usr/lib/libc_G0.a");
dl_initialized= 1;
}
/*
* open the file. We do the symbol resolution right away so that we
* will know if there are undefined symbols. (This is in fact the
* same semantics as "ld -A". ie. you cannot have undefined symbols.
*/
if ((handle=dl_open(filename, DL_NOW))==NULL) {
int count;
char **list= dl_undefinedSymbols(&count);
/* list the undefined symbols, if any */
if(count) {
elog(NOTICE, "dl: Undefined:");
while(*list) {
elog(NOTICE, " %s", *list);
list++;
}
}
}
return (void *)handle;
}

View File

@@ -0,0 +1,19 @@
/*-------------------------------------------------------------------------
*
* machine.h--
*
*
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: machine.h,v 1.1.1.1 1996/07/09 06:21:45 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef MACHINE_H
#define MACHINE_H
#define BLCKSZ 8192
#endif

View File

@@ -0,0 +1,36 @@
/*-------------------------------------------------------------------------
*
* port-protos.h--
* prototypes for Ultrix-specific routines
*
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: port-protos.h,v 1.1.1.1 1996/07/09 06:21:45 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef PORT_PORTOS_H
#define PORT_PORTOS_H
#include "utils/dynamic_loader.h"
#include "dl.h"
/* dynloader.c */
/*
* New dynamic loader.
*
* This dynamic loader uses Andrew Yu's libdl-1.0 package for Ultrix 4.x.
* (Note that pg_dlsym and pg_dlclose are actually macros defined in
* "port-protos.h".)
*/
#define pg_dlsym(h, f) ((func_ptr)dl_sym(h, f))
#define pg_dlclose(h) dl_close(h)
#define pg_dlerror() dl_error()
/* port.c */
extern void init_address_fixup(void);
#endif /* PORT_PORTOS_H */

View File

@@ -0,0 +1,25 @@
/*-------------------------------------------------------------------------
*
* port.c--
* Ultrix-specific routines
*
* Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/port/ultrix4/Attic/port.c,v 1.1.1.1 1996/07/09 06:21:45 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
#include <sys/syscall.h>
#include <sys/sysmips.h>
#include "c.h"
void
init_address_fixup()
{
#ifdef NOFIXADE
syscall(SYS_sysmips, MIPS_FIXADE, 0, NULL, NULL, NULL);
#endif /* NOFIXADE */
}

View File

@@ -0,0 +1,23 @@
/*-------------------------------------------------------------------------
*
* strdup.c--
* copies a null-terminated string.
*
* Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/port/ultrix4/Attic/strdup.c,v 1.1.1.1 1996/07/09 06:21:45 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
#include <string.h>
char *
strdup(char *string)
{
char *nstr;
nstr = strcpy((char *)palloc(strlen(string)+1), string);
return nstr;
}

View File

@@ -0,0 +1,2 @@
#define BLCKSZ 8192
#define NOFILE 100

625
src/backend/port/win32/nt.c Normal file
View File

@@ -0,0 +1,625 @@
#include <windows.h>
#include <time.h>
#include "postgres.h"
#include "storage/ipc.h"
/* The name of the Postgres 95 ipc file mapping object */
#define IPC_NAME "PG95_IPC"
/* The name of the Postgres 95 ipc file mapping object semaphore */
#define IPC_SEM_NAME "PG95_IPC_SEM"
/* The maximum length of a shared memory object name */
#define IPC_MAX_SHMEM_NAME 32
/* The maximum number of emulated Unix shared memory segments */
#define IPC_NMAXSHM 10
/* The Maximum number of elements in a semaphore set. Note that this
** is just a guess.
*/
#define IPC_NMAXSEMGRP 7
/* The various states of a semaphore */
#define SIGNALED 1
#define UNSIGNALED 0
#define UNUSED -1
/* The security attribute structure necessary for handles to be inhereted */
SECURITY_ATTRIBUTES sec_attrib = { sizeof (LPSECURITY_ATTRIBUTES),
NULL, TRUE};
/*
Postgres95 uses semaphores and shared memory. Both are provided by
Unix and NT, although NT uses a different method for referencing
them. Rather than changing the function calls used by Postgres95
to use NT system services, we've written code to emulate the Unix
system calls. We deliberately don't do a complete emulation of the
Unix calls, partly because it doesn't appear possible, but also
because only a few options of the Unix calls are actually used by
Postgres95.
The most noticable difference between the way Unix and NT use semaphores
is that the central entity on Unix is a semaphore set consisting of
potientially many actual semaphores whereas on NT a semaphore handle
represents just one actual semaphore. Furthermore, a Unix semaphore set
is identified by one semaphore id no matter how many elements there
are in the set. Given a Unix semaphore id, the Unix API provides a way
to index into the set to reference a specific semaphore.
You might think that since both a semaphore id and a semaphore handle
is just an integer there won't be any changes necessary to the Postgres95
code to deal with NT semaphores. If it weren't for the existence of
multi-semaphore semaphore sets this would be true.
To handle semaphore sets a fixed-size table, whose size is partially
based on the sum of the maximum number of semaphores times the maximum
number of semaphores per semaphore set, is created and kept in shared
memory that is visable to every backend started by the Postmaster.
Each semaphore set entry consists of an arbitrary key value, which serves
to identify the semaphore set, and IPC_NMAXSEMGRP array elements to
store the NT semaphore handles representing the NT semaphore used for
the semaphore set. Semaphore IDs are just indices into this table.
In order to distinguish occupied entries in this table -1 is always
considered an invalid semaphore ID.
This table is also used to store information about shared memory
segments. Fortunately, there is a one-to-one mapping between Unix
shared memory IDs and NT shared memory handles so the code to emulate
Unix shared memory is simple.
*/
/* We need one of these for each emulated semaphore set */
struct Pg_sem
{
key_t Pg_sem_key;
HANDLE Pg_sem_handle[IPC_NMAXSEMGRP];
int Pg_sem_nsems;
};
/* We need one of these for each emulated shared memory segment */
struct Pg_shm
{
key_t Pg_shm_key;
HANDLE Pg_shm_handle;
};
/* This structure is what's stored in shared memory. Note that
** since both the shared memory and semaphore data is in the same
** table, and the table is protected by a single NT semaphore, there's
** a chance that semaphore manipulation could be slowed down by
** shared memory manipulation, and vice versa. But, since both are
** allocated primarily when the Postmaster starts up, which isn't time
** critical, I don't think this will prove to be a problem.
*/
static struct Pg_shared
{
int Pg_next_sem;
int Pg_next_shm;
struct Pg_sem Pg_sem[IPC_NMAXSEM];
struct Pg_shm Pg_shm[IPC_NMAXSHM];
} *Pg_shared_ptr;
/* The semaphore that protects the shared memory table */
HANDLE Pg_shared_hnd;
/*
** Perform a semaphore operation. We're passed a semaphore set id,
** a pointer to an array of sembuf structures, and the number
** of elements in the array. Each element in the sembuf structure
** describes a specific semaphore within the semaphore set and the
** operation to perform on it.
*/
int
semop(int semid, struct sembuf *sops, u_int nsops)
{
u_int i;
int result;
HANDLE hndl;
/* Go through all the sops structures */
for (i = 0; i < nsops; i++)
{
struct sembuf *sptr;
int semval;
int av_sem_op;
sptr = &sops[i];
/*
printf("performing %d in sem # %d\n", sptr->sem_op, sptr->sem_num);
*/
/*
** Postgres95 uses -255 to represent a lock request
** and 255 to show a lock release. Changing these values
** to -1 and 1 make it easier to keep track of the state
** of the semaphore.
*/
if (sptr->sem_op == -255)
sptr->sem_op = -1;
else if (sptr->sem_op == 255)
sptr->sem_op = 1;
else
printf("invalid sem_op %d\n", sptr->sem_op);
_get_ipc_sem();
hndl = Pg_shared_ptr->Pg_sem[semid].Pg_sem_handle[sptr->sem_num];
_rel_ipc_sem();
semval = _get_sem_val(hndl);
if (sptr->sem_op == 0)
{
if (semval == UNSIGNALED)
return(semval);
else
{
if (sptr->sem_flg & IPC_NOWAIT)
return(SIGNALED);
else
result = WaitForSingleObject(hndl, 5000);
}
}
av_sem_op = abs(sptr->sem_op);
/* If a lock is being attempted */
if (sptr->sem_op < 0)
{
if (semval >= av_sem_op)
{
semval -= av_sem_op;
if (semval <= UNSIGNALED)
result = WaitForSingleObject(hndl, 5000);
}
else
{
if (sptr->sem_flg & IPC_NOWAIT)
return(SIGNALED);
else
result = WaitForSingleObject(hndl, 5000);
}
}
/* If a lock is being released */
if (sptr->sem_op > 0)
{
semval += av_sem_op;
if (semval > 0)
ReleaseSemaphore(hndl, 1, NULL);
}
}
}
int
semget(key_t key, int nsems, int semflg)
{
int id, new_sem, ret_val;
/* If nmsems is 0 then assume that we're just checking whether
** the semaphore identified by key exists. Assume that
** if key is IPC_PRIVATE that this should always fail.
*/
if (nsems == 0)
{
if (key == IPC_PRIVATE)
ret_val = -1;
else
{
_get_ipc_sem();
id = _get_sem_id(key);
_rel_ipc_sem();
ret_val = id;
}
return(ret_val);
}
/* See if there's already a semaphore with the key.
** If not, record the key, allocate enough space for the
** handles of the semaphores, and then create the semaphores.
*/
_get_ipc_sem();
id = _get_sem_id(key);
if (id == UNUSED)
{
register int i;
struct Pg_sem *pg_ptr;
new_sem = Pg_shared_ptr->Pg_next_sem++;
pg_ptr = &(Pg_shared_ptr->Pg_sem[new_sem]);
pg_ptr->Pg_sem_key = key;
pg_ptr->Pg_sem_nsems = nsems;
for (i = 0; i < nsems; i++)
pg_ptr->Pg_sem_handle[i] = CreateSemaphore(&sec_attrib, 1, 255, NULL);
ret_val = new_sem;
}
else
ret_val = id;
_rel_ipc_sem();
return(ret_val);
}
/* These next two functions could be written as one function, although
** doing so would require some additional logic.
*/
/* Given a semaphore key, return the corresponding id.
** This function assumes that the shared memory table is being
** protected by the shared memory table semaphore.
*/
_get_sem_id(key_t key)
{
register int i;
/* Go through the shared memory table looking for a semaphore
** whose key matches what we're looking for
*/
for (i = 0; i < Pg_shared_ptr->Pg_next_sem; i++)
if (Pg_shared_ptr->Pg_sem[i].Pg_sem_key == key)
return(i);
/* Return UNUSED if we didn't find a match */
return(UNUSED);
}
/* Given a shared memory key, return the corresponding id
** This function assumes that the shared memory table is being
** protected by the shared memory table semaphore.
*/
_get_shm_id(key_t key)
{
register int i;
/* Go through the shared memory table looking for a semaphore
** whose key matches what we're looking for
*/
for (i = 0; i < Pg_shared_ptr->Pg_next_shm; i++)
if (Pg_shared_ptr->Pg_shm[i].Pg_shm_key == key)
return(i);
/* Return UNUSED if we didn't find a match */
return(UNUSED);
}
int
semctl(int semid, int semnum, int cmd, void *y)
{
int old_val;
HANDLE hndl;
switch (cmd)
{
case SETALL:
case SETVAL:
/* We can't change the value of a semaphore under
** NT except by releasing it or waiting for it.
*/
return(0);
case GETVAL:
_get_ipc_sem();
hndl = Pg_shared_ptr->Pg_sem[semid].Pg_sem_handle[semnum];
_rel_ipc_sem();
old_val = _get_sem_val(hndl);
return(old_val);
}
}
/* Get the current value of the semaphore whose handle is passed in hnd
** This function does NOT assume that the shared memory table is being
** protected by the shared memory table semaphore.
*/
int
_get_sem_val(HANDLE hnd)
{
DWORD waitresult;
/* Try to get the semaphore */
waitresult = WaitForSingleObject(hnd, 0L);
/* Check what the value of the semaphore was */
switch(waitresult)
{
/* The semaphore was signaled so we just got it.
** Since we don't really want to keep it, since we just
** wanted to test its value, go ahead and release it.
*/
case WAIT_OBJECT_0:
ReleaseSemaphore(hnd, 1, NULL);
return(SIGNALED);
/* The semaphore was non-signaled meaning someone else had it. */
case WAIT_TIMEOUT:
return(UNSIGNALED);
}
}
int
shmget(key_t key, uint32 size, int flags)
{
HANDLE hnd;
char name[IPC_MAX_SHMEM_NAME];
int id;
/* Get the handle for the key, if any. */
_get_ipc_sem();
id = _get_shm_id(key);
_rel_ipc_sem();
/* If we're really going to create a new mapping */
if (flags != 0)
{
/* if the key is already being used return an error */
if (id != UNUSED)
return(-1);
/* convert the key to a character string */
sprintf(name, "%d", key);
hnd = CreateFileMapping((HANDLE)0xffffffff,
&sec_attrib, PAGE_READWRITE,
0, size, name);
if (hnd == NULL)
return(-1);
else
{
int new_ipc;
struct Pg_shm *pg_ptr;
_get_ipc_sem();
new_ipc = Pg_shared_ptr->Pg_next_shm++;
pg_ptr = &(Pg_shared_ptr->Pg_shm[new_ipc]);
pg_ptr->Pg_shm_key = key;
pg_ptr->Pg_shm_handle = hnd;
_rel_ipc_sem();
return(new_ipc);
}
}
/* flags is 0 so we just want the id for the existing mapping */
else
return(id);
}
shmdt(char *shmaddr)
{
UnmapViewOfFile(shmaddr);
}
int
shmctl(IpcMemoryId shmid, int cmd, struct shmid_ds *buf)
{
int x = 0;
if (cmd == IPC_RMID)
{
_get_ipc_sem();
CloseHandle(Pg_shared_ptr->Pg_shm[shmid].Pg_shm_handle);
_rel_ipc_sem();
return(0);
}
x = x / x;
}
/* Attach to the already created shared memory segment */
LPVOID *
shmat(int shmid, void *shmaddr, int shmflg)
{
LPVOID *ret_addr;
_get_ipc_sem();
ret_addr = MapViewOfFile(Pg_shared_ptr->Pg_shm[shmid].Pg_shm_handle,
FILE_MAP_ALL_ACCESS, 0, 0, 0);
_rel_ipc_sem();
if (ret_addr == NULL)
{
int jon;
jon = GetLastError();
}
return(ret_addr);
}
/* This is the function that is called when the postmaster starts up.
** It is here that the shared memory table is created. Also, create
** the semaphore that will be used to protect the shared memory table.
** TODO - do something with the return value.
*/
_nt_init()
{
HANDLE hnd;
int size = sizeof (struct Pg_shared);
/* Create the file mapping for the shared memory to be
** used to store the ipc table.
*/
hnd = CreateFileMapping((HANDLE)0xffffffff,
&sec_attrib, PAGE_READWRITE,
0, size, IPC_NAME);
if (hnd == NULL)
{
size = GetLastError();
return(-1);
}
Pg_shared_hnd = CreateSemaphore(&sec_attrib, 1, 255, IPC_SEM_NAME);
if (Pg_shared_hnd == NULL)
{
size = GetLastError();
return(-1);
}
}
/* This function gets called by every backend at startup time. Its
** main duty is to put the address of the shared memory table pointed
** to by Pg_shared_ptr. There's no need to get the IPC_SEM_NAME semaphore
** because this function is called before we start manipulating the
** shared memory table.
*/
void
_nt_attach()
{
HANDLE hnd;
/* Get a handle to the shared memory table */
hnd = OpenFileMapping(FILE_MAP_ALL_ACCESS,
FALSE, IPC_NAME);
/* Map the ipc shared memory table into the address space
** of this process at an address returned by MapViewOfFile
*/
Pg_shared_ptr = (struct Pg_shared *) MapViewOfFile(hnd,
FILE_MAP_ALL_ACCESS, 0, 0, 0);
if (Pg_shared_ptr == NULL)
{
hnd = GetLastError();
return(-1);
}
}
_get_ipc_sem()
{
WaitForSingleObject(Pg_shared_hnd, 5000);
}
_rel_ipc_sem()
{
ReleaseSemaphore(Pg_shared_hnd, 1, NULL);
}
pg_dlerror(void)
{
int x = 0;
x = x / x;
}
pg_dlclose(void *handle)
{
FreeLibrary(handle);
}
void *
pg_dlopen(char *filename)
{
HINSTANCE hinstlib;
hinstlib = LoadLibrary(filename);
return (hinstlib);
}
void *
pg_dlsym(void *handle, char *funcname)
{
void *proc;
proc = GetProcAddress(handle, funcname);
return (proc);
}
void
ftruncate(int fd, int offset)
{
HANDLE hnd;
_lseek(fd, offset, SEEK_SET);
hnd = _get_osfhandle(fd);
SetEndOfFile(hnd);
}
/* The rest are just stubs that are intended to serve as place holders
** in case we want to set breakpoints to see what's happening when
** these routines are called. They'll eventually have to be filled
** in but they're not necessary to get Postgres95 going.
*/
setuid(int i)
{
int x = 1;
x = x / x;
}
setsid()
{
int x = 1;
x = x / x;
}
vfork(void)
{
int x = 0;
x = x / x;
}
ttyname(int y)
{
int x = 0;
x = x / x;
}
step(char *string, char *expbuf)
{
int x = 0;
x = x / x;
}
siglongjmp(int env, int value)
{
int x = 0;
x = x / x;
}
pause(void)
{
int x = 0;
x = x / x;
}
kill(int process, int signal)
{
int x = 1;
x = x / x;
}
getuid(void)
{
int x = 1;
x = x / x;
}
geteuid( void )
{
int x = 1;
x = x / x;
}
int
fsync(int filedes)
{
}
fork(void)
{
int x = 0;
x = x / x;
}
char *
compile(char *instring,char *expbuf,char *endbuf,int eof)
{
int x = 0;
x = x / x;
}
beginRecipe(char *s)
{
int x = 0;
x = x / x;
}

View File

@@ -0,0 +1,54 @@
typedef char * caddr_t;
typedef unsigned long u_long;
typedef unsigned int u_int;
typedef unsigned short u_short;
typedef unsigned char u_char;
typedef unsigned int mode_t;
typedef u_int uid_t;
typedef u_int gid_t;
typedef int key_t;
#define IPC_PRIVATE ((key_t)0)
/* Common IPC operation flag definitions. We'll use
** the Unix values unless we find a reason not to.
*/
#define IPC_CREAT 0001000 /* create entry if key doesn't exist */
#define IPC_EXCL 0002000 /* fail if key exists */
#define IPC_NOWAIT 0004000 /* error if request must wait */
struct sembuf
{
u_short sem_num;
short sem_op;
short sem_flg;
};
#define USE_POSIX_TIME
#define NEED_RINT
#define MAXHOSTNAMELEN 12 /* where is the official definition of this? */
#define MAXPATHLEN _MAX_PATH /* in winsock.h */
#define POSTPORT "5432"
/* NT has stricmp not strcasecmp. Which is ANSI? */
#define strcasecmp(a,b) _stricmp(a,b)
#define isascii(a) __isascii(a)
#define random() rand()
/* These are bogus values used so that we can compile ipc.c */
#define SETALL 2
#define SETVAL 3
#define IPC_RMID 4
#define GETNCNT 5
#define GETVAL 6
/* for float.c */
#define NEED_CBRT
#define NEED_ISINF
#define POSTGRESDIR "d:\\pglite"
#define PGDATADIR "d:\\pglite\\data"

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1,56 @@
Copyright 1992, 1993, 1994 Henry Spencer. All rights reserved.
This software is not subject to any license of the American Telephone
and Telegraph Company or of the Regents of the University of California.
Permission is granted to anyone to use this software for any purpose on
any computer system, and to alter it and redistribute it, subject
to the following restrictions:
1. The author is not responsible for the consequences of use of this
software, no matter how awful, even if they arise from flaws in it.
2. The origin of this software must not be misrepresented, either by
explicit claim or by omission. Since few users ever read sources,
credits must appear in the documentation.
3. Altered versions must be plainly marked as such, and must not be
misrepresented as being the original software. Since few users
ever read sources, credits must appear in the documentation.
4. This notice may not be removed or altered.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
/*-
* Copyright (c) 1994
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)COPYRIGHT 8.1 (Berkeley) 3/16/94
*/

View File

@@ -0,0 +1,14 @@
# @(#)Makefile.inc 8.1 (Berkeley) 6/4/93
# regex sources
.PATH: ${.CURDIR}/regex
CFLAGS+=-DPOSIX_MISTAKE
SRCS+= regcomp.c regerror.c regexec.c regfree.c
MAN3+= regex.0
MAN7+= re_format.0
MLINKS+=regex.3 regcomp.3 regex.3 regexec.3 regex.3 regerror.3
MLINKS+=regexec.3 regfree.3

View File

@@ -0,0 +1,94 @@
# @(#)WHATSNEW 8.3 (Berkeley) 3/18/94
New in alpha3.4: The complex bug alluded to below has been fixed (in a
slightly kludgey temporary way that may hurt efficiency a bit; this is
another "get it out the door for 4.4" release). The tests at the end of
the tests file have accordingly been uncommented. The primary sign of
the bug was that something like a?b matching ab matched b rather than ab.
(The bug was essentially specific to this exact situation, else it would
have shown up earlier.)
New in alpha3.3: The definition of word boundaries has been altered
slightly, to more closely match the usual programming notion that "_"
is an alphabetic. Stuff used for pre-ANSI systems is now in a subdir,
and the makefile no longer alludes to it in mysterious ways. The
makefile has generally been cleaned up some. Fixes have been made
(again!) so that the regression test will run without -DREDEBUG, at
the cost of weaker checking. A workaround for a bug in some folks'
<assert.h> has been added. And some more things have been added to
tests, including a couple right at the end which are commented out
because the code currently flunks them (complex bug; fix coming).
Plus the usual minor cleanup.
New in alpha3.2: Assorted bits of cleanup and portability improvement
(the development base is now a BSDI system using GCC instead of an ancient
Sun system, and the newer compiler exposed some glitches). Fix for a
serious bug that affected REs using many [] (including REG_ICASE REs
because of the way they are implemented), *sometimes*, depending on
memory-allocation patterns. The header-file prototypes no longer name
the parameters, avoiding possible name conflicts. The possibility that
some clot has defined CHAR_MIN as (say) `-128' instead of `(-128)' is
now handled gracefully. "uchar" is no longer used as an internal type
name (too many people have the same idea). Still the same old lousy
performance, alas.
New in alpha3.1: Basically nothing, this release is just a bookkeeping
convenience. Stay tuned.
New in alpha3.0: Performance is no better, alas, but some fixes have been
made and some functionality has been added. (This is basically the "get
it out the door in time for 4.4" release.) One bug fix: regfree() didn't
free the main internal structure (how embarrassing). It is now possible
to put NULs in either the RE or the target string, using (resp.) a new
REG_PEND flag and the old REG_STARTEND flag. The REG_NOSPEC flag to
regcomp() makes all characters ordinary, so you can match a literal
string easily (this will become more useful when performance improves!).
There are now primitives to match beginnings and ends of words, although
the syntax is disgusting and so is the implementation. The REG_ATOI
debugging interface has changed a bit. And there has been considerable
internal cleanup of various kinds.
New in alpha2.3: Split change list out of README, and moved flags notes
into Makefile. Macro-ized the name of regex(7) in regex(3), since it has
to change for 4.4BSD. Cleanup work in engine.c, and some new regression
tests to catch tricky cases thereof.
New in alpha2.2: Out-of-date manpages updated. Regerror() acquires two
small extensions -- REG_ITOA and REG_ATOI -- which avoid debugging kludges
in my own test program and might be useful to others for similar purposes.
The regression test will now compile (and run) without REDEBUG. The
BRE \$ bug is fixed. Most uses of "uchar" are gone; it's all chars now.
Char/uchar parameters are now written int/unsigned, to avoid possible
portability problems with unpromoted parameters. Some unsigned casts have
been introduced to minimize portability problems with shifting into sign
bits.
New in alpha2.1: Lots of little stuff, cleanup and fixes. The one big
thing is that regex.h is now generated, using mkh, rather than being
supplied in the distribution; due to circularities in dependencies,
you have to build regex.h explicitly by "make h". The two known bugs
have been fixed (and the regression test now checks for them), as has a
problem with assertions not being suppressed in the absence of REDEBUG.
No performance work yet.
New in alpha2: Backslash-anything is an ordinary character, not an
error (except, of course, for the handful of backslashed metacharacters
in BREs), which should reduce script breakage. The regression test
checks *where* null strings are supposed to match, and has generally
been tightened up somewhat. Small bug fixes in parameter passing (not
harmful, but technically errors) and some other areas. Debugging
invoked by defining REDEBUG rather than not defining NDEBUG.
New in alpha+3: full prototyping for internal routines, using a little
helper program, mkh, which extracts prototypes given in stylized comments.
More minor cleanup. Buglet fix: it's CHAR_BIT, not CHAR_BITS. Simple
pre-screening of input when a literal string is known to be part of the
RE; this does wonders for performance.
New in alpha+2: minor bits of cleanup. Notably, the number "32" for the
word width isn't hardwired into regexec.c any more, the public header
file prototypes the functions if __STDC__ is defined, and some small typos
in the manpages have been fixed.
New in alpha+1: improvements to the manual pages, and an important
extension, the REG_STARTEND option to regexec().

View File

@@ -0,0 +1,70 @@
/*-
* Copyright (c) 1992, 1993, 1994 Henry Spencer.
* Copyright (c) 1992, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Henry Spencer.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)cclass.h 8.3 (Berkeley) 3/20/94
*/
/* character-class table */
static struct cclass {
char *name;
char *chars;
char *multis;
} cclasses[] = {
"alnum", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
0123456789", "",
"alpha", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
"",
"blank", " \t", "",
"cntrl", "\007\b\t\n\v\f\r\1\2\3\4\5\6\16\17\20\21\22\23\24\
\25\26\27\30\31\32\33\34\35\36\37\177", "",
"digit", "0123456789", "",
"graph", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",
"",
"lower", "abcdefghijklmnopqrstuvwxyz",
"",
"print", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ ",
"",
"punct", "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",
"",
"space", "\t\n\v\f\r ", "",
"upper", "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
"",
"xdigit", "0123456789ABCDEFabcdef",
"",
NULL, 0, ""
};

View File

@@ -0,0 +1,141 @@
/*-
* Copyright (c) 1992, 1993, 1994 Henry Spencer.
* Copyright (c) 1992, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Henry Spencer.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)cname.h 8.3 (Berkeley) 3/20/94
*/
/* character-name table */
static struct cname {
char *name;
char code;
} cnames[] = {
"NUL", '\0',
"SOH", '\001',
"STX", '\002',
"ETX", '\003',
"EOT", '\004',
"ENQ", '\005',
"ACK", '\006',
"BEL", '\007',
"alert", '\007',
"BS", '\010',
"backspace", '\b',
"HT", '\011',
"tab", '\t',
"LF", '\012',
"newline", '\n',
"VT", '\013',
"vertical-tab", '\v',
"FF", '\014',
"form-feed", '\f',
"CR", '\015',
"carriage-return", '\r',
"SO", '\016',
"SI", '\017',
"DLE", '\020',
"DC1", '\021',
"DC2", '\022',
"DC3", '\023',
"DC4", '\024',
"NAK", '\025',
"SYN", '\026',
"ETB", '\027',
"CAN", '\030',
"EM", '\031',
"SUB", '\032',
"ESC", '\033',
"IS4", '\034',
"FS", '\034',
"IS3", '\035',
"GS", '\035',
"IS2", '\036',
"RS", '\036',
"IS1", '\037',
"US", '\037',
"space", ' ',
"exclamation-mark", '!',
"quotation-mark", '"',
"number-sign", '#',
"dollar-sign", '$',
"percent-sign", '%',
"ampersand", '&',
"apostrophe", '\'',
"left-parenthesis", '(',
"right-parenthesis", ')',
"asterisk", '*',
"plus-sign", '+',
"comma", ',',
"hyphen", '-',
"hyphen-minus", '-',
"period", '.',
"full-stop", '.',
"slash", '/',
"solidus", '/',
"zero", '0',
"one", '1',
"two", '2',
"three", '3',
"four", '4',
"five", '5',
"six", '6',
"seven", '7',
"eight", '8',
"nine", '9',
"colon", ':',
"semicolon", ';',
"less-than-sign", '<',
"equals-sign", '=',
"greater-than-sign", '>',
"question-mark", '?',
"commercial-at", '@',
"left-square-bracket", '[',
"backslash", '\\',
"reverse-solidus", '\\',
"right-square-bracket", ']',
"circumflex", '^',
"circumflex-accent", '^',
"underscore", '_',
"low-line", '_',
"grave-accent", '`',
"left-brace", '{',
"left-curly-bracket", '{',
"vertical-line", '|',
"right-brace", '}',
"right-curly-bracket", '}',
"tilde", '~',
"DEL", '\177',
NULL, 0,
};

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,269 @@
.\" Copyright (c) 1992, 1993, 1994 Henry Spencer.
.\" Copyright (c) 1992, 1993, 1994
.\" The Regents of the University of California. All rights reserved.
.\"
.\" This code is derived from software contributed to Berkeley by
.\" Henry Spencer.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the University of
.\" California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)re_format.7 8.3 (Berkeley) 3/20/94
.\"
.TH RE_FORMAT 7 "March 20, 1994"
.SH NAME
re_format \- POSIX 1003.2 regular expressions
.SH DESCRIPTION
Regular expressions (``RE''s),
as defined in POSIX 1003.2, come in two forms:
modern REs (roughly those of
.IR egrep ;
1003.2 calls these ``extended'' REs)
and obsolete REs (roughly those of
.IR ed ;
1003.2 ``basic'' REs).
Obsolete REs mostly exist for backward compatibility in some old programs;
they will be discussed at the end.
1003.2 leaves some aspects of RE syntax and semantics open;
`\(dg' marks decisions on these aspects that
may not be fully portable to other 1003.2 implementations.
.PP
A (modern) RE is one\(dg or more non-empty\(dg \fIbranches\fR,
separated by `|'.
It matches anything that matches one of the branches.
.PP
A branch is one\(dg or more \fIpieces\fR, concatenated.
It matches a match for the first, followed by a match for the second, etc.
.PP
A piece is an \fIatom\fR possibly followed
by a single\(dg `*', `+', `?', or \fIbound\fR.
An atom followed by `*' matches a sequence of 0 or more matches of the atom.
An atom followed by `+' matches a sequence of 1 or more matches of the atom.
An atom followed by `?' matches a sequence of 0 or 1 matches of the atom.
.PP
A \fIbound\fR is `{' followed by an unsigned decimal integer,
possibly followed by `,'
possibly followed by another unsigned decimal integer,
always followed by `}'.
The integers must lie between 0 and RE_DUP_MAX (255\(dg) inclusive,
and if there are two of them, the first may not exceed the second.
An atom followed by a bound containing one integer \fIi\fR
and no comma matches
a sequence of exactly \fIi\fR matches of the atom.
An atom followed by a bound
containing one integer \fIi\fR and a comma matches
a sequence of \fIi\fR or more matches of the atom.
An atom followed by a bound
containing two integers \fIi\fR and \fIj\fR matches
a sequence of \fIi\fR through \fIj\fR (inclusive) matches of the atom.
.PP
An atom is a regular expression enclosed in `()' (matching a match for the
regular expression),
an empty set of `()' (matching the null string)\(dg,
a \fIbracket expression\fR (see below), `.'
(matching any single character), `^' (matching the null string at the
beginning of a line), `$' (matching the null string at the
end of a line), a `\e' followed by one of the characters
`^.[$()|*+?{\e'
(matching that character taken as an ordinary character),
a `\e' followed by any other character\(dg
(matching that character taken as an ordinary character,
as if the `\e' had not been present\(dg),
or a single character with no other significance (matching that character).
A `{' followed by a character other than a digit is an ordinary
character, not the beginning of a bound\(dg.
It is illegal to end an RE with `\e'.
.PP
A \fIbracket expression\fR is a list of characters enclosed in `[]'.
It normally matches any single character from the list (but see below).
If the list begins with `^',
it matches any single character
(but see below) \fInot\fR from the rest of the list.
If two characters in the list are separated by `\-', this is shorthand
for the full \fIrange\fR of characters between those two (inclusive) in the
collating sequence,
e.g. `[0-9]' in ASCII matches any decimal digit.
It is illegal\(dg for two ranges to share an
endpoint, e.g. `a-c-e'.
Ranges are very collating-sequence-dependent,
and portable programs should avoid relying on them.
.PP
To include a literal `]' in the list, make it the first character
(following a possible `^').
To include a literal `\-', make it the first or last character,
or the second endpoint of a range.
To use a literal `\-' as the first endpoint of a range,
enclose it in `[.' and `.]' to make it a collating element (see below).
With the exception of these and some combinations using `[' (see next
paragraphs), all other special characters, including `\e', lose their
special significance within a bracket expression.
.PP
Within a bracket expression, a collating element (a character,
a multi-character sequence that collates as if it were a single character,
or a collating-sequence name for either)
enclosed in `[.' and `.]' stands for the
sequence of characters of that collating element.
The sequence is a single element of the bracket expression's list.
A bracket expression containing a multi-character collating element
can thus match more than one character,
e.g. if the collating sequence includes a `ch' collating element,
then the RE `[[.ch.]]*c' matches the first five characters
of `chchcc'.
.PP
Within a bracket expression, a collating element enclosed in `[=' and
`=]' is an equivalence class, standing for the sequences of characters
of all collating elements equivalent to that one, including itself.
(If there are no other equivalent collating elements,
the treatment is as if the enclosing delimiters were `[.' and `.]'.)
For example, if o and \o'o^' are the members of an equivalence class,
then `[[=o=]]', `[[=\o'o^'=]]', and `[o\o'o^']' are all synonymous.
An equivalence class may not\(dg be an endpoint
of a range.
.PP
Within a bracket expression, the name of a \fIcharacter class\fR enclosed
in `[:' and `:]' stands for the list of all characters belonging to that
class.
Standard character class names are:
.PP
.RS
.nf
.ta 3c 6c 9c
alnum digit punct
alpha graph space
blank lower upper
cntrl print xdigit
.fi
.RE
.PP
These stand for the character classes defined in
.IR ctype (3).
A locale may provide others.
A character class may not be used as an endpoint of a range.
.PP
There are two special cases\(dg of bracket expressions:
the bracket expressions `[[:<:]]' and `[[:>:]]' match the null string at
the beginning and end of a word respectively.
A word is defined as a sequence of
word characters
which is neither preceded nor followed by
word characters.
A word character is an
.I alnum
character (as defined by
.IR ctype (3))
or an underscore.
This is an extension,
compatible with but not specified by POSIX 1003.2,
and should be used with
caution in software intended to be portable to other systems.
.PP
In the event that an RE could match more than one substring of a given
string,
the RE matches the one starting earliest in the string.
If the RE could match more than one substring starting at that point,
it matches the longest.
Subexpressions also match the longest possible substrings, subject to
the constraint that the whole match be as long as possible,
with subexpressions starting earlier in the RE taking priority over
ones starting later.
Note that higher-level subexpressions thus take priority over
their lower-level component subexpressions.
.PP
Match lengths are measured in characters, not collating elements.
A null string is considered longer than no match at all.
For example,
`bb*' matches the three middle characters of `abbbc',
`(wee|week)(knights|nights)' matches all ten characters of `weeknights',
when `(.*).*' is matched against `abc' the parenthesized subexpression
matches all three characters, and
when `(a*)*' is matched against `bc' both the whole RE and the parenthesized
subexpression match the null string.
.PP
If case-independent matching is specified,
the effect is much as if all case distinctions had vanished from the
alphabet.
When an alphabetic that exists in multiple cases appears as an
ordinary character outside a bracket expression, it is effectively
transformed into a bracket expression containing both cases,
e.g. `x' becomes `[xX]'.
When it appears inside a bracket expression, all case counterparts
of it are added to the bracket expression, so that (e.g.) `[x]'
becomes `[xX]' and `[^x]' becomes `[^xX]'.
.PP
No particular limit is imposed on the length of REs\(dg.
Programs intended to be portable should not employ REs longer
than 256 bytes,
as an implementation can refuse to accept such REs and remain
POSIX-compliant.
.PP
Obsolete (``basic'') regular expressions differ in several respects.
`|', `+', and `?' are ordinary characters and there is no equivalent
for their functionality.
The delimiters for bounds are `\e{' and `\e}',
with `{' and `}' by themselves ordinary characters.
The parentheses for nested subexpressions are `\e(' and `\e)',
with `(' and `)' by themselves ordinary characters.
`^' is an ordinary character except at the beginning of the
RE or\(dg the beginning of a parenthesized subexpression,
`$' is an ordinary character except at the end of the
RE or\(dg the end of a parenthesized subexpression,
and `*' is an ordinary character if it appears at the beginning of the
RE or the beginning of a parenthesized subexpression
(after a possible leading `^').
Finally, there is one new type of atom, a \fIback reference\fR:
`\e' followed by a non-zero decimal digit \fId\fR
matches the same sequence of characters
matched by the \fId\fRth parenthesized subexpression
(numbering subexpressions by the positions of their opening parentheses,
left to right),
so that (e.g.) `\e([bc]\e)\e1' matches `bb' or `cc' but not `bc'.
.SH SEE ALSO
regex(3)
.PP
POSIX 1003.2, section 2.8 (Regular Expression Notation).
.SH BUGS
Having two kinds of REs is a botch.
.PP
The current 1003.2 spec says that `)' is an ordinary character in
the absence of an unmatched `(';
this was an unintentional result of a wording error,
and change is likely.
Avoid relying on it.
.PP
Back references are a dreadful botch,
posing major problems for efficient implementations.
They are also somewhat vaguely defined
(does
`a\e(\e(b\e)*\e2\e)*d' match `abbbd'?).
Avoid using them.
.PP
1003.2's specification of case-independent matching is vague.
The ``one case implies all cases'' definition given above
is current consensus among implementors as to the right interpretation.
.PP
The syntax for word boundaries is incredibly ugly.

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,180 @@
/*-
* Copyright (c) 1992, 1993, 1994 Henry Spencer.
* Copyright (c) 1992, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Henry Spencer.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)regerror.c 8.4 (Berkeley) 3/20/94
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)regerror.c 8.4 (Berkeley) 3/20/94";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#include <stdlib.h>
#include <regex.h>
#include "utils.h"
/* ========= begin header generated by ./mkh ========= */
#ifdef __cplusplus
extern "C" {
#endif
/* === regerror.c === */
static char *regatoi __P((const regex_t *preg, char *localbuf));
#ifdef __cplusplus
}
#endif
/* ========= end header generated by ./mkh ========= */
/*
= #define REG_NOMATCH 1
= #define REG_BADPAT 2
= #define REG_ECOLLATE 3
= #define REG_ECTYPE 4
= #define REG_EESCAPE 5
= #define REG_ESUBREG 6
= #define REG_EBRACK 7
= #define REG_EPAREN 8
= #define REG_EBRACE 9
= #define REG_BADBR 10
= #define REG_ERANGE 11
= #define REG_ESPACE 12
= #define REG_BADRPT 13
= #define REG_EMPTY 14
= #define REG_ASSERT 15
= #define REG_INVARG 16
= #define REG_ATOI 255 // convert name to number (!)
= #define REG_ITOA 0400 // convert number to name (!)
*/
static struct rerr {
int code;
char *name;
char *explain;
} rerrs[] = {
REG_NOMATCH, "REG_NOMATCH", "regexec() failed to match",
REG_BADPAT, "REG_BADPAT", "invalid regular expression",
REG_ECOLLATE, "REG_ECOLLATE", "invalid collating element",
REG_ECTYPE, "REG_ECTYPE", "invalid character class",
REG_EESCAPE, "REG_EESCAPE", "trailing backslash (\\)",
REG_ESUBREG, "REG_ESUBREG", "invalid backreference number",
REG_EBRACK, "REG_EBRACK", "brackets ([ ]) not balanced",
REG_EPAREN, "REG_EPAREN", "parentheses not balanced",
REG_EBRACE, "REG_EBRACE", "braces not balanced",
REG_BADBR, "REG_BADBR", "invalid repetition count(s)",
REG_ERANGE, "REG_ERANGE", "invalid character range",
REG_ESPACE, "REG_ESPACE", "out of memory",
REG_BADRPT, "REG_BADRPT", "repetition-operator operand invalid",
REG_EMPTY, "REG_EMPTY", "empty (sub)expression",
REG_ASSERT, "REG_ASSERT", "\"can't happen\" -- you found a bug",
REG_INVARG, "REG_INVARG", "invalid argument to regex routine",
0, "", "*** unknown regexp error code ***",
};
/*
- regerror - the interface to error numbers
= extern size_t regerror(int, const regex_t *, char *, size_t);
*/
/* ARGSUSED */
size_t
regerror(errcode, preg, errbuf, errbuf_size)
int errcode;
const regex_t *preg;
char *errbuf;
size_t errbuf_size;
{
register struct rerr *r;
register size_t len;
register int target = errcode &~ REG_ITOA;
register char *s;
char convbuf[50];
if (errcode == REG_ATOI)
s = regatoi(preg, convbuf);
else {
for (r = rerrs; r->code != 0; r++)
if (r->code == target)
break;
if (errcode&REG_ITOA) {
if (r->code != 0)
(void) strcpy(convbuf, r->name);
else
sprintf(convbuf, "REG_0x%x", target);
assert(strlen(convbuf) < sizeof(convbuf));
s = convbuf;
} else
s = r->explain;
}
len = strlen(s) + 1;
if (errbuf_size > 0) {
if (errbuf_size > len)
(void) strcpy(errbuf, s);
else {
(void) strncpy(errbuf, s, errbuf_size-1);
errbuf[errbuf_size-1] = '\0';
}
}
return(len);
}
/*
- regatoi - internal routine to implement REG_ATOI
== static char *regatoi(const regex_t *preg, char *localbuf);
*/
static char *
regatoi(preg, localbuf)
const regex_t *preg;
char *localbuf;
{
register struct rerr *r;
register size_t siz;
register char *p;
for (r = rerrs; r->code != 0; r++)
if (strcmp(r->name, preg->re_endp) == 0)
break;
if (r->code == 0)
return("0");
sprintf(localbuf, "%d", r->code);
return(localbuf);
}

View File

@@ -0,0 +1,538 @@
.\" Copyright (c) 1992, 1993, 1994 Henry Spencer.
.\" Copyright (c) 1992, 1993, 1994
.\" The Regents of the University of California. All rights reserved.
.\"
.\" This code is derived from software contributed to Berkeley by
.\" Henry Spencer.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the University of
.\" California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)regex.3 8.4 (Berkeley) 3/20/94
.\"
.TH REGEX 3 "March 20, 1994"
.de ZR
.\" one other place knows this name: the SEE ALSO section
.IR re_format (7) \\$1
..
.SH NAME
regcomp, regexec, regerror, regfree \- regular-expression library
.SH SYNOPSIS
.ft B
.\".na
#include <sys/types.h>
.br
#include <regex.h>
.HP 10
int regcomp(regex_t\ *preg, const\ char\ *pattern, int\ cflags);
.HP
int\ regexec(const\ regex_t\ *preg, const\ char\ *string,
size_t\ nmatch, regmatch_t\ pmatch[], int\ eflags);
.HP
size_t\ regerror(int\ errcode, const\ regex_t\ *preg,
char\ *errbuf, size_t\ errbuf_size);
.HP
void\ regfree(regex_t\ *preg);
.\".ad
.ft
.SH DESCRIPTION
These routines implement POSIX 1003.2 regular expressions (``RE''s);
see
.ZR .
.I Regcomp
compiles an RE written as a string into an internal form,
.I regexec
matches that internal form against a string and reports results,
.I regerror
transforms error codes from either into human-readable messages,
and
.I regfree
frees any dynamically-allocated storage used by the internal form
of an RE.
.PP
The header
.I <regex.h>
declares two structure types,
.I regex_t
and
.IR regmatch_t ,
the former for compiled internal forms and the latter for match reporting.
It also declares the four functions,
a type
.IR regoff_t ,
and a number of constants with names starting with ``REG_''.
.PP
.I Regcomp
compiles the regular expression contained in the
.I pattern
string,
subject to the flags in
.IR cflags ,
and places the results in the
.I regex_t
structure pointed to by
.IR preg .
.I Cflags
is the bitwise OR of zero or more of the following flags:
.IP REG_EXTENDED \w'REG_EXTENDED'u+2n
Compile modern (``extended'') REs,
rather than the obsolete (``basic'') REs that
are the default.
.IP REG_BASIC
This is a synonym for 0,
provided as a counterpart to REG_EXTENDED to improve readability.
.IP REG_NOSPEC
Compile with recognition of all special characters turned off.
All characters are thus considered ordinary,
so the ``RE'' is a literal string.
This is an extension,
compatible with but not specified by POSIX 1003.2,
and should be used with
caution in software intended to be portable to other systems.
REG_EXTENDED and REG_NOSPEC may not be used
in the same call to
.IR regcomp .
.IP REG_ICASE
Compile for matching that ignores upper/lower case distinctions.
See
.ZR .
.IP REG_NOSUB
Compile for matching that need only report success or failure,
not what was matched.
.IP REG_NEWLINE
Compile for newline-sensitive matching.
By default, newline is a completely ordinary character with no special
meaning in either REs or strings.
With this flag,
`[^' bracket expressions and `.' never match newline,
a `^' anchor matches the null string after any newline in the string
in addition to its normal function,
and the `$' anchor matches the null string before any newline in the
string in addition to its normal function.
.IP REG_PEND
The regular expression ends,
not at the first NUL,
but just before the character pointed to by the
.I re_endp
member of the structure pointed to by
.IR preg .
The
.I re_endp
member is of type
.IR const\ char\ * .
This flag permits inclusion of NULs in the RE;
they are considered ordinary characters.
This is an extension,
compatible with but not specified by POSIX 1003.2,
and should be used with
caution in software intended to be portable to other systems.
.PP
When successful,
.I regcomp
returns 0 and fills in the structure pointed to by
.IR preg .
One member of that structure
(other than
.IR re_endp )
is publicized:
.IR re_nsub ,
of type
.IR size_t ,
contains the number of parenthesized subexpressions within the RE
(except that the value of this member is undefined if the
REG_NOSUB flag was used).
If
.I regcomp
fails, it returns a non-zero error code;
see DIAGNOSTICS.
.PP
.I Regexec
matches the compiled RE pointed to by
.I preg
against the
.IR string ,
subject to the flags in
.IR eflags ,
and reports results using
.IR nmatch ,
.IR pmatch ,
and the returned value.
The RE must have been compiled by a previous invocation of
.IR regcomp .
The compiled form is not altered during execution of
.IR regexec ,
so a single compiled RE can be used simultaneously by multiple threads.
.PP
By default,
the NUL-terminated string pointed to by
.I string
is considered to be the text of an entire line, minus any terminating
newline.
The
.I eflags
argument is the bitwise OR of zero or more of the following flags:
.IP REG_NOTBOL \w'REG_STARTEND'u+2n
The first character of
the string
is not the beginning of a line, so the `^' anchor should not match before it.
This does not affect the behavior of newlines under REG_NEWLINE.
.IP REG_NOTEOL
The NUL terminating
the string
does not end a line, so the `$' anchor should not match before it.
This does not affect the behavior of newlines under REG_NEWLINE.
.IP REG_STARTEND
The string is considered to start at
\fIstring\fR\ + \fIpmatch\fR[0].\fIrm_so\fR
and to have a terminating NUL located at
\fIstring\fR\ + \fIpmatch\fR[0].\fIrm_eo\fR
(there need not actually be a NUL at that location),
regardless of the value of
.IR nmatch .
See below for the definition of
.IR pmatch
and
.IR nmatch .
This is an extension,
compatible with but not specified by POSIX 1003.2,
and should be used with
caution in software intended to be portable to other systems.
Note that a non-zero \fIrm_so\fR does not imply REG_NOTBOL;
REG_STARTEND affects only the location of the string,
not how it is matched.
.PP
See
.ZR
for a discussion of what is matched in situations where an RE or a
portion thereof could match any of several substrings of
.IR string .
.PP
Normally,
.I regexec
returns 0 for success and the non-zero code REG_NOMATCH for failure.
Other non-zero error codes may be returned in exceptional situations;
see DIAGNOSTICS.
.PP
If REG_NOSUB was specified in the compilation of the RE,
or if
.I nmatch
is 0,
.I regexec
ignores the
.I pmatch
argument (but see below for the case where REG_STARTEND is specified).
Otherwise,
.I pmatch
points to an array of
.I nmatch
structures of type
.IR regmatch_t .
Such a structure has at least the members
.I rm_so
and
.IR rm_eo ,
both of type
.I regoff_t
(a signed arithmetic type at least as large as an
.I off_t
and a
.IR ssize_t ),
containing respectively the offset of the first character of a substring
and the offset of the first character after the end of the substring.
Offsets are measured from the beginning of the
.I string
argument given to
.IR regexec .
An empty substring is denoted by equal offsets,
both indicating the character following the empty substring.
.PP
The 0th member of the
.I pmatch
array is filled in to indicate what substring of
.I string
was matched by the entire RE.
Remaining members report what substring was matched by parenthesized
subexpressions within the RE;
member
.I i
reports subexpression
.IR i ,
with subexpressions counted (starting at 1) by the order of their opening
parentheses in the RE, left to right.
Unused entries in the array\(emcorresponding either to subexpressions that
did not participate in the match at all, or to subexpressions that do not
exist in the RE (that is, \fIi\fR\ > \fIpreg\fR\->\fIre_nsub\fR)\(emhave both
.I rm_so
and
.I rm_eo
set to \-1.
If a subexpression participated in the match several times,
the reported substring is the last one it matched.
(Note, as an example in particular, that when the RE `(b*)+' matches `bbb',
the parenthesized subexpression matches each of the three `b's and then
an infinite number of empty strings following the last `b',
so the reported substring is one of the empties.)
.PP
If REG_STARTEND is specified,
.I pmatch
must point to at least one
.I regmatch_t
(even if
.I nmatch
is 0 or REG_NOSUB was specified),
to hold the input offsets for REG_STARTEND.
Use for output is still entirely controlled by
.IR nmatch ;
if
.I nmatch
is 0 or REG_NOSUB was specified,
the value of
.IR pmatch [0]
will not be changed by a successful
.IR regexec .
.PP
.I Regerror
maps a non-zero
.I errcode
from either
.I regcomp
or
.I regexec
to a human-readable, printable message.
If
.I preg
is non-NULL,
the error code should have arisen from use of
the
.I regex_t
pointed to by
.IR preg ,
and if the error code came from
.IR regcomp ,
it should have been the result from the most recent
.I regcomp
using that
.IR regex_t .
.RI ( Regerror
may be able to supply a more detailed message using information
from the
.IR regex_t .)
.I Regerror
places the NUL-terminated message into the buffer pointed to by
.IR errbuf ,
limiting the length (including the NUL) to at most
.I errbuf_size
bytes.
If the whole message won't fit,
as much of it as will fit before the terminating NUL is supplied.
In any case,
the returned value is the size of buffer needed to hold the whole
message (including terminating NUL).
If
.I errbuf_size
is 0,
.I errbuf
is ignored but the return value is still correct.
.PP
If the
.I errcode
given to
.I regerror
is first ORed with REG_ITOA,
the ``message'' that results is the printable name of the error code,
e.g. ``REG_NOMATCH'',
rather than an explanation thereof.
If
.I errcode
is REG_ATOI,
then
.I preg
shall be non-NULL and the
.I re_endp
member of the structure it points to
must point to the printable name of an error code;
in this case, the result in
.I errbuf
is the decimal digits of
the numeric value of the error code
(0 if the name is not recognized).
REG_ITOA and REG_ATOI are intended primarily as debugging facilities;
they are extensions,
compatible with but not specified by POSIX 1003.2,
and should be used with
caution in software intended to be portable to other systems.
Be warned also that they are considered experimental and changes are possible.
.PP
.I Regfree
frees any dynamically-allocated storage associated with the compiled RE
pointed to by
.IR preg .
The remaining
.I regex_t
is no longer a valid compiled RE
and the effect of supplying it to
.I regexec
or
.I regerror
is undefined.
.PP
None of these functions references global variables except for tables
of constants;
all are safe for use from multiple threads if the arguments are safe.
.SH IMPLEMENTATION CHOICES
There are a number of decisions that 1003.2 leaves up to the implementor,
either by explicitly saying ``undefined'' or by virtue of them being
forbidden by the RE grammar.
This implementation treats them as follows.
.PP
See
.ZR
for a discussion of the definition of case-independent matching.
.PP
There is no particular limit on the length of REs,
except insofar as memory is limited.
Memory usage is approximately linear in RE size, and largely insensitive
to RE complexity, except for bounded repetitions.
See BUGS for one short RE using them
that will run almost any system out of memory.
.PP
A backslashed character other than one specifically given a magic meaning
by 1003.2 (such magic meanings occur only in obsolete [``basic''] REs)
is taken as an ordinary character.
.PP
Any unmatched [ is a REG_EBRACK error.
.PP
Equivalence classes cannot begin or end bracket-expression ranges.
The endpoint of one range cannot begin another.
.PP
RE_DUP_MAX, the limit on repetition counts in bounded repetitions, is 255.
.PP
A repetition operator (?, *, +, or bounds) cannot follow another
repetition operator.
A repetition operator cannot begin an expression or subexpression
or follow `^' or `|'.
.PP
`|' cannot appear first or last in a (sub)expression or after another `|',
i.e. an operand of `|' cannot be an empty subexpression.
An empty parenthesized subexpression, `()', is legal and matches an
empty (sub)string.
An empty string is not a legal RE.
.PP
A `{' followed by a digit is considered the beginning of bounds for a
bounded repetition, which must then follow the syntax for bounds.
A `{' \fInot\fR followed by a digit is considered an ordinary character.
.PP
`^' and `$' beginning and ending subexpressions in obsolete (``basic'')
REs are anchors, not ordinary characters.
.SH SEE ALSO
grep(1), re_format(7)
.PP
POSIX 1003.2, sections 2.8 (Regular Expression Notation)
and
B.5 (C Binding for Regular Expression Matching).
.SH DIAGNOSTICS
Non-zero error codes from
.I regcomp
and
.I regexec
include the following:
.PP
.nf
.ta \w'REG_ECOLLATE'u+3n
REG_NOMATCH regexec() failed to match
REG_BADPAT invalid regular expression
REG_ECOLLATE invalid collating element
REG_ECTYPE invalid character class
REG_EESCAPE \e applied to unescapable character
REG_ESUBREG invalid backreference number
REG_EBRACK brackets [ ] not balanced
REG_EPAREN parentheses ( ) not balanced
REG_EBRACE braces { } not balanced
REG_BADBR invalid repetition count(s) in { }
REG_ERANGE invalid character range in [ ]
REG_ESPACE ran out of memory
REG_BADRPT ?, *, or + operand invalid
REG_EMPTY empty (sub)expression
REG_ASSERT ``can't happen''\(emyou found a bug
REG_INVARG invalid argument, e.g. negative-length string
.fi
.SH HISTORY
Originally written by Henry Spencer.
Altered for inclusion in the 4.4BSD distribution.
.SH BUGS
This is an alpha release with known defects.
Please report problems.
.PP
There is one known functionality bug.
The implementation of internationalization is incomplete:
the locale is always assumed to be the default one of 1003.2,
and only the collating elements etc. of that locale are available.
.PP
The back-reference code is subtle and doubts linger about its correctness
in complex cases.
.PP
.I Regexec
performance is poor.
This will improve with later releases.
.I Nmatch
exceeding 0 is expensive;
.I nmatch
exceeding 1 is worse.
.I Regexec
is largely insensitive to RE complexity \fIexcept\fR that back
references are massively expensive.
RE length does matter; in particular, there is a strong speed bonus
for keeping RE length under about 30 characters,
with most special characters counting roughly double.
.PP
.I Regcomp
implements bounded repetitions by macro expansion,
which is costly in time and space if counts are large
or bounded repetitions are nested.
An RE like, say,
`((((a{1,100}){1,100}){1,100}){1,100}){1,100}'
will (eventually) run almost any existing machine out of swap space.
.PP
There are suspected problems with response to obscure error conditions.
Notably,
certain kinds of internal overflow,
produced only by truly enormous REs or by multiply nested bounded repetitions,
are probably not handled well.
.PP
Due to a mistake in 1003.2, things like `a)b' are legal REs because `)' is
a special character only in the presence of a previous unmatched `('.
This can't be fixed until the spec is fixed.
.PP
The standard's definition of back references is vague.
For example, does
`a\e(\e(b\e)*\e2\e)*d' match `abbbd'?
Until the standard is clarified,
behavior in such cases should not be relied on.
.PP
The implementation of word-boundary matching is a bit of a kludge,
and bugs may lurk in combinations of word-boundary matching and anchoring.

View File

@@ -0,0 +1,106 @@
/*-
* Copyright (c) 1992 Henry Spencer.
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Henry Spencer of the University of Toronto.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)regex.h 8.2 (Berkeley) 1/3/94
*/
#ifndef _REGEX_H_
#define _REGEX_H_
#include <sys/cdefs.h>
/* types */
typedef off_t regoff_t;
typedef struct {
int re_magic;
size_t re_nsub; /* number of parenthesized subexpressions */
__const char *re_endp; /* end pointer for REG_PEND */
struct re_guts *re_g; /* none of your business :-) */
} regex_t;
typedef struct {
regoff_t rm_so; /* start of match */
regoff_t rm_eo; /* end of match */
} regmatch_t;
/* regcomp() flags */
#define REG_BASIC 0000
#define REG_EXTENDED 0001
#define REG_ICASE 0002
#define REG_NOSUB 0004
#define REG_NEWLINE 0010
#define REG_NOSPEC 0020
#define REG_PEND 0040
#define REG_DUMP 0200
/* regerror() flags */
#define REG_NOMATCH 1
#define REG_BADPAT 2
#define REG_ECOLLATE 3
#define REG_ECTYPE 4
#define REG_EESCAPE 5
#define REG_ESUBREG 6
#define REG_EBRACK 7
#define REG_EPAREN 8
#define REG_EBRACE 9
#define REG_BADBR 10
#define REG_ERANGE 11
#define REG_ESPACE 12
#define REG_BADRPT 13
#define REG_EMPTY 14
#define REG_ASSERT 15
#define REG_INVARG 16
#define REG_ATOI 255 /* convert name to number (!) */
#define REG_ITOA 0400 /* convert number to name (!) */
/* regexec() flags */
#define REG_NOTBOL 00001
#define REG_NOTEOL 00002
#define REG_STARTEND 00004
#define REG_TRACE 00400 /* tracing of execution */
#define REG_LARGE 01000 /* force large representation */
#define REG_BACKR 02000 /* force use of backref code */
__BEGIN_DECLS
int regcomp __P((regex_t *, const char *, int));
size_t regerror __P((int, const regex_t *, char *, size_t));
int regexec __P((const regex_t *,
const char *, size_t, regmatch_t [], int));
void regfree __P((regex_t *));
__END_DECLS
#endif /* !_REGEX_H_ */

View File

@@ -0,0 +1,175 @@
/*-
* Copyright (c) 1992, 1993, 1994 Henry Spencer.
* Copyright (c) 1992, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Henry Spencer.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)regex2.h 8.4 (Berkeley) 3/20/94
*/
/*
* First, the stuff that ends up in the outside-world include file
*/
/*
typedef off_t regoff_t;
typedef struct {
int re_magic;
size_t re_nsub; // number of parenthesized subexpressions
const char *re_endp; // end pointer for REG_PEND
struct re_guts *re_g; // none of your business :-)
} regex_t;
typedef struct {
regoff_t rm_so; // start of match
regoff_t rm_eo; // end of match
} regmatch_t;
*/
/*
* internals of regex_t
*/
#define MAGIC1 ((('r'^0200)<<8) | 'e')
/*
* The internal representation is a *strip*, a sequence of
* operators ending with an endmarker. (Some terminology etc. is a
* historical relic of earlier versions which used multiple strips.)
* Certain oddities in the representation are there to permit running
* the machinery backwards; in particular, any deviation from sequential
* flow must be marked at both its source and its destination. Some
* fine points:
*
* - OPLUS_ and O_PLUS are *inside* the loop they create.
* - OQUEST_ and O_QUEST are *outside* the bypass they create.
* - OCH_ and O_CH are *outside* the multi-way branch they create, while
* OOR1 and OOR2 are respectively the end and the beginning of one of
* the branches. Note that there is an implicit OOR2 following OCH_
* and an implicit OOR1 preceding O_CH.
*
* In state representations, an operator's bit is on to signify a state
* immediately *preceding* "execution" of that operator.
*/
typedef unsigned long sop; /* strip operator */
typedef long sopno;
#define OPRMASK 0xf8000000
#define OPDMASK 0x07ffffff
#define OPSHIFT ((unsigned)27)
#define OP(n) ((n)&OPRMASK)
#define OPND(n) ((n)&OPDMASK)
#define SOP(op, opnd) ((op)|(opnd))
/* operators meaning operand */
/* (back, fwd are offsets) */
#define OEND (1<<OPSHIFT) /* endmarker - */
#define OCHAR (2<<OPSHIFT) /* character unsigned char */
#define OBOL (3<<OPSHIFT) /* left anchor - */
#define OEOL (4<<OPSHIFT) /* right anchor - */
#define OANY (5<<OPSHIFT) /* . - */
#define OANYOF (6<<OPSHIFT) /* [...] set number */
#define OBACK_ (7<<OPSHIFT) /* begin \d paren number */
#define O_BACK (8<<OPSHIFT) /* end \d paren number */
#define OPLUS_ (9<<OPSHIFT) /* + prefix fwd to suffix */
#define O_PLUS (10<<OPSHIFT) /* + suffix back to prefix */
#define OQUEST_ (11<<OPSHIFT) /* ? prefix fwd to suffix */
#define O_QUEST (12<<OPSHIFT) /* ? suffix back to prefix */
#define OLPAREN (13<<OPSHIFT) /* ( fwd to ) */
#define ORPAREN (14<<OPSHIFT) /* ) back to ( */
#define OCH_ (15<<OPSHIFT) /* begin choice fwd to OOR2 */
#define OOR1 (16<<OPSHIFT) /* | pt. 1 back to OOR1 or OCH_ */
#define OOR2 (17<<OPSHIFT) /* | pt. 2 fwd to OOR2 or O_CH */
#define O_CH (18<<OPSHIFT) /* end choice back to OOR1 */
#define OBOW (19<<OPSHIFT) /* begin word - */
#define OEOW (20<<OPSHIFT) /* end word - */
/*
* Structure for [] character-set representation. Character sets are
* done as bit vectors, grouped 8 to a byte vector for compactness.
* The individual set therefore has both a pointer to the byte vector
* and a mask to pick out the relevant bit of each byte. A hash code
* simplifies testing whether two sets could be identical.
*
* This will get trickier for multicharacter collating elements. As
* preliminary hooks for dealing with such things, we also carry along
* a string of multi-character elements, and decide the size of the
* vectors at run time.
*/
typedef struct {
uch *ptr; /* -> uch [csetsize] */
uch mask; /* bit within array */
uch hash; /* hash code */
size_t smultis;
char *multis; /* -> char[smulti] ab\0cd\0ef\0\0 */
} cset;
/* note that CHadd and CHsub are unsafe, and CHIN doesn't yield 0/1 */
#define CHadd(cs, c) ((cs)->ptr[(uch)(c)] |= (cs)->mask, (cs)->hash += (c))
#define CHsub(cs, c) ((cs)->ptr[(uch)(c)] &= ~(cs)->mask, (cs)->hash -= (c))
#define CHIN(cs, c) ((cs)->ptr[(uch)(c)] & (cs)->mask)
#define MCadd(p, cs, cp) mcadd(p, cs, cp) /* regcomp() internal fns */
#define MCsub(p, cs, cp) mcsub(p, cs, cp)
#define MCin(p, cs, cp) mcin(p, cs, cp)
/* stuff for character categories */
typedef unsigned char cat_t;
/*
* main compiled-expression structure
*/
struct re_guts {
int magic;
# define MAGIC2 ((('R'^0200)<<8)|'E')
sop *strip; /* malloced area for strip */
int csetsize; /* number of bits in a cset vector */
int ncsets; /* number of csets in use */
cset *sets; /* -> cset [ncsets] */
uch *setbits; /* -> uch[csetsize][ncsets/CHAR_BIT] */
int cflags; /* copy of regcomp() cflags argument */
sopno nstates; /* = number of sops */
sopno firststate; /* the initial OEND (normally 0) */
sopno laststate; /* the final OEND */
int iflags; /* internal flags */
# define USEBOL 01 /* used ^ */
# define USEEOL 02 /* used $ */
# define BAD 04 /* something wrong */
int nbol; /* number of ^ used */
int neol; /* number of $ used */
int ncategories; /* how many character categories */
cat_t *categories; /* ->catspace[-CHAR_MIN] */
char *must; /* match must contain this string */
int mlen; /* length of must */
size_t nsub; /* copy of re_nsub */
int backrefs; /* does it use back references? */
sopno nplus; /* how deep does it nest +s? */
/* catspace must be last */
cat_t catspace[1]; /* actually [NC] */
};
/* misc utilities */
#define OUT (CHAR_MAX+1) /* a non-character value */
#define ISWORD(c) (isalnum(c) || (c) == '_')

View File

@@ -0,0 +1,181 @@
/*-
* Copyright (c) 1992, 1993, 1994 Henry Spencer.
* Copyright (c) 1992, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Henry Spencer.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)regexec.c 8.3 (Berkeley) 3/20/94
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)regexec.c 8.3 (Berkeley) 3/20/94";
#endif /* LIBC_SCCS and not lint */
/*
* the outer shell of regexec()
*
* This file includes engine.c *twice*, after muchos fiddling with the
* macros that code uses. This lets the same code operate on two different
* representations for state sets.
*/
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <ctype.h>
#include <regex.h>
#include "utils.h"
#include "regex2.h"
static int nope = 0; /* for use in asserts; shuts lint up */
/* macros for manipulating states, small version */
#define states long
#define states1 states /* for later use in regexec() decision */
#define CLEAR(v) ((v) = 0)
#define SET0(v, n) ((v) &= ~(1 << (n)))
#define SET1(v, n) ((v) |= 1 << (n))
#define ISSET(v, n) ((v) & (1 << (n)))
#define ASSIGN(d, s) ((d) = (s))
#define EQ(a, b) ((a) == (b))
#define STATEVARS int dummy /* dummy version */
#define STATESETUP(m, n) /* nothing */
#define STATETEARDOWN(m) /* nothing */
#define SETUP(v) ((v) = 0)
#define onestate int
#define INIT(o, n) ((o) = (unsigned)1 << (n))
#define INC(o) ((o) <<= 1)
#define ISSTATEIN(v, o) ((v) & (o))
/* some abbreviations; note that some of these know variable names! */
/* do "if I'm here, I can also be there" etc without branches */
#define FWD(dst, src, n) ((dst) |= ((unsigned)(src)&(here)) << (n))
#define BACK(dst, src, n) ((dst) |= ((unsigned)(src)&(here)) >> (n))
#define ISSETBACK(v, n) ((v) & ((unsigned)here >> (n)))
/* function names */
#define SNAMES /* engine.c looks after details */
#include "engine.c"
/* now undo things */
#undef states
#undef CLEAR
#undef SET0
#undef SET1
#undef ISSET
#undef ASSIGN
#undef EQ
#undef STATEVARS
#undef STATESETUP
#undef STATETEARDOWN
#undef SETUP
#undef onestate
#undef INIT
#undef INC
#undef ISSTATEIN
#undef FWD
#undef BACK
#undef ISSETBACK
#undef SNAMES
/* macros for manipulating states, large version */
#define states char *
#define CLEAR(v) memset(v, 0, m->g->nstates)
#define SET0(v, n) ((v)[n] = 0)
#define SET1(v, n) ((v)[n] = 1)
#define ISSET(v, n) ((v)[n])
#define ASSIGN(d, s) memcpy(d, s, m->g->nstates)
#define EQ(a, b) (memcmp(a, b, m->g->nstates) == 0)
#define STATEVARS int vn; char *space
#define STATESETUP(m, nv) { (m)->space = malloc((nv)*(m)->g->nstates); \
if ((m)->space == NULL) return(REG_ESPACE); \
(m)->vn = 0; }
#define STATETEARDOWN(m) { free((m)->space); }
#define SETUP(v) ((v) = &m->space[m->vn++ * m->g->nstates])
#define onestate int
#define INIT(o, n) ((o) = (n))
#define INC(o) ((o)++)
#define ISSTATEIN(v, o) ((v)[o])
/* some abbreviations; note that some of these know variable names! */
/* do "if I'm here, I can also be there" etc without branches */
#define FWD(dst, src, n) ((dst)[here+(n)] |= (src)[here])
#define BACK(dst, src, n) ((dst)[here-(n)] |= (src)[here])
#define ISSETBACK(v, n) ((v)[here - (n)])
/* function names */
#define LNAMES /* flag */
#include "engine.c"
/*
- regexec - interface for matching
= extern int regexec(const regex_t *, const char *, size_t, \
= regmatch_t [], int);
= #define REG_NOTBOL 00001
= #define REG_NOTEOL 00002
= #define REG_STARTEND 00004
= #define REG_TRACE 00400 // tracing of execution
= #define REG_LARGE 01000 // force large representation
= #define REG_BACKR 02000 // force use of backref code
*
* We put this here so we can exploit knowledge of the state representation
* when choosing which matcher to call. Also, by this point the matchers
* have been prototyped.
*/
int /* 0 success, REG_NOMATCH failure */
regexec(preg, string, nmatch, pmatch, eflags)
const regex_t *preg;
const char *string;
size_t nmatch;
regmatch_t pmatch[];
int eflags;
{
register struct re_guts *g = preg->re_g;
#ifdef REDEBUG
# define GOODFLAGS(f) (f)
#else
# define GOODFLAGS(f) ((f)&(REG_NOTBOL|REG_NOTEOL|REG_STARTEND))
#endif
if (preg->re_magic != MAGIC1 || g->magic != MAGIC2)
return(REG_BADPAT);
assert(!(g->iflags&BAD));
if (g->iflags&BAD) /* backstop for no-debug case */
return(REG_BADPAT);
eflags = GOODFLAGS(eflags);
if (g->nstates <= CHAR_BIT*sizeof(states1) && !(eflags&REG_LARGE))
return(smatcher(g, (char *)string, nmatch, pmatch, eflags));
else
return(lmatcher(g, (char *)string, nmatch, pmatch, eflags));
}

View File

@@ -0,0 +1,69 @@
/*
* Copyright (c) 1986 by University of Toronto.
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley
* by Henry Spencer.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)regexp.h 8.1 (Berkeley) 6/2/93
*/
#ifndef _REGEXP_H_
#define _REGEXP_H_
/*
* Definitions etc. for regexp(3) routines.
*
* Caveat: this is V8 regexp(3) [actually, a reimplementation thereof],
* not the System V one.
*/
#define NSUBEXP 10
typedef struct regexp {
char *startp[NSUBEXP];
char *endp[NSUBEXP];
char regstart; /* Internal use only. */
char reganch; /* Internal use only. */
char *regmust; /* Internal use only. */
int regmlen; /* Internal use only. */
char program[1]; /* Unwarranted chumminess with compiler. */
} regexp;
#include <sys/cdefs.h>
__BEGIN_DECLS
regexp *regcomp __P((const char *));
int regexec __P((const regexp *, const char *));
void regsub __P((const regexp *, const char *, char *));
void regerror __P((const char *));
__END_DECLS
#endif /* !_REGEXP_H_ */

View File

@@ -0,0 +1,80 @@
/*-
* Copyright (c) 1992, 1993, 1994 Henry Spencer.
* Copyright (c) 1992, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Henry Spencer.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)regfree.c 8.3 (Berkeley) 3/20/94
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)regfree.c 8.3 (Berkeley) 3/20/94";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <regex.h>
#include "utils.h"
#include "regex2.h"
/*
- regfree - free everything
= extern void regfree(regex_t *);
*/
void
regfree(preg)
regex_t *preg;
{
register struct re_guts *g;
if (preg->re_magic != MAGIC1) /* oops */
return; /* nice to complain, but hard */
g = preg->re_g;
if (g == NULL || g->magic != MAGIC2) /* oops again */
return;
preg->re_magic = 0; /* mark it invalid */
g->magic = 0; /* mark it invalid */
if (g->strip != NULL)
free((char *)g->strip);
if (g->sets != NULL)
free((char *)g->sets);
if (g->setbits != NULL)
free((char *)g->setbits);
if (g->must != NULL)
free(g->must);
free((char *)g);
}

View File

@@ -0,0 +1,57 @@
/*-
* Copyright (c) 1992, 1993, 1994 Henry Spencer.
* Copyright (c) 1992, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Henry Spencer.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)utils.h 8.3 (Berkeley) 3/20/94
*/
/* utility definitions */
#define DUPMAX 100000000 /* xxx is this right? */
#define INFINITY (DUPMAX + 1)
#define NC (CHAR_MAX - CHAR_MIN + 1)
typedef unsigned char uch;
/* switch off assertions (if not already off) if no REDEBUG */
#ifndef REDEBUG
#ifndef NDEBUG
#define NDEBUG /* no assertions please */
#endif
#endif
#include <assert.h>
/* for old systems with bcopy() but no memmove() */
#ifdef USEBCOPY
#define memmove(d, s, c) bcopy(s, d, c)
#endif

View File

@@ -0,0 +1,29 @@
/*-------------------------------------------------------------------------
*
* rusagestub.h--
* Stubs for getrusage(3).
*
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: rusagestub.h,v 1.1.1.1 1996/07/09 06:21:46 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef RUSAGESTUB_H
#define RUSAGESTUB_H
#include <sys/time.h> /* for struct timeval */
#include <limits.h> /* for CLK_TCK */
#define RUSAGE_SELF 0
#define RUSAGE_CHILDREN -1
struct rusage {
struct timeval ru_utime; /* user time used */
struct timeval ru_stime; /* system time used */
};
extern int getrusage(int who, struct rusage *rusage);
#endif /* RUSAGESTUB_H */

View File

@@ -0,0 +1,124 @@
/*
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Berkeley Software Design, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)cdefs.h 8.7 (Berkeley) 1/21/94
*/
#ifndef _CDEFS_H_
#define _CDEFS_H_
#if defined(__cplusplus)
#define __BEGIN_DECLS extern "C" {
#define __END_DECLS };
#else
#define __BEGIN_DECLS
#define __END_DECLS
#endif
/*
* The __CONCAT macro is used to concatenate parts of symbol names, e.g.
* with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo.
* The __CONCAT macro is a bit tricky -- make sure you don't put spaces
* in between its arguments. __CONCAT can also concatenate double-quoted
* strings produced by the __STRING macro, but this only works with ANSI C.
*/
#if defined(__STDC__) || defined(__cplusplus)
#define __P(protos) protos /* full-blown ANSI C */
#define __CONCAT(x,y) x ## y
#define __STRING(x) #x
#define __const const /* define reserved names to standard */
#define __signed signed
#define __volatile volatile
#if defined(__cplusplus)
#define __inline inline /* convert to C++ keyword */
#else
#ifndef __GNUC__
#define __inline /* delete GCC keyword */
#endif /* !__GNUC__ */
#endif /* !__cplusplus */
#else /* !(__STDC__ || __cplusplus) */
#define __P(protos) () /* traditional C preprocessor */
#define __CONCAT(x,y) x/**/y
#define __STRING(x) "x"
#ifndef __GNUC__
#define __const /* delete pseudo-ANSI C keywords */
#define __inline
#define __signed
#define __volatile
/*
* In non-ANSI C environments, new programs will want ANSI-only C keywords
* deleted from the program and old programs will want them left alone.
* When using a compiler other than gcc, programs using the ANSI C keywords
* const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS.
* When using "gcc -traditional", we assume that this is the intent; if
* __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone.
*/
#ifndef NO_ANSI_KEYWORDS
#define const /* delete ANSI C keywords */
#define inline
#define signed
#define volatile
#endif
#endif /* !__GNUC__ */
#endif /* !(__STDC__ || __cplusplus) */
/*
* GCC1 and some versions of GCC2 declare dead (non-returning) and
* pure (no side effects) functions using "volatile" and "const";
* unfortunately, these then cause warnings under "-ansi -pedantic".
* GCC2 uses a new, peculiar __attribute__((attrs)) style. All of
* these work for GNU C++ (modulo a slight glitch in the C++ grammar
* in the distribution version of 2.5.5).
*/
#if !defined(__GNUC__) || __GNUC__ < 2 || __GNUC_MINOR__ < 5
#define __attribute__(x) /* delete __attribute__ if non-gcc or gcc1 */
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define __dead __volatile
#define __pure __const
#endif
#endif
/* Delete pseudo-keywords wherever they are not available or needed. */
#ifndef __dead
#define __dead
#define __pure
#endif
typedef long off_t;
#endif /* !_CDEFS_H_ */

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1 @@