sync with OpenBSD -current
This commit is contained in:
parent
87d00f0a9c
commit
f41d8bece2
26 changed files with 342 additions and 151 deletions
|
@ -1,4 +1,4 @@
|
|||
/* $OpenBSD: b.c,v 1.50 2024/01/25 16:40:51 millert Exp $ */
|
||||
/* $OpenBSD: b.c,v 1.51 2024/04/25 18:33:53 millert Exp $ */
|
||||
/****************************************************************
|
||||
Copyright (C) Lucent Technologies 1997
|
||||
All Rights Reserved
|
||||
|
@ -613,11 +613,11 @@ static void resize_gototab(fa *f, int state)
|
|||
size_t orig_size = f->gototab[state].allocated; // 2nd half of new mem is this size
|
||||
memset(p + orig_size, 0, orig_size * sizeof(gtte)); // clean it out
|
||||
|
||||
f->gototab[state].allocated = new_size; // update gotottab info
|
||||
f->gototab[state].allocated = new_size; // update gototab info
|
||||
f->gototab[state].entries = p;
|
||||
}
|
||||
|
||||
static int get_gototab(fa *f, int state, int ch) /* hide gototab inplementation */
|
||||
static int get_gototab(fa *f, int state, int ch) /* hide gototab implementation */
|
||||
{
|
||||
gtte key;
|
||||
gtte *item;
|
||||
|
@ -644,7 +644,7 @@ static int entry_cmp(const void *l, const void *r)
|
|||
return left->ch - right->ch;
|
||||
}
|
||||
|
||||
static int set_gototab(fa *f, int state, int ch, int val) /* hide gototab inplementation */
|
||||
static int set_gototab(fa *f, int state, int ch, int val) /* hide gototab implementation */
|
||||
{
|
||||
if (f->gototab[state].inuse == 0) {
|
||||
f->gototab[state].entries[0].ch = ch;
|
||||
|
@ -657,8 +657,8 @@ static int set_gototab(fa *f, int state, int ch, int val) /* hide gototab inplem
|
|||
if (tab->inuse + 1 >= tab->allocated)
|
||||
resize_gototab(f, state);
|
||||
|
||||
f->gototab[state].entries[f->gototab[state].inuse-1].ch = ch;
|
||||
f->gototab[state].entries[f->gototab[state].inuse-1].state = val;
|
||||
f->gototab[state].entries[f->gototab[state].inuse].ch = ch;
|
||||
f->gototab[state].entries[f->gototab[state].inuse].state = val;
|
||||
f->gototab[state].inuse++;
|
||||
return val;
|
||||
} else {
|
||||
|
@ -683,9 +683,9 @@ static int set_gototab(fa *f, int state, int ch, int val) /* hide gototab inplem
|
|||
gtt *tab = & f->gototab[state];
|
||||
if (tab->inuse + 1 >= tab->allocated)
|
||||
resize_gototab(f, state);
|
||||
++tab->inuse;
|
||||
f->gototab[state].entries[tab->inuse].ch = ch;
|
||||
f->gototab[state].entries[tab->inuse].state = val;
|
||||
++tab->inuse;
|
||||
|
||||
qsort(f->gototab[state].entries,
|
||||
f->gototab[state].inuse, sizeof(gtte), entry_cmp);
|
||||
|
@ -836,8 +836,6 @@ int nematch(fa *f, const char *p0) /* non-empty match, for sub */
|
|||
}
|
||||
|
||||
|
||||
#define MAX_UTF_BYTES 4 // UTF-8 is up to 4 bytes long
|
||||
|
||||
/*
|
||||
* NAME
|
||||
* fnematch
|
||||
|
@ -874,16 +872,28 @@ bool fnematch(fa *pfa, FILE *f, char **pbuf, int *pbufsize, int quantum)
|
|||
|
||||
do {
|
||||
/*
|
||||
* Call u8_rune with at least MAX_UTF_BYTES ahead in
|
||||
* Call u8_rune with at least awk_mb_cur_max ahead in
|
||||
* the buffer until EOF interferes.
|
||||
*/
|
||||
if (k - j < MAX_UTF_BYTES) {
|
||||
if (k + MAX_UTF_BYTES > buf + bufsize) {
|
||||
if (k - j < awk_mb_cur_max) {
|
||||
if (k + awk_mb_cur_max > buf + bufsize) {
|
||||
char *obuf = buf;
|
||||
adjbuf(&buf, &bufsize,
|
||||
bufsize + MAX_UTF_BYTES,
|
||||
bufsize + awk_mb_cur_max,
|
||||
quantum, 0, "fnematch");
|
||||
|
||||
/* buf resized, maybe moved. update pointers */
|
||||
*pbufsize = bufsize;
|
||||
if (obuf != buf) {
|
||||
i = buf + (i - obuf);
|
||||
j = buf + (j - obuf);
|
||||
k = buf + (k - obuf);
|
||||
*pbuf = buf;
|
||||
if (patlen)
|
||||
patbeg = buf + (patbeg - obuf);
|
||||
}
|
||||
}
|
||||
for (n = MAX_UTF_BYTES ; n > 0; n--) {
|
||||
for (n = awk_mb_cur_max ; n > 0; n--) {
|
||||
*k++ = (c = getc(f)) != EOF ? c : 0;
|
||||
if (c == EOF) {
|
||||
if (ferror(f))
|
||||
|
@ -920,10 +930,6 @@ bool fnematch(fa *pfa, FILE *f, char **pbuf, int *pbufsize, int quantum)
|
|||
s = 2;
|
||||
} while (1);
|
||||
|
||||
/* adjbuf() may have relocated a resized buffer. Inform the world. */
|
||||
*pbuf = buf;
|
||||
*pbufsize = bufsize;
|
||||
|
||||
if (patlen) {
|
||||
/*
|
||||
* Under no circumstances is the last character fed to
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue