]>
git.proxmox.com Git - libgit2.git/blob - examples/args.h
1 #ifndef INCLUDE_examples_args_h__
2 #define INCLUDE_examples_args_h__
5 * Argument-processing helper structure
11 int opts_done
: 1; /**< Did we see a -- separator */
13 #define ARGS_INFO_INIT { argc, argv, 0, 0 }
14 #define ARGS_CURRENT(args) args->argv[args->pos]
17 * Check if a string has the given prefix. Returns 0 if not prefixed
18 * or the length of the prefix if it is.
20 extern size_t is_prefixed(const char *str
, const char *pfx
);
23 * Match an integer string, returning 1 if matched, 0 if not.
25 extern int is_integer(int *out
, const char *str
, int allow_negative
);
28 * Check current `args` entry against `opt` string. If it matches
29 * exactly, take the next arg as a string; if it matches as a prefix with
30 * an equal sign, take the remainder as a string; if value not supplied,
31 * default value `def` will be given. otherwise return 0.
33 extern int optional_str_arg(
34 const char **out
, struct args_info
*args
, const char *opt
, const char *def
);
37 * Check current `args` entry against `opt` string. If it matches
38 * exactly, take the next arg as a string; if it matches as a prefix with
39 * an equal sign, take the remainder as a string; otherwise return 0.
41 extern int match_str_arg(
42 const char **out
, struct args_info
*args
, const char *opt
);
45 * Check current `args` entry against `opt` string parsing as uint16. If
46 * `opt` matches exactly, take the next arg as a uint16_t value; if `opt`
47 * is a prefix (equal sign optional), take the remainder of the arg as a
48 * uint16_t value; otherwise return 0.
50 extern int match_uint16_arg(
51 uint16_t *out
, struct args_info
*args
, const char *opt
);
54 * Check current `args` entry against `opt` string parsing as uint32. If
55 * `opt` matches exactly, take the next arg as a uint16_t value; if `opt`
56 * is a prefix (equal sign optional), take the remainder of the arg as a
57 * uint32_t value; otherwise return 0.
59 extern int match_uint32_arg(
60 uint32_t *out
, struct args_info
*args
, const char *opt
);
63 * Check current `args` entry against `opt` string parsing as int. If
64 * `opt` matches exactly, take the next arg as an int value; if it matches
65 * as a prefix (equal sign optional), take the remainder of the arg as a
66 * int value; otherwise return 0.
68 extern int match_int_arg(
69 int *out
, struct args_info
*args
, const char *opt
, int allow_negative
);
72 * Check current `args` entry against a "bool" `opt` (ie. --[no-]progress).
73 * If `opt` matches positively, out will be set to 1, or if `opt` matches
74 * negatively, out will be set to 0, and in both cases 1 will be returned.
75 * If neither the positive or the negative form of opt matched, out will be -1,
76 * and 0 will be returned.
78 extern int match_bool_arg(int *out
, struct args_info
*args
, const char *opt
);
81 * Check if we're processing past the single -- separator
83 extern int match_arg_separator(struct args_info
*args
);
86 * Consume all remaining arguments in a git_strarray
88 extern void strarray_from_args(git_strarray
*array
, struct args_info
*args
);