diff options
| author | Linquize <linquize@yahoo.com.hk> | 2014-10-12 15:52:53 +0800 |
|---|---|---|
| committer | Linquize <linquize@yahoo.com.hk> | 2014-10-12 19:25:20 +0800 |
| commit | d6bbcefce3a6daf6ee2ece329e9708ca44409252 (patch) | |
| tree | 65ee4d2273924a1d8e1e3561fb71077de4c4f816 /examples/common.c | |
| parent | 9e49cb7a4ba4f6961e3681cb59421cec04a50893 (diff) | |
| download | libgit2-d6bbcefce3a6daf6ee2ece329e9708ca44409252.tar.gz | |
describe: add example
Diffstat (limited to 'examples/common.c')
| -rw-r--r-- | examples/common.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/examples/common.c b/examples/common.c index a066c153c..0f25f3787 100644 --- a/examples/common.c +++ b/examples/common.c @@ -53,6 +53,33 @@ size_t is_prefixed(const char *str, const char *pfx) return strncmp(str, pfx, len) ? 0 : len; } +int optional_str_arg( + const char **out, struct args_info *args, const char *opt, const char *def) +{ + const char *found = args->argv[args->pos]; + size_t len = is_prefixed(found, opt); + + if (!len) + return 0; + + if (!found[len]) { + if (args->pos + 1 == args->argc) { + *out = def; + return 1; + } + args->pos += 1; + *out = args->argv[args->pos]; + return 1; + } + + if (found[len] == '=') { + *out = found + len + 1; + return 1; + } + + return 0; +} + int match_str_arg( const char **out, struct args_info *args, const char *opt) { |
