/[zanavi_public1]/navit/navit/map/textfile/textfile.c
ZANavi

Diff of /navit/navit/map/textfile/textfile.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 27 Revision 28
53} 53}
54 54
55static void 55static void
56map_destroy_textfile(struct map_priv *m) 56map_destroy_textfile(struct map_priv *m)
57{ 57{
58 dbg(1,"map_destroy_textfile\n"); 58 // dbg(1,"map_destroy_textfile\n");
59 g_free(m->filename); 59 g_free(m->filename);
60 if(m->charset) { 60 if(m->charset) {
61 g_free(m->charset); 61 g_free(m->charset);
62 } 62 }
63 g_free(m); 63 g_free(m);
83static int 83static int
84textfile_coord_get(void *priv_data, struct coord *c, int count) 84textfile_coord_get(void *priv_data, struct coord *c, int count)
85{ 85{
86 struct map_rect_priv *mr=priv_data; 86 struct map_rect_priv *mr=priv_data;
87 int ret=0; 87 int ret=0;
88 dbg(1,"textfile_coord_get %d\n",count); 88 // dbg(1,"textfile_coord_get %d\n",count);
89 while (count--) { 89 while (count--) {
90 if (mr->f && !feof(mr->f) && (!mr->item.id_hi || !mr->eoc) && parse_line(mr, mr->item.id_hi)) { 90 if (mr->f && !feof(mr->f) && (!mr->item.id_hi || !mr->eoc) && parse_line(mr, mr->item.id_hi))
91 {
91 *c=mr->c; 92 *c=mr->c;
92 dbg(1,"c=0x%x,0x%x\n", c->x, c->y); 93 //dbg(1,"c=0x%x,0x%x\n", c->x, c->y);
93 c++; 94 c++;
94 ret++; 95 ret++;
95 get_line(mr); 96 get_line(mr);
96 if (mr->item.id_hi) 97 if (mr->item.id_hi)
97 mr->eoc=1; 98 mr->eoc=1;
99 }
98 } else { 100 else
101 {
99 mr->more=0; 102 mr->more=0;
100 break; 103 break;
101 } 104 }
102 } 105 }
103 return ret; 106 return ret;
123static int 126static int
124textfile_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr) 127textfile_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
125{ 128{
126 struct map_rect_priv *mr=priv_data; 129 struct map_rect_priv *mr=priv_data;
127 char *str=NULL; 130 char *str=NULL;
128 dbg(1,"textfile_attr_get mr=%p attrs='%s' ", mr, mr->attrs); 131 //dbg(1,"textfile_attr_get mr=%p attrs='%s' ", mr, mr->attrs);
129 if (attr_type != mr->attr_last) { 132 if (attr_type != mr->attr_last) {
130 dbg(1,"reset attr_pos\n"); 133 //dbg(1,"reset attr_pos\n");
131 mr->attr_pos=0; 134 mr->attr_pos=0;
132 mr->attr_last=attr_type; 135 mr->attr_last=attr_type;
133 } 136 }
134 if (attr_type == attr_any) { 137 if (attr_type == attr_any) {
135 dbg(1,"attr_any"); 138 //dbg(1,"attr_any");
136 if (attr_from_line(mr->attrs,NULL,&mr->attr_pos,mr->attr, mr->attr_name)) { 139 if (attr_from_line(mr->attrs,NULL,&mr->attr_pos,mr->attr, mr->attr_name)) {
137 attr_type=attr_from_name(mr->attr_name); 140 attr_type=attr_from_name(mr->attr_name);
138 dbg(1,"found attr '%s' 0x%x\n", mr->attr_name, attr_type); 141 //dbg(1,"found attr '%s' 0x%x\n", mr->attr_name, attr_type);
139 attr->type=attr_type; 142 attr->type=attr_type;
140 textfile_encode_attr(mr->attr, attr_type, attr); 143 textfile_encode_attr(mr->attr, attr_type, attr);
141 return 1; 144 return 1;
142 } 145 }
143 } else { 146 } else {
144 str=attr_to_name(attr_type); 147 str=attr_to_name(attr_type);
145 dbg(1,"attr='%s' ",str); 148 //dbg(1,"attr='%s' ",str);
146 if (attr_from_line(mr->attrs,str,&mr->attr_pos,mr->attr, NULL)) { 149 if (attr_from_line(mr->attrs,str,&mr->attr_pos,mr->attr, NULL)) {
147 textfile_encode_attr(mr->attr, attr_type, attr); 150 textfile_encode_attr(mr->attr, attr_type, attr);
148 dbg(1,"found\n"); 151 //dbg(1,"found\n");
149 return 1; 152 return 1;
150 } 153 }
151 } 154 }
152 dbg(1,"not found\n"); 155 //dbg(1,"not found\n");
153 return 0; 156 return 0;
154} 157}
155 158
156static struct item_methods methods_textfile = { 159static struct item_methods methods_textfile = {
157 textfile_coord_rewind, 160 textfile_coord_rewind,
163static struct map_rect_priv * 166static struct map_rect_priv *
164map_rect_new_textfile(struct map_priv *map, struct map_selection *sel) 167map_rect_new_textfile(struct map_priv *map, struct map_selection *sel)
165{ 168{
166 struct map_rect_priv *mr; 169 struct map_rect_priv *mr;
167 170
168 dbg(1,"map_rect_new_textfile\n"); 171 //dbg(1,"map_rect_new_textfile\n");
169 mr=g_new0(struct map_rect_priv, 1); 172 mr=g_new0(struct map_rect_priv, 1);
170 mr->m=map; 173 mr->m=map;
171 mr->sel=sel; 174 mr->sel=sel;
172 if (map->flags & 1) 175 if (map->flags & 1)
173 mr->item.id_hi=1; 176 mr->item.id_hi=1;
191 g_free(oargs); 194 g_free(oargs);
192 sep=","; 195 sep=",";
193 } 196 }
194 sel=sel->next; 197 sel=sel->next;
195 } 198 }
196 dbg(1,"popen args %s\n", args); 199 //dbg(1,"popen args %s\n", args);
197 mr->args=args; 200 mr->args=args;
198 mr->f=popen(mr->args, "r"); 201 mr->f=popen(mr->args, "r");
199 mr->pos=0; 202 mr->pos=0;
200 mr->lastlen=0; 203 mr->lastlen=0;
201#else 204#else
202 dbg(0,"map_rect_new_textfile is unable to work with pipes %s\n",map->filename); 205 dbg(0,"map_rect_new_textfile is unable to work with pipes %s\n",map->filename);
203#endif 206#endif
204 } else { 207 } else {
205 mr->f=fopen(map->filename, "r"); 208 mr->f=fopen(map->filename, "r");
206 } 209 }
207 if(!mr->f) { 210 if(!mr->f)
211 {
208 printf("map_rect_new_textfile unable to open textfile %s\n",map->filename); 212 printf("map_rect_new_textfile unable to open textfile %s\n",map->filename);
209 } 213 }
210 get_line(mr); 214 get_line(mr);
211 return mr; 215 return mr;
212} 216}
213 217
214 218
215static void 219static void
216map_rect_destroy_textfile(struct map_rect_priv *mr) 220map_rect_destroy_textfile(struct map_rect_priv *mr)
217{ 221{
218 if (mr->f) { 222 if (mr->f)
223 {
219 if (mr->m->is_pipe) { 224 if (mr->m->is_pipe)
225 {
220#ifdef HAVE_POPEN 226#ifdef HAVE_POPEN
221 pclose(mr->f); 227 pclose(mr->f);
222#endif 228#endif
223 } 229 }
224 else { 230 else
231 {
225 fclose(mr->f); 232 fclose(mr->f);
226 } 233 }
227 } 234 }
228 g_free(mr); 235 g_free(mr);
229} 236}
230 237
231static struct item * 238static struct item *
232map_rect_get_item_textfile(struct map_rect_priv *mr) 239map_rect_get_item_textfile(struct map_rect_priv *mr)
233{ 240{
234 char *p,type[SIZE]; 241 char *p,type[SIZE];
235 dbg(1,"map_rect_get_item_textfile id_hi=%d line=%s", mr->item.id_hi, mr->line); 242 //dbg(1,"map_rect_get_item_textfile id_hi=%d line=%s", mr->item.id_hi, mr->line);
236 if (!mr->f) { 243 if (!mr->f) {
237 return NULL; 244 return NULL;
238 } 245 }
239 while (mr->more) { 246 while (mr->more) {
240 struct coord c; 247 struct coord c;
241 textfile_coord_get(mr, &c, 1); 248 textfile_coord_get(mr, &c, 1);
242 } 249 }
243 for(;;) { 250 for(;;) {
244 if (feof(mr->f)) { 251 if (feof(mr->f)) {
245 dbg(1,"map_rect_get_item_textfile: eof %d\n",mr->item.id_hi); 252 //dbg(1,"map_rect_get_item_textfile: eof %d\n",mr->item.id_hi);
246 if (mr->m->flags & 1) { 253 if (mr->m->flags & 1) {
247 if (!mr->item.id_hi) 254 if (!mr->item.id_hi)
248 return NULL; 255 return NULL;
249 mr->item.id_hi=0; 256 mr->item.id_hi=0;
250 } else { 257 } else {
271 mr->attrs[0]='\0'; 278 mr->attrs[0]='\0';
272 if (!parse_line(mr, 1)) { 279 if (!parse_line(mr, 1)) {
273 get_line(mr); 280 get_line(mr);
274 continue; 281 continue;
275 } 282 }
276 dbg(1,"map_rect_get_item_textfile: point found\n"); 283 //dbg(1,"map_rect_get_item_textfile: point found\n");
277 mr->eoc=0; 284 mr->eoc=0;
278 mr->item.id_lo=mr->pos; 285 mr->item.id_lo=mr->pos;
279 } else { 286 } else {
280 if (parse_line(mr, 1)) { 287 if (parse_line(mr, 1)) {
281 get_line(mr); 288 get_line(mr);
282 continue; 289 continue;
283 } 290 }
284 dbg(1,"map_rect_get_item_textfile: line found\n"); 291 //dbg(1,"map_rect_get_item_textfile: line found\n");
285 if (! mr->line[0]) { 292 if (! mr->line[0]) {
286 get_line(mr); 293 get_line(mr);
287 continue; 294 continue;
288 } 295 }
289 mr->item.id_lo=mr->pos; 296 mr->item.id_lo=mr->pos;
290 strcpy(mr->attrs, mr->line); 297 strcpy(mr->attrs, mr->line);
291 get_line(mr); 298 get_line(mr);
292 dbg(1,"mr=%p attrs=%s\n", mr, mr->attrs); 299 //dbg(1,"mr=%p attrs=%s\n", mr, mr->attrs);
293 } 300 }
294 dbg(1,"get_attrs %s\n", mr->attrs); 301 //dbg(1,"get_attrs %s\n", mr->attrs);
295 if (attr_from_line(mr->attrs,"type",NULL,type,NULL)) { 302 if (attr_from_line(mr->attrs,"type",NULL,type,NULL)) {
296 dbg(1,"type='%s'\n", type); 303 //dbg(1,"type='%s'\n", type);
297 mr->item.type=item_from_name(type); 304 mr->item.type=item_from_name(type);
298 if (mr->item.type == type_none) 305 if (mr->item.type == type_none)
299 printf("Warning: type '%s' unknown\n", type); 306 printf("Warning: type '%s' unknown\n", type);
300 } else { 307 } else {
301 get_line(mr); 308 get_line(mr);
302 continue; 309 continue;
303 } 310 }
304 mr->attr_last=attr_none; 311 mr->attr_last=attr_none;
305 mr->more=1; 312 mr->more=1;
306 dbg(1,"return attr='%s'\n", mr->attrs); 313 //dbg(1,"return attr='%s'\n", mr->attrs);
307 return &mr->item; 314 return &mr->item;
308 } 315 }
309} 316}
310 317
311static struct item * 318static struct item *
376} 383}
377 384
378void 385void
379plugin_init(void) 386plugin_init(void)
380{ 387{
381 dbg(1,"textfile: plugin_init\n"); 388 //dbg(1,"textfile: plugin_init\n");
382 plugin_register_map_type("textfile", map_new_textfile); 389 plugin_register_map_type("textfile", map_new_textfile);
383} 390}
384 391

Legend:
Removed from v.27  
changed lines
  Added in v.28

   
Visit the ZANavi Wiki