00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00029 #ifndef _RTXBUFFER_H_
00030 #define _RTXBUFFER_H_
00031
00032 #include "rtxsrc/rtxContext.h"
00033
00034
00035 #define MIN_STREAM_BACKOFF 0
00036
00037 #ifdef __cplusplus
00038 extern "C" {
00039 #endif
00040
00041 EXTERNRT int rtxCheckBuffer (OSCTXT* pctxt, size_t nbytes);
00042
00054 EXTERNRT int rtxCheckOutputBuffer (OSCTXT* pctxt, size_t nbytes);
00055
00067 EXTERNRT int rtxExpandOutputBuffer (OSCTXT* pctxt, size_t nbytes);
00068
00069 EXTERNRT int rtxCheckInputBuffer (OSCTXT* pctxt, size_t nbytes);
00070
00071 EXTERNRT int rtxCopyAsciiText (OSCTXT* pctxt, const char* text);
00072
00073 EXTERNRT int rtxCopyUTF8Text (OSCTXT* pctxt, const OSUTF8CHAR* text);
00074
00075 EXTERNRT int rtxCopyUnicodeText (OSCTXT* pctxt, const OSUNICHAR* text);
00076
00089 EXTERNRT int rtxReadBytesSafe
00090 (OSCTXT* pctxt, OSOCTET* buffer, size_t bufsize, size_t nocts);
00091
00101 EXTERNRT int rtxReadBytes (OSCTXT* pctxt, OSOCTET* pdata, size_t nocts);
00102
00119 EXTERNRT int rtxReadBytesDynamic
00120 (OSCTXT* pctxt, OSOCTET** ppdata, size_t nocts, OSBOOL* pMemAlloc);
00121
00130 EXTERNRT int rtxWriteBytes
00131 (OSCTXT* pctxt, const OSOCTET* pdata, size_t nocts);
00132
00133
00134
00135 #define OSRTPUTCHAR(pctxt,ch) rtxWriteBytes (pctxt, (OSOCTET*)&ch, 1)
00136
00137 #define OSRTPUTCHARREV(pctxt,ch) \
00138 (pctxt)->buffer.data[--(pctxt)->buffer.byteIndex]=(OSOCTET)ch;
00139
00140 #define OSRTZTERM(pctxt) \
00141 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex]=(OSOCTET)0;
00142
00143 #define OSRTSAFEZTERM(pctxt) \
00144 do { \
00145 if (rtxCheckOutputBuffer (pctxt, 1) == 0) \
00146 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex]=(OSOCTET)0; \
00147 else return LOG_RTERRNEW (pctxt, RTERR_BUFOVFLW); \
00148 } while (0)
00149
00150 #define OSRTSAFEPUTCHAR(pctxt,ch) \
00151 do { \
00152 if (rtxCheckOutputBuffer (pctxt, 1) == 0) \
00153 (pctxt)->lastChar= \
00154 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex++]=(OSOCTET)ch; \
00155 else return LOG_RTERRNEW (pctxt, RTERR_BUFOVFLW); \
00156 } while (0)
00157
00158 #define OSRTSAFEPUTCHAR1(pctxt,ch,stat) \
00159 do { \
00160 OSOCTET b = (OSOCTET)ch; \
00161 rtxWriteBytes (pctxt, &b, 1); \
00162 } while (0)
00163
00164 #if 0
00165 #define OSRTSAFEPUTCHAR2(pctxt,ch,prealloc) \
00166 do { \
00167 if (rtxCheckOutputBuffer (pctxt, ((prealloc > 1)?prealloc:1)) == 0) \
00168 (pctxt)->lastChar= \
00169 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex++]=(OSOCTET)ch; \
00170 else return LOG_RTERRNEW (pctxt, RTERR_BUFOVFLW); \
00171 } while (0)
00172 #endif
00173
00174 #define OSRTMEMCPY(pctxt,bdata,len) \
00175 do { \
00176 OSCRTLSAFEMEMCPY (&(pctxt)->buffer.data[(pctxt)->buffer.byteIndex], \
00177 (pctxt)->buffer.size-(pctxt)->buffer.byteIndex, bdata, len); \
00178 (pctxt)->buffer.byteIndex += len; \
00179 (pctxt)->lastChar = (pctxt)->buffer.data[(pctxt)->buffer.byteIndex-1]; \
00180 } while (0)
00181
00182 #define OSRTMEMCPYREV(pctxt,bdata,len) \
00183 do { \
00184 (pctxt)->buffer.byteIndex -= len; \
00185 OSCRTLSAFEMEMCPY (&(pctxt)->buffer.data[(pctxt)->buffer.byteIndex], \
00186 (pctxt)->buffer.size-(pctxt)->buffer.byteIndex, bdata, len); \
00187 } while (0)
00188
00189 #define OSRTSAFEMEMCPY(pctxt,bdata,len) \
00190 do { \
00191 if (rtxCheckOutputBuffer (pctxt, len) == 0) { \
00192 OSCRTLMEMCPY (&(pctxt)->buffer.data[(pctxt)->buffer.byteIndex], bdata, len); \
00193 (pctxt)->buffer.byteIndex += len; \
00194 (pctxt)->lastChar = (pctxt)->buffer.data[(pctxt)->buffer.byteIndex-1]; } \
00195 else return LOG_RTERRNEW (pctxt, RTERR_BUFOVFLW); \
00196 } while (0)
00197
00198 #define OSRTSAFEMEMCPY1(pctxt,bdata,len,stat) \
00199 do { \
00200 if (rtxCheckOutputBuffer (pctxt, len) == 0) { \
00201 OSCRTLMEMCPY (&(pctxt)->buffer.data[(pctxt)->buffer.byteIndex], bdata, len); \
00202 (pctxt)->buffer.byteIndex += len; \
00203 (pctxt)->lastChar = (pctxt)->buffer.data[(pctxt)->buffer.byteIndex-1]; \
00204 stat = 0; } \
00205 else stat = RTERR_BUFOVFLW; \
00206 } while (0)
00207
00208 #define OSRTGETBUFUTF8LEN(pctxt) \
00209 rtxCalcUTF8Len (OSRTBUFPTR (pctxt), OSRTBUFSIZE (pctxt))
00210
00211 #define OSRTCHKBUFUTF8LEN(pctxt,lower,upper,stat) \
00212 do { size_t nchars = OSRTGETBUFUTF8LEN (pctxt); \
00213 stat = (nchars >= lower && nchars <= upper) ? 0 : RTERR_CONSVIO; } while(0)
00214
00215 #define OSRTENDOFBUF(pctxt) ((pctxt)->buffer.byteIndex >= (pctxt)->buffer.size)
00216
00217 #ifdef __cplusplus
00218 }
00219 #endif
00220
00221 #endif