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.

csv_util.h 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. Copyright (C) 2002 Alex Mottram (geo_alexm at cox-internet.com)
  3. Copyright (C) 2002-2014 Robert Lipe
  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 <QtCore/QStringList>
  17. /* function prototypes */
  18. char*
  19. #ifndef DEBUG_MEM
  20. csv_stringtrim(const char* string, const char* enclosure, int strip_max);
  21. #else
  22. CSV_STRINGTRIM(const char* string, const char* enclosure, int strip_max, DEBUG_PARAMS);
  23. #define csv_stringtrim( s, e,m ) CSV_STRINGTRIM( s, e, m, __FILE__, __LINE__)
  24. #endif
  25. QString csv_stringtrim(const QString& source, const QString& enclosure);
  26. char*
  27. csv_lineparse(const char* stringstart, const char* delimited_by, const char* enclosed_in, const int line_no);
  28. void
  29. human_to_dec(const char* instr, double* outlat, double* outlon, int which);
  30. char*
  31. #ifndef DEBUG_MEM
  32. csv_stringclean(const char* string, const char* chararray);
  33. #else
  34. CSV_STRINGCLEAN(const char* string, const char* chararray,DEBUG_PARAMS);
  35. #define csv_stringclean(s,c) CSV_STRINGCLEAN(s,c,__FILE__,__LINE__)
  36. #endif
  37. QString csv_stringclean(const QString& string, const QString& chararray);
  38. void
  39. xcsv_data_read(void);
  40. void
  41. xcsv_data_write(void);
  42. void
  43. xcsv_file_init(void);
  44. void
  45. xcsv_prologue_add(char*);
  46. void
  47. xcsv_epilogue_add(char*);
  48. void
  49. xcsv_ifield_add(char*, char*, char*);
  50. void
  51. xcsv_ofield_add(char*, char*, char*, int options);
  52. void
  53. xcsv_destroy_style(void);
  54. const char*
  55. xcsv_get_char_from_constant_table(char* key);
  56. /****************************************************************************/
  57. /* types required for various xcsv functions */
  58. /****************************************************************************/
  59. /* something to map fields to waypts */
  60. #define OPTIONS_NODELIM 1
  61. #define OPTIONS_ABSOLUTE 2
  62. #define OPTIONS_OPTIONAL 3
  63. typedef struct field_map {
  64. queue Q;
  65. char* key;
  66. char* val;
  67. char* printfc;
  68. int hashed_key;
  69. int options;
  70. } field_map_t;
  71. /* something to map config file constants to chars */
  72. typedef struct char_map {
  73. const char* key;
  74. const char* chars;
  75. } char_map_t;
  76. namespace gpsbabel
  77. {
  78. class File;
  79. }
  80. /*
  81. * a Class describing all the wonderful elements of xcsv files, in a
  82. * nutshell.
  83. * It completely shows that this began life as a C struct...baby steps.
  84. */
  85. class XcsvFile {
  86. public:
  87. XcsvFile();
  88. bool is_internal; /* bool - is internal (1) or parsed (0) */
  89. /* header lines for writing at the top of the file. */
  90. QStringList prologue;
  91. /* footer lines for writing at the bottom of the file. */
  92. QStringList epilogue;
  93. QString field_delimiter; /* comma, quote, etc... */
  94. QString field_encloser; /* doublequote, etc... */
  95. QString record_delimiter; /* newline, c/r, etc... */
  96. QString badchars; /* characters we never write to output */
  97. queue ifield; /* input field mapping */
  98. queue* ofield; /* output field mapping */
  99. int ifield_ct; /* actual # of ifields */
  100. int ofield_ct; /* actual # of ofields */
  101. gpsbabel::File* file;
  102. QTextStream* stream;
  103. QTextCodec* codec;
  104. QString fname; /* ptr to filename of above. */
  105. char* description; /* Description for help text */
  106. char* extension; /* preferred filename extension (for wrappers)*/
  107. short_handle mkshort_handle;/* handle for mkshort() */
  108. ff_type type; /* format type for GUI wrappers. */
  109. int gps_datum; /* result of GPS_Lookup_Datum_Index */
  110. gpsdata_type datatype; /* can be wptdata, rtedata or trkdata */
  111. /* ... or ZERO to keep the old behaviour */
  112. };
  113. /****************************************************************************/
  114. /* obligatory global struct */
  115. /****************************************************************************/
  116. extern XcsvFile xcsv_file;