Skip to content

Commit 8855b97

Browse files
committed
Refactor suggest_doc_links() into suggest_doc_links_CMD_SYS() and suggest_doc_links_CMD_USR() [networkupstools#2977]
Signed-off-by: Jim Klimov <[email protected]>
1 parent d8d7cf5 commit 8855b97

File tree

19 files changed

+40
-21
lines changed

19 files changed

+40
-21
lines changed

NEWS.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ https://github.com/networkupstools/nut/milestone/9
129129
[#2957]
130130
* Fixed a couple of ancient memory leaks: one "shared" during driver
131131
program initialization, and one specific to `dummy-ups` wind-down. [#2972]
132+
* Refactored `suggest_doc_links()` introduced in a recent NUT release into
133+
separate `suggest_doc_links_CMD_SYS()` and `suggest_doc_links_CMD_USR()`
134+
helper methods (used in command-line help of programs that refer to their
135+
manual pages), wrapping a common implementation. [#2977]
132136

133137
- `dummy-ups` driver updates:
134138
* A new instruction `ALARM` was added for the `Dummy Mode` operation
@@ -289,6 +293,8 @@ https://github.com/networkupstools/nut/milestone/11
289293
(development or release snapshot); many programs now display such
290294
references in their command-line usage help, method `suggest_doc_links()`
291295
was introduced for this purpose. [issue #722, PR #2733]
296+
- Note that this method was split into several with NUT v2.843, with
297+
similar names. [PR #2977]
292298
293299
- A technologically and practically interesting revamp of NUT mesh of
294300
link:https://www.gnu.org/software/automake/[automake] (`Makefile.am`)

clients/upsc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static void usage(const char *prog)
6868

6969
nut_report_config_flags();
7070

71-
printf("\n%s", suggest_doc_links(prog, NULL));
71+
printf("\n%s", suggest_doc_links_CMD_USR(prog, NULL));
7272
}
7373

7474
static void printvar(const char *var)

clients/upscmd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static void usage(const char *prog)
7575

7676
nut_report_config_flags();
7777

78-
printf("\n%s", suggest_doc_links(prog, "upsd.users"));
78+
printf("\n%s", suggest_doc_links_CMD_USR(prog, "upsd.users"));
7979
}
8080

8181
static void print_cmd(char *cmdname)

clients/upslog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ static void help(const char *prog)
235235

236236
nut_report_config_flags();
237237

238-
printf("\n%s", suggest_doc_links(prog, NULL));
238+
printf("\n%s", suggest_doc_links_CMD_SYS(prog, NULL));
239239

240240
exit(EXIT_SUCCESS);
241241
}

clients/upsmon.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3269,7 +3269,7 @@ static void help(const char *arg_progname)
32693269

32703270
nut_report_config_flags();
32713271

3272-
printf("\n%s", suggest_doc_links(arg_progname, "upsmon.conf"));
3272+
printf("\n%s", suggest_doc_links_CMD_SYS(arg_progname, "upsmon.conf"));
32733273

32743274
exit(EXIT_SUCCESS);
32753275
}

clients/upsrw.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static void usage(const char *prog)
7676

7777
nut_report_config_flags();
7878

79-
printf("\n%s", suggest_doc_links(prog, "upsd.users"));
79+
printf("\n%s", suggest_doc_links_CMD_USR(prog, "upsd.users"));
8080
}
8181

8282
static void clean_exit(void)

clients/upssched.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1524,7 +1524,7 @@ static void help(const char *arg_progname)
15241524

15251525
nut_report_config_flags();
15261526

1527-
printf("\n%s", suggest_doc_links(arg_progname, "upsmon.conf"));
1527+
printf("\n%s", suggest_doc_links_CMD_SYS(arg_progname, "upsmon.conf"));
15281528

15291529
exit(EXIT_SUCCESS);
15301530
}

common/common-nut_version.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ void nut_report_config_flags(void)
270270
}
271271
}
272272

273-
const char *suggest_doc_links(const char *progname, const char *progconf) {
273+
static const char *do_suggest_doc_links(const char *progname, const char *progconf, const char *mansection) {
274274
static char buf[LARGEBUF];
275275

276276
buf[0] = '\0';
@@ -297,7 +297,9 @@ const char *suggest_doc_links(const char *progname, const char *progconf) {
297297
*/
298298
snprintfcat(buf, sizeof(buf),
299299
"Read The Fine Manual ('man %s %s') and/or ",
300-
MAN_SECTION_CMD_SYS, buf2);
300+
mansection, buf2);
301+
#else
302+
NUT_UNUSED_VARIABLE(mansection);
301303
#endif
302304
snprintfcat(buf, sizeof(buf),
303305
"see\n\t%s/docs/man/%s.html\n",
@@ -314,3 +316,11 @@ const char *suggest_doc_links(const char *progname, const char *progconf) {
314316

315317
return buf;
316318
}
319+
320+
const char *suggest_doc_links_CMD_SYS(const char *progname, const char *progconf) {
321+
return do_suggest_doc_links(progname, progconf, MAN_SECTION_CMD_SYS);
322+
}
323+
324+
const char *suggest_doc_links_CMD_USR(const char *progname, const char *progconf) {
325+
return do_suggest_doc_links(progname, progconf, MAN_SECTION_CMD_USR);
326+
}

docs/nut-versioning.adoc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,9 +419,11 @@ common-nut_version.c
419419
It is used from a number of other methods, such as `print_banner_once()`,
420420
`nut_report_config_flags()`, and so ends up in version reports of programs
421421
via their `help()`/`usage()` methods.
422-
* Method `suggest_doc_links()` prepares a uniform bit of text for driver and
423-
tool programs to report in their `help()`/`usage()` methods, to refer to
424-
their manual page under the `NUT_WEBSITE_BASE`.
422+
* Methods `suggest_doc_links_CMD_SYS()` and `suggest_doc_links_CMD_USR()` help
423+
by preparing a uniform bit of text for driver and tool programs to report in
424+
their `help()`/`usage()` methods, to refer to their locally delivered manual
425+
page (if documentation was built) and an on-line copy under the
426+
`NUT_WEBSITE_BASE`.
425427
426428
Man pages
427429
~~~~~~~~~

drivers/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ static void help_msg(void)
297297

298298
upsdrv_help();
299299

300-
printf("\n%s", suggest_doc_links(progname, "ups.conf"));
300+
printf("\n%s", suggest_doc_links_CMD_SYS(progname, "ups.conf"));
301301
}
302302
#endif /* DRIVERS_MAIN_WITHOUT_MAIN */
303303

0 commit comments

Comments
 (0)