Exemplo n.º 1
0
static int
textfile_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
{	
	struct map_rect_priv *mr=priv_data;
	char *str=NULL;
	dbg(1,"textfile_attr_get mr=%p attrs='%s' ", mr, mr->attrs);
	if (attr_type != mr->attr_last) {
		dbg(1,"reset attr_pos\n");
		mr->attr_pos=0;
		mr->attr_last=attr_type;
	}
	if (attr_type == attr_any) {
		dbg(1,"attr_any");
		if (get_tag(mr->attrs,NULL,&mr->attr_pos,mr->attr, mr->attr_name)) {
			attr_type=attr_from_name(mr->attr_name);
			dbg(1,"found attr '%s' 0x%x\n", mr->attr_name, attr_type);
			attr->type=attr_type;
			textfile_encode_attr(mr->attr, attr_type, attr);
			return 1;
		}
	} else {
		str=attr_to_name(attr_type);
		dbg(1,"attr='%s' ",str);
		if (get_tag(mr->attrs,str,&mr->attr_pos,mr->attr, NULL)) {
			textfile_encode_attr(mr->attr, attr_type, attr);
			dbg(1,"found\n");
			return 1;
		}
	}
	dbg(1,"not found\n");
	return 0;
}
Exemplo n.º 2
0
struct attr *
attr_new_from_text(const char *name, const char *value)
{
	enum attr_type attr;
	struct attr *ret;

	ret=g_new0(struct attr, 1);
	dbg(1,"enter name='%s' value='%s'\n", name, value);
	attr=attr_from_name(name);
	ret->type=attr;
	switch (attr) {
	case attr_item_type:
		ret->u.item_type=item_from_name(value);
		break;
	default:
		if (attr >= attr_type_string_begin && attr <= attr_type_string_end) {
			ret->u.str=value;
			break;
		}
		if (attr >= attr_type_int_begin && attr <= attr_type_int_end) {
			ret->u.num=atoi(value);
			break;
		}
		dbg(1,"default\n");
		g_free(ret);
		ret=NULL;
	}
	return ret;
}
Exemplo n.º 3
0
struct attr *
attr_new_from_text(const char *name, const char *value)
{
	enum attr_type attr;
	struct attr *ret;
	struct coord_geo *g;
	struct coord c;

	ret=g_new0(struct attr, 1);
	dbg(1,"enter name='%s' value='%s'\n", name, value);
	attr=attr_from_name(name);
	ret->type=attr;
	switch (attr) {
	case attr_item_type:
		ret->u.item_type=item_from_name(value);
		break;
	default:
		if (attr >= attr_type_string_begin && attr <= attr_type_string_end) {
			ret->u.str=(char *)value;
			break;
		}
		if (attr >= attr_type_int_begin && attr <= attr_type_int_end) {
			ret->u.num=atoi(value);
			break;
		}
		if (attr >= attr_type_color_begin && attr <= attr_type_color_end) {
			struct color *color=g_new0(struct color, 1);
			int r,g,b,a;
			ret->u.color=color;
			if(strlen(value)==7){
				sscanf(value,"#%02x%02x%02x", &r, &g, &b);
				color->r = (r << 8) | r;
				color->g = (g << 8) | g;
				color->b = (b << 8) | b;
				color->a = (65535);
			} else if(strlen(value)==9){
				sscanf(value,"#%02x%02x%02x%02x", &r, &g, &b, &a);
				color->r = (r << 8) | r;
				color->g = (g << 8) | g;
				color->b = (b << 8) | b;
				color->a = (a << 8) | a;
			} else {
				dbg(0,"color %s has unknown format\n",value);
			}
			break;
		}
		if (attr >= attr_type_coord_geo_start && attr <= attr_type_coord_geo_end) {
			g=g_new(struct coord_geo, 1);
			ret->u.coord_geo=g;
			coord_parse(value, projection_mg, &c);
			transform_to_geo(projection_mg, &c, g);
			break;
		}
		dbg(1,"default\n");
		g_free(ret);
		ret=NULL;
	}
Exemplo n.º 4
0
static PyObject *
navit_get_attr_py(navitObject *self, PyObject *args)
{
	char *name;
	struct attr attr;
	if (!PyArg_ParseTuple(args, "s", &name))
		return NULL;
	if (!navit_get_attr(self->navit, attr_from_name(name), &attr, NULL)) {
		dbg(0,"get_attr not ok\n");
		Py_RETURN_NONE;
	}
	dbg(0,"get_attr ok\n");
	return python_object_from_attr(&attr);
}
Exemplo n.º 5
0
Arquivo: attr.c Projeto: albertz/navit
struct attr *
attr_new_from_text(const char *name, const char *value)
{
	enum attr_type attr;
	struct attr *ret;
	struct coord_geo *g;
	struct coord c;
	char *pos,*type_str,*str,*tok;
	int min,max,count;

	ret=g_new0(struct attr, 1);
	dbg(1,"enter name='%s' value='%s'\n", name, value);
	attr=attr_from_name(name);
	ret->type=attr;
	switch (attr) {
	case attr_item_type:
		ret->u.item_type=item_from_name(value);
		break;
	case attr_item_types:
		count=0;
		type_str=g_strdup(value);
		str=type_str;
		while ((tok=strtok(str, ","))) {
			ret->u.item_types=g_realloc(ret->u.item_types, (count+2)*sizeof(enum item_type));
			ret->u.item_types[count++]=item_from_name(tok);
			ret->u.item_types[count]=type_none;
        	        str=NULL;
        	}
		g_free(type_str);
		break;
	case attr_attr_types:
		count=0;
		type_str=g_strdup(value);
		str=type_str;
		while ((tok=strtok(str, ","))) {
			ret->u.attr_types=g_realloc(ret->u.attr_types, (count+2)*sizeof(enum attr_type));
			ret->u.attr_types[count++]=attr_from_name(tok);
			ret->u.attr_types[count]=attr_none;
        	        str=NULL;
        	}
		g_free(type_str);
		break;
	case attr_dash:
		count=0;
		type_str=g_strdup(value);
		str=type_str;
		while ((tok=strtok(str, ","))) {
			ret->u.dash=g_realloc(ret->u.dash, (count+2)*sizeof(int));
			ret->u.dash[count++]=g_ascii_strtoull(tok,NULL,0);
			ret->u.dash[count]=0;
        	        str=NULL;
        	}
		g_free(type_str);
		break;
	case attr_order:
	case attr_sequence_range:
	case attr_angle_range:
	case attr_speed_range:
		pos=strchr(value, '-');
		min=0;
		max=32767;
		if (! pos) {
                	sscanf(value,"%d",&min);
                	max=min;
		} else if (pos == value)
			sscanf(value,"-%d",&max);
		else
                	sscanf(value,"%d-%d",&min, &max);
		ret->u.range.min=min;
		ret->u.range.max=max;
		break;
	default:
		if (attr >= attr_type_string_begin && attr <= attr_type_string_end) {
			ret->u.str=g_strdup(value);
			break;
		}
		if (attr >= attr_type_int_begin && attr <= attr_type_int_end) {
			if (value[0] == '0' && value[1] == 'x')
				ret->u.num=strtoul(value, NULL, 0);
			else
				ret->u.num=strtol(value, NULL, 0);
			
			if ((attr >= attr_type_rel_abs_begin) && (attr < attr_type_boolean_begin)) {
				/* Absolute values are from -0x40000000 - 0x40000000, with 0x0 being 0 (who would have thought that?)
					 Relative values are from 0x40000001 - 0x80000000, with 0x60000000 being 0 */
				if (strchr(value, '%')) {
					if ((ret->u.num > 0x20000000) || (ret->u.num < -0x1FFFFFFF)) {
						dbg(0, "Relative possibly-relative attribute with invalid value %i\n", ret->u.num);
					}

					ret->u.num += 0x60000000;
				} else {
					if ((ret->u.num > 0x40000000) || (ret->u.num < -0x40000000)) {
						dbg(0, "Non-relative possibly-relative attribute with invalid value %i\n", ret->u.num);
					}
				}
			} else 	if (attr >= attr_type_boolean_begin) { // also check for yes and no
				if (g_ascii_strcasecmp(value,"no") && g_ascii_strcasecmp(value,"0") && g_ascii_strcasecmp(value,"false")) 
					ret->u.num=1;
				else
					ret->u.num=0;
			}
			break;
		}
		if (attr >= attr_type_color_begin && attr <= attr_type_color_end) {
			struct color *color=g_new0(struct color, 1);
			int r,g,b,a;
			ret->u.color=color;
			if(strlen(value)==7){
				sscanf(value,"#%02x%02x%02x", &r, &g, &b);
				color->r = (r << 8) | r;
				color->g = (g << 8) | g;
				color->b = (b << 8) | b;
				color->a = (65535);
			} else if(strlen(value)==9){
				sscanf(value,"#%02x%02x%02x%02x", &r, &g, &b, &a);
				color->r = (r << 8) | r;
				color->g = (g << 8) | g;
				color->b = (b << 8) | b;
				color->a = (a << 8) | a;
			} else {
				dbg(0,"color %s has unknown format\n",value);
			}
			break;
		}
		if (attr >= attr_type_coord_geo_begin && attr <= attr_type_coord_geo_end) {
			g=g_new(struct coord_geo, 1);
			ret->u.coord_geo=g;
			coord_parse(value, projection_mg, &c);
			transform_to_geo(projection_mg, &c, g);
			break;
		}
		dbg(1,"default\n");
		g_free(ret);
		ret=NULL;
	}
Exemplo n.º 6
0
static DBusHandlerResult
request_navit_set_attr(DBusConnection *connection, DBusMessage *message)
{
    struct navit *navit;
	DBusMessageIter iter, iterattr;
    struct attr attr;
    char *attr_type;

	navit = object_get_from_message(message, "navit");
	if (! navit)
		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    dbus_message_iter_init(message, &iter);
    dbus_message_iter_get_basic(&iter, &attr_type);
    attr.type = attr_from_name(attr_type); 
    dbg(0, "attr value: 0x%x string: %s\n", attr.type, attr_type);
    
    if (attr.type == attr_none)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
    
    dbus_message_iter_next(&iter);
    dbus_message_iter_recurse(&iter, &iterattr);
    dbg(0, "seems valid. signature: %s\n", dbus_message_iter_get_signature(&iterattr));
    
    if (attr.type > attr_type_item_begin && attr.type < attr_type_item_end)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    else if (attr.type > attr_type_int_begin && attr.type < attr_type_boolean_begin) {
        if (dbus_message_iter_get_arg_type(&iterattr) == DBUS_TYPE_INT32)
        {
            dbus_message_iter_get_basic(&iterattr, &attr.u.num);
            if (navit_set_attr(navit, &attr))
                return empty_reply(connection, message);
        }
    }
    else if(attr.type > attr_type_boolean_begin && attr.type < attr_type_int_end) {
        if (dbus_message_iter_get_arg_type(&iterattr) == DBUS_TYPE_BOOLEAN)
        {
            dbus_message_iter_get_basic(&iterattr, &attr.u.num);
            if (navit_set_attr(navit, &attr))
                return empty_reply(connection, message);
        }
    }
#if 0
    else if(attr.type > attr_type_string_begin && attr.type < attr_type_string_end)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    else if(attr.type > attr_type_special_begin && attr.type < attr_type_special_end)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    else if(attr.type > attr_type_double_begin && attr.type < attr_type_double_end)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    else if(attr.type > attr_type_coord_geo_begin && attr.type < attr_type_coord_geo_end)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    else if(attr.type > attr_type_color_begin && attr.type < attr_type_color_end)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    else if(attr.type > attr_type_object_begin && attr.type < attr_type_object_end)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    else if(attr.type > attr_type_coord_begin && attr.type < attr_type_coord_end)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    else if(attr.type > attr_type_pcoord_begin && attr.type < attr_type_pcoord_end)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    else if(attr.type > attr_type_callback_begin && attr.type < attr_type_callback_end)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
#endif
    else {
        dbg(0, "zomg really unhandled111\n");
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
    }
    
    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
Exemplo n.º 7
0
static DBusHandlerResult
request_navit_get_attr(DBusConnection *connection, DBusMessage *message)
{
    struct navit *navit;
    DBusMessageIter iter;
    char * attr_type = NULL;
    struct attr attr;
    navit = object_get_from_message(message, "navit");
    if (! navit)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    dbus_message_iter_init(message, &iter);
    dbus_message_iter_get_basic(&iter, &attr_type);
    attr.type = attr_from_name(attr_type); 
    dbg(0, "attr value: 0x%x string: %s\n", attr.type, attr_type);

    if (attr.type == attr_none)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
    
    if (attr.type > attr_type_item_begin && attr.type < attr_type_item_end)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    else if (attr.type > attr_type_int_begin && attr.type < attr_type_boolean_begin)
    {
        dbg(0, "int detected\n");
        if(navit_get_attr(navit, attr.type, &attr, NULL)) {
            dbg(0, "%s = %i\n", attr_type, attr.u.num);
            return reply_simple_as_variant(connection, message, attr.u.num, DBUS_TYPE_INT32);
        }
    }

    else if(attr.type > attr_type_boolean_begin && attr.type < attr_type_int_end)
    {
        dbg(0, "bool detected\n");
        if(navit_get_attr(navit, attr.type, &attr, NULL)) {
            dbg(0, "%s = %i\n", attr_type, attr.u.num);
            return reply_simple_as_variant(connection, message, attr.u.num, DBUS_TYPE_BOOLEAN);
        }
    }

    else if(attr.type > attr_type_string_begin && attr.type < attr_type_string_end)
    {
        dbg(0, "string detected\n");
        if(navit_get_attr(navit, attr.type, &attr, NULL)) {
            dbg(0, "%s = %s\n", attr_type, &attr.u.layout);
            return reply_simple_as_variant(connection, message, &attr.u.layout, DBUS_TYPE_STRING);
        }
    }

#if 0
    else if(attr.type > attr_type_special_begin && attr.type < attr_type_special_end)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    else if(attr.type > attr_type_double_begin && attr.type < attr_type_double_end)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    else if(attr.type > attr_type_coord_geo_begin && attr.type < attr_type_coord_geo_end)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    else if(attr.type > attr_type_color_begin && attr.type < attr_type_color_end)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    else if(attr.type > attr_type_object_begin && attr.type < attr_type_object_end)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    else if(attr.type > attr_type_coord_begin && attr.type < attr_type_coord_end)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    else if(attr.type > attr_type_pcoord_begin && attr.type < attr_type_pcoord_end)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    else if(attr.type > attr_type_callback_begin && attr.type < attr_type_callback_end)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
#endif
    else {
        dbg(0, "zomg really unhandled111\n");
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
    }

    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}