Update -h handling code to be consistent with latest (#5419)

* Rename `totalFlagAndArgLength` to `flagAndArgLength`
* Rename `maxOptionAndArgLength` to `maxFlagAndArgLength`
* Rename `optionLength` to `flagLength`
* Rename `totalLength` to `flagAndArgLength`
* Replace `sizeof(options) / sizeof(options[0])` with `RZ_ARRAY_SIZE(options)`
This commit is contained in:
Khairul Azhar Kasmiran 2025-09-28 22:36:07 +08:00 committed by GitHub
parent fef5cb03fb
commit 697bfa8b70
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 93 additions and 93 deletions

View file

@ -88,18 +88,18 @@ static int help(bool verbose) {
"-x", "[num]", "Number of expected failed tests",
// clang-format on
};
size_t maxOptionAndArgLength = 0;
for (int i = 0; i < sizeof(options) / sizeof(options[0]); i += 3) {
size_t optionLength = strlen(options[i]);
size_t maxFlagAndArgLength = 0;
for (int i = 0; i < RZ_ARRAY_SIZE(options); i += 3) {
size_t flagLength = strlen(options[i]);
size_t argLength = strlen(options[i + 1]);
size_t totalLength = optionLength + argLength;
if (totalLength > maxOptionAndArgLength) {
maxOptionAndArgLength = totalLength;
size_t flagAndArgLength = flagLength + argLength;
if (flagAndArgLength > maxFlagAndArgLength) {
maxFlagAndArgLength = flagAndArgLength;
}
}
for (int i = 0; i < sizeof(options) / sizeof(options[0]); i += 3) {
if (i + 1 < sizeof(options) / sizeof(options[0])) {
rz_print_colored_help_option(options[i], options[i + 1], options[i + 2], maxOptionAndArgLength);
for (int i = 0; i < RZ_ARRAY_SIZE(options); i += 3) {
if (i + 1 < RZ_ARRAY_SIZE(options)) {
rz_print_colored_help_option(options[i], options[i + 1], options[i + 2], maxFlagAndArgLength);
}
}
printf("Supported test types: @json @unit @fuzz @cmds\n"

View file

@ -139,18 +139,18 @@ static int main_help(RZ_BORROW RZ_NONNULL RzCore *core, int line) {
"-z, -zz", "", "Do not load strings or load them even in raw",
// clang-format on
};
size_t maxOptionAndArgLength = 0;
for (int i = 0; i < sizeof(options) / sizeof(options[0]); i += 3) {
size_t optionLength = strlen(options[i]);
size_t maxFlagAndArgLength = 0;
for (int i = 0; i < RZ_ARRAY_SIZE(options); i += 3) {
size_t flagLength = strlen(options[i]);
size_t argLength = strlen(options[i + 1]);
size_t totalLength = optionLength + argLength;
if (totalLength > maxOptionAndArgLength) {
maxOptionAndArgLength = totalLength;
size_t flagAndArgLength = flagLength + argLength;
if (flagAndArgLength > maxFlagAndArgLength) {
maxFlagAndArgLength = flagAndArgLength;
}
}
for (int i = 0; i < sizeof(options) / sizeof(options[0]); i += 3) {
if (i + 1 < sizeof(options) / sizeof(options[0])) {
rz_print_colored_help_option(options[i], options[i + 1], options[i + 2], maxOptionAndArgLength);
for (int i = 0; i < RZ_ARRAY_SIZE(options); i += 3) {
if (i + 1 < RZ_ARRAY_SIZE(options)) {
rz_print_colored_help_option(options[i], options[i + 1], options[i + 2], maxFlagAndArgLength);
}
}
}

View file

@ -207,18 +207,18 @@ static int rasm_show_help(int v) {
// clang-format on
};
if (v != 1) {
size_t maxOptionAndArgLength = 0;
for (int i = 0; i < sizeof(options) / sizeof(options[0]); i += 3) {
size_t optionLength = strlen(options[i]);
size_t maxFlagAndArgLength = 0;
for (int i = 0; i < RZ_ARRAY_SIZE(options); i += 3) {
size_t flagLength = strlen(options[i]);
size_t argLength = strlen(options[i + 1]);
size_t totalLength = optionLength + argLength;
if (totalLength > maxOptionAndArgLength) {
maxOptionAndArgLength = totalLength;
size_t flagAndArgLength = flagLength + argLength;
if (flagAndArgLength > maxFlagAndArgLength) {
maxFlagAndArgLength = flagAndArgLength;
}
}
for (int i = 0; i < sizeof(options) / sizeof(options[0]); i += 3) {
if (i + 1 < sizeof(options) / sizeof(options[0])) {
rz_print_colored_help_option(options[i], options[i + 1], options[i + 2], maxOptionAndArgLength);
for (int i = 0; i < RZ_ARRAY_SIZE(options); i += 3) {
if (i + 1 < RZ_ARRAY_SIZE(options)) {
rz_print_colored_help_option(options[i], options[i + 1], options[i + 2], maxFlagAndArgLength);
}
}
}

View file

@ -253,9 +253,9 @@ static int help(void) {
for (int i = 0; i < RZ_ARRAY_SIZE(options); i += 4) {
size_t flagLength = options[i] ? strlen(options[i]) : 0;
size_t argLength = options[i + 1] ? strlen(options[i + 1]) : 0;
size_t totalFlagAndArgLength = flagLength + argLength;
if (totalFlagAndArgLength > maxFlagAndArgLength) {
maxFlagAndArgLength = totalFlagAndArgLength;
size_t flagAndArgLength = flagLength + argLength;
if (flagAndArgLength > maxFlagAndArgLength) {
maxFlagAndArgLength = flagAndArgLength;
}
size_t descLength = strlen(options[i + 2]);
if (descLength > maxDescLength) {

View file

@ -218,18 +218,18 @@ static int rzbin_show_help(int v) {
"-Z", "", "Guess size of binary program",
// clang-format on
};
size_t maxOptionAndArgLength = 0;
for (int i = 0; i < sizeof(options) / sizeof(options[0]); i += 3) {
size_t optionLength = strlen(options[i]);
size_t maxFlagAndArgLength = 0;
for (int i = 0; i < RZ_ARRAY_SIZE(options); i += 3) {
size_t flagLength = strlen(options[i]);
size_t argLength = strlen(options[i + 1]);
size_t totalLength = optionLength + argLength;
if (totalLength > maxOptionAndArgLength) {
maxOptionAndArgLength = totalLength;
size_t flagAndArgLength = flagLength + argLength;
if (flagAndArgLength > maxFlagAndArgLength) {
maxFlagAndArgLength = flagAndArgLength;
}
}
for (int i = 0; i < sizeof(options) / sizeof(options[0]); i += 3) {
if (i + 1 < sizeof(options) / sizeof(options[0])) {
rz_print_colored_help_option(options[i], options[i + 1], options[i + 2], maxOptionAndArgLength);
for (int i = 0; i < RZ_ARRAY_SIZE(options); i += 3) {
if (i + 1 < RZ_ARRAY_SIZE(options)) {
rz_print_colored_help_option(options[i], options[i + 1], options[i + 2], maxFlagAndArgLength);
}
}
}

View file

@ -243,18 +243,18 @@ static void rz_diff_show_help(bool usage_only) {
"", "", " symbols | compare symbols found in the files",
// clang-format on
};
size_t maxOptionAndArgLength = 0;
for (int i = 0; i < sizeof(options) / sizeof(options[0]); i += 3) {
size_t optionLength = strlen(options[i]);
size_t maxFlagAndArgLength = 0;
for (int i = 0; i < RZ_ARRAY_SIZE(options); i += 3) {
size_t flagLength = strlen(options[i]);
size_t argLength = strlen(options[i + 1]);
size_t totalLength = optionLength + argLength;
if (totalLength > maxOptionAndArgLength) {
maxOptionAndArgLength = totalLength;
size_t flagAndArgLength = flagLength + argLength;
if (flagAndArgLength > maxFlagAndArgLength) {
maxFlagAndArgLength = flagAndArgLength;
}
}
for (int i = 0; i < sizeof(options) / sizeof(options[0]); i += 3) {
if (i + 1 < sizeof(options) / sizeof(options[0])) {
rz_print_colored_help_option(options[i], options[i + 1], options[i + 2], maxOptionAndArgLength);
for (int i = 0; i < RZ_ARRAY_SIZE(options); i += 3) {
if (i + 1 < RZ_ARRAY_SIZE(options)) {
rz_print_colored_help_option(options[i], options[i + 1], options[i + 2], maxFlagAndArgLength);
}
}

View file

@ -223,18 +223,18 @@ static int show_help(const char *argv0, int line) {
"-Z", "", "Show string found on each search hit",
// clang-format on
};
size_t maxOptionAndArgLength = 0;
for (int i = 0; i < sizeof(options) / sizeof(options[0]); i += 3) {
size_t optionLength = strlen(options[i]);
size_t maxFlagAndArgLength = 0;
for (int i = 0; i < RZ_ARRAY_SIZE(options); i += 3) {
size_t flagLength = strlen(options[i]);
size_t argLength = strlen(options[i + 1]);
size_t totalLength = optionLength + argLength;
if (totalLength > maxOptionAndArgLength) {
maxOptionAndArgLength = totalLength;
size_t flagAndArgLength = flagLength + argLength;
if (flagAndArgLength > maxFlagAndArgLength) {
maxFlagAndArgLength = flagAndArgLength;
}
}
for (int i = 0; i < sizeof(options) / sizeof(options[0]); i += 3) {
if (i + 1 < sizeof(options) / sizeof(options[0])) {
rz_print_colored_help_option(options[i], options[i + 1], options[i + 2], maxOptionAndArgLength);
for (int i = 0; i < RZ_ARRAY_SIZE(options); i += 3) {
if (i + 1 < RZ_ARRAY_SIZE(options)) {
rz_print_colored_help_option(options[i], options[i + 1], options[i + 2], maxFlagAndArgLength);
}
}
return 0;

View file

@ -50,18 +50,18 @@ static int usage(int v) {
"-z", "" ,"Output in C string syntax",
// clang-format on
};
size_t maxOptionAndArgLength = 0;
for (int i = 0; i < sizeof(options) / sizeof(options[0]); i += 3) {
size_t optionLength = strlen(options[i]);
size_t maxFlagAndArgLength = 0;
for (int i = 0; i < RZ_ARRAY_SIZE(options); i += 3) {
size_t flagLength = strlen(options[i]);
size_t argLength = strlen(options[i + 1]);
size_t totalLength = optionLength + argLength;
if (totalLength > maxOptionAndArgLength) {
maxOptionAndArgLength = totalLength;
size_t flagAndArgLength = flagLength + argLength;
if (flagAndArgLength > maxFlagAndArgLength) {
maxFlagAndArgLength = flagAndArgLength;
}
}
for (int i = 0; i < sizeof(options) / sizeof(options[0]); i += 3) {
if (i + 1 < sizeof(options) / sizeof(options[0])) {
rz_print_colored_help_option(options[i], options[i + 1], options[i + 2], maxOptionAndArgLength);
for (int i = 0; i < RZ_ARRAY_SIZE(options); i += 3) {
if (i + 1 < RZ_ARRAY_SIZE(options)) {
rz_print_colored_help_option(options[i], options[i + 1], options[i + 2], maxFlagAndArgLength);
}
}
}

View file

@ -109,18 +109,18 @@ static void rz_hash_show_help(bool usage_only) {
"", "", "If 's:' prefix is specified",
// clang-format on
};
size_t maxOptionAndArgLength = 0;
for (int i = 0; i < sizeof(options) / sizeof(options[0]); i += 3) {
size_t optionLength = strlen(options[i]);
size_t maxFlagAndArgLength = 0;
for (int i = 0; i < RZ_ARRAY_SIZE(options); i += 3) {
size_t flagLength = strlen(options[i]);
size_t argLength = strlen(options[i + 1]);
size_t totalLength = optionLength + argLength;
if (totalLength > maxOptionAndArgLength) {
maxOptionAndArgLength = totalLength;
size_t flagAndArgLength = flagLength + argLength;
if (flagAndArgLength > maxFlagAndArgLength) {
maxFlagAndArgLength = flagAndArgLength;
}
}
for (int i = 0; i < sizeof(options) / sizeof(options[0]); i += 3) {
if (i + 1 < sizeof(options) / sizeof(options[0])) {
rz_print_colored_help_option(options[i], options[i + 1], options[i + 2], maxOptionAndArgLength);
for (int i = 0; i < RZ_ARRAY_SIZE(options); i += 3) {
if (i + 1 < RZ_ARRAY_SIZE(options)) {
rz_print_colored_help_option(options[i], options[i + 1], options[i + 2], maxFlagAndArgLength);
}
}
}

View file

@ -37,18 +37,18 @@ static void rz_run_help(int v) {
"--", "[program] [args]", "Run commands",
// clang-format on
};
size_t maxOptionAndArgLength = 0;
for (int i = 0; i < sizeof(options) / sizeof(options[0]); i += 3) {
size_t optionLength = strlen(options[i]);
size_t maxFlagAndArgLength = 0;
for (int i = 0; i < RZ_ARRAY_SIZE(options); i += 3) {
size_t flagLength = strlen(options[i]);
size_t argLength = strlen(options[i + 1]);
size_t totalLength = optionLength + argLength;
if (totalLength > maxOptionAndArgLength) {
maxOptionAndArgLength = totalLength;
size_t flagAndArgLength = flagLength + argLength;
if (flagAndArgLength > maxFlagAndArgLength) {
maxFlagAndArgLength = flagAndArgLength;
}
}
for (int i = 0; i < sizeof(options) / sizeof(options[0]); i += 3) {
if (i + 1 < sizeof(options) / sizeof(options[0])) {
rz_print_colored_help_option(options[i], options[i + 1], options[i + 2], maxOptionAndArgLength);
for (int i = 0; i < RZ_ARRAY_SIZE(options); i += 3) {
if (i + 1 < RZ_ARRAY_SIZE(options)) {
rz_print_colored_help_option(options[i], options[i + 1], options[i + 2], maxFlagAndArgLength);
}
}
}

View file

@ -26,18 +26,18 @@ static void rz_sign_show_help(void) {
"-v", "", "Show version information",
// clang-format on
};
size_t maxOptionAndArgLength = 0;
for (int i = 0; i < sizeof(options) / sizeof(options[0]); i += 3) {
size_t optionLength = strlen(options[i]);
size_t maxFlagAndArgLength = 0;
for (int i = 0; i < RZ_ARRAY_SIZE(options); i += 3) {
size_t flagLength = strlen(options[i]);
size_t argLength = strlen(options[i + 1]);
size_t totalLength = optionLength + argLength;
if (totalLength > maxOptionAndArgLength) {
maxOptionAndArgLength = totalLength;
size_t flagAndArgLength = flagLength + argLength;
if (flagAndArgLength > maxFlagAndArgLength) {
maxFlagAndArgLength = flagAndArgLength;
}
}
for (int i = 0; i < sizeof(options) / sizeof(options[0]); i += 3) {
if (i + 1 < sizeof(options) / sizeof(options[0])) {
rz_print_colored_help_option(options[i], options[i + 1], options[i + 2], maxOptionAndArgLength);
for (int i = 0; i < RZ_ARRAY_SIZE(options); i += 3) {
if (i + 1 < RZ_ARRAY_SIZE(options)) {
rz_print_colored_help_option(options[i], options[i + 1], options[i + 2], maxFlagAndArgLength);
}
}
printf("Examples:\n"