mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Run clang-format on everything (#1332)
This commit is contained in:
@@ -66,10 +66,12 @@ void parseInlinePalSpec(char const * const rawArg) {
|
||||
assert(len <= arg.length());
|
||||
|
||||
errorMessage(msg);
|
||||
fprintf(stderr,
|
||||
"In inline palette spec: %s\n"
|
||||
" ",
|
||||
rawArg);
|
||||
fprintf(
|
||||
stderr,
|
||||
"In inline palette spec: %s\n"
|
||||
" ",
|
||||
rawArg
|
||||
);
|
||||
for (auto i = ofs; i; --i) {
|
||||
putc(' ', stderr);
|
||||
}
|
||||
@@ -97,12 +99,17 @@ void parseInlinePalSpec(char const * const rawArg) {
|
||||
auto pos = std::min(arg.find_first_not_of("0123456789ABCDEFabcdef"sv, n), arg.length());
|
||||
switch (pos - n) {
|
||||
case 3:
|
||||
color = Rgba(singleToHex(arg[n + 0]), singleToHex(arg[n + 1]), singleToHex(arg[n + 2]),
|
||||
0xFF);
|
||||
color = Rgba(
|
||||
singleToHex(arg[n + 0]), singleToHex(arg[n + 1]), singleToHex(arg[n + 2]), 0xFF
|
||||
);
|
||||
break;
|
||||
case 6:
|
||||
color = Rgba(toHex(arg[n + 0], arg[n + 1]), toHex(arg[n + 2], arg[n + 3]),
|
||||
toHex(arg[n + 4], arg[n + 5]), 0xFF);
|
||||
color = Rgba(
|
||||
toHex(arg[n + 0], arg[n + 1]),
|
||||
toHex(arg[n + 2], arg[n + 3]),
|
||||
toHex(arg[n + 4], arg[n + 5]),
|
||||
0xFF
|
||||
);
|
||||
break;
|
||||
case 0:
|
||||
parseError(n - 1, 1, "Missing color after '#'");
|
||||
@@ -239,36 +246,31 @@ static std::optional<U> parseDec(std::string const &str, std::string::size_type
|
||||
return std::optional<U>{value};
|
||||
}
|
||||
|
||||
static std::optional<Rgba> parseColor(std::string const &str, std::string::size_type &n,
|
||||
uint16_t i) {
|
||||
static std::optional<Rgba>
|
||||
parseColor(std::string const &str, std::string::size_type &n, uint16_t i) {
|
||||
std::optional<uint8_t> r = parseDec<uint8_t>(str, n);
|
||||
if (!r) {
|
||||
error("Failed to parse color #%d (\"%s\"): invalid red component", i + 1,
|
||||
str.c_str());
|
||||
error("Failed to parse color #%d (\"%s\"): invalid red component", i + 1, str.c_str());
|
||||
return std::nullopt;
|
||||
}
|
||||
skipWhitespace(str, n);
|
||||
if (n == str.length()) {
|
||||
error("Failed to parse color #%d (\"%s\"): missing green component", i + 1,
|
||||
str.c_str());
|
||||
error("Failed to parse color #%d (\"%s\"): missing green component", i + 1, str.c_str());
|
||||
return std::nullopt;
|
||||
}
|
||||
std::optional<uint8_t> g = parseDec<uint8_t>(str, n);
|
||||
if (!g) {
|
||||
error("Failed to parse color #%d (\"%s\"): invalid green component", i + 1,
|
||||
str.c_str());
|
||||
error("Failed to parse color #%d (\"%s\"): invalid green component", i + 1, str.c_str());
|
||||
return std::nullopt;
|
||||
}
|
||||
skipWhitespace(str, n);
|
||||
if (n == str.length()) {
|
||||
error("Failed to parse color #%d (\"%s\"): missing blue component", i + 1,
|
||||
str.c_str());
|
||||
error("Failed to parse color #%d (\"%s\"): missing blue component", i + 1, str.c_str());
|
||||
return std::nullopt;
|
||||
}
|
||||
std::optional<uint8_t> b = parseDec<uint8_t>(str, n);
|
||||
if (!b) {
|
||||
error("Failed to parse color #%d (\"%s\"): invalid blue component", i + 1,
|
||||
str.c_str());
|
||||
error("Failed to parse color #%d (\"%s\"): invalid blue component", i + 1, str.c_str());
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
@@ -301,10 +303,14 @@ static void parsePSPFile(std::filebuf &file) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (uint16_t nbPalColors = options.nbColorsPerPal * options.nbPalettes; *nbColors > nbPalColors) {
|
||||
warning("PSP file contains %" PRIu16 " colors, but there can only be %" PRIu16
|
||||
"; ignoring extra",
|
||||
*nbColors, nbPalColors);
|
||||
if (uint16_t nbPalColors = options.nbColorsPerPal * options.nbPalettes;
|
||||
*nbColors > nbPalColors) {
|
||||
warning(
|
||||
"PSP file contains %" PRIu16 " colors, but there can only be %" PRIu16
|
||||
"; ignoring extra",
|
||||
*nbColors,
|
||||
nbPalColors
|
||||
);
|
||||
nbColors = nbPalColors;
|
||||
}
|
||||
|
||||
@@ -320,8 +326,11 @@ static void parsePSPFile(std::filebuf &file) {
|
||||
return;
|
||||
}
|
||||
if (n != line.length()) {
|
||||
error("Failed to parse color #%d (\"%s\"): trailing characters after blue component",
|
||||
i + 1, line.c_str());
|
||||
error(
|
||||
"Failed to parse color #%d (\"%s\"): trailing characters after blue component",
|
||||
i + 1,
|
||||
line.c_str()
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -372,9 +381,12 @@ static void parseGPLFile(std::filebuf &file) {
|
||||
}
|
||||
|
||||
if (nbColors > maxNbColors) {
|
||||
warning("GPL file contains %" PRIu16 " colors, but there can only be %" PRIu16
|
||||
"; ignoring extra",
|
||||
nbColors, maxNbColors);
|
||||
warning(
|
||||
"GPL file contains %" PRIu16 " colors, but there can only be %" PRIu16
|
||||
"; ignoring extra",
|
||||
nbColors,
|
||||
maxNbColors
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -393,8 +405,11 @@ static void parseHEXFile(std::filebuf &file) {
|
||||
|
||||
if (line.length() != 6
|
||||
|| line.find_first_not_of("0123456789ABCDEFabcdef"sv) != std::string::npos) {
|
||||
error("Failed to parse color #%d (\"%s\"): invalid \"rrggbb\" line",
|
||||
nbColors + 1, line.c_str());
|
||||
error(
|
||||
"Failed to parse color #%d (\"%s\"): invalid \"rrggbb\" line",
|
||||
nbColors + 1,
|
||||
line.c_str()
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -411,9 +426,12 @@ static void parseHEXFile(std::filebuf &file) {
|
||||
}
|
||||
|
||||
if (nbColors > maxNbColors) {
|
||||
warning("HEX file contains %" PRIu16 " colors, but there can only be %" PRIu16
|
||||
"; ignoring extra",
|
||||
nbColors, maxNbColors);
|
||||
warning(
|
||||
"HEX file contains %" PRIu16 " colors, but there can only be %" PRIu16
|
||||
"; ignoring extra",
|
||||
nbColors,
|
||||
maxNbColors
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -436,10 +454,14 @@ static void parseACTFile(std::filebuf &file) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (uint16_t nbPalColors = options.nbColorsPerPal * options.nbPalettes; nbColors > nbPalColors) {
|
||||
warning("ACT file contains %" PRIu16 " colors, but there can only be %" PRIu16
|
||||
"; ignoring extra",
|
||||
nbColors, nbPalColors);
|
||||
if (uint16_t nbPalColors = options.nbColorsPerPal * options.nbPalettes;
|
||||
nbColors > nbPalColors) {
|
||||
warning(
|
||||
"ACT file contains %" PRIu16 " colors, but there can only be %" PRIu16
|
||||
"; ignoring extra",
|
||||
nbColors,
|
||||
nbPalColors
|
||||
);
|
||||
nbColors = nbPalColors;
|
||||
}
|
||||
|
||||
@@ -486,10 +508,14 @@ static void parseACOFile(std::filebuf &file) {
|
||||
}
|
||||
uint16_t nbColors = readBE<uint16_t>(buf);
|
||||
|
||||
if (uint16_t nbPalColors = options.nbColorsPerPal * options.nbPalettes; nbColors > nbPalColors) {
|
||||
warning("ACO file contains %" PRIu16 " colors, but there can only be %" PRIu16
|
||||
"; ignoring extra",
|
||||
nbColors, nbPalColors);
|
||||
if (uint16_t nbPalColors = options.nbColorsPerPal * options.nbPalettes;
|
||||
nbColors > nbPalColors) {
|
||||
warning(
|
||||
"ACO file contains %" PRIu16 " colors, but there can only be %" PRIu16
|
||||
"; ignoring extra",
|
||||
nbColors,
|
||||
nbPalColors
|
||||
);
|
||||
nbColors = nbPalColors;
|
||||
}
|
||||
|
||||
@@ -543,16 +569,22 @@ static void parseGBCFile(std::filebuf &file) {
|
||||
if (len == 0) {
|
||||
break;
|
||||
} else if (len != sizeof(buf)) {
|
||||
error("GBC palette dump contains %zu 8-byte palette%s, plus %zu byte%s",
|
||||
options.palSpec.size(), options.palSpec.size() == 1 ? "" : "s", len,
|
||||
len == 1 ? "" : "s");
|
||||
error(
|
||||
"GBC palette dump contains %zu 8-byte palette%s, plus %zu byte%s",
|
||||
options.palSpec.size(),
|
||||
options.palSpec.size() == 1 ? "" : "s",
|
||||
len,
|
||||
len == 1 ? "" : "s"
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
options.palSpec.push_back({Rgba::fromCGBColor(readLE<uint16_t>(&buf[0])),
|
||||
Rgba::fromCGBColor(readLE<uint16_t>(&buf[2])),
|
||||
Rgba::fromCGBColor(readLE<uint16_t>(&buf[4])),
|
||||
Rgba::fromCGBColor(readLE<uint16_t>(&buf[6]))});
|
||||
options.palSpec.push_back(
|
||||
{Rgba::fromCGBColor(readLE<uint16_t>(&buf[0])),
|
||||
Rgba::fromCGBColor(readLE<uint16_t>(&buf[2])),
|
||||
Rgba::fromCGBColor(readLE<uint16_t>(&buf[4])),
|
||||
Rgba::fromCGBColor(readLE<uint16_t>(&buf[6]))}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -576,14 +608,16 @@ void parseExternalPalSpec(char const *arg) {
|
||||
std::tuple{"GBC", &parseGBCFile, std::ios::binary},
|
||||
};
|
||||
|
||||
auto iter = std::find_if(RANGE(parsers),
|
||||
[&arg, &ptr](decltype(parsers)::value_type const &parser) {
|
||||
return strncasecmp(arg, std::get<0>(parser), ptr - arg) == 0;
|
||||
});
|
||||
auto iter =
|
||||
std::find_if(RANGE(parsers), [&arg, &ptr](decltype(parsers)::value_type const &parser) {
|
||||
return strncasecmp(arg, std::get<0>(parser), ptr - arg) == 0;
|
||||
});
|
||||
if (iter == parsers.end()) {
|
||||
error("Unknown external palette format \"%.*s\"",
|
||||
static_cast<int>(std::min(ptr - arg, static_cast<decltype(ptr - arg)>(INT_MAX))),
|
||||
arg);
|
||||
error(
|
||||
"Unknown external palette format \"%.*s\"",
|
||||
static_cast<int>(std::min(ptr - arg, static_cast<decltype(ptr - arg)>(INT_MAX))),
|
||||
arg
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user