From 32eb2a148ea7a257a058658af36e9f8c801a524a Mon Sep 17 00:00:00 2001 From: Mark Tiefenbruck Date: Thu, 27 Dec 2007 22:15:06 -0800 Subject: move RegExp to FbTk --- src/ClientPattern.cc | 1 - src/ClientPattern.hh | 4 +- src/FbTk/Makefile.am | 1 + src/FbTk/RegExp.cc | 96 +++++++++++++++++++++++++++++++++++++++++++++ src/FbTk/RegExp.hh | 66 +++++++++++++++++++++++++++++++ src/Makefile.am | 3 +- src/RegExp.cc | 109 --------------------------------------------------- src/RegExp.hh | 66 ------------------------------- 8 files changed, 166 insertions(+), 180 deletions(-) create mode 100644 src/FbTk/RegExp.cc create mode 100644 src/FbTk/RegExp.hh delete mode 100644 src/RegExp.cc delete mode 100644 src/RegExp.hh diff --git a/src/ClientPattern.cc b/src/ClientPattern.cc index d094e63..fcc2370 100644 --- a/src/ClientPattern.cc +++ b/src/ClientPattern.cc @@ -23,7 +23,6 @@ // $Id$ #include "ClientPattern.hh" -#include "RegExp.hh" #include "FocusControl.hh" #include "Layer.hh" diff --git a/src/ClientPattern.hh b/src/ClientPattern.hh index b76aef8..4531c4a 100644 --- a/src/ClientPattern.hh +++ b/src/ClientPattern.hh @@ -26,7 +26,7 @@ #ifndef CLIENTPATTERN_HH #define CLIENTPATTERN_HH -#include "RegExp.hh" +#include "FbTk/RegExp.hh" #include "NotCopyable.hh" #include @@ -99,7 +99,7 @@ private: struct Term { Term(const std::string ®str, bool full_match) :regexp(regstr, full_match){}; std::string orig; - RegExp regexp; + FbTk::RegExp regexp; WinProperty prop; bool negate; }; diff --git a/src/FbTk/Makefile.am b/src/FbTk/Makefile.am index 86f8594..5f1c246 100644 --- a/src/FbTk/Makefile.am +++ b/src/FbTk/Makefile.am @@ -41,6 +41,7 @@ libFbTk_a_SOURCES = App.hh App.cc Color.cc Color.hh Command.hh \ XLayer.cc XLayer.hh XLayerItem.cc XLayerItem.hh \ Resource.hh Resource.cc \ StringUtil.hh StringUtil.cc Parser.hh Parser.cc \ + RegExp.hh RegExp.cc \ FbString.hh FbString.cc \ Subject.hh Subject.cc Observer.hh Observer.cc \ Transparent.hh Transparent.cc \ diff --git a/src/FbTk/RegExp.cc b/src/FbTk/RegExp.cc new file mode 100644 index 0000000..df98982 --- /dev/null +++ b/src/FbTk/RegExp.cc @@ -0,0 +1,96 @@ +// RegExp.cc for FbTk +// Copyright (c) 2003 Henrik Kinnunen (fluxgen at fluxbox dot org) +// and Simon Bowden (rathnor at users.sourceforge.net) +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +#include "RegExp.hh" + +//use GNU extensions +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif // _GNU_SOURCE + +#include +#include + +using std::string; + +#ifdef USE_REGEXP +using std::cerr; +using std::endl; +#endif // USE_REGEXP + +namespace FbTk { + +// full_match is to say if we match on this regexp using the full string +// or just a substring. Substrings aren't supported if not HAVE_REGEXP +RegExp::RegExp(const string &str, bool full_match): +#ifdef USE_REGEXP +m_regex(0) { + string match; + if (full_match) { + match = "^"; + match.append(str); + match.append("$"); + } else { + match = str; + } + + m_regex = new regex_t; + int ret = regcomp(m_regex, match.c_str(), REG_NOSUB | REG_EXTENDED); + if (ret != 0) { + delete m_regex; // I don't think I regfree a failed compile? + m_regex = 0; + } +} +#else // notdef USE_REGEXP +m_str(str) {} +#endif // USE_REGEXP + +RegExp::~RegExp() { +#ifdef USE_REGEXP + if (m_regex != 0) { + regfree(m_regex); + delete m_regex; + } +#endif // USE_REGEXP +} + +bool RegExp::match(const string &str) const { +#ifdef USE_REGEXP + if (m_regex) + return regexec(m_regex, str.c_str(), 0, 0, 0) == 0; + else + return false; +#else // notdef USE_REGEXP + return (m_str == str); +#endif // USE_REGEXP +} + + +bool RegExp::error() const { +#ifdef USE_REGEXP + return m_regex == 0; +#else + return m_str == ""; +#endif // USE_REGEXP +} + +}; // end namespace FbTk diff --git a/src/FbTk/RegExp.hh b/src/FbTk/RegExp.hh new file mode 100644 index 0000000..0386670 --- /dev/null +++ b/src/FbTk/RegExp.hh @@ -0,0 +1,66 @@ +// RegExp.hh for FbTk +// Copyright (c) 2002 Xavier Brouckaert +// Copyright (c) 2003 Henrik Kinnunen (fluxgen at fluxbox dot org) +// and Simon Bowden (rathnor at users.sourceforge.net) +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +#ifndef FBTK_REGEXP_HH +#define FBTK_REGEXP_HH + +#include "NotCopyable.hh" + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif // HAVE_CONFIG_H + +#include + +/* + * If USE_REGEXP isn't defined, then we match just using simple string equality + */ + +#ifdef USE_REGEXP +#include +#include +#endif // USE_REGEXP + +namespace FbTk { + +class RegExp: private NotCopyable { +public: + RegExp(const std::string &str, bool full_match = true); + ~RegExp(); + + bool match(const std::string &str) const; + + bool error() const; + +private: +#ifdef USE_REGEXP + regex_t* m_regex; +#else // notdef USE_REGEXP + std::string m_str; +#endif // USE_REGEXP + +}; + +}; // end namespace FbTk + +#endif // FBTK_REGEXP_HH diff --git a/src/Makefile.am b/src/Makefile.am index dfed93b..b40affd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -78,9 +78,8 @@ if GNOME gnome_SOURCE= Gnome.hh Gnome.cc endif if REMEMBER_SRC -# For now we only want regexp if we have remember REMEMBER_SOURCE= Remember.hh Remember.cc \ - RegExp.hh RegExp.cc ClientPattern.hh ClientPattern.cc + ClientPattern.hh ClientPattern.cc endif if TOOLBAR_SRC TOOLBAR_SOURCE = Toolbar.hh Toolbar.cc \ diff --git a/src/RegExp.cc b/src/RegExp.cc deleted file mode 100644 index 895cc7b..0000000 --- a/src/RegExp.cc +++ /dev/null @@ -1,109 +0,0 @@ -// RegExp.cc for Fluxbox Window Manager -// Copyright (c) 2003 Henrik Kinnunen (fluxgen at fluxbox dot org) -// and Simon Bowden (rathnor at users.sourceforge.net) -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -// $Id$ - -#include "RegExp.hh" -#include "FbTk/I18n.hh" - -//use GNU extensions -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif // _GNU_SOURCE - -#include -#include - -using std::string; - -#ifdef USE_REGEXP -using std::cerr; -using std::endl; -#endif // USE_REGEXP - - -/******************************************************** - * RegExp * - **********/ - -// full_match is to say if we match on this regexp using the full string -// or just a substring. Substrings aren't supported if not HAVE_REGEXP -RegExp::RegExp(const string &str, bool full_match): -#ifdef USE_REGEXP -m_regex(0) { - string match; - if (full_match) { - match = "^"; - match.append(str); - match.append("$"); - } else { - match = str; - } - - m_regex = new regex_t; - int ret = regcomp(m_regex, match.c_str(), REG_NOSUB | REG_EXTENDED); - if (ret != 0) { - char *errstr = 0; - _FB_USES_NLS; - // gives us the length of the string - unsigned int size = regerror(ret, m_regex, errstr, 0); - errstr = new char[size]; - - regerror(ret, m_regex, errstr, size); - cerr<<_FB_CONSOLETEXT(Fluxbox, ErrorRegexp, "Error parsing regular expression", "Error parsing regular expression (following)")<<": "< - -/* - * If USE_REGEXP isn't defined, then we match just using simple string equality - */ - -#ifdef USE_REGEXP -#include -#include -#endif // USE_REGEXP - -class WinClient; - -class RegExp:private FbTk::NotCopyable { -public: - RegExp(const std::string &str, bool full_match = true); - ~RegExp(); - - bool match(const std::string &str) const; - - bool error() const; - -private: -#ifdef USE_REGEXP - regex_t* m_regex; -#else // notdef USE_REGEXP - std::string m_str; -#endif // USE_REGEXP - -}; - -#endif // REGEXP_HH -- cgit v0.11.2