Skip to content

Commit

Permalink
Fix multi-line compatible parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
pelrun authored and dev-0x7C6 committed Dec 6, 2024
1 parent 2219b33 commit 3488a59
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/fdt/fdt-property-types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct property_info {
};

const static QHash<string, property_info> property_map = {
{"compatible", {property_type::string, word_size::custom}},
{"compatible", {property_type::multiline, word_size::custom}},
{"phandle", {property_type::number, word_size::_32}},
{"pinctrl-names", {property_type::multiline, word_size::custom}},
};
31 changes: 19 additions & 12 deletions src/fdt/fdt-view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,29 @@ string present(const fdt_property &property) {
return name + " = \"" + value + "\";";
};

auto result_multi = [&](auto &value) {
auto lines = value.split(0);
lines.removeLast();

string ret;
for (auto i = 0; i < lines.count(); ++i) {
if (i == lines.count() - 1)
ret += lines[i];
else
ret += lines[i] + "\", \"";
}

return result_str(std::move(ret));
};

if (property_map.contains(name)) {
const property_info info = property_map.value(name);
if (property_type::string == info.type)
return result_str({data});

if (property_type::multiline == info.type)
return result_multi(data);

if (property_type::number == info.type)
return result(string::number(convert(*reinterpret_cast<const u32 *>(data.data()))));
}
Expand All @@ -57,18 +75,7 @@ string present(const fdt_property &property) {
return result(string::number(convert(*reinterpret_cast<const u32 *>(data.data()))));

if (names_regexp.match(name).hasMatch()) {
auto lines = data.split(0);
lines.removeLast();

string ret;
for (auto i = 0; i < lines.count(); ++i) {
if (i == lines.count() - 1)
ret += lines[i];
else
ret += lines[i] + ", ";
}

return result_str(std::move(ret));
return result_multi(data);
}

if (std::count_if(data.begin(), data.end(), [](auto &&value) { return value == 0x00; }) == 1 &&
Expand Down

0 comments on commit 3488a59

Please sign in to comment.