TF++, Miscellaneous classes and modules in C++:

◆ main()

int main ( int  iargc,
char *  argv[] 
)

Definition at line 46 of file misctest.cc.

References tfxx::cmdline::arg_no, tfxx::util::hexdump(), MISCTEST_VERSION, tfxx::cmdline::Commandline::optset(), and TFXX_hexdump.

47 {
48 
49  // define usage information
50  char usage_text[]=
51  {
52  MISCTEST_VERSION "\n"
53  "usage: misctest [--hexdump]" "\n"
54  " or: misctest --help|-h" "\n"
55  };
56 
57  // define full help text
58  char help_text[]=
59  {
60  "--hexdump test hex dump function"
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  // 2: verbose mode
72  {"hexdump",arg_no,"-"},
73  {NULL}
74  };
75 
76  // no arguments? print usage...
77  if (iargc<2)
78  {
79  cerr << usage_text << endl;
80  exit(0);
81  }
82 
83  // collect options from commandline
84  Commandline cmdline(iargc, argv, options);
85 
86  // help requested? print full help text...
87  if (cmdline.optset(0))
88  {
89  cerr << usage_text << endl;
90  cerr << help_text << endl;
91  exit(0);
92  }
93 
94  /*
95  // dummy operation: print option settings
96  for (int iopt=0; iopt<2; iopt++)
97  {
98  cout << "option: '" << options[iopt].opt_string << "'" << endl;
99  if (cmdline.optset(iopt)) { cout << " option was set"; }
100  else { cout << "option was not set"; }
101  cout << endl;
102  cout << " argument (string): '" << cmdline.string_arg(iopt) << "'" << endl;
103  cout << " argument (int): '" << cmdline.int_arg(iopt) << "'" << endl;
104  cout << " argument (long): '" << cmdline.long_arg(iopt) << "'" << endl;
105  cout << " argument (float): '" << cmdline.float_arg(iopt) << "'" << endl;
106  cout << " argument (double): '" << cmdline.double_arg(iopt) << "'" << endl;
107  cout << " argument (bool): '";
108  if (cmdline.bool_arg(iopt))
109  { cout << "true"; } else { cout << "false"; }
110  cout << "'" << endl;
111  }
112  while (cmdline.extra()) { cout << cmdline.next() << endl; }
113 
114  // dummy operation: print rest of command line
115  while (cmdline.extra()) { cout << cmdline.next() << endl; }
116  */
117 
118  // hexdump
119  // -------
120  if (cmdline.optset(2))
121  {
122  int v=12;
123  char q[]="Hi there. This is a quite long character sequence.";
124  TFXX_hexdump(v);
125  std::cout << std::endl;
126  TFXX_hexdump(q);
127  std::cout << std::endl;
128  std::cout << "raw output of 30 bytes of q:" << std::endl;
129  tfxx::util::hexdump(q, 30);
130  std::cout << std::endl;
131  TFXX_hexdump(cmdline);
132  } // hexdump
133 }
#define TFXX_hexdump(V)
produce hexdump to stdout, preceeded by object name.
Definition: hexdump.h:98
#define MISCTEST_VERSION
Definition: misctest.cc:35
Namespace containing all components of module commandline. ,.
Definition: commandline.cc:41
Evaluates commandline by calling long_getopt. ,You may instantiate a Commandline object by passing th...
Definition: commandline.h:201
std::ostream & hexdump(const void *pp, const unsigned int &size, std::ostream &os, const char &c, const unsigned int &n)
output hex dump of memory area.
Definition: hexdump.cc:44
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
Here is the call graph for this function: