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

Everywhere: Prefer {:#x} over 0x{:x} in format strings

The former automatically adapts the prefix to binary and octal
output, and is what we already use in the majority of cases.

Patch generated by:

    rg -l '0x\{' | xargs sed -i '' -e 's/0x{:/{:#/'

I ran it 4 times (until it stopped changing things) since each
invocation only converted one instance per line.

No behavior change.
This commit is contained in:
Nico Weber 2024-02-21 09:38:31 -05:00 committed by Andreas Kling
parent f963bb4f36
commit 24a469f521
18 changed files with 64 additions and 64 deletions

View file

@ -69,7 +69,7 @@ ErrorOr<void> AddressRangesV5::for_each_range(Function<void(Range)> callback)
case RangeListEntryType::EndOfList:
return {};
default:
dbgln("unsupported range list entry type: 0x{:x}", entry_type);
dbgln("unsupported range list entry type: {:#x}", entry_type);
return Error::from_string_literal("Unsupported range list entry type");
}
}

View file

@ -17,19 +17,19 @@ bool validate_flattened_device_tree(FlattenedDeviceTreeHeader const& header, Rea
{
if (header.magic != 0xD00DFEEDU) {
if (verbose == Verbose::Yes)
warnln("FDT Header has invalid magic value 0x{:08x}. Are you sure it's a flattened device tree?", header.magic);
warnln("FDT Header has invalid magic value {:#08x}. Are you sure it's a flattened device tree?", header.magic);
return false;
}
if ((header.off_mem_rsvmap & ~0x7) != header.off_mem_rsvmap) {
if (verbose == Verbose::Yes)
warnln("FDT Header's MemoryReservationBlock is not 8 byte aligned! Offset: 0x{:08x}", header.off_mem_rsvmap);
warnln("FDT Header's MemoryReservationBlock is not 8 byte aligned! Offset: {:#08x}", header.off_mem_rsvmap);
return false;
}
if ((header.off_dt_struct & ~0x3) != header.off_dt_struct) {
if (verbose == Verbose::Yes)
warnln("FDT Header's StructureBlock is not 4 byte aligned! Offset: 0x{:08x}", header.off_dt_struct);
warnln("FDT Header's StructureBlock is not 4 byte aligned! Offset: {:#08x}", header.off_dt_struct);
return false;
}
@ -116,16 +116,16 @@ bool validate_flattened_device_tree(FlattenedDeviceTreeHeader const& header, Rea
ErrorOr<void> dump(FlattenedDeviceTreeHeader const& header, ReadonlyBytes raw_device_tree)
{
outln("/dts-v1/;");
outln("// magic: 0x{:08x}", header.magic);
outln("// totalsize: 0x{:08x} ({})", header.totalsize, header.totalsize);
outln("// off_dt_struct: 0x{:08x}", header.off_dt_struct);
outln("// off_dt_strings: 0x{:08x}", header.off_dt_strings);
outln("// off_mem_rsvmap: 0x{:08x}", header.off_mem_rsvmap);
outln("// version: 0x{:08x}", header.version);
outln("// last_comp_version: 0x{:08x}", header.last_comp_version);
outln("// boot_cpuid_phys: 0x{:08x}", header.boot_cpuid_phys);
outln("// size_dt_strings: 0x{:08x}", header.size_dt_strings);
outln("// size_dt_struct: 0x{:08x}", header.size_dt_struct);
outln("// magic: {:#08x}", header.magic);
outln("// totalsize: {:#08x} ({})", header.totalsize, header.totalsize);
outln("// off_dt_struct: {:#08x}", header.off_dt_struct);
outln("// off_dt_strings: {:#08x}", header.off_dt_strings);
outln("// off_mem_rsvmap: {:#08x}", header.off_mem_rsvmap);
outln("// version: {:#08x}", header.version);
outln("// last_comp_version: {:#08x}", header.last_comp_version);
outln("// boot_cpuid_phys: {:#08x}", header.boot_cpuid_phys);
outln("// size_dt_strings: {:#08x}", header.size_dt_strings);
outln("// size_dt_struct: {:#08x}", header.size_dt_struct);
if (!validate_flattened_device_tree(header, raw_device_tree, Verbose::Yes))
return Error::from_errno(EINVAL);
@ -134,7 +134,7 @@ ErrorOr<void> dump(FlattenedDeviceTreeHeader const& header, ReadonlyBytes raw_de
auto const* mem_reserve_block = reinterpret_cast<FlattenedDeviceTreeReserveEntry const*>(&raw_device_tree[header.off_mem_rsvmap]);
u64 next_block_offset = header.off_mem_rsvmap + sizeof(FlattenedDeviceTreeReserveEntry);
while ((next_block_offset < header.off_dt_struct) && (*mem_reserve_block != FlattenedDeviceTreeReserveEntry {})) {
outln("/memreserve/ 0x{:08x} 0x{:08x};", mem_reserve_block->address, mem_reserve_block->size);
outln("/memreserve/ {:#08x} {:#08x};", mem_reserve_block->address, mem_reserve_block->size);
++mem_reserve_block;
next_block_offset += sizeof(FlattenedDeviceTreeReserveEntry);
}

View file

@ -42,7 +42,7 @@ ErrorOr<void> FullBox::read_from_stream(BoxStream& stream)
void FullBox::dump(String const& prepend) const
{
outln("{}{} (version = {}, flags = 0x{:x})", prepend, box_type(), version, flags);
outln("{}{} (version = {}, flags = {:#x})", prepend, box_type(), version, flags);
}
static String add_indent(String const& string)

View file

@ -1171,7 +1171,7 @@ static ErrorOr<void> read_colour_encoding(JPEGStream& stream, [[maybe_unused]] J
context.color_transform = ColorTransform::YCCK;
break;
default:
dbgln("0x{:x} is not a specified transform flag value, ignoring", color_transform);
dbgln("{:#x} is not a specified transform flag value, ignoring", color_transform);
}
return {};

View file

@ -294,7 +294,7 @@ static ErrorOr<VP8XHeader> decode_webp_chunk_VP8X(RIFF::Chunk const& vp8x_chunk)
// 3 bytes height minus one
u32 height = (vp8x_chunk[7] | (vp8x_chunk[8] << 8) | (vp8x_chunk[9] << 16)) + 1;
dbgln_if(WEBP_DEBUG, "flags 0x{:x} --{}{}{}{}{}{}, width {}, height {}",
dbgln_if(WEBP_DEBUG, "flags {:#x} --{}{}{}{}{}{}, width {}, height {}",
flags,
has_icc ? " icc" : "",
has_alpha ? " alpha" : "",

View file

@ -328,7 +328,7 @@ ErrorOr<void, ValidationError> Validator::validate(Limits const& limits, size_t
template<u64 opcode>
ErrorOr<void, ValidationError> Validator::validate_instruction(Instruction const& instruction, Stack&, bool&)
{
return Errors::invalid(ByteString::formatted("instruction opcode (0x{:x}) (missing validation!)", instruction.opcode().value()));
return Errors::invalid(ByteString::formatted("instruction opcode ({:#x}) (missing validation!)", instruction.opcode().value()));
}
#define VALIDATE_INSTRUCTION(name) \
@ -3774,7 +3774,7 @@ ErrorOr<void, ValidationError> Validator::validate(Instruction const& instructio
#undef M
default:
is_constant = false;
return Errors::invalid(ByteString::formatted("instruction opcode (0x{:x})", instruction.opcode().value()));
return Errors::invalid(ByteString::formatted("instruction opcode ({:#x})", instruction.opcode().value()));
}
}

View file

@ -544,7 +544,7 @@ Optional<StyleProperty> ResolvedCSSStyleDeclaration::property(PropertyID propert
// FIXME: This is a stopgap until we implement shorthand -> longhand conversion.
auto value = style->maybe_null_property(property_id);
if (!value) {
dbgln("FIXME: ResolvedCSSStyleDeclaration::property(property_id=0x{:x}) No value for property ID in newly computed style case.", to_underlying(property_id));
dbgln("FIXME: ResolvedCSSStyleDeclaration::property(property_id={:#x}) No value for property ID in newly computed style case.", to_underlying(property_id));
return {};
}
return StyleProperty {

View file

@ -129,7 +129,7 @@ void WebGLRenderingContextBase::active_texture(GLenum texture)
if (m_context_lost)
return;
dbgln_if(WEBGL_CONTEXT_DEBUG, "WebGLRenderingContextBase::active_texture(texture=0x{:08x})", texture);
dbgln_if(WEBGL_CONTEXT_DEBUG, "WebGLRenderingContextBase::active_texture(texture={:#08x})", texture);
m_context->gl_active_texture(texture);
}
@ -138,7 +138,7 @@ void WebGLRenderingContextBase::clear(GLbitfield mask)
if (m_context_lost)
return;
dbgln_if(WEBGL_CONTEXT_DEBUG, "WebGLRenderingContextBase::clear(mask=0x{:08x})", mask);
dbgln_if(WEBGL_CONTEXT_DEBUG, "WebGLRenderingContextBase::clear(mask={:#08x})", mask);
m_context->gl_clear(mask);
// FIXME: This should only be done if this is targeting the front buffer.
@ -168,7 +168,7 @@ void WebGLRenderingContextBase::clear_stencil(GLint s)
if (m_context_lost)
return;
dbgln_if(WEBGL_CONTEXT_DEBUG, "WebGLRenderingContextBase::clear_stencil(s=0x{:08x})", s);
dbgln_if(WEBGL_CONTEXT_DEBUG, "WebGLRenderingContextBase::clear_stencil(s={:#08x})", s);
m_context->gl_clear_stencil(s);
}
@ -186,7 +186,7 @@ void WebGLRenderingContextBase::cull_face(GLenum mode)
if (m_context_lost)
return;
dbgln_if(WEBGL_CONTEXT_DEBUG, "WebGLRenderingContextBase::cull_face(mode=0x{:08x})", mode);
dbgln_if(WEBGL_CONTEXT_DEBUG, "WebGLRenderingContextBase::cull_face(mode={:#08x})", mode);
m_context->gl_cull_face(mode);
}
@ -195,7 +195,7 @@ void WebGLRenderingContextBase::depth_func(GLenum func)
if (m_context_lost)
return;
dbgln_if(WEBGL_CONTEXT_DEBUG, "WebGLRenderingContextBase::depth_func(func=0x{:08x})", func);
dbgln_if(WEBGL_CONTEXT_DEBUG, "WebGLRenderingContextBase::depth_func(func={:#08x})", func);
m_context->gl_depth_func(func);
}
@ -244,7 +244,7 @@ void WebGLRenderingContextBase::front_face(GLenum mode)
if (m_context_lost)
return;
dbgln_if(WEBGL_CONTEXT_DEBUG, "WebGLRenderingContextBase::front_face(mode=0x{:08x})", mode);
dbgln_if(WEBGL_CONTEXT_DEBUG, "WebGLRenderingContextBase::front_face(mode={:#08x})", mode);
m_context->gl_front_face(mode);
}
@ -300,7 +300,7 @@ void WebGLRenderingContextBase::stencil_op(GLenum fail, GLenum zfail, GLenum zpa
if (m_context_lost)
return;
dbgln_if(WEBGL_CONTEXT_DEBUG, "WebGLRenderingContextBase::stencil_op(fail=0x{:08x}, zfail=0x{:08x}, zpass=0x{:08x})", fail, zfail, zpass);
dbgln_if(WEBGL_CONTEXT_DEBUG, "WebGLRenderingContextBase::stencil_op(fail={:#08x}, zfail={:#08x}, zpass={:#08x})", fail, zfail, zpass);
m_context->gl_stencil_op_separate(GL_FRONT_AND_BACK, fail, zfail, zpass);
}
@ -309,7 +309,7 @@ void WebGLRenderingContextBase::stencil_op_separate(GLenum face, GLenum fail, GL
if (m_context_lost)
return;
dbgln_if(WEBGL_CONTEXT_DEBUG, "WebGLRenderingContextBase::stencil_op_separate(face=0x{:08x}, fail=0x{:08x}, zfail=0x{:08x}, zpass=0x{:08x})", face, fail, zfail, zpass);
dbgln_if(WEBGL_CONTEXT_DEBUG, "WebGLRenderingContextBase::stencil_op_separate(face={:#08x}, fail={:#08x}, zfail={:#08x}, zpass={:#08x})", face, fail, zfail, zpass);
m_context->gl_stencil_op_separate(face, fail, zfail, zpass);
}

View file

@ -337,13 +337,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
out_optional(" primary platform", profile->primary_platform().map([](auto platform) { return primary_platform_name(platform); }));
auto flags = profile->flags();
outln(" flags: 0x{:08x}", flags.bits());
outln(" flags: {:#08x}", flags.bits());
outln(" - {}embedded in file", flags.is_embedded_in_file() ? "" : "not ");
outln(" - can{} be used independently of embedded color data", flags.can_be_used_independently_of_embedded_color_data() ? "" : "not");
if (auto unknown_icc_bits = flags.icc_bits() & ~Gfx::ICC::Flags::KnownBitsMask)
outln(" other unknown ICC bits: 0x{:04x}", unknown_icc_bits);
outln(" other unknown ICC bits: {:#04x}", unknown_icc_bits);
if (auto color_management_module_bits = flags.color_management_module_bits())
outln(" CMM bits: 0x{:04x}", color_management_module_bits);
outln(" CMM bits: {:#04x}", color_management_module_bits);
out_optional(" device manufacturer", TRY(profile->device_manufacturer().map([](auto device_manufacturer) {
return hyperlink(device_manufacturer_url(device_manufacturer), device_manufacturer);
@ -353,7 +353,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
})));
auto device_attributes = profile->device_attributes();
outln(" device attributes: 0x{:016x}", device_attributes.bits());
outln(" device attributes: {:#016x}", device_attributes.bits());
outln(" media is:");
outln(" - {}",
device_attributes.media_reflectivity() == Gfx::ICC::DeviceAttributes::MediaReflectivity::Reflective ? "reflective" : "transparent");
@ -365,7 +365,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
device_attributes.media_color() == Gfx::ICC::DeviceAttributes::MediaColor::Colored ? "colored" : "black and white");
VERIFY((flags.icc_bits() & ~Gfx::ICC::DeviceAttributes::KnownBitsMask) == 0);
if (auto vendor_bits = device_attributes.vendor_bits())
outln(" vendor bits: 0x{:08x}", vendor_bits);
outln(" vendor bits: {:#08x}", vendor_bits);
outln(" rendering intent: {}", Gfx::ICC::rendering_intent_name(profile->rendering_intent()));
outln(" pcs illuminant: {}", profile->pcs_illuminant());
@ -532,7 +532,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
}
} else if (tag_data->type() == Gfx::ICC::NamedColor2TagData::Type) {
auto& named_colors = static_cast<Gfx::ICC::NamedColor2TagData&>(*tag_data);
outln(" vendor specific flag: 0x{:08x}", named_colors.vendor_specific_flag());
outln(" vendor specific flag: {:#08x}", named_colors.vendor_specific_flag());
outln(" common name prefix: \"{}\"", named_colors.prefix());
outln(" common name suffix: \"{}\"", named_colors.suffix());
outln(" {} colors:", named_colors.size());
@ -540,11 +540,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
const auto& pcs = named_colors.pcs_coordinates(i);
// FIXME: Display decoded values? (See ICC v4 6.3.4.2 and 10.8.)
out(" \"{}\", PCS coordinates: 0x{:04x} 0x{:04x} 0x{:04x}", TRY(named_colors.color_name(i)), pcs.xyz.x, pcs.xyz.y, pcs.xyz.z);
out(" \"{}\", PCS coordinates: {:#04x} {:#04x} {:#04x}", TRY(named_colors.color_name(i)), pcs.xyz.x, pcs.xyz.y, pcs.xyz.z);
if (auto number_of_device_coordinates = named_colors.number_of_device_coordinates(); number_of_device_coordinates > 0) {
out(", device coordinates:");
for (size_t j = 0; j < number_of_device_coordinates; ++j)
out(" 0x{:04x}", named_colors.device_coordinates(i)[j]);
out(" {:#04x}", named_colors.device_coordinates(i)[j]);
}
outln();
}
@ -577,7 +577,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
if (auto name = signature.name_for_tag(tag_signature); name.has_value()) {
outln(" signature: {}", name.value());
} else {
outln(" signature: Unknown ('{:c}{:c}{:c}{:c}' / 0x{:08x})",
outln(" signature: Unknown ('{:c}{:c}{:c}{:c}' / {:#08x})",
signature.signature() >> 24, (signature.signature() >> 16) & 0xff, (signature.signature() >> 8) & 0xff, signature.signature() & 0xff,
signature.signature());
}

View file

@ -96,11 +96,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
if (usb_db) {
StringView vendor_string = usb_db->get_vendor(vendor_id);
StringView device_string = usb_db->get_device(vendor_id, product_id);
outln(" idVendor 0x{:04x} {}", device_descriptor.get_u32("vendor_id"sv).value_or(0), vendor_string);
outln(" idProduct 0x{:04x} {}", device_descriptor.get_u32("product_id"sv).value_or(0), device_string);
outln(" idVendor {:#04x} {}", device_descriptor.get_u32("vendor_id"sv).value_or(0), vendor_string);
outln(" idProduct {:#04x} {}", device_descriptor.get_u32("product_id"sv).value_or(0), device_string);
} else {
outln(" idVendor 0x{:04x}", device_descriptor.get_u32("vendor_id"sv).value_or(0));
outln(" idProduct 0x{:04x}", device_descriptor.get_u32("product_id"sv).value_or(0));
outln(" idVendor {:#04x}", device_descriptor.get_u32("vendor_id"sv).value_or(0));
outln(" idProduct {:#04x}", device_descriptor.get_u32("product_id"sv).value_or(0));
}
outln(" bcdDevice {}", device_descriptor.get_u32("device_release_bcd"sv).value_or(0));
outln(" iManufacturer {}", device_descriptor.get_u32("manufacturer_id_descriptor_index"sv).value_or(0));
@ -116,7 +116,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
outln(" bDescriptorType {}", configuration_descriptor.get_u32("descriptor_type"sv).value_or(0));
outln(" wTotalLength {}", configuration_descriptor.get_u32("total_length"sv).value_or(0));
outln(" bNumInterfaces {}", configuration_descriptor.get_u32("number_of_interfaces"sv).value_or(0));
outln(" bmAttributes 0x{:02x}", configuration_descriptor.get_u32("attributes_bitmap"sv).value_or(0));
outln(" bmAttributes {:#02x}", configuration_descriptor.get_u32("attributes_bitmap"sv).value_or(0));
outln(" MaxPower {}mA", configuration_descriptor.get_u32("max_power"sv).value_or(0) * 2u);
auto const& interface_descriptors = config_value.as_object().get_array("interfaces"sv).value();
@ -153,9 +153,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
outln(" Endpoint Descriptor:");
outln(" bLength {}", endpoint_descriptor.get_u32("length"sv).value_or(0));
outln(" bDescriptorType {}", endpoint_descriptor.get_u32("descriptor_type"sv).value_or(0));
outln(" bEndpointAddress 0x{:02x} EP {} {}", endpoint_address, (endpoint_address & 0xFu), ((endpoint_address & 0x80u) ? "IN" : "OUT"));
outln(" bmAttributes 0x{:02x}", endpoint_descriptor.get_u32("attribute_bitmap"sv).value_or(0));
outln(" wMaxPacketSize 0x{:04x}", endpoint_descriptor.get_u32("max_packet_size"sv).value_or(0));
outln(" bEndpointAddress {:#02x} EP {} {}", endpoint_address, (endpoint_address & 0xFu), ((endpoint_address & 0x80u) ? "IN" : "OUT"));
outln(" bmAttributes {:#02x}", endpoint_descriptor.get_u32("attribute_bitmap"sv).value_or(0));
outln(" wMaxPacketSize {:#04x}", endpoint_descriptor.get_u32("max_packet_size"sv).value_or(0));
outln(" bInterval {}", endpoint_descriptor.get_u32("polling_interval"sv).value_or(0));
});
});

View file

@ -290,7 +290,7 @@ struct Formatter<BitflagDerivative> : StandardFormatter {
// No more BitflagOptions are available. Any remaining flags are unrecognized.
if (had_any_output)
TRY(format_builder.put_literal(" | "sv));
format_builder.builder().appendff("0x{:x} (?)", static_cast<unsigned>(remaining));
format_builder.builder().appendff("{:#x} (?)", static_cast<unsigned>(remaining));
had_any_output = true;
}

View file

@ -132,9 +132,9 @@ static void print_line_c_style(Bytes line)
{
out(" ");
for (size_t i = 0; i < line.size() - 1; ++i) {
out("0x{:02x}, ", line[i]);
out("{:#02x}, ", line[i]);
}
out("0x{:02x}", line[line.size() - 1]);
out("{:#02x}", line[line.size() - 1]);
}
static ErrorOr<String> path_to_variable_name(StringView path)