-// Copyright (c) 1987-2023 by the citadel.org team
+// Copyright (c) 1987-2024 by the citadel.org team
//
-// This program is open source software. Use, duplication, or disclosure
-// is subject to the terms of the GNU General Public License, version 3.
+// This program is open source software. Use, duplication, or disclosure is subject to the GNU General Public License, version 3.
#define _GNU_SOURCE
#include "sysdep.h"
#endif
int BaseStrBufSize = 64;
int EnableSplice = 0;
-int ZLibCompressionRatio = -1; /* defaults to 6 */
+int ZLibCompressionRatio = -1; // defaults to 6
#ifdef HAVE_ZLIB
-#define DEF_MEM_LEVEL 8 /*< memlevel??? */
-#define OS_CODE 0x03 /*< unix */
-const int gz_magic[2] = { 0x1f, 0x8b }; /* gzip magic header */
+#define DEF_MEM_LEVEL 8 // memlevel???
+#define OS_CODE 0x03 // unix
+const int gz_magic[2] = { 0x1f, 0x8b }; // gzip magic header
#endif
const char *StrBufNOTNULL = ((char*) NULL) - 1;
}
#else
-/* void it... */
+// void it...
#define dbg_FreeStrBuf(a, b)
#define dbg_IncreaseBuf(a)
#define dbg_Init(a)
#endif
-/*
- * swaps the contents of two StrBufs
- * this is to be used to have cheap switched between a work-buffer and a target buffer
- * A First one
- * B second one
- */
+// swaps the contents of two StrBufs
+// this is to be used to have cheap switched between a work-buffer and a target buffer
+// A First one
+// B second one
static inline void iSwapBuffers(StrBuf *A, StrBuf *B) {
StrBuf C;
}
-/*
- * Cast operator to Plain String
- * @note if the buffer is altered by StrBuf operations, this pointer may become
- * invalid. So don't lean on it after altering the buffer!
- * Since this operation is considered cheap, rather call it often than risking
- * your pointer to become invalid!
- * Str the string we want to get the c-string representation for
- * @returns the Pointer to the Content. Don't mess with it!
- */
+// Cast operator to Plain String
+// note: if the buffer is altered by StrBuf operations, this pointer may become
+// invalid. So don't lean on it after altering the buffer!
+// Since this operation is considered cheap, rather call it often than risking
+// your pointer to become invalid!
+// Str the string we want to get the c-string representation for
+// returns the Pointer to the Content. Don't mess with it!
inline const char *ChrPtr(const StrBuf *Str) {
if (Str == NULL)
return "";
}
-/*
- * since we know strlen()'s result, provide it here.
- * Str the string to return the length to
- * @returns contentlength of the buffer
- */
+// since we know strlen()'s result, provide it here.
+// Str the string to return the length to
+// returns contentlength of the buffer
inline int StrLength(const StrBuf *Str) {
return (Str != NULL) ? Str->BufUsed : 0;
}
}
-/*
- * shrink long term buffers to their real size so they don't waste memory
- * Buf buffer to shrink
- * Force if not set, will just executed if the buffer is much to big; set for lifetime strings
- * @returns physical size of the buffer
- */
+// shrink long term buffers to their real size so they don't waste memory
+// Buf buffer to shrink
+// Force if not set, will just executed if the buffer is much to big; set for lifetime strings
+// returns physical size of the buffer
long StrBufShrinkToFit(StrBuf *Buf, int Force) {
if (Buf == NULL)
return -1;
}
-/*
- * Allocate a new buffer with default buffer size
- * @returns the new stringbuffer
- */
+// Allocate a new buffer with default buffer size
+// returns the new stringbuffer
StrBuf *NewStrBuf(void) {
StrBuf *NewBuf;
}
-/*
- * Copy Constructor; returns a duplicate of CopyMe
- * CopyMe Buffer to faxmilate
- * @returns the new stringbuffer
- */
+// Copy Constructor; returns a duplicate of CopyMe
+// CopyMe Buffer to faxmilate
+// returns the new stringbuffer
StrBuf *NewStrBufDup(const StrBuf *CopyMe) {
StrBuf *NewBuf;
}
-/*
- * Copy Constructor; CreateRelpaceMe will contain CopyFlushMe afterwards.
- * NoMe if non-NULL, we will use that buffer as value; KeepOriginal will abused as len.
- * CopyFlushMe Buffer to faxmilate if KeepOriginal, or to move into CreateRelpaceMe if !KeepOriginal.
- * CreateRelpaceMe If NULL, will be created, else Flushed and filled CopyFlushMe
- * KeepOriginal should CopyFlushMe remain intact? or may we Steal its buffer?
- * @returns the new stringbuffer
- */
+// Copy Constructor; CreateRelpaceMe will contain CopyFlushMe afterwards.
+// NoMe if non-NULL, we will use that buffer as value; KeepOriginal will abused as len.
+// CopyFlushMe Buffer to faxmilate if KeepOriginal, or to move into CreateRelpaceMe if !KeepOriginal.
+// CreateRelpaceMe If NULL, will be created, else Flushed and filled CopyFlushMe
+// KeepOriginal should CopyFlushMe remain intact? or may we Steal its buffer?
+// returns the new stringbuffer
void NewStrBufDupAppendFlush(StrBuf **CreateRelpaceMe, StrBuf *CopyFlushMe, const char *NoMe, int KeepOriginal) {
StrBuf *NewBuf;
return;
}
- /*
- * Randomly Chosen: bigger than 64 chars is cheaper to swap the buffers instead of copying.
- * else *CreateRelpaceMe may use more memory than needed in a longer term, CopyFlushMe might
- * be a big IO-Buffer...
- */
+ // Randomly Chosen: bigger than 64 chars is cheaper to swap the buffers instead of copying.
+ // else *CreateRelpaceMe may use more memory than needed in a longer term, CopyFlushMe might
+ // be a big IO-Buffer...
if (KeepOriginal || (StrLength(CopyFlushMe) < 256)) {
if (*CreateRelpaceMe == NULL) {
*CreateRelpaceMe = NewBuf = NewStrBufPlain(NULL, CopyFlushMe->BufUsed);
}
-/*
- * create a new Buffer using an existing c-string
- * this function should also be used if you want to pre-suggest
- * the buffer size to allocate in conjunction with ptr == NULL
- * ptr the c-string to copy; may be NULL to create a blank instance
- * nChars How many chars should we copy; -1 if we should measure the length ourselves
- * @returns the new stringbuffer
- */
+// create a new Buffer using an existing c-string
+// this function should also be used if you want to pre-suggest
+// the buffer size to allocate in conjunction with ptr == NULL
+// ptr the c-string to copy; may be NULL to create a blank instance
+// nChars How many chars should we copy; -1 if we should measure the length ourselves
+// returns the new stringbuffer
StrBuf *NewStrBufPlain(const char* ptr, int nChars) {
StrBuf *NewBuf;
size_t Siz = BaseStrBufSize;
}
-/*
- * Set an existing buffer from a c-string
- * Buf buffer to load
- * ptr c-string to put into
- * nChars set to -1 if we should work 0-terminated
- * @returns the new length of the string
- */
+//
+// Set an existing buffer from a c-string
+// Buf buffer to load
+// ptr c-string to put into
+// nChars set to -1 if we should work 0-terminated
+// @returns the new length of the string
+///
int StrBufPlain(StrBuf *Buf, const char* ptr, int nChars) {
size_t Siz;
size_t CopySize;
}
-/*
- * use strbuf as wrapper for a string constant for easy handling
- * StringConstant a string to wrap
- * SizeOfStrConstant should be sizeof(StringConstant)-1
- */
-StrBuf* _NewConstStrBuf(const char* StringConstant, size_t SizeOfStrConstant)
-{
+//
+// use strbuf as wrapper for a string constant for easy handling
+// StringConstant a string to wrap
+// SizeOfStrConstant should be sizeof(StringConstant)-1
+///
+StrBuf *_NewConstStrBuf(const char* StringConstant, size_t SizeOfStrConstant) {
StrBuf *NewBuf;
NewBuf = (StrBuf*) malloc(sizeof(StrBuf));
}
-/*
- * flush the content of a Buf; keep its struct
- * buf Buffer to flush
- */
+//
+// flush the content of a Buf; keep its struct
+// buf Buffer to flush
+///
int FlushStrBuf(StrBuf *buf) {
if ((buf == NULL) || (buf->buf == NULL)) {
return -1;
return 0;
}
-/*
- * wipe the content of a Buf thoroughly (overwrite it -> expensive); keep its struct
- * buf Buffer to wipe
- */
-int FLUSHStrBuf(StrBuf *buf)
-{
+//
+// wipe the content of a Buf thoroughly (overwrite it -> expensive); keep its struct
+// buf Buffer to wipe
+///
+int FLUSHStrBuf(StrBuf *buf) {
if (buf == NULL)
return -1;
if (buf->ConstBuf)
#ifdef SIZE_DEBUG
int hFreeDbglog = -1;
#endif
-/*
- * Release a Buffer
- * Its a double pointer, so it can NULL your pointer
- * so fancy SIG11 appear instead of random results
- * FreeMe Pointer Pointer to the buffer to free
- */
-void FreeStrBuf (StrBuf **FreeMe)
-{
+//
+// Release a Buffer
+// Its a double pointer, so it can NULL your pointer
+// so fancy SIG11 appear instead of random results
+// FreeMe Pointer Pointer to the buffer to free
+///
+void FreeStrBuf (StrBuf **FreeMe) {
if (*FreeMe == NULL)
return;
*FreeMe = NULL;
}
-/*
- * flatten a Buffer to the Char * we return
- * Its a double pointer, so it can NULL your pointer
- * so fancy SIG11 appear instead of random results
- * The Callee then owns the buffer and is responsible for freeing it.
- * SmashMe Pointer Pointer to the buffer to release Buf from and free
- * @returns the pointer of the buffer; Callee owns the memory thereafter.
- */
+//
+// flatten a Buffer to the Char * we return
+// Its a double pointer, so it can NULL your pointer
+// so fancy SIG11 appear instead of random results
+// The Callee then owns the buffer and is responsible for freeing it.
+// SmashMe Pointer Pointer to the buffer to release Buf from and free
+// @returns the pointer of the buffer; Callee owns the memory thereafter.
+///
char *SmashStrBuf (StrBuf **SmashMe) {
char *Ret;
}
-/*
- * Release the buffer
- * If you want put your StrBuf into a Hash, use this as Destructor.
- * VFreeMe untyped pointer to a StrBuf. be shure to do the right thing [TM]
- */
+// Release the buffer
+// If you want put your StrBuf into a Hash, use this as Destructor.
+// VFreeMe untyped pointer to a StrBuf. be shure to do the right thing [TM]
void HFreeStrBuf (void *VFreeMe) {
StrBuf *FreeMe = (StrBuf*)VFreeMe;
if (FreeMe == NULL)
}
-/*******************************************************************************
- * Simple string transformations *
- *******************************************************************************/
+//******************************************************************************
+// Simple string transformations *
+//******************************************************************************/
-// Wrapper around atol
+// Wrapper around atol
long StrTol(const StrBuf *Buf) {
if (Buf == NULL)
return 0;
}
-// Wrapper around atoi
+// Wrapper around atoi
int StrToi(const StrBuf *Buf) {
if (Buf == NULL)
return 0;
return NCharsRemain;
}
-/**
- * Cut nChars from the start of the string
- * Buf Buffer to modify
- * nChars how many chars should be skipped?
- */
-void StrBufCutLeft(StrBuf *Buf, int nChars)
-{
+// Cut nChars from the start of the string
+// Buf Buffer to modify
+// nChars how many chars should be skipped?
+void StrBufCutLeft(StrBuf *Buf, int nChars) {
if ((Buf == NULL) || (Buf->BufUsed == 0)) return;
if (nChars >= Buf->BufUsed) {
FlushStrBuf(Buf);
Buf->buf[Buf->BufUsed] = '\0';
}
-/**
- * Cut the trailing n Chars from the string
- * Buf Buffer to modify
- * nChars how many chars should be trunkated?
- */
-void StrBufCutRight(StrBuf *Buf, int nChars)
-{
+// Cut the trailing n Chars from the string
+// Buf Buffer to modify
+// nChars how many chars should be trunkated?
+void StrBufCutRight(StrBuf *Buf, int nChars) {
if ((Buf == NULL) || (Buf->BufUsed == 0) || (Buf->buf == NULL))
return;
Buf->buf[Buf->BufUsed] = '\0';
}
-/**
- * Cut the string after n Chars
- * Buf Buffer to modify
- * AfternChars after how many chars should we trunkate the string?
- * At if non-null and points inside of our string, cut it there.
- */
-void StrBufCutAt(StrBuf *Buf, int AfternChars, const char *At)
-{
+
+// Cut the string after n Chars
+// Buf Buffer to modify
+// AfternChars after how many chars should we trunkate the string?
+// At if non-null and points inside of our string, cut it there.
+void StrBufCutAt(StrBuf *Buf, int AfternChars, const char *At) {
if ((Buf == NULL) || (Buf->BufUsed == 0)) return;
if (At != NULL){
AfternChars = At - Buf->buf;
}
-/**
- * Strip leading and trailing spaces from a string; with premeasured and adjusted length.
- * Buf the string to modify
- */
-void StrBufTrim(StrBuf *Buf)
-{
+// Strip leading and trailing spaces from a string; with premeasured and adjusted length.
+// Buf the string to modify
+void StrBufTrim(StrBuf *Buf) {
int delta = 0;
if ((Buf == NULL) || (Buf->BufUsed == 0)) return;
}
if (delta > 0) StrBufCutLeft(Buf, delta);
}
-/**
- * changes all spaces in the string (tab, linefeed...) to Blank (0x20)
- * Buf the string to modify
- */
-void StrBufSpaceToBlank(StrBuf *Buf)
-{
+
+
+// changes all spaces in the string (tab, linefeed...) to Blank (0x20)
+// Buf the string to modify
+void StrBufSpaceToBlank(StrBuf *Buf) {
char *pche, *pch;
if ((Buf == NULL) || (Buf->BufUsed == 0)) return;
}
}
-void StrBufStripAllBut(StrBuf *Buf, char leftboundary, char rightboundary)
-{
+void StrBufStripAllBut(StrBuf *Buf, char leftboundary, char rightboundary) {
const char *pLeft;
const char *pRight;
}
-/**
- * uppercase the contents of a buffer
- * Buf the buffer to translate
- */
-void StrBufUpCase(StrBuf *Buf)
-{
+// uppercase the contents of a buffer
+// Buf the buffer to translate
+void StrBufUpCase(StrBuf *Buf) {
char *pch, *pche;
if ((Buf == NULL) || (Buf->BufUsed == 0)) return;
}
-/**
- * lowercase the contents of a buffer
- * Buf the buffer to translate
- */
-void StrBufLowerCase(StrBuf *Buf)
-{
+// lowercase the contents of a buffer
+// Buf the buffer to translate
+void StrBufLowerCase(StrBuf *Buf) {
char *pch, *pche;
if ((Buf == NULL) || (Buf->BufUsed == 0)) return;
}
-/*******************************************************************************
- * a tokenizer that kills, maims, and destroys *
- *******************************************************************************/
+//******************************************************************************
+// a tokenizer that kills, maims, and destroys *
+//******************************************************************************/
-/**
- * Replace a token at a given place with a given length by another token with given length
- * Buf String where to work on
- * where where inside of the Buf is the search-token
- * HowLong How long is the token to be replaced
- * Repl Token to insert at 'where'
- * ReplLen Length of repl
- * @returns -1 if fail else length of resulting Buf
- */
+//*
+// Replace a token at a given place with a given length by another token with given length
+// Buf String where to work on
+// where where inside of the Buf is the search-token
+// HowLong How long is the token to be replaced
+// Repl Token to insert at 'where'
+// ReplLen Length of repl
+// @returns -1 if fail else length of resulting Buf
+///
int StrBufReplaceToken(StrBuf *Buf, long where, long HowLong, const char *Repl, long ReplLen) {
if ((Buf == NULL) || (where > Buf->BufUsed) || (where + HowLong > Buf->BufUsed)) {
memmove(Buf->buf + where + ReplLen, Buf->buf + where + HowLong, Buf->BufUsed - where - HowLong);
memcpy(Buf->buf + where, Repl, ReplLen);
Buf->BufUsed += ReplLen - HowLong;
+ Buf->buf[Buf->BufUsed] = 0;
return Buf->BufUsed;
}
-/**
- * Counts the numbmer of tokens in a buffer
- * source String to count tokens in
- * tok Tokenizer char to count
- * @returns numbers of tokenizer chars found
- */
+// Counts the numbmer of tokens in a buffer
+// source String to count tokens in
+// tok Tokenizer char to count
+// @returns numbers of tokenizer chars found
int StrBufNum_tokens(const StrBuf *source, char tok) {
char *pch, *pche;
long NTokens;
return NTokens;
}
-/**
- * a string tokenizer
- * Source StringBuffer to read into
- * parmnum n'th Parameter to remove
- * separator tokenizer character
- * @returns -1 if not found, else length of token.
- */
-int StrBufRemove_token(StrBuf *Source, int parmnum, char separator)
-{
+
+// a string tokenizer
+// Source StringBuffer to read into
+// parmnum n'th Parameter to remove
+// separator tokenizer character
+// @returns -1 if not found, else length of token.
+int StrBufRemove_token(StrBuf *Source, int parmnum, char separator) {
int ReducedBy;
- char *d, *s, *end; /* dest, source */
+ char *d, *s, *end; // dest, source
int count = 0;
- /* Find desired eter */
+ // Find desired eter
end = Source->buf + Source->BufUsed;
d = Source->buf;
while ((d <= end) && (count < parmnum)) {
- /* End of string, bail! */
+ // End of string, bail!
if (!*d) {
d = NULL;
break;
d++;
}
if ((d == NULL) || (d >= end))
- return 0; /* @Parameter not found */
+ return 0; // Parameter not found
- /* Find next eter */
+ // Find next eter
s = d;
while ((s <= end) && (*s && *s != separator)) {
s++;
s++;
ReducedBy = d - s;
- /* Hack and slash */
+ // Hack and slash
if (s >= end) {
return 0;
}
*--d = '\0';
Source->BufUsed += ReducedBy;
}
- /*
- while (*s) {
- *d++ = *s++;
- }
- *d = 0;
- */
+
+ //while (*s) {
+ //*d++ = *s++;
+ //}
+ //*d = 0;
+
return ReducedBy;
}
-int StrBufExtract_tokenFromStr(StrBuf *dest, const char *Source, long SourceLen, int parmnum, char separator)
-{
+int StrBufExtract_tokenFromStr(StrBuf *dest, const char *Source, long SourceLen, int parmnum, char separator) {
const StrBuf Temp = {
(char*)Source,
SourceLen,
return StrBufExtract_token(dest, &Temp, parmnum, separator);
}
-/**
- * a string tokenizer
- * dest Destination StringBuffer
- * Source StringBuffer to read into
- * parmnum n'th Parameter to extract
- * separator tokenizer character
- * @returns -1 if not found, else length of token.
- */
-int StrBufExtract_token(StrBuf *dest, const StrBuf *Source, int parmnum, char separator)
-{
- const char *s, *e; //* source * /
- int len = 0; //* running total length of extracted string * /
- int current_token = 0; //* token currently being processed * /
+// a string tokenizer
+// dest Destination StringBuffer
+// Source StringBuffer to read into
+// parmnum n'th Parameter to extract
+// separator tokenizer character
+// returns -1 if not found, else length of token.
+int StrBufExtract_token(StrBuf *dest, const StrBuf *Source, int parmnum, char separator) {
+ const char *s, *e; // source
+ int len = 0; // running total length of extracted string
+ int current_token = 0; // token currently being processed
if (dest != NULL) {
dest->buf[0] = '\0';
}
-
-
-
-/**
- * a string tokenizer to fetch an integer
- * Source String containing tokens
- * parmnum n'th Parameter to extract
- * separator tokenizer character
- * @returns 0 if not found, else integer representation of the token
- */
-int StrBufExtract_int(const StrBuf* Source, int parmnum, char separator)
-{
+// a string tokenizer to fetch an integer
+// Source String containing tokens
+// parmnum n'th Parameter to extract
+// separator tokenizer character
+// @returns 0 if not found, else integer representation of the token
+int StrBufExtract_int(const StrBuf* Source, int parmnum, char separator) {
StrBuf tmp;
char buf[64];
return 0;
}
-/**
- * a string tokenizer to fetch a long integer
- * Source String containing tokens
- * parmnum n'th Parameter to extract
- * separator tokenizer character
- * @returns 0 if not found, else long integer representation of the token
- */
-long StrBufExtract_long(const StrBuf* Source, int parmnum, char separator)
-{
+
+// a string tokenizer to fetch a long integer
+// Source String containing tokens
+// parmnum n'th Parameter to extract
+// separator tokenizer character
+// returns 0 if not found, else long integer representation of the token
+long StrBufExtract_long(const StrBuf* Source, int parmnum, char separator) {
StrBuf tmp;
char buf[64];
}
-/**
- * a string tokenizer to fetch an unsigned long
- * Source String containing tokens
- * parmnum n'th Parameter to extract
- * separator tokenizer character
- * @returns 0 if not found, else unsigned long representation of the token
- */
-unsigned long StrBufExtract_unsigned_long(const StrBuf* Source, int parmnum, char separator)
-{
+// a string tokenizer to fetch an unsigned long
+// Source String containing tokens
+// parmnum n'th Parameter to extract
+// separator tokenizer character
+// returns 0 if not found, else unsigned long representation of the token
+unsigned long StrBufExtract_unsigned_long(const StrBuf* Source, int parmnum, char separator) {
StrBuf tmp;
char buf[64];
char *pnum;
}
-
-/**
- * a string tokenizer; Bounds checker
- * function to make shure whether StrBufExtract_NextToken and friends have reached the end of the string.
- * Source our tokenbuffer
- * pStart the token iterator pointer to inspect
- * @returns whether the revolving pointer is inside of the search range
- */
+// a string tokenizer; Bounds checker
+// function to make shure whether StrBufExtract_NextToken and friends have reached the end of the string.
+// Source our tokenbuffer
+// pStart the token iterator pointer to inspect
+// returns whether the revolving pointer is inside of the search range
int StrBufHaveNextToken(const StrBuf *Source, const char **pStart) {
if ((Source == NULL) || (*pStart == StrBufNOTNULL) || (Source->BufUsed == 0)) {
return 0;
* PlainIn way in from plain old c strings
* PlainInLen way in from plain old c strings; maybe you've got binary data or know the length?
*/
-void StrBufHexEscAppend(StrBuf *OutBuf, const StrBuf *In, const unsigned char *PlainIn, long PlainInLen)
-{
+void StrBufHexEscAppend(StrBuf *OutBuf, const StrBuf *In, const unsigned char *PlainIn, long PlainInLen) {
const unsigned char *pch, *pche;
char *pt, *pte;
int len;
* nolinebreaks if set to 1, linebreaks are removed from the string.
* if set to 2, linebreaks are replaced by <br/>
*/
-long StrEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn, int nbsp, int nolinebreaks)
-{
+long StrEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn, int nbsp, int nolinebreaks) {
const char *aptr, *eiptr;
char *bptr, *eptr;
long len;
* Source source buffer; set to NULL if you just have a C-String
* PlainIn Plain-C string to append; set to NULL if unused
*/
-void StrMsgEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn)
-{
+void StrMsgEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn) {
const char *aptr, *eiptr;
char *tptr, *eptr;
long len;
* Source source buffer; set to NULL if you just have a C-String
* PlainIn Plain-C string to append; set to NULL if unused
*/
-void StrIcalEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn)
-{
+void StrIcalEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn) {
const char *aptr, *eiptr;
char *tptr, *eptr;
long len;
* PlainIn Plain-C string to append; set to NULL if unused
* @returns size of result or -1
*/
-long StrECMAEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn)
-{
+long StrECMAEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn) {
const char *aptr, *eiptr;
char *bptr, *eptr;
long len;
* Mute char to put over invalid chars
* Buf Buffor to transform
*/
-int StrBufSanitizeAscii(StrBuf *Buf, const char Mute)
-{
+int StrBufSanitizeAscii(StrBuf *Buf, const char Mute) {
unsigned char *pch;
if (Buf == NULL) return -1;
* Buf Buffer to translate
* StripBlanks Reduce several blanks to one?
*/
-long StrBufUnescape(StrBuf *Buf, int StripBlanks)
-{
+long StrBufUnescape(StrBuf *Buf, int StripBlanks) {
int a, b;
char hex[3];
long len;
* source Source string to be encoded.
* @returns encoded length; -1 if non success.
*/
-int StrBufRFC2047encode(StrBuf **target, const StrBuf *source)
-{
+int StrBufRFC2047encode(StrBuf **target, const StrBuf *source) {
const char headerStr[] = "=?UTF-8?Q?";
int need_to_encode = 0;
int i = 0;
* removes all \\r s from the string, or replaces them with \n if its not a combination of both.
* buf Buffer to modify
*/
-void StrBufToUnixLF(StrBuf *buf)
-{
+void StrBufToUnixLF(StrBuf *buf) {
char *pche, *pchS, *pchT;
if (buf == NULL)
return;
* fromcode Source encoding
* pic anonimized pointer to iconv struct
*/
-void ctdl_iconv_open(const char *tocode, const char *fromcode, void *pic)
-{
+void ctdl_iconv_open(const char *tocode, const char *fromcode, void *pic) {
#ifdef HAVE_ICONV
iconv_t ic = (iconv_t)(-1) ;
ic = iconv_open(tocode, fromcode);
* bptr where to start searching
* @returns found position, NULL if none.
*/
-static inline const char *FindNextEnd (const StrBuf *Buf, const char *bptr)
-{
+static inline const char *FindNextEnd (const StrBuf *Buf, const char *bptr) {
const char * end;
/* Find the next ?Q? */
if (Buf->BufUsed - (bptr - Buf->buf) < 6)
* TmpBuf To share a workbuffer over several iterations. prepare to have it filled with useless stuff afterwards.
* pic Pointer to the iconv-session Object
*/
-void StrBufConvert(StrBuf *ConvertBuf, StrBuf *TmpBuf, void *pic)
-{
+void StrBufConvert(StrBuf *ConvertBuf, StrBuf *TmpBuf, void *pic) {
#ifdef HAVE_ICONV
long trycount = 0;
size_t siz;
* FoundCharset overrides DefaultCharset if non-empty; If we find a charset inside of the string,
* put it here for later use where no string might be known.
*/
-void StrBuf_RFC822_to_Utf8(StrBuf *Target, const StrBuf *DecodeMe, const StrBuf* DefaultCharset, StrBuf *FoundCharset)
-{
+void StrBuf_RFC822_to_Utf8(StrBuf *Target, const StrBuf *DecodeMe, const StrBuf* DefaultCharset, StrBuf *FoundCharset) {
StrBuf *ConvertBuf;
StrBuf *ConvertBuf2;
ConvertBuf = NewStrBufPlain(NULL, StrLength(DecodeMe));
* Char the character to examine
* @returns width of utf8 chars in bytes; if the sequence is broken 0 is returned; 1 if its simply ASCII.
*/
-static inline int Ctdl_GetUtf8SequenceLength(const char *CharS, const char *CharE)
-{
+static inline int Ctdl_GetUtf8SequenceLength(const char *CharS, const char *CharE) {
int n = 0;
unsigned char test = (1<<7);
* Char character to inspect
* @returns yes or no
*/
-static inline int Ctdl_IsUtf8SequenceStart(const char Char)
-{
+static inline int Ctdl_IsUtf8SequenceStart(const char Char) {
/** 11??.???? indicates an UTF8 Sequence. */
return ((Char & 0xC0) == 0xC0);
}
* Buf string to measure
* @returns the number of glyphs in Buf
*/
-long StrBuf_Utf8StrLen(StrBuf *Buf)
-{
+long StrBuf_Utf8StrLen(StrBuf *Buf) {
int n = 0;
int m = 0;
char *aptr, *eptr;
* maxlen how long may the string become?
* @returns current length of the string
*/
-long StrBuf_Utf8StrCut(StrBuf *Buf, int maxlen)
-{
+long StrBuf_Utf8StrCut(StrBuf *Buf, int maxlen) {
char *aptr, *eptr;
int n = 0, m = 0;
* Attention! If you feed this a Const String, you must maintain the uncompressed buffer yourself!
* Buf buffer whose content is to be gzipped
*/
-int CompressBuffer(StrBuf *Buf)
-{
+int CompressBuffer(StrBuf *Buf) {
#ifdef HAVE_ZLIB
char *compressed_data = NULL;
size_t compressed_len, bufsize;
* File I/O; Callbacks to libevent *
*******************************************************************************/
-long StrBuf_read_one_chunk_callback (int fd, short event, IOBuffer *FB)
-{
+long StrBuf_read_one_chunk_callback (int fd, short event, IOBuffer *FB) {
long bufremain = 0;
int n;
* check whether the chunk-buffer has more data waiting or not.
* FB Chunk-Buffer to inspect
*/
-eReadState StrBufCheckBuffer(IOBuffer *FB)
-{
+eReadState StrBufCheckBuffer(IOBuffer *FB) {
if (FB == NULL)
return eReadFail;
if (FB->Buf->BufUsed == 0)
* Error strerror() on error
* @returns numbers of chars read
*/
-int StrBufTCP_read_line(StrBuf *buf, int *fd, int append, const char **Error)
-{
+int StrBufTCP_read_line(StrBuf *buf, int *fd, int append, const char **Error) {
int len, rlen, slen;
if ((buf == NULL) || (buf->buf == NULL)) {
* Error strerror() on error
* @returns numbers of chars read
*/
-int StrBufReadBLOB(StrBuf *Buf, int *fd, int append, long nBytes, const char **Error)
-{
+int StrBufReadBLOB(StrBuf *Buf, int *fd, int append, long nBytes, const char **Error) {
int fdflags;
int rlen;
int nSuccessLess;