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; }
struct log * log_new(struct attr * parent,struct attr **attrs) { struct log *ret=g_new0(struct log, 1); struct attr *data,*overwrite,*lazy,*mkdir,*flush_size,*flush_time; struct file_wordexp *wexp; char *filename, **wexp_data; dbg(1,"enter\n"); ret->func=&log_func; navit_object_ref((struct navit_object *)ret); data=attr_search(attrs, NULL, attr_data); if (! data) return NULL; filename=data->u.str; wexp=file_wordexp_new(filename); if (wexp && file_wordexp_get_count(wexp) > 0) { wexp_data=file_wordexp_get_array(wexp); filename=wexp_data[0]; } if (filename) ret->filename=g_strdup(filename); if (wexp) file_wordexp_destroy(wexp); overwrite=attr_search(attrs, NULL, attr_overwrite); if (overwrite) ret->overwrite=overwrite->u.num; lazy=attr_search(attrs, NULL, attr_lazy); if (lazy) ret->lazy=lazy->u.num; mkdir=attr_search(attrs, NULL, attr_mkdir); if (mkdir) ret->mkdir=mkdir->u.num; flush_size=attr_search(attrs, NULL, attr_flush_size); if (flush_size) ret->flush_size=flush_size->u.num; flush_time=attr_search(attrs, NULL, attr_flush_time); if (flush_time) ret->flush_time=flush_time->u.num; if (ret->flush_time) { dbg(1,"interval %d\n", ret->flush_time*1000); ret->timer_callback=callback_new_1(callback_cast(log_timer), ret); ret->timer=event_add_timeout(ret->flush_time*1000, 1, ret->timer_callback); } expand_filenames(ret); if (ret->lazy) log_set_last_flush(ret); else log_open(ret); ret->attrs=attr_list_dup(attrs); return ret; }