예제 #1
0
파일: maps.c 프로젝트: PDXostc/navit
struct maps *
maps_new(struct attr *parent, struct attr **attrs)
{
	struct attr *data,**attrs_dup;
	if (!parent) {
		dbg(lvl_error,"No parent\n");
		return NULL;
	}
	if (parent->type != attr_mapset) {
		dbg(lvl_error,"Parent must be mapset\n");
		return NULL;
	}
	dbg(lvl_debug,"enter\n");
	attrs_dup=attr_list_dup(attrs);
	data=attr_search(attrs_dup, NULL, attr_data);
	if (data) {
		struct file_wordexp *wexp=file_wordexp_new(data->u.str);
		int i,count=file_wordexp_get_count(wexp);
		char **array=file_wordexp_get_array(wexp);
		struct attr *name;
		struct attr *name_provided = attr_search(attrs_dup, NULL, attr_name);

		// if no name was provided, fill the name with the location
		if (!name_provided) {
			struct attr name_tmp;
			name_tmp.type = attr_name;
			name_tmp.u.str="NULL";
			attrs_dup=attr_generic_add_attr(attrs_dup, &name_tmp);
			name = attr_search(attrs_dup, NULL, attr_name);
		}

		for (i = 0 ; i < count ; i++) {
			struct attr map;
			g_free(data->u.str);
			data->u.str=g_strdup(array[i]);

			if (!name_provided) {
				g_free(name->u.str);
				name->u.str=g_strdup(array[i]);
			}

			map.type=attr_map;
			map.u.map=map_new(parent, attrs_dup);

			if (map.u.map) {
				mapset_add_attr(parent->u.mapset, &map);
				navit_object_unref(map.u.navit_object);
			}
			
		}
		file_wordexp_destroy(wexp);	
	} else {
		dbg(lvl_error,"no data attribute\n");
	}
	attr_list_free(attrs_dup);
	return NULL;
}
예제 #2
0
int
vehicleprofile_add_attr(struct vehicleprofile *this_, struct attr *attr)
{
    this_->attrs=attr_generic_add_attr(this_->attrs, attr);
    struct attr item_types_attr;
    switch (attr->type) {
    case attr_roadprofile:
        if (roadprofile_get_attr(attr->u.roadprofile, attr_item_types, &item_types_attr, NULL)) {
            enum item_type *types=item_types_attr.u.item_types;
            while (*types != type_none) {
                g_hash_table_insert(this_->roadprofile_hash, (void *)(long)(*types), attr->u.roadprofile);
                types++;
            }
        }
        break;
    default:
        break;
    }
    return 1;
}