Commit 8acc6201 authored by Mark Lindner's avatar Mark Lindner

Prefix all internal functions with 'libconfig_'

parent a6b370e7
......@@ -52,6 +52,10 @@ int main(int argc, char **argv)
return(EXIT_FAILURE);
}
string tmp;
cfg.lookupValue("name", tmp);
std::cout << "name: " << tmp << std::endl;
// Get the store name.
try
{
......
......@@ -96,7 +96,7 @@ static void capture_parse_pos(void *scanner, struct scan_context *scan_ctx,
config_setting_t *setting)
{
setting->line = (unsigned int)libconfig_yyget_lineno(scanner);
setting->file = scanctx_current_filename(scan_ctx);
setting->file = libconfig_scanctx_current_filename(scan_ctx);
}
#define CAPTURE_PARSE_POS(S) \
......@@ -1418,13 +1418,13 @@ yyreduce:
case 21:
#line 186 "grammar.y" /* yacc.c:1646 */
{ parsectx_append_string(ctx, (yyvsp[0].sval)); free((yyvsp[0].sval)); }
{ libconfig_parsectx_append_string(ctx, (yyvsp[0].sval)); free((yyvsp[0].sval)); }
#line 1423 "grammar.c" /* yacc.c:1646 */
break;
case 22:
#line 187 "grammar.y" /* yacc.c:1646 */
{ parsectx_append_string(ctx, (yyvsp[0].sval)); free((yyvsp[0].sval)); }
{ libconfig_parsectx_append_string(ctx, (yyvsp[0].sval)); free((yyvsp[0].sval)); }
#line 1429 "grammar.c" /* yacc.c:1646 */
break;
......@@ -1583,7 +1583,7 @@ yyreduce:
{
if(IN_ARRAY() || IN_LIST())
{
const char *s = parsectx_take_string(ctx);
const char *s = libconfig_parsectx_take_string(ctx);
config_setting_t *e = config_setting_set_string_elem(ctx->parent, -1, s);
__delete(s);
......@@ -1599,7 +1599,7 @@ yyreduce:
}
else
{
const char *s = parsectx_take_string(ctx);
const char *s = libconfig_parsectx_take_string(ctx);
config_setting_set_string(ctx->setting, s);
__delete(s);
}
......
......@@ -56,7 +56,7 @@ static void capture_parse_pos(void *scanner, struct scan_context *scan_ctx,
config_setting_t *setting)
{
setting->line = (unsigned int)libconfig_yyget_lineno(scanner);
setting->file = scanctx_current_filename(scan_ctx);
setting->file = libconfig_scanctx_current_filename(scan_ctx);
}
#define CAPTURE_PARSE_POS(S) \
......@@ -183,8 +183,8 @@ value:
;
string:
TOK_STRING { parsectx_append_string(ctx, $1); free($1); }
| string TOK_STRING { parsectx_append_string(ctx, $2); free($2); }
TOK_STRING { libconfig_parsectx_append_string(ctx, $1); free($1); }
| string TOK_STRING { libconfig_parsectx_append_string(ctx, $2); free($2); }
;
simple_value:
......@@ -318,7 +318,7 @@ simple_value:
{
if(IN_ARRAY() || IN_LIST())
{
const char *s = parsectx_take_string(ctx);
const char *s = libconfig_parsectx_take_string(ctx);
config_setting_t *e = config_setting_set_string_elem(ctx->parent, -1, s);
__delete(s);
......@@ -334,7 +334,7 @@ simple_value:
}
else
{
const char *s = parsectx_take_string(ctx);
const char *s = libconfig_parsectx_take_string(ctx);
config_setting_set_string(ctx->setting, s);
__delete(s);
}
......
/* ----------------------------------------------------------------------------
libconfig - A library for processing structured configuration files
Copyright (C) 2005-2018 Mark A Lindner
Copyright (C) 2005-2020 Mark A Lindner
This file is part of libconfig.
......@@ -539,15 +539,15 @@ static int __config_read(config_t *config, FILE *stream, const char *filename,
config_clear(config);
parsectx_init(&parse_ctx);
libconfig_parsectx_init(&parse_ctx);
parse_ctx.config = config;
parse_ctx.parent = config->root;
parse_ctx.setting = config->root;
__config_locale_override();
scanctx_init(&scan_ctx, filename);
config->root->file = scanctx_current_filename(&scan_ctx);
libconfig_scanctx_init(&scan_ctx, filename);
config->root->file = libconfig_scanctx_current_filename(&scan_ctx);
scan_ctx.config = config;
libconfig_yylex_init_extra(&scan_ctx, &scanner);
......@@ -563,17 +563,18 @@ static int __config_read(config_t *config, FILE *stream, const char *filename,
{
YY_BUFFER_STATE buf;
config->error_file = scanctx_current_filename(&scan_ctx);
config->error_file = libconfig_scanctx_current_filename(&scan_ctx);
config->error_type = CONFIG_ERR_PARSE;
/* Unwind the include stack, freeing the buffers and closing the files. */
while((buf = (YY_BUFFER_STATE)scanctx_pop_include(&scan_ctx)) != NULL)
while((buf = (YY_BUFFER_STATE)libconfig_scanctx_pop_include(&scan_ctx))
!= NULL)
libconfig_yy_delete_buffer(buf, scanner);
}
libconfig_yylex_destroy(scanner);
config->filenames = scanctx_cleanup(&scan_ctx);
parsectx_cleanup(&parse_ctx);
config->filenames = libconfig_scanctx_cleanup(&scan_ctx);
libconfig_parsectx_cleanup(&parse_ctx);
__config_locale_restore();
......
/* ----------------------------------------------------------------------------
libconfig - A library for processing structured configuration files
Copyright (C) 2005-2018 Mark A Lindner
Copyright (C) 2005-2020 Mark A Lindner
This file is part of libconfig.
......@@ -36,14 +36,14 @@ struct parse_context
strbuf_t string;
};
#define parsectx_init(C) \
#define libconfig_parsectx_init(C) \
__zero(C)
#define parsectx_cleanup(C) \
__delete(strbuf_release(&((C)->string)))
#define libconfig_parsectx_cleanup(C) \
__delete(libconfig_strbuf_release(&((C)->string)))
#define parsectx_append_string(C, S) \
strbuf_append_string(&((C)->string), (S))
#define parsectx_take_string(C) \
strbuf_release(&((C)->string))
#define libconfig_parsectx_append_string(C, S) \
libconfig_strbuf_append_string(&((C)->string), (S))
#define libconfig_parsectx_take_string(C) \
libconfig_strbuf_release(&((C)->string))
#endif /* __libconfig_parsectx_h */
/* ----------------------------------------------------------------------------
libconfig - A library for processing structured configuration files
Copyright (C) 2005-2018 Mark A Lindner
Copyright (C) 2005-2020 Mark A Lindner
This file is part of libconfig.
......@@ -35,19 +35,19 @@ static const char *err_include_too_deep = "include file nesting too deep";
/* ------------------------------------------------------------------------- */
void scanctx_init(struct scan_context *ctx, const char *top_filename)
void libconfig_scanctx_init(struct scan_context *ctx, const char *top_filename)
{
__zero(ctx);
if(top_filename)
{
ctx->top_filename = strdup(top_filename);
strvec_append(&(ctx->filenames), ctx->top_filename);
libconfig_strvec_append(&(ctx->filenames), ctx->top_filename);
}
}
/* ------------------------------------------------------------------------- */
const char **scanctx_cleanup(struct scan_context *ctx)
const char **libconfig_scanctx_cleanup(struct scan_context *ctx)
{
int i;
......@@ -61,15 +61,15 @@ const char **scanctx_cleanup(struct scan_context *ctx)
__delete(frame->files);
}
__delete(strbuf_release(&(ctx->string)));
__delete(libconfig_strbuf_release(&(ctx->string)));
return(strvec_release(&(ctx->filenames)));
return(libconfig_strvec_release(&(ctx->filenames)));
}
/* ------------------------------------------------------------------------- */
FILE *scanctx_push_include(struct scan_context *ctx, void *prev_buffer,
const char *path, const char **error)
FILE *libconfig_scanctx_push_include(struct scan_context *ctx, void *prev_buffer,
const char *path, const char **error)
{
struct include_stack_frame *frame;
const char **files = NULL, **f;
......@@ -102,7 +102,7 @@ FILE *scanctx_push_include(struct scan_context *ctx, void *prev_buffer,
frame = &(ctx->include_stack[ctx->stack_depth]);
for(f = files; *f; ++f)
strvec_append(&(ctx->filenames), *f);
libconfig_strvec_append(&(ctx->filenames), *f);
frame->files = files;
frame->current_file = NULL;
......@@ -110,16 +110,17 @@ FILE *scanctx_push_include(struct scan_context *ctx, void *prev_buffer,
frame->parent_buffer = prev_buffer;
++(ctx->stack_depth);
fp = scanctx_next_include_file(ctx, error);
fp = libconfig_scanctx_next_include_file(ctx, error);
if(!fp)
(void)scanctx_pop_include(ctx);
(void)libconfig_scanctx_pop_include(ctx);
return(fp);
}
/* ------------------------------------------------------------------------- */
FILE *scanctx_next_include_file(struct scan_context *ctx, const char **error)
FILE *libconfig_scanctx_next_include_file(struct scan_context *ctx,
const char **error)
{
struct include_stack_frame *include_frame;
......@@ -153,7 +154,7 @@ FILE *scanctx_next_include_file(struct scan_context *ctx, const char **error)
/* ------------------------------------------------------------------------- */
void *scanctx_pop_include(struct scan_context *ctx)
void *libconfig_scanctx_pop_include(struct scan_context *ctx)
{
struct include_stack_frame *frame;
......@@ -176,16 +177,16 @@ void *scanctx_pop_include(struct scan_context *ctx)
/* ------------------------------------------------------------------------- */
char *scanctx_take_string(struct scan_context *ctx)
char *libconfig_scanctx_take_string(struct scan_context *ctx)
{
char *r = strbuf_release(&(ctx->string));
char *r = libconfig_strbuf_release(&(ctx->string));
return(r ? r : strdup(""));
}
/* ------------------------------------------------------------------------- */
const char *scanctx_current_filename(struct scan_context *ctx)
const char *libconfig_scanctx_current_filename(struct scan_context *ctx)
{
if(ctx->stack_depth > 0)
return(*(ctx->include_stack[ctx->stack_depth - 1].current_file));
......
/* ----------------------------------------------------------------------------
libconfig - A library for processing structured configuration files
Copyright (C) 2005-2018 Mark A Lindner
Copyright (C) 2005-2020 Mark A Lindner
This file is part of libconfig.
......@@ -55,8 +55,9 @@ struct scan_context
strvec_t filenames;
};
extern void scanctx_init(struct scan_context *ctx, const char *top_filename);
extern const char **scanctx_cleanup(struct scan_context *ctx);
extern void libconfig_scanctx_init(struct scan_context *ctx,
const char *top_filename);
extern const char **libconfig_scanctx_cleanup(struct scan_context *ctx);
/*
* Pushes a new frame onto the include stack, and returns an open stream to the
......@@ -76,8 +77,10 @@ extern const char **scanctx_cleanup(struct scan_context *ctx);
* *error is NULL, it means there are no files in the list. Otherwise, it
* points to an error and parsing should be aborted.
*/
extern FILE *scanctx_push_include(struct scan_context *ctx, void *prev_buffer,
const char *path, const char **error);
extern FILE *libconfig_scanctx_push_include(struct scan_context *ctx,
void *prev_buffer,
const char *path,
const char **error);
/*
* Returns the next include file in the current include stack frame.
......@@ -85,22 +88,22 @@ extern FILE *scanctx_push_include(struct scan_context *ctx, void *prev_buffer,
* Returns NULL on failure or if there are no more files left in the current
* frame. If there was an error, sets *error.
*/
extern FILE *scanctx_next_include_file(struct scan_context *ctx,
const char **error);
extern FILE *libconfig_scanctx_next_include_file(struct scan_context *ctx,
const char **error);
/*
* Pops a frame off the include stack.
*/
extern void *scanctx_pop_include(struct scan_context *ctx);
extern void *libconfig_scanctx_pop_include(struct scan_context *ctx);
#define scanctx_append_string(C, S) \
strbuf_append_string(&((C)->string), (S))
#define libconfig_scanctx_append_string(C, S) \
libconfig_strbuf_append_string(&((C)->string), (S))
#define scanctx_append_char(C, X) \
strbuf_append_char(&((C)->string), (X))
#define libconfig_scanctx_append_char(C, X) \
libconfig_strbuf_append_char(&((C)->string), (X))
extern char *scanctx_take_string(struct scan_context *ctx);
extern char *libconfig_scanctx_take_string(struct scan_context *ctx);
extern const char *scanctx_current_filename(struct scan_context *ctx);
extern const char *libconfig_scanctx_current_filename(struct scan_context *ctx);
#endif /* __libconfig_scanctx_h */
This diff is collapsed.
......@@ -443,9 +443,10 @@ void yyfree ( void * , yyscan_t yyscanner );
#ifdef YY_HEADER_EXPORT_START_CONDITIONS
#define INITIAL 0
#define COMMENT 1
#define STRING 2
#define INCLUDE 3
#define SINGLE_LINE_COMMENT 1
#define MULTI_LINE_COMMENT 2
#define STRING 3
#define INCLUDE 4
#endif
......@@ -711,8 +712,8 @@ extern int yylex \
#undef yyTABLES_NAME
#endif
#line 198 "scanner.l"
#line 200 "scanner.l"
#line 716 "scanner.h"
#line 717 "scanner.h"
#undef libconfig_yyIN_HEADER
#endif /* libconfig_yyHEADER_H */
/* -*- mode: C -*- */
/* --------------------------------------------------------------------------
libconfig - A library for processing structured configuration files
Copyright (C) 2005-2018 Mark A Lindner
Copyright (C) 2005-2020 Mark A Lindner
This file is part of libconfig.
......@@ -79,33 +79,33 @@ include_open ^[ \t]*@include[ \t]+\"
<MULTI_LINE_COMMENT>\n { /* ignore */ }
\" { BEGIN STRING; }
<STRING>[^\"\\]+ { scanctx_append_string(yyextra, yytext); }
<STRING>\\n { scanctx_append_char(yyextra, '\n'); }
<STRING>\\r { scanctx_append_char(yyextra, '\r'); }
<STRING>\\t { scanctx_append_char(yyextra, '\t'); }
<STRING>\\f { scanctx_append_char(yyextra, '\f'); }
<STRING>\\\\ { scanctx_append_char(yyextra, '\\'); }
<STRING>\\\" { scanctx_append_char(yyextra, '\"'); }
<STRING>[^\"\\]+ { libconfig_scanctx_append_string(yyextra, yytext); }
<STRING>\\n { libconfig_scanctx_append_char(yyextra, '\n'); }
<STRING>\\r { libconfig_scanctx_append_char(yyextra, '\r'); }
<STRING>\\t { libconfig_scanctx_append_char(yyextra, '\t'); }
<STRING>\\f { libconfig_scanctx_append_char(yyextra, '\f'); }
<STRING>\\\\ { libconfig_scanctx_append_char(yyextra, '\\'); }
<STRING>\\\" { libconfig_scanctx_append_char(yyextra, '\"'); }
<STRING>{hexchar} {
char c = (char)(strtol(yytext + 2, NULL, 16) & 0xFF);
scanctx_append_char(yyextra, c);
libconfig_scanctx_append_char(yyextra, c);
}
<STRING>\\ { scanctx_append_char(yyextra, '\\'); }
<STRING>\\ { libconfig_scanctx_append_char(yyextra, '\\'); }
<STRING>\" {
yylval->sval = scanctx_take_string(yyextra);
yylval->sval = libconfig_scanctx_take_string(yyextra);
BEGIN INITIAL;
return(TOK_STRING);
}
{include_open} { BEGIN INCLUDE; }
<INCLUDE>[^\"\\]+ { scanctx_append_string(yyextra, yytext); }
<INCLUDE>\\\\ { scanctx_append_char(yyextra, '\\'); }
<INCLUDE>\\\" { scanctx_append_char(yyextra, '\"'); }
<INCLUDE>[^\"\\]+ { libconfig_scanctx_append_string(yyextra, yytext); }
<INCLUDE>\\\\ { libconfig_scanctx_append_char(yyextra, '\\'); }
<INCLUDE>\\\" { libconfig_scanctx_append_char(yyextra, '\"'); }
<INCLUDE>\" {
const char *error = NULL;
const char *path = scanctx_take_string(yyextra);
FILE *fp = scanctx_push_include(yyextra, (void *)YY_CURRENT_BUFFER, path,
&error);
const char *path = libconfig_scanctx_take_string(yyextra);
FILE *fp = libconfig_scanctx_push_include(yyextra, (void *)YY_CURRENT_BUFFER,
path, &error);
__delete(path);
if(fp)
......@@ -117,7 +117,7 @@ include_open ^[ \t]*@include[ \t]+\"
else if(error)
{
yyextra->config->error_text = error;
yyextra->config->error_file = scanctx_current_filename(yyextra);
yyextra->config->error_file = libconfig_scanctx_current_filename(yyextra);
yyextra->config->error_line = libconfig_yyget_lineno(yyscanner);
return TOK_ERROR;
}
......@@ -169,7 +169,7 @@ include_open ^[ \t]*@include[ \t]+\"
const char *error = NULL;
FILE *fp;
fp = scanctx_next_include_file(yyextra, &error);
fp = libconfig_scanctx_next_include_file(yyextra, &error);
if(fp)
{
yyin = fp;
......@@ -180,14 +180,14 @@ include_open ^[ \t]*@include[ \t]+\"
else if(error)
{
yyextra->config->error_text = error;
yyextra->config->error_file = scanctx_current_filename(yyextra);
yyextra->config->error_file = libconfig_scanctx_current_filename(yyextra);
yyextra->config->error_line = libconfig_yyget_lineno(yyscanner);
return TOK_ERROR;
}
else
{
/* No more files in the current include list. */
YY_BUFFER_STATE buf = (YY_BUFFER_STATE)scanctx_pop_include(yyextra);
YY_BUFFER_STATE buf = (YY_BUFFER_STATE)libconfig_scanctx_pop_include(yyextra);
if(buf)
{
yy_delete_buffer(YY_CURRENT_BUFFER, yyscanner);
......
/* ----------------------------------------------------------------------------
libconfig - A library for processing structured configuration files
Copyright (C) 2005-2018 Mark A Lindner
Copyright (C) 2005-2020 Mark A Lindner
This file is part of libconfig.
......@@ -30,7 +30,7 @@
/* ------------------------------------------------------------------------- */
void strbuf_ensure_capacity(strbuf_t *buf, size_t len)
void libconfig_strbuf_ensure_capacity(strbuf_t *buf, size_t len)
{
static const size_t mask = ~(STRING_BLOCK_SIZE - 1);
......@@ -44,7 +44,7 @@ void strbuf_ensure_capacity(strbuf_t *buf, size_t len)
/* ------------------------------------------------------------------------- */
char *strbuf_release(strbuf_t *buf)
char *libconfig_strbuf_release(strbuf_t *buf)
{
char *r = buf->string;
__zero(buf);
......@@ -53,19 +53,19 @@ char *strbuf_release(strbuf_t *buf)
/* ------------------------------------------------------------------------- */
void strbuf_append_string(strbuf_t *buf, const char *s)
void libconfig_strbuf_append_string(strbuf_t *buf, const char *s)
{
size_t len = strlen(s);
strbuf_ensure_capacity(buf, len);
libconfig_strbuf_ensure_capacity(buf, len);
strcpy(buf->string + buf->length, s);
buf->length += len;
}
/* ------------------------------------------------------------------------- */
void strbuf_append_char(strbuf_t *buf, char c)
void libconfig_strbuf_append_char(strbuf_t *buf, char c)
{
strbuf_ensure_capacity(buf, 1);
libconfig_strbuf_ensure_capacity(buf, 1);
*(buf->string + buf->length) = c;
++(buf->length);
*(buf->string + buf->length) = '\0';
......
/* ----------------------------------------------------------------------------
libconfig - A library for processing structured configuration files
Copyright (C) 2005-2018 Mark A Lindner
Copyright (C) 2005-2020 Mark A Lindner
This file is part of libconfig.
......@@ -33,10 +33,10 @@ typedef struct
size_t capacity;
} strbuf_t;
void strbuf_append_string(strbuf_t *buf, const char *s);
void libconfig_strbuf_append_string(strbuf_t *buf, const char *s);
void strbuf_append_char(strbuf_t *buf, char c);
void libconfig_strbuf_append_char(strbuf_t *buf, char c);
char *strbuf_release(strbuf_t *buf);
char *libconfig_strbuf_release(strbuf_t *buf);
#endif /* __libconfig_strbuf_h */
/* ----------------------------------------------------------------------------
libconfig - A library for processing structured configuration files
Copyright (C) 2005-2018 Mark A Lindner
Copyright (C) 2005-2020 Mark A Lindner
This file is part of libconfig.
......@@ -29,7 +29,7 @@
/* ------------------------------------------------------------------------- */
void strvec_append(strvec_t *vec, const char *s)
void libconfig_strvec_append(strvec_t *vec, const char *s)
{
if(vec->length == vec->capacity)
{
......@@ -47,7 +47,7 @@ void strvec_append(strvec_t *vec, const char *s)
/* ------------------------------------------------------------------------- */
const char **strvec_release(strvec_t *vec)
const char **libconfig_strvec_release(strvec_t *vec)
{
const char **r = vec->strings;
if(r)
......
/* ----------------------------------------------------------------------------
libconfig - A library for processing structured configuration files
Copyright (C) 2005-2018 Mark A Lindner
Copyright (C) 2005-2020 Mark A Lindner
This file is part of libconfig.
......@@ -34,8 +34,8 @@ typedef struct
size_t capacity;
} strvec_t;
void strvec_append(strvec_t *vec, const char *s);
void libconfig_strvec_append(strvec_t *vec, const char *s);
const char **strvec_release(strvec_t *vec);
const char **libconfig_strvec_release(strvec_t *vec);
#endif /* __libconfig_strvec_h */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment