Commit 95e19acb authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

provides now file specific options

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: 1763
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 8b8d0fed
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id: Makefile,v 1.15 2003-06-24 19:13:46 tforb Exp $
# $Id: Makefile,v 1.16 2005-06-28 10:51:12 tforb Exp $
#
# Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
#
......@@ -26,11 +26,20 @@
# ============================================================================
#
HEADERS=$(shell find . -name \*.h)
#HEADERS=$(shell find . -name \*.h)
HEADERS=misc/range.h misc/xcmdline.h misc/error.h misc/commandline.h \
misc/complexio.h misc/misc.h misc/fortranio.h
#misc/blitzfortranio.h
#misc/blitzutil.h
#hacks/hack_blitztogrepg.h
#hacks/hack_blitztotable.h
#SRC=misc/fortranio.cc misc/commandline.cc misc/ioswap.cc misc/error.cc \
# misc/blitzfortranio.cc hacks/hack_blitztogrepg.cc
SRC=misc/fortranio.cc misc/commandline.cc misc/ioswap.cc misc/error.cc
TESTS=$(filter-out tests/blitztest,$(wildcard tests/*.cc))
SRC=misc/fortranio.cc misc/commandline.cc misc/ioswap.cc misc/error.cc \
misc/xcmdline.cc
#TESTS=$(filter-out tests/blitztest,$(wildcard tests/*.cc))
TESTS=tests/commandlinetest.cc tests/fortraniotest.cc
#tests/blitztest.cc
FTESTS=$(wildcard tests/*.f)
README=$(shell find . -name README) README.xtra
......@@ -162,5 +171,9 @@ tests/%: tests/%.f
tests/%.run: tests/%
cd tests; echo "#############################"; $(MAKE) $(notdir $@)
tests/%.remake:
/bin/rm -fv $(patsubst %.remake,%,$@)
/bin/rm -fv $(patsubst %.remake,%.o,$@)
$(MAKE) $(patsubst %.remake,%,$@)
# ----- END OF Makefile -----
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: commandline.h,v 1.4 2002-11-20 15:19:25 forbrig Exp $
* $Id: commandline.h,v 1.5 2005-06-28 10:51:13 tforb Exp $
*
* \date 12/01/2002
* \author Thomas Forbriger
......@@ -23,8 +23,9 @@
#ifndef TF_COMMANDLINE_H_
//! $Id: newclass,v 1.2 2000/10/13 09:16:32 forbrig Exp 3
#define TF_COMMANDLINE_H_ \
"$Id: commandline.h,v 1.4 2002-11-20 15:19:25 forbrig Exp $";
"$Id: commandline.h,v 1.5 2005-06-28 10:51:13 tforb Exp $";
#include <iostream>
#include <string>
namespace tfxx {
......
/*! \file xcmdline.cc
* \brief parse extra commandline values (implementation)
*
* ----------------------------------------------------------------------------
*
* $Id: xcmdline.cc,v 1.1 2005-06-28 10:51:13 tforb Exp $
* \author Thomas Forbriger
* \date 28/06/2005
*
* parse extra commandline values (implementation)
*
* Copyright (c) 2005 by Thomas Forbriger (BFO Schiltach)
*
* REVISIONS and CHANGES
* - 28/06/2005 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define TF_XCMDLINE_CC_VERSION \
"TF_XCMDLINE_CC V1.0 "
#define TF_XCMDLINE_CC_CVSID \
"$Id: xcmdline.cc,v 1.1 2005-06-28 10:51:13 tforb Exp $"
#include <tfxx/xcmdline.h>
namespace tfxx {
namespace cmdline {
namespace helper {
typedef std::list<std::string> Tkeylist;
class CmdlineArgument {
public:
CmdlineArgument(const std::string& arg,
const Tkeylist& keys);
bool isoption() const { return(Misoption); }
std::string value() const { return(Mvalue); }
FileOption option() const { return(Moption); }
private:
std::string Mvalue;
FileOption Moption;
bool Misoption;
}; // class CmdlineArgument
CmdlineArgument::CmdlineArgument(const std::string& arg,
const Tkeylist& keys)
{
Mvalue=arg;
Misoption=false;
helper::Tkeylist::const_iterator i=keys.begin();
// std::cout << Mvalue << std::endl;
while ((i!=keys.end()) && (!Misoption))
{
// std::cout << *i << " " << Mvalue.find(*i) << std::endl;
if (Mvalue.find(*i) == 0)
{
Misoption=true;
Moption.key=*i;
Moption.value=Mvalue.substr(Moption.key.size());
}
++i;
}
} // CmdlineArgument constructor
} // namespace helper
/*======================================================================*/
Tparsed parse_cmdline(tfxx::cmdline::Commandline& c,
const char** keys,
const bool& debug)
{
// fill a search list
// ------------------
helper::Tkeylist keylist;
const char* key=*keys;
while (key != NULL)
{
std::string keystring(key);
keylist.push_back(keystring+":");
++keys;
key=*keys;
}
// report search list if requested
if (debug)
{
std::cout << "DEBUG (parse_cmdline): keys are ";
helper::Tkeylist::const_iterator i=keylist.begin();
while (i!=keylist.end())
{
std::cout << "\"" << *i << "\" ";
++i;
}
std::cout << std::endl;
}
// parse rest of command line
// --------------------------
Tparsed retval;
Filename filename;
bool first=true;
while (c.extra())
{
helper::CmdlineArgument ca(c.next(), keylist);
if (first)
{
first=false;
filename.name=ca.value();
}
else
{
if (ca.isoption())
{
filename.options.push_back(ca.option());
}
else
{
retval.push_back(filename);
filename.options.clear();
filename.name=ca.value();
}
}
}
if (!first) { retval.push_back(filename); }
return(retval);
}
} // namespace cmdline
} // namespace tfxx
/* ----- END OF xcmdline.cc ----- */
/*! \file xcmdline.h
* \brief parse extra commandline values (prototypes)
*
* ----------------------------------------------------------------------------
*
* $Id: xcmdline.h,v 1.1 2005-06-28 10:51:13 tforb Exp $
* \author Thomas Forbriger
* \date 28/06/2005
*
* parse extra commandline values (prototypes)
*
* Copyright (c) 2005 by Thomas Forbriger (BFO Schiltach)
*
* REVISIONS and CHANGES
* - 28/06/2005 V1.0 Thomas Forbriger
*
* ============================================================================
*/
// include guard
#ifndef TF_XCMDLINE_H_VERSION
#define TF_XCMDLINE_H_VERSION \
"TF_XCMDLINE_H V1.0 "
#define TF_XCMDLINE_H_CVSID \
"$Id: xcmdline.h,v 1.1 2005-06-28 10:51:13 tforb Exp $"
#include <tfxx/commandline.h>
#include <string>
#include <list>
namespace tfxx {
namespace cmdline {
struct FileOption {
std::string key;
std::string value;
}; // struct FileOption
typedef std::list<FileOption> Toptionlist;
struct Filename {
std::string name;
Toptionlist options;
}; // struct Filename
/*!
*
* in case you want pass options in the form
*
* filename f:option1 dl:option2 k:option3
*
* you should generate keys of the form
*
* static const char* keys[]={"f", "dl", "k", 0};
*/
typedef std::list<Filename> Tparsed;
Tparsed parse_cmdline(tfxx::cmdline::Commandline& c,
const char** keys,
const bool& debug=false);
} // namespace cmdline
} // namespace tfxx
#endif // TF_XCMDLINE_H_VERSION (includeguard)
/* ----- END OF xcmdline.h ----- */
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id: Makefile,v 1.7 2002-11-28 21:34:08 forbrig Exp $
# $Id: Makefile,v 1.8 2005-06-28 10:51:13 tforb Exp $
#
# Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
#
......@@ -10,6 +10,7 @@
# - 15/11/2002 V1.0 Thomas Forbriger
# - 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
#
# ============================================================================
#
......@@ -64,7 +65,7 @@ $(addsuffix .o,$(CXXTESTS)): %.o: %.cc
$(CXX) -c -o $@ $< $(CXXFLAGS) $(CPPFLAGS) $(FLAGS)
$(STANDARDTEST): %: %.o; $(CXX) -o $@ $< $(LDFLAGS)
$(BINARYTEST): %: %.o; $(CXX) -o $@ $< $(LDFLAGS) -ltfxx -lblitz
$(BINARYTEST): %: %.o; $(CXX) -o $@ $< $(LDFLAGS) -ltfxx
$(FORTRANTEST): %: %.o; $(CC) -o $@ $< $(LDFLAGS) -ltf -lf2c -lm
$(addsuffix .g77,$(FORTRANTEST)): %.g77: %.o77
$(FC) -o $@ $< $(LDFLAGS) -ltf77
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: commandlinetest.cc,v 1.3 2002-11-20 15:19:26 forbrig Exp $
* $Id: commandlinetest.cc,v 1.4 2005-06-28 10:51:14 tforb Exp $
* \author Thomas Forbriger
* \date 15/11/2002
*
......@@ -19,10 +19,11 @@
#define COMMANDLINETEST_VERSION \
"COMMANDLINETEST V1.0 test commandline class"
#define COMMANDLINETEST_CVSID \
"$Id: commandlinetest.cc,v 1.3 2002-11-20 15:19:26 forbrig Exp $"
"$Id: commandlinetest.cc,v 1.4 2005-06-28 10:51:14 tforb Exp $"
#include <iostream>
#include <tfxx/commandline.h>
#include <tfxx/xcmdline.h>
using std::cout;
using std::cerr;
......@@ -45,7 +46,7 @@ int main(int iargc, char* argv[])
{
COMMANDLINETEST_VERSION "\n"
"usage: commandlinetest argument [-v] [-o n] [-f name] [-q [r]]" "\n"
" [-longopt f] [value [value ...]]" "\n"
" [-longopt f] [-F] [value [value ...]]" "\n"
" or: commandlinetest --help|-h" "\n"
};
......@@ -61,6 +62,8 @@ int main(int iargc, char* argv[])
"-f name set a string value (argument mandatory)" "\n"
"-q r set an integer value (argument optional)" "\n"
"-longopt f set the value for a long option name" "\n"
"-F evaluate file name options" "\n"
" availabe keys are: \"f\", \"dl\", \"k\"" "\n"
" " "\n"
"Long options may be abbreviated - test it!" "\n"
" " "\n"
......@@ -91,9 +94,14 @@ int main(int iargc, char* argv[])
{"q",arg_opt,"10.5"},
// 5: verbose mode
{"longopt",arg_yes,"default"},
// 6: evaluate filename options
{"F",arg_no,"-"},
{NULL}
};
// define filename options
static const char* keys[]={"f", "dl", "k", 0};
// no arguments? print usage...
if (iargc<2)
{
......@@ -156,10 +164,40 @@ int main(int iargc, char* argv[])
else { cout << " default:"; }
cout << " -longopt: '" << cmdline.string_arg(5) << "'" << endl;
// dummy operation: print rest of command line
cout << endl;
cout << "And here is the rest of your command line arguments:" << endl;
while (cmdline.extra()) { cout << cmdline.next() << endl; }
if (!cmdline.optset(6))
{
// dummy operation: print rest of command line
cout << endl;
cout << "And here is the rest of your command line arguments:" << endl;
while (cmdline.extra()) { cout << cmdline.next() << endl; }
}
else
{
cout << endl;
cout << "Parse file names and options" << endl;
cout << "Supported options keys are:" << endl;
const char** thekeys=keys;
const char* key=*thekeys;
while (key != NULL)
{
std::cout << " next key is: \"" << key << "\"" << std::endl;
++thekeys;
key=*thekeys;
}
Tparsed result=parse_cmdline(cmdline, keys, cmdline.optset(1));
Tparsed::const_iterator i=result.begin();
while(i!=result.end())
{
std::cout << "filename: \"" << i->name << "\"" << std::endl;
Toptionlist::const_iterator j=i->options.begin();
while(j!=i->options.end())
{
std::cout << " " << j->key << " \"" << j->value << "\"" << std::endl;
++j;
}
++i;
}
}
}
/* ----- END OF commandlinetest.cc ----- */
Supports Markdown
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