From: Dan Fandrich Date: Fri, 28 Jun 2024 21:41:29 +0000 (-0700) Subject: curl: follow-up to fix categories in --help X-Git-Tag: curl-8_9_0~107 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=127aa61f0608d849a20410fe0eef0daba0ba6e38;p=thirdparty%2Fcurl.git curl: follow-up to fix categories in --help The commit 6483813b was missing changes necessitated by 2abfc75 that causes a crash. Also, use ARRAYSIZE() for cleaner code. Follow-up to 6483813b Ref #14055 --- diff --git a/src/tool_help.c b/src/tool_help.c index a3df3b14b6..a12626eff3 100644 --- a/src/tool_help.c +++ b/src/tool_help.c @@ -39,6 +39,10 @@ # define USE_WATT32 #endif +#ifndef ARRAYSIZE +#define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0])) +#endif + struct category_descriptors { const char *opt; const char *desc; @@ -112,7 +116,7 @@ static void print_category(unsigned int category, unsigned int cols) static int get_category_content(const char *category, unsigned int cols) { unsigned int i; - for(i = 0; i < sizeof(categories)/sizeof(categories[0]); ++i) + for(i = 0; i < ARRAYSIZE(categories); ++i) if(curl_strequal(categories[i].opt, category)) { printf("%s: %s\n", categories[i].opt, categories[i].desc); print_category(categories[i].category, cols); @@ -125,7 +129,7 @@ static int get_category_content(const char *category, unsigned int cols) static void get_categories(void) { unsigned int i; - for(i = 0; i < sizeof(categories)/sizeof(categories[0]); ++i) + for(i = 0; i < ARRAYSIZE(categories); ++i) printf(" %-11s %s\n", categories[i].opt, categories[i].desc); } @@ -134,9 +138,9 @@ static void get_categories_list(unsigned int width) { unsigned int i; size_t col = 0; - for(i = 0; categories[i].opt; ++i) { + for(i = 0; i < ARRAYSIZE(categories); ++i) { size_t len = strlen(categories[i].opt); - if(!categories[i + 1].opt) { + if(i == ARRAYSIZE(categories) - 1) { /* final category */ if(col + len + 1 < width) printf("%s.\n", categories[i].opt); diff --git a/tests/data/test1461 b/tests/data/test1461 index e9a93b5a97..669e5fbf45 100644 --- a/tests/data/test1461 +++ b/tests/data/test1461 @@ -47,8 +47,9 @@ Usage: curl [options...] This is not the full help; this menu is split into categories. Use "--help category" to get an overview of all categories, which are: -auth, connection, curl, dns, file, ftp, http, imap, misc, output, pop3, post, -proxy, scp, sftp, smtp, ssh, telnet, tftp, tls, ech, upload, verbose. +auth, connection, curl, deprecated, dns, file, ftp, global, http, imap, ldap, +output, pop3, post, proxy, scp, sftp, smtp, ssh, telnet, tftp, timeout, tls, +upload, verbose. For all options use the manual or "--help all".