4 * Copyright (c) 2010 Nicholas Marriott <nicholas.marriott@gmail.com>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include <sys/types.h>
29 * Manipulate command arguments.
32 /* List of argument values. */
33 TAILQ_HEAD(args_values
, args_value
);
35 /* Single arguments flag. */
38 struct args_values values
;
42 #define ARGS_ENTRY_OPTIONAL_VALUE 0x1
44 RB_ENTRY(args_entry
) entry
;
47 /* Parsed argument flags and values. */
49 struct args_tree tree
;
51 struct args_value
*values
;
54 /* Prepared command state. */
55 struct args_command_state
{
56 struct cmd_list
*cmdlist
;
58 struct cmd_parse_input pi
;
61 static struct args_entry
*args_find(struct args
*, u_char
);
63 static int args_cmp(struct args_entry
*, struct args_entry
*);
64 RB_GENERATE_STATIC(args_tree
, args_entry
, entry
, args_cmp
);
66 /* Arguments tree comparison function. */
68 args_cmp(struct args_entry
*a1
, struct args_entry
*a2
)
70 return (a1
->flag
- a2
->flag
);
73 /* Find a flag in the arguments tree. */
74 static struct args_entry
*
75 args_find(struct args
*args
, u_char flag
)
77 struct args_entry entry
;
80 return (RB_FIND(args_tree
, &args
->tree
, &entry
));
85 args_copy_value(struct args_value
*to
, struct args_value
*from
)
87 to
->type
= from
->type
;
92 to
->cmdlist
= from
->cmdlist
;
93 to
->cmdlist
->references
++;
96 to
->string
= xstrdup(from
->string
);
101 /* Type to string. */
103 args_type_to_string (enum args_type type
)
117 /* Get value as string. */
119 args_value_as_string(struct args_value
*value
)
121 switch (value
->type
) {
125 if (value
->cached
== NULL
)
126 value
->cached
= cmd_list_print(value
->cmdlist
, 0);
127 return (value
->cached
);
129 return (value
->string
);
131 fatalx("unexpected argument type");
134 /* Create an empty arguments set. */
140 args
= xcalloc(1, sizeof *args
);
141 RB_INIT(&args
->tree
);
145 /* Parse a single flag. */
147 args_parse_flag_argument(struct args_value
*values
, u_int count
, char **cause
,
148 struct args
*args
, u_int
*i
, const char *string
, int flag
,
149 int optional_argument
)
151 struct args_value
*argument
, *new;
154 new = xcalloc(1, sizeof *new);
155 if (*string
!= '\0') {
156 new->type
= ARGS_STRING
;
157 new->string
= xstrdup(string
);
164 argument
= &values
[*i
];
165 if (argument
->type
!= ARGS_STRING
) {
166 xasprintf(cause
, "-%c argument must be a string", flag
);
170 if (argument
== NULL
) {
171 if (optional_argument
) {
172 log_debug("%s: -%c (optional)", __func__
, flag
);
173 args_set(args
, flag
, NULL
, ARGS_ENTRY_OPTIONAL_VALUE
);
174 return (0); /* either - or end */
176 xasprintf(cause
, "-%c expects an argument", flag
);
179 args_copy_value(new, argument
);
183 s
= args_value_as_string(new);
184 log_debug("%s: -%c = %s", __func__
, flag
, s
);
185 args_set(args
, flag
, new, 0);
189 /* Parse flags argument. */
191 args_parse_flags(const struct args_parse
*parse
, struct args_value
*values
,
192 u_int count
, char **cause
, struct args
*args
, u_int
*i
)
194 struct args_value
*value
;
196 const char *found
, *string
;
197 int optional_argument
;
200 if (value
->type
!= ARGS_STRING
)
203 string
= value
->string
;
204 log_debug("%s: next %s", __func__
, string
);
205 if (*string
++ != '-' || *string
== '\0')
208 if (string
[0] == '-' && string
[1] == '\0')
217 if (!isalnum(flag
)) {
218 xasprintf(cause
, "invalid flag -%c", flag
);
222 found
= strchr(parse
->template, flag
);
224 xasprintf(cause
, "unknown flag -%c", flag
);
227 if (found
[1] != ':') {
228 log_debug("%s: -%c", __func__
, flag
);
229 args_set(args
, flag
, NULL
, 0);
232 optional_argument
= (found
[2] == ':');
233 return (args_parse_flag_argument(values
, count
, cause
, args
, i
,
234 string
, flag
, optional_argument
));
238 /* Parse arguments into a new argument set. */
240 args_parse(const struct args_parse
*parse
, struct args_value
*values
,
241 u_int count
, char **cause
)
245 enum args_parse_type type
;
246 struct args_value
*value
, *new;
251 return (args_create());
253 args
= args_create();
254 for (i
= 1; i
< count
; /* nothing */) {
255 stop
= args_parse_flags(parse
, values
, count
, cause
, args
, &i
);
263 log_debug("%s: flags end at %u of %u", __func__
, i
, count
);
265 for (/* nothing */; i
< count
; i
++) {
268 s
= args_value_as_string(value
);
269 log_debug("%s: %u = %s (type %s)", __func__
, i
, s
,
270 args_type_to_string (value
->type
));
272 if (parse
->cb
!= NULL
) {
273 type
= parse
->cb(args
, args
->count
, cause
);
274 if (type
== ARGS_PARSE_INVALID
) {
279 type
= ARGS_PARSE_STRING
;
281 args
->values
= xrecallocarray(args
->values
,
282 args
->count
, args
->count
+ 1, sizeof *args
->values
);
283 new = &args
->values
[args
->count
++];
286 case ARGS_PARSE_INVALID
:
287 fatalx("unexpected argument type");
288 case ARGS_PARSE_STRING
:
289 if (value
->type
!= ARGS_STRING
) {
291 "argument %u must be \"string\"",
296 args_copy_value(new, value
);
298 case ARGS_PARSE_COMMANDS_OR_STRING
:
299 args_copy_value(new, value
);
301 case ARGS_PARSE_COMMANDS
:
302 if (value
->type
!= ARGS_COMMANDS
) {
304 "argument %u must be { commands }",
309 args_copy_value(new, value
);
315 if (parse
->lower
!= -1 && args
->count
< (u_int
)parse
->lower
) {
317 "too few arguments (need at least %u)",
322 if (parse
->upper
!= -1 && args
->count
> (u_int
)parse
->upper
) {
324 "too many arguments (need at most %u)",
332 /* Copy and expand a value. */
334 args_copy_copy_value(struct args_value
*to
, struct args_value
*from
, int argc
,
340 to
->type
= from
->type
;
341 switch (from
->type
) {
345 expanded
= xstrdup(from
->string
);
346 for (i
= 0; i
< argc
; i
++) {
347 s
= cmd_template_replace(expanded
, argv
[i
], i
+ 1);
351 to
->string
= expanded
;
354 to
->cmdlist
= cmd_list_copy(from
->cmdlist
, argc
, argv
);
359 /* Copy an arguments set. */
361 args_copy(struct args
*args
, int argc
, char **argv
)
363 struct args
*new_args
;
364 struct args_entry
*entry
;
365 struct args_value
*value
, *new_value
;
368 cmd_log_argv(argc
, argv
, "%s", __func__
);
370 new_args
= args_create();
371 RB_FOREACH(entry
, args_tree
, &args
->tree
) {
372 if (TAILQ_EMPTY(&entry
->values
)) {
373 for (i
= 0; i
< entry
->count
; i
++)
374 args_set(new_args
, entry
->flag
, NULL
, 0);
377 TAILQ_FOREACH(value
, &entry
->values
, entry
) {
378 new_value
= xcalloc(1, sizeof *new_value
);
379 args_copy_copy_value(new_value
, value
, argc
, argv
);
380 args_set(new_args
, entry
->flag
, new_value
, 0);
383 if (args
->count
== 0)
385 new_args
->count
= args
->count
;
386 new_args
->values
= xcalloc(args
->count
, sizeof *new_args
->values
);
387 for (i
= 0; i
< args
->count
; i
++) {
388 new_value
= &new_args
->values
[i
];
389 args_copy_copy_value(new_value
, &args
->values
[i
], argc
, argv
);
396 args_free_value(struct args_value
*value
)
398 switch (value
->type
) {
405 cmd_list_free(value
->cmdlist
);
413 args_free_values(struct args_value
*values
, u_int count
)
417 for (i
= 0; i
< count
; i
++)
418 args_free_value(&values
[i
]);
421 /* Free an arguments set. */
423 args_free(struct args
*args
)
425 struct args_entry
*entry
;
426 struct args_entry
*entry1
;
427 struct args_value
*value
;
428 struct args_value
*value1
;
430 args_free_values(args
->values
, args
->count
);
433 RB_FOREACH_SAFE(entry
, args_tree
, &args
->tree
, entry1
) {
434 RB_REMOVE(args_tree
, &args
->tree
, entry
);
435 TAILQ_FOREACH_SAFE(value
, &entry
->values
, entry
, value1
) {
436 TAILQ_REMOVE(&entry
->values
, value
, entry
);
437 args_free_value(value
);
446 /* Convert arguments to vector. */
448 args_to_vector(struct args
*args
, int *argc
, char ***argv
)
456 for (i
= 0; i
< args
->count
; i
++) {
457 switch (args
->values
[i
].type
) {
461 cmd_append_argv(argc
, argv
, args
->values
[i
].string
);
464 s
= cmd_list_print(args
->values
[i
].cmdlist
, 0);
465 cmd_append_argv(argc
, argv
, s
);
472 /* Convert arguments from vector. */
474 args_from_vector(int argc
, char **argv
)
476 struct args_value
*values
;
479 values
= xcalloc(argc
, sizeof *values
);
480 for (i
= 0; i
< argc
; i
++) {
481 values
[i
].type
= ARGS_STRING
;
482 values
[i
].string
= xstrdup(argv
[i
]);
488 static void printflike(3, 4)
489 args_print_add(char **buf
, size_t *len
, const char *fmt
, ...)
496 slen
= xvasprintf(&s
, fmt
, ap
);
500 *buf
= xrealloc(*buf
, *len
);
502 strlcat(*buf
, s
, *len
);
506 /* Add value to string. */
508 args_print_add_value(char **buf
, size_t *len
, struct args_value
*value
)
510 char *expanded
= NULL
;
513 args_print_add(buf
, len
, " ");
515 switch (value
->type
) {
519 expanded
= cmd_list_print(value
->cmdlist
, 0);
520 args_print_add(buf
, len
, "{ %s }", expanded
);
523 expanded
= args_escape(value
->string
);
524 args_print_add(buf
, len
, "%s", expanded
);
530 /* Print a set of arguments. */
532 args_print(struct args
*args
)
537 struct args_entry
*entry
;
538 struct args_entry
*last
= NULL
;
539 struct args_value
*value
;
542 buf
= xcalloc(1, len
);
544 /* Process the flags first. */
545 RB_FOREACH(entry
, args_tree
, &args
->tree
) {
546 if (entry
->flags
& ARGS_ENTRY_OPTIONAL_VALUE
)
548 if (!TAILQ_EMPTY(&entry
->values
))
552 args_print_add(&buf
, &len
, "-");
553 for (j
= 0; j
< entry
->count
; j
++)
554 args_print_add(&buf
, &len
, "%c", entry
->flag
);
557 /* Then the flags with arguments. */
558 RB_FOREACH(entry
, args_tree
, &args
->tree
) {
559 if (entry
->flags
& ARGS_ENTRY_OPTIONAL_VALUE
) {
561 args_print_add(&buf
, &len
, " -%c", entry
->flag
);
563 args_print_add(&buf
, &len
, "-%c", entry
->flag
);
567 if (TAILQ_EMPTY(&entry
->values
))
569 TAILQ_FOREACH(value
, &entry
->values
, entry
) {
571 args_print_add(&buf
, &len
, " -%c", entry
->flag
);
573 args_print_add(&buf
, &len
, "-%c", entry
->flag
);
574 args_print_add_value(&buf
, &len
, value
);
578 if (last
&& (last
->flags
& ARGS_ENTRY_OPTIONAL_VALUE
))
579 args_print_add(&buf
, &len
, " --");
581 /* And finally the argument vector. */
582 for (i
= 0; i
< args
->count
; i
++)
583 args_print_add_value(&buf
, &len
, &args
->values
[i
]);
588 /* Escape an argument. */
590 args_escape(const char *s
)
592 static const char dquoted
[] = " #';${}%";
593 static const char squoted
[] = " \"";
594 char *escaped
, *result
;
595 int flags
, quotes
= 0;
598 xasprintf(&result
, "''");
601 if (s
[strcspn(s
, dquoted
)] != '\0')
603 else if (s
[strcspn(s
, squoted
)] != '\0')
608 (quotes
!= 0 || s
[0] == '~')) {
609 xasprintf(&escaped
, "\\%c", s
[0]);
613 flags
= VIS_OCTAL
|VIS_CSTYLE
|VIS_TAB
|VIS_NL
;
616 utf8_stravis(&escaped
, s
, flags
);
619 xasprintf(&result
, "'%s'", escaped
);
620 else if (quotes
== '"') {
622 xasprintf(&result
, "\"\\%s\"", escaped
);
624 xasprintf(&result
, "\"%s\"", escaped
);
627 xasprintf(&result
, "\\%s", escaped
);
629 result
= xstrdup(escaped
);
635 /* Return if an argument is present. */
637 args_has(struct args
*args
, u_char flag
)
639 struct args_entry
*entry
;
641 entry
= args_find(args
, flag
);
644 return (entry
->count
);
647 /* Set argument value in the arguments tree. */
649 args_set(struct args
*args
, u_char flag
, struct args_value
*value
, int flags
)
651 struct args_entry
*entry
;
653 entry
= args_find(args
, flag
);
655 entry
= xcalloc(1, sizeof *entry
);
658 entry
->flags
= flags
;
659 TAILQ_INIT(&entry
->values
);
660 RB_INSERT(args_tree
, &args
->tree
, entry
);
663 if (value
!= NULL
&& value
->type
!= ARGS_NONE
)
664 TAILQ_INSERT_TAIL(&entry
->values
, value
, entry
);
667 /* Get argument value. Will be NULL if it isn't present. */
669 args_get(struct args
*args
, u_char flag
)
671 struct args_entry
*entry
;
673 if ((entry
= args_find(args
, flag
)) == NULL
)
675 if (TAILQ_EMPTY(&entry
->values
))
677 return (TAILQ_LAST(&entry
->values
, args_values
)->string
);
680 /* Get first argument. */
682 args_first(struct args
*args
, struct args_entry
**entry
)
684 *entry
= RB_MIN(args_tree
, &args
->tree
);
687 return ((*entry
)->flag
);
690 /* Get next argument. */
692 args_next(struct args_entry
**entry
)
694 *entry
= RB_NEXT(args_tree
, &args
->tree
, *entry
);
697 return ((*entry
)->flag
);
700 /* Get argument count. */
702 args_count(struct args
*args
)
704 return (args
->count
);
707 /* Get argument values. */
709 args_values(struct args
*args
)
711 return (args
->values
);
714 /* Get argument value. */
716 args_value(struct args
*args
, u_int idx
)
718 if (idx
>= args
->count
)
720 return (&args
->values
[idx
]);
723 /* Return argument as string. */
725 args_string(struct args
*args
, u_int idx
)
727 if (idx
>= args
->count
)
729 return (args_value_as_string(&args
->values
[idx
]));
732 /* Make a command now. */
734 args_make_commands_now(struct cmd
*self
, struct cmdq_item
*item
, u_int idx
,
737 struct args_command_state
*state
;
739 struct cmd_list
*cmdlist
;
741 state
= args_make_commands_prepare(self
, item
, idx
, NULL
, 0, expand
);
742 cmdlist
= args_make_commands(state
, 0, NULL
, &error
);
743 if (cmdlist
== NULL
) {
744 cmdq_error(item
, "%s", error
);
748 cmdlist
->references
++;
749 args_make_commands_free(state
);
753 /* Save bits to make a command later. */
754 struct args_command_state
*
755 args_make_commands_prepare(struct cmd
*self
, struct cmdq_item
*item
, u_int idx
,
756 const char *default_command
, int wait
, int expand
)
758 struct args
*args
= cmd_get_args(self
);
759 struct cmd_find_state
*target
= cmdq_get_target(item
);
760 struct client
*tc
= cmdq_get_target_client(item
);
761 struct args_value
*value
;
762 struct args_command_state
*state
;
765 state
= xcalloc(1, sizeof *state
);
767 if (idx
< args
->count
) {
768 value
= &args
->values
[idx
];
769 if (value
->type
== ARGS_COMMANDS
) {
770 state
->cmdlist
= value
->cmdlist
;
771 state
->cmdlist
->references
++;
776 if (default_command
== NULL
)
777 fatalx("argument out of range");
778 cmd
= default_command
;
783 state
->cmd
= format_single_from_target(item
, cmd
);
785 state
->cmd
= xstrdup(cmd
);
786 log_debug("%s: %s", __func__
, state
->cmd
);
789 state
->pi
.item
= item
;
790 cmd_get_source(self
, &state
->pi
.file
, &state
->pi
.line
);
792 if (state
->pi
.c
!= NULL
)
793 state
->pi
.c
->references
++;
794 cmd_find_copy_state(&state
->pi
.fs
, target
);
799 /* Return argument as command. */
801 args_make_commands(struct args_command_state
*state
, int argc
, char **argv
,
804 struct cmd_parse_result
*pr
;
808 if (state
->cmdlist
!= NULL
) {
810 return (state
->cmdlist
);
811 return (cmd_list_copy(state
->cmdlist
, argc
, argv
));
814 cmd
= xstrdup(state
->cmd
);
815 log_debug("%s: %s", __func__
, cmd
);
816 cmd_log_argv(argc
, argv
, __func__
);
817 for (i
= 0; i
< argc
; i
++) {
818 new_cmd
= cmd_template_replace(cmd
, argv
[i
], i
+ 1);
819 log_debug("%s: %%%u %s: %s", __func__
, i
+ 1, argv
[i
], new_cmd
);
823 log_debug("%s: %s", __func__
, cmd
);
825 pr
= cmd_parse_from_string(cmd
, &state
->pi
);
827 switch (pr
->status
) {
828 case CMD_PARSE_ERROR
:
831 case CMD_PARSE_SUCCESS
:
832 return (pr
->cmdlist
);
834 fatalx("invalid parse return state");
837 /* Free commands state. */
839 args_make_commands_free(struct args_command_state
*state
)
841 if (state
->cmdlist
!= NULL
)
842 cmd_list_free(state
->cmdlist
);
843 if (state
->pi
.c
!= NULL
)
844 server_client_unref(state
->pi
.c
);
849 /* Get prepared command. */
851 args_make_commands_get_command(struct args_command_state
*state
)
857 if (state
->cmdlist
!= NULL
) {
858 first
= cmd_list_first(state
->cmdlist
);
860 return (xstrdup(""));
861 return (xstrdup(cmd_get_entry(first
)->name
));
863 n
= strcspn(state
->cmd
, " ,");
864 xasprintf(&s
, "%.*s", n
, state
->cmd
);
868 /* Get first value in argument. */
870 args_first_value(struct args
*args
, u_char flag
)
872 struct args_entry
*entry
;
874 if ((entry
= args_find(args
, flag
)) == NULL
)
876 return (TAILQ_FIRST(&entry
->values
));
879 /* Get next value in argument. */
881 args_next_value(struct args_value
*value
)
883 return (TAILQ_NEXT(value
, entry
));
886 /* Convert an argument value to a number. */
888 args_strtonum(struct args
*args
, u_char flag
, long long minval
,
889 long long maxval
, char **cause
)
893 struct args_entry
*entry
;
894 struct args_value
*value
;
896 if ((entry
= args_find(args
, flag
)) == NULL
) {
897 *cause
= xstrdup("missing");
900 value
= TAILQ_LAST(&entry
->values
, args_values
);
902 value
->type
!= ARGS_STRING
||
903 value
->string
== NULL
) {
904 *cause
= xstrdup("missing");
908 ll
= strtonum(value
->string
, minval
, maxval
, &errstr
);
909 if (errstr
!= NULL
) {
910 *cause
= xstrdup(errstr
);
918 /* Convert an argument value to a number, and expand formats. */
920 args_strtonum_and_expand(struct args
*args
, u_char flag
, long long minval
,
921 long long maxval
, struct cmdq_item
*item
, char **cause
)
926 struct args_entry
*entry
;
927 struct args_value
*value
;
929 if ((entry
= args_find(args
, flag
)) == NULL
) {
930 *cause
= xstrdup("missing");
933 value
= TAILQ_LAST(&entry
->values
, args_values
);
935 value
->type
!= ARGS_STRING
||
936 value
->string
== NULL
) {
937 *cause
= xstrdup("missing");
941 formatted
= format_single_from_target(item
, value
->string
);
942 ll
= strtonum(formatted
, minval
, maxval
, &errstr
);
944 if (errstr
!= NULL
) {
945 *cause
= xstrdup(errstr
);
953 /* Convert an argument to a number which may be a percentage. */
955 args_percentage(struct args
*args
, u_char flag
, long long minval
,
956 long long maxval
, long long curval
, char **cause
)
959 struct args_entry
*entry
;
961 if ((entry
= args_find(args
, flag
)) == NULL
) {
962 *cause
= xstrdup("missing");
965 if (TAILQ_EMPTY(&entry
->values
)) {
966 *cause
= xstrdup("empty");
969 value
= TAILQ_LAST(&entry
->values
, args_values
)->string
;
970 return (args_string_percentage(value
, minval
, maxval
, curval
, cause
));
973 /* Convert a string to a number which may be a percentage. */
975 args_string_percentage(const char *value
, long long minval
, long long maxval
,
976 long long curval
, char **cause
)
980 size_t valuelen
= strlen(value
);
984 *cause
= xstrdup("empty");
987 if (value
[valuelen
- 1] == '%') {
988 copy
= xstrdup(value
);
989 copy
[valuelen
- 1] = '\0';
991 ll
= strtonum(copy
, 0, 100, &errstr
);
993 if (errstr
!= NULL
) {
994 *cause
= xstrdup(errstr
);
997 ll
= (curval
* ll
) / 100;
999 *cause
= xstrdup("too small");
1003 *cause
= xstrdup("too large");
1007 ll
= strtonum(value
, minval
, maxval
, &errstr
);
1008 if (errstr
!= NULL
) {
1009 *cause
= xstrdup(errstr
);
1019 * Convert an argument to a number which may be a percentage, and expand
1023 args_percentage_and_expand(struct args
*args
, u_char flag
, long long minval
,
1024 long long maxval
, long long curval
, struct cmdq_item
*item
, char **cause
)
1027 struct args_entry
*entry
;
1029 if ((entry
= args_find(args
, flag
)) == NULL
) {
1030 *cause
= xstrdup("missing");
1033 if (TAILQ_EMPTY(&entry
->values
)) {
1034 *cause
= xstrdup("empty");
1037 value
= TAILQ_LAST(&entry
->values
, args_values
)->string
;
1038 return (args_string_percentage_and_expand(value
, minval
, maxval
, curval
,
1043 * Convert a string to a number which may be a percentage, and expand formats.
1046 args_string_percentage_and_expand(const char *value
, long long minval
,
1047 long long maxval
, long long curval
, struct cmdq_item
*item
, char **cause
)
1051 size_t valuelen
= strlen(value
);
1054 if (value
[valuelen
- 1] == '%') {
1055 copy
= xstrdup(value
);
1056 copy
[valuelen
- 1] = '\0';
1058 f
= format_single_from_target(item
, copy
);
1059 ll
= strtonum(f
, 0, 100, &errstr
);
1062 if (errstr
!= NULL
) {
1063 *cause
= xstrdup(errstr
);
1066 ll
= (curval
* ll
) / 100;
1068 *cause
= xstrdup("too small");
1072 *cause
= xstrdup("too large");
1076 f
= format_single_from_target(item
, value
);
1077 ll
= strtonum(f
, minval
, maxval
, &errstr
);
1079 if (errstr
!= NULL
) {
1080 *cause
= xstrdup(errstr
);