Commit 02c70ad4 authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

reintegrated branch

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: 5091
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent b05b8fd3
......@@ -91,7 +91,7 @@ $(call CHECKVARS,TF_BROWSER TF_WWWBASEDIR)
#HEADERS=$(shell find . -name \*.h)
DIRSTOINCLUDE= ./cmdline ./misc ./affio ./containers \
./strings ./fileio ./num
./strings ./fileio ./num ./fs
#./hacks
#./blitzio
HEADERS=$(wildcard $(addsuffix /*.h,$(DIRSTOINCLUDE)))
......@@ -99,7 +99,8 @@ 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/regextest.cc \
tests/filetest.cc tests/rangetest.cc
tests/filetest.cc tests/rangetest.cc tests/fstest.cc \
tests/exceptiontest.cc
#tests/blitztest.cc
FTESTS=$(wildcard tests/*.f)
README=$(shell find . -name README) README.xtra
......
This is a legacy version of the repository. It may be incomplete as well as
inconsistent. See README.history for details. For the old stock of the
repository copyright and licence conditions apply as specified for versions
commited after 2015-03-01. Use recent versions as a base for new development.
The legacy version is only stored to keep a record of history.
/*! \file dirname.cc
* \brief interface to dirname(3) (implementation)
*
* ----------------------------------------------------------------------------
*
* $Id$
* \author Thomas Forbriger
* \date 16/12/2012
*
* interface to dirname(3) (implementation)
*
* Copyright (c) 2012 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
* - 16/12/2012 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define TF_DIRNAME_CC_VERSION \
"TF_DIRNAME_CC V1.0"
#define TF_DIRNAME_CC_CVSID \
"$Id$"
#include <tfxx/fs.h>
#include <cstring>
#include <libgen.h>
namespace tfxx {
namespace fs {
std::string dirname(const std::string& path)
{
unsigned int n=path.length()+2;
char* p=new char[n];
std::strncpy(p, path.c_str(), n);
std::string retval(::dirname(p));
delete[] p;
return retval;
}
} // namespace fs
}
/* ----- END OF dirname.cc ----- */
/*! \file exception.cc
* \brief exception class for file system utilities (implementation)
*
* ----------------------------------------------------------------------------
*
* $Id$
* \author Thomas Forbriger
* \date 16/12/2012
*
* exception class for file system utilities (implementation)
*
* Copyright (c) 2012 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
* - 16/12/2012 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define TF_EXCEPTION_CC_VERSION \
"TF_EXCEPTION_CC V1.0 "
#define TF_EXCEPTION_CC_CVSID \
"$Id$"
#include <iostream>
#include <tfxx/fs.h>
#include <tfxx/error.h>
#include <cstring>
namespace tfxx {
namespace error {
FSException::FSException(const char* message,
const char* file,
const int& line,
const int& errno):
TBase(message, file, line, "file system utility returned error"),
Merrno(errno)
{
if (this->report_on_construct_is_true()) { this->fs_report(); }
}
void FSException::report() const
{
TBase::report();
this->fs_report();
}
void FSException::fs_report() const
{
std::cerr << " error value: " << Merrno << std::endl;
std::cerr << " " << strerror(Merrno) << std::endl;
}
} // namespace error
}
/* ----- END OF exception.cc ----- */
/*! \file fs.h
* \brief file system utilities (prototypes)
*
* ----------------------------------------------------------------------------
*
* $Id$
* \author Thomas Forbriger
* \date 16/12/2012
*
* file system utilities (prototypes)
*
* Copyright (c) 2012 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
* - 16/12/2012 V1.0 Thomas Forbriger
*
* ============================================================================
*/
// include guard
#ifndef TF_FS_H_VERSION
#define TF_FS_H_VERSION \
"TF_FS_H V1.0 "
#define TF_FS_H_CVSID \
"$Id$"
#include<string>
#include<tfxx/error.h>
/*! \defgroup group_fs File system utilities.
*
* \brief An interface to libc file system functions.
*
* The module is presented in namespace tfxx::fs.
* You will find an example in tests/fstest.cc.
*
* \sa group_fs_h
*
*/
/*! \brief Interface provided through fs.h
*
* \defgroup group_fs_h Interface provided through fs.h
*
* \ingroup group_fs
*/
namespace tfxx {
namespace error {
/*! \brief exception class for file system utilities
*
* \ingroup group_fs, group_fs_h
* \sa TFXX_Xassert
* \sa tfxx::error::Exception
*/
class FSException: public tfxx::error::Exception
{
public:
//! base class
typedef tfxx::error::Exception TBase;
//! Create with message, failed assertion, and code position
FSException(const char* message,
const char* file,
const int& line,
const int& errno);
//! provide explicit virtual destructor
virtual ~FSException() { }
//! Screen report
virtual void report() const;
//! true, if exception reports error errno
bool iserrno(const int& errno) const { return (errno==Merrno); }
private:
//! my report
void fs_report() const;
//! error number
int Merrno;
}; // class exception
} // namespace error
/*! \brief Namespace for all file system utilities.
*
* \ingroup group_fs
* \sa group_fs
* \sa group_fs_h
*/
namespace fs {
/*----------------------------------------------------------------------*/
// functions
/*! \brief return path with its last non-slash component removed
*
* \ingroup group_fs
* C++ interface to dirname(3)
*/
std::string dirname(const std::string& path);
/*! \brief create a directory
*
* \ingroup group_fs
* C++ interface to mkdir(2)
*/
void mkdir(const std::string& path);
/*! \brief create a directory with all parents
*
* \ingroup group_fs
* C++ interface to mkdir(2)
*/
void mkdirp(const std::string& path);
} // namespace fs
} // namespace tfxx
#endif // TF_FS_H_VERSION (includeguard)
/* ----- END OF fs.h ----- */
/*! \file mkdir.cc
* \brief interface to mkdir(2) (implementation)
*
* ----------------------------------------------------------------------------
*
* $Id$
* \author Thomas Forbriger
* \date 16/12/2012
*
* interface to mkdir(2) (implementation)
*
* Copyright (c) 2012 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
* - 16/12/2012 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define TF_MKDIR_CC_VERSION \
"TF_MKDIR_CC V1.0 "
#define TF_MKDIR_CC_CVSID \
"$Id$"
#include <tfxx/fs.h>
#include <sys/stat.h>
#include <errno.h>
namespace tfxx {
namespace fs {
void mkdir(const std::string& path)
{
int status;
status=::mkdir(path.c_str(),
S_IRUSR | S_IWUSR | S_IXUSR |
S_IRGRP | S_IWGRP | S_IXGRP |
S_IROTH | S_IWOTH | S_IXOTH);
int errsv=errno;
if (status != 0)
{
throw tfxx::error::FSException("mkdir() failed",
__FILE__, __LINE__, errsv);
}
}
} // namespace fs
}
/* ----- END OF mkdir.cc ----- */
/*! \file mkdirp.cc
* \brief create a complete path (implementation)
*
* ----------------------------------------------------------------------------
*
* $Id$
* \author Thomas Forbriger
* \date 16/12/2012
*
* create a complete path (implementation)
*
* Copyright (c) 2012 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
* - 16/12/2012 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define TF_MKDIRP_CC_VERSION \
"TF_MKDIRP_CC V1.0 "
#define TF_MKDIRP_CC_CVSID \
"$Id$"
#include <tfxx/fs.h>
#include <errno.h>
namespace tfxx {
namespace fs {
void mkdirp(const std::string& path)
{
tfxx::error::Exception::dont_report_on_construct();
try {
tfxx::fs::mkdir(path);
} catch (const tfxx::error::FSException& e) {
if (!e.iserrno(ENOENT))
{
e.report();
throw(e);
}
std::string dir=tfxx::fs::dirname(path);
if (dir == path)
{
e.report();
throw(e);
}
else
{
// std::cerr << "going to create " << dir << std::endl;
tfxx::fs::mkdirp(dir);
// std::cerr << "retry to create " << path << std::endl;
tfxx::fs::mkdir(path);
}
} catch (tfxx::error::Exception& e) {
e.report();
throw(e);
}
tfxx::error::Exception::restore_report_state();
} // void mkdirp(const std::string& path)
} // namespace fs
}
/* ----- END OF mkdirp.cc ----- */
......@@ -48,29 +48,30 @@ namespace error {
//! initialize and instantiate
bool Exception::Mreport_on_construct=true;
std::stack<bool> Exception::Mprevious_report_state;
//! construct from nothing
Exception::Exception():
Mmessage(NULL), Mfile(NULL), Mline(0), Mcondition(NULL)
{ if (Mreport_on_construct) { report(); } }
{ if (this->report_on_construct_is_true()) { base_report(); } }
//! construct with message
Exception::Exception(const char* message):
Mmessage(message), Mfile(NULL), Mline(0), Mcondition(NULL)
{ if (Mreport_on_construct) { report(); } }
{ if (this->report_on_construct_is_true()) { base_report(); } }
//! construct with message and file info
Exception::Exception(const char* message,
const char* condition):
Mmessage(message), Mfile(NULL), Mline(0), Mcondition(condition)
{ if (Mreport_on_construct) { report(); } }
{ if (this->report_on_construct_is_true()) { base_report(); } }
//! construct with message and file info
Exception::Exception(const char* message,
const char* file,
const int& line):
Mmessage(message), Mfile(file), Mline(line), Mcondition(NULL)
{ if (Mreport_on_construct) { report(); } }
{ if (this->report_on_construct_is_true()) { base_report(); } }
//! construct with message and file info and condition
Exception::Exception(const char* message,
......@@ -78,18 +79,30 @@ namespace error {
const int& line,
const char* condition):
Mmessage(message), Mfile(file), Mline(line), Mcondition(condition)
{ if (Mreport_on_construct) { report(); } }
{ if (this->report_on_construct_is_true()) { base_report(); } }
//! switch on
void Exception::report_on_construct()
{
Mreport_on_construct=true;
Mprevious_report_state.push(Mreport_on_construct);
Mreport_on_construct=true;
}
//! switch off
void Exception::dont_report_on_construct()
{
Mreport_on_construct=false;
Mprevious_report_state.push(Mreport_on_construct);
Mreport_on_construct=false;
}
//! restore
void Exception::restore_report_state()
{
if (!Mprevious_report_state.empty())
{
Mreport_on_construct=Mprevious_report_state.top();
Mprevious_report_state.pop();
}
}
//! report
......
......@@ -44,6 +44,8 @@
#define TF_ERROR_H_CVSID \
"$Id$"
#include<stack>
namespace tfxx {
/*! \defgroup group_error Error handling module
......@@ -101,6 +103,11 @@ namespace error {
static void report_on_construct();
//! Issue NO screen report on construction of exception
static void dont_report_on_construct();
//! Restore previous report state
static void restore_report_state();
protected:
bool report_on_construct_is_true() const
{ return Mreport_on_construct; }
private:
//! Screen report
void base_report() const;
......@@ -111,9 +118,11 @@ namespace error {
//! pointer to file name string
const char* Mfile;
//! pointer to line number in source file
const int& Mline;
int Mline;
//! pointer to assertion condition text string
const char* Mcondition;
//! a place to store previous report state
static std::stack<bool> Mprevious_report_state;
}; // class exception
} // namespace error
......
......@@ -48,7 +48,7 @@ clean: ;
STANDARDTEST=
# all that need the binary library
BINARYTEST=commandlinetest fortraniotest blitztest stringtest \
handletest regextest filetest rangetest
handletest regextest filetest rangetest fstest exceptiontest
# F77 part of the I/O test
FORTRANTEST=fortranF77
......@@ -104,4 +104,5 @@ fortraniotestintel: fortranF77.g77 fortraniotest
fortraniotest%.out:
$(MAKE) $(patsubst %.out,%,$@) > $@ 2>&1
# ----- END OF Makefile -----
/*! \file exceptiontest.cc
* \brief test exception classes
*
* ----------------------------------------------------------------------------
*
* $Id$
* \author Thomas Forbriger
* \date 17/12/2012
*
* test exception classes
*
* Copyright (c) 2012 by Thomas Forbriger (BFO Schiltach)
*
* REVISIONS and CHANGES
* - 17/12/2012 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define EXCEPTIONTEST_VERSION \
"EXCEPTIONTEST V1.0 test exception classes"
#define EXCEPTIONTEST_CVSID \
"$Id$"
#include <iostream>
#include <tfxx/commandline.h>
#include <tfxx/error.h>
#include <tfxx/fs.h>
using std::cout;
using std::cerr;
using std::endl;
/*======================================================================*/
void throwb()
{
throw tfxx::error::FSException("simulate fs error",
__FILE__, __LINE__, 5);
}
void throwa()
{
TFXX_abort("abort anyway");
}
class A {
public:
A(const bool& throwbase): Mtb(throwbase) { }
void setflag(const bool& tb) { Mtb=tb; }
void throwit() const
{
if (Mtb)
{
throwa();