Alien-SVN
view release on metacpan or search on metacpan
src/subversion/subversion/libsvn_subr/config_file.c view on Meta::CPAN
svn_stringbuf_t *section;
svn_stringbuf_t *option;
svn_stringbuf_t *value;
/* Parser buffer for getc() to avoid call overhead into several libraries
for every character */
char parser_buffer[SVN__STREAM_CHUNK_SIZE]; /* Larger than most config files */
size_t buffer_pos; /* Current position within parser_buffer */
size_t buffer_size; /* parser_buffer contains this many bytes */
} parse_context_t;
/* Emulate getc() because streams don't support it.
*
* In order to be able to ungetc(), use the CXT instead of the stream
* to be able to store the 'ungotton' character.
*
*/
static APR_INLINE svn_error_t *
parser_getc(parse_context_t *ctx, int *c)
{
do
{
if (ctx->ungotten_char != EOF)
{
*c = ctx->ungotten_char;
ctx->ungotten_char = EOF;
}
else if (ctx->buffer_pos < ctx->buffer_size)
{
*c = (unsigned char)ctx->parser_buffer[ctx->buffer_pos];
ctx->buffer_pos++;
}
else
{
ctx->buffer_pos = 0;
ctx->buffer_size = sizeof(ctx->parser_buffer);
SVN_ERR(svn_stream_read(ctx->stream, ctx->parser_buffer,
&(ctx->buffer_size)));
if (ctx->buffer_pos < ctx->buffer_size)
{
*c = (unsigned char)ctx->parser_buffer[ctx->buffer_pos];
ctx->buffer_pos++;
}
else
*c = EOF;
}
}
while (*c == '\r');
return SVN_NO_ERROR;
}
/* Simplified version of parser_getc() to be used inside skipping loops.
* It will not check for 'ungotton' chars and may or may not ignore '\r'.
*
* In a 'while(cond) getc();' loop, the first iteration must call
* parser_getc to handle all the special cases. Later iterations should
* use parser_getc_plain for maximum performance.
*/
static APR_INLINE svn_error_t *
parser_getc_plain(parse_context_t *ctx, int *c)
{
if (ctx->buffer_pos < ctx->buffer_size)
{
*c = (unsigned char)ctx->parser_buffer[ctx->buffer_pos];
ctx->buffer_pos++;
return SVN_NO_ERROR;
}
return parser_getc(ctx, c);
}
/* Emulate ungetc() because streams don't support it.
*
* Use CTX to store the ungotten character C.
*/
static APR_INLINE svn_error_t *
parser_ungetc(parse_context_t *ctx, int c)
{
ctx->ungotten_char = c;
return SVN_NO_ERROR;
}
/* Eat chars from STREAM until encounter non-whitespace, newline, or EOF.
Set *PCOUNT to the number of characters eaten, not counting the
last one, and return the last char read (the one that caused the
break). */
static APR_INLINE svn_error_t *
skip_whitespace(parse_context_t *ctx, int *c, int *pcount)
{
int ch = 0;
int count = 0;
SVN_ERR(parser_getc(ctx, &ch));
while (svn_ctype_isspace(ch) && ch != '\n' && ch != EOF)
{
++count;
SVN_ERR(parser_getc_plain(ctx, &ch));
}
*pcount = count;
*c = ch;
return SVN_NO_ERROR;
}
/* Skip to the end of the line (or file). Returns the char that ended
the line; the char is either EOF or newline. */
static APR_INLINE svn_error_t *
skip_to_eoln(parse_context_t *ctx, int *c)
{
int ch;
SVN_ERR(parser_getc(ctx, &ch));
while (ch != '\n' && ch != EOF)
SVN_ERR(parser_getc_plain(ctx, &ch));
( run in 0.806 second using v1.01-cache-2.11-cpan-71847e10f99 )