From 3278b75942bdbe706f7a0fba87729bb1e935b68b Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Mon, 20 Feb 2017 00:05:25 -0800 Subject: Import Upstream version 5d2 --- rgx.c | 82 ++++++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 42 insertions(+), 40 deletions(-) (limited to 'rgx.c') diff --git a/rgx.c b/rgx.c index 1006cf8..e89564a 100644 --- a/rgx.c +++ b/rgx.c @@ -1,18 +1,18 @@ /* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. - * + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * the Free Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111, USA. * * As a special exception, the Free Software Foundation gives permission * for additional uses of the text contained in its release of GUILE. @@ -36,14 +36,18 @@ * * If you write modifications of your own for GUILE, it is your choice * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. + * If you do not wish that, delete this exception notice. */ /* "rgx.c" regular expression matching using C regex library. Author: Aubrey Jaffer */ #include "scm.h" -#include "regex.h" +#ifdef __FreeBSD__ +# include "gnuregex.h" +#else +# include "regex.h" +#endif #include /* added by Denys Duchier: for bcopy */ #ifdef sun @@ -51,7 +55,7 @@ #endif static char rcsid[] = - "$Id: rgx.c,v 1.4 1998/09/11 18:13:43 radey Exp $"; + "$Id: rgx.c,v 1.12 1999/09/07 16:55:54 jaffer Exp $"; #ifdef HAVE_ALLOCA # include @@ -111,7 +115,7 @@ typedef struct regex_info { #ifndef _GNU_SOURCE int options; /* for anchored pattern when matching */ regex_t rgx_anchored; -#endif +#endif } regex_info; sizet fregex(ptr) @@ -120,11 +124,11 @@ sizet fregex(ptr) regfree(RGX(ptr)); #ifndef _GNU_SOURCE /* options are null => we compiled the anchored pattern */ - if (RGX_INFO(ptr)->options==NULL) + if (RGX_INFO(ptr)->options==0) regfree(RGX2(ptr)); -#endif - free(CHARS(ptr)); - return sizeof(regex_t); +#endif + must_free(CHARS(ptr), (sizet)LENGTH(ptr)); + return 0; } int prinregex(exp, port, writing) @@ -141,7 +145,6 @@ int prinregex(exp, port, writing) SCM markregex(ptr) SCM ptr; { - SETGC8MARK(ptr); SETGC8MARK(RGX_PATTERN(ptr)); return BOOL_F; } @@ -166,9 +169,9 @@ SCM lregerror(scode) #ifdef __REGEXP_LIBRARY_H__ /* XXX - gnu regexp doesn't use the re parameter, so we will ignore it in a very untidy way. */ - len = regerror(code, 0, 0, 0); + len = regerror(code, 0L, 0L, 0); str = makstr(len-1); - regerror(code, 0, CHARS(str), len); + regerror(code, 0L, CHARS(str), len); #else str = makfromstr(s_error, (sizet)5); #endif @@ -190,14 +193,13 @@ SCM lregcomp(pattern, flags) #endif ASSERT(NIMP(pattern) && STRINGP(pattern), pattern, ARG1, s_regcomp); - ASSERT(UNBNDP(flags) || (NIMP(flags) && STRINGP(flags)), + ASSERT(UNBNDP(flags) || (NIMP(flags) && STRINGP(flags)), flags, ARG2, s_regcomp); DEFER_INTS; - z = must_malloc_cell((long)sizeof(regex_info), s_regex); + z = must_malloc_cell((long)sizeof(regex_info), (SCM)tc16_rgx, s_regex); scm_protect_temp(&z); info=(regex_info*)CHARS(z); prog = &(info->rgx); - CAR(z) = tc16_rgx; #ifdef __REGEXP_LIBRARY_H__ for(i=sizeof(regex_t);i--;((char *)prog)[i] = 0); # ifndef _GNU_SOURCE @@ -223,7 +225,7 @@ SCM lregcomp(pattern, flags) for (i=0; ifastmap = must_malloc(CHAR_SET_SIZE, s_regex); else - prog->fastmap = NULL; - + prog->fastmap = 0; + if (ignore_case) { prog->translate = must_malloc(CHAR_SET_SIZE, s_regex); for (i = 0; i < CHAR_SET_SIZE; i++) prog->translate[i] = ISUPPER (i) ? tolower (i) : i; } else - prog->translate = NULL; + prog->translate = 0; - prog->buffer = NULL; + prog->buffer = 0; prog->allocated = 0; re_set_syntax(options); @@ -287,7 +289,7 @@ SCM lregcomp(pattern, flags) z = MAKINUM(i); } #else - info->options = options; + info->options = options; i = regcomp(prog, CHARS(pattern), options); if (i) z = MAKINUM(i); #endif @@ -341,7 +343,7 @@ SCM lregmatp(prog, str) { int flags = 0; /* XXX - optional arg? */ - flags = regexec(RGX(prog), CHARS(str), 0, NULL, flags); + flags = regexec(RGX(prog), CHARS(str), 0, 0, flags); if (!flags) return BOOL_T; if (REG_NOMATCH!=flags) wta(MAKINUM(flags), s_error, s_regmatp); return BOOL_F; @@ -377,7 +379,7 @@ SCM lregsearchmatch(prog, str, args, search, vector) #ifdef _GNU_SOURCE { int ret, dir=1; - struct re_registers regs, *pregs=NULL; + struct re_registers regs, *pregs=0; if (search && start<0) start *= -1, dir = -1; @@ -395,7 +397,7 @@ SCM lregsearchmatch(prog, str, args, search, vector) ret = re_search(RGX(prog), CHARS(str), size, start, dir*size, pregs); else ret = re_match(RGX(prog), CHARS(str), size, start, pregs); - + if (ret < 0) return BOOL_F; @@ -464,7 +466,7 @@ SCM lregsearchmatch(prog, str, args, search, vector) return MAKINUM(pm[0].rm_eo - pm[0].rm_so); } -#endif /* _GNU_SOURCE */ +#endif /* _GNU_SOURCE */ } SCM lregsearch(prog, str, args) @@ -511,7 +513,7 @@ SCM stringsplitutil(prog, str, vector) next_break = lregsearchv(prog, str, cons(MAKINUM(search_base), EOL)); while (next_break != BOOL_F) { - match_start = INUM(VELTS(next_break)[0]); + match_start = INUM(VELTS(next_break)[0]); match_end = INUM(VELTS(next_break)[1]); if (match_start < match_end) { @@ -560,7 +562,7 @@ SCM lstringsplitv(prog, str) { return stringsplitutil(prog, str, VECTOR); } - + typedef struct _item { struct _item *next; char *string; @@ -614,12 +616,12 @@ SCM lstringedit(prog, editspec, args) * of integers for substrings to be inserted and * integers representing matched subexpressions that * should be inserted. - */ + */ maxsubnum = RGX(prog)->re_nsub; anchor = 0; backslash = 0; - editlist = NULL; + editlist = 0; ptr = CHARS(editspec); for (i=0; inext; cur->next = prev; } @@ -652,7 +654,7 @@ SCM lstringedit(prog, editspec, args) anchor = 0; search_base = 0; editcount = 0; - substrings = NULL; + substrings = 0; next_edit = lregsearchv(prog, str, cons(MAKINUM(search_base), EOL)); @@ -660,7 +662,7 @@ SCM lstringedit(prog, editspec, args) if (INUMP(count) && (editcount==INUM(count))) break; - match_start = INUM(VELTS(next_edit)[0]); + match_start = INUM(VELTS(next_edit)[0]); match_end = INUM(VELTS(next_edit)[1]); if (match_start < match_end) { @@ -671,10 +673,10 @@ SCM lstringedit(prog, editspec, args) for (edit=editlist; edit; edit=edit->next) { if (edit->end == -1) { /* A backslash number in the original editspec */ - PUSH(substrings, CHARS(str), - INUM(VELTS(next_edit)[edit->start*2+0]), + PUSH(substrings, CHARS(str), + INUM(VELTS(next_edit)[edit->start*2+0]), INUM(VELTS(next_edit)[edit->start*2+1])); - } else + } else /* normal string in the editspec */ PUSH(substrings, edit->string, edit->start, edit->end); } -- cgit v1.2.3