Example of shell parsing.
#ifndef DEBUG
#define DEBUG
#endif
#include <stdio.h>
extern "C" int main()
{
int test_argc;
char *test_argv[6];
shell::bind("test");
test_argc = 5;
test_argv[0] = (char *)"test";
test_argv[1] = (char *)"--lines=5";
test_argv[2] = (char *)"-r";
test_argv[3] = (char *)"a";
test_argv[4] = (char *)"b";
test_argv[5] = NULL;
shell::flagopt rflag('r', "--reverse", "reverse order of arguments");
shell::flagopt tflag('t', "--testing", "never hit this flag");
shell::numericopt lines('l', "--lines", "number of lines in output");
shell args(test_argc, test_argv);
assert(!tflag);
assert(*lines == 5);
assert(args() == 2);
assert(
eq(args[0],
"a"));
prefix = shell::path(shell::SYSTEM_PREFIX);
subdir = shell::path(shell::SYSTEM_PREFIX, "test");
basedir = shell::path(shell::SYSTEM_PREFIX, "/test");
prefix = prefix + "/test";
assert(
eq(basedir,
"/test"));
assert(
eq(subdir, prefix));
}
Top level include file for the GNU uCommon C++ core library.
Common namespace for all ucommon objects.
String string_t
A convenience type for string.
bool eq(const struct sockaddr *s1, const struct sockaddr *s2)
Compare two socket addresses to see if equal.
bool is(T &object)
Convenience function to validate object assuming it is castable to bool.