You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
2.8KB

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