+static char *
+ucimap_data_to_string(struct ucimap_section_data *sd, struct uci_optmap *om, union ucimap_data *data)
+{
+ static char buf[32];
+ char *str = NULL;
+
+ switch(om->type & UCIMAP_SUBTYPE) {
+ case UCIMAP_STRING:
+ str = data->s;
+ break;
+ case UCIMAP_INT:
+ sprintf(buf, "%d", data->i);
+ str = buf;
+ break;
+ case UCIMAP_BOOL:
+ sprintf(buf, "%d", !!data->b);
+ str = buf;
+ break;
+ case UCIMAP_SECTION:
+ if (data->ptr)
+ str = (char *) ucimap_ptr_section(om->data.sm, data->ptr)->section_name;
+ else
+ str = "";
+ break;
+ case UCIMAP_CUSTOM:
+ break;
+ default:
+ return NULL;
+ }
+
+ if (om->format) {
+ union ucimap_data tdata;
+
+ if (ucimap_is_custom(om->type)) {
+ tdata.s = (char *)data;
+ data = &tdata;
+ }
+
+ if (om->format(ucimap_section_ptr(sd), om, data, &str) < 0)
+ return NULL;
+
+ if (!str)
+ str = "";
+ }
+ return str;
+}
+