*/
static int flt_ot_parse_cfg_check(const char *file, int linenum, char **args, const void *id, const struct flt_ot_parse_data *parse_data, size_t parse_data_size, const struct flt_ot_parse_data **pdata, char **err)
{
- int i, retval = ERR_NONE;
+ int i, argc, retval = ERR_NONE;
FLT_OT_FUNC("\"%s\", %d, %p, %p, %p, %zu, %p:%p, %p:%p", file, linenum, args, id, parse_data, parse_data_size, FLT_OT_DPTR_ARGS(pdata), FLT_OT_DPTR_ARGS(err));
*pdata = NULL;
+ /* First check here if args[0] is the correct keyword. */
for (i = 0; (*pdata == NULL) && (i < parse_data_size); i++)
if (strcmp(parse_data[i].name, args[0]) == 0)
*pdata = parse_data + i;
if (*pdata == NULL)
FLT_OT_PARSE_ERR(err, "'%s' : unknown keyword", args[0]);
+ else
+ argc = flt_ot_args_count(args);
if ((retval & ERR_CODE) || (id == NULL))
/* Do nothing. */;
* line than is required.
*/
if (!(retval & ERR_CODE))
- for (i = 1; i < (*pdata)->args_min; i++)
- if (!FLT_OT_ARG_ISVALID(i))
- FLT_OT_PARSE_ERR(err, "'%s' : too few arguments (use '%s%s')", args[0], (*pdata)->name, (*pdata)->usage);
+ if (argc < (*pdata)->args_min)
+ FLT_OT_PARSE_ERR(err, "'%s' : too few arguments (use '%s%s')", args[0], (*pdata)->name, (*pdata)->usage);
/*
* Checking that more arguments are specified in the configuration
* line than the maximum allowed.
*/
- if (!(retval & ERR_CODE) && ((*pdata)->args_max > 0)) {
- for ( ; (i <= (*pdata)->args_max) && FLT_OT_ARG_ISVALID(i); i++);
-
- if (i > (*pdata)->args_max)
+ if (!(retval & ERR_CODE) && ((*pdata)->args_max > 0))
+ if (argc > (*pdata)->args_max)
FLT_OT_PARSE_ERR(err, "'%s' : too many arguments (use '%s%s')", args[0], (*pdata)->name, (*pdata)->usage);
- }
/* Checking that the first argument has only allowed characters. */
if (!(retval & ERR_CODE) && ((*pdata)->check_name > 0)) {
*/
void flt_ot_args_dump(char **args)
{
- int i, n;
+ int i, argc;
- for (n = 1; FLT_OT_ARG_ISVALID(n); n++);
+ argc = flt_ot_args_count(args);
- (void)fprintf(stderr, FLT_OT_DBG_FMT("%.*sargs[%d]: { '%s' "), dbg_indent_level, FLT_OT_DBG_INDENT, n, args[0]);
+ (void)fprintf(stderr, FLT_OT_DBG_FMT("%.*sargs[%d]: { '%s' "), dbg_indent_level, FLT_OT_DBG_INDENT, argc, args[0]);
- for (i = 1; FLT_OT_ARG_ISVALID(i); i++)
+ for (i = 1; i < argc; i++)
(void)fprintf(stderr, "'%s' ", args[i]);
(void)fprintf(stderr, "}\n");
*/
int flt_ot_args_count(char **args)
{
- int retval = 0;
-
- if (args != NULL)
- for ( ; FLT_OT_ARG_ISVALID(retval); retval++);
+ int i, retval = 0;
+
+ if (args == NULL)
+ return retval;
+
+ /*
+ * It is possible that some arguments within the configuration line
+ * are not specified; that is, they are set to a blank string.
+ *
+ * For example:
+ * keyword '' arg_2
+ *
+ * In that case the content of the args field will be like this:
+ * args[0]: 'keyword'
+ * args[1]: NULL pointer
+ * args[2]: 'arg_2'
+ * args[3 .. MAX_LINE_ARGS): NULL pointers
+ *
+ * The total number of arguments is the index of the last argument
+ * (increased by 1) that is not a NULL pointer.
+ */
+ for (i = 0; i < MAX_LINE_ARGS; i++)
+ if (FLT_OT_ARG_ISVALID(i))
+ retval = i + 1;
return retval;
}
*/
void flt_ot_args_to_str(char **args, int idx, char **str)
{
- int i;
+ int i, argc;
if ((args == NULL) || (*args == NULL))
return;
- for (i = idx; FLT_OT_ARG_ISVALID(i); i++)
- (void)memprintf(str, "%s%s%s", (*str == NULL) ? "" : *str, (i == idx) ? "" : " ", args[i]);
+ argc = flt_ot_args_count(args);
+
+ for (i = idx; i < argc; i++)
+ (void)memprintf(str, "%s%s%s", (*str == NULL) ? "" : *str, (i == idx) ? "" : " ", (args[i] == NULL) ? "" : args[i]);
}