1*5ba1f45fSchristos /* Copyright (C) 2011-2024 Free Software Foundation, Inc. 24b169a6bSchristos 34b169a6bSchristos This file is part of GDB. 44b169a6bSchristos 54b169a6bSchristos This program is free software; you can redistribute it and/or modify 64b169a6bSchristos it under the terms of the GNU General Public License as published by 74b169a6bSchristos the Free Software Foundation; either version 3 of the License, or 84b169a6bSchristos (at your option) any later version. 94b169a6bSchristos 104b169a6bSchristos This program is distributed in the hope that it will be useful, 114b169a6bSchristos but WITHOUT ANY WARRANTY; without even the implied warranty of 124b169a6bSchristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 134b169a6bSchristos GNU General Public License for more details. 144b169a6bSchristos 154b169a6bSchristos You should have received a copy of the GNU General Public License 164b169a6bSchristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 174b169a6bSchristos 184b169a6bSchristos #include "gdb_regex.h" 194b169a6bSchristos #include "gdbsupport/def-vector.h" 204b169a6bSchristos 214b169a6bSchristos compiled_regex::compiled_regex (const char *regex, int cflags, 224b169a6bSchristos const char *message) 234b169a6bSchristos { 244b169a6bSchristos gdb_assert (regex != NULL); 254b169a6bSchristos gdb_assert (message != NULL); 264b169a6bSchristos 274b169a6bSchristos int code = regcomp (&m_pattern, regex, cflags); 284b169a6bSchristos if (code != 0) 294b169a6bSchristos { 304b169a6bSchristos size_t length = regerror (code, &m_pattern, NULL, 0); 314b169a6bSchristos gdb::def_vector<char> err (length); 324b169a6bSchristos 334b169a6bSchristos regerror (code, &m_pattern, err.data (), length); 344b169a6bSchristos error (("%s: %s"), message, err.data ()); 354b169a6bSchristos } 364b169a6bSchristos } 374b169a6bSchristos 384b169a6bSchristos compiled_regex::~compiled_regex () 394b169a6bSchristos { 404b169a6bSchristos regfree (&m_pattern); 414b169a6bSchristos } 424b169a6bSchristos 434b169a6bSchristos int 444b169a6bSchristos compiled_regex::exec (const char *string, size_t nmatch, 454b169a6bSchristos regmatch_t pmatch[], int eflags) const 464b169a6bSchristos { 474b169a6bSchristos return regexec (&m_pattern, string, nmatch, pmatch, eflags); 484b169a6bSchristos } 494b169a6bSchristos 504b169a6bSchristos int 514b169a6bSchristos compiled_regex::search (const char *string, 524b169a6bSchristos int length, int start, int range, 534b169a6bSchristos struct re_registers *regs) 544b169a6bSchristos { 554b169a6bSchristos return re_search (&m_pattern, string, length, start, range, regs); 564b169a6bSchristos } 57