Skip to content

Commit

Permalink
operator: record the base position on matchloc objects
Browse files Browse the repository at this point in the history
Signed-off-by: Masatake YAMATO <[email protected]>
  • Loading branch information
masatake committed Dec 12, 2022
1 parent 1a9f953 commit 6c8ce10
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 3 additions & 2 deletions main/lregex.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion main/script_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6c8ce10

Please sign in to comment.