TF++, Miscellaneous classes and modules in C++:
fstest.cc
Go to the documentation of this file.
1 
37 #define FSTEST_VERSION \
38  "FSTEST V1.0 test file system utilities"
39 
40 #include <iostream>
41 #include <tfxx/commandline.h>
42 #include <tfxx/fs.h>
43 
44 using std::cout;
45 using std::cerr;
46 using std::endl;
47 
48 struct Options {
50 }; // struct Options
51 
52 int main(int iargc, char* argv[])
53 {
54 
55  // define usage information
56  char usage_text[]=
57  {
58  FSTEST_VERSION "\n"
59  "usage: fstest [-d] [-m] [-p] path [path ...]" "\n"
60  " or: fstest --help|-h" "\n"
61  };
62 
63  // define full help text
64  char help_text[]=
65  {
66  FSTEST_CVSID
67  };
68 
69  // define commandline options
70  using namespace tfxx::cmdline;
71  static Declare options[]=
72  {
73  // 0: print help
74  {"help",arg_no,"-"},
75  // 1: verbose mode
76  {"v",arg_no,"-"},
77  // 2: dirname
78  {"d",arg_no,"-"},
79  // 3: mkdir
80  {"m",arg_no,"-"},
81  // 4: mkdirp
82  {"p",arg_no,"-"},
83  {NULL}
84  };
85 
86  // no arguments? print usage...
87  if (iargc<2)
88  {
89  cerr << usage_text << endl;
90  exit(0);
91  }
92 
93  // collect options from commandline
94  Commandline cmdline(iargc, argv, options);
95 
96  // help requested? print full help text...
97  if (cmdline.optset(0))
98  {
99  cerr << usage_text << endl;
100  cerr << help_text << endl;
101  exit(0);
102  }
103 
104  Options opt;
105 
106  opt.dirname=cmdline.optset(2);
107  opt.mkdir=cmdline.optset(3);
108  opt.mkdirp=cmdline.optset(4);
109 
110  /*
111  // dummy operation: print option settings
112  for (int iopt=0; iopt<2; iopt++)
113  {
114  cout << "option: '" << options[iopt].opt_string << "'" << endl;
115  if (cmdline.optset(iopt)) { cout << " option was set"; }
116  else { cout << "option was not set"; }
117  cout << endl;
118  cout << " argument (string): '" << cmdline.string_arg(iopt) << "'" << endl;
119  cout << " argument (int): '" << cmdline.int_arg(iopt) << "'" << endl;
120  cout << " argument (long): '" << cmdline.long_arg(iopt) << "'" << endl;
121  cout << " argument (float): '" << cmdline.float_arg(iopt) << "'" << endl;
122  cout << " argument (double): '" << cmdline.double_arg(iopt) << "'" << endl;
123  cout << " argument (bool): '";
124  if (cmdline.bool_arg(iopt))
125  { cout << "true"; } else { cout << "false"; }
126  cout << "'" << endl;
127  }
128  */
129  while (cmdline.extra())
130  {
131  std::string path=cmdline.next();
132  cout << "\nnext on command line:\n" << path << endl;
133 
134  if (opt.dirname)
135  {
136  cout << "dirname("<<path<<"): " << tfxx::fs::dirname(path) << endl;
137  }
138 
139  if (opt.mkdir)
140  {
141  cout << "create directory " << path << endl;
142  tfxx::fs::mkdir(path);
143  }
144 
145  if (opt.mkdirp)
146  {
147  cout << "create directory path " << path << endl;
148  tfxx::fs::mkdirp(path);
149  }
150  }
151 }
152 
153 /* ----- END OF fstest.cc ----- */
bool dirname
Definition: fstest.cc:49
std::string dirname(const std::string &path)
return path with its last non-slash component removed
Definition: dirname.cc:45
bool optset(const int &iopt) const
true if option # iopt was set on commandline
Definition: commandline.h:213
#define FSTEST_VERSION
Definition: fstest.cc:37
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
bool mkdir
Definition: fstest.cc:49
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
bool mkdirp
Definition: fstest.cc:49
option has no argument
Definition: commandline.h:100
void mkdirp(const std::string &path)
create a directory with all parents
Definition: mkdirp.cc:44
int main(int iargc, char *argv[])
Definition: fstest.cc:52
void mkdir(const std::string &path)
create a directory
Definition: mkdir.cc:45