Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
16ff44ad
Commit
16ff44ad
authored
Jul 19, 2009
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
conf: use the tokenizer library
parent
1745e687
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
90 additions
and
70 deletions
+90
-70
Makefile.am
Makefile.am
+8
-8
conf.c
src/conf.c
+82
-62
No files found.
Makefile.am
View file @
16ff44ad
...
...
@@ -649,7 +649,7 @@ test_read_conf_CPPFLAGS = $(AM_CPPFLAGS) \
test_read_conf_LDADD
=
$(MPD_LIBS)
\
$(GLIB_LIBS)
test_read_conf_SOURCES
=
test
/read_conf.c
\
src/conf.c src/
buffer2array
.c src/utils.c
src/conf.c src/
tokenizer
.c src/utils.c
test_run_input_CPPFLAGS
=
$(AM_CPPFLAGS)
\
$(ARCHIVE_CFLAGS)
\
...
...
@@ -659,7 +659,7 @@ test_run_input_LDADD = $(MPD_LIBS) \
$(INPUT_LIBS)
\
$(GLIB_LIBS)
test_run_input_SOURCES
=
test
/run_input.c
\
src/conf.c src/
buffer2array
.c src/utils.c
\
src/conf.c src/
tokenizer
.c src/utils.c
\
src/tag.c src/tag_pool.c src/tag_save.c
\
$(ARCHIVE_SRC)
\
$(INPUT_SRC)
...
...
@@ -674,7 +674,7 @@ test_run_decoder_LDADD = $(MPD_LIBS) \
$(INPUT_LIBS)
$(DECODER_LIBS)
\
$(GLIB_LIBS)
test_run_decoder_SOURCES
=
test
/run_decoder.c
\
src/conf.c src/
buffer2array
.c src/utils.c src/log.c
\
src/conf.c src/
tokenizer
.c src/utils.c src/log.c
\
src/tag.c src/tag_pool.c
\
src/replay_gain.c
\
src/uri.c
\
...
...
@@ -693,7 +693,7 @@ test_read_tags_LDADD = $(MPD_LIBS) \
$(INPUT_LIBS)
$(DECODER_LIBS)
\
$(GLIB_LIBS)
test_read_tags_SOURCES
=
test
/read_tags.c
\
src/conf.c src/
buffer2array
.c src/utils.c src/log.c
\
src/conf.c src/
tokenizer
.c src/utils.c src/log.c
\
src/tag.c src/tag_pool.c
\
src/replay_gain.c
\
src/uri.c
\
...
...
@@ -709,7 +709,7 @@ test_run_filter_LDADD = $(MPD_LIBS) \
test_run_filter_SOURCES
=
test
/run_filter.c
\
src/filter_plugin.c
\
src/filter_registry.c
\
src/conf.c src/
buffer2array
.c src/utils.c
\
src/conf.c src/
tokenizer
.c src/utils.c
\
src/pcm_volume.c src/pcm_convert.c
\
src/pcm_format.c src/pcm_channels.c src/pcm_dither.c
\
src/pcm_resample.c src/pcm_resample_fallback.c
\
...
...
@@ -723,7 +723,7 @@ endif
if
ENABLE_ENCODER
noinst_PROGRAMS
+=
test
/run_encoder
test_run_encoder_SOURCES
=
test
/run_encoder.c
\
src/conf.c src/
buffer2array
.c
\
src/conf.c src/
tokenizer
.c
\
src/utils.c
\
src/tag.c src/tag_pool.c
\
src/audio_parser.c
\
...
...
@@ -747,7 +747,7 @@ test_run_output_LDADD = $(MPD_LIBS) \
$(OUTPUT_LIBS)
\
$(GLIB_LIBS)
test_run_output_SOURCES
=
test
/run_output.c
\
src/conf.c src/
buffer2array
.c src/utils.c src/log.c
\
src/conf.c src/
tokenizer
.c src/utils.c src/log.c
\
src/audio_parser.c
\
src/timer.c
\
src/tag.c src/tag_pool.c
\
...
...
@@ -772,7 +772,7 @@ test_read_mixer_LDADD = $(MPD_LIBS) \
$(OUTPUT_LIBS)
\
$(GLIB_LIBS)
test_read_mixer_SOURCES
=
test
/read_mixer.c
\
src/conf.c src/
buffer2array
.c src/utils.c src/log.c
\
src/conf.c src/
tokenizer
.c src/utils.c src/log.c
\
src/mixer_control.c src/mixer_api.c
\
src/filter_plugin.c
\
src/filter/volume_filter_plugin.c
\
...
...
src/conf.c
View file @
16ff44ad
...
...
@@ -19,7 +19,7 @@
#include "conf.h"
#include "utils.h"
#include "
buffer2array
.h"
#include "
tokenizer
.h"
#include "path.h"
#include <glib.h>
...
...
@@ -36,10 +36,6 @@
#define MAX_STRING_SIZE MPD_PATH_MAX+80
#define CONF_COMMENT '#'
#define CONF_BLOCK_BEGIN "{"
#define CONF_BLOCK_END "}"
#define CONF_LINE_TOKEN_MAX 3
struct
config_entry
{
const
char
*
const
name
;
...
...
@@ -250,60 +246,59 @@ config_read_block(FILE *fp, int *count, char *string)
{
struct
config_param
*
ret
=
config_new_param
(
NULL
,
*
count
);
int
i
;
int
numberOfArgs
;
int
argsMinusComment
;
while
(
true
)
{
char
*
line
;
const
char
*
name
,
*
value
;
GError
*
error
=
NULL
;
while
(
fgets
(
string
,
MAX_STRING_SIZE
,
fp
))
{
char
*
array
[
CONF_LINE_TOKEN_MAX
]
=
{
NULL
};
line
=
fgets
(
string
,
MAX_STRING_SIZE
,
fp
);
if
(
line
==
NULL
)
g_error
(
"Expected '}' before end-of-file"
);
(
*
count
)
++
;
line
=
g_strchug
(
line
);
if
(
*
line
==
0
||
*
line
==
CONF_COMMENT
)
continue
;
numberOfArgs
=
buffer2array
(
string
,
array
,
CONF_LINE_TOKEN_MAX
);
if
(
*
line
==
'}'
)
{
/* end of this block; return from the function
(and from this "while" loop) */
for
(
i
=
0
;
i
<
numberOfArgs
;
i
++
)
{
if
(
array
[
i
][
0
]
=
=
CONF_COMMENT
)
break
;
}
line
=
g_strchug
(
line
+
1
);
if
(
*
line
!=
0
&&
*
line
!
=
CONF_COMMENT
)
g_error
(
"line %i: Unknown tokens after '}'"
,
*
count
);
argsMinusComment
=
i
;
if
(
0
==
argsMinusComment
)
{
continue
;
return
ret
;
}
if
(
1
==
argsMinusComment
&&
0
==
strcmp
(
array
[
0
],
CONF_BLOCK_END
))
{
break
;
}
/* parse name and value */
if
(
2
!=
argsMinusComment
)
{
g_error
(
"improperly formatted config file at line %i:"
" %s
\n
"
,
*
count
,
string
);
name
=
tokenizer_next_word
(
&
line
,
&
error
);
if
(
name
==
NULL
)
{
assert
(
*
line
!=
0
);
g_error
(
"line %i: %s"
,
*
count
,
error
->
message
);
}
if
(
0
==
strcmp
(
array
[
0
],
CONF_BLOCK_BEGIN
)
||
0
==
strcmp
(
array
[
1
],
CONF_BLOCK_BEGIN
)
||
0
==
strcmp
(
array
[
0
],
CONF_BLOCK_END
)
||
0
==
strcmp
(
array
[
1
],
CONF_BLOCK_END
))
{
g_error
(
"improperly formatted config file at line %i: %s "
"in block beginning at line %i
\n
"
,
*
count
,
string
,
ret
->
line
);
value
=
tokenizer_next_string
(
&
line
,
&
error
);
if
(
value
==
NULL
)
{
if
(
*
line
==
0
)
g_error
(
"line %i: Value missing"
,
*
count
);
else
g_error
(
"line %i: %s"
,
*
count
,
error
->
message
);
}
config_add_block_param
(
ret
,
array
[
0
],
array
[
1
],
*
count
);
}
if
(
*
line
!=
0
&&
*
line
!=
CONF_COMMENT
)
g_error
(
"line %i: Unknown tokens after value"
,
*
count
);
return
ret
;
config_add_block_param
(
ret
,
name
,
value
,
*
count
);
}
}
void
config_read_file
(
const
char
*
file
)
{
FILE
*
fp
;
char
string
[
MAX_STRING_SIZE
+
1
];
int
i
;
int
numberOfArgs
;
int
argsMinusComment
;
int
count
=
0
;
struct
config_entry
*
entry
;
struct
config_param
*
param
;
...
...
@@ -316,48 +311,73 @@ void config_read_file(const char *file)
}
while
(
fgets
(
string
,
MAX_STRING_SIZE
,
fp
))
{
char
*
array
[
CONF_LINE_TOKEN_MAX
]
=
{
NULL
};
char
*
line
;
const
char
*
name
,
*
value
;
GError
*
error
=
NULL
;
count
++
;
numberOfArgs
=
buffer2array
(
string
,
array
,
CONF_LINE_TOKEN_MAX
);
for
(
i
=
0
;
i
<
numberOfArgs
;
i
++
)
{
if
(
array
[
i
][
0
]
==
CONF_COMMENT
)
break
;
}
line
=
g_strchug
(
string
);
if
(
*
line
==
0
||
*
line
==
CONF_COMMENT
)
continue
;
argsMinusComment
=
i
;
/* the first token in each line is the name, followed
by either the value or '{' */
if
(
0
==
argsMinusComment
)
{
continue
;
name
=
tokenizer_next_word
(
&
line
,
&
error
);
if
(
name
==
NULL
)
{
assert
(
*
line
!=
0
);
g_error
(
"line %i: %s"
,
count
,
error
->
message
);
}
if
(
2
!=
argsMinusComment
)
{
g_error
(
"improperly formatted config file at line %i:"
" %s
\n
"
,
count
,
string
);
}
/* get the definition of that option, and check the
"repeatable" flag */
entry
=
config_entry_get
(
array
[
0
]
);
entry
=
config_entry_get
(
name
);
if
(
entry
==
NULL
)
g_error
(
"unrecognized parameter in config file at "
"line %i: %s
\n
"
,
count
,
string
);
"line %i: %s
\n
"
,
count
,
name
);
if
(
entry
->
params
!=
NULL
&&
!
entry
->
repeatable
)
{
param
=
entry
->
params
->
data
;
g_error
(
"config parameter
\"
%s
\"
is first defined on "
"line %i and redefined on line %i
\n
"
,
array
[
0
]
,
param
->
line
,
count
);
name
,
param
->
line
,
count
);
}
/* now parse the block or the value */
if
(
entry
->
block
)
{
if
(
0
!=
strcmp
(
array
[
1
],
CONF_BLOCK_BEGIN
))
{
g_error
(
"improperly formatted config file at "
"line %i: %s
\n
"
,
count
,
string
);
}
/* it's a block, call config_read_block() */
if
(
*
line
!=
'{'
)
g_error
(
"line %i: '{' expected"
,
count
);
line
=
g_strchug
(
line
+
1
);
if
(
*
line
!=
0
&&
*
line
!=
CONF_COMMENT
)
g_error
(
"line %i: Unknown tokens after '{'"
,
count
);
param
=
config_read_block
(
fp
,
&
count
,
string
);
}
else
param
=
config_new_param
(
array
[
1
],
count
);
}
else
{
/* a string value */
value
=
tokenizer_next_string
(
&
line
,
&
error
);
if
(
value
==
NULL
)
{
if
(
*
line
==
0
)
g_error
(
"line %i: Value missing"
,
count
);
else
g_error
(
"line %i: %s"
,
count
,
error
->
message
);
}
if
(
*
line
!=
0
&&
*
line
!=
CONF_COMMENT
)
g_error
(
"line %i: Unknown tokens after value"
,
count
);
param
=
config_new_param
(
value
,
count
);
}
entry
->
params
=
g_slist_append
(
entry
->
params
,
param
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment