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
6cdb2a48
Commit
6cdb2a48
authored
Jan 21, 2015
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fs/io/BufferedReader: count line numbers
Replaces the dirty code in config/ConfigFile.cxx.
parent
d8bef327
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
26 deletions
+38
-26
ConfigFile.cxx
src/config/ConfigFile.cxx
+26
-24
BufferedReader.cxx
src/fs/io/BufferedReader.cxx
+4
-1
BufferedReader.hxx
src/fs/io/BufferedReader.hxx
+8
-1
No files found.
src/config/ConfigFile.cxx
View file @
6cdb2a48
...
...
@@ -78,9 +78,9 @@ config_read_name_value(struct config_param *param, char *input, unsigned line,
}
static
struct
config_param
*
config_read_block
(
BufferedReader
&
reader
,
int
*
count
,
Error
&
error
)
config_read_block
(
BufferedReader
&
reader
,
Error
&
error
)
{
struct
config_param
*
ret
=
new
config_param
(
*
count
);
struct
config_param
*
ret
=
new
config_param
(
reader
.
GetLineNumber
()
);
while
(
true
)
{
char
*
line
=
reader
.
ReadLine
();
...
...
@@ -93,7 +93,6 @@ config_read_block(BufferedReader &reader, int *count, Error &error)
return
nullptr
;
}
(
*
count
)
++
;
line
=
StripLeft
(
line
);
if
(
*
line
==
0
||
*
line
==
CONF_COMMENT
)
continue
;
...
...
@@ -106,8 +105,8 @@ config_read_block(BufferedReader &reader, int *count, Error &error)
if
(
*
line
!=
0
&&
*
line
!=
CONF_COMMENT
)
{
delete
ret
;
error
.
Format
(
config_file_domain
,
"line %
i
: Unknown tokens after '}'"
,
*
count
);
"line %
y
: Unknown tokens after '}'"
,
reader
.
GetLineNumber
()
);
return
nullptr
;
}
...
...
@@ -116,10 +115,11 @@ config_read_block(BufferedReader &reader, int *count, Error &error)
/* parse name and value */
if
(
!
config_read_name_value
(
ret
,
line
,
*
count
,
error
))
{
if
(
!
config_read_name_value
(
ret
,
line
,
reader
.
GetLineNumber
(),
error
))
{
assert
(
*
line
!=
0
);
delete
ret
;
error
.
FormatPrefix
(
"line %
i: "
,
*
count
);
error
.
FormatPrefix
(
"line %
u: "
,
reader
.
GetLineNumber
()
);
return
nullptr
;
}
}
...
...
@@ -141,7 +141,6 @@ Append(config_param *&head, config_param *p)
static
bool
ReadConfigFile
(
ConfigData
&
config_data
,
BufferedReader
&
reader
,
Error
&
error
)
{
int
count
=
0
;
struct
config_param
*
param
;
while
(
true
)
{
...
...
@@ -151,8 +150,6 @@ ReadConfigFile(ConfigData &config_data, BufferedReader &reader, Error &error)
const
char
*
name
,
*
value
;
count
++
;
line
=
StripLeft
(
line
);
if
(
*
line
==
0
||
*
line
==
CONF_COMMENT
)
continue
;
...
...
@@ -164,7 +161,7 @@ ReadConfigFile(ConfigData &config_data, BufferedReader &reader, Error &error)
name
=
tokenizer
.
NextWord
(
error
);
if
(
name
==
nullptr
)
{
assert
(
!
tokenizer
.
IsEnd
());
error
.
FormatPrefix
(
"line %
i: "
,
count
);
error
.
FormatPrefix
(
"line %
u: "
,
reader
.
GetLineNumber
()
);
return
false
;
}
...
...
@@ -175,7 +172,8 @@ ReadConfigFile(ConfigData &config_data, BufferedReader &reader, Error &error)
if
(
o
==
ConfigOption
::
MAX
)
{
error
.
Format
(
config_file_domain
,
"unrecognized parameter in config file at "
"line %i: %s
\n
"
,
count
,
name
);
"line %u: %s
\n
"
,
reader
.
GetLineNumber
(),
name
);
return
false
;
}
...
...
@@ -187,8 +185,9 @@ ReadConfigFile(ConfigData &config_data, BufferedReader &reader, Error &error)
param
=
head
;
error
.
Format
(
config_file_domain
,
"config parameter
\"
%s
\"
is first defined "
"on line %i and redefined on line %i
\n
"
,
name
,
param
->
line
,
count
);
"on line %d and redefined on line %u
\n
"
,
name
,
param
->
line
,
reader
.
GetLineNumber
());
return
false
;
}
...
...
@@ -199,19 +198,20 @@ ReadConfigFile(ConfigData &config_data, BufferedReader &reader, Error &error)
if
(
tokenizer
.
CurrentChar
()
!=
'{'
)
{
error
.
Format
(
config_file_domain
,
"line %i: '{' expected"
,
count
);
"line %u: '{' expected"
,
reader
.
GetLineNumber
());
return
false
;
}
line
=
StripLeft
(
tokenizer
.
Rest
()
+
1
);
if
(
*
line
!=
0
&&
*
line
!=
CONF_COMMENT
)
{
error
.
Format
(
config_file_domain
,
"line %
i
: Unknown tokens after '{'"
,
count
);
"line %
u
: Unknown tokens after '{'"
,
reader
.
GetLineNumber
()
);
return
false
;
}
param
=
config_read_block
(
reader
,
&
count
,
error
);
param
=
config_read_block
(
reader
,
error
);
if
(
param
==
nullptr
)
{
return
false
;
}
...
...
@@ -222,10 +222,11 @@ ReadConfigFile(ConfigData &config_data, BufferedReader &reader, Error &error)
if
(
value
==
nullptr
)
{
if
(
tokenizer
.
IsEnd
())
error
.
Format
(
config_file_domain
,
"line %
i
: Value missing"
,
count
);
"line %
u
: Value missing"
,
reader
.
GetLineNumber
()
);
else
error
.
FormatPrefix
(
"line %i: "
,
count
);
error
.
FormatPrefix
(
"line %u: "
,
reader
.
GetLineNumber
());
return
false
;
}
...
...
@@ -233,12 +234,13 @@ ReadConfigFile(ConfigData &config_data, BufferedReader &reader, Error &error)
if
(
!
tokenizer
.
IsEnd
()
&&
tokenizer
.
CurrentChar
()
!=
CONF_COMMENT
)
{
error
.
Format
(
config_file_domain
,
"line %
i
: Unknown tokens after value"
,
count
);
"line %
u
: Unknown tokens after value"
,
reader
.
GetLineNumber
()
);
return
false
;
}
param
=
new
config_param
(
value
,
count
);
param
=
new
config_param
(
value
,
reader
.
GetLineNumber
());
}
Append
(
head
,
param
);
...
...
src/fs/io/BufferedReader.cxx
View file @
6cdb2a48
...
...
@@ -59,8 +59,10 @@ BufferedReader::ReadLine()
{
do
{
char
*
line
=
ReadBufferedLine
(
buffer
);
if
(
line
!=
nullptr
)
if
(
line
!=
nullptr
)
{
++
line_number
;
return
line
;
}
}
while
(
Fill
(
true
));
if
(
last_error
.
IsDefined
()
||
!
eof
||
buffer
.
IsEmpty
())
...
...
@@ -78,5 +80,6 @@ BufferedReader::ReadLine()
char
*
line
=
buffer
.
Read
().
data
;
buffer
.
Clear
();
++
line_number
;
return
line
;
}
src/fs/io/BufferedReader.hxx
View file @
6cdb2a48
...
...
@@ -41,9 +41,12 @@ class BufferedReader {
bool
eof
;
unsigned
line_number
;
public
:
BufferedReader
(
Reader
&
_reader
)
:
reader
(
_reader
),
buffer
(
4096
),
eof
(
false
)
{}
:
reader
(
_reader
),
buffer
(
4096
),
eof
(
false
),
line_number
(
0
)
{}
gcc_pure
bool
Check
()
const
{
...
...
@@ -70,6 +73,10 @@ public:
}
char
*
ReadLine
();
unsigned
GetLineNumber
()
const
{
return
line_number
;
}
};
#endif
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