Add:Core:Beginning of work on writing navit.xml
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Sun, 20 Sep 2009 19:16:46 +0000 (19:16 +0000)
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Sun, 20 Sep 2009 19:16:46 +0000 (19:16 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk/navit@2584 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/attr.c
navit/attr_def.h
navit/gui/internal/gui_internal.c
navit/vehicle.c

index bf5ac89..7495cb2 100644 (file)
@@ -249,6 +249,12 @@ attr_to_text(struct attr *attr, struct map *map, int pretty)
                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));    
 }
 
@@ -267,15 +273,40 @@ attr_search(struct attr **attrs, struct attr *last, enum attr_type attr)
 }
 
 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;
index 72d3648..5826e9d 100644 (file)
@@ -22,6 +22,7 @@
 /* common */
 ATTR2(0x00000000,none)
 ATTR(any)
+ATTR(any_xml)
 
 ATTR2(0x00010000,type_item_begin)
 ATTR(town_streets_item)
index c4c19e5..830d9f9 100644 (file)
@@ -3152,6 +3152,28 @@ gui_internal_is_active_vehicle(struct gui_priv *this, struct vehicle
        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.
@@ -3187,6 +3209,9 @@ gui_internal_cmd_set_active_profile(struct gui_priv *this, struct
         struct attr vehicle = {attr_vehicle, {v}};
         navit_set_attr(this->nav, &vehicle);
     }
+       save_vehicle_xml(v);
+
+                       
 }
 
 /**
index a57c924..5518b04 100644 (file)
@@ -189,6 +189,19 @@ vehicle_new(struct attr *parent, struct attr **attrs)
        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)
 {