cstrc, cstrd - convert between ANSI C-strings and strings
# include <begemot.h>
char * cstrc(char **pstr, char delim, size_t
char * cstrd(const char *str, char delim,
function converts a string as specified in the ANSI C-standard
to the usual internal representation. All escape sequences are (hopefully)
recognized. Setting cstrwarn
to any non-zero value enables some warning
messages, which are emitted via warn
is the address of
a pointer to the string to be parsed. Delim
is the character at which
the parsing should stop. It should be a single or a double quote character.
Parsing stops also if a NUL character is found. * pstr
is left pointing
to the terminating character. At entry to the function * pstr
point behind the initial delimiter. * plen
will hold the number of
bytes in the output string. The string will be NUL termninated, but note, that
it may contain embedded NULs.
prints a string with non-printable characters converted to escape
is escaped in the output string (usually '\'' or
The user is responsible the deallocate the memory returned by cstrc
. Both functions call xalloc
(l) and xrealloc
therefor end in panic
(l) if not enough memory is available.
Both functions return allocated memory that must be freed by the caller. They
may never return NULL.