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
1914e114
Commit
1914e114
authored
Dec 28, 2008
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
conf: use GLib instead of utils.h/log.h
parent
859aac72
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
36 deletions
+37
-36
conf.c
src/conf.c
+37
-36
No files found.
src/conf.c
View file @
1914e114
...
@@ -17,15 +17,14 @@
...
@@ -17,15 +17,14 @@
*/
*/
#include "conf.h"
#include "conf.h"
#include "log.h"
#include "utils.h"
#include "utils.h"
#include "buffer2array.h"
#include "buffer2array.h"
#include "list.h"
#include "list.h"
#include "path.h"
#include "path.h"
#include "os_compat.h"
#include "os_compat.h"
#include <glib.h>
#define MAX_STRING_SIZE MPD_PATH_MAX+80
#define MAX_STRING_SIZE MPD_PATH_MAX+80
#define CONF_COMMENT '#'
#define CONF_COMMENT '#'
...
@@ -62,12 +61,12 @@ static int get_bool(const char *value)
...
@@ -62,12 +61,12 @@ static int get_bool(const char *value)
static
ConfigParam
*
newConfigParam
(
char
*
value
,
int
line
)
static
ConfigParam
*
newConfigParam
(
char
*
value
,
int
line
)
{
{
ConfigParam
*
ret
=
xmalloc
(
sizeof
(
ConfigParam
)
);
ConfigParam
*
ret
=
g_new
(
ConfigParam
,
1
);
if
(
!
value
)
if
(
!
value
)
ret
->
value
=
NULL
;
ret
->
value
=
NULL
;
else
else
ret
->
value
=
x
strdup
(
value
);
ret
->
value
=
g_
strdup
(
value
);
ret
->
line
=
line
;
ret
->
line
=
line
;
...
@@ -101,7 +100,7 @@ static void freeConfigParam(ConfigParam * param)
...
@@ -101,7 +100,7 @@ static void freeConfigParam(ConfigParam * param)
static
ConfigEntry
*
newConfigEntry
(
int
repeatable
,
int
block
)
static
ConfigEntry
*
newConfigEntry
(
int
repeatable
,
int
block
)
{
{
ConfigEntry
*
ret
=
xmalloc
(
sizeof
(
ConfigEntry
)
);
ConfigEntry
*
ret
=
g_new
(
ConfigEntry
,
1
);
ret
->
mask
=
0
;
ret
->
mask
=
0
;
ret
->
configParamList
=
ret
->
configParamList
=
...
@@ -126,7 +125,7 @@ static void registerConfigParam(const char *name, int repeatable, int block)
...
@@ -126,7 +125,7 @@ static void registerConfigParam(const char *name, int repeatable, int block)
ConfigEntry
*
entry
;
ConfigEntry
*
entry
;
if
(
findInList
(
configEntriesList
,
name
,
NULL
))
if
(
findInList
(
configEntriesList
,
name
,
NULL
))
FATAL
(
"config parameter
\"
%s
\"
already registered
\n
"
,
name
);
g_error
(
"config parameter
\"
%s
\"
already registered
\n
"
,
name
);
entry
=
newConfigEntry
(
repeatable
,
block
);
entry
=
newConfigEntry
(
repeatable
,
block
);
...
@@ -192,13 +191,13 @@ static void addBlockParam(ConfigParam * param, char *name, char *value,
...
@@ -192,13 +191,13 @@ static void addBlockParam(ConfigParam * param, char *name, char *value,
{
{
param
->
numberOfBlockParams
++
;
param
->
numberOfBlockParams
++
;
param
->
blockParams
=
x
realloc
(
param
->
blockParams
,
param
->
blockParams
=
g_
realloc
(
param
->
blockParams
,
param
->
numberOfBlockParams
*
param
->
numberOfBlockParams
*
sizeof
(
BlockParam
));
sizeof
(
BlockParam
));
param
->
blockParams
[
param
->
numberOfBlockParams
-
1
].
name
=
x
strdup
(
name
);
param
->
blockParams
[
param
->
numberOfBlockParams
-
1
].
name
=
g_
strdup
(
name
);
param
->
blockParams
[
param
->
numberOfBlockParams
-
1
].
value
=
param
->
blockParams
[
param
->
numberOfBlockParams
-
1
].
value
=
x
strdup
(
value
);
g_
strdup
(
value
);
param
->
blockParams
[
param
->
numberOfBlockParams
-
1
].
line
=
line
;
param
->
blockParams
[
param
->
numberOfBlockParams
-
1
].
line
=
line
;
}
}
...
@@ -234,17 +233,17 @@ static ConfigParam *readConfigBlock(FILE * fp, int *count, char *string)
...
@@ -234,17 +233,17 @@ static ConfigParam *readConfigBlock(FILE * fp, int *count, char *string)
}
}
if
(
2
!=
argsMinusComment
)
{
if
(
2
!=
argsMinusComment
)
{
FATAL
(
"improperly formatted config file at line %i:"
g_error
(
"improperly formatted config file at line %i:"
" %s
\n
"
,
*
count
,
string
);
" %s
\n
"
,
*
count
,
string
);
}
}
if
(
0
==
strcmp
(
array
[
0
],
CONF_BLOCK_BEGIN
)
||
if
(
0
==
strcmp
(
array
[
0
],
CONF_BLOCK_BEGIN
)
||
0
==
strcmp
(
array
[
1
],
CONF_BLOCK_BEGIN
)
||
0
==
strcmp
(
array
[
1
],
CONF_BLOCK_BEGIN
)
||
0
==
strcmp
(
array
[
0
],
CONF_BLOCK_END
)
||
0
==
strcmp
(
array
[
0
],
CONF_BLOCK_END
)
||
0
==
strcmp
(
array
[
1
],
CONF_BLOCK_END
))
{
0
==
strcmp
(
array
[
1
],
CONF_BLOCK_END
))
{
FATAL
(
"improperly formatted config file at line %i: %s
\n
"
g_error
(
"improperly formatted config file at line %i: %s
"
"in block beginning at line %i
\n
"
,
"in block beginning at line %i
\n
"
,
*
count
,
string
,
ret
->
line
);
*
count
,
string
,
ret
->
line
);
}
}
addBlockParam
(
ret
,
array
[
0
],
array
[
1
],
*
count
);
addBlockParam
(
ret
,
array
[
0
],
array
[
1
],
*
count
);
...
@@ -266,8 +265,8 @@ void readConf(const char *file)
...
@@ -266,8 +265,8 @@ void readConf(const char *file)
ConfigParam
*
param
;
ConfigParam
*
param
;
if
(
!
(
fp
=
fopen
(
file
,
"r"
)))
{
if
(
!
(
fp
=
fopen
(
file
,
"r"
)))
{
FATAL
(
"problems opening file %s for reading: %s
\n
"
,
file
,
g_error
(
"problems opening file %s for reading: %s
\n
"
,
strerror
(
errno
));
file
,
strerror
(
errno
));
}
}
while
(
fgets
(
string
,
MAX_STRING_SIZE
,
fp
))
{
while
(
fgets
(
string
,
MAX_STRING_SIZE
,
fp
))
{
...
@@ -289,13 +288,13 @@ void readConf(const char *file)
...
@@ -289,13 +288,13 @@ void readConf(const char *file)
}
}
if
(
2
!=
argsMinusComment
)
{
if
(
2
!=
argsMinusComment
)
{
FATAL
(
"improperly formatted config file at line %i:"
g_error
(
"improperly formatted config file at line %i:"
" %s
\n
"
,
count
,
string
);
" %s
\n
"
,
count
,
string
);
}
}
if
(
!
findInList
(
configEntriesList
,
array
[
0
],
&
voidPtr
))
{
if
(
!
findInList
(
configEntriesList
,
array
[
0
],
&
voidPtr
))
{
FATAL
(
"unrecognized parameter in config file at line
"
g_error
(
"unrecognized parameter in config file at
"
"
%i: %s
\n
"
,
count
,
string
);
"line
%i: %s
\n
"
,
count
,
string
);
}
}
entry
=
(
ConfigEntry
*
)
voidPtr
;
entry
=
(
ConfigEntry
*
)
voidPtr
;
...
@@ -303,15 +302,15 @@ void readConf(const char *file)
...
@@ -303,15 +302,15 @@ void readConf(const char *file)
if
(
!
(
entry
->
mask
&
CONF_REPEATABLE_MASK
)
&&
if
(
!
(
entry
->
mask
&
CONF_REPEATABLE_MASK
)
&&
entry
->
configParamList
->
numberOfNodes
)
{
entry
->
configParamList
->
numberOfNodes
)
{
param
=
entry
->
configParamList
->
firstNode
->
data
;
param
=
entry
->
configParamList
->
firstNode
->
data
;
FATAL
(
"config parameter
\"
%s
\"
is first defined on line
"
g_error
(
"config parameter
\"
%s
\"
is first defined on
"
"%i and redefined on line %i
\n
"
,
array
[
0
]
,
"line %i and redefined on line %i
\n
"
,
param
->
line
,
count
);
array
[
0
],
param
->
line
,
count
);
}
}
if
(
entry
->
mask
&
CONF_BLOCK_MASK
)
{
if
(
entry
->
mask
&
CONF_BLOCK_MASK
)
{
if
(
0
!=
strcmp
(
array
[
1
],
CONF_BLOCK_BEGIN
))
{
if
(
0
!=
strcmp
(
array
[
1
],
CONF_BLOCK_BEGIN
))
{
FATAL
(
"improperly formatted config file at "
g_error
(
"improperly formatted config file at "
"line %i: %s
\n
"
,
count
,
string
);
"line %i: %s
\n
"
,
count
,
string
);
}
}
param
=
readConfigBlock
(
fp
,
&
count
,
string
);
param
=
readConfigBlock
(
fp
,
&
count
,
string
);
}
else
}
else
...
@@ -371,9 +370,9 @@ BlockParam *getBlockParam(ConfigParam * param, const char *name)
...
@@ -371,9 +370,9 @@ BlockParam *getBlockParam(ConfigParam * param, const char *name)
for
(
i
=
0
;
i
<
param
->
numberOfBlockParams
;
i
++
)
{
for
(
i
=
0
;
i
<
param
->
numberOfBlockParams
;
i
++
)
{
if
(
0
==
strcmp
(
name
,
param
->
blockParams
[
i
].
name
))
{
if
(
0
==
strcmp
(
name
,
param
->
blockParams
[
i
].
name
))
{
if
(
ret
)
{
if
(
ret
)
{
ERROR
(
"
\"
%s
\"
first defined on line %i, and "
g_warning
(
"
\"
%s
\"
first defined on line %i, and "
"redefined on line %i
\n
"
,
name
,
"redefined on line %i
\n
"
,
name
,
ret
->
line
,
param
->
blockParams
[
i
].
line
);
ret
->
line
,
param
->
blockParams
[
i
].
line
);
}
}
ret
=
param
->
blockParams
+
i
;
ret
=
param
->
blockParams
+
i
;
}
}
...
@@ -388,14 +387,15 @@ ConfigParam *parseConfigFilePath(const char *name, int force)
...
@@ -388,14 +387,15 @@ ConfigParam *parseConfigFilePath(const char *name, int force)
char
*
path
;
char
*
path
;
if
(
!
param
&&
force
)
if
(
!
param
&&
force
)
FATAL
(
"config parameter
\"
%s
\"
not found
\n
"
,
name
);
g_error
(
"config parameter
\"
%s
\"
not found
\n
"
,
name
);
if
(
!
param
)
if
(
!
param
)
return
NULL
;
return
NULL
;
path
=
parsePath
(
param
->
value
);
path
=
parsePath
(
param
->
value
);
if
(
!
path
)
if
(
!
path
)
FATAL
(
"error parsing
\"
%s
\"
at line %i
\n
"
,
name
,
param
->
line
);
g_error
(
"error parsing
\"
%s
\"
at line %i
\n
"
,
name
,
param
->
line
);
free
(
param
->
value
);
free
(
param
->
value
);
param
->
value
=
path
;
param
->
value
=
path
;
...
@@ -413,9 +413,9 @@ int getBoolConfigParam(const char *name, int force)
...
@@ -413,9 +413,9 @@ int getBoolConfigParam(const char *name, int force)
ret
=
get_bool
(
param
->
value
);
ret
=
get_bool
(
param
->
value
);
if
(
force
&&
ret
==
CONF_BOOL_INVALID
)
if
(
force
&&
ret
==
CONF_BOOL_INVALID
)
FATAL
(
"%s is not a boolean value (yes, true, 1) or "
g_error
(
"%s is not a boolean value (yes, true, 1) or "
"(no, false, 0) on line %i
\n
"
,
"(no, false, 0) on line %i
\n
"
,
name
,
param
->
line
);
name
,
param
->
line
);
return
ret
;
return
ret
;
}
}
...
@@ -439,8 +439,9 @@ int getBoolBlockParam(ConfigParam *param, const char *name, int force)
...
@@ -439,8 +439,9 @@ int getBoolBlockParam(ConfigParam *param, const char *name, int force)
ret
=
get_bool
(
bp
->
value
);
ret
=
get_bool
(
bp
->
value
);
if
(
force
&&
ret
==
CONF_BOOL_INVALID
)
if
(
force
&&
ret
==
CONF_BOOL_INVALID
)
FATAL
(
"%s is not a boolean value (yes, true, 1) or "
g_error
(
"%s is not a boolean value (yes, true, 1) or "
"(no, false, 0) on line %i
\n
"
,
bp
->
value
,
bp
->
line
);
"(no, false, 0) on line %i
\n
"
,
bp
->
value
,
bp
->
line
);
return
ret
;
return
ret
;
}
}
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