Commit 538e3002 authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

regex compiles and is tested on fenoglio

This is a legacy commit from before 2015-03-01.
It may be incomplete as well as inconsistent.
See COPYING.legacy and README.history for details.


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 2455
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 54c87980
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id: Makefile,v 1.30 2007-12-05 12:20:01 tforb Exp $
# $Id: Makefile,v 1.31 2007-12-05 14:04:30 tforb Exp $
#
# Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
#
......@@ -58,7 +58,7 @@ HEADERS=$(wildcard $(addsuffix /*.h,$(DIRSTOINCLUDE)))
SRC=$(wildcard $(addsuffix /*.cc,$(DIRSTOINCLUDE)))
#TESTS=$(filter-out tests/blitztest,$(wildcard tests/*.cc))
TESTS=tests/commandlinetest.cc tests/fortraniotest.cc \
tests/stringtest.cc tests/handletest.cc
tests/stringtest.cc tests/handletest.cc tests/regextest.cc
#tests/blitztest.cc
FTESTS=$(wildcard tests/*.f)
README=$(shell find . -name README) README.xtra
......@@ -89,7 +89,7 @@ endif
FLAGS=$(MYFLAGS)
CXXFLAGS=-fhonor-std -Wall $(FLAGS)
CXXFLAGS=$(FLAGS)
LDFLAGS=-L$(LOCLIBDIR)
LDFLAGS=-L$(LOCLIBDIR) $(TF_LINK_REGEXX)
CPPFLAGS=-I$(LOCINCLUDEDIR) $(FLAGS) $(REGEXXFLAG)
#CPPFLAGS=-I$(LOCINCLUDEDIR) $(FLAGS) -I$(BLITZINCLUDE)
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: regexx.cc,v 1.1 2007-12-05 12:20:02 tforb Exp $
* $Id: regexx.cc,v 1.2 2007-12-05 14:04:31 tforb Exp $
* \author Thomas Forbriger
* \date 05/12/2007
*
......@@ -35,12 +35,120 @@
#define TF_REGEXX_CC_VERSION \
"TF_REGEXX_CC V1.0 "
#define TF_REGEXX_CC_CVSID \
"$Id: regexx.cc,v 1.1 2007-12-05 12:20:02 tforb Exp $"
"$Id: regexx.cc,v 1.2 2007-12-05 14:04:31 tforb Exp $"
#include <regexx.h>
#include <tfxx/regexx.h>
namespace tf {
#ifdef OLDLIBREGEXX
#include<regexx.hh>
#else
#include<boost/regex.hpp>
#endif
}
namespace tfxx {
namespace string {
namespace helper {
//! create instance.
regexxcontainer::regexxcontainer() { }
//! create instance and set expression to \c e.
regexxcontainer::regexxcontainer(const std::string& e) { }
//! create instance and set expression to \c e.
regexxcontainer::~regexxcontainer() { }
/*======================================================================*/
// use old libregexx
#ifdef OLDLIBREGEXX
/*! we need a helper class to hide the internals.
*
* delegate everything to the container class.
*/
class myregexxcontainer:
public tfxx::string::helper::regexxcontainer {
public:
//! create instance.
myregexxcontainer():
tfxx::string::helper::regexxcontainer()
{ this->expression(std::string(".*")); }
//! create instance and set expression to \c e.
myregexxcontainer(const std::string& e):
tfxx::string::helper::regexxcontainer(e)
{ this->expression(e); }
//! create instance and set expression to \c e.
virtual ~myregexxcontainer() { }
//! set expression to \c e.
virtual void expression(const std::string& e)
{ Mregex.expr(e); }
//! return expression
virtual std::string expression() const
{ return(Mregex.expr()); }
//! return true is \c s matches expression.
virtual bool match(const std::string s)
{
Mregex.str(s);
return (Mregex.exec());
}
private:
regexx::Regexx Mregex;
}; // class myregexxcontainer
/*======================================================================*/
// use libboost_regex
#else
/*! we need a helper class to hide the internals.
*
* delegate everything to the container class.
*/
class myregexxcontainer:
public tfxx::string::helper::regexxcontainer {
public:
//! create instance.
myregexxcontainer():
tfxx::string::helper::regexxcontainer()
{ this->expression(std::string(".*")); }
//! create instance and set expression to \c e.
myregexxcontainer(const std::string& e):
tfxx::string::helper::regexxcontainer(e)
{ this->expression(e); }
//! create instance and set expression to \c e.
virtual ~myregexxcontainer() { }
//! set expression to \c e.
virtual void expression(const std::string& e)
{ Mregex.assign(e); }
//! return expression
virtual std::string expression() const
{ return(Mregex.str()); }
//! return true is \c s matches expression.
virtual bool match(const std::string s)
{ return(boost::regex_match(s, Mregex)); }
private:
boost::regex Mregex;
}; // class myregexxcontainer
#endif
} // namespace helper
/*======================================================================*/
// common code
//! create instance.
regexx::regexx()
{ Mcontainer=new tfxx::string::helper::myregexxcontainer; }
//! create instance and set expression to \c e.
regexx::regexx(const std::string& e)
{ Mcontainer=new tfxx::string::helper::myregexxcontainer(e); }
//! remove instance.
regexx::~regexx()
{ delete(Mcontainer); }
} // namespace string
} // namespace tfxx
/* ----- END OF regexx.cc ----- */
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: regexx.h,v 1.3 2007-12-05 12:20:02 tforb Exp $
* $Id: regexx.h,v 1.4 2007-12-05 14:04:31 tforb Exp $
* \author Thomas Forbriger
* \date 05/12/2007
*
......@@ -39,7 +39,7 @@
#define TF_REGEXX_H_VERSION \
"TF_REGEXX_H V1.0"
#define TF_REGEXX_H_CVSID \
"$Id: regexx.h,v 1.3 2007-12-05 12:20:02 tforb Exp $"
"$Id: regexx.h,v 1.4 2007-12-05 14:04:31 tforb Exp $"
#include<string>
......@@ -54,18 +54,19 @@ namespace tfxx {
* delegate everything to the container class.
*/
class regexxcontainer {
//! create instance.
regexx();
//! create instance and set expression to \c e.
regexx(const std::string& e);
//! create instance and set expression to \c e.
virtual ~regexx();
//! set expression to \c e.
virtual void expression(const std::string& e);
//! return expression
virtual std::string expression() const;
//! return true is \c s matches expression.
virtual bool match(const std::string s);
public:
//! create instance.
regexxcontainer();
//! create instance and set expression to \c e.
regexxcontainer(const std::string& e);
//! create instance and set expression to \c e.
virtual ~regexxcontainer();
//! set expression to \c e.
virtual void expression(const std::string& e) =0;
//! return expression
virtual std::string expression() const =0;
//! return true is \c s matches expression.
virtual bool match(const std::string s) =0;
}; // class regexxcontainer
} // namespace helper
......@@ -84,6 +85,8 @@ namespace tfxx {
regexx();
//! create instance and set expression to \c e.
regexx(const std::string& e);
//! remove instance.
~regexx();
//! set expression to \c e.
void expression(const std::string& e)
{ Mcontainer->expression(e); }
......
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id: Makefile,v 1.12 2006-06-14 07:50:25 tforb Exp $
# $Id: Makefile,v 1.13 2007-12-05 14:04:31 tforb Exp $
#
# Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
#
......@@ -11,13 +11,13 @@
# - 19/11/2002 V1.1 provide f2c rules too for tests on AIX
# - 28/11/2002 V1.2 added blitztest
# - 28/06/2005 V1.3 disabled blitz
# - 05/12/2007 V1.4 provide test for regex
#
# ============================================================================
#
CPPFLAGS=-I$(LOCINCLUDEDIR) -I$(SERVERINCLUDEDIR) -I$(BLITZINCLUDE)
CFLAGS=-I$(LOCINCLUDEDIR) -I$(SERVERINCLUDEDIR) -I$(BLITZINCLUDE)
LDFLAGS=-L$(SERVERLIBDIR) -L$(LOCLIBDIR) -L$(BLITZLIB)
CPPFLAGS=-I$(LOCINCLUDEDIR) -I$(SERVERINCLUDEDIR)
CFLAGS=-I$(LOCINCLUDEDIR) -I$(SERVERINCLUDEDIR)
LDFLAGS=-L$(SERVERLIBDIR) -L$(LOCLIBDIR) $(TF_LINK_REGEXX)
CXXFLAGS=-Wall $(FLAGS)
#CXXFLAGS=$(FLAGS)
......@@ -47,7 +47,7 @@ clean: ;
STANDARDTEST=
# all that need the binary library
BINARYTEST=commandlinetest fortraniotest blitztest stringtest \
handletest
handletest regextest
# F77 part of the I/O test
FORTRANTEST=fortranF77
......@@ -66,8 +66,8 @@ $(addsuffix .o,$(CXXTESTS)): %.o: %.cc
$(CXX) -c -o $@ $< $(CXXFLAGS) $(CPPFLAGS) $(FLAGS)
$(STANDARDTEST): %: %.o; $(CXX) -o $@ $< $(LDFLAGS)
$(BINARYTEST): %: %.o; $(CXX) -o $@ $< $(LDFLAGS) -ltfxx
$(FORTRANTEST): %: %.o; $(CC) -o $@ $< $(LDFLAGS) -ltf -lf2c -lm
$(BINARYTEST): %: %.o; $(CXX) -o $@ $< -ltfxx $(LDFLAGS)
$(FORTRANTEST): %: %.o; $(CC) -o $@ $< -ltf $(LDFLAGS) -lf2c -lm
$(addsuffix .g77,$(FORTRANTEST)): %.g77: %.o77
$(FC) -o $@ $< $(LDFLAGS) -ltf77
......
/*! \file regextest.cc
* \brief test regex match function
*
* ----------------------------------------------------------------------------
*
* $Id: regextest.cc,v 1.1 2007-12-05 14:04:31 tforb Exp $
* \author Thomas Forbriger
* \date 05/12/2007
*
* test regex match function
*
* Copyright (c) 2007 by Thomas Forbriger (BFO Schiltach)
*
* ----
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* ----
*
* REVISIONS and CHANGES
* - 05/12/2007 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define REGEXTEST_VERSION \
"REGEXTEST V1.0 test regex match function"
#define REGEXTEST_CVSID \
"$Id: regextest.cc,v 1.1 2007-12-05 14:04:31 tforb Exp $"
#include <iostream>
#include <tfxx/commandline.h>
#include <tfxx/regexx.h>
using std::cout;
using std::cerr;
using std::endl;
int main(int iargc, char* argv[])
{
// define usage information
char usage_text[]=
{
REGEXTEST_VERSION "\n"
"usage: regextest" "\n"
" or: regextest --help|-h" "\n"
};
// define full help text
char help_text[]=
{
REGEXTEST_CVSID
"first string on command line: regular expression" "\n"
"subsequent strings will be checked against expression" "\n"
};
// define commandline options
using namespace tfxx::cmdline;
static Declare options[]=
{
// 0: print help
{"help",arg_no,"-"},
// 1: verbose mode
{"v",arg_no,"-"},
{NULL}
};
// no arguments? print usage...
if (iargc<2)
{
cerr << usage_text << endl;
exit(0);
}
// collect options from commandline
Commandline cmdline(iargc, argv, options);
// help requested? print full help text...
if (cmdline.optset(0))
{
cerr << usage_text << endl;
cerr << help_text << endl;
exit(0);
}
/*
// dummy operation: print option settings
for (int iopt=0; iopt<2; iopt++)
{
cout << "option: '" << options[iopt].opt_string << "'" << endl;
if (cmdline.optset(iopt)) { cout << " option was set"; }
else { cout << "option was not set"; }
cout << endl;
cout << " argument (string): '" << cmdline.string_arg(iopt) << "'" << endl;
cout << " argument (int): '" << cmdline.int_arg(iopt) << "'" << endl;
cout << " argument (long): '" << cmdline.long_arg(iopt) << "'" << endl;
cout << " argument (float): '" << cmdline.float_arg(iopt) << "'" << endl;
cout << " argument (double): '" << cmdline.double_arg(iopt) << "'" << endl;
cout << " argument (bool): '";
if (cmdline.bool_arg(iopt))
{ cout << "true"; } else { cout << "false"; }
cout << "'" << endl;
}
while (cmdline.extra()) { cout << cmdline.next() << endl; }
// dummy operation: print rest of command line
while (cmdline.extra()) { cout << cmdline.next() << endl; }
*/
TFXX_assert(cmdline.extra(), "missing regular expression");
tfxx::string::regexx myregex(cmdline.next());
cout << "regular expression: " << myregex.expression() << endl;
while (cmdline.extra())
{
std::string teststring(cmdline.next());
if (myregex.match(teststring))
{
cout << "matches: ";
}
else
{
cout << "does NOT match: ";
}
cout << teststring << endl;
}
}
/* ----- END OF regextest.cc ----- */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment