+ static char val0[] = "0";
+ static char val1[] = "1";
+ static char val_none[] = "";
+
+ if (!strcmp(val, "0") || !strcmp(val, "off") || !strcmp(val, "false") || !strcmp(val, "disabled"))
+ return val0;
+ if (!strcmp(val, "1") || !strcmp(val, "on") || !strcmp(val, "true") || !strcmp(val, "enabled"))
+ return val1;
+
+ return val_none;
+}
+
+static int
+validate_option(struct uci_context *ctx, char *package, char *section, char *option)
+{
+ char *datatype = strstr(option, ":");
+ struct uci_ptr ptr = { 0 };
+ char *val;
+ int ret = 0;
+
+ if (!datatype) {
+ fprintf(stderr, "%s is not a valid option\n", option);
+ return -1;
+ }
+
+ *datatype = '\0';
+ datatype++;
+ val = strstr(datatype, ":");
+ if (val) {
+ *val = '\0';
+ val++;
+ }
+
+ ptr.package = package;
+ ptr.section = section;
+ ptr.option = option;
+
+ if (!uci_lookup_ptr(ctx, &ptr, NULL, false))
+ if (ptr.flags & UCI_LOOKUP_COMPLETE)
+ if (ptr.last->type == UCI_TYPE_OPTION)
+ if ( ptr.o->type == UCI_TYPE_STRING)
+ if (ptr.o->v.string)
+ val = ptr.o->v.string;
+
+ if (val) {
+ ret = dt_parse(datatype, val);
+ fprintf(stderr, "%s.%s.%s=%s validates as %s with %s\n", package, section, option,
+ val, datatype, ret ? "true" : "false");
+ }
+
+ if (ret && !strcmp(datatype, "bool"))
+ printf("%s=%s; ", option, bool_to_num(val));
+ else if (ret)
+ printf("%s=%s; ", option, val);
+ else
+ printf("unset -v %s; ", option);
+
+ return ret;
+}
+
+int
+main(int argc, char **argv)
+{
+ struct uci_context *ctx;
+ struct uci_package *package;
+ int len = argc - 4;