1 2 /*--------------------------------------------------------------------*/ 3 /*--- A simple sequence matching facility. ---*/ 4 /*--- pub_tool_seqmatch.h ---*/ 5 /*--------------------------------------------------------------------*/ 6 7 /* 8 This file is part of Valgrind, a dynamic binary instrumentation 9 framework. 10 11 Copyright (C) 2008-2012 OpenWorks Ltd 12 info (at) open-works.co.uk 13 14 This program is free software; you can redistribute it and/or 15 modify it under the terms of the GNU General Public License as 16 published by the Free Software Foundation; either version 2 of the 17 License, or (at your option) any later version. 18 19 This program is distributed in the hope that it will be useful, but 20 WITHOUT ANY WARRANTY; without even the implied warranty of 21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 General Public License for more details. 23 24 You should have received a copy of the GNU General Public License 25 along with this program; if not, write to the Free Software 26 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 27 02111-1307, USA. 28 29 The GNU General Public License is contained in the file COPYING. 30 */ 31 32 #ifndef __PUB_TOOL_SEQMATCH_H 33 #define __PUB_TOOL_SEQMATCH_H 34 35 /* Perform totally abstractified sequence matching, of an input 36 sequence against a pattern sequence. The pattern sequence may 37 include '*' elements (matches any number of anything) and '?' 38 elements (matches exactly one element). '*' patterns are matched 39 frugally, meaning that they are "assigned" the minimum amount of 40 input needed to make the match work. 41 42 This routine is recursive. The recursion depth is equal to the 43 number of '*' elements in the pattern. There is no guard against 44 excessive recursion. This function has no global state and so is 45 thread-safe and re-entrant. (It needs to be, since m_errormgr will 46 effectively construct two simultaneous calls to it, once to match 47 at the frame level, and whilst that is happening, once at the 48 function/object-name level.) 49 50 When matchAll is True, the entire input sequence must match the 51 pattern, else the match fails. When False, it's ok for some tail 52 of the input sequence to be unused -- so we're only matching a 53 prefix. 54 55 The pattern array is starts at 'patt' and consists of 'nPatt' 56 elements each of size 'szbPatt'. For the initial call, pass a 57 value of zero to 'ixPatt'. 58 59 Ditto for input/nInput/szbInput/ixInput. 60 61 pIsStar should return True iff the pointed-to pattern element is 62 conceptually a '*'. 63 64 pIsQuery should return True iff the pointed-to-pattern element is 65 conceptually a '?'. 66 67 pattEQinp takes a pointer to a pattern element and a pointer to an 68 input element. It should return True iff they are considered 69 equal. Note that the pattern element is guaranteed to be neither 70 (conceptually) '*' nor '?', so it must be a literal (in the sense 71 that all the input sequence elements are literal). 72 73 input might be lazily constructed when pattEQinp is called. 74 For lazily constructing the input element, the two last arguments 75 of pattEQinp are the inputCompleter and the index of the input 76 element to complete. 77 inputCompleter can be NULL. 78 */ 79 Bool VG_(generic_match) ( 80 Bool matchAll, 81 void* patt, SizeT szbPatt, UWord nPatt, UWord ixPatt, 82 void* input, SizeT szbInput, UWord nInput, UWord ixInput, 83 Bool (*pIsStar)(void*), 84 Bool (*pIsQuery)(void*), 85 Bool (*pattEQinp)(void*,void*,void*,UWord), 86 void* inputCompleter 87 ); 88 89 /* Mini-regexp function. Searches for 'pat' in 'str'. Supports 90 meta-symbols '*' and '?'. There is no way to escape meta-symbols 91 in the pattern. */ 92 Bool VG_(string_match) ( const Char* pat, const Char* str ); 93 94 #endif // __PUB_TOOL_SEQMATCH_H 95 96 /*--------------------------------------------------------------------*/ 97 /*--- end pub_tool_seqmatch.h ---*/ 98 /*--------------------------------------------------------------------*/ 99