char buf[SIZ * 3];
long n;
n = snprintf(buf, SIZ * 3, "%c+|%ld|%ld|%ld|%s|%s|\n",
- FromWhere,
- (*FreeMe)->nIncreases,
- (*FreeMe)->BufUsed,
- (*FreeMe)->BufSize,
- (*FreeMe)->bt,
- (*FreeMe)->bt_lastinc);
+ FromWhere,
+ (*FreeMe)->nIncreases,
+ (*FreeMe)->BufUsed,
+ (*FreeMe)->BufSize,
+ (*FreeMe)->bt,
+ (*FreeMe)->bt_lastinc
+ );
n = write(hFreeDbglog, buf, n);
}
else {
char buf[128];
long n;
n = snprintf(buf, 128, "%c_|0|%ld%ld|\n",
- FromWhere,
- (*FreeMe)->BufUsed,
- (*FreeMe)->BufSize);
+ FromWhere,
+ (*FreeMe)->BufUsed,
+ (*FreeMe)->BufSize
+ );
n = write(hFreeDbglog, buf, n);
}
}
* flush the content of a Buf; keep its struct
* buf Buffer to flush
*/
-int FlushStrBuf(StrBuf *buf)
-{
- if ((buf == NULL) || (buf->buf == NULL))
+int FlushStrBuf(StrBuf *buf) {
+ if ((buf == NULL) || (buf->buf == NULL)) {
return -1;
- if (buf->ConstBuf)
- return -1;
+ }
+ if (buf->ConstBuf) {
+ return -1;
+ }
buf->buf[0] ='\0';
buf->BufUsed = 0;
return 0;
// AppendBuf Buffer to copy at the end of our buffer
// Offset Should we start copying from an offset?
void StrBufAppendBuf(StrBuf *Buf, const StrBuf *AppendBuf, unsigned long Offset) {
- if ((AppendBuf == NULL) || (AppendBuf->buf == NULL) ||
- (Buf == NULL) || (Buf->buf == NULL))
+ if ((AppendBuf == NULL) || (AppendBuf->buf == NULL) || (Buf == NULL) || (Buf->buf == NULL)) {
return;
+ }
if (Buf->BufSize - Offset < AppendBuf->BufUsed + Buf->BufUsed + 1)
IncreaseBuf(Buf, (Buf->BufUsed > 0), AppendBuf->BufUsed + Buf->BufUsed);
IncreaseBuf(Buf, (Buf->BufUsed > 0), BufSizeRequired);
}
- memcpy(Buf->buf + Buf->BufUsed,
- AppendBuf + Offset,
- aps);
+ memcpy(Buf->buf + Buf->BufUsed, AppendBuf + Offset, aps);
Buf->BufUsed += aps;
Buf->buf[Buf->BufUsed] = '\0';
}
return 0;
}
if (Offset + nChars < Source->BufUsed) {
- if ((nChars >= dest->BufSize) &&
- (IncreaseBuf(dest, 0, nChars + 1) == -1))
+ if ((nChars >= dest->BufSize) && (IncreaseBuf(dest, 0, nChars + 1) == -1)) {
return 0;
+ }
memcpy(dest->buf, Source->buf + Offset, nChars);
dest->BufUsed = nChars;
dest->buf[dest->BufUsed] = '\0';
return nChars;
}
NCharsRemain = Source->BufUsed - Offset;
- if ((NCharsRemain >= dest->BufSize) &&
- (IncreaseBuf(dest, 0, NCharsRemain + 1) == -1))
+ if ((NCharsRemain >= dest->BufSize) && (IncreaseBuf(dest, 0, NCharsRemain + 1) == -1)) {
return 0;
+ }
memcpy(dest->buf, Source->buf + Offset, NCharsRemain);
dest->BufUsed = NCharsRemain;
dest->buf[dest->BufUsed] = '\0';
int delta = 0;
if ((Buf == NULL) || (Buf->BufUsed == 0)) return;
- while ((Buf->BufUsed > 0) &&
- isspace(Buf->buf[Buf->BufUsed - 1]))
- {
+ while ((Buf->BufUsed > 0) && isspace(Buf->buf[Buf->BufUsed - 1])) {
Buf->BufUsed --;
}
Buf->buf[Buf->BufUsed] = '\0';
* 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)
-{
+int StrBufReplaceToken(StrBuf *Buf, long where, long HowLong, const char *Repl, long ReplLen) {
- if ((Buf == NULL) ||
- (where > Buf->BufUsed) ||
- (where + HowLong > Buf->BufUsed))
+ if ((Buf == NULL) || (where > Buf->BufUsed) || (where + HowLong > Buf->BufUsed)) {
return -1;
+ }
- if (where + ReplLen - HowLong > Buf->BufSize)
- if (IncreaseBuf(Buf, 1, Buf->BufUsed + ReplLen) < 0)
+ if (where + ReplLen - HowLong > Buf->BufSize) {
+ if (IncreaseBuf(Buf, 1, Buf->BufUsed + ReplLen) < 0) {
return -1;
+ }
+ }
- memmove(Buf->buf + where + ReplLen,
- Buf->buf + where + HowLong,
- Buf->BufUsed - where - HowLong);
-
- memcpy(Buf->buf + where,
- Repl, ReplLen);
-
+ memmove(Buf->buf + where + ReplLen, Buf->buf + where + HowLong, Buf->BufUsed - where - HowLong);
+ memcpy(Buf->buf + where, Repl, ReplLen);
Buf->BufUsed += ReplLen - HowLong;
-
return Buf->BufUsed;
}
* tok Tokenizer char to count
* @returns numbers of tokenizer chars found
*/
-int StrBufNum_tokens(const StrBuf *source, char tok)
-{
+int StrBufNum_tokens(const StrBuf *source, char tok) {
char *pch, *pche;
long NTokens;
if ((source == NULL) || (source->BufUsed == 0))
/* Find desired eter */
end = Source->buf + Source->BufUsed;
d = Source->buf;
- while ((d <= end) &&
- (count < parmnum))
- {
+ while ((d <= end) && (count < parmnum)) {
/* End of string, bail! */
if (!*d) {
d = NULL;
/* Find next eter */
s = d;
- while ((s <= end) &&
- (*s && *s != separator))
- {
+ while ((s <= end) && (*s && *s != separator)) {
s++;
}
if (*s == separator)
break;
}
}
- if ( (current_token == parmnum) &&
- (*s != separator)) {
+ if ( (current_token == parmnum) && (*s != separator)) {
dest->buf[len] = *s;
++len;
}
* 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))
- {
+int StrBufHaveNextToken(const StrBuf *Source, const char **pStart) {
+ if ((Source == NULL) || (*pStart == StrBufNOTNULL) || (Source->BufUsed == 0)) {
return 0;
}
- if (*pStart == NULL)
- {
+ if (*pStart == NULL) {
return 1;
}
- else if (*pStart > Source->buf + Source->BufUsed)
- {
+ else if (*pStart > Source->buf + Source->BufUsed) {
return 0;
}
- else if (*pStart <= Source->buf)
- {
+ else if (*pStart <= Source->buf) {
return 0;
}
* separator tokenizer
* @returns -1 if not found, else length of token.
*/
-int StrBufExtract_NextToken(StrBuf *dest, const StrBuf *Source, const char **pStart, char separator)
-{
+int StrBufExtract_NextToken(StrBuf *dest, const StrBuf *Source, const char **pStart, char separator) {
const char *s; /* source */
const char *EndBuffer; /* end stop of source buffer */
int current_token = 0; /* token currently being processed */
int len = 0; /* running total length of extracted string */
- if ((Source == NULL) ||
- (Source->BufUsed == 0) )
- {
+ if ((Source == NULL) || (Source->BufUsed == 0)) {
*pStart = StrBufNOTNULL;
- if (dest != NULL)
+ if (dest != NULL) {
FlushStrBuf(dest);
+ }
return -1;
}
EndBuffer = Source->buf + Source->BufUsed;
- if (dest != NULL)
- {
+ if (dest != NULL) {
dest->buf[0] = '\0';
dest->BufUsed = 0;
}
- else
- {
+ else {
*pStart = EndBuffer + 1;
return -1;
}
- if (*pStart == NULL)
- {
+ if (*pStart == NULL) {
*pStart = Source->buf; /* we're starting to examine this buffer. */
}
- else if ((*pStart < Source->buf) ||
- (*pStart > EndBuffer ) )
- {
+ else if ((*pStart < Source->buf) || (*pStart > EndBuffer ) ) {
return -1; /* no more tokens to find. */
}
s = *pStart;
/* start to find the next token */
- while ((s <= EndBuffer) &&
- (current_token == 0) )
- {
- if (*s == separator)
- {
+ while ((s <= EndBuffer) && (current_token == 0) ) {
+ if (*s == separator) {
/* we found the next token */
++current_token;
}
- if (len >= dest->BufSize)
- {
+ if (len >= dest->BufSize) {
/* our Dest-buffer isn't big enough, increase it. */
dest->BufUsed = len;
* nTokens number of tokens to fastforward over
* @returns -1 if not found, else length of token.
*/
-int StrBufSkip_NTokenS(const StrBuf *Source, const char **pStart, char separator, int nTokens)
-{
+int StrBufSkip_NTokenS(const StrBuf *Source, const char **pStart, char separator, int nTokens) {
const char *s, *EndBuffer; //* source * /
int len = 0; //* running total length of extracted string * /
int current_token = 0; //* token currently being processed * /
- if ((Source == NULL) ||
- (Source->BufUsed ==0)) {
+ if ((Source == NULL) || (Source->BufUsed ==0)) {
return(-1);
}
if (nTokens == 0)
return (-1);
}
-
s = *pStart;
- //cit_backtrace();
- //lprintf (CTDL_DEBUG, "test >: n: %d sep: %c source: %s \n willi \n", parmnum, separator, source);
-
while ((s < EndBuffer) && !IsEmptyStr(s)) {
if (*s == separator) {
++current_token;
return(len);
}
-/**
- * a string tokenizer to fetch an integer
- * Source StringBuffer to read from
- * pStart Cursor on the tokenstring
- * separator tokenizer character
- * @returns 0 if not found, else integer representation of the token
- */
-int StrBufExtractNext_int(const StrBuf* Source, const char **pStart, char separator)
-{
+
+// a string tokenizer to fetch an integer
+// Source StringBuffer to read from
+// pStart Cursor on the tokenstring
+// separator tokenizer character
+// returns 0 if not found, else integer representation of the token
+int StrBufExtractNext_int(const StrBuf* Source, const char **pStart, char separator) {
StrBuf tmp;
char buf[64];
return 0;
}
-/**
- * a string tokenizer to fetch a long integer
- * Source StringBuffer to read from
- * pStart Cursor on the tokenstring
- * separator tokenizer character
- * @returns 0 if not found, else long integer representation of the token
- */
-long StrBufExtractNext_long(const StrBuf* Source, const char **pStart, char separator)
-{
+
+// a string tokenizer to fetch a long integer
+// Source StringBuffer to read from
+// pStart Cursor on the tokenstring
+// separator tokenizer character
+// returns 0 if not found, else long integer representation of the token
+long StrBufExtractNext_long(const StrBuf* Source, const char **pStart, char separator) {
StrBuf tmp;
char buf[64];
}
-/**
- * a string tokenizer to fetch an unsigned long
- * Source StringBuffer to read from
- * pStart Cursor on the tokenstring
- * separator tokenizer character
- * @returns 0 if not found, else unsigned long representation of the token
- */
-unsigned long StrBufExtractNext_unsigned_long(const StrBuf* Source, const char **pStart, char separator)
-{
+// a string tokenizer to fetch an unsigned long
+// Source StringBuffer to read from
+// pStart Cursor on the tokenstring
+// separator tokenizer character
+// returns 0 if not found, else unsigned long representation of the token
+unsigned long StrBufExtractNext_unsigned_long(const StrBuf* Source, const char **pStart, char separator) {
StrBuf tmp;
char buf[64];
char *pnum;
}
-
-
-
/*******************************************************************************
* Escape Appending *
*******************************************************************************/
-/**
- * Escape a string for feeding out as a URL while appending it to a Buffer
- * OutBuf the output buffer
- * In Buffer to encode
- * PlainIn way in from plain old c strings
- */
-void StrBufUrlescAppend(StrBuf *OutBuf, const StrBuf *In, const char *PlainIn)
-{
+// Escape a string for feeding out as a URL while appending it to a Buffer
+// OutBuf the output buffer
+// In Buffer to encode
+// PlainIn way in from plain old c strings
+void StrBufUrlescAppend(StrBuf *OutBuf, const StrBuf *In, const char *PlainIn) {
const char *pch, *pche;
char *pt, *pte;
int len;
- if (((In == NULL) && (PlainIn == NULL)) || (OutBuf == NULL) )
+ if (((In == NULL) && (PlainIn == NULL)) || (OutBuf == NULL) ) {
return;
+ }
if (PlainIn != NULL) {
len = strlen(PlainIn);
pch = PlainIn;
}
-/*
- * Escape a string for feeding out as a the username/password part of an URL while appending it to a Buffer
- * OutBuf the output buffer
- * In Buffer to encode
- * PlainIn way in from plain old c strings
- */
+// Escape a string for feeding out as a the username/password part of an URL while appending it to a Buffer
+// OutBuf the output buffer
+// In Buffer to encode
+// PlainIn way in from plain old c strings
void StrBufUrlescUPAppend(StrBuf *OutBuf, const StrBuf *In, const char *PlainIn) {
const char *pch, *pche;
char *pt, *pte;
*pt = '\0';
}
-/*
- * append a string with characters having a special meaning in xml encoded to the buffer
- * OutBuf the output buffer
- * In Buffer to encode
- * 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?
- * OverrideLowChars should chars < 0x20 be replaced by _ or escaped as xml entity?
- */
+
+// append a string with characters having a special meaning in xml encoded to the buffer
+// OutBuf the output buffer
+// In Buffer to encode
+// 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?
+// OverrideLowChars should chars < 0x20 be replaced by _ or escaped as xml entity?
void StrBufXMLEscAppend(StrBuf *OutBuf,
const StrBuf *In,
const char *PlainIn,
return Target->BufUsed;
}
-/**
- * Append a string, escaping characters which have meaning in HTML + json.
- *
- * Target target buffer
- * Source source buffer; set to NULL if you just have a C-String
- * PlainIn Plain-C string to append; set to NULL if unused
- * nbsp If nonzero, spaces are converted to non-breaking spaces.
- * nolinebreaks if set to 1, linebreaks are removed from the string.
- * if set to 2, linebreaks are replaced by <br/>
- */
-long StrHtmlEcmaEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn, int nbsp, int nolinebreaks)
-{
+// Append a string, escaping characters which have meaning in HTML + json.
+//
+// Target target buffer
+// Source source buffer; set to NULL if you just have a C-String
+// PlainIn Plain-C string to append; set to NULL if unused
+// nbsp If nonzero, spaces are converted to non-breaking spaces.
+// nolinebreaks if set to 1, linebreaks are removed from the string.
+// if set to 2, linebreaks are replaced by <br/>
+long StrHtmlEcmaEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn, int nbsp, int nolinebreaks) {
const char *aptr, *eiptr;
char *bptr, *eptr;
long len;
int IsUtf8Sequence = 0;
- if (((Source == NULL) && (PlainIn == NULL)) || (Target == NULL) )
+ if (((Source == NULL) && (PlainIn == NULL)) || (Target == NULL)) {
return -1;
-
+ }
if (PlainIn != NULL) {
aptr = PlainIn;
len = strlen(PlainIn);
len = Source->BufUsed;
}
- if (len == 0)
+ if (len == 0) {
return -1;
+ }
bptr = Target->buf + Target->BufUsed;
- eptr = Target->buf + Target->BufSize - 11; /* our biggest unit to put in... */
+ eptr = Target->buf + Target->BufSize - 11; // our biggest unit to put in...
- while (aptr < eiptr){
+ while (aptr < eiptr) {
if(bptr >= eptr) {
IncreaseBuf(Target, 1, -1);
- eptr = Target->buf + Target->BufSize - 11; /* our biggest unit to put in... */
+ eptr = Target->buf + Target->BufSize - 11; // our biggest unit to put in...
bptr = Target->buf + Target->BufUsed;
}
switch (*aptr) {
isxdigit(*(aptr + 3)) &&
isxdigit(*(aptr + 4)) &&
isxdigit(*(aptr + 5)))
- { /* oh, a unicode escaper. let it pass through. */
+ { /* oh, a unicode escaper. let it pass through. */
memcpy(bptr, aptr, 6);
aptr += 5;
bptr +=6;
Target->BufUsed += 6;
}
- else
- {
+ else {
*bptr = '\\';
bptr ++;
*bptr = '\\';
bptr ++;
Target->BufUsed += 2;
break;
- case 32:
+ case 32:
if (nbsp == 1) {
memcpy(bptr, HKEY(" "));
bptr += 6;
}
-/*
- * unhide special chars hidden to the HTML escaper
- * target buffer to put the unescaped string in
- * source buffer to unescape
- */
+
+// unhide special chars hidden to the HTML escaper
+// target buffer to put the unescaped string in
+// source buffer to unescape
void StrBufEUid_unescapize(StrBuf *target, const StrBuf *source) {
int a, b, len;
char hex[3];
if (target != NULL)
FlushStrBuf(target);
- if ((source == NULL) || (target == NULL) || (target->buf == NULL))
- {
+ if ((source == NULL) || (target == NULL) || (target->buf == NULL)) {
return;
}
vStreamT *StrBufNewStreamContext(eStreamType type, const char **Err) {
- //base64_decodestate *state;;
*Err = NULL;
switch (type) {
- //case eBase64Decode:
- //case eBase64Encode:
- //state = (base64_decodestate*) malloc(sizeof(base64_decodestate));
- //base64_init_decodestate(state);
- //return (vStreamT*) state;
- //break;
-
case eZLibDecode: {
z_enc_stream *stream;