"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "re.c" between
gawk-5.0.1.tar.xz and gawk-5.1.0.tar.xz

About: GNU awk - pattern scanning and processing language.

re.c  (gawk-5.0.1.tar.xz):re.c  (gawk-5.1.0.tar.xz)
/* /*
* re.c - compile regular expressions. * re.c - compile regular expressions.
*/ */
/* /*
* Copyright (C) 1991-2018 the Free Software Foundation, Inc. * Copyright (C) 1991-2019 the Free Software Foundation, Inc.
* *
* This file is part of GAWK, the GNU implementation of the * This file is part of GAWK, the GNU implementation of the
* AWK Programming Language. * AWK Programming Language.
* *
* GAWK is free software; you can redistribute it and/or modify * GAWK is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* GAWK is distributed in the hope that it will be useful, * GAWK is distributed in the hope that it will be useful,
skipping to change at line 110 skipping to change at line 110
if ( is_multibyte == 1 if ( is_multibyte == 1
|| is_multibyte == (size_t) -1 || is_multibyte == (size_t) -1
|| is_multibyte == (size_t) -2 || is_multibyte == (size_t) -2
|| is_multibyte == 0) { || is_multibyte == 0) {
/* We treat it as a single-byte character. */ /* We treat it as a single-byte character. */
is_multibyte = 0; is_multibyte = 0;
} }
} }
const char *ok_to_escape; const char *ok_to_escape;
if (do_traditional) if (do_posix)
ok_to_escape = "{}()|*+?.^$\\[]/-";
else if (do_traditional)
ok_to_escape = "()|*+?.^$\\[]/-"; ok_to_escape = "()|*+?.^$\\[]/-";
else else
ok_to_escape = "<>`'BywWsS{}()|*+?.^$\\[]/-"; ok_to_escape = "<>`'BywWsS{}()|*+?.^$\\[]/-";
/* We skip multibyte character, since it must not be a special /* We skip multibyte character, since it must not be a special
character. */ character. */
if ((gawk_mb_cur_max == 1 || ! is_multibyte) && if ((gawk_mb_cur_max == 1 || ! is_multibyte) &&
(*src == '\\')) { (*src == '\\')) {
c = *++src; c = *++src;
switch (c) { switch (c) {
skipping to change at line 392 skipping to change at line 394
/* dfaerror --- print an error message for the dfa routines */ /* dfaerror --- print an error message for the dfa routines */
void void
dfaerror(const char *s) dfaerror(const char *s)
{ {
fatal("%s", s); fatal("%s", s);
exit(EXIT_FATAL); /* for DJGPP */ exit(EXIT_FATAL); /* for DJGPP */
} }
/* re_cache_get --- populate regexp cache if empty */
static inline Regexp *
re_cache_get(NODE *t)
{
if (t->re_reg[IGNORECASE] == NULL)
t->re_reg[IGNORECASE] = make_regexp(t->re_exp->stptr, t->re_exp->
stlen, IGNORECASE, t->re_cnt, true);
return t->re_reg[IGNORECASE];
}
/* re_update --- recompile a dynamic regexp */ /* re_update --- recompile a dynamic regexp */
Regexp * Regexp *
re_update(NODE *t) re_update(NODE *t)
{ {
NODE *t1; NODE *t1;
if (t->type == Node_val && (t->flags & REGEX) != 0) if (t->type == Node_val && (t->flags & REGEX) != 0)
return t->typed_re->re_reg[IGNORECASE]; return re_cache_get(t->typed_re);
if ((t->re_flags & CONSTANT) != 0) { if ((t->re_flags & CONSTANT) != 0) {
/* it's a constant, so just return it as is */ /* it's a constant, so just return it as is */
assert(t->type == Node_regex); assert(t->type == Node_regex);
return t->re_reg[IGNORECASE]; return re_cache_get(t);
} }
t1 = t->re_exp; t1 = t->re_exp;
if (t->re_text != NULL) { if (t->re_text != NULL) {
/* if contents haven't changed, just return it */ /* if contents haven't changed, just return it */
if (cmp_nodes(t->re_text, t1, true) == 0) if (cmp_nodes(t->re_text, t1, true) == 0)
return t->re_reg[IGNORECASE]; return re_cache_get(t);
/* things changed, fall through to recompile */ /* things changed, fall through to recompile */
unref(t->re_text); unref(t->re_text);
} }
/* get fresh copy of the text of the regexp */ /* get fresh copy of the text of the regexp */
t->re_text = dupnode(t1); t->re_text = dupnode(t1);
/* text changed */ /* text changed */
/* free old */ /* free old */
if (t->re_reg[0] != NULL) if (t->re_reg[0] != NULL) {
refree(t->re_reg[0]); refree(t->re_reg[0]);
if (t->re_reg[1] != NULL) t->re_reg[0] = NULL;
}
if (t->re_reg[1] != NULL) {
refree(t->re_reg[1]); refree(t->re_reg[1]);
if (t->re_cnt > 0) t->re_reg[1] = NULL;
t->re_cnt++; }
if (t->re_cnt > 10) if (t->re_cnt > 0 && ++t->re_cnt > 10)
/*
* The regex appears to update frequently, so disable DFA
* matching (which trades off expensive upfront compilation
* overhead for faster subsequent matching).
*/
t->re_cnt = 0; t->re_cnt = 0;
if (t->re_text == NULL) { if (t->re_text == NULL) {
/* reset regexp text if needed */ /* reset regexp text if needed */
t1 = t->re_exp; t1 = t->re_exp;
unref(t->re_text); unref(t->re_text);
t->re_text = dupnode(t1); t->re_text = dupnode(t1);
} }
/* compile it */ return re_cache_get(t);
t->re_reg[0] = make_regexp(t->re_text->stptr, t->re_text->stlen,
false, t->re_cnt, true);
t->re_reg[1] = make_regexp(t->re_text->stptr, t->re_text->stlen,
true, t->re_cnt, true);
return t->re_reg[IGNORECASE];
} }
/* resetup --- choose what kind of regexps we match */ /* resetup --- choose what kind of regexps we match */
void void
resetup() resetup()
{ {
// init localeinfo for dfa // init localeinfo for dfa
init_localeinfo(& localeinfo); init_localeinfo(& localeinfo);
 End of changes. 10 change blocks. 
17 lines changed or deleted 31 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)