Back to index

php5  5.3.10
regtrav.c
Go to the documentation of this file.
00001 /**********************************************************************
00002   regtrav.c -  Oniguruma (regular expression library)
00003 **********************************************************************/
00004 /*-
00005  * Copyright (c) 2002-2004  K.Kosako  <sndgk393 AT ybb DOT ne DOT jp>
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions
00010  * are met:
00011  * 1. Redistributions of source code must retain the above copyright
00012  *    notice, this list of conditions and the following disclaimer.
00013  * 2. Redistributions in binary form must reproduce the above copyright
00014  *    notice, this list of conditions and the following disclaimer in the
00015  *    documentation and/or other materials provided with the distribution.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00027  * SUCH DAMAGE.
00028  */
00029 
00030 #include "regint.h"
00031 
00032 #ifdef USE_CAPTURE_HISTORY
00033 
00034 static int
00035 capture_tree_traverse(OnigCaptureTreeNode* node, int at,
00036                       int(*callback_func)(int,int,int,int,int,void*),
00037                       int level, void* arg)
00038 {
00039   int r, i;
00040 
00041   if (node == (OnigCaptureTreeNode* )0)
00042     return 0;
00043 
00044   if ((at & ONIG_TRAVERSE_CALLBACK_AT_FIRST) != 0) {
00045     r = (*callback_func)(node->group, node->beg, node->end,
00046                          level, ONIG_TRAVERSE_CALLBACK_AT_FIRST, arg);
00047     if (r != 0) return r;
00048   }
00049 
00050   for (i = 0; i < node->num_childs; i++) {
00051     r = capture_tree_traverse(node->childs[i], at,
00052                               callback_func, level + 1, arg);
00053     if (r != 0) return r;
00054   }
00055 
00056   if ((at & ONIG_TRAVERSE_CALLBACK_AT_LAST) != 0) {
00057     r = (*callback_func)(node->group, node->beg, node->end,
00058                          level, ONIG_TRAVERSE_CALLBACK_AT_LAST, arg);
00059     if (r != 0) return r;
00060   }
00061 
00062   return 0;
00063 }
00064 #endif /* USE_CAPTURE_HISTORY */
00065 
00066 extern int
00067 onig_capture_tree_traverse(OnigRegion* region, int at,
00068                   int(*callback_func)(int,int,int,int,int,void*), void* arg)
00069 {
00070 #ifdef USE_CAPTURE_HISTORY
00071   return capture_tree_traverse(region->history_root, at,
00072                                callback_func, 0, arg);
00073 #else
00074   return ONIG_NO_SUPPORT_CONFIG;
00075 #endif
00076 }