forked from GPSBabel/gpsbabel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
csv_util.h
160 lines (123 loc) · 4.5 KB
/
csv_util.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
Copyright (C) 2002 Alex Mottram (geo_alexm at cox-internet.com)
Copyright (C) 2002-2014 Robert Lipe
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
*/
#include "queue.h"
#include "defs.h"
#include <QtCore/QStringList>
class QTextStream;
/* function prototypes */
char*
#ifndef DEBUG_MEM
csv_stringtrim(const char* string, const char* enclosure, int strip_max);
#else
CSV_STRINGTRIM(const char* string, const char* enclosure, int strip_max, DEBUG_PARAMS);
#define csv_stringtrim( s, e,m ) CSV_STRINGTRIM( s, e, m, __FILE__, __LINE__)
#endif
QString csv_stringtrim(const QString& source, const QString& enclosure);
char*
csv_lineparse(const char* stringstart, const char* delimited_by, const char* enclosed_in, const int line_no);
void
human_to_dec(const char* instr, double* outlat, double* outlon, int which);
inline void
human_to_dec(const QString instr, double* outlat, double* outlon, int which) {
human_to_dec(CSTR(instr), outlat, outlon, which);
}
char*
#ifndef DEBUG_MEM
csv_stringclean(const char* string, const char* chararray);
#else
CSV_STRINGCLEAN(const char* string, const char* chararray,DEBUG_PARAMS);
#define csv_stringclean(s,c) CSV_STRINGCLEAN(s,c,__FILE__,__LINE__)
#endif
QString csv_stringclean(const QString& string, const QString& chararray);
void
xcsv_data_read(void);
void
xcsv_data_write(void);
void
xcsv_file_init(void);
void
xcsv_prologue_add(char*);
void
xcsv_epilogue_add(char*);
void
xcsv_ifield_add(char*, char*, char*);
void
xcsv_ofield_add(char*, char*, char*, int options);
void
xcsv_destroy_style(void);
const char*
xcsv_get_char_from_constant_table(char* key);
/****************************************************************************/
/* types required for various xcsv functions */
/****************************************************************************/
/* something to map fields to waypts */
#define OPTIONS_NODELIM 1
#define OPTIONS_ABSOLUTE 2
#define OPTIONS_OPTIONAL 3
typedef struct field_map {
queue Q;
char* key;
char* val;
char* printfc;
int hashed_key;
int options;
} field_map_t;
/* something to map config file constants to chars */
typedef struct char_map {
const char* key;
const char* chars;
} char_map_t;
namespace gpsbabel
{
class File;
}
/*
* a Class describing all the wonderful elements of xcsv files, in a
* nutshell.
* It completely shows that this began life as a C struct...baby steps.
*/
class XcsvFile {
public:
XcsvFile();
bool is_internal; /* bool - is internal (1) or parsed (0) */
/* header lines for writing at the top of the file. */
QStringList prologue;
/* footer lines for writing at the bottom of the file. */
QStringList epilogue;
QString field_delimiter; /* comma, quote, etc... */
QString field_encloser; /* doublequote, etc... */
QString record_delimiter; /* newline, c/r, etc... */
QString badchars; /* characters we never write to output */
queue ifield; /* input field mapping */
queue* ofield; /* output field mapping */
int ifield_ct; /* actual # of ifields */
int ofield_ct; /* actual # of ofields */
gpsbabel::File* file;
QTextStream* stream;
QTextCodec* codec;
QString fname; /* ptr to filename of above. */
char* description; /* Description for help text */
char* extension; /* preferred filename extension (for wrappers)*/
short_handle mkshort_handle;/* handle for mkshort() */
ff_type type; /* format type for GUI wrappers. */
int gps_datum; /* result of GPS_Lookup_Datum_Index */
gpsdata_type datatype; /* can be wptdata, rtedata or trkdata */
/* ... or ZERO to keep the old behaviour */
};
/****************************************************************************/
/* obligatory global struct */
/****************************************************************************/
extern XcsvFile xcsv_file;