From a05890e55c6f67157ee55618cf77a364fe734003 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Tue, 5 Aug 2008 15:09:30 -0400 Subject: Handle flags and booleans better in command parser We were occasionally misattributing one command for another --- src/libply/ply-command-parser.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/libply/ply-command-parser.c b/src/libply/ply-command-parser.c index 131c3af..e812298 100644 --- a/src/libply/ply-command-parser.c +++ b/src/libply/ply-command-parser.c @@ -589,19 +589,38 @@ ply_command_option_read_arguments (ply_command_option_t *option, assert (argument != NULL); if (argument_is_option (argument)) - return false; + { + if (option->type == PLY_COMMAND_OPTION_TYPE_BOOLEAN || + option->type == PLY_COMMAND_OPTION_TYPE_FLAG) + { + option->result.as_boolean = true; + return true; + } - ply_list_remove_node (arguments, node); + return false; + } switch (option->type) { case PLY_COMMAND_OPTION_TYPE_FLAG: case PLY_COMMAND_OPTION_TYPE_BOOLEAN: + + /* next argument isn't ours, so treat it like an unqualified + * flag + */ + if (rpmatch (argument) < 0) + { + option->result.as_boolean = true; + return true; + } + option->result.as_boolean = (bool) rpmatch (argument); + ply_list_remove_node (arguments, node); return true; case PLY_COMMAND_OPTION_TYPE_STRING: - option->result.as_string = strdup (argument); + option->result.as_string = strdup (argument); + ply_list_remove_node (arguments, node); return true; case PLY_COMMAND_OPTION_TYPE_INTEGER: @@ -625,7 +644,7 @@ ply_command_option_read_arguments (ply_command_option_t *option, return false; option->result.as_integer = (int) argument_as_long; - + ply_list_remove_node (arguments, node); return true; } } -- cgit