Blame src/regtrav.c

Packit Service bd74e6
/**********************************************************************
Packit Service bd74e6
  regtrav.c -  Oniguruma (regular expression library)
Packit Service bd74e6
**********************************************************************/
Packit Service bd74e6
/*-
Packit Service bd74e6
 * Copyright (c) 2002-2004  K.Kosako  <sndgk393 AT ybb DOT ne DOT jp>
Packit Service bd74e6
 * All rights reserved.
Packit Service bd74e6
 *
Packit Service bd74e6
 * Redistribution and use in source and binary forms, with or without
Packit Service bd74e6
 * modification, are permitted provided that the following conditions
Packit Service bd74e6
 * are met:
Packit Service bd74e6
 * 1. Redistributions of source code must retain the above copyright
Packit Service bd74e6
 *    notice, this list of conditions and the following disclaimer.
Packit Service bd74e6
 * 2. Redistributions in binary form must reproduce the above copyright
Packit Service bd74e6
 *    notice, this list of conditions and the following disclaimer in the
Packit Service bd74e6
 *    documentation and/or other materials provided with the distribution.
Packit Service bd74e6
 *
Packit Service bd74e6
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
Packit Service bd74e6
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit Service bd74e6
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit Service bd74e6
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
Packit Service bd74e6
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit Service bd74e6
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
Packit Service bd74e6
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
Packit Service bd74e6
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
Packit Service bd74e6
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
Packit Service bd74e6
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
Packit Service bd74e6
 * SUCH DAMAGE.
Packit Service bd74e6
 */
Packit Service bd74e6
Packit Service bd74e6
#include "regint.h"
Packit Service bd74e6
Packit Service bd74e6
#ifdef USE_CAPTURE_HISTORY
Packit Service bd74e6
Packit Service bd74e6
static int
Packit Service bd74e6
capture_tree_traverse(OnigCaptureTreeNode* node, int at,
Packit Service bd74e6
                      int(*callback_func)(int,int,int,int,int,void*),
Packit Service bd74e6
                      int level, void* arg)
Packit Service bd74e6
{
Packit Service bd74e6
  int r, i;
Packit Service bd74e6
Packit Service bd74e6
  if (node == (OnigCaptureTreeNode* )0)
Packit Service bd74e6
    return 0;
Packit Service bd74e6
Packit Service bd74e6
  if ((at & ONIG_TRAVERSE_CALLBACK_AT_FIRST) != 0) {
Packit Service bd74e6
    r = (*callback_func)(node->group, node->beg, node->end,
Packit Service bd74e6
                         level, ONIG_TRAVERSE_CALLBACK_AT_FIRST, arg);
Packit Service bd74e6
    if (r != 0) return r;
Packit Service bd74e6
  }
Packit Service bd74e6
Packit Service bd74e6
  for (i = 0; i < node->num_childs; i++) {
Packit Service bd74e6
    r = capture_tree_traverse(node->childs[i], at,
Packit Service bd74e6
                              callback_func, level + 1, arg);
Packit Service bd74e6
    if (r != 0) return r;
Packit Service bd74e6
  }
Packit Service bd74e6
Packit Service bd74e6
  if ((at & ONIG_TRAVERSE_CALLBACK_AT_LAST) != 0) {
Packit Service bd74e6
    r = (*callback_func)(node->group, node->beg, node->end,
Packit Service bd74e6
                         level, ONIG_TRAVERSE_CALLBACK_AT_LAST, arg);
Packit Service bd74e6
    if (r != 0) return r;
Packit Service bd74e6
  }
Packit Service bd74e6
Packit Service bd74e6
  return 0;
Packit Service bd74e6
}
Packit Service bd74e6
#endif /* USE_CAPTURE_HISTORY */
Packit Service bd74e6
Packit Service bd74e6
extern int
Packit Service bd74e6
onig_capture_tree_traverse(OnigRegion* region, int at,
Packit Service bd74e6
                  int(*callback_func)(int,int,int,int,int,void*), void* arg)
Packit Service bd74e6
{
Packit Service bd74e6
#ifdef USE_CAPTURE_HISTORY
Packit Service bd74e6
  return capture_tree_traverse(region->history_root, at,
Packit Service bd74e6
                               callback_func, 0, arg);
Packit Service bd74e6
#else
Packit Service bd74e6
  return ONIG_NO_SUPPORT_CONFIG;
Packit Service bd74e6
#endif
Packit Service bd74e6
}