Merge commit '3985029fd63ff5abfef0a3d2b0eef64b2b3f6cea' as 'external/cflags'
This commit is contained in:
56
external/cflags/examples/example.c
vendored
Normal file
56
external/cflags/examples/example.c
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
#include "cflags.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void parse_file(const char * filename)
|
||||
{
|
||||
printf("parsing %s\n", filename);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
cflags_t * flags = cflags_init();
|
||||
|
||||
bool help = false;
|
||||
cflags_add_bool(flags, '\0', "help", &help, "display this help and exit");
|
||||
|
||||
bool debug = false;
|
||||
cflags_add_bool(flags, 'd', "debug", &debug, "enable debug mode");
|
||||
|
||||
int count = 0;
|
||||
cflags_add_int(flags, 'c', "count", &count, "enter a number");
|
||||
|
||||
float amount = 0.f;
|
||||
cflags_add_float(flags, 'a', "amount", &amount, "enter a float");
|
||||
|
||||
cflags_add_bool(flags, 'q', "really-long-argument-name", NULL, "testing really long argument names");
|
||||
|
||||
cflags_add_string_callback(flags, 'f', "file", &parse_file, "process a file");
|
||||
|
||||
cflags_flag_t * verbose = cflags_add_bool(flags, 'v', "verbose", NULL, "enables verbose output, repeat up to 4 times for more verbosity");
|
||||
|
||||
// Parse the command arguments
|
||||
if (!cflags_parse(flags, argc, argv) || help || argc == 1) {
|
||||
cflags_print_usage(flags,
|
||||
"[OPTION]... [ARG]...",
|
||||
"Tests the cflags library.",
|
||||
"Additional information about this library can be found by at:\n"
|
||||
" https://github.com/WhoBrokeTheBuild/cflags");
|
||||
}
|
||||
|
||||
printf("help: %d\n", help);
|
||||
printf("debug: %d\n", debug);
|
||||
|
||||
printf("count: %d\n", count);
|
||||
printf("amount: %f\n", amount);
|
||||
|
||||
printf("verbosity: %d\n", verbose->count);
|
||||
|
||||
printf("argc/argv:\n");
|
||||
for (int i = 0; i < flags->argc; ++i) {
|
||||
printf("positional %d: %s\n", i, flags->argv[i]);
|
||||
}
|
||||
|
||||
cflags_free(flags);
|
||||
|
||||
return 0;
|
||||
}
|
||||
64
external/cflags/examples/example.cpp
vendored
Normal file
64
external/cflags/examples/example.cpp
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
#include "cflags.hpp"
|
||||
|
||||
void parse_file(const char * filename)
|
||||
{
|
||||
printf("parsing %s\n", filename);
|
||||
}
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
cflags::cflags flags;
|
||||
|
||||
bool help = false;
|
||||
flags.add_bool('\0', "help", &help, "display this help and exit");
|
||||
|
||||
bool debug = false;
|
||||
flags.add_bool('d', "debug", &debug, "enable debug mode");
|
||||
|
||||
int count = 0;
|
||||
flags.add_int('c', "count", &count, "enter a number");
|
||||
|
||||
float amount = 0.f;
|
||||
flags.add_float('a', "amount", &amount, "enter a float");
|
||||
|
||||
flags.add_bool('q', "really-long-argument-name", nullptr, "testing really long argument names");
|
||||
|
||||
flags.add_cstring_callback('f', "file", &parse_file, "process a file");
|
||||
|
||||
flags.add_string_callback('n', "name",
|
||||
[](std::string name) {
|
||||
printf("Hello %s\n", name.c_str());
|
||||
},
|
||||
"say hello to name");
|
||||
|
||||
auto verbose = flags.add_bool('v', "verbose", NULL, "enables verbose output, repeat up to 4 times for more verbosity");
|
||||
|
||||
if (!flags.parse(argc, argv) || help || argc == 1) {
|
||||
flags.print_usage(
|
||||
"[OPTION]... [ARG]...",
|
||||
"Tests the cflags library.",
|
||||
"Additional information about this library can be found by contacting:\n"
|
||||
" sdl.slane@gmail.com");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("help: %d\n", help);
|
||||
printf("debug: %d\n", debug);
|
||||
|
||||
printf("count: %d\n", count);
|
||||
printf("amount: %f\n", amount);
|
||||
|
||||
printf("verbosity: %d\n", verbose->count);
|
||||
|
||||
printf("args:\n");
|
||||
for (auto& arg : flags.args) {
|
||||
printf("Positional %s\n", arg.data());
|
||||
}
|
||||
|
||||
printf("argc/argv:\n");
|
||||
for (int i = 0; i < flags.argc; ++i) {
|
||||
printf("positional %d: %s\n", i, flags.argv[i]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user