fx.cmdline: convert to new assembly build system
This commit is contained in:
+155
-93
@@ -1,53 +1,64 @@
|
||||
#ifndef FX_CMD_H_
|
||||
#define FX_CMD_H_
|
||||
|
||||
#include <fx/core/bst.h>
|
||||
#include <fx/core/init.h>
|
||||
#include <fx/core/iterator.h>
|
||||
#include <fx/core/queue.h>
|
||||
#include <fx/ds/array.h>
|
||||
#include <fx/bst.h>
|
||||
#include <fx/collections/array.h>
|
||||
#include <fx/init.h>
|
||||
#include <fx/iterator.h>
|
||||
#include <fx/queue.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define fx_arglist_foreach(it, q) \
|
||||
for (int z__fx_unique_name() = fx_arglist_iterator_begin( \
|
||||
q, FX_COMMAND_INVALID_ID, FX_COMMAND_INVALID_ID, (it)); \
|
||||
fx_arglist_iterator_is_valid(it); fx_arglist_iterator_next(it))
|
||||
#define fx_arglist_foreach(it, q) \
|
||||
for (int z__fx_unique_name() = fx_arglist_iterator_begin( \
|
||||
q, \
|
||||
FX_COMMAND_INVALID_ID, \
|
||||
FX_COMMAND_INVALID_ID, \
|
||||
(it)); \
|
||||
fx_arglist_iterator_is_valid(it); \
|
||||
fx_arglist_iterator_next(it))
|
||||
|
||||
#define fx_arglist_foreach_filtered(it, q, opt_id, arg_id) \
|
||||
for (int z__fx_unique_name() \
|
||||
= fx_arglist_iterator_begin(q, opt_id, arg_id, (it)); \
|
||||
fx_arglist_iterator_is_valid(it); fx_arglist_iterator_next(it))
|
||||
#define fx_arglist_foreach_filtered(it, q, opt_id, arg_id) \
|
||||
for (int z__fx_unique_name() \
|
||||
= fx_arglist_iterator_begin(q, opt_id, arg_id, (it)); \
|
||||
fx_arglist_iterator_is_valid(it); \
|
||||
fx_arglist_iterator_next(it))
|
||||
|
||||
#define fx_arglist_option_foreach(it, q) \
|
||||
for (int z__fx_unique_name() \
|
||||
= fx_arglist_option_iterator_begin(q, FX_COMMAND_INVALID_ID, (it)); \
|
||||
fx_arglist_option_iterator_is_valid(it); \
|
||||
#define fx_arglist_option_foreach(it, q) \
|
||||
for (int z__fx_unique_name() = fx_arglist_option_iterator_begin( \
|
||||
q, \
|
||||
FX_COMMAND_INVALID_ID, \
|
||||
(it)); \
|
||||
fx_arglist_option_iterator_is_valid(it); \
|
||||
fx_arglist_option_iterator_next(it))
|
||||
|
||||
#define fx_arglist_option_foreach_filtered(it, q, opt_id) \
|
||||
for (int z__fx_unique_name() \
|
||||
= fx_arglist_option_iterator_begin(q, opt_id, (it)); \
|
||||
fx_arglist_option_iterator_is_valid(it); \
|
||||
#define fx_arglist_option_foreach_filtered(it, q, opt_id) \
|
||||
for (int z__fx_unique_name() \
|
||||
= fx_arglist_option_iterator_begin(q, opt_id, (it)); \
|
||||
fx_arglist_option_iterator_is_valid(it); \
|
||||
fx_arglist_option_iterator_next(it))
|
||||
|
||||
#define FX_COMMAND(id, parent_id) \
|
||||
static fx_command *command_##id = NULL; \
|
||||
#define FX_COMMAND(id, parent_id) \
|
||||
static fx_command *command_##id = NULL; \
|
||||
static void __init_##id( \
|
||||
fx_command *, fx_command_option *, fx_command_arg *, \
|
||||
fx_command_usage *); \
|
||||
FX_INIT(init_##id) \
|
||||
fx_command *, \
|
||||
fx_command_option *, \
|
||||
fx_command_arg *, \
|
||||
fx_command_usage *); \
|
||||
FX_INIT(init_##id) \
|
||||
{ \
|
||||
command_##id = fx_command_create(id); \
|
||||
if ((parent_id) != FX_COMMAND_INVALID_ID) { \
|
||||
fx_command_set_parent(command_##id, parent_id); \
|
||||
command_##id = fx_command_create(id); \
|
||||
if ((parent_id) != FX_COMMAND_INVALID_ID) { \
|
||||
fx_command_set_parent(command_##id, parent_id); \
|
||||
} \
|
||||
__init_##id(command_##id, NULL, NULL, NULL); \
|
||||
fx_command_register(command_##id); \
|
||||
fx_command_register(command_##id); \
|
||||
} \
|
||||
static void __init_##id( \
|
||||
fx_command *this_cmd, fx_command_option *this_opt, \
|
||||
fx_command_arg *this_arg, fx_command_usage *this_usage)
|
||||
fx_command *this_cmd, \
|
||||
fx_command_option *this_opt, \
|
||||
fx_command_arg *this_arg, \
|
||||
fx_command_usage *this_usage)
|
||||
|
||||
#define FX_COMMAND_NAME(name) fx_command_set_name(this_cmd, (name))
|
||||
#define FX_COMMAND_LONG_NAME(name) fx_command_set_long_name(this_cmd, (name))
|
||||
@@ -56,41 +67,44 @@
|
||||
#define FX_COMMAND_FLAGS(flags) fx_command_set_flags(this_cmd, (flags))
|
||||
#define FX_COMMAND_FUNCTION(fn) fx_command_set_callback(this_cmd, (fn))
|
||||
|
||||
#define FX_COMMAND_OPTION(id) \
|
||||
fx_command_option *opt_##id = fx_command_add_option(this_cmd, (id)); \
|
||||
#define FX_COMMAND_OPTION(id) \
|
||||
fx_command_option *opt_##id = fx_command_add_option(this_cmd, (id)); \
|
||||
this_opt = opt_##id; \
|
||||
if (this_opt)
|
||||
|
||||
#define FX_COMMAND_OPTION_GEN(id) \
|
||||
fx_command_option *z__fx_unique_name() \
|
||||
= fx_command_add_option(this_cmd, (id)); \
|
||||
this_opt = z__fx_unique_name(); \
|
||||
#define FX_COMMAND_OPTION_GEN(id) \
|
||||
fx_command_option *z__fx_unique_name() \
|
||||
= fx_command_add_option(this_cmd, (id)); \
|
||||
this_opt = z__fx_unique_name(); \
|
||||
if (this_opt)
|
||||
|
||||
#define FX_COMMAND_HELP_OPTION() \
|
||||
do { \
|
||||
fx_command_option *opt \
|
||||
= fx_command_add_option(this_cmd, FX_COMMAND_OPTION_HELP); \
|
||||
fx_command_option_set_description(opt, "Show this help message"); \
|
||||
fx_command_option_set_short_name(opt, 'h'); \
|
||||
fx_command_option_set_long_name(opt, "help"); \
|
||||
#define FX_COMMAND_HELP_OPTION() \
|
||||
do { \
|
||||
fx_command_option *opt = fx_command_add_option( \
|
||||
this_cmd, \
|
||||
FX_COMMAND_OPTION_HELP); \
|
||||
fx_command_option_set_description( \
|
||||
opt, \
|
||||
"Show this help message"); \
|
||||
fx_command_option_set_short_name(opt, 'h'); \
|
||||
fx_command_option_set_long_name(opt, "help"); \
|
||||
} while (0)
|
||||
|
||||
#define FX_OPTION_LONG_NAME(name) \
|
||||
#define FX_OPTION_LONG_NAME(name) \
|
||||
fx_command_option_set_long_name(this_opt, (name))
|
||||
|
||||
#define FX_OPTION_SHORT_NAME(name) \
|
||||
#define FX_OPTION_SHORT_NAME(name) \
|
||||
fx_command_option_set_short_name(this_opt, (name))
|
||||
|
||||
#define FX_OPTION_DESC(desc) fx_command_option_set_description(this_opt, (desc))
|
||||
|
||||
#define FX_OPTION_ARG(id) \
|
||||
fx_command_arg *arg_##id = fx_command_option_add_arg(this_opt, (id)); \
|
||||
#define FX_OPTION_ARG(id) \
|
||||
fx_command_arg *arg_##id = fx_command_option_add_arg(this_opt, (id)); \
|
||||
this_arg = arg_##id; \
|
||||
if (this_arg)
|
||||
|
||||
#define FX_COMMAND_ARG(id) \
|
||||
fx_command_arg *arg_##id = fx_command_add_arg(this_cmd, (id)); \
|
||||
#define FX_COMMAND_ARG(id) \
|
||||
fx_command_arg *arg_##id = fx_command_add_arg(this_cmd, (id)); \
|
||||
this_arg = arg_##id; \
|
||||
if (this_arg)
|
||||
|
||||
@@ -98,37 +112,38 @@
|
||||
|
||||
#define FX_ARG_DESC(desc) fx_command_arg_set_description(this_arg, (desc))
|
||||
|
||||
#define FX_ARG_NR_VALUES(nr_values) \
|
||||
#define FX_ARG_NR_VALUES(nr_values) \
|
||||
fx_command_arg_set_nr_values(this_arg, (nr_values))
|
||||
|
||||
#define FX_ARG_ALLOWED_VALUES(...) \
|
||||
#define FX_ARG_ALLOWED_VALUES(...) \
|
||||
static const char *allowed_values[] = { \
|
||||
__VA_ARGS__, \
|
||||
NULL, \
|
||||
}; \
|
||||
fx_command_arg_set_allowed_values(this_arg, allowed_values)
|
||||
|
||||
#define FX_COMMAND_USAGE() \
|
||||
fx_command_usage *z__fx_unique_name() = fx_command_add_usage(this_cmd); \
|
||||
this_usage = z__fx_unique_name(); \
|
||||
#define FX_COMMAND_USAGE() \
|
||||
fx_command_usage *z__fx_unique_name() \
|
||||
= fx_command_add_usage(this_cmd); \
|
||||
this_usage = z__fx_unique_name(); \
|
||||
if (this_usage)
|
||||
|
||||
#define FX_COMMAND_USAGE_COMMAND(cmd_id) \
|
||||
#define FX_COMMAND_USAGE_COMMAND(cmd_id) \
|
||||
fx_command_usage_add_command(this_usage, cmd_id)
|
||||
|
||||
#define FX_COMMAND_USAGE_COMMAND_PLACEHOLDER() \
|
||||
#define FX_COMMAND_USAGE_COMMAND_PLACEHOLDER() \
|
||||
fx_command_usage_add_command(this_usage, FX_COMMAND_INVALID_ID)
|
||||
|
||||
#define FX_COMMAND_USAGE_OPT(opt_id) \
|
||||
#define FX_COMMAND_USAGE_OPT(opt_id) \
|
||||
fx_command_usage_add_option(this_usage, opt_##opt_id)
|
||||
|
||||
#define FX_COMMAND_USAGE_OPT_PLACEHOLDER() \
|
||||
#define FX_COMMAND_USAGE_OPT_PLACEHOLDER() \
|
||||
fx_command_usage_add_option(this_usage, NULL)
|
||||
|
||||
#define FX_COMMAND_USAGE_ARG(opt_id) \
|
||||
#define FX_COMMAND_USAGE_ARG(opt_id) \
|
||||
fx_command_usage_add_arg(this_usage, arg_##opt_id)
|
||||
|
||||
#define FX_COMMAND_USAGE_ARG_PLACEHOLDER() \
|
||||
#define FX_COMMAND_USAGE_ARG_PLACEHOLDER() \
|
||||
fx_command_usage_add_arg(this_usage, NULL)
|
||||
|
||||
#define FX_COMMAND_OPTION_HELP ((uintptr_t)0xF0000001)
|
||||
@@ -197,90 +212,137 @@ typedef struct fx_arglist fx_arglist;
|
||||
typedef struct fx_arglist_option fx_arglist_option;
|
||||
|
||||
typedef int (*fx_command_callback)(
|
||||
const fx_command *, const fx_arglist *, const fx_array *);
|
||||
const fx_command *,
|
||||
const fx_arglist *,
|
||||
const fx_array *);
|
||||
|
||||
FX_API fx_command *fx_command_create(unsigned int id);
|
||||
FX_API void fx_command_destroy(fx_command *cmd);
|
||||
FX_API fx_status fx_command_register(fx_command *cmd);
|
||||
FX_API int fx_command_dispatch(unsigned int cmd_id, int argc, const char **argv);
|
||||
FX_API int fx_command_dispatch(
|
||||
unsigned int cmd_id,
|
||||
int argc,
|
||||
const char **argv);
|
||||
|
||||
FX_API fx_status fx_command_set_name(fx_command *cmd, const char *name);
|
||||
FX_API fx_status fx_command_set_long_name(fx_command *cmd, const char *name);
|
||||
FX_API fx_status fx_command_set_short_name(fx_command *cmd, char name);
|
||||
FX_API fx_status fx_command_set_flags(fx_command *cmd, fx_command_flags flags);
|
||||
FX_API fx_status fx_command_set_description(fx_command *cmd, const char *description);
|
||||
FX_API fx_status fx_command_set_description(
|
||||
fx_command *cmd,
|
||||
const char *description);
|
||||
FX_API fx_status fx_command_set_callback(
|
||||
fx_command *cmd, fx_command_callback callback);
|
||||
fx_command *cmd,
|
||||
fx_command_callback callback);
|
||||
FX_API fx_status fx_command_set_parent(fx_command *cmd, unsigned int parent_id);
|
||||
FX_API fx_command_option *fx_command_add_option(fx_command *cmd, int id);
|
||||
FX_API fx_command_arg *fx_command_add_arg(fx_command *cmd, int id);
|
||||
FX_API fx_command_usage *fx_command_add_usage(fx_command *cmd);
|
||||
|
||||
FX_API const fx_command_option *fx_command_get_option(const fx_command *cmd, int id);
|
||||
FX_API const fx_command_option *fx_command_get_option(
|
||||
const fx_command *cmd,
|
||||
int id);
|
||||
|
||||
FX_API const char *fx_command_option_get_long_name(const fx_command_option *opt);
|
||||
FX_API const char *fx_command_option_get_long_name(
|
||||
const fx_command_option *opt);
|
||||
FX_API char fx_command_option_get_short_name(const fx_command_option *opt);
|
||||
FX_API const char *fx_command_option_get_description(fx_command_option *opt);
|
||||
FX_API fx_status fx_command_option_set_long_name(
|
||||
fx_command_option *opt, const char *name);
|
||||
FX_API fx_status fx_command_option_set_short_name(fx_command_option *opt, char name);
|
||||
fx_command_option *opt,
|
||||
const char *name);
|
||||
FX_API fx_status fx_command_option_set_short_name(
|
||||
fx_command_option *opt,
|
||||
char name);
|
||||
FX_API fx_status fx_command_option_set_description(
|
||||
fx_command_option *opt, const char *description);
|
||||
FX_API fx_command_arg *fx_command_option_add_arg(fx_command_option *opt, int id);
|
||||
fx_command_option *opt,
|
||||
const char *description);
|
||||
FX_API fx_command_arg *fx_command_option_add_arg(
|
||||
fx_command_option *opt,
|
||||
int id);
|
||||
|
||||
FX_API fx_status fx_command_arg_set_name(fx_command_arg *arg, const char *name);
|
||||
FX_API fx_status fx_command_arg_set_description(
|
||||
fx_command_arg *arg, const char *description);
|
||||
fx_command_arg *arg,
|
||||
const char *description);
|
||||
FX_API fx_status fx_command_arg_set_nr_values(
|
||||
fx_command_arg *arg, fx_command_arg_value_count nr_values);
|
||||
fx_command_arg *arg,
|
||||
fx_command_arg_value_count nr_values);
|
||||
FX_API fx_status fx_command_arg_set_allowed_values(
|
||||
fx_command_arg *arg, const char **allowed_values);
|
||||
fx_command_arg *arg,
|
||||
const char **allowed_values);
|
||||
|
||||
FX_API fx_status fx_command_usage_add_option(
|
||||
fx_command_usage *usage, fx_command_option *opt);
|
||||
fx_command_usage *usage,
|
||||
fx_command_option *opt);
|
||||
FX_API fx_status fx_command_usage_add_arg(
|
||||
fx_command_usage *usage, fx_command_arg *opt);
|
||||
fx_command_usage *usage,
|
||||
fx_command_arg *opt);
|
||||
FX_API fx_status fx_command_usage_add_command(
|
||||
fx_command_usage *usage, unsigned int cmd_id);
|
||||
fx_command_usage *usage,
|
||||
unsigned int cmd_id);
|
||||
|
||||
FX_API fx_status fx_arglist_get_string(
|
||||
const fx_arglist *args, unsigned int opt_id, unsigned int arg_id,
|
||||
unsigned int index, const char **out);
|
||||
const fx_arglist *args,
|
||||
unsigned int opt_id,
|
||||
unsigned int arg_id,
|
||||
unsigned int index,
|
||||
const char **out);
|
||||
FX_API fx_status fx_arglist_get_int(
|
||||
const fx_arglist *args, unsigned int opt_id, unsigned int arg_id,
|
||||
unsigned int index, long long *out);
|
||||
const fx_arglist *args,
|
||||
unsigned int opt_id,
|
||||
unsigned int arg_id,
|
||||
unsigned int index,
|
||||
long long *out);
|
||||
FX_API fx_status fx_arglist_get_uint(
|
||||
const fx_arglist *args, unsigned int opt_id, unsigned int arg_id,
|
||||
unsigned int index, unsigned long long *out);
|
||||
const fx_arglist *args,
|
||||
unsigned int opt_id,
|
||||
unsigned int arg_id,
|
||||
unsigned int index,
|
||||
unsigned long long *out);
|
||||
FX_API fx_status fx_arglist_get_option(
|
||||
const fx_arglist *args, unsigned int opt_id, unsigned int index,
|
||||
const fx_arglist *args,
|
||||
unsigned int opt_id,
|
||||
unsigned int index,
|
||||
fx_arglist_option **out);
|
||||
FX_API size_t fx_arglist_get_count(
|
||||
const fx_arglist *args, unsigned int opt_id, unsigned int arg_id);
|
||||
const fx_arglist *args,
|
||||
unsigned int opt_id,
|
||||
unsigned int arg_id);
|
||||
|
||||
FX_API fx_status fx_arglist_report_missing_option(
|
||||
const fx_arglist *args, unsigned int opt_id);
|
||||
const fx_arglist *args,
|
||||
unsigned int opt_id);
|
||||
FX_API fx_status fx_arglist_report_unexpected_arg(
|
||||
const fx_arglist *args, const char *value);
|
||||
const fx_arglist *args,
|
||||
const char *value);
|
||||
FX_API fx_status fx_arglist_report_invalid_arg_value(
|
||||
const fx_arglist *args, unsigned int opt_id, unsigned int arg_id,
|
||||
const fx_arglist *args,
|
||||
unsigned int opt_id,
|
||||
unsigned int arg_id,
|
||||
const char *value);
|
||||
FX_API fx_status fx_arglist_report_missing_args(
|
||||
const fx_arglist *args, unsigned int opt_id, unsigned int arg_id,
|
||||
const fx_arglist *args,
|
||||
unsigned int opt_id,
|
||||
unsigned int arg_id,
|
||||
size_t nr_supplied);
|
||||
|
||||
FX_API fx_status fx_arglist_option_get_value(
|
||||
const fx_arglist_option *opt, unsigned int arg_id, unsigned int index,
|
||||
const fx_arglist_option *opt,
|
||||
unsigned int arg_id,
|
||||
unsigned int index,
|
||||
fx_arglist_value **out);
|
||||
|
||||
FX_API int fx_arglist_iterator_begin(
|
||||
const fx_arglist *args, unsigned int opt_filter, unsigned int arg_filter,
|
||||
const fx_arglist *args,
|
||||
unsigned int opt_filter,
|
||||
unsigned int arg_filter,
|
||||
fx_arglist_iterator *it);
|
||||
FX_API bool fx_arglist_iterator_next(fx_arglist_iterator *it);
|
||||
FX_API bool fx_arglist_iterator_is_valid(const fx_arglist_iterator *it);
|
||||
|
||||
FX_API int fx_arglist_option_iterator_begin(
|
||||
const fx_arglist *args, unsigned int opt_filter,
|
||||
const fx_arglist *args,
|
||||
unsigned int opt_filter,
|
||||
fx_arglist_option_iterator *it);
|
||||
FX_API bool fx_arglist_option_iterator_next(fx_arglist_option_iterator *it);
|
||||
FX_API bool fx_arglist_option_iterator_is_valid(
|
||||
|
||||
Reference in New Issue
Block a user