return g_strdup_printf("%f", *attr->u.numd);
if (type >= attr_type_object_begin && type <= attr_type_object_end)
return g_strdup_printf("(object[%s])", attr_to_name(type));
+ if (type >= attr_type_color_begin && type <= attr_type_color_end) {
+ if (attr->u.color->a != 65535)
+ return g_strdup_printf("#%02x%02x%02x%02x", attr->u.color->r>>8,attr->u.color->g>>8,attr->u.color->b>>8, attr->u.color->a>>8);
+ else
+ return g_strdup_printf("#%02x%02x%02x", attr->u.color->r>>8,attr->u.color->g>>8,attr->u.color->b>>8);
+ }
return g_strdup_printf("(no text[%s])", attr_to_name(type));
}
}
int
+attr_match(enum attr_type search, enum attr_type found)
+{
+ switch (search) {
+ case attr_any:
+ return 1;
+ case attr_any_xml:
+ switch (found) {
+ case attr_callback:
+ return 0;
+ default:
+ return 1;
+ }
+ default:
+ return search == found;
+ }
+}
+
+int
attr_generic_get_attr(struct attr **attrs, struct attr **def_attrs, enum attr_type type, struct attr *attr, struct attr_iter *iter)
{
while (attrs && *attrs) {
- if ((*attrs)->type == type) {
+ if (attr_match(type,(*attrs)->type)) {
*attr=**attrs;
- return 1;
+ if (!iter)
+ return 1;
+ if (*((void **)iter) < (void *)attrs) {
+ *((void **)iter)=(void *)attrs;
+ return 1;
+ }
}
attrs++;
}
+ if (type == attr_any || type == attr_any_xml)
+ return 0;
while (def_attrs && *def_attrs) {
if ((*def_attrs)->type == type) {
*attr=**def_attrs;
return active_vehicle.u.vehicle == vehicle;
}
+static void
+save_vehicle_xml(struct vehicle *v)
+{
+ struct attr attr;
+ struct attr_iter *iter=vehicle_attr_iter_new();
+ int childs=0;
+ dbg(0,"enter\n");
+ printf("<vehicle");
+ while (vehicle_get_attr(v, attr_any_xml, &attr, iter)) {
+ if (attr_type_begin(attr.type) == attr_type_object_begin)
+ childs=1;
+ else
+ printf(" %s=\"%s\"",attr_to_name(attr.type),attr_to_text(&attr, NULL, 1));
+ }
+ if (childs) {
+ printf(">\n");
+ printf("</vehicle>\n");
+ } else
+ printf(" />\n");
+ vehicle_attr_iter_destroy(iter);
+}
+
/**
* Reacts to a button press that changes a vehicle's active profile.
struct attr vehicle = {attr_vehicle, {v}};
navit_set_attr(this->nav, &vehicle);
}
+ save_vehicle_xml(v);
+
+
}
/**
return this_;
}
+struct attr_iter *
+vehicle_attr_iter_new(void)
+{
+ return g_new0(void *,1);
+}
+
+void
+vehicle_attr_iter_destroy(struct attr_iter *iter)
+{
+ g_free(iter);
+}
+
+
int
vehicle_get_attr(struct vehicle *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
{