16#include <isl_config.h>
27 *(
unsigned *)(((
char *)opt) +
arg->offset) =
arg->u.choice.default_value;
32 *(
unsigned *)(((
char *)opt) +
arg->offset) =
arg->u.flags.default_value;
39 *(
unsigned *)(((
char *)opt) +
arg->offset) =
arg->u.b.default_value;
49 child = calloc(1,
arg->u.child.child->options_size);
50 *(
void **)(((
char *)opt) +
arg->offset) =
child;
59 arg->u.user.init(((
char *)opt) +
arg->offset);
64 *(
int *)(((
char *)opt) +
arg->offset) =
arg->u.i.default_value;
69 *(
long *)(((
char *)opt) +
arg->offset) =
arg->u.l.default_value;
74 *(
unsigned long *)(((
char *)opt) +
arg->offset) =
arg->u.ul.default_value;
79 const char *
str = NULL;
80 if (
arg->u.str.default_value)
81 str = strdup(
arg->u.str.default_value);
82 *(
const char **)(((
char *)opt) +
arg->offset) =
str;
87 *(
const char ***)(((
char *) opt) +
arg->offset) = NULL;
88 *(
int *)(((
char *) opt) +
arg->u.str_list.offset_n) = 0;
145 *(
void **)(((
char *)opt) +
arg->offset));
151 int n = *(
int *)(((
char *) opt) +
arg->u.str_list.offset_n);
152 char **list = *(
char ***)(((
char *) opt) +
arg->offset);
154 for (
i = 0;
i <
n; ++
i)
161 if (
arg->u.user.clear)
162 arg->u.user.clear(((
char *)opt) +
arg->offset);
176 free(*(
char **)(((
char *)opt) +
arg[
i].
offset));
231 if (prefixes->
n >= 10) {
232 fprintf(stderr,
"too many prefixes\n");
235 prefixes->
len[prefixes->
n] = strlen(prefix);
236 prefixes->
prefix[prefixes->
n] = prefix;
259 for (i = 0; i < prefixes->
n; ++i) {
260 printf(
"%s-", prefixes->
prefix[i]);
261 len += strlen(prefixes->
prefix[i]) + 1;
277 for (i = first ? *first : 0; i < prefixes->
n; ++i) {
278 size_t len = prefixes->
len[i];
279 const char *prefix = prefixes->
prefix[i];
280 if (strncmp(
name, prefix, len) == 0 &&
name[len] ==
'-') {
345 int wrap_len = 75 - indent;
347 if (
pos + 1 >= indent)
348 printf(
"\n%*s", indent,
"");
350 printf(
"%*s", indent -
pos,
"");
353 while (len > wrap_len) {
358 space = strchr(s + wrap_len,
' ');
362 printf(
"%.*s", l, s);
365 printf(
"\n%*s", indent,
"");
382 const char *default_prefix =
"[default: ";
383 const char *default_suffix =
"]";
386 len = strlen(default_prefix) + strlen(def) + strlen(default_suffix);
390 printf(
"\n%30s",
"");
392 printf(
"%*s", 30 -
pos,
"");
395 printf(
"\n%30s",
"");
399 printf(
"%s%s%s", default_prefix, def, default_suffix);
405 const char *s =
"none";
408 p = (
unsigned *)(((
char *) opt) + decl->
offset);
446 const char *default_prefix =
"[default: ";
447 const char *default_suffix =
"]";
448 int len = strlen(default_prefix) + strlen(default_suffix);
451 p = (
unsigned *)(((
char *) opt) + decl->
offset);
452 for (i = 0; decl->
u.
flags.flags[i].name; ++i)
453 if ((*
p & decl->
u.
flags.flags[i].mask) ==
454 decl->
u.
flags.flags[i].value)
455 len += strlen(decl->
u.
flags.flags[i].name);
459 printf(
"\n%30s",
"");
461 printf(
"%*s", 30 -
pos,
"");
464 printf(
"\n%30s",
"");
468 printf(
"%s", default_prefix);
470 for (first = 1, i = 0; decl->
u.
flags.flags[i].name; ++i)
471 if ((*
p & decl->
u.
flags.flags[i].mask) ==
472 decl->
u.
flags.flags[i].value) {
475 printf(
"%s", decl->
u.
flags.flags[i].name);
479 printf(
"%s", default_suffix);
492 for (i = 0; decl->
u.
flags.flags[i].name; ++i) {
498 decl->
u.
flags.flags[j].mask == decl->
u.
flags.flags[i].mask;
504 printf(
"%s", decl->
u.
flags.flags[j].name);
505 pos += strlen(decl->
u.
flags.flags[j].name);
520 unsigned *
p = opt ? (
unsigned *)(((
char *) opt) + decl->
offset) : NULL;
521 int no =
p ? *
p == 1 : 0;
540 int *
p = (
int *)(((
char *) opt) + decl->
offset);
544 snprintf(
val,
sizeof(
val),
"%d", *
p);
553 long *
p = (
long *)(((
char *) opt) + decl->
offset);
585 const char **
p = (
const char **)(((
char *) opt) + decl->
offset);
670 printf(
" %s\n",
arg[i].help_msg);
674 child = *(
void **)(((
char *) opt) +
arg[i].offset);
686 slash = strrchr(prog,
'/');
689 if (strncmp(prog,
"lt-", 3) == 0)
700 switch (decl[i].
type) {
721 printf(
"Usage: %s [OPTION...]",
prog_name(prog));
725 printf(
" %s",
arg[i].argument_name);
732 printf(
" -V, --version\n");
746 const char *start,
const char *end)
749 if (end - start == strlen(decl->
long_name) &&
750 !strncmp(start, decl->
long_name, end - start))
759 if (!strncmp(
arg,
"--", 2))
767 struct isl_prefixes *prefixes,
int need_argument,
int *has_argument)
774 if (need_argument && !
arg[2])
777 *has_argument =
arg[2] !=
'\0';
788 if (need_argument && !
equal)
792 *has_argument = !!
equal;
810 choice =
skip_name(decl,
arg[0], prefixes, 0, &has_argument);
814 if (!has_argument && (!
arg[1] ||
arg[1][0] ==
'-')) {
815 unsigned u = decl->
u.
choice.default_selected;
817 *(
unsigned *)(((
char *)opt) + decl->
offset) = u;
835 *(
unsigned *)(((
char *)opt) + decl->
offset) = u;
839 return has_argument ? 1 : 2;
850 for (i = 0; decl->
u.
flags.flags[i].name; ++i) {
851 if (strncmp(flag, decl->
u.
flags.flags[i].name,
len))
854 *
val &= ~decl->u.flags.flags[i].mask;
871 flags =
skip_name(decl,
arg[0], prefixes, 0, &has_argument);
875 if (!has_argument && !
arg[1])
883 while ((comma = strchr(flags,
',')) != NULL) {
891 *(
unsigned *)(((
char *)opt) + decl->
offset) =
val;
893 return has_argument ? 1 : 2;
900 unsigned *
p = (
unsigned *)(((
char *)opt) + decl->
offset);
906 int val = strtol(
arg[1], &endptr, 0);
907 if (*endptr ==
'\0' && (
val == 0 ||
val == 1)) {
918 decl->
u.
b.
set(opt, 1);
933 if (strncmp(
name,
"no-", 3))
943 decl->
u.
b.
set(opt, 0);
956 char **
p = (
char **)(((
char *)opt) + decl->
offset);
958 s =
skip_name(decl,
arg[0], prefixes, 0, &has_argument);
981 char **list = *(
char ***)(((
char *) opt) + decl->
offset);
983 list = realloc(list, (*
n + 1) *
sizeof(
char *));
986 *(
char ***)(((
char *) opt) + decl->
offset) = list;
987 list[*
n] = strdup(s);
998 s =
skip_name(decl,
arg[0], prefixes, 0, &has_argument);
1021 int *
p = (
int *)(((
char *)opt) + decl->
offset);
1033 int i = strtol(
arg[1], &endptr, 0);
1034 if (*endptr ==
'\0') {
1049 long *
p = (
long *)(((
char *)opt) + decl->
offset);
1056 long l = strtol(
val, NULL, 0);
1059 decl->
u.
l.
set(opt, l);
1064 long l = strtol(
arg[1], &endptr, 0);
1065 if (*endptr ==
'\0') {
1068 decl->
u.
l.
set(opt, l);
1089 unsigned long *
p = (
unsigned long *)(((
char *)opt) + decl->
offset);
1096 *
p = strtoul(
val, NULL, 0);
1101 unsigned long ul = strtoul(
arg[1], &endptr, 0);
1102 if (*endptr ==
'\0') {
1123 child = *(
void **)(((
char *)opt) + decl->
offset);
1139 switch (decl[i].
type) {
1194 switch (decl[i].
type) {
1252 if (strcmp(
arg,
"--help") == 0 || strcmp(
arg,
"-h") == 0)
1267 for (i = 1; i < argc; ++i) {
1268 if ((strcmp(argv[i],
"--version") == 0 ||
1273 while (argc > 1 + skip) {
1275 if (argv[1 + skip][0] !=
'-') {
1281 *
p = strdup(argv[1 + skip]);
1285 fprintf(stderr,
"%s: extra argument: %s\n",
1292 check_help(args, argv[1 + skip], argv[0], opt, flags);
1298 fprintf(stderr,
"%s: unrecognized option: %s\n",
1306 fprintf(stderr,
"%s: expecting %d more argument(s)\n",
#define ISL_ARG_SINGLE_DASH
#define ISL_ARG_SKIP_HELP
#define ISL_ARG_PHANTOM_BOOL(s, l, setter, h)
#define ISL_ARG_OFFSET_NONE
#define ISL_FL_ISSET(l, f)
__isl_export __isl_give ISL_HMAP __isl_take ISL_KEY __isl_take ISL_VAL * val
static void print_long_help(struct isl_arg *decl, struct isl_prefixes *prefixes, void *opt)
static void set_default_user(struct isl_arg *arg, void *opt)
static void set_default_long(struct isl_arg *arg, void *opt)
static int n_arg(struct isl_arg *arg)
static void print_ulong_help(struct isl_arg *decl, struct isl_prefixes *prefixes)
static void print_bool_help(struct isl_arg *decl, struct isl_prefixes *prefixes, void *opt)
static int isl_arg_str_list_append(struct isl_arg *decl, void *opt, const char *s)
static int print_prefixes(struct isl_prefixes *prefixes)
static struct isl_arg help_arg[]
static int match_long_name(struct isl_arg *decl, const char *start, const char *end)
static void free_str_list(struct isl_arg *arg, void *opt)
static void drop_prefix(struct isl_prefixes *prefixes, int first)
static void print_default_choice(struct isl_arg *decl, void *opt, int pos)
static const char * skip_prefixes(const char *name, struct isl_prefixes *prefixes, int *first)
static void print_help_and_exit(struct isl_arg *arg, const char *prog, void *opt)
static void print_str_list_help(struct isl_arg *decl, struct isl_prefixes *prefixes)
static const char * skip_dash_dash(struct isl_arg *decl, const char *arg)
static void free_args(struct isl_arg *arg, void *opt)
static void print_default(struct isl_arg *decl, const char *def, int pos)
void isl_args_set_defaults(struct isl_args *args, void *opt)
static void print_version_and_exit(struct isl_arg *decl)
static void print_choice_help(struct isl_arg *decl, struct isl_prefixes *prefixes, void *opt)
static int wrap_msg(const char *s, int indent, int pos)
static int print_argument_name(struct isl_arg *decl, const char *name, int pos)
static void set_default_choice(struct isl_arg *arg, void *opt)
static int next_arg(struct isl_arg *arg, int a)
void isl_args_free(struct isl_args *args, void *opt)
static void print_int_help(struct isl_arg *decl, struct isl_prefixes *prefixes, void *opt)
int isl_args_parse(struct isl_args *args, int argc, char **argv, void *opt, unsigned flags)
static int parse_bool_option(struct isl_arg *decl, char **arg, struct isl_prefixes *prefixes, void *opt)
static int any_version(struct isl_arg *decl)
static void set_default_bool(struct isl_arg *arg, void *opt)
static void set_default_child(struct isl_arg *arg, void *opt)
static const char * skip_name(struct isl_arg *decl, const char *arg, struct isl_prefixes *prefixes, int need_argument, int *has_argument)
static void print_default_flags(struct isl_arg *decl, void *opt, int pos)
static void print_str_help(struct isl_arg *decl, struct isl_prefixes *prefixes, void *opt)
static void free_user(struct isl_arg *arg, void *opt)
static void free_child(struct isl_arg *arg, void *opt)
static int drop_argument(int argc, char **argv, int drop, int n)
const void * isl_memrchr(const void *s, int c, size_t n)
static int add_prefix(struct isl_prefixes *prefixes, const char *prefix)
static void set_default_ulong(struct isl_arg *arg, void *opt)
static int parse_long_option(struct isl_arg *decl, char **arg, struct isl_prefixes *prefixes, void *opt)
static int parse_str_list_option(struct isl_arg *decl, char **arg, struct isl_prefixes *prefixes, void *opt)
static int parse_int_option(struct isl_arg *decl, char **arg, struct isl_prefixes *prefixes, void *opt)
static void print_help(struct isl_arg *arg, struct isl_prefixes *prefixes, void *opt)
static void set_default_str(struct isl_arg *arg, void *opt)
static int parse_ulong_option(struct isl_arg *decl, char **arg, struct isl_prefixes *prefixes, void *opt)
static const char * prog_name(const char *prog)
static int parse_str_option(struct isl_arg *decl, char **arg, struct isl_prefixes *prefixes, void *opt)
static int parse_child_option(struct isl_arg *decl, char **arg, struct isl_prefixes *prefixes, void *opt)
static int parse_option(struct isl_arg *decl, char **arg, struct isl_prefixes *prefixes, void *opt)
static int set_flag(struct isl_arg *decl, unsigned *val, const char *flag, size_t len)
static void set_default_str_list(struct isl_arg *arg, void *opt)
static void set_default_int(struct isl_arg *arg, void *opt)
static void print_flags_help(struct isl_arg *decl, struct isl_prefixes *prefixes, void *opt)
static void set_default_flags(struct isl_arg *arg, void *opt)
static int parse_choice_option(struct isl_arg *decl, char **arg, struct isl_prefixes *prefixes, void *opt)
static int print_help_msg(struct isl_arg *decl, int pos)
static void check_help(struct isl_args *args, char *arg, char *prog, void *opt, unsigned flags)
static int parse_flags_option(struct isl_arg *decl, char **arg, struct isl_prefixes *prefixes, void *opt)
static int print_arg_help(struct isl_arg *decl, struct isl_prefixes *prefixes, int no)
static void drop(struct isl_coalesce_info *info)
static isl_bool no(const void *entry, const void *val)
static unsigned pos(__isl_keep isl_space *space, enum isl_dim_type type)
static void print_version(void)
static bool any(const std::vector< bool > &vector)
int(* set)(void *opt, unsigned val)
unsigned default_selected
void(* print_version)(void)
const char * argument_name
struct isl_arg_choice * choice
struct isl_arg::@0::@10 version
struct isl_arg::@0::@8 str_list