From c46a8227d0bfc31e4f71b6441303348f5c31174b Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Wed, 20 Jan 2021 16:12:46 -0800 Subject: Added --skip flag for skipping over patterns --- pattern.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'pattern.c') diff --git a/pattern.c b/pattern.c index 17560b4..ff9841f 100644 --- a/pattern.c +++ b/pattern.c @@ -120,14 +120,7 @@ static pat_t *expand_choices(file_t *f, pat_t *first) if (!second) file_err(f, str, str, "There should be a pattern here after a '/'"); second = expand_choices(f, second); - pat_t *choice = new_pat(f, first->start, BP_OTHERWISE); - if (first->len == second->len) - choice->len = first->len; - else choice->len = -1; - choice->end = second->end; - choice->args.multiple.first = first; - choice->args.multiple.second = second; - return choice; + return either_pat(f, first, second); } // @@ -139,7 +132,6 @@ pat_t *chain_together(file_t *f, pat_t *first, pat_t *second) if (first == NULL) return second; if (second == NULL) return first; pat_t *chain = new_pat(f, first->start, BP_CHAIN); - chain->start = first->start; if (first->len >= 0 && second->len >= 0) chain->len = first->len + second->len; else chain->len = -1; @@ -162,6 +154,24 @@ pat_t *chain_together(file_t *f, pat_t *first, pat_t *second) return chain; } +// +// Given two patterns, return a new pattern for matching either the first +// pattern or the second. If either pattern is NULL, return the other. +// +pat_t *either_pat(file_t *f, pat_t *first, pat_t *second) +{ + if (first == NULL) return second; + if (second == NULL) return first; + pat_t *either = new_pat(f, first->start, BP_OTHERWISE); + if (first->len == second->len) + either->len = first->len; + else either->len = -1; + either->end = second->end; + either->args.multiple.first = first; + either->args.multiple.second = second; + return either; +} + // // Wrapper for _bp_simplepattern() that expands any postfix operators // @@ -262,17 +272,7 @@ static pat_t *_bp_simplepattern(file_t *f, const char *str) pat->len = 1; pat->end = str; - - if (all == NULL) { - all = pat; - } else { - pat_t *either = new_pat(f, all->start, BP_OTHERWISE); - either->end = pat->end; - either->args.multiple.first = all; - either->args.multiple.second = pat; - either->len = 1; - all = either; - } + all = either_pat(f, all, pat); pat = NULL; } while (matchchar(&str, ',')); -- cgit v1.2.3