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 #include "rtxsrc/rtxSList.h"
00034
00035
00036 #define MIN_STREAM_BACKOFF 0
00037
00041 typedef struct _OSRTBufLocDescr {
00042 OSSIZE numocts;
00043 OSSIZE offset;
00044 } OSRTBufLocDescr;
00045
00046 #ifdef __cplusplus
00047 extern "C" {
00048 #endif
00049
00050
00051 EXTERNRT int rtxCheckBuffer (OSCTXT* pctxt, size_t nbytes);
00052
00064 EXTERNRT int rtxCheckOutputBuffer (OSCTXT* pctxt, size_t nbytes);
00065
00077 EXTERNRT int rtxExpandOutputBuffer (OSCTXT* pctxt, size_t nbytes);
00078
00079 EXTERNRT int rtxCheckInputBuffer (OSCTXT* pctxt, size_t nbytes);
00080
00081 EXTERNRT int rtxCopyAsciiText (OSCTXT* pctxt, const char* text);
00082
00083 EXTERNRT int rtxCopyUTF8Text (OSCTXT* pctxt, const OSUTF8CHAR* text);
00084
00085 EXTERNRT int rtxCopyUnicodeText (OSCTXT* pctxt, const OSUNICHAR* text);
00086
00099 EXTERNRT int rtxReadBytesSafe
00100 (OSCTXT* pctxt, OSOCTET* buffer, size_t bufsize, size_t nocts);
00101
00111 EXTERNRT int rtxReadBytes (OSCTXT* pctxt, OSOCTET* pdata, size_t nocts);
00112
00129 EXTERNRT int rtxReadBytesDynamic
00130 (OSCTXT* pctxt, OSOCTET** ppdata, size_t nocts, OSBOOL* pMemAlloc);
00131
00140 EXTERNRT int rtxWriteBytes
00141 (OSCTXT* pctxt, const OSOCTET* pdata, size_t nocts);
00142
00143
00156 EXTERNRT int rtxEncCanonicalSort (OSCTXT* pctxt,
00157 OSCTXT* pMemCtxt,
00158 OSRTSList* pList);
00159
00164 EXTERNRT void rtxGetBufLocDescr (OSCTXT *pctxt, OSRTBufLocDescr* pDescr);
00165
00178 EXTERNRT void rtxAddBufLocDescr (OSCTXT *pctxt, OSRTSList* pElemList,
00179 OSRTBufLocDescr* pDescr);
00180
00181
00182
00183 #define OSRTPUTCHAR(pctxt,ch) rtxWriteBytes (pctxt, (OSOCTET*)&ch, 1)
00184
00185 #define OSRTPUTCHARREV(pctxt,ch) \
00186 (pctxt)->buffer.data[--(pctxt)->buffer.byteIndex]=(OSOCTET)ch;
00187
00188 #define OSRTZTERM(pctxt) \
00189 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex]=(OSOCTET)0;
00190
00191 #define OSRTSAFEZTERM(pctxt) \
00192 do { \
00193 if (rtxCheckOutputBuffer (pctxt, 1) == 0) \
00194 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex]=(OSOCTET)0; \
00195 else return LOG_RTERRNEW (pctxt, RTERR_BUFOVFLW); \
00196 } while (0)
00197
00198 #define OSRTSAFEPUTCHAR(pctxt,ch) \
00199 do { \
00200 if (rtxCheckOutputBuffer (pctxt, 1) == 0) \
00201 (pctxt)->lastChar= \
00202 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex++]=(OSOCTET)ch; \
00203 else return LOG_RTERRNEW (pctxt, RTERR_BUFOVFLW); \
00204 } while (0)
00205
00206 #define OSRTSAFEPUTCHAR1(pctxt,ch,stat) \
00207 do { \
00208 OSOCTET b = (OSOCTET)ch; \
00209 rtxWriteBytes (pctxt, &b, 1); \
00210 } while (0)
00211
00212 #if 0
00213 #define OSRTSAFEPUTCHAR2(pctxt,ch,prealloc) \
00214 do { \
00215 if (rtxCheckOutputBuffer (pctxt, ((prealloc > 1)?prealloc:1)) == 0) \
00216 (pctxt)->lastChar= \
00217 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex++]=(OSOCTET)ch; \
00218 else return LOG_RTERRNEW (pctxt, RTERR_BUFOVFLW); \
00219 } while (0)
00220 #endif
00221
00222 #define OSRTMEMCPY(pctxt,bdata,len) \
00223 do { \
00224 OSCRTLSAFEMEMCPY (&(pctxt)->buffer.data[(pctxt)->buffer.byteIndex], \
00225 (pctxt)->buffer.size-(pctxt)->buffer.byteIndex, bdata, len); \
00226 (pctxt)->buffer.byteIndex += len; \
00227 (pctxt)->lastChar = (pctxt)->buffer.data[(pctxt)->buffer.byteIndex-1]; \
00228 } while (0)
00229
00230 #define OSRTMEMCPYREV(pctxt,bdata,len) \
00231 do { \
00232 (pctxt)->buffer.byteIndex -= len; \
00233 OSCRTLSAFEMEMCPY (&(pctxt)->buffer.data[(pctxt)->buffer.byteIndex], \
00234 (pctxt)->buffer.size-(pctxt)->buffer.byteIndex, bdata, len); \
00235 } while (0)
00236
00237 #define OSRTSAFEMEMCPY(pctxt,bdata,len) \
00238 do { \
00239 if (rtxCheckOutputBuffer (pctxt, len) == 0) { \
00240 OSCRTLMEMCPY (&(pctxt)->buffer.data[(pctxt)->buffer.byteIndex], bdata, len); \
00241 (pctxt)->buffer.byteIndex += len; \
00242 (pctxt)->lastChar = (pctxt)->buffer.data[(pctxt)->buffer.byteIndex-1]; } \
00243 else return LOG_RTERRNEW (pctxt, RTERR_BUFOVFLW); \
00244 } while (0)
00245
00246 #define OSRTSAFEMEMCPY1(pctxt,bdata,len,stat) \
00247 do { \
00248 if (rtxCheckOutputBuffer (pctxt, len) == 0) { \
00249 OSCRTLMEMCPY (&(pctxt)->buffer.data[(pctxt)->buffer.byteIndex], bdata, len); \
00250 (pctxt)->buffer.byteIndex += len; \
00251 (pctxt)->lastChar = (pctxt)->buffer.data[(pctxt)->buffer.byteIndex-1]; \
00252 stat = 0; } \
00253 else stat = RTERR_BUFOVFLW; \
00254 } while (0)
00255
00256 #define OSRTGETBUFUTF8LEN(pctxt) \
00257 rtxCalcUTF8Len (OSRTBUFPTR (pctxt), OSRTBUFSIZE (pctxt))
00258
00259 #define OSRTCHKBUFUTF8LEN(pctxt,lower,upper,stat) \
00260 do { size_t nchars = OSRTGETBUFUTF8LEN (pctxt); \
00261 stat = (nchars >= lower && nchars <= upper) ? 0 : RTERR_CONSVIO; } while(0)
00262
00263 #define OSRTENDOFBUF(pctxt) ((pctxt)->buffer.byteIndex >= (pctxt)->buffer.size)
00264
00265 #ifdef __cplusplus
00266 }
00267 #endif
00268
00269 #endif