1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:47:35 +00:00

pmap: Sort memory regions in output

This makes the program 100% nicer to use. :^)
This commit is contained in:
Andreas Kling 2021-01-24 19:15:34 +01:00
parent 7a71d4b887
commit f8d643284e

View file

@ -26,6 +26,7 @@
#include <AK/ByteBuffer.h> #include <AK/ByteBuffer.h>
#include <AK/JsonObject.h> #include <AK/JsonObject.h>
#include <AK/QuickSort.h>
#include <AK/String.h> #include <AK/String.h>
#include <LibCore/ArgsParser.h> #include <LibCore/ArgsParser.h>
#include <LibCore/File.h> #include <LibCore/File.h>
@ -70,7 +71,13 @@ int main(int argc, char** argv)
auto file_contents = file->read_all(); auto file_contents = file->read_all();
auto json = JsonValue::from_string(file_contents); auto json = JsonValue::from_string(file_contents);
ASSERT(json.has_value()); ASSERT(json.has_value());
json.value().as_array().for_each([](auto& value) {
Vector<JsonValue> sorted_regions = json.value().as_array().values();
quick_sort(sorted_regions, [](auto& a, auto& b) {
return a.as_object().get("address").to_u32() < b.as_object().get("address").to_u32();
});
for (auto& value : sorted_regions) {
auto map = value.as_object(); auto map = value.as_object();
auto address = map.get("address").to_int(); auto address = map.get("address").to_int();
auto size = map.get("size").to_string(); auto size = map.get("size").to_string();
@ -100,7 +107,7 @@ int main(int argc, char** argv)
auto name = map.get("name").to_string(); auto name = map.get("name").to_string();
printf("%-20s ", name.characters()); printf("%-20s ", name.characters());
printf("\n"); printf("\n");
}); }
return 0; return 0;
} }