snapshot of project "mawk", label t20140818

This commit is contained in:
Thomas E. Dickey 2014-08-18 20:34:56 -04:00
parent 21c8d02105
commit 9f91f661ec
7 changed files with 81 additions and 66 deletions

View File

@ -1,8 +1,8 @@
-- $MawkId: CHANGES,v 1.194 2014/08/18 00:26:13 tom Exp $
-- $MawkId: CHANGES,v 1.195 2014/08/18 18:44:45 tom Exp $
Changes by Thomas E Dickey <dickey@invisible-island.net>
20140817
20140818
+ fix a comparison in rexp3.c to work with embedded nulls (patch by
Mike Brennan).
+ in-progress changes to implement "gsub2", which will reduce copying.

View File

@ -1,4 +1,4 @@
MANIFEST for mawk, version t20140817
MANIFEST for mawk, version t20140818
--------------------------------------------------------------------------------
MANIFEST this file
ACKNOWLEDGMENT acknowledgements

View File

@ -11,7 +11,7 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*
* $MawkId: bi_funct.c,v 1.78 2014/08/18 00:03:33 tom Exp $
* $MawkId: bi_funct.c,v 1.83 2014/08/18 19:28:51 tom Exp $
* @Log: bi_funct.c,v @
* Revision 1.9 1996/01/14 17:16:11 mike
* flush_all_output() before system()
@ -1149,6 +1149,15 @@ bi_sub(CELL *sp)
return_CELL("bi_sub", sp);
}
#if defined(DEBUG_GSUB) || !defined(EXP_UNROLLED_GSUB)
#define USE_GSUB0
#endif
#if defined(EXP_UNROLLED_GSUB)
#define USE_GSUB2
#endif
#ifdef USE_GSUB1
typedef enum {
btFinish = 0,
btNormal,
@ -1191,13 +1200,6 @@ typedef struct {
#define NextResult NextGSUB.result
#define NextTarget NextGSUB.target
#define NextTargetLen NextGSUB.target_len
#if defined(DEBUG_GSUB) || !defined(EXP_UNROLLED_GSUB)
#define USE_GSUB0
#endif
#if defined(EXP_UNROLLED_GSUB)
#define USE_GSUB1
#endif
static unsigned repl_cnt; /* number of global replacements */
@ -1362,12 +1364,14 @@ gsub2(PTR re, CELL *repl, CELL *target)
* On the second pass, actually apply changes - if any.
*/
for (pass = 0; pass < 2; ++pass) {
int skip0 = -1;
TRACE(("start pass %d\n", pass + 1));
repl_cnt = 0;
for (j = 0; j <= (int) input->len; ++j) {
size_t howmuch;
char *where = REmatch(input->str + j,
input->len - j,
input->len - (size_t) j,
cast_to_re(re),
&howmuch);
/*
@ -1376,7 +1380,7 @@ gsub2(PTR re, CELL *repl, CELL *target)
* is in 'howmuch'.
*/
if (where != 0) {
have = (where - (input->str + j));
have = (size_t) (where - (input->str + j));
if (have) {
TRACE(("..before match:%d:", (int) have));
TRACE_STRING2(input->str + j, have);
@ -1393,8 +1397,6 @@ gsub2(PTR re, CELL *repl, CELL *target)
TRACE_STRING2(where, howmuch);
TRACE(("\n"));
++repl_cnt;
if (repl->type == C_REPLV) {
sval = new_STRING1(where, howmuch);
cellcpy(&xrepl, repl);
@ -1407,28 +1409,36 @@ gsub2(PTR re, CELL *repl, CELL *target)
TRACE_STRING2(string(&xrepl)->str, have);
TRACE(("\n"));
if (pass) {
memcpy(output->str + used, string(&xrepl)->str, have);
used += have;
} else {
want += have;
if (howmuch || (j != skip0)) {
++repl_cnt;
if (pass) {
memcpy(output->str + used, string(&xrepl)->str, have);
used += have;
} else {
want += have;
}
}
if (howmuch) {
j = (where - input->str) + howmuch - 1;
} else if (j < (int) input->len) {
TRACE(("..emptied:"));
TRACE_STRING2(input->str + j, 1);
TRACE(("\n"));
if (pass) {
output->str[used++] = input->str[j];
} else {
++want;
j = (int) ((size_t) (where - input->str) + howmuch) - 1;
} else {
j = (int) (where - input->str);
if (j < (int) input->len) {
TRACE(("..emptied:"));
TRACE_STRING2(input->str + j, 1);
TRACE(("\n"));
if (pass) {
output->str[used++] = input->str[j];
} else {
++want;
}
}
}
skip0 = (howmuch != 0) ? (j + 1) : -1;
} else {
if (repl_cnt) {
have = (input->len - j);
have = (input->len - (size_t) j);
TRACE(("..after match:%d:", (int) have));
TRACE_STRING2(input->str + j, have);
TRACE(("\n"));
@ -1462,6 +1472,7 @@ gsub2(PTR re, CELL *repl, CELL *target)
#ifdef EXP_UNROLLED_GSUB
/* #define DEBUG_GSUB 1 */
#ifdef USE_GSUB1
static size_t gsub_max;
static GSUB_STK *gsub_stk;
@ -1613,6 +1624,7 @@ gsub1(PTR re, int level)
return ThisResult;
}
#endif
/* set up for call to gsub() */
CELL *
@ -1622,11 +1634,14 @@ bi_gsub(CELL *sp)
CELL sc; /* copy of replacement target */
CELL tc; /* build the result here */
STRING *result;
#if defined(USE_GSUB0) || defined(USE_GSUB2)
#if defined(DEBUG_GSUB)
STRING *resul2;
#endif
#ifdef USE_GSUB2
#else
size_t stack_needs;
int level = 0;
#endif
TRACE_FUNC("bi_gsub", sp);
@ -1649,8 +1664,24 @@ bi_gsub(CELL *sp)
TRACE(("arg2: "));
TRACE_CELL(&sc);
stack_needs = (string(&sc)->len + 2) * 2;
#ifdef DEBUG_GSUB
{
STRING *target = new_STRING1(string(&sc)->str, string(&sc)->len);
repl_cnt = 0;
cellcpy(&ThisReplace, sp + 1);
resul2 = gsub0(sp->ptr, &ThisReplace, target->str, target->len, 1);
TRACE(("OLD ->%u:", repl_cnt));
TRACE_STRING(resul2);
TRACE(("\n"));
free_STRING(target);
}
#endif
#ifdef USE_GSUB2
result = gsub2(sp->ptr, sp + 1, &sc);
tc.ptr = (PTR) result;
#else
stack_needs = (string(&sc)->len + 2) * 2;
if (stack_needs > gsub_max) {
if (gsub_max) {
zfree(gsub_stk, gsub_max * sizeof(GSUB_STK));
@ -1658,29 +1689,6 @@ bi_gsub(CELL *sp)
gsub_stk = zmalloc(stack_needs * sizeof(GSUB_STK));
gsub_max = stack_needs;
}
#ifdef USE_GSUB0
{
STRING *target = new_STRING1(string(&sc)->str, string(&sc)->len);
repl_cnt = 0;
cellcpy(&ThisReplace, sp + 1);
resul2 = gsub0(sp->ptr, &ThisReplace, target->str, target->len, 1);
TRACE(("OLD ->%d:", (int) resul2->len));
TRACE_STRING(resul2);
TRACE(("\n"));
free_STRING(target);
}
#endif
#ifdef USE_GSUB2
{
resul2 = gsub2(sp->ptr, sp + 1, &sc);
if (resul2 != 0) {
TRACE(("XXX ->%d:", (int) resul2->len));
TRACE_STRING(resul2);
TRACE(("\n"));
}
}
#endif
ThisBranch = btFinish;
ThisEmptyOk = 1;
@ -1693,12 +1701,14 @@ bi_gsub(CELL *sp)
result = gsub1(sp->ptr, 0);
tc.ptr = (PTR) result;
#endif
#ifdef USE_GSUB0
#ifdef DEBUG_GSUB
TRACE(("NEW -> %d:", (int) result->len));
TRACE_STRING(result);
TRACE(("\n"));
if (resul2 != 0 &&
if (result != 0 &&
resul2 != 0 &&
((result->len != resul2->len) ||
memcmp(result->str, resul2->str, result->len))) {
TRACE(("OOPS: gsub result NEW != OLD\n"));
@ -1709,12 +1719,15 @@ bi_gsub(CELL *sp)
tc.type = C_STRING;
slow_cell_assign(cp, &tc);
}
#ifdef USE_GSUB2
#else
#ifdef NO_LEAKS
if (gsub_stk != 0) {
zfree(gsub_stk, stack_needs * sizeof(GSUB_STK));
gsub_stk = 0;
gsub_max = 0;
}
#endif
#endif
sp->type = C_DOUBLE;
@ -1728,7 +1741,9 @@ bi_gsub(CELL *sp)
/* cleanup */
free_STRING(string(&sc));
free_STRING(string(&tc));
if (tc.ptr != 0) {
free_STRING(string(&tc));
}
repl_destroy(sp + 1);
return_CELL("bi_gsub", sp);

View File

@ -1,4 +1,4 @@
mawk-cur (1.3.4-20140817) unstable; urgency=low
mawk-cur (1.3.4-20140818) unstable; urgency=low
* improve field- and buffer-limits
* configure-script updates

View File

@ -1,8 +1,8 @@
Summary: mawk - pattern scanning and text processing language
%define AppProgram mawk
%define AppVersion 1.3.4
%define AppRelease 20140817
# $MawkId: mawk.spec,v 1.37 2014/08/17 20:04:23 tom Exp $
%define AppRelease 20140818
# $MawkId: mawk.spec,v 1.38 2014/08/18 09:10:06 tom Exp $
Name: %{AppProgram}
Version: %{AppVersion}
Release: %{AppRelease}

View File

@ -11,9 +11,9 @@ the GNU General Public License, version 2, 1991.
*/
/*
* $MawkId: patchlev.h,v 1.60 2014/08/17 20:04:23 tom Exp $
* $MawkId: patchlev.h,v 1.61 2014/08/18 09:10:06 tom Exp $
*/
#define PATCH_BASE 1
#define PATCH_LEVEL 3
#define PATCH_STRING ".4"
#define DATE_STRING "20140817"
#define DATE_STRING "20140818"

View File

@ -11,7 +11,7 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*
* $MawkId: version.c,v 1.17 2014/08/15 00:56:12 tom Exp $
* $MawkId: version.c,v 1.18 2014/08/18 20:34:56 tom Exp $
*/
#include "mawk.h"
@ -20,8 +20,8 @@ the GNU General Public License, version 2, 1991.
#define VERSION_STRING \
"mawk %d.%d%s %s\n\
Copyright 2014, Thomas E. Dickey\n\
Copyright 2014, Michael D. Brennan\n\n"
Copyright 2008-2013,2014, Thomas E. Dickey\n\
Copyright 1991-1996,2014, Michael D. Brennan\n\n"
static const char fmt[] = "%-14s%10lu\n";