From 6c8ce10bcc5ae5232a5c169f7dd5d159af5ed4eb Mon Sep 17 00:00:00 2001 From: Masatake YAMATO Date: Tue, 13 Dec 2022 03:21:54 +0900 Subject: [PATCH] operator: record the base position on matchloc objects Signed-off-by: Masatake YAMATO --- main/lregex.c | 5 +++-- main/script_p.h | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/main/lregex.c b/main/lregex.c index 08133b1c92..61498121fc 100644 --- a/main/lregex.c +++ b/main/lregex.c @@ -3539,17 +3539,18 @@ static matchLoc *make_mloc (scriptWindow *window, int group, bool start) matchLoc *mloc = xMalloc (1, matchLoc); if (window->patbuf->regptype == REG_PARSER_SINGLE_LINE) { + mloc->base = 0; mloc->delta = 0; mloc->line = getInputLineNumber (); mloc->pos = getInputFilePosition (); } else { + mloc->base = window->line - window->start; mloc->delta = (start ? window->pmatch [group].rm_so : window->pmatch [group].rm_eo); - off_t offset = (window->line + mloc->delta) - window->start; - mloc->line = getInputLineNumberForFileOffset (offset); + mloc->line = getInputLineNumberForFileOffset (mloc->base + mloc->delta); mloc->pos = getInputFilePositionForLine (mloc->line); } return mloc; diff --git a/main/script_p.h b/main/script_p.h index 5122322598..7e8852da53 100644 --- a/main/script_p.h +++ b/main/script_p.h @@ -52,7 +52,11 @@ extern void optscriptHelp (OptVM *vm, FILE *fp, EsObject *procdocs extern xtagType optscriptGetXtagType (const EsObject *extra); typedef struct { - unsigned long delta; /* for _advanceto operator */ + unsigned long base; /* useless when the parser type is + * REG_PARSER_SINGLE_LINE. + * base + delta is the file offset. */ + unsigned long delta; /* for _advanceto operator, relateive from + * the base. */ unsigned long line; MIOPos pos; } matchLoc;