aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHannes Eder <hannes@hanneseder.net>2009-01-08 21:50:56 +0100
committerChristopher Li <sparse@chrisli.org>2009-07-17 23:06:04 +0000
commit2b287c89f01e9e51afb6f219ee2b1934bfc4a082 (patch)
treee71830ecfbbdfa75ab749d5e15d653e88054e602
parent507e53fbd95737f05615d1bd97803ce5457a4872 (diff)
downloadsparse-2b287c89f01e9e51afb6f219ee2b1934bfc4a082.tar.gz
refactor handle_switch_f
This also fixes a possible source of bugs in parsing other -f<whatever> options, i.e. -ftabstop=foo would set the option -ffoo. Signed-off-by: Hannes Eder <hannes@hanneseder.net>
-rw-r--r--lib.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/lib.c b/lib.c
index e0adc533..2b8d21ed 100644
--- a/lib.c
+++ b/lib.c
@@ -522,25 +522,34 @@ static char **handle_switch_O(char *arg, char **next)
return next;
}
+static char **handle_switch_ftabstop(char *arg, char **next)
+{
+ char *end;
+ unsigned long val;
+
+ if (*arg == '\0')
+ die("error: missing argument to \"-ftabstop=\"");
+
+ /* we silently ignore silly values */
+ val = strtoul(arg, &end, 10);
+ if (*end == '\0' && 1 <= val && val <= 100)
+ tabstop = val;
+
+ return next;
+}
+
static char **handle_switch_f(char *arg, char **next)
{
int flag = 1;
arg++;
- if (!strncmp(arg, "tabstop=", 8)) {
- char *end;
- unsigned long val;
- arg += 8;
+ if (!strncmp(arg, "tabstop=", 8))
+ return handle_switch_ftabstop(arg+8, next);
- if (*arg == '\0')
- die("error: missing argument to \"-ftabstop=\"");
+ /* handle switches w/ arguments above, boolean and only boolean below */
- /* we silently ignore silly values */
- val = strtoul(arg, &end, 10);
- if (*end == '\0' && 1 <= val && val <= 100)
- tabstop = val;
- } else if (!strncmp(arg, "no-", 3)) {
+ if (!strncmp(arg, "no-", 3)) {
flag = 0;
arg += 3;
}