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.

gbfile.h 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. Common GPSBabel file I/O API
  3. Copyright (C) 2006,2007,2008 Olaf Klein, o.b.klein@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. #ifndef GBFILE_H
  17. #define GBFILE_H
  18. #include "defs.h"
  19. #include "cet.h"
  20. #include <QtCore/QString>
  21. struct gbfile_s;
  22. typedef struct gbfile_s gbfile;
  23. typedef uint32_t gbsize_t;
  24. typedef void (*gbfclearerr_cb)(gbfile* self);
  25. typedef int (*gbfclose_cb)(gbfile* self);
  26. typedef int (*gbfeof_cb)(gbfile* self);
  27. typedef int (*gbferror_cb)(gbfile* self);
  28. typedef int (*gbfflush_cb)(gbfile* self);
  29. typedef gbfile* (*gbfopen_cb)(gbfile* self, const char* mode);
  30. typedef gbsize_t (*gbfread_cb)(void* buf, const gbsize_t size, const gbsize_t members, gbfile* self);
  31. typedef int (*gbfseek_cb)(gbfile* self, int32_t offset, int whence);
  32. typedef gbsize_t (*gbftell_cb)(gbfile* self);
  33. typedef gbsize_t (*gbfwrite_cb)(const void* buf, const gbsize_t size, const gbsize_t members, gbfile* self);
  34. typedef int (*gbfungetc_cb)(const int c, gbfile* self);
  35. typedef struct gbfile_s {
  36. #ifdef DEBUG_MEM
  37. void* dummy; /* ZERO pointer for stdio oop's */
  38. #endif
  39. union {
  40. FILE* std;
  41. unsigned char* mem;
  42. #if !ZLIB_INHIBITED
  43. gzFile gz;
  44. #endif
  45. } handle;
  46. char* name;
  47. char* module;
  48. char* buff; /* static growing buffer, primary used by gbprintf */
  49. int buffsz;
  50. char mode;
  51. int back;
  52. gbsize_t mempos; /* curr. position in memory */
  53. gbsize_t memlen; /* max. number of written bytes to memory */
  54. gbsize_t memsz; /* curr. size of allocated memory */
  55. unsigned char big_endian:1;
  56. unsigned char binary:1;
  57. unsigned char gzapi:1;
  58. unsigned char memapi:1;
  59. unsigned char unicode:1;
  60. unsigned char unicode_checked:1;
  61. unsigned char is_pipe:1;
  62. gbfclearerr_cb fileclearerr;
  63. gbfclose_cb fileclose;
  64. gbfeof_cb fileeof;
  65. gbferror_cb fileerror;
  66. gbfflush_cb fileflush;
  67. gbfopen_cb fileopen;
  68. gbfread_cb fileread;
  69. gbfseek_cb fileseek;
  70. gbftell_cb filetell;
  71. gbfungetc_cb fileungetc;
  72. gbfwrite_cb filewrite;
  73. } gbfile_t;
  74. gbfile* gbfopen(const QString filename, const char* mode, const char* module);
  75. gbfile* gbfopen_be(const QString filename, const char* mode, const char* module);
  76. #define gbfopen_le gbfopen
  77. void gbfclose(gbfile* file);
  78. gbsize_t gbfread(void* buf, const gbsize_t size, const gbsize_t members, gbfile* file);
  79. gbsize_t gbfread(QString& buf, const gbsize_t size, const gbsize_t members, gbfile* file);
  80. int gbfgetc(gbfile* file);
  81. QString gbfgets(char* buf, int len, gbfile* file);
  82. int gbvfprintf(gbfile* file, const char* format, va_list ap);
  83. int gbfprintf(gbfile* file, const char* format, ...);
  84. int gbfputc(int c, gbfile* file);
  85. int gbfputs(const QString& s, gbfile* file);
  86. int gbfwrite(const void* buf, const gbsize_t size, const gbsize_t members, gbfile* file);
  87. int gbfflush(gbfile* file);
  88. void gbfclearerr(gbfile* file);
  89. int gbferror(gbfile* file);
  90. void gbfrewind(gbfile* file);
  91. int gbfseek(gbfile* file, int32_t offset, int whence);
  92. gbsize_t gbftell(gbfile* file);
  93. int gbfeof(gbfile* file);
  94. int gbfungetc(const int c, gbfile* file);
  95. int32_t gbfgetint32(gbfile* file);
  96. #define gbfgetuint32 (uint32_t)gbfgetint32
  97. int16_t gbfgetint16(gbfile* file);
  98. #define gbfgetuint16 (uint16_t)gbfgetint16
  99. double gbfgetdbl(gbfile* file); // read a double value
  100. float gbfgetflt(gbfile* file); // read a float value
  101. char* gbfgetstr(gbfile* file); // read until any type of line-breaks or EOF
  102. QString gbfgetpstr(gbfile* file); // read a pascal string
  103. QString gbfgetcstr(gbfile* file); // read a null terminated string
  104. char* gbfgetcstr_old(gbfile* file); // read a null terminated string
  105. int gbfputint16(const int16_t i, gbfile* file);
  106. #define gbfputuint16(a,b) gbfputint16((uint16_t)(a),(b))
  107. int gbfputint32(const int32_t i, gbfile* file);
  108. #define gbfputuint32(a,b) gbfputint32((uint32_t)(a),(b))
  109. int gbfputdbl(const double d, gbfile* file); // write a double value
  110. int gbfputflt(const float f, gbfile* file); // write a float value
  111. int gbfputcstr(const QString& s, gbfile* file); // write string including '\0'
  112. int gbfputpstr(const QString& s, gbfile* file); // write as pascal string
  113. gbsize_t gbfcopyfrom(gbfile* file, gbfile* src, gbsize_t count);
  114. #endif