Jpp  18.5.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPrintProperties.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 #include <iomanip>
4 #include <string>
5 #include <vector>
6 #include <set>
7 #include <map>
8 
10 #include "JLang/JEquation.hh"
11 
12 #include "Jeep/JProperties.hh"
13 #include "Jeep/JComment.hh"
14 #include "Jeep/JParser.hh"
15 #include "Jeep/JMessage.hh"
16 
17 /**
18  * \file
19  *
20  * General purpose program to print properties file.
21  * \author mdejong
22  */
23 int main(int argc, char **argv)
24 {
25  using namespace std;
26  using namespace JPP;
27 
28  string inputFile;
29  JEquationParameters parameters("=", ";\n", "", "#");
30  set<string> key;
31  int debug;
32 
33  try {
34 
35  JProperties properties;
36 
37  properties["sep"] = parameters.getSeparator();
38  properties["eol"] = parameters.getEndOfLine();
39  properties["div"] = parameters.getDivision();
40  properties["skip"] = parameters.getSkipLine();
41  properties["left"] = parameters.getLeftBracket();
42  properties["right"] = parameters.getRightBracket();
43  properties["ws"] = parameters.getWhiteSpace();
44  properties["cc"] = parameters.getComment();
45 
46  JParser<> zap("General purpose program to print properties file.");
47 
48  zap['f'] = make_field(inputFile);
49  zap['@'] = make_field(properties) = JPARSER::initialised();
50  zap['k'] = make_field(key, "key");
51  zap['d'] = make_field(debug, "debug level") = 2;
52 
53  zap(argc, argv);
54  }
55  catch(const exception &error) {
56  FATAL(error.what() << endl);
57  }
58 
59 
60  JComment comment;
61 
62  const JEquationFacet facet(parameters);
63 
64  // input
65 
66  ifstream in(inputFile.c_str());
67 
68  in >> comment;
69 
70  in.imbue(locale(in.getloc(), facet.clone()));
71 
72  for (JEquation equation; in >> equation; ) {
73 
74  DEBUG(equation << endl);
75 
76  for (const auto& i : key) {
77 
78  if (equation.getKey().find(i) == 0) {
79  cout << ' ' << equation.getValue();
80  }
81  }
82  }
83 
84  in.close();
85 }
Utility class to parse command line options.
Definition: JParser.hh:1514
const std::string & getEndOfLine() const
Get end of line characters.
int main(int argc, char *argv[])
Definition: Main.cc:15
Utility class to parse parameter values.
Definition: JProperties.hh:497
const std::string & getSeparator() const
Get separator characters.
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
Simple data structure to support I/O of equations (see class JLANG::JEquation).
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:83
Utility class to parse parameter values.
char getRightBracket() const
Get right bracket.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
char getLeftBracket() const
Get left bracket.
const std::string & getDivision() const
Get division characters.
const std::string & getComment() const
Get comment string.
General purpose messaging.
const std::string & getSkipLine() const
Get skip line characters.
#define FATAL(A)
Definition: JMessage.hh:67
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:48
Utility class to parse command line options.
const std::string & getWhiteSpace() const
Get white space characters.
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62