1 /*
2 Read Yahoo Geocoded files.
3
4 Copyright (C) 2005 Robert Lipe, robertlipe@usa.net
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
19
20 */
21
22 #include "defs.h"
23 #include "xmlgeneric.h"
24
25 static waypoint *wpt_tmp;
26 static char *as;
27
28 #define MYNAME "yahoo"
29
30 static
31 arglist_t yahoo_args[] = {
32 {
33 "addrsep", &as,
34 "String to separate concatenated address fields (default=\", \")",
35 ", ", ARGTYPE_STRING, ARG_NOMINMAX
36 },
37 ARG_TERMINATOR
38 };
39
40 static xg_callback wpt_s, wpt_lat, wpt_lon, wpt_e;
41 static xg_callback wpt_addr /*, wpt_city, wpt_state, wpt_zip, wpt_country*/;
42
43 static xg_tag_mapping gl_map[] = {
44 { wpt_s, cb_start, "/ResultSet/Result" },
45 { wpt_lat, cb_cdata, "/ResultSet/Result/Latitude" },
46 { wpt_lon, cb_cdata, "/ResultSet/Result/Longitude" },
47 { wpt_addr, cb_cdata, "/ResultSet/Result/Address" },
48 { wpt_addr, cb_cdata, "/ResultSet/Result/City" },
49 { wpt_addr, cb_cdata, "/ResultSet/Result/State" },
50 { wpt_addr, cb_cdata, "/ResultSet/Result/Zip" },
51 { wpt_addr, cb_cdata, "/ResultSet/Result/Country" },
52 { wpt_e, cb_end, "/ResultSet/Result" },
53 { NULL, (xg_cb_type)0, NULL}
54 };
55
56 static void
yahoo_rd_init(const char * fname)57 yahoo_rd_init(const char *fname)
58 {
59 xml_init(fname, gl_map, NULL);
60 }
61
62 static void
yahoo_read(void)63 yahoo_read(void)
64 {
65 xml_read();
66 }
67
68 static void
yahoo_rd_deinit(void)69 yahoo_rd_deinit(void)
70 {
71 xml_deinit();
72 }
73
74 static void
yahoo_wr_init(const char * fname)75 yahoo_wr_init(const char *fname)
76 {
77 fatal("Writing file of type %s is not supported\n", MYNAME);
78 }
79
wpt_s(const char * args,const char ** unused)80 void wpt_s(const char *args, const char **unused)
81 {
82 wpt_tmp = waypt_new();
83 }
84
wpt_e(const char * args,const char ** unused)85 void wpt_e(const char *args, const char **unused)
86 {
87 waypt_add(wpt_tmp);
88 wpt_tmp = NULL;
89 }
90
wpt_lat(const char * args,const char ** unused)91 void wpt_lat(const char *args, const char **unused)
92 {
93 wpt_tmp->latitude = atof(args);
94 }
95
wpt_lon(const char * args,const char ** unused)96 void wpt_lon(const char *args, const char **unused)
97 {
98 wpt_tmp->longitude = atof(args);
99 }
100
wpt_addr(const char * args,const char ** unused)101 void wpt_addr(const char *args, const char **unused)
102 {
103 if (wpt_tmp->notes) {
104 wpt_tmp->notes = xstrappend(wpt_tmp->notes, as);
105 }
106 wpt_tmp->notes = xstrappend(wpt_tmp->notes, args);
107 }
108
109 ff_vecs_t yahoo_vecs = {
110 ff_type_file,
111 { ff_cap_read },
112 yahoo_rd_init,
113 yahoo_wr_init,
114 yahoo_rd_deinit,
115 NULL,
116 yahoo_read,
117 NULL,
118 NULL,
119 yahoo_args,
120 CET_CHARSET_ASCII, 0 /* CET-REVIEW */
121 };
122