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
;
766 state
= xcalloc(1, sizeof *state
);
768 if (idx
< args
->count
) {
769 value
= &args
->values
[idx
];
770 if (value
->type
== ARGS_COMMANDS
) {
771 state
->cmdlist
= value
->cmdlist
;
772 state
->cmdlist
->references
++;
777 if (default_command
== NULL
)
778 fatalx("argument out of range");
779 cmd
= default_command
;
784 state
->cmd
= format_single_from_target(item
, cmd
);
786 state
->cmd
= xstrdup(cmd
);
787 log_debug("%s: %s", __func__
, state
->cmd
);
790 state
->pi
.item
= item
;
791 cmd_get_source(self
, &file
, &state
->pi
.line
);
793 state
->pi
.file
= xstrdup(file
);
795 if (state
->pi
.c
!= NULL
)
796 state
->pi
.c
->references
++;
797 cmd_find_copy_state(&state
->pi
.fs
, target
);
802 /* Return argument as command. */
804 args_make_commands(struct args_command_state
*state
, int argc
, char **argv
,
807 struct cmd_parse_result
*pr
;
811 if (state
->cmdlist
!= NULL
) {
813 return (state
->cmdlist
);
814 return (cmd_list_copy(state
->cmdlist
, argc
, argv
));
817 cmd
= xstrdup(state
->cmd
);
818 log_debug("%s: %s", __func__
, cmd
);
819 cmd_log_argv(argc
, argv
, __func__
);
820 for (i
= 0; i
< argc
; i
++) {
821 new_cmd
= cmd_template_replace(cmd
, argv
[i
], i
+ 1);
822 log_debug("%s: %%%u %s: %s", __func__
, i
+ 1, argv
[i
], new_cmd
);
826 log_debug("%s: %s", __func__
, cmd
);
828 pr
= cmd_parse_from_string(cmd
, &state
->pi
);
830 switch (pr
->status
) {
831 case CMD_PARSE_ERROR
:
834 case CMD_PARSE_SUCCESS
:
835 return (pr
->cmdlist
);
837 fatalx("invalid parse return state");
840 /* Free commands state. */
842 args_make_commands_free(struct args_command_state
*state
)
844 if (state
->cmdlist
!= NULL
)
845 cmd_list_free(state
->cmdlist
);
846 if (state
->pi
.c
!= NULL
)
847 server_client_unref(state
->pi
.c
);
848 free((void *)state
->pi
.file
);
853 /* Get prepared command. */
855 args_make_commands_get_command(struct args_command_state
*state
)
861 if (state
->cmdlist
!= NULL
) {
862 first
= cmd_list_first(state
->cmdlist
);
864 return (xstrdup(""));
865 return (xstrdup(cmd_get_entry(first
)->name
));
867 n
= strcspn(state
->cmd
, " ,");
868 xasprintf(&s
, "%.*s", n
, state
->cmd
);
872 /* Get first value in argument. */
874 args_first_value(struct args
*args
, u_char flag
)
876 struct args_entry
*entry
;
878 if ((entry
= args_find(args
, flag
)) == NULL
)
880 return (TAILQ_FIRST(&entry
->values
));
883 /* Get next value in argument. */
885 args_next_value(struct args_value
*value
)
887 return (TAILQ_NEXT(value
, entry
));
890 /* Convert an argument value to a number. */
892 args_strtonum(struct args
*args
, u_char flag
, long long minval
,
893 long long maxval
, char **cause
)
897 struct args_entry
*entry
;
898 struct args_value
*value
;
900 if ((entry
= args_find(args
, flag
)) == NULL
) {
901 *cause
= xstrdup("missing");
904 value
= TAILQ_LAST(&entry
->values
, args_values
);
906 value
->type
!= ARGS_STRING
||
907 value
->string
== NULL
) {
908 *cause
= xstrdup("missing");
912 ll
= strtonum(value
->string
, minval
, maxval
, &errstr
);
913 if (errstr
!= NULL
) {
914 *cause
= xstrdup(errstr
);
922 /* Convert an argument value to a number, and expand formats. */
924 args_strtonum_and_expand(struct args
*args
, u_char flag
, long long minval
,
925 long long maxval
, struct cmdq_item
*item
, char **cause
)
930 struct args_entry
*entry
;
931 struct args_value
*value
;
933 if ((entry
= args_find(args
, flag
)) == NULL
) {
934 *cause
= xstrdup("missing");
937 value
= TAILQ_LAST(&entry
->values
, args_values
);
939 value
->type
!= ARGS_STRING
||
940 value
->string
== NULL
) {
941 *cause
= xstrdup("missing");
945 formatted
= format_single_from_target(item
, value
->string
);
946 ll
= strtonum(formatted
, minval
, maxval
, &errstr
);
948 if (errstr
!= NULL
) {
949 *cause
= xstrdup(errstr
);
957 /* Convert an argument to a number which may be a percentage. */
959 args_percentage(struct args
*args
, u_char flag
, long long minval
,
960 long long maxval
, long long curval
, char **cause
)
963 struct args_entry
*entry
;
965 if ((entry
= args_find(args
, flag
)) == NULL
) {
966 *cause
= xstrdup("missing");
969 if (TAILQ_EMPTY(&entry
->values
)) {
970 *cause
= xstrdup("empty");
973 value
= TAILQ_LAST(&entry
->values
, args_values
)->string
;
974 return (args_string_percentage(value
, minval
, maxval
, curval
, cause
));
977 /* Convert a string to a number which may be a percentage. */
979 args_string_percentage(const char *value
, long long minval
, long long maxval
,
980 long long curval
, char **cause
)
984 size_t valuelen
= strlen(value
);
988 *cause
= xstrdup("empty");
991 if (value
[valuelen
- 1] == '%') {
992 copy
= xstrdup(value
);
993 copy
[valuelen
- 1] = '\0';
995 ll
= strtonum(copy
, 0, 100, &errstr
);
997 if (errstr
!= NULL
) {
998 *cause
= xstrdup(errstr
);
1001 ll
= (curval
* ll
) / 100;
1003 *cause
= xstrdup("too small");
1007 *cause
= xstrdup("too large");
1011 ll
= strtonum(value
, minval
, maxval
, &errstr
);
1012 if (errstr
!= NULL
) {
1013 *cause
= xstrdup(errstr
);
1023 * Convert an argument to a number which may be a percentage, and expand
1027 args_percentage_and_expand(struct args
*args
, u_char flag
, long long minval
,
1028 long long maxval
, long long curval
, struct cmdq_item
*item
, char **cause
)
1031 struct args_entry
*entry
;
1033 if ((entry
= args_find(args
, flag
)) == NULL
) {
1034 *cause
= xstrdup("missing");
1037 if (TAILQ_EMPTY(&entry
->values
)) {
1038 *cause
= xstrdup("empty");
1041 value
= TAILQ_LAST(&entry
->values
, args_values
)->string
;
1042 return (args_string_percentage_and_expand(value
, minval
, maxval
, curval
,
1047 * Convert a string to a number which may be a percentage, and expand formats.
1050 args_string_percentage_and_expand(const char *value
, long long minval
,
1051 long long maxval
, long long curval
, struct cmdq_item
*item
, char **cause
)
1055 size_t valuelen
= strlen(value
);
1058 if (value
[valuelen
- 1] == '%') {
1059 copy
= xstrdup(value
);
1060 copy
[valuelen
- 1] = '\0';
1062 f
= format_single_from_target(item
, copy
);
1063 ll
= strtonum(f
, 0, 100, &errstr
);
1066 if (errstr
!= NULL
) {
1067 *cause
= xstrdup(errstr
);
1070 ll
= (curval
* ll
) / 100;
1072 *cause
= xstrdup("too small");
1076 *cause
= xstrdup("too large");
1080 f
= format_single_from_target(item
, value
);
1081 ll
= strtonum(f
, minval
, maxval
, &errstr
);
1083 if (errstr
!= NULL
) {
1084 *cause
= xstrdup(errstr
);