summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2016-08-16 11:01:09 +0200
committerPatrick Steinhardt <ps@pks.im>2016-10-10 09:04:42 +0200
commit5c2a8361d779477b4d3474c660157bd62e750fe2 (patch)
tree261e5d66ab68e5fdd88c63314d36e61663dd5918 /examples
parent7314da105532306dad21843c8997b746b02fa3ed (diff)
downloadlibgit2-5c2a8361d779477b4d3474c660157bd62e750fe2.tar.gz
examples: diff: parse correct types for line-diffopts
Diffstat (limited to 'examples')
-rw-r--r--examples/common.c19
-rw-r--r--examples/common.h9
-rw-r--r--examples/diff.c6
3 files changed, 31 insertions, 3 deletions
diff --git a/examples/common.c b/examples/common.c
index 0f25f3787..96f5eaa8e 100644
--- a/examples/common.c
+++ b/examples/common.c
@@ -146,6 +146,25 @@ int match_uint16_arg(
return 1;
}
+int match_uint32_arg(
+ uint32_t *out, struct args_info *args, const char *opt)
+{
+ const char *found = match_numeric_arg(args, opt);
+ uint16_t val;
+ char *endptr = NULL;
+
+ if (!found)
+ return 0;
+
+ val = (uint32_t)strtoul(found, &endptr, 0);
+ if (!endptr || *endptr != '\0')
+ fatal("expected number after argument", opt);
+
+ if (out)
+ *out = val;
+ return 1;
+}
+
static int match_int_internal(
int *out, const char *str, int allow_negative, const char *opt)
{
diff --git a/examples/common.h b/examples/common.h
index b9fa37ce9..adea0d318 100644
--- a/examples/common.h
+++ b/examples/common.h
@@ -73,6 +73,15 @@ extern int match_uint16_arg(
uint16_t *out, struct args_info *args, const char *opt);
/**
+ * Check current `args` entry against `opt` string parsing as uint32. If
+ * `opt` matches exactly, take the next arg as a uint16_t value; if `opt`
+ * is a prefix (equal sign optional), take the remainder of the arg as a
+ * uint32_t value; otherwise return 0.
+ */
+extern int match_uint32_arg(
+ uint32_t *out, struct args_info *args, const char *opt);
+
+/**
* Check current `args` entry against `opt` string parsing as int. If
* `opt` matches exactly, take the next arg as an int value; if it matches
* as a prefix (equal sign optional), take the remainder of the arg as a
diff --git a/examples/diff.c b/examples/diff.c
index b69cb2218..9a4f7a59f 100644
--- a/examples/diff.c
+++ b/examples/diff.c
@@ -293,11 +293,11 @@ static void parse_opts(struct opts *o, int argc, char *argv[])
else if (is_prefixed(a, "-B") || is_prefixed(a, "--break-rewrites"))
/* TODO: parse thresholds */
o->findopts.flags |= GIT_DIFF_FIND_REWRITES;
- else if (!match_uint16_arg(
+ else if (!match_uint32_arg(
&o->diffopts.context_lines, &args, "-U") &&
- !match_uint16_arg(
+ !match_uint32_arg(
&o->diffopts.context_lines, &args, "--unified") &&
- !match_uint16_arg(
+ !match_uint32_arg(
&o->diffopts.interhunk_lines, &args, "--inter-hunk-context") &&
!match_uint16_arg(
&o->diffopts.id_abbrev, &args, "--abbrev") &&