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
ac887d3a
Commit
ac887d3a
authored
Jan 30, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ConfigFile: simplify error cleanup
parent
e294ccae
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
23 deletions
+24
-23
ConfigFile.cxx
src/ConfigFile.cxx
+24
-23
No files found.
src/ConfigFile.cxx
View file @
ac887d3a
...
...
@@ -136,26 +136,15 @@ config_read_block(FILE *fp, int *count, char *string, GError **error_r)
}
}
bool
ReadConfigFile
(
ConfigData
&
config_data
,
const
Path
&
path
,
GError
**
error_r
)
static
bool
ReadConfigFile
(
ConfigData
&
config_data
,
FILE
*
fp
,
GError
**
error_r
)
{
assert
(
!
path
.
IsNull
());
const
std
::
string
path_utf8
=
path
.
ToUTF8
();
assert
(
fp
!=
nullptr
);
FILE
*
fp
;
char
string
[
MAX_STRING_SIZE
+
1
];
int
count
=
0
;
struct
config_param
*
param
;
g_debug
(
"loading file %s"
,
path_utf8
.
c_str
());
if
(
!
(
fp
=
FOpen
(
path
,
"r"
)))
{
g_set_error
(
error_r
,
config_quark
(),
errno
,
"Failed to open %s: %s"
,
path_utf8
.
c_str
(),
g_strerror
(
errno
));
return
false
;
}
while
(
fgets
(
string
,
MAX_STRING_SIZE
,
fp
))
{
char
*
line
;
const
char
*
name
,
*
value
;
...
...
@@ -175,7 +164,6 @@ ReadConfigFile(ConfigData &config_data, const Path &path, GError **error_r)
assert
(
*
line
!=
0
);
g_propagate_prefixed_error
(
error_r
,
error
,
"line %i: "
,
count
);
fclose
(
fp
);
return
false
;
}
...
...
@@ -187,7 +175,6 @@ ReadConfigFile(ConfigData &config_data, const Path &path, GError **error_r)
g_set_error
(
error_r
,
config_quark
(),
0
,
"unrecognized parameter in config file at "
"line %i: %s
\n
"
,
count
,
name
);
fclose
(
fp
);
return
false
;
}
...
...
@@ -201,7 +188,6 @@ ReadConfigFile(ConfigData &config_data, const Path &path, GError **error_r)
"config parameter
\"
%s
\"
is first defined "
"on line %i and redefined on line %i
\n
"
,
name
,
param
->
line
,
count
);
fclose
(
fp
);
return
false
;
}
...
...
@@ -213,7 +199,6 @@ ReadConfigFile(ConfigData &config_data, const Path &path, GError **error_r)
if
(
*
line
!=
'{'
)
{
g_set_error
(
error_r
,
config_quark
(),
0
,
"line %i: '{' expected"
,
count
);
fclose
(
fp
);
return
false
;
}
...
...
@@ -222,13 +207,11 @@ ReadConfigFile(ConfigData &config_data, const Path &path, GError **error_r)
g_set_error
(
error_r
,
config_quark
(),
0
,
"line %i: Unknown tokens after '{'"
,
count
);
fclose
(
fp
);
return
false
;
}
param
=
config_read_block
(
fp
,
&
count
,
string
,
error_r
);
if
(
param
==
NULL
)
{
fclose
(
fp
);
return
false
;
}
}
else
{
...
...
@@ -247,7 +230,6 @@ ReadConfigFile(ConfigData &config_data, const Path &path, GError **error_r)
g_error_free
(
error
);
}
fclose
(
fp
);
return
false
;
}
...
...
@@ -255,7 +237,6 @@ ReadConfigFile(ConfigData &config_data, const Path &path, GError **error_r)
g_set_error
(
error_r
,
config_quark
(),
0
,
"line %i: Unknown tokens after value"
,
count
);
fclose
(
fp
);
return
false
;
}
...
...
@@ -264,7 +245,27 @@ ReadConfigFile(ConfigData &config_data, const Path &path, GError **error_r)
params
=
g_slist_append
(
params
,
param
);
}
fclose
(
fp
);
return
true
;
}
bool
ReadConfigFile
(
ConfigData
&
config_data
,
const
Path
&
path
,
GError
**
error_r
)
{
assert
(
!
path
.
IsNull
());
const
std
::
string
path_utf8
=
path
.
ToUTF8
();
g_debug
(
"loading file %s"
,
path_utf8
.
c_str
());
FILE
*
fp
=
FOpen
(
path
,
"r"
);
if
(
fp
==
nullptr
)
{
g_set_error
(
error_r
,
config_quark
(),
errno
,
"Failed to open %s: %s"
,
path_utf8
.
c_str
(),
g_strerror
(
errno
));
return
false
;
}
bool
result
=
ReadConfigFile
(
config_data
,
fp
,
error_r
);
fclose
(
fp
);
return
result
;
}
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