Commit 82ba12a1 authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

proceeding

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.
changed concept for commandline parser:
now uses a multimap


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 1829
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 28a7305a
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: xcmdline.cc,v 1.1 2005-06-28 10:51:13 tforb Exp $
* $Id: xcmdline.cc,v 1.2 2005-07-07 07:52:07 tforb Exp $
* \author Thomas Forbriger
* \date 28/06/2005
*
......@@ -19,7 +19,7 @@
#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 $"
"$Id: xcmdline.cc,v 1.2 2005-07-07 07:52:07 tforb Exp $"
#include <tfxx/xcmdline.h>
......@@ -36,10 +36,10 @@ namespace tfxx {
const Tkeylist& keys);
bool isoption() const { return(Misoption); }
std::string value() const { return(Mvalue); }
FileOption option() const { return(Moption); }
Tfileoption option() const { return(Moption); }
private:
std::string Mvalue;
FileOption Moption;
Tfileoption Moption;
bool Misoption;
}; // class CmdlineArgument
......@@ -56,8 +56,8 @@ namespace tfxx {
if (Mvalue.find(*i) == 0)
{
Misoption=true;
Moption.key=*i;
Moption.value=Mvalue.substr(Moption.key.size());
Moption.first = i->substr(0, i->size()-1);
Moption.second= Mvalue.substr(Moption.first.size()+1);
}
++i;
}
......@@ -65,7 +65,7 @@ namespace tfxx {
} // namespace helper
/*======================================================================*/
/*----------------------------------------------------------------------*/
Tparsed parse_cmdline(tfxx::cmdline::Commandline& c,
const char** keys,
......@@ -112,7 +112,7 @@ namespace tfxx {
{
if (ca.isoption())
{
filename.options.push_back(ca.option());
filename.options.insert(ca.option());
}
else
{
......@@ -125,9 +125,32 @@ namespace tfxx {
if (!first) { retval.push_back(filename); }
return(retval);
} // parse_cmdline
/*======================================================================*/
Toptionmap Filename::extract(const std::string& key) const
{
typedef Toptionmap::const_iterator Tomi;
typedef std::pair<Tomi, Tomi> Tomipair;
Tomipair equalrange=options.equal_range(key);
Toptionmap retval(equalrange.first, equalrange.second);
return retval;
}
/*----------------------------------------------------------------------*/
std::string Filename::value(const std::string& key) const
{
std::string retval;
Toptionmap::const_iterator p=options.find(key);
if (p != options.end())
{ retval=p->second; }
return retval;
} // Filename::value
} // namespace cmdline
} // namespace tfxx
/* ----- END OF xcmdline.cc ----- */
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: xcmdline.h,v 1.1 2005-06-28 10:51:13 tforb Exp $
* $Id: xcmdline.h,v 1.2 2005-07-07 07:52:07 tforb Exp $
* \author Thomas Forbriger
* \date 28/06/2005
*
......@@ -23,28 +23,36 @@
#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 $"
"$Id: xcmdline.h,v 1.2 2005-07-07 07:52:07 tforb Exp $"
#include <tfxx/commandline.h>
#include <string>
#include <map>
#include <list>
namespace tfxx {
namespace cmdline {
struct FileOption {
std::string key;
std::string value;
}; // struct FileOption
typedef std::pair<std::string, std::string> Tfileoption;
typedef std::list<FileOption> Toptionlist;
typedef std::multimap<std::string, std::string> Toptionmap;
struct Filename {
std::string name;
Toptionlist options;
Toptionmap options;
//! return all entries for a given key
Toptionmap extract(const std::string& key) const;
//! return values for option with given key
std::string value(const std::string& key) const;
//! number of entries for key
Toptionmap::size_type count(const std::string& key) const
{ return options.count(key); }
//! tell if the key is present
bool haskey(const std::string& key) const
{ return (this->count(key) > 0); }
}; // struct Filename
/*!
/*! \brief parse command line arguments for file names and options
*
* in case you want pass options in the form
*
......@@ -58,8 +66,9 @@ namespace tfxx {
Tparsed parse_cmdline(tfxx::cmdline::Commandline& c,
const char** keys,
const bool& debug=false);
} // namespace cmdline
} // namespace tfxx
#endif // TF_XCMDLINE_H_VERSION (includeguard)
......
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id: Makefile,v 1.10 2005-07-04 13:06:10 tforb Exp $
# $Id: Makefile,v 1.11 2005-07-07 07:52:07 tforb Exp $
#
# Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
#
......@@ -17,8 +17,8 @@
CPPFLAGS=-I$(LOCINCLUDEDIR) -I$(SERVERINCLUDEDIR) -I$(BLITZINCLUDE)
LDFLAGS=-L$(SERVERLIBDIR) -L$(LOCLIBDIR) -L$(BLITZLIB)
CXXFLAGS=-fhonor-std -Wall $(FLAGS)
CXXFLAGS=$(FLAGS)
CXXFLAGS=-Wall $(FLAGS)
#CXXFLAGS=$(FLAGS)
FC=g77
FCFLAGS=-Wall -ffixed-line-length-0 -fno-backslash
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: commandlinetest.cc,v 1.4 2005-06-28 10:51:14 tforb Exp $
* $Id: commandlinetest.cc,v 1.5 2005-07-07 07:52:07 tforb Exp $
* \author Thomas Forbriger
* \date 15/11/2002
*
......@@ -19,7 +19,7 @@
#define COMMANDLINETEST_VERSION \
"COMMANDLINETEST V1.0 test commandline class"
#define COMMANDLINETEST_CVSID \
"$Id: commandlinetest.cc,v 1.4 2005-06-28 10:51:14 tforb Exp $"
"$Id: commandlinetest.cc,v 1.5 2005-07-07 07:52:07 tforb Exp $"
#include <iostream>
#include <tfxx/commandline.h>
......@@ -189,12 +189,35 @@ int main(int iargc, char* argv[])
while(i!=result.end())
{
std::cout << "filename: \"" << i->name << "\"" << std::endl;
Toptionlist::const_iterator j=i->options.begin();
Toptionmap::const_iterator j=i->options.begin();
while(j!=i->options.end())
{
std::cout << " " << j->key << " \"" << j->value << "\"" << std::endl;
std::cout << " " << j->first
<< " \"" << j->second << "\"" << std::endl;
++j;
}
const char ** k=keys;
while (*k != NULL)
{
if (i->haskey(*k))
{
std::cout << " key " << *k << ": found " << i->count(*k)
<< " entries" << std::endl;
std::cout << " first entry is \"" << i->value(*k) <<
"\"" << std::endl;
Toptionmap e=i->extract(*k);
std::cout << " all entries are:" << std::endl;
Toptionmap::const_iterator p=e.begin();
while(p != e.end())
{
std::cout << " \"" << p->second << "\"" << std::endl;
++p;
}
}
++k;
key=*thekeys;
}
// next filename
++i;
}
}
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: tidofi.cc,v 1.3 2005-07-06 14:10:03 tforb Exp $
* $Id: tidofi.cc,v 1.4 2005-07-07 07:52:08 tforb Exp $
* \author Thomas Forbriger
* \date 17/02/2004
*
......@@ -19,7 +19,7 @@
#define TIDOFI_VERSION \
"TIDOFI V1.0 time domain filter"
#define TIDOFI_CVSID \
"$Id: tidofi.cc,v 1.3 2005-07-06 14:10:03 tforb Exp $"
"$Id: tidofi.cc,v 1.4 2005-07-07 07:52:08 tforb Exp $"
#include <iostream>
#include <fstream>
......@@ -226,26 +226,43 @@ int main(int iargc, char* argv[])
filefree.append(TIDOFI_VERSION);
filefree.append(TIDOFI_CVSID);
std::string line;
line="commands are read from";
if (opt.readstdin)
if (opt.readcommandfile || opt.readstdin)
{
line += " stdin";
if (opt.readcommandfile)
line="commands are read from";
if (opt.readstdin)
{
line += " (first) and";
line += " stdin";
if (opt.readcommandfile)
{
line += " (first) and";
}
else
{
line += ":";
}
}
filefree.append(line);
line.clear();
if (opt.readcommandfile)
{
line += "file \"" + opt.commandfile + "\":";
filefree.append(line);
}
if (filtercommands.lines.size() > 0)
{
filefree.append(filtercommands);
}
else
{
filefree.append(" command list is empty!");
}
}
filefree.append(line);
line.clear();
if (opt.readcommandfile)
else
{
line += "file \"" + opt.commandfile + "\"";
filefree.append(line);
filefree.append("no filtercommands were read");
}
filefree.append("read commands:");
filefree.append(filtercommands);
filefree.append("output file name:");
filefree.append(outfile);
filefree.append(" " + outfile);
filefree.append("input file selection:");
tfxx::cmdline::Tparsed::const_iterator file=arguments.begin();
while (file != arguments.end())
......@@ -260,8 +277,66 @@ int main(int iargc, char* argv[])
}
if (line.size()>2) { filefree.append(line); }
++file;
}
if (arguments.size()>1)
{
filefree.append("In cases where more than one input file is read,");
filefree.append("the SRCE line is taken from the first file only (if");
filefree.append("present there).");
}
}
/*======================================================================*/
// start processing
// open output file
// ----------------
if (opt.verbose) { cout << "open output file " << outfile << endl; }
// check if output file exists and open
if (!opt.overwrite)
{
std::ifstream file(outfile.c_str(),std::ios_base::in);
TFXX_assert((!file.good()),"ERROR: output file exists!");
}
std::ofstream ofs(outfile.c_str());
sff::SFFostream<Tseries> os(ofs, opt.debug);
// set flag to process header of first input file
bool firstfile=true;
// cycle through all input files
// -----------------------------
tfxx::cmdline::Tparsed::const_iterator infile=arguments.begin();
while (infile != arguments.end())
{
// open input file
if (opt.verbose) { cout << "open input file " << infile->name << endl; }
std::ifstream ifs(infile->name.c_str());
datread::ianystream is(ifs, datread::anyID(opt.inputformat));
// handle file header
if (firstfile)
{
if (is.hasfree())
{
sff::FREE infilefree;
is >> infilefree;
filefree.append("block read from first input file:");
filefree.append(infilefree);
}
os << filefree;
is (is.hassrce())
{
sff::SRCE insrceline;
is >> insrceline;
os << insrceline;
}
}
// cycle through traces of input file
// ----------------------------------
firstfile=false;
++infile;
}
cout << filefree;
}
......
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