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 @@ ...@@ -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 * \author Thomas Forbriger
* \date 28/06/2005 * \date 28/06/2005
* *
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#define TF_XCMDLINE_CC_VERSION \ #define TF_XCMDLINE_CC_VERSION \
"TF_XCMDLINE_CC V1.0 " "TF_XCMDLINE_CC V1.0 "
#define TF_XCMDLINE_CC_CVSID \ #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> #include <tfxx/xcmdline.h>
...@@ -36,10 +36,10 @@ namespace tfxx { ...@@ -36,10 +36,10 @@ namespace tfxx {
const Tkeylist& keys); const Tkeylist& keys);
bool isoption() const { return(Misoption); } bool isoption() const { return(Misoption); }
std::string value() const { return(Mvalue); } std::string value() const { return(Mvalue); }
FileOption option() const { return(Moption); } Tfileoption option() const { return(Moption); }
private: private:
std::string Mvalue; std::string Mvalue;
FileOption Moption; Tfileoption Moption;
bool Misoption; bool Misoption;
}; // class CmdlineArgument }; // class CmdlineArgument
...@@ -56,8 +56,8 @@ namespace tfxx { ...@@ -56,8 +56,8 @@ namespace tfxx {
if (Mvalue.find(*i) == 0) if (Mvalue.find(*i) == 0)
{ {
Misoption=true; Misoption=true;
Moption.key=*i; Moption.first = i->substr(0, i->size()-1);
Moption.value=Mvalue.substr(Moption.key.size()); Moption.second= Mvalue.substr(Moption.first.size()+1);
} }
++i; ++i;
} }
...@@ -65,7 +65,7 @@ namespace tfxx { ...@@ -65,7 +65,7 @@ namespace tfxx {
} // namespace helper } // namespace helper
/*======================================================================*/ /*----------------------------------------------------------------------*/
Tparsed parse_cmdline(tfxx::cmdline::Commandline& c, Tparsed parse_cmdline(tfxx::cmdline::Commandline& c,
const char** keys, const char** keys,
...@@ -112,7 +112,7 @@ namespace tfxx { ...@@ -112,7 +112,7 @@ namespace tfxx {
{ {
if (ca.isoption()) if (ca.isoption())
{ {
filename.options.push_back(ca.option()); filename.options.insert(ca.option());
} }
else else
{ {
...@@ -125,9 +125,32 @@ namespace tfxx { ...@@ -125,9 +125,32 @@ namespace tfxx {
if (!first) { retval.push_back(filename); } if (!first) { retval.push_back(filename); }
return(retval); 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 cmdline
} // namespace tfxx } // namespace tfxx
/* ----- END OF xcmdline.cc ----- */ /* ----- END OF xcmdline.cc ----- */
...@@ -3,7 +3,7 @@ ...@@ -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 * \author Thomas Forbriger
* \date 28/06/2005 * \date 28/06/2005
* *
...@@ -23,28 +23,36 @@ ...@@ -23,28 +23,36 @@
#define TF_XCMDLINE_H_VERSION \ #define TF_XCMDLINE_H_VERSION \
"TF_XCMDLINE_H V1.0 " "TF_XCMDLINE_H V1.0 "
#define TF_XCMDLINE_H_CVSID \ #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 <tfxx/commandline.h>
#include <string> #include <string>
#include <map>
#include <list> #include <list>
namespace tfxx { namespace tfxx {
namespace cmdline { namespace cmdline {
struct FileOption { typedef std::pair<std::string, std::string> Tfileoption;
std::string key;
std::string value;
}; // struct FileOption
typedef std::list<FileOption> Toptionlist; typedef std::multimap<std::string, std::string> Toptionmap;
struct Filename { struct Filename {
std::string name; 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 }; // struct Filename
/*! /*! \brief parse command line arguments for file names and options
* *
* in case you want pass options in the form * in case you want pass options in the form
* *
...@@ -58,8 +66,9 @@ namespace tfxx { ...@@ -58,8 +66,9 @@ namespace tfxx {
Tparsed parse_cmdline(tfxx::cmdline::Commandline& c, Tparsed parse_cmdline(tfxx::cmdline::Commandline& c,
const char** keys, const char** keys,
const bool& debug=false); const bool& debug=false);
} // namespace cmdline } // namespace cmdline
} // namespace tfxx } // namespace tfxx
#endif // TF_XCMDLINE_H_VERSION (includeguard) #endif // TF_XCMDLINE_H_VERSION (includeguard)
......
# this is <Makefile> # 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) # Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
# #
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
CPPFLAGS=-I$(LOCINCLUDEDIR) -I$(SERVERINCLUDEDIR) -I$(BLITZINCLUDE) CPPFLAGS=-I$(LOCINCLUDEDIR) -I$(SERVERINCLUDEDIR) -I$(BLITZINCLUDE)
LDFLAGS=-L$(SERVERLIBDIR) -L$(LOCLIBDIR) -L$(BLITZLIB) LDFLAGS=-L$(SERVERLIBDIR) -L$(LOCLIBDIR) -L$(BLITZLIB)
CXXFLAGS=-fhonor-std -Wall $(FLAGS) CXXFLAGS=-Wall $(FLAGS)
CXXFLAGS=$(FLAGS) #CXXFLAGS=$(FLAGS)
FC=g77 FC=g77
FCFLAGS=-Wall -ffixed-line-length-0 -fno-backslash FCFLAGS=-Wall -ffixed-line-length-0 -fno-backslash
......
...@@ -3,7 +3,7 @@ ...@@ -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 * \author Thomas Forbriger
* \date 15/11/2002 * \date 15/11/2002
* *
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#define COMMANDLINETEST_VERSION \ #define COMMANDLINETEST_VERSION \
"COMMANDLINETEST V1.0 test commandline class" "COMMANDLINETEST V1.0 test commandline class"
#define COMMANDLINETEST_CVSID \ #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 <iostream>
#include <tfxx/commandline.h> #include <tfxx/commandline.h>
...@@ -189,12 +189,35 @@ int main(int iargc, char* argv[]) ...@@ -189,12 +189,35 @@ int main(int iargc, char* argv[])
while(i!=result.end()) while(i!=result.end())
{ {
std::cout << "filename: \"" << i->name << "\"" << std::endl; 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()) while(j!=i->options.end())
{ {
std::cout << " " << j->key << " \"" << j->value << "\"" << std::endl; std::cout << " " << j->first
<< " \"" << j->second << "\"" << std::endl;
++j; ++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; ++i;
} }
} }
......
...@@ -3,7 +3,7 @@ ...@@ -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 * \author Thomas Forbriger
* \date 17/02/2004 * \date 17/02/2004
* *
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#define TIDOFI_VERSION \ #define TIDOFI_VERSION \
"TIDOFI V1.0 time domain filter" "TIDOFI V1.0 time domain filter"
#define TIDOFI_CVSID \ #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 <iostream>
#include <fstream> #include <fstream>
...@@ -226,26 +226,43 @@ int main(int iargc, char* argv[]) ...@@ -226,26 +226,43 @@ int main(int iargc, char* argv[])
filefree.append(TIDOFI_VERSION); filefree.append(TIDOFI_VERSION);
filefree.append(TIDOFI_CVSID); filefree.append(TIDOFI_CVSID);
std::string line; std::string line;
line="commands are read from"; if (opt.readcommandfile || opt.readstdin)
if (opt.readstdin)
{ {
line += " stdin"; line="commands are read from";
if (opt.readcommandfile) 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); else
line.clear();
if (opt.readcommandfile)
{ {
line += "file \"" + opt.commandfile + "\""; filefree.append("no filtercommands were read");
filefree.append(line);
} }
filefree.append("read commands:");
filefree.append(filtercommands);
filefree.append("output file name:"); filefree.append("output file name:");
filefree.append(outfile); filefree.append(" " + outfile);
filefree.append("input file selection:"); filefree.append("input file selection:");
tfxx::cmdline::Tparsed::const_iterator file=arguments.begin(); tfxx::cmdline::Tparsed::const_iterator file=arguments.begin();
while (file != arguments.end()) while (file != arguments.end())
...@@ -260,8 +277,66 @@ int main(int iargc, char* argv[]) ...@@ -260,8 +277,66 @@ int main(int iargc, char* argv[])
} }
if (line.size()>2) { filefree.append(line); } if (line.size()>2) { filefree.append(line); }
++file; ++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;
} }
......
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