diff options
author | Junio C Hamano <junkio@cox.net> | 2005-06-03 01:37:54 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-06-03 11:23:03 -0700 |
commit | 0e3994fa97e9876b571531444b97ae6e63fd744d (patch) | |
tree | f8ff146064f56528bc09efc7eafcc59f61fb344d /diff.c | |
parent | [PATCH] diff: Fix docs and add -O to diff-helper. (diff) | |
download | tgif-0e3994fa97e9876b571531444b97ae6e63fd744d.tar.xz |
[PATCH] diff: Clean up diff_scoreopt_parse().
This cleans up diff_scoreopt_parse() function that is used to
parse the fractional notation -B, -C and -M option takes. The
callers are modified to check for errors and complain. Earlier
they silently ignored malformed input and falled back on the
default.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'diff.c')
-rw-r--r-- | diff.c | 39 |
1 files changed, 39 insertions, 0 deletions
@@ -589,6 +589,45 @@ void diff_setup(int flags) } +static int parse_num(const char **cp_p) +{ + int num, scale, ch, cnt; + const char *cp = *cp_p; + + cnt = num = 0; + scale = 1; + while ('0' <= (ch = *cp) && ch <= '9') { + if (cnt++ < 5) { + /* We simply ignore more than 5 digits precision. */ + scale *= 10; + num = num * 10 + ch - '0'; + } + *cp++; + } + *cp_p = cp; + + /* user says num divided by scale and we say internally that + * is MAX_SCORE * num / scale. + */ + return (MAX_SCORE * num / scale); +} + +int diff_scoreopt_parse(const char *opt) +{ + int opt1, cmd; + + if (*opt++ != '-') + return -1; + cmd = *opt++; + if (cmd != 'M' && cmd != 'C' && cmd != 'B') + return -1; /* that is not a -M, -C nor -B option */ + + opt1 = parse_num(&opt); + if (*opt != 0) + return -1; + return opt1; +} + struct diff_queue_struct diff_queued_diff; void diff_q(struct diff_queue_struct *queue, struct diff_filepair *dp) |