* Simple string transformations *
*******************************************************************************/
-/*
- * Wrapper around atol
- */
-long StrTol(const StrBuf *Buf)
-{
+// Wrapper around atol
+long StrTol(const StrBuf *Buf) {
if (Buf == NULL)
return 0;
if(Buf->BufUsed > 0)
return 0;
}
-/*
- * Wrapper around atoi
- */
-int StrToi(const StrBuf *Buf)
-{
+
+// Wrapper around atoi
+int StrToi(const StrBuf *Buf) {
if (Buf == NULL)
return 0;
if (Buf->BufUsed > 0)
return 0;
}
-/*
- * Checks to see if the string is a pure number
- * Buf The buffer to inspect
- * @returns 1 if its a pure number, 0, if not.
- */
+
+// Checks to see if the string is a pure number
+// Buf The buffer to inspect
+// returns 1 if its a pure number, 0, if not.
int StrBufIsNumber(const StrBuf *Buf) {
char * pEnd;
if ((Buf == NULL) || (Buf->BufUsed == 0)) {
return 0;
}
-/**
- * modifies a Single char of the Buf
- * You can point to it via char* or a zero-based integer
- * Buf The buffer to manipulate
- * ptr char* to zero; use NULL if unused
- * nThChar zero based pointer into the string; use -1 if unused
- * PeekValue The Character to place into the position
- */
-long StrBufPeek(StrBuf *Buf, const char* ptr, long nThChar, char PeekValue)
-{
+
+// modifies a Single char of the Buf
+// You can point to it via char* or a zero-based integer
+// Buf The buffer to manipulate
+// ptr char* to zero; use NULL if unused
+// nThChar zero based pointer into the string; use -1 if unused
+// PeekValue The Character to place into the position
+long StrBufPeek(StrBuf *Buf, const char* ptr, long nThChar, char PeekValue) {
if (Buf == NULL)
return -1;
if (ptr != NULL)
return nThChar;
}
-/**
- * modifies a range of chars of the Buf
- * You can point to it via char* or a zero-based integer
- * Buf The buffer to manipulate
- * ptr char* to zero; use NULL if unused
- * nThChar zero based pointer into the string; use -1 if unused
- * nChars how many chars are to be flushed?
- * PookValue The Character to place into that area
- */
-long StrBufPook(StrBuf *Buf, const char* ptr, long nThChar, long nChars, char PookValue)
-{
+
+// modifies a range of chars of the Buf
+// You can point to it via char* or a zero-based integer
+// Buf The buffer to manipulate
+// ptr char* to zero; use NULL if unused
+// nThChar zero based pointer into the string; use -1 if unused
+// nChars how many chars are to be flushed?
+// PookValue The Character to place into that area
+long StrBufPook(StrBuf *Buf, const char* ptr, long nThChar, long nChars, char PookValue) {
if (Buf == NULL)
return -1;
if (ptr != NULL)
nChars = Buf->BufUsed - nThChar;
memset(Buf->buf + nThChar, PookValue, nChars);
- /* just to be shure... */
+ // just to be sure...
Buf->buf[Buf->BufUsed] = 0;
return nChars;
}
-/**
- * Append a StringBuffer to the buffer
- * Buf Buffer to modify
- * 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)
-{
+
+// Append a StringBuffer to the buffer
+// Buf Buffer to modify
+// 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))
return;
Buf->buf[Buf->BufUsed] = '\0';
}
-/*
- * sprintf like function appending the formated string to the buffer
- * vsnprintf version to wrap into own calls
- * Buf Buffer to extend by format and Params
- * format printf alike format to add
- * ap va_list containing the items for format
- */
-void StrBufVAppendPrintf(StrBuf *Buf, const char *format, va_list ap)
-{
+
+// sprintf like function appending the formated string to the buffer
+// vsnprintf version to wrap into own calls
+// Buf Buffer to extend by format and Params
+// format printf alike format to add
+// ap va_list containing the items for format
+void StrBufVAppendPrintf(StrBuf *Buf, const char *format, va_list ap) {
va_list apl;
size_t BufSize;
size_t nWritten;
while (newused >= BufSize) {
va_copy(apl, ap);
- nWritten = vsnprintf(Buf->buf + Offset,
- Buf->BufSize - Offset,
- format, apl);
+ nWritten = vsnprintf(Buf->buf + Offset, Buf->BufSize - Offset, format, apl);
va_end(apl);
newused = Offset + nWritten;
if (newused >= Buf->BufSize) {
if (IncreaseBuf(Buf, 1, newused) == -1)
- return; /* TODO: error handling? */
+ return; // TODO: error handling?
newused = Buf->BufSize + 1;
}
else {
}
}
-/**
- * sprintf like function appending the formated string to the buffer
- * Buf Buffer to extend by format and Params
- * format printf alike format to add
- */
-void StrBufAppendPrintf(StrBuf *Buf, const char *format, ...)
-{
+
+// sprintf like function appending the formated string to the buffer
+// Buf Buffer to extend by format and Params
+// format printf alike format to add
+void StrBufAppendPrintf(StrBuf *Buf, const char *format, ...) {
size_t BufSize;
size_t nWritten;
size_t Offset;
while (newused >= BufSize) {
va_start(arg_ptr, format);
- nWritten = vsnprintf(Buf->buf + Buf->BufUsed,
- Buf->BufSize - Buf->BufUsed,
- format, arg_ptr);
+ nWritten = vsnprintf(Buf->buf + Buf->BufUsed, Buf->BufSize - Buf->BufUsed, format, arg_ptr);
va_end(arg_ptr);
newused = Buf->BufUsed + nWritten;
if (newused >= Buf->BufSize) {
if (IncreaseBuf(Buf, 1, newused) == -1)
- return; /* TODO: error handling? */
+ return; // TODO: error handling?
newused = Buf->BufSize + 1;
}
else {
}
}
-/**
- * sprintf like function putting the formated string into the buffer
- * Buf Buffer to extend by format and Parameters
- * format printf alike format to add
- */
-void StrBufPrintf(StrBuf *Buf, const char *format, ...)
-{
+
+// sprintf like function putting the formated string into the buffer
+// Buf Buffer to extend by format and Parameters
+// format printf alike format to add
+void StrBufPrintf(StrBuf *Buf, const char *format, ...) {
size_t nWritten;
va_list arg_ptr;
va_end(arg_ptr);
if (nWritten >= Buf->BufSize) {
if (IncreaseBuf(Buf, 0, 0) == -1)
- return; /* TODO: error handling? */
+ return; // TODO: error handling?
nWritten = Buf->BufSize + 1;
continue;
}
}
}
-/**
- * Callback for cURL to append the webserver reply to a buffer
- * ptr pre-defined by the cURL API; see man 3 curl for mre info
- * size pre-defined by the cURL API; see man 3 curl for mre info
- * nmemb pre-defined by the cURL API; see man 3 curl for mre info
- * stream pre-defined by the cURL API; see man 3 curl for mre info
- */
-size_t CurlFillStrBuf_callback(void *ptr, size_t size, size_t nmemb, void *stream)
-{
+
+// Callback for cURL to append the webserver reply to a buffer
+// ptr, size, nmemb, and stream are pre-defined by the cURL API; see man 3 curl for more info
+size_t CurlFillStrBuf_callback(void *ptr, size_t size, size_t nmemb, void *stream) {
StrBuf *Target;
}
-/**
- * extracts a substring from Source into dest
- * dest buffer to place substring into
- * Source string to copy substring from
- * Offset chars to skip from start
- * nChars number of chars to copy
- * @returns the number of chars copied; may be different from nChars due to the size of Source
- */
-int StrBufSub(StrBuf *dest, const StrBuf *Source, unsigned long Offset, size_t nChars)
-{
+// extracts a substring from Source into dest
+// dest buffer to place substring into
+// Source string to copy substring from
+// Offset chars to skip from start
+// nChars number of chars to copy
+// returns the number of chars copied; may be different from nChars due to the size of Source
+int StrBufSub(StrBuf *dest, const StrBuf *Source, unsigned long Offset, size_t nChars) {
size_t NCharsRemain;
- if (Offset > Source->BufUsed)
- {
+ if (Offset > Source->BufUsed) {
if (dest != NULL)
FlushStrBuf(dest);
return 0;
}
- if (Offset + nChars < Source->BufUsed)
- {
+ if (Offset + nChars < Source->BufUsed) {
if ((nChars >= dest->BufSize) &&
(IncreaseBuf(dest, 0, nChars + 1) == -1))
return 0;
}
-
-
-
/*******************************************************************************
* wrapping ZLib *
*******************************************************************************/
return 0;
}
+
/*******************************************************************************
* File I/O; Callbacks to libevent *
*******************************************************************************/
* where a cut left is inexpensive
*/
- if (FB->ReadWritePointer != NULL)
- {
+ if (FB->ReadWritePointer != NULL) {
long already_read;
already_read = FB->ReadWritePointer - FB->Buf->buf;
FB->ReadWritePointer = FB->Buf->buf;
bufremain = FB->Buf->BufSize;
}
- else if ((unread < 64) ||
- (bufremain < already_read))
- {
+ else if ((unread < 64) || (bufremain < already_read)) {
/*
* if its just a tiny bit remaining, or we run out of space...
* lets tidy up.
FB->ReadWritePointer = FB->Buf->buf;
bufremain = FB->Buf->BufSize - unread - 1;
}
- else if (bufremain < (FB->Buf->BufSize / 10))
- {
+ else if (bufremain < (FB->Buf->BufSize / 10)) {
/* get a bigger buffer */
IncreaseBuf(FB->Buf, 0, FB->Buf->BufUsed + 1);
return n;
}
-int StrBuf_write_one_chunk_callback(int fd, short event, IOBuffer *FB)
-{
+
+int StrBuf_write_one_chunk_callback(int fd, short event, IOBuffer *FB) {
long WriteRemain;
int n;
return n;
}
-/**
- * extract a "next line" from Buf; Ptr to persist across several iterations
- * LineBuf your line will be copied here.
- * FB BLOB with lines of text...
- * Ptr moved arround to keep the next-line across several iterations
- * has to be &NULL on start; will be &NotNULL on end of buffer
- * @returns size of copied buffer
- */
-eReadState StrBufChunkSipLine(StrBuf *LineBuf, IOBuffer *FB)
-{
+
+// extract a "next line" from Buf; Ptr to persist across several iterations
+// LineBuf your line will be copied here.
+// FB BLOB with lines of text...
+// Ptr moved arround to keep the next-line across several iterations
+// has to be &NULL on start; will be &NotNULL on end of buffer
+// returns size of copied buffer
+eReadState StrBufChunkSipLine(StrBuf *LineBuf, IOBuffer *FB) {
const char *aptr, *ptr, *eptr;
char *optr, *xptr;
eptr = FB->Buf->buf + FB->Buf->BufUsed;
xptr = LineBuf->buf + LineBuf->BufSize - 1;
- while ((ptr <= eptr) &&
- (*ptr != '\n') &&
- (*ptr != '\r') )
- {
+ while ((ptr <= eptr) && (*ptr != '\n') && (*ptr != '\r') ) {
*optr = *ptr;
optr++; ptr++;
if (optr == xptr) {
if ((*(ptr - 1) != '\r') && (*(ptr - 1) != '\n')) {
LineBuf->BufUsed = optr - LineBuf->buf;
*optr = '\0';
- if ((FB->ReadWritePointer != NULL) &&
- (FB->ReadWritePointer != FB->Buf->buf))
- {
- /* Ok, the client application read all the data
- it was interested in so far. Since there is more to read,
- we now shrink the buffer, and move the rest over.
- */
- StrBufCutLeft(FB->Buf,
- FB->ReadWritePointer - FB->Buf->buf);
+ if ((FB->ReadWritePointer != NULL) && (FB->ReadWritePointer != FB->Buf->buf)) {
+ // Ok, the client application read all the data
+ // it was interested in so far. Since there is more to read,
+ // we now shrink the buffer, and move the rest over.
+ StrBufCutLeft(FB->Buf, FB->ReadWritePointer - FB->Buf->buf);
FB->ReadWritePointer = FB->Buf->buf;
}
return eMustReadMore;
return eReadSuccess;
}
-long IOBufferStrLength(IOBuffer *FB)
-{
+
+long IOBufferStrLength(IOBuffer *FB) {
if ((FB == NULL) || (FB->Buf == NULL))
return 0;
if (FB->ReadWritePointer == NULL)
}
-/**
- * Read a line from socket
- * flushes and closes the FD on error
- * Line the line to read from the fd / I/O Buffer
- * buf the buffer to get the input to
- * fd pointer to the filedescriptor to read
- * timeout number of successless selects until we bail out
- * selectresolution how long to wait on each select
- * Error strerror() on error
- * @returns numbers of chars read
- */
+// Read a line from socket
+// flushes and closes the FD on error
+// Line the line to read from the fd / I/O Buffer
+// buf the buffer to get the input to
+// fd pointer to the filedescriptor to read
+// timeout number of successless selects until we bail out
+// selectresolution how long to wait on each select
+// Error strerror() on error
+// returns numbers of chars read
int StrBufTCP_read_buffered_line(StrBuf *Line,
StrBuf *buf,
int *fd,
if (pch != NULL) {
rlen = 0;
len = pch - buf->buf;
- if (len > 0 && (*(pch - 1) == '\r') )
+ if (len > 0 && (*(pch - 1) == '\r') ) {
rlen ++;
+ }
StrBufSub(Line, buf, 0, len - rlen);
StrBufCutLeft(buf, len + 1);
return len - rlen;
}
}
- if (buf->BufSize - buf->BufUsed < 10)
+ if (buf->BufSize - buf->BufUsed < 10) {
IncreaseBuf(buf, 1, -1);
+ }
fdflags = fcntl(*fd, F_GETFL);
IsNonBlock = (fdflags & O_NONBLOCK) == O_NONBLOCK;
nSuccessLess ++;
continue;
}
- rlen = read(*fd,
- &buf->buf[buf->BufUsed],
- buf->BufSize - buf->BufUsed - 1);
+ rlen = read(*fd, &buf->buf[buf->BufUsed], buf->BufSize - buf->BufUsed - 1);
if (rlen < 1) {
*Error = strerror(errno);
close(*fd);
buf->BufUsed += rlen;
buf->buf[buf->BufUsed] = '\0';
pch = strchr(buf->buf, '\n');
- if ((pch == NULL) &&
- (buf->BufUsed + 10 > buf->BufSize) &&
- (IncreaseBuf(buf, 1, -1) == -1))
+ if ((pch == NULL) && (buf->BufUsed + 10 > buf->BufSize) && (IncreaseBuf(buf, 1, -1) == -1)) {
return -1;
+ }
continue;
}
static const char *ErrRBLF_PreConditionFailed="StrBufTCP_read_buffered_line_fast: Wrong arguments or invalid Filedescriptor";
static const char *ErrRBLF_SelectFailed="StrBufTCP_read_buffered_line_fast: Select failed without reason";
static const char *ErrRBLF_NotEnoughSentFromServer="StrBufTCP_read_buffered_line_fast: No complete line was sent from peer";
-/**
- * Read a line from socket
- * flushes and closes the FD on error
- * Line where to append our Line read from the fd / I/O Buffer;
- * IOBuf the buffer to get the input to; lifetime pair to FD
- * Pos pointer to the current read position, should be NULL initialized on opening the FD it belongs to.!
- * fd pointer to the filedescriptor to read
- * timeout number of successless selects until we bail out
- * selectresolution how long to wait on each select
- * Error strerror() on error
- * @returns numbers of chars read or -1 in case of error. "\n" will become 0
- */
+
+
+// Read a line from socket
+// flushes and closes the FD on error
+// Line where to append our Line read from the fd / I/O Buffer;
+// IOBuf the buffer to get the input to; lifetime pair to FD
+// Pos pointer to the current read position, should be NULL initialized on opening the FD it belongs to.!
+// fd pointer to the filedescriptor to read
+// timeout number of successless selects until we bail out
+// selectresolution how long to wait on each select
+// Error strerror() on error
+// returns numbers of chars read or -1 in case of error. "\n" will become 0
int StrBufTCP_read_buffered_line_fast(StrBuf *Line,
StrBuf *IOBuf,
const char **Pos,
struct timeval tv;
retlen = 0;
- if ((Line == NULL) ||
- (Pos == NULL) ||
- (IOBuf == NULL) ||
- (*fd == -1))
- {
- if (Pos != NULL)
+ if ((Line == NULL) || (Pos == NULL) || (IOBuf == NULL) || (*fd == -1)) {
+ if (Pos != NULL) {
*Pos = NULL;
+ }
*Error = ErrRBLF_PreConditionFailed;
return -1;
}
pos = *Pos;
- if ((IOBuf->BufUsed > 0) &&
- (pos != NULL) &&
- (pos < IOBuf->buf + IOBuf->BufUsed))
- {
+ if ((IOBuf->BufUsed > 0) && (pos != NULL) && (pos < IOBuf->buf + IOBuf->BufUsed)) {
char *pcht;
pche = IOBuf->buf + IOBuf->BufUsed;
pch = pos;
pcht = Line->buf;
- while ((pch < pche) && (*pch != '\n'))
- {
- if (Line->BufUsed + 10 > Line->BufSize)
- {
+ while ((pch < pche) && (*pch != '\n')) {
+ if (Line->BufUsed + 10 > Line->BufSize) {
long apos;
apos = pcht - Line->buf;
*pcht = '\0';
}
len = pch - pos;
- if (len > 0 && (*(pch - 1) == '\r') )
- {
+ if (len > 0 && (*(pch - 1) == '\r') ) {
retlen--;
len --;
pcht --;
}
*pcht = '\0';
- if ((pch >= pche) || (*pch == '\0'))
- {
+ if ((pch >= pche) || (*pch == '\0')) {
FlushStrBuf(IOBuf);
*Pos = NULL;
pch = NULL;
pos = 0;
}
- if ((pch != NULL) &&
- (pch <= pche))
- {
+ if ((pch != NULL) && (pch <= pche)) {
if (pch + 1 >= pche) {
*Pos = NULL;
FlushStrBuf(IOBuf);
}
- else
+ else {
*Pos = pch + 1;
-
+ }
return retlen;
}
else
/* If we come here, Pos is Unset since we read everything into Line, and now go for more. */
- if (IOBuf->BufSize - IOBuf->BufUsed < 10)
+ if (IOBuf->BufSize - IOBuf->BufUsed < 10) {
IncreaseBuf(IOBuf, 1, -1);
+ }
fdflags = fcntl(*fd, F_GETFL);
IsNonBlock = (fdflags & O_NONBLOCK) == O_NONBLOCK;
while ((nSuccessLess < timeout) &&
(pLF == NULL) &&
(*fd != -1)) {
- if (IsNonBlock)
- {
+ if (IsNonBlock) {
tv.tv_sec = 1;
tv.tv_usec = 0;
continue;
}
}
- rlen = read(*fd,
- &IOBuf->buf[IOBuf->BufUsed],
- IOBuf->BufSize - IOBuf->BufUsed - 1);
+ rlen = read(*fd, &IOBuf->buf[IOBuf->BufUsed], IOBuf->BufSize - IOBuf->BufUsed - 1);
if (rlen < 1) {
*Error = strerror(errno);
close(*fd);
if ((pLF >= pche) || (*pLF == '\0'))
pLF = NULL;
- if (IOBuf->BufUsed + 10 > IOBuf->BufSize)
- {
+ if (IOBuf->BufUsed + 10 > IOBuf->BufSize) {
long apos = 0;
if (pLF != NULL) apos = pLF - IOBuf->buf;
continue;
}
- else
- {
+ else {
nSuccessLess++;
}
}
if (pLF != NULL) {
pos = IOBuf->buf;
len = pLF - pos;
- if (len > 0 && (*(pLF - 1) == '\r') )
+ if (len > 0 && (*(pLF - 1) == '\r') ) {
len --;
+ }
StrBufAppendBufPlain(Line, ChrPtr(IOBuf), len, 0);
- if (pLF + 1 >= IOBuf->buf + IOBuf->BufUsed)
- {
+ if (pLF + 1 >= IOBuf->buf + IOBuf->BufUsed) {
FlushStrBuf(IOBuf);
}
else
struct timeval tv;
fd_set rfds;
- if ((Buf == NULL) || (Buf->buf == NULL) || (*fd == -1))
- {
+ if ((Buf == NULL) || (Buf->buf == NULL) || (*fd == -1)) {
*Error = ErrRBLF_BLOBPreConditionFailed;
return -1;
}
- if (!append)
+ if (!append) {
FlushStrBuf(Buf);
- if (Buf->BufUsed + nBytes >= Buf->BufSize)
+ }
+ if (Buf->BufUsed + nBytes >= Buf->BufSize) {
IncreaseBuf(Buf, 1, Buf->BufUsed + nBytes);
-
+ }
ptr = Buf->buf + Buf->BufUsed;
fdflags = fcntl(*fd, F_GETFL);
IsNonBlock = (fdflags & O_NONBLOCK) == O_NONBLOCK;
nSuccessLess = 0;
- while ((nRead < nBytes) &&
- (*fd != -1))
- {
- if (IsNonBlock)
- {
+ while ((nRead < nBytes) && (*fd != -1)) {
+ if (IsNonBlock) {
tv.tv_sec = 1;
tv.tv_usec = 0;
*Error = strerror(errno);
close (*fd);
*fd = -1;
- if (*Error == NULL)
+ if (*Error == NULL) {
*Error = ErrRBLF_SelectFailed;
+ }
return -1;
}
if (! FD_ISSET(*fd, &rfds) != 0) {
const char *ErrRBB_BLOBFPreConditionFailed = "StrBufReadBLOBBuffered: to many selects; aborting.";
const char *ErrRBB_too_many_selects = "StrBufReadBLOBBuffered: to many selects; aborting.";
-/**
- * Input binary data from socket
- * flushes and closes the FD on error
- * Blob put binary thing here
- * IOBuf the buffer to get the input to
- * Pos offset inside of IOBuf
- * fd pointer to the filedescriptor to read
- * append Append to an existing string or replace?
- * nBytes the maximal number of bytes to read
- * check whether we should search for '000\n' terminators in case of timeouts
- * Error strerror() on error
- * @returns numbers of chars read
- */
+
+
+// Input binary data from socket
+// flushes and closes the FD on error
+// Blob put binary thing here
+// IOBuf the buffer to get the input to
+// Pos offset inside of IOBuf
+// fd pointer to the filedescriptor to read
+// append Append to an existing string or replace?
+// nBytes the maximal number of bytes to read
+// check whether we should search for '000\n' terminators in case of timeouts
+// Error strerror() on error
+// returns numbers of chars read
int StrBufReadBLOBBuffered(StrBuf *Blob,
StrBuf *IOBuf,
const char **Pos,
int nSuccessLess = 0;
int MaxTries;
- if ((Blob == NULL) ||
- (*fd == -1) ||
- (IOBuf == NULL) ||
- (Pos == NULL))
- {
+ if ((Blob == NULL) || (*fd == -1) || (IOBuf == NULL) || (Pos == NULL)) {
if (Pos != NULL)
*Pos = NULL;
*Error = ErrRBB_BLOBFPreConditionFailed;
rlen = IOBuf->BufUsed - rlen;
- if ((IOBuf->BufUsed > 0) && (pos != NULL) && (pos < IOBuf->buf + IOBuf->BufUsed))
- {
+ if ((IOBuf->BufUsed > 0) && (pos != NULL) && (pos < IOBuf->buf + IOBuf->BufUsed)) {
if (rlen < nBytes) {
memcpy(Blob->buf + Blob->BufUsed, pos, rlen);
Blob->BufUsed += rlen;
}
}
rlen = read(*fd, ptr, IOBuf->BufSize - (ptr - IOBuf->buf));
- // if (rlen == -1) { 2021feb27 ajc changed this, apparently we will always get at least 1 byte unless the connection is broken
- if (rlen < 1) {
+ if (rlen < 1) { // We will always get at least 1 byte unless the connection is broken
close(*fd);
*fd = -1;
*Error = strerror(errno);
return nRead + nAlreadyRead;
}
-/**
- * extract a "next line" from Buf; Ptr to persist across several iterations
- * LineBuf your line will be copied here.
- * Buf BLOB with lines of text...
- * Ptr moved arround to keep the next-line across several iterations
- * has to be &NULL on start; will be &NotNULL on end of buffer
- * @returns size of remaining buffer
- */
-int StrBufSipLine(StrBuf *LineBuf, const StrBuf *Buf, const char **Ptr)
-{
+
+// extract a "next line" from Buf; Ptr to persist across several iterations
+// LineBuf your line will be copied here.
+// Buf BLOB with lines of text...
+// Ptr moved arround to keep the next-line across several iterations
+// has to be &NULL on start; will be &NotNULL on end of buffer
+// returns size of remaining buffer
+int StrBufSipLine(StrBuf *LineBuf, const StrBuf *Buf, const char **Ptr) {
const char *aptr, *ptr, *eptr;
char *optr, *xptr;
- if ((Buf == NULL) ||
- (*Ptr == StrBufNOTNULL) ||
- (LineBuf == NULL)||
- (LineBuf->buf == NULL))
- {
+ if ((Buf == NULL) || (*Ptr == StrBufNOTNULL) || (LineBuf == NULL)|| (LineBuf->buf == NULL)) {
*Ptr = StrBufNOTNULL;
return 0;
}
eptr = Buf->buf + Buf->BufUsed;
xptr = LineBuf->buf + LineBuf->BufSize - 1;
- while ((ptr <= eptr) &&
- (*ptr != '\n') &&
- (*ptr != '\r') )
- {
+ while ((ptr <= eptr) && (*ptr != '\n') && (*ptr != '\r') ) {
*optr = *ptr;
optr++; ptr++;
if (optr == xptr) {
}
-/**
- * removes double slashes from pathnames
- * Dir directory string to filter
- * RemoveTrailingSlash allows / disallows trailing slashes
- */
-void StrBufStripSlashes(StrBuf *Dir, int RemoveTrailingSlash)
-{
+// removes double slashes from pathnames
+// Dir directory string to filter
+// RemoveTrailingSlash allows / disallows trailing slashes
+void StrBufStripSlashes(StrBuf *Dir, int RemoveTrailingSlash) {
char *a, *b;
a = b = Dir->buf;
}
-/*
- * Decode a quoted-printable encoded StrBuf buffer "in place"
- * This is possible because the decoded will always be shorter than the encoded
- * so we don't have to worry about the buffer being to small.
- */
-void StrBufDecodeQP(StrBuf *Buf)
-{
+// Decode a quoted-printable encoded StrBuf buffer "in place"
+// This is possible because the decoded will always be shorter than the encoded
+// so we don't have to worry about the buffer being to small.
+void StrBufDecodeQP(StrBuf *Buf) {
if (!Buf) { // sanity check #1
return;
}