Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
Sunxi Tools
Commits
65059d05
Commit
65059d05
authored
May 06, 2012
by
Alejandro Mery
Browse files
fex2bin: sighly cleaned key=value parsing loop
parent
4348a750
Changes
1
Hide whitespace changes
Inline
Side-by-side
fex2bin.c
View file @
65059d05
...
@@ -100,20 +100,15 @@ static int parse_fex(FILE *in, const char *filename, struct script *script)
...
@@ -100,20 +100,15 @@ static int parse_fex(FILE *in, const char *filename, struct script *script)
if
(
!
last_section
)
{
if
(
!
last_section
)
{
errf
(
"E: %s:%zu: data must follow a section.
\n
"
,
errf
(
"E: %s:%zu: data must follow a section.
\n
"
,
filename
,
line
);
filename
,
line
);
ok
=
0
;
goto
parse_error
;
break
;
};
};
while
(
isalnum
(
*
p
)
||
*
p
==
'_'
)
while
(
isalnum
(
*
p
)
||
*
p
==
'_'
)
p
++
;
p
++
;
mark
=
p
;
mark
=
p
;
p
=
skip_blank
(
p
);
p
=
skip_blank
(
p
);
if
(
*
p
!=
'='
)
{
if
(
*
p
!=
'='
)
errf
(
"E: %s:%zu: invalid character at %zu.
\n
"
,
goto
invalid_char_at_p
;
filename
,
line
,
p
-
buffer
+
1
);
ok
=
0
;
break
;
}
*
mark
=
'\0'
;
/* truncate key */
*
mark
=
'\0'
;
/* truncate key */
p
=
skip_blank
(
p
+
1
);
p
=
skip_blank
(
p
+
1
);
...
@@ -147,8 +142,7 @@ static int parse_fex(FILE *in, const char *filename, struct script *script)
...
@@ -147,8 +142,7 @@ static int parse_fex(FILE *in, const char *filename, struct script *script)
else
if
(
port_num
<
0
||
port_num
>
255
)
{
else
if
(
port_num
<
0
||
port_num
>
255
)
{
errf
(
"E: %s:%zu: port out of range at %zu.
\n
"
,
errf
(
"E: %s:%zu: port out of range at %zu.
\n
"
,
filename
,
line
,
p
-
buffer
+
1
);
filename
,
line
,
p
-
buffer
+
1
);
ok
=
0
;
goto
parse_error
;
break
;
}
else
{
}
else
{
p
=
end
;
p
=
end
;
errf
(
"%s.%s = GPIO %d.%ld (%s)
\n
"
,
errf
(
"%s.%s = GPIO %d.%ld (%s)
\n
"
,
...
@@ -157,27 +151,27 @@ static int parse_fex(FILE *in, const char *filename, struct script *script)
...
@@ -157,27 +151,27 @@ static int parse_fex(FILE *in, const char *filename, struct script *script)
continue
;
continue
;
}
}
}
}
errf
(
"E: %s:%zu: invalid character at %zu.
\n
"
,
filename
,
line
,
p
-
buffer
+
1
);
}
else
if
(
isdigit
(
*
p
))
{
}
else
if
(
isdigit
(
*
p
))
{
long
long
v
=
0
;
long
long
v
=
0
;
char
*
end
;
char
*
end
;
v
=
strtoll
(
p
,
&
end
,
0
);
v
=
strtoll
(
p
,
&
end
,
0
);
if
(
end
!=
pe
)
{
p
=
end
;
errf
(
"E: %s:%zu: invalid character at %zu.
\n
"
,
if
(
p
!=
pe
)
{
filename
,
line
,
end
-
buffer
+
1
)
;
;
}
else
if
(
v
>
UINT32_MAX
)
{
}
else
if
(
v
>
UINT32_MAX
)
{
errf
(
"E: %s:%zu: value out of range %lld.
\n
"
,
errf
(
"E: %s:%zu: value out of range %lld.
\n
"
,
filename
,
line
,
v
);
filename
,
line
,
v
);
goto
parse_error
;
}
else
if
(
script_single_entry_new
(
last_section
,
key
,
v
))
{
}
else
if
(
script_single_entry_new
(
last_section
,
key
,
v
))
{
errf
(
"%s.%s = %lld
\n
"
,
errf
(
"%s.%s = %lld
\n
"
,
last_section
->
name
,
key
,
v
);
last_section
->
name
,
key
,
v
);
continue
;
continue
;
}
}
}
else
{
errf
(
"E: %s:%zu: invalid character at %zu.
\n
"
,
filename
,
line
,
p
-
buffer
+
1
);
}
}
invalid_char_at_p:
errf
(
"E: %s:%zu: invalid character at %zu.
\n
"
,
filename
,
line
,
p
-
buffer
+
1
);
parse_error:
ok
=
0
;
ok
=
0
;
}
}
};
};
...
...
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