Skip to content

Commit 989868c

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 5ce2771 commit 989868c

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
@@ -293,6 +297,8 @@ https://github.com/networkupstools/nut/milestone/11
293297
(development or release snapshot); many programs now display such
294298
references in their command-line usage help, method `suggest_doc_links()`
295299
was introduced for this purpose. [issue #722, PR #2733]
300+
- Note that this method was split into several with NUT v2.843, with
301+
similar names. [PR #2977]
296302
297303
- A technologically and practically interesting revamp of NUT mesh of
298304
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

drivers/upsdrvctl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1281,7 +1281,7 @@ static void help(const char *arg_progname)
12811281
printf(" Fields: UPSNAME UPSDRV RUNNING PF_PID S_RESPONSIVE S_PID S_STATUS\n");
12821282
printf(" (PF_* = according to PID file, if any; S_* = via socket protocol)\n");
12831283

1284-
printf("\n%s", suggest_doc_links(arg_progname, "ups.conf"));
1284+
printf("\n%s", suggest_doc_links_CMD_SYS(arg_progname, "ups.conf"));
12851285
#if (defined(WITH_SOLARIS_SMF) && WITH_SOLARIS_SMF) || (defined(HAVE_SYSTEMD) && HAVE_SYSTEMD)
12861286
printf("NOTE: On this system you should prefer upsdrvsvcctl and nut-driver-enumerator\n");
12871287
#endif

include/common.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ const char *describe_NUT_VERSION_once(void);
227227
* Optional "progconf" allows to suggest config file(s) to study as well.
228228
* NOTE: the string in buffer starts with text and ends with one EOL char.
229229
*/
230-
const char *suggest_doc_links(const char *progname, const char *progconf);
230+
const char *suggest_doc_links_CMD_SYS(const char *progname, const char *progconf);
231+
const char *suggest_doc_links_CMD_USR(const char *progname, const char *progconf);
231232

232233
/* Based on NUT_QUIET_INIT_BANNER envvar (present and empty or "true")
233234
* hide the NUT tool name+version banners; show them by default */

scripts/Windows/wininit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ static void help(const char *arg_progname)
723723
printf(" -V Display NUT version and exit\n");
724724
printf(" -h Display this help and exit\n"); /* also /? but be hush about the one slash */
725725

726-
printf("\n%s", suggest_doc_links(
726+
printf("\n%s", suggest_doc_links_CMD_SYS(
727727
"nut.exe" /*arg_progname*/,
728728
"nut.conf, ups.conf, upsmon.conf, upsd.conf and upsd.users"
729729
));

server/pipedebug.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ int main(int argc, char **argv)
139139
fprintf(stderr, " %s apcsmart-com1\n",
140140
argv[0]);
141141

142-
fprintf(stderr, "\n%s", suggest_doc_links(prog, NULL));
142+
fprintf(stderr, "\n%s", suggest_doc_links_CMD_SYS(prog, NULL));
143143

144144
exit(EXIT_SUCCESS);
145145
}

server/sockdebug.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ int main(int argc, char **argv)
145145
argv[0]);
146146
fprintf(stderr, " for socket files placed in the standard location\n");
147147

148-
fprintf(stderr, "\n%s", suggest_doc_links(prog, NULL));
148+
fprintf(stderr, "\n%s", suggest_doc_links_CMD_SYS(prog, NULL));
149149

150150
exit(EXIT_SUCCESS);
151151
}

server/upsd.c

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

18261826
nut_report_config_flags();
18271827

1828-
printf("\n%s", suggest_doc_links(progname, "ups.conf, upsd.conf and upsd.users"));
1828+
printf("\n%s", suggest_doc_links_CMD_SYS(progname, "ups.conf, upsd.conf and upsd.users"));
18291829

18301830
exit(EXIT_SUCCESS);
18311831
}

tools/nut-scanner/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ libnutscan_la_LDFLAGS += @NETLIBS_GETADDRS@
9696
# object .so names would differ)
9797
#
9898
# libnutscan version information
99-
libnutscan_la_LDFLAGS += -version-info 4:0:0
99+
libnutscan_la_LDFLAGS += -version-info 5:0:0
100100

101101
# libnutscan exported symbols regex
102102
# WARNING: Since the library includes parts of libcommon (as much as needed

tools/nut-scanner/nut-scanner.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1155,7 +1155,7 @@ static void show_usage(const char *arg_progname)
11551155
printf(" -q, --quiet: Display only scan result. No information on currently scanned bus is displayed.\n");
11561156
printf(" -D, --nut_debug_level: Raise the debugging level. Use this multiple times to see more details.\n");
11571157

1158-
printf("\n%s", suggest_doc_links(arg_progname, "ups.conf"));
1158+
printf("\n%s", suggest_doc_links_CMD_SYS(arg_progname, "ups.conf"));
11591159
}
11601160

11611161
int main(int argc, char *argv[])

tools/nutconf/nutconf-cli.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ void Usage::print(const std::string & bin) {
209209

210210
std::cerr
211211
/* << std::endl // last line of s_text is blank */
212-
<< suggest_doc_links(bin.c_str(), nullptr);
212+
<< suggest_doc_links_CMD_SYS(bin.c_str(), nullptr);
213213
/* Method output brings its own endl */
214214
}
215215

0 commit comments

Comments
 (0)