+ case DT_STRING:
+ printf("'");
+
+ for (p = val; *p; p++)
+ if (*p == '\'')
+ printf("'\"'\"'");
+ else
+ printf("%c", *p);
+
+ printf("'");
+ break;
+
+ default:
+ printf("%s", val);
+ break;
+ }
+}
+
+static void
+export_value(enum dt_type type, const char *name, const char *val)
+{
+ if ((type == DT_INVALID) || !val || !*val)
+ {
+ printf("unset -v %s; ", name);
+ return;
+ }
+
+ printf("%s=", name);
+ escape_value(type, val);
+ printf("; ");
+}
+
+static int
+validate_value(struct uci_ptr *ptr, const char *expr, const char *def)
+{
+ int i = 0;
+ bool empty = true, first = true;
+ enum dt_type type = DT_INVALID;
+ struct uci_element *e;
+ struct uci_option *opt = ptr->o;
+
+ if (opt->type == UCI_TYPE_LIST)
+ {
+ uci_foreach_element(&opt->v.list, e)
+ {
+ if (!e->name || !*e->name)
+ continue;
+
+ empty = false;
+ break;
+ }
+
+ if (empty)
+ {
+ export_value(DT_STRING, ptr->option, def);
+ return 0;
+ }
+
+ uci_foreach_element(&opt->v.list, e)
+ {
+ if (!e->name || !*e->name)
+ continue;
+
+ if (first)
+ printf("%s=", ptr->option);
+ else
+ printf("\\ ");
+
+ first = false;
+ type = dt_parse(expr, e->name);
+
+ if (type != DT_INVALID)
+ escape_value(type, e->name);
+
+ fprintf(stderr, "%s.%s.%s[%u]=%s validates as %s with %s\n",
+ ptr->package, ptr->section, ptr->option, i++, e->name,
+ expr, type ? "true" : "false");
+ }
+
+ printf("; ");
+ }
+ else
+ {
+ if (!opt->v.string || !*opt->v.string)
+ {
+ export_value(DT_STRING, ptr->option, def);
+ return 0;
+ }
+
+ type = dt_parse(expr, opt->v.string);
+ export_value(type, ptr->option, opt->v.string);
+
+ fprintf(stderr, "%s.%s.%s=%s validates as %s with %s\n",
+ ptr->package, ptr->section, ptr->option, opt->v.string,
+ expr, type ? "true" : "false");
+ }
+ return type ? 0 : -1;