TF++, Miscellaneous classes and modules in C++:
regextest.cc
Go to the documentation of this file.
1 
34 #define REGEXTEST_VERSION \
35  "REGEXTEST V1.0 test regex match function"
36 
37 #include <iostream>
38 #include <tfxx/commandline.h>
39 #include <tfxx/regexx.h>
40 
41 using std::cout;
42 using std::cerr;
43 using std::endl;
44 
45 int main(int iargc, char* argv[])
46 {
47 
48  // define usage information
49  char usage_text[]=
50  {
52  "usage: regextest" "\n"
53  " or: regextest --help|-h" "\n"
54  };
55 
56  // define full help text
57  char help_text[]=
58  {
59  "first string on command line: regular expression" "\n"
60  "subsequent strings will be checked against expression" "\n"
61  };
62 
63  // define commandline options
64  using namespace tfxx::cmdline;
65  static Declare options[]=
66  {
67  // 0: print help
68  {"help",arg_no,"-"},
69  // 1: verbose mode
70  {"v",arg_no,"-"},
71  {NULL}
72  };
73 
74  // no arguments? print usage...
75  if (iargc<2)
76  {
77  cerr << usage_text << endl;
78  exit(0);
79  }
80 
81  // collect options from commandline
82  Commandline cmdline(iargc, argv, options);
83 
84  // help requested? print full help text...
85  if (cmdline.optset(0))
86  {
87  cerr << usage_text << endl;
88  cerr << help_text << endl;
89  exit(0);
90  }
91 
92  /*
93  // dummy operation: print option settings
94  for (int iopt=0; iopt<2; iopt++)
95  {
96  cout << "option: '" << options[iopt].opt_string << "'" << endl;
97  if (cmdline.optset(iopt)) { cout << " option was set"; }
98  else { cout << "option was not set"; }
99  cout << endl;
100  cout << " argument (string): '" << cmdline.string_arg(iopt) << "'" << endl;
101  cout << " argument (int): '" << cmdline.int_arg(iopt) << "'" << endl;
102  cout << " argument (long): '" << cmdline.long_arg(iopt) << "'" << endl;
103  cout << " argument (float): '" << cmdline.float_arg(iopt) << "'" << endl;
104  cout << " argument (double): '" << cmdline.double_arg(iopt) << "'" << endl;
105  cout << " argument (bool): '";
106  if (cmdline.bool_arg(iopt))
107  { cout << "true"; } else { cout << "false"; }
108  cout << "'" << endl;
109  }
110  while (cmdline.extra()) { cout << cmdline.next() << endl; }
111 
112  // dummy operation: print rest of command line
113  while (cmdline.extra()) { cout << cmdline.next() << endl; }
114  */
115 
116  TFXX_assert(cmdline.extra(), "missing regular expression");
117  tfxx::string::regexx myregex(cmdline.next());
118  cout << "regular expression: " << myregex.expression() << endl;
119 
120  while (cmdline.extra())
121  {
122  std::string teststring(cmdline.next());
123  if (myregex.match(teststring))
124  {
125  cout << "matches: ";
126  }
127  else
128  {
129  cout << "does NOT match: ";
130  }
131  cout << teststring << endl;
132  }
133 }
134 
135 /* ----- END OF regextest.cc ----- */
#define TFXX_assert(C, M)
Check an assertion and report by throwing an exception.
Definition: error.h:175
void expression(const std::string &e)
set expression to e.
Definition: regexx.h:88
bool optset(const int &iopt) const
true if option # iopt was set on commandline
Definition: commandline.h:213
int main(int iargc, char *argv[])
Definition: regextest.cc:45
#define REGEXTEST_VERSION
Definition: regextest.cc:34
char * next()
returns char-array of next commandline argument
Definition: commandline.h:243
Namespace containing all components of module commandline. ,.
Definition: commandline.cc:41
bool extra() const
true if there are more commandline arguments
Definition: commandline.h:240
Evaluates commandline by calling long_getopt. ,You may instantiate a Commandline object by passing th...
Definition: commandline.h:201
struct to define options ,This struct is used to define a list of options. An example is: ...
Definition: commandline.h:136
option has no argument
Definition: commandline.h:100