buffer.h
Go to the documentation of this file.
/***************************************************************************
begin : Fri Sep 12 2003
copyright : (C) 2020 by Martin Preuss
email : martin@libchipcard.de
***************************************************************************
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library 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 *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
* MA 02111-1307 USA *
* *
***************************************************************************/
#ifndef GWENHYWFAR_BUFFER_H
#define GWENHYWFAR_BUFFER_H
#include <gwenhywfar/gwenhywfarapi.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct GWEN_BUFFER GWEN_BUFFER;
#ifdef __cplusplus
}
#endif
#include <gwenhywfar/types.h>
//#include <gwenhywfar/syncio.h>
#include <stdio.h>
/* This is needed for PalmOS, because it define some functions needed */
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
#define GWEN_BUFFER_MAX_BOOKMARKS 64
#define GWEN_BUFFER_MODE_DYNAMIC 0x0001
#define GWEN_BUFFER_MODE_ABORT_ON_MEMFULL 0x0002
#define GWEN_BUFFER_MODE_READONLY 0x0020
#define GWEN_BUFFER_MODE_DEFAULT \
(\
GWEN_BUFFER_MODE_DYNAMIC | \
GWEN_BUFFER_MODE_ABORT_ON_MEMFULL\
)
GWENHYWFAR_API
GWEN_BUFFER *GWEN_Buffer_new(char *buffer,
uint32_t size,
uint32_t used,
int take_ownership);
GWENHYWFAR_API
void GWEN_Buffer_Attach(GWEN_BUFFER *bf);
GWENHYWFAR_API
void GWEN_Buffer_free(GWEN_BUFFER *bf);
GWENHYWFAR_API
GWEN_BUFFER *GWEN_Buffer_dup(GWEN_BUFFER *bf);
GWENHYWFAR_API
int GWEN_Buffer_Relinquish(GWEN_BUFFER *bf);
GWENHYWFAR_API
uint32_t GWEN_Buffer_GetMode(GWEN_BUFFER *bf);
GWENHYWFAR_API
void GWEN_Buffer_SetMode(GWEN_BUFFER *bf, uint32_t mode);
GWENHYWFAR_API
void GWEN_Buffer_AddMode(GWEN_BUFFER *bf, uint32_t mode);
GWENHYWFAR_API
void GWEN_Buffer_SubMode(GWEN_BUFFER *bf, uint32_t mode);
GWENHYWFAR_API
uint32_t GWEN_Buffer_GetHardLimit(GWEN_BUFFER *bf);
GWENHYWFAR_API
void GWEN_Buffer_SetHardLimit(GWEN_BUFFER *bf, uint32_t l);
GWENHYWFAR_API
uint32_t GWEN_Buffer_GetStep(GWEN_BUFFER *bf);
GWENHYWFAR_API
void GWEN_Buffer_SetStep(GWEN_BUFFER *bf, uint32_t step);
GWENHYWFAR_API
int GWEN_Buffer_ReserveBytes(GWEN_BUFFER *bf, uint32_t res);
GWENHYWFAR_API
char *GWEN_Buffer_GetStart(const GWEN_BUFFER *bf);
GWENHYWFAR_API
uint32_t GWEN_Buffer_GetSize(const GWEN_BUFFER *bf);
GWENHYWFAR_API
uint32_t GWEN_Buffer_GetPos(const GWEN_BUFFER *bf);
GWENHYWFAR_API
int GWEN_Buffer_SetPos(GWEN_BUFFER *bf, uint32_t i);
GWENHYWFAR_API
uint32_t GWEN_Buffer_GetUsedBytes(const GWEN_BUFFER *bf);
GWENHYWFAR_API
uint32_t GWEN_Buffer_GetBookmark(const GWEN_BUFFER *bf, unsigned int idx);
GWENHYWFAR_API
void GWEN_Buffer_SetBookmark(GWEN_BUFFER *bf, unsigned int idx,
uint32_t v);
GWENHYWFAR_API
int GWEN_Buffer_AppendBytes(GWEN_BUFFER *bf,
const char *buffer,
uint32_t size);
GWENHYWFAR_API GWEN_FORMAT(printf, 2, 3)
int GWEN_Buffer_AppendArgs(GWEN_BUFFER *bf, const char *fmt, ...);
GWENHYWFAR_API
int GWEN_Buffer_FillWithBytes(GWEN_BUFFER *bf,
unsigned char c,
uint32_t size);
GWENHYWFAR_API
int GWEN_Buffer_FillLeftWithBytes(GWEN_BUFFER *bf,
unsigned char c,
uint32_t size);
GWENHYWFAR_API
int GWEN_Buffer_AppendString(GWEN_BUFFER *bf,
const char *buffer);
GWENHYWFAR_API
int GWEN_Buffer_AppendByte(GWEN_BUFFER *bf, char c);
GWENHYWFAR_API
int GWEN_Buffer_InsertBytes(GWEN_BUFFER *bf,
const char *buffer,
uint32_t size);
GWENHYWFAR_API
int GWEN_Buffer_InsertRoom(GWEN_BUFFER *bf,
uint32_t size);
GWENHYWFAR_API
int GWEN_Buffer_RemoveRoom(GWEN_BUFFER *bf, uint32_t size);
GWENHYWFAR_API
int GWEN_Buffer_ReplaceBytes(GWEN_BUFFER *bf,
uint32_t rsize,
const char *buffer,
uint32_t size);
GWENHYWFAR_API
int GWEN_Buffer_InsertString(GWEN_BUFFER *bf,
const char *buffer);
GWENHYWFAR_API
int GWEN_Buffer_InsertByte(GWEN_BUFFER *bf, char c);
GWENHYWFAR_API
int GWEN_Buffer_ReadByte(GWEN_BUFFER *bf);
GWENHYWFAR_API
int GWEN_Buffer_ReadBytes(GWEN_BUFFER *bf,
char *buffer,
uint32_t *size);
GWENHYWFAR_API
int GWEN_Buffer_PeekByte(GWEN_BUFFER *bf);
GWENHYWFAR_API
int GWEN_Buffer_IncrementPos(GWEN_BUFFER *bf, uint32_t i);
GWENHYWFAR_API
int GWEN_Buffer_DecrementPos(GWEN_BUFFER *bf, uint32_t i);
GWENHYWFAR_API
int GWEN_Buffer_AdjustUsedBytes(GWEN_BUFFER *bf);
GWENHYWFAR_API
int GWEN_Buffer_InsertBuffer(GWEN_BUFFER *bf,
GWEN_BUFFER *sf);
GWENHYWFAR_API
int GWEN_Buffer_AppendBuffer(GWEN_BUFFER *bf,
GWEN_BUFFER *sf);
GWENHYWFAR_API
uint32_t GWEN_Buffer_GetMaxUnsegmentedWrite(GWEN_BUFFER *bf);
GWENHYWFAR_API
uint32_t GWEN_Buffer_GetBytesLeft(GWEN_BUFFER *bf);
GWENHYWFAR_API
char *GWEN_Buffer_GetPosPointer(const GWEN_BUFFER *bf);
GWENHYWFAR_API
void GWEN_Buffer_Reset(GWEN_BUFFER *bf);
GWENHYWFAR_API
void GWEN_Buffer_Rewind(GWEN_BUFFER *bf);
GWENHYWFAR_API
int GWEN_Buffer_AllocRoom(GWEN_BUFFER *bf, uint32_t size);
/* crops the buffer to the specified bytes */
GWENHYWFAR_API
int GWEN_Buffer_Crop(GWEN_BUFFER *bf,
uint32_t pos,
uint32_t l);
/* Overwrite complete buffer with a given value.
* This does not only overwrite the used bytes but all the memory held
* by this object.
*/
GWENHYWFAR_API
void GWEN_Buffer_OverwriteContent(GWEN_BUFFER *bf, int c);
GWENHYWFAR_API
int GWEN_Buffer_KeepTextBetweenStrings(GWEN_BUFFER *bf,
const char *openingString,
const char *closingString,
int onlyBetween);
GWENHYWFAR_API
void GWEN_Buffer_Dump(GWEN_BUFFER *bf, unsigned int insert);
GWENHYWFAR_API int GWENHYWFAR_CB GWEN_Buffer_CacheFn_Attach(void *ptr);
GWENHYWFAR_API int GWENHYWFAR_CB GWEN_Buffer_CacheFn_Free(void *ptr);
#ifdef __cplusplus
}
#endif
#endif
GWEN_Buffer_AllocRoom
GWENHYWFAR_API int GWEN_Buffer_AllocRoom(GWEN_BUFFER *bf, uint32_t size)
GWEN_Buffer_new
GWENHYWFAR_API GWEN_BUFFER * GWEN_Buffer_new(char *buffer, uint32_t size, uint32_t used, int take_ownership)
GWEN_Buffer_KeepTextBetweenStrings
GWENHYWFAR_API int GWEN_Buffer_KeepTextBetweenStrings(GWEN_BUFFER *bf, const char *openingString, const char *closingString, int onlyBetween)
GWEN_Buffer_GetPosPointer
GWENHYWFAR_API char * GWEN_Buffer_GetPosPointer(const GWEN_BUFFER *bf)
GWEN_Buffer_AppendString
GWENHYWFAR_API int GWEN_Buffer_AppendString(GWEN_BUFFER *bf, const char *buffer)
GWEN_Buffer_ReadBytes
GWENHYWFAR_API int GWEN_Buffer_ReadBytes(GWEN_BUFFER *bf, char *buffer, uint32_t *size)
GWEN_Buffer_SetPos
GWENHYWFAR_API int GWEN_Buffer_SetPos(GWEN_BUFFER *bf, uint32_t i)
GWEN_Buffer_InsertBuffer
GWENHYWFAR_API int GWEN_Buffer_InsertBuffer(GWEN_BUFFER *bf, GWEN_BUFFER *sf)
GWEN_Buffer_Relinquish
GWENHYWFAR_API int GWEN_Buffer_Relinquish(GWEN_BUFFER *bf)
GWEN_Buffer_GetMaxUnsegmentedWrite
GWENHYWFAR_API uint32_t GWEN_Buffer_GetMaxUnsegmentedWrite(GWEN_BUFFER *bf)
GWEN_Buffer_InsertString
GWENHYWFAR_API int GWEN_Buffer_InsertString(GWEN_BUFFER *bf, const char *buffer)
GWEN_Buffer_Crop
GWENHYWFAR_API int GWEN_Buffer_Crop(GWEN_BUFFER *bf, uint32_t pos, uint32_t l)
GWEN_Buffer_AdjustUsedBytes
GWENHYWFAR_API int GWEN_Buffer_AdjustUsedBytes(GWEN_BUFFER *bf)
GWEN_Buffer_GetStep
GWENHYWFAR_API uint32_t GWEN_Buffer_GetStep(GWEN_BUFFER *bf)
GWEN_Buffer_SetHardLimit
GWENHYWFAR_API void GWEN_Buffer_SetHardLimit(GWEN_BUFFER *bf, uint32_t l)
GWEN_Buffer_GetPos
GWENHYWFAR_API uint32_t GWEN_Buffer_GetPos(const GWEN_BUFFER *bf)
GWEN_Buffer_PeekByte
GWENHYWFAR_API int GWEN_Buffer_PeekByte(GWEN_BUFFER *bf)
GWEN_Buffer_SetMode
GWENHYWFAR_API void GWEN_Buffer_SetMode(GWEN_BUFFER *bf, uint32_t mode)
GWEN_Buffer_dup
GWENHYWFAR_API GWEN_BUFFER * GWEN_Buffer_dup(GWEN_BUFFER *bf)
GWEN_Buffer_AppendByte
GWENHYWFAR_API int GWEN_Buffer_AppendByte(GWEN_BUFFER *bf, char c)
GWEN_Buffer_DecrementPos
GWENHYWFAR_API int GWEN_Buffer_DecrementPos(GWEN_BUFFER *bf, uint32_t i)
GWEN_Buffer_SetBookmark
GWENHYWFAR_API void GWEN_Buffer_SetBookmark(GWEN_BUFFER *bf, unsigned int idx, uint32_t v)
GWEN_Buffer_GetMode
GWENHYWFAR_API uint32_t GWEN_Buffer_GetMode(GWEN_BUFFER *bf)
GWEN_Buffer_GetSize
GWENHYWFAR_API uint32_t GWEN_Buffer_GetSize(const GWEN_BUFFER *bf)
GWEN_Buffer_InsertBytes
GWENHYWFAR_API int GWEN_Buffer_InsertBytes(GWEN_BUFFER *bf, const char *buffer, uint32_t size)
GWEN_Buffer_Attach
GWENHYWFAR_API void GWEN_Buffer_Attach(GWEN_BUFFER *bf)
GWEN_Buffer_IncrementPos
GWENHYWFAR_API int GWEN_Buffer_IncrementPos(GWEN_BUFFER *bf, uint32_t i)
GWEN_Buffer_OverwriteContent
GWENHYWFAR_API void GWEN_Buffer_OverwriteContent(GWEN_BUFFER *bf, int c)
GWEN_Buffer_AddMode
GWENHYWFAR_API void GWEN_Buffer_AddMode(GWEN_BUFFER *bf, uint32_t mode)
GWEN_Buffer_RemoveRoom
GWENHYWFAR_API int GWEN_Buffer_RemoveRoom(GWEN_BUFFER *bf, uint32_t size)
GWEN_Buffer_InsertByte
GWENHYWFAR_API int GWEN_Buffer_InsertByte(GWEN_BUFFER *bf, char c)
GWEN_Buffer_AppendBytes
GWENHYWFAR_API int GWEN_Buffer_AppendBytes(GWEN_BUFFER *bf, const char *buffer, uint32_t size)
GWEN_Buffer_free
GWENHYWFAR_API void GWEN_Buffer_free(GWEN_BUFFER *bf)
GWEN_Buffer_ReplaceBytes
GWENHYWFAR_API int GWEN_Buffer_ReplaceBytes(GWEN_BUFFER *bf, uint32_t rsize, const char *buffer, uint32_t size)
GWEN_Buffer_ReserveBytes
GWENHYWFAR_API int GWEN_Buffer_ReserveBytes(GWEN_BUFFER *bf, uint32_t res)
GWEN_Buffer_GetUsedBytes
GWENHYWFAR_API uint32_t GWEN_Buffer_GetUsedBytes(const GWEN_BUFFER *bf)
GWEN_Buffer_GetStart
GWENHYWFAR_API char * GWEN_Buffer_GetStart(const GWEN_BUFFER *bf)
GWEN_Buffer_Dump
GWENHYWFAR_API void GWEN_Buffer_Dump(GWEN_BUFFER *bf, unsigned int insert)
GWEN_Buffer_SetStep
GWENHYWFAR_API void GWEN_Buffer_SetStep(GWEN_BUFFER *bf, uint32_t step)
GWEN_Buffer_Reset
GWENHYWFAR_API void GWEN_Buffer_Reset(GWEN_BUFFER *bf)
GWEN_Buffer_InsertRoom
GWENHYWFAR_API int GWEN_Buffer_InsertRoom(GWEN_BUFFER *bf, uint32_t size)
GWEN_Buffer_CacheFn_Attach
GWENHYWFAR_API int GWENHYWFAR_CB GWEN_Buffer_CacheFn_Attach(void *ptr)
GWEN_Buffer_Rewind
GWENHYWFAR_API void GWEN_Buffer_Rewind(GWEN_BUFFER *bf)
GWEN_Buffer_ReadByte
GWENHYWFAR_API int GWEN_Buffer_ReadByte(GWEN_BUFFER *bf)
GWEN_Buffer_GetBookmark
GWENHYWFAR_API uint32_t GWEN_Buffer_GetBookmark(const GWEN_BUFFER *bf, unsigned int idx)
GWEN_Buffer_AppendBuffer
GWENHYWFAR_API int GWEN_Buffer_AppendBuffer(GWEN_BUFFER *bf, GWEN_BUFFER *sf)
GWEN_Buffer_FillWithBytes
GWENHYWFAR_API const char GWENHYWFAR_API int GWEN_Buffer_FillWithBytes(GWEN_BUFFER *bf, unsigned char c, uint32_t size)
GWEN_Buffer_CacheFn_Free
GWENHYWFAR_API int GWENHYWFAR_CB GWEN_Buffer_CacheFn_Free(void *ptr)
GWEN_Buffer_GetHardLimit
GWENHYWFAR_API uint32_t GWEN_Buffer_GetHardLimit(GWEN_BUFFER *bf)
GWEN_Buffer_FillLeftWithBytes
GWENHYWFAR_API int GWEN_Buffer_FillLeftWithBytes(GWEN_BUFFER *bf, unsigned char c, uint32_t size)
GWEN_Buffer_SubMode
GWENHYWFAR_API void GWEN_Buffer_SubMode(GWEN_BUFFER *bf, uint32_t mode)
fmt
GWENHYWFAR_API const char * fmt
Definition buffer.h:283
GWEN_Buffer_GetBytesLeft
GWENHYWFAR_API uint32_t GWEN_Buffer_GetBytesLeft(GWEN_BUFFER *bf)
GWEN_BUFFER
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
Definition buffer.h:38
gwenhywfarapi.h
GWEN_FORMAT
#define GWEN_FORMAT(fmt, pos, argstart)
Definition gwenhywfarapi.h:160
GWENHYWFAR_API
#define GWENHYWFAR_API
Definition gwenhywfarapi.h:67
GWENHYWFAR_CB
#define GWENHYWFAR_CB
Definition gwenhywfarapi.h:89
types.h