head 1.13; access; symbols release_4_2:1.13 aix_ok:1.11 Version_2_1:1.5; locks; strict; comment @ * @; 1.13 date 93.11.01.00.49.39; author aoki; state Exp; branches; next 1.12; 1.12 date 93.10.05.22.37.43; author marcel; state Exp; branches; next 1.11; 1.11 date 93.09.28.02.37.01; author aoki; state Exp; branches; next 1.10; 1.10 date 93.09.22.02.05.51; author aoki; state Exp; branches; next 1.9; 1.9 date 93.03.18.23.39.30; author aoki; state Exp; branches; next 1.8; 1.8 date 91.11.11.22.39.44; author mer; state Exp; branches; next 1.7; 1.7 date 91.07.22.12.12.52; author mer; state Exp; branches; next 1.6; 1.6 date 91.07.13.21.15.33; author mer; state Exp; branches; next 1.5; 1.5 date 91.01.22.19.39.02; author mao; state Exp; branches; next 1.4; 1.4 date 90.08.22.15.34.31; author choi; state Exp; branches; next 1.3; 1.3 date 90.08.15.08.20.07; author cimarron; state Exp; branches; next 1.2; 1.2 date 90.07.31.14.21.17; author mao; state Exp; branches; next 1.1; 1.1 date 90.07.31.12.46.21; author mao; state Exp; branches; next ; desc @regular expression pattern-matching code @ 1.13 log @revision 1.11 somehow got backed out. watch out for those "co -l" commands folks. @ text @/* ---------------------------------------------------------------- * FILE * regexp.c * * DESCRIPTION * regular expression handling code. * * INTERFACE ROUTINES * char16regexeq * char16regexne * textregexeq * textregexne * * NOTES * Uses the old AT&T compile/step code. While this is not very * politically-correct (it has been removed from 4.x BSD) it is * the most portable C library solution since everyone names their * own regular expression routines something different (applying * different standards)... * * IDENTIFICATION * $Header: /faerie/aoki/postgres/src/backend/utils/adt/RCS/regexp.c,v 1.11 1993/09/28 02:37:01 aoki Exp $ * ---------------------------------------------------------------- */ #include "tmp/postgres.h" /* postgres system include file */ #include "utils/log.h" /* for logging postgres errors */ /* * macros to support the regexp(3) library calls */ #define INIT register char *p = instring; #define GETC() (*p++) #define PEEKC() *(p+1) #define UNGETC(c) (*--p = (c)) #define RETURN(v) return(v) #define ERROR(val) elog(WARN, "regexp library reports error %d", (val)); #define EXPBUFSZ 256 #define P2CHARLEN 2 #define P4CHARLEN 4 #define P8CHARLEN 8 #define P16CHARLEN 16 #if defined(DISABLE_XOPEN_NLS) #undef _XOPEN_SOURCE #endif /* DISABLE_XOPEN_NLS */ #include /* * interface routines called by the function manager */ /* * routines that use the regexp stuff */ bool char2regexeq(arg1, p) uint16 arg1; struct varlena *p; { char *expbuf, *endbuf; char *sterm, *pterm; int result; char *s = (char *) &arg1; if (!s || !p) return FALSE; expbuf = (char *) palloc(EXPBUFSZ); endbuf = expbuf + (EXPBUFSZ - 1); /* be sure sterm is null-terminated */ sterm = (char *) palloc(P2CHARLEN + 1); bzero(sterm, P2CHARLEN + 1); strncpy(sterm, s, P2CHARLEN); /* p is a text = varlena, not a string so we have to make * a string from the vl_data field of the struct. */ /* palloc the length of the text + the null character */ pterm = (char *) palloc(p->vl_len - sizeof(int32) + 1); bcopy(p->vl_dat, pterm, p->vl_len - sizeof(int32)); *(pterm + p->vl_len - sizeof(int32)) = (char)NULL; /* compile the re */ (void) compile(pterm, expbuf, endbuf, NULL); /* do the regexp matching */ result = step(sterm, expbuf); pfree(expbuf); pfree(sterm); pfree(pterm); return ((bool) result); } bool char2regexne(arg1, p) uint16 arg1; struct varlena *p; { return (!char2regexeq(arg1, p)); } bool char4regexeq(arg1, p) uint32 arg1; struct varlena *p; { char *expbuf, *endbuf; char *sterm, *pterm; int result; char *s = (char *) &arg1; if (!s || !p) return FALSE; expbuf = (char *) palloc(EXPBUFSZ); endbuf = expbuf + (EXPBUFSZ - 1); /* be sure sterm is null-terminated */ sterm = (char *) palloc(P4CHARLEN + 1); bzero(sterm, P4CHARLEN + 1); strncpy(sterm, s, P4CHARLEN); /* p is a text = varlena, not a string so we have to make * a string from the vl_data field of the struct. */ /* palloc the length of the text + the null character */ pterm = (char *) palloc(p->vl_len - sizeof(int32) + 1); bcopy(p->vl_dat, pterm, p->vl_len - sizeof(int32)); *(pterm + p->vl_len - sizeof(int32)) = (char)NULL; /* compile the re */ (void) compile(pterm, expbuf, endbuf, NULL); /* do the regexp matching */ result = step(sterm, expbuf); pfree(expbuf); pfree(sterm); pfree(pterm); return ((bool) result); } bool char4regexne(arg1, p) uint32 arg1; struct varlena *p; { return (!char4regexeq(arg1, p)); } bool char8regexeq(s, p) char *s; struct varlena *p; { char *expbuf, *endbuf; char *sterm, *pterm; int result; if (!s || !p) return FALSE; expbuf = (char *) palloc(EXPBUFSZ); endbuf = expbuf + (EXPBUFSZ - 1); /* be sure sterm is null-terminated */ sterm = (char *) palloc(P8CHARLEN + 1); bzero(sterm, P8CHARLEN + 1); strncpy(sterm, s, P8CHARLEN); /* p is a text = varlena, not a string so we have to make * a string from the vl_data field of the struct. */ /* palloc the length of the text + the null character */ pterm = (char *) palloc(p->vl_len - sizeof(int32) + 1); bcopy(p->vl_dat, pterm, p->vl_len - sizeof(int32)); *(pterm + p->vl_len - sizeof(int32)) = (char)NULL; /* compile the re */ (void) compile(pterm, expbuf, endbuf, NULL); /* do the regexp matching */ result = step(sterm, expbuf); pfree(expbuf); pfree(sterm); pfree(pterm); return ((bool) result); } bool char8regexne(s, p) char *s; struct varlena *p; { return (!char8regexeq(s, p)); } bool char16regexeq(s, p) char *s; struct varlena *p; { char *expbuf, *endbuf; char *sterm, *pterm; int result; if (!s || !p) return FALSE; expbuf = (char *) palloc(EXPBUFSZ); endbuf = expbuf + (EXPBUFSZ - 1); /* be sure sterm is null-terminated */ sterm = (char *) palloc(P16CHARLEN + 1); bzero(sterm, P16CHARLEN + 1); strncpy(sterm, s, P16CHARLEN); /* p is a text = varlena, not a string so we have to make * a string from the vl_data field of the struct. */ /* palloc the length of the text + the null character */ pterm = (char *) palloc(p->vl_len - sizeof(int32) + 1); bcopy(p->vl_dat, pterm, p->vl_len - sizeof(int32)); *(pterm + p->vl_len - sizeof(int32)) = (char)NULL; /* compile the re */ (void) compile(pterm, expbuf, endbuf, NULL); /* do the regexp matching */ result = step(sterm, expbuf); pfree(expbuf); pfree(sterm); pfree(pterm); return ((bool) result); } bool char16regexne(s, p) char *s; struct varlena *p; { return (!char16regexeq(s, p)); } bool textregexeq(s, p) struct varlena *s; struct varlena *p; { char *expbuf, *endbuf; char *sbuf, *pbuf; int result; if (!s || !p) return FALSE; /* --------------- * text is a varlena, not a string so we have to make * a string from the vl_data field of the struct. * jeff 13 July 1991 * --------------- */ /* palloc the length of the text + the null character */ sbuf = (char *) palloc(s->vl_len - sizeof(int32) + 1); pbuf = (char *) palloc(p->vl_len - sizeof(int32) + 1); expbuf = (char *) palloc(EXPBUFSZ); endbuf = expbuf + (EXPBUFSZ - 1); bcopy(s->vl_dat, sbuf, s->vl_len - sizeof(int32)); bcopy(p->vl_dat, pbuf, p->vl_len - sizeof(int32)); *(sbuf + s->vl_len - sizeof(int32)) = (char)NULL; *(pbuf + p->vl_len - sizeof(int32)) = (char)NULL; /* compile the re */ (void) compile(pbuf, expbuf, endbuf, NULL); /* do the regexp matching */ result = step(sbuf, expbuf); pfree(expbuf); pfree(sbuf); pfree(pbuf); return ((bool) result); } bool textregexne(s, p) char *s; char *p; { return (!textregexeq(s, p)); } @ 1.12 log @added re matching for char2, char4, char8 changed char16regexeq(char16, char16) to char16regexeq(char16, text) @ text @d1 19 a19 2 /* * regexp.c -- regular expression handling code. d21 3 a23 1 * $Header: /data/01/postgres/src/backend/utils/adt/RCS/regexp.c,v 1.9 1993/03/18 23:39:30 aoki Exp $ d25 1 d45 1 a45 1 #if defined(PORTNAME_alpha) d47 1 a47 1 #endif /* PORTNAME_alpha */ @ 1.11 log @xopen nls reparameterized @ text @d1 2 a2 19 /* ---------------------------------------------------------------- * FILE * regexp.c * * DESCRIPTION * regular expression handling code. * * INTERFACE ROUTINES * char16regexeq * char16regexne * textregexeq * textregexne * * NOTES * Uses the old AT&T compile/step code. While this is not very * politically-correct (it has been removed from 4.x BSD) it is * the most portable C library solution since everyone names their * own regular expression routines something different (applying * different standards)... d4 1 a4 3 * IDENTIFICATION * $Header: /faerie/aoki/postgres/src/backend/utils/adt/RCS/regexp.c,v 1.10 1993/09/22 02:05:51 aoki Exp aoki $ * ---------------------------------------------------------------- a5 1 d20 4 a23 1 #define PCHARLEN 16 d25 1 a25 1 #if defined(DISABLE_XOPEN_NLS) d27 1 a27 1 #endif /* DISABLE_XOPEN_NLS */ d38 149 d189 1 a189 1 char *p; d201 12 a212 7 /* be sure the strings are null-terminated */ sterm = (char *) palloc(PCHARLEN + 1); bzero(sterm, PCHARLEN + 1); strncpy(sterm, s, PCHARLEN); pterm = (char *) palloc(PCHARLEN + 1); bzero(pterm, PCHARLEN + 1); strncpy(pterm, p, PCHARLEN); d230 1 a230 1 char *p; @ 1.10 log @aix @ text @d22 1 a22 1 * $Header: /data/01/postgres/src/backend/utils/adt/RCS/regexp.c,v 1.9 1993/03/18 23:39:30 aoki Exp $ d42 1 a42 4 #if defined(PORTNAME_alpha) || defined(PORTNAME_aix) /* * XOPEN NLS support breaks this stuff horribly. */ d44 1 a44 1 #endif /* PORTNAME_alpha || PORTNAME_aix */ @ 1.9 log @for now, use old bsd regex under alpha. someday (like when we do hpux) we'll have to deal with the xopen international garbage. @ text @d1 19 a19 2 /* * regexp.c -- regular expression handling code. d21 3 a23 1 * $Header: /home2/aoki/master/src/backend/utils/adt/RCS/regexp.c,v 1.8 1991/11/11 22:39:44 mer Exp aoki $ d25 1 d42 4 a45 1 #if defined(PORTNAME_alpha) d47 1 a47 1 #endif /* PORTNAME_alpha */ @ 1.8 log @bug fix - text regexp processing was writing beyond end of palloc'd space. @ text @d4 1 a4 1 * $Header: /users/mer/postgres/src/utils/adt/RCS/regexp.c,v 1.7 1991/07/22 12:12:52 mer Exp mer $ d22 3 a24 3 #ifdef sprite #include "regexp.h" #else a25 1 #endif /* sprite */ @ 1.7 log @fix for null fields in relations passed in as parameters @ text @d4 1 a4 1 * $Header: RCS/regexp.c,v 1.6 91/07/13 21:15:33 mer Exp Locker: mer $ d105 4 a108 4 bcopy(s->vl_dat, sbuf, s->vl_len); bcopy(p->vl_dat, pbuf, p->vl_len); *(sbuf + s->vl_len) = (char)NULL; *(pbuf + p->vl_len) = (char)NULL; @ 1.6 log @bug fix in textregexpeq - accounts for the fact that text is a varlena @ text @d4 1 a4 1 * $Header: RCS/regexp.c,v 1.5 91/01/22 19:39:02 mao Exp Locker: mer $ d44 3 d87 3 @ 1.5 log @change interface to regexp routines to match what the function manager expects. @ text @d4 1 a4 1 * $Header: RCS/regexp.c,v 1.4 90/08/22 15:34:31 choi Exp Locker: mao $ d6 1 a6 1 #include "tmp/c.h" /* postgres system include file */ d78 2 a79 2 char *s; char *p; d82 1 d85 11 d99 6 d106 1 a106 1 (void) compile(p, expbuf, endbuf, NULL); d109 1 a109 1 result = step(s, expbuf); d112 2 @ 1.4 log @lines added for Sprite OS port. @ text @d4 1 a4 1 * $Header: RCS/regexp.c,v 1.3 90/08/15 08:20:07 cimarron Exp Locker: choi $ d29 4 d36 2 a37 1 char16regexeq(p, s) a38 1 char *s; d65 1 a65 4 if (result) return (true); else return (false); d69 2 a70 1 textregexeq(p, s) d72 6 d79 1 d95 9 a103 4 if (result) return (true); else return (false); @ 1.3 log @added pathnames to include statements @ text @d4 1 a4 1 * $Header: RCS/regexp.c,v 1.2 90/07/31 14:21:17 mao Exp Locker: cimarron $ d22 3 d26 1 @ 1.2 log @botched declaration of RETURN macro @ text @d4 1 a4 1 * $Header: RCS/regexp.c,v 1.1 90/07/31 12:46:21 mao Exp Locker: mao $ d6 2 a7 2 #include "c.h" /* postgres system include file */ #include "log.h" /* for logging postgres errors */ @ 1.1 log @Initial revision @ text @d4 1 a4 1 * $Header$ d16 1 a16 1 #define RETURN(v) (v) @