Skip to content

Commit d3244d9

Browse files
committed
operator: record the base position on matchloc objects
Signed-off-by: Masatake YAMATO <[email protected]>
1 parent 43c14a7 commit d3244d9

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

main/lregex.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3539,17 +3539,18 @@ static matchLoc *make_mloc (scriptWindow *window, int group, bool start)
35393539
matchLoc *mloc = xMalloc (1, matchLoc);
35403540
if (window->patbuf->regptype == REG_PARSER_SINGLE_LINE)
35413541
{
3542+
mloc->base = 0;
35423543
mloc->delta = 0;
35433544
mloc->line = getInputLineNumber ();
35443545
mloc->pos = getInputFilePosition ();
35453546
}
35463547
else
35473548
{
3549+
mloc->base = window->line - window->start;
35483550
mloc->delta = (start
35493551
? window->pmatch [group].rm_so
35503552
: window->pmatch [group].rm_eo);
3551-
off_t offset = (window->line + mloc->delta) - window->start;
3552-
mloc->line = getInputLineNumberForFileOffset (offset);
3553+
mloc->line = getInputLineNumberForFileOffset (mloc->base + mloc->delta);
35533554
mloc->pos = getInputFilePositionForLine (mloc->line);
35543555
}
35553556
return mloc;

main/script_p.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ extern void optscriptHelp (OptVM *vm, FILE *fp, EsObject *procdocs
5252
extern xtagType optscriptGetXtagType (const EsObject *extra);
5353

5454
typedef struct {
55-
unsigned long delta; /* for _advanceto operator */
55+
unsigned long base; /* useless when the parser type is
56+
* REG_PARSER_SINGLE_LINE.
57+
* base + delta is the file offset. */
58+
unsigned long delta; /* for _advanceto operator, relateive from
59+
* the base. */
5660
unsigned long line;
5761
MIOPos pos;
5862
} matchLoc;

0 commit comments

Comments
 (0)