if (cur_state->has_backref) { int i; re_dfa_t *dfa = (re_dfa_t *) preg->buffer; for (i = 0; i < cur_state->nodes.nelem; ++i) { re_token_type_t type; int node = cur_state->nodes.elems[i]; int entity = (dfa->nodes[node].type != OP_CONTEXT_NODE ? node : dfa->nodes[node].opr.ctx_info->entity); type = dfa->nodes[entity].type; if (type == OP_BACK_REF) { int clexp_idx; for (clexp_idx = 0; clexp_idx < cur_state->nodes.nelem; ++clexp_idx) { re_token_t *clexp_node; clexp_node = dfa->nodes + cur_state->nodes.elems[clexp_idx]; if (clexp_node->type == OP_CLOSE_SUBEXP && clexp_node->opr.idx + 1== dfa->nodes[entity].opr.idx) { err = match_ctx_add_entry (mctx, node, 0, 0, 0); if (BE (err != REG_NOERROR, 0)) return -2; break; } } } } }
check_matching (preg, mctx, fl_search, fl_longest_match)    const regex_t *preg;    re_match_context_t *mctx;    int fl_search, fl_longest_match;{  reg_errcode_t err;  int match = 0;  int match_last = -1;  int cur_str_idx = re_string_cur_idx (mctx->input);  re_dfastate_t *cur_state;  cur_state = acquire_init_state_context (&err, preg, mctx, cur_str_idx);  /* An initial state must not be NULL(invalid state).  */  if (BE (cur_state == NULL, 0))    return -2;  if (mctx->state_log != NULL)    mctx->state_log[cur_str_idx] = cur_state;  /* If the RE accepts NULL string.  */  if (cur_state->halt)    {      if (!cur_state->has_constraint          || check_halt_state_context (preg, cur_state, mctx, cur_str_idx))        {          if (!fl_longest_match)            return cur_str_idx;          else            {              match_last = cur_str_idx;              match = 1;            }        }    }  while (!re_string_eoi (mctx->input))    {      cur_state = transit_state (&err, preg, mctx, cur_state,                                 fl_search && !match);      if (cur_state == NULL) /* Reached at the invalid state or an error.  */        {          cur_str_idx = re_string_cur_idx (mctx->input);          if (BE (err != REG_NOERROR, 0))            return -2;          if (fl_search && !match)            {              /* Restart from initial state, since we are searching                 the point from where matching start.  */#ifdef RE_ENABLE_I18N              if (MB_CUR_MAX == 1                  || re_string_first_byte (mctx->input, cur_str_idx))#endif /* RE_ENABLE_I18N */                cur_state = acquire_init_state_context (&err, preg, mctx,                                                        cur_str_idx);              if (BE (cur_state == NULL && err != REG_NOERROR, 0))                return -2;              if (mctx->state_log != NULL)                mctx->state_log[cur_str_idx] = cur_state;            }          else if (!fl_longest_match && match)            break;          else /* (fl_longest_match && match) || (!fl_search && !match)  */            {              if (mctx->state_log == NULL)                break;              else                {                  int max = mctx->state_log_top;                  for (; cur_str_idx <= max; ++cur_str_idx)                    if (mctx->state_log[cur_str_idx] != NULL)                      break;                  if (cur_str_idx > max)                    break;                }            }        }      if (cur_state != NULL && cur_state->halt)        {          /* Reached at a halt state.             Check the halt state can satisfy the current context.  */          if (!cur_state->has_constraint              || check_halt_state_context (preg, cur_state, mctx,                                           re_string_cur_idx (mctx->input)))            {              /* We found an appropriate halt state.  */              match_last = re_string_cur_idx (mctx->input);              match = 1;              if (!fl_longest_match)                break;            }        }   }  return match_last;}