static int parse_line(FILE *f, char *buffer, char **name, struct coord *c) { int pos; char *s,*i; *name=NULL; if (! fgets(buffer, 2048, f)) return -3; pos=coord_parse(buffer, projection_mg, c); if (! pos) return -2; if (!buffer[pos] || buffer[pos] == '\n') return -1; buffer[strlen(buffer)-1]='\0'; s=buffer+pos+1; if (!strncmp(s,"type=", 5)) { i=index(s, '"'); if (i) { s=i+1; i=index(s, '"'); if (i) *i='\0'; } } *name=s; return pos; }
void bookmarks_get_center_from_file(struct bookmarks *this_, char *file, struct coord *center) { FILE *f; char *line = NULL; dbg(0,"enter\n"); size_t line_size = 0; enum projection pro; f = fopen(file, "r"); if (! f) return; getline(&line, &line_size, f); fclose(f); if (line) { pro = transform_get_projection(this_->trans); coord_parse(g_strchomp(line), pro, center); dbg(0,"******** get center from file *********\n"); free(line); } return; }
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; }
static int parse_line(struct map_rect_priv *mr, int attr) { int pos; pos=coord_parse(mr->line, projection_mg, &mr->c); if (pos < strlen(mr->line) && attr) { strcpy(mr->attrs, mr->line+pos); } return pos; }
int pcoord_parse(const char *c_str, enum projection pro, struct pcoord *pc_ret) { struct coord c; int ret; ret = coord_parse(c_str, pro, &c); pc_ret->x = c.x; pc_ret->y = c.y; pc_ret->pro = pro; return ret; }
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; }
void navit_init(struct navit *this_) { struct menu *mapmen,*men,*men2; struct map *map; struct mapset_handle *handle; struct mapset *ms=this_->mapsets->data; if (this_->menubar) { mapmen=menu_add(this_->menubar, "Map", menu_type_submenu, NULL, NULL, NULL); // menu_add(map, "Test", menu_type_menu, NULL, NULL); men=menu_add(mapmen, "Layout", menu_type_submenu, NULL, NULL, NULL); menu_add(men, "Test", menu_type_menu, NULL, NULL, NULL); men=menu_add(mapmen, "Projection", menu_type_submenu, NULL, NULL, NULL); menu_add(men, "M&G", menu_type_menu, navit_projection_set, this_, (void *)projection_mg); menu_add(men, "Garmin", menu_type_menu, navit_projection_set, this_, (void *)projection_garmin); handle=mapset_open(ms); while ((map=mapset_next(handle,0))) { char *s=g_strdup_printf("%s:%s", map_get_type(map), map_get_filename(map)); men2=menu_add(mapmen, s, menu_type_toggle, navit_map_toggle, this_, map); menu_set_toggle(men2, map_get_active(map)); g_free(s); } mapset_close(handle); } { struct mapset *ms=this_->mapsets->data; struct coord c; int pos,flag=0; FILE *f; char buffer[2048]; this_->route=route_new(ms); this_->navigation=navigation_new(ms); dbg(0,"navigation_register_callback(%p, ... %p)\n", this_->navigation, this_); navigation_register_callback(this_->navigation, navigation_mode_long, navit_show_roadbook, this_); #if 1 this_->track=track_new(ms); #endif men=NULL; if (this_->menubar) { men=menu_add(this_->menubar, "Route", menu_type_submenu, NULL, NULL, NULL); men=menu_add(men, "Former Destinations", menu_type_submenu, NULL, NULL, NULL); } f=fopen("destination.txt", "r"); if (f) { while (! feof(f) && fgets(buffer, 2048, f)) { if ((pos=coord_parse(buffer, projection_mg, &c))) { if (buffer[pos] && buffer[pos] != '\n' ) { struct coord *cn=g_new(struct coord, 1); *cn=c; buffer[strlen(buffer)-1]='\0'; if (men) menu_add(men, buffer+pos+1, menu_type_menu, navit_set_destination_menu, this_, cn); } flag=1; } } fclose(f); if (flag) route_set_destination(this_->route, &c); } } global_navit=this_; }