forked from GPSBabel/gpsbabel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gbfile.h
139 lines (114 loc) · 4.71 KB
/
gbfile.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
/*
Common GPSBabel file I/O API
Copyright (C) 2006,2007,2008 Olaf Klein, [email protected]
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
*/
#ifndef GBFILE_H
#define GBFILE_H
#include "defs.h"
#include "cet.h"
#include <QtCore/QString>
struct gbfile_s;
typedef struct gbfile_s gbfile;
typedef uint32_t gbsize_t;
typedef void (*gbfclearerr_cb)(gbfile* self);
typedef int (*gbfclose_cb)(gbfile* self);
typedef int (*gbfeof_cb)(gbfile* self);
typedef int (*gbferror_cb)(gbfile* self);
typedef int (*gbfflush_cb)(gbfile* self);
typedef gbfile* (*gbfopen_cb)(gbfile* self, const char* mode);
typedef gbsize_t (*gbfread_cb)(void* buf, const gbsize_t size, const gbsize_t members, gbfile* self);
typedef int (*gbfseek_cb)(gbfile* self, int32_t offset, int whence);
typedef gbsize_t (*gbftell_cb)(gbfile* self);
typedef gbsize_t (*gbfwrite_cb)(const void* buf, const gbsize_t size, const gbsize_t members, gbfile* self);
typedef int (*gbfungetc_cb)(const int c, gbfile* self);
typedef struct gbfile_s {
#ifdef DEBUG_MEM
void* dummy; /* ZERO pointer for stdio oop's */
#endif
union {
FILE* std;
unsigned char* mem;
#if !ZLIB_INHIBITED
gzFile gz;
#endif
} handle;
char* name;
char* module;
char* buff; /* static growing buffer, primary used by gbprintf */
int buffsz;
char mode;
int back;
gbsize_t mempos; /* curr. position in memory */
gbsize_t memlen; /* max. number of written bytes to memory */
gbsize_t memsz; /* curr. size of allocated memory */
unsigned char big_endian:1;
unsigned char binary:1;
unsigned char gzapi:1;
unsigned char memapi:1;
unsigned char unicode:1;
unsigned char unicode_checked:1;
unsigned char is_pipe:1;
gbfclearerr_cb fileclearerr;
gbfclose_cb fileclose;
gbfeof_cb fileeof;
gbferror_cb fileerror;
gbfflush_cb fileflush;
gbfopen_cb fileopen;
gbfread_cb fileread;
gbfseek_cb fileseek;
gbftell_cb filetell;
gbfungetc_cb fileungetc;
gbfwrite_cb filewrite;
} gbfile_t;
gbfile* gbfopen(const QString filename, const char* mode, const char* module);
gbfile* gbfopen_be(const QString filename, const char* mode, const char* module);
#define gbfopen_le gbfopen
void gbfclose(gbfile* file);
gbsize_t gbfread(void* buf, const gbsize_t size, const gbsize_t members, gbfile* file);
gbsize_t gbfread(QString& buf, const gbsize_t size, const gbsize_t members, gbfile* file);
int gbfgetc(gbfile* file);
QString gbfgets(char* buf, int len, gbfile* file);
int gbvfprintf(gbfile* file, const char* format, va_list ap);
int gbfprintf(gbfile* file, const char* format, ...);
int gbfputc(int c, gbfile* file);
int gbfputs(const QString& s, gbfile* file);
int gbfwrite(const void* buf, const gbsize_t size, const gbsize_t members, gbfile* file);
int gbfflush(gbfile* file);
void gbfclearerr(gbfile* file);
int gbferror(gbfile* file);
void gbfrewind(gbfile* file);
int gbfseek(gbfile* file, int32_t offset, int whence);
gbsize_t gbftell(gbfile* file);
int gbfeof(gbfile* file);
int gbfungetc(const int c, gbfile* file);
int32_t gbfgetint32(gbfile* file);
#define gbfgetuint32 (uint32_t)gbfgetint32
int16_t gbfgetint16(gbfile* file);
#define gbfgetuint16 (uint16_t)gbfgetint16
double gbfgetdbl(gbfile* file); // read a double value
float gbfgetflt(gbfile* file); // read a float value
char* gbfgetstr(gbfile* file); // read until any type of line-breaks or EOF
QString gbfgetpstr(gbfile* file); // read a pascal string
QString gbfgetcstr(gbfile* file); // read a null terminated string
char* gbfgetcstr_old(gbfile* file); // read a null terminated string
int gbfputint16(const int16_t i, gbfile* file);
#define gbfputuint16(a,b) gbfputint16((uint16_t)(a),(b))
int gbfputint32(const int32_t i, gbfile* file);
#define gbfputuint32(a,b) gbfputint32((uint32_t)(a),(b))
int gbfputdbl(const double d, gbfile* file); // write a double value
int gbfputflt(const float f, gbfile* file); // write a float value
int gbfputcstr(const QString& s, gbfile* file); // write string including '\0'
int gbfputpstr(const QString& s, gbfile* file); // write as pascal string
gbsize_t gbfcopyfrom(gbfile* file, gbfile* src, gbsize_t count);
#endif