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.

easygps.cc 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*
  2. Access to EasyGPS files.
  3. Copyright (C) 2003 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 <stdio.h>
  18. static gbfile* file_in;
  19. static gbfile* file_out;
  20. static short_handle mkshort_handle;
  21. /* static char *deficon = NULL; */
  22. #define MYNAME "EasyGPS"
  23. static
  24. arglist_t easygps_args[] = {
  25. /* {"deficon", &deficon, "Default icon name", "Waypoint",
  26. ARGTYPE_STRING}, */
  27. ARG_TERMINATOR
  28. };
  29. static void
  30. rd_init(const QString& fname)
  31. {
  32. int sz;
  33. char ibuf[100] = {'0'} ;
  34. const char* ezsig = "TerraByte Location File";
  35. file_in = gbfopen_le(fname, "rb", MYNAME);
  36. sz = gbfread(ibuf, 1, 52, file_in);
  37. if ((sz < 52) ||
  38. strncmp(ibuf, ezsig, sizeof(ezsig)-1) ||
  39. (ibuf[51] != 'W')) {
  40. fatal(MYNAME ": %s is not an EasyGPS file.\n", qPrintable(fname));
  41. }
  42. }
  43. static void
  44. rd_deinit(void)
  45. {
  46. gbfclose(file_in);
  47. }
  48. static void
  49. wr_init(const QString& fname)
  50. {
  51. file_out = gbfopen_le(fname, "wb", MYNAME);
  52. mkshort_handle = mkshort_new_handle();
  53. }
  54. static void
  55. wr_deinit(void)
  56. {
  57. gbfclose(file_out);
  58. mkshort_del_handle(&mkshort_handle);
  59. }
  60. static void
  61. data_read(void)
  62. {
  63. char p;
  64. char ibuf[10];
  65. do {
  66. unsigned char tag;
  67. Waypoint* wpt_tmp;
  68. wpt_tmp = new Waypoint;
  69. UrlLink link;
  70. for (tag = gbfgetc(file_in); tag != 0xff; tag = gbfgetc(file_in)) {
  71. switch (tag) {
  72. case 1:
  73. wpt_tmp->shortname = gbfgetpstr(file_in);
  74. break;
  75. case 2:
  76. case 3:
  77. wpt_tmp->description = gbfgetpstr(file_in);
  78. break;
  79. case 5:
  80. wpt_tmp->notes = gbfgetpstr(file_in);
  81. break;
  82. case 6: {
  83. QString ult = gbfgetpstr(file_in);
  84. link.url_link_text_ = ult;
  85. }
  86. break;
  87. case 7: {
  88. QString id = gbfgetpstr(file_in);
  89. wpt_tmp->icon_descr = id;
  90. }
  91. break;
  92. case 8: /* NULL Terminated (vs. pascal) descr */
  93. wpt_tmp->notes = gbfgetcstr(file_in);
  94. break;
  95. case 9: { /* NULL Terminated (vs. pascal) link */
  96. QString url = gbfgetcstr(file_in);
  97. link.url_ = url;
  98. }
  99. break;
  100. case 0x10: {
  101. QString ult = gbfgetcstr(file_in);
  102. link.url_link_text_ = ult;
  103. }
  104. break;
  105. case 0x63:
  106. wpt_tmp->latitude = gbfgetdbl(file_in);
  107. break;
  108. case 0x64:
  109. wpt_tmp->longitude = gbfgetdbl(file_in);
  110. break;
  111. case 0x65:
  112. case 0x66:
  113. gbfread(ibuf, 8, 1, file_in);
  114. break;
  115. case 0x84:
  116. case 0x85:
  117. gbfread(ibuf, 4, 1, file_in);
  118. break;
  119. case 0x86: /* May be proximity. I think it's time. */
  120. gbfread(ibuf, 4, 1, file_in);
  121. break;
  122. default:
  123. printf("Unknown tag %x\n", tag);
  124. ;
  125. }
  126. }
  127. if (!link.url_.isEmpty() || !link.url_link_text_.isEmpty()) {
  128. wpt_tmp->AddUrlLink(link);
  129. }
  130. waypt_add(wpt_tmp);
  131. p = gbfgetc(file_in);
  132. } while (!gbfeof(file_in) && (p == 'W'));
  133. }
  134. static void
  135. ez_disp(const Waypoint* wpt)
  136. {
  137. gbfputc('W', file_out);
  138. if (!wpt->shortname.isEmpty()) {
  139. gbfputc(1, file_out);
  140. gbfputpstr(wpt->shortname, file_out);
  141. }
  142. if (!wpt->description.isEmpty()) {
  143. gbfputc(3, file_out);
  144. gbfputpstr(wpt->description, file_out);
  145. }
  146. if (!wpt->icon_descr.isNull()) {
  147. gbfputc(7, file_out);
  148. gbfputpstr(wpt->icon_descr, file_out);
  149. }
  150. gbfputc(0x63, file_out);
  151. gbfputdbl(wpt->latitude, file_out);
  152. gbfputc(0x64, file_out);
  153. gbfputdbl(wpt->longitude, file_out);
  154. if (!wpt->notes.isEmpty()) {
  155. gbfputc(5, file_out);
  156. gbfputpstr(wpt->notes, file_out);
  157. }
  158. if (wpt->HasUrlLink()) {
  159. UrlLink link = wpt->GetUrlLink();
  160. if (!link.url_link_text_.isEmpty()) {
  161. gbfputc(6, file_out);
  162. gbfputpstr(link.url_link_text_, file_out);
  163. }
  164. if (!link.url_.isEmpty()) {
  165. gbfputc(9, file_out);
  166. gbfputcstr(link.url_, file_out);
  167. }
  168. }
  169. gbfputc(0xff, file_out);
  170. }
  171. static void
  172. data_write(void)
  173. {
  174. setshort_length(mkshort_handle, 6);
  175. gbfprintf(file_out,
  176. "TerraByte Location File Copyright 2001 TopoGrafix\n");
  177. /*
  178. * I don't know what this is.
  179. */
  180. gbfprintf(file_out, "%c", 0xb);
  181. waypt_disp_all(ez_disp);
  182. /*
  183. * Files seem to always end in a zero.
  184. */
  185. gbfputc(0x00, file_out);
  186. }
  187. ff_vecs_t easygps_vecs = {
  188. ff_type_file,
  189. FF_CAP_RW_WPT,
  190. rd_init,
  191. wr_init,
  192. rd_deinit,
  193. wr_deinit,
  194. data_read,
  195. data_write,
  196. NULL,
  197. easygps_args,
  198. CET_CHARSET_ASCII, 0 /* CET REVIEW */
  199. };