Skip to content

Commit

Permalink
Move options output to a separate function
Browse files Browse the repository at this point in the history
Signed-off-by: Alexey Gladkov <[email protected]>
  • Loading branch information
legionus committed Sep 24, 2024
1 parent d78fd34 commit c5ad423
Show file tree
Hide file tree
Showing 21 changed files with 75 additions and 421 deletions.
23 changes: 2 additions & 21 deletions src/chvt.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,10 @@
static void __attribute__((noreturn))
usage(int rc, const struct kbd_help *options)
{
const struct kbd_help *h;
fprintf(stderr, _("Usage: %s [option...] N\n"), get_progname());
if (options) {
int max = 0;

fprintf(stderr, "\n");
fprintf(stderr, _("Options:"));
fprintf(stderr, "\n");

for (h = options; h && h->opts; h++) {
int len = (int) strlen(h->opts);
if (max < len)
max = len;
}
max += 2;

for (h = options; h && h->opts; h++)
fprintf(stderr, " %-*s %s\n", max, h->opts, h->desc);
}

fprintf(stderr, "\n");
fprintf(stderr, _("Report bugs to authors.\n"));
fprintf(stderr, "\n");
print_options(options);
print_report_bugs();

exit(rc);
}
Expand Down
23 changes: 2 additions & 21 deletions src/deallocvt.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,10 @@
static void __attribute__((noreturn))
usage(int rc, const struct kbd_help *options)
{
const struct kbd_help *h;
fprintf(stderr, _("Usage: %s [option...] [N ...]\n"), get_progname());
if (options) {
int max = 0;

fprintf(stderr, "\n");
fprintf(stderr, _("Options:"));
fprintf(stderr, "\n");

for (h = options; h && h->opts; h++) {
int len = (int) strlen(h->opts);
if (max < len)
max = len;
}
max += 2;

for (h = options; h && h->opts; h++)
fprintf(stderr, " %-*s %s\n", max, h->opts, h->desc);
}

fprintf(stderr, "\n");
fprintf(stderr, _("Report bugs to authors.\n"));
fprintf(stderr, "\n");
print_options(options);
print_report_bugs();

exit(rc);
}
Expand Down
25 changes: 3 additions & 22 deletions src/dumpkeys.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,9 @@ static int fd;
static void __attribute__((noreturn))
usage(int rc, const struct kbd_help *options)
{
const struct kbd_help *h;

fprintf(stderr, _("Usage: %s [option...]\n"), get_progname());

if (options) {
int max = 0;

fprintf(stderr, "\n");
fprintf(stderr, _("Options:"));
fprintf(stderr, "\n");

for (h = options; h && h->opts; h++) {
int len = (int) strlen(h->opts);
if (max < len)
max = len;
}
max += 2;

for (h = options; h && h->opts; h++)
fprintf(stderr, " %-*s %s\n", max, h->opts, h->desc);
}
print_options(options);

fprintf(stderr, "\n");
fprintf(stderr, _("Available charsets: "));
Expand All @@ -60,9 +42,8 @@ usage(int rc, const struct kbd_help *options)
" 8 - one line for each (modifier,keycode) pair;\n"
" 16 - one line for each keycode until 1st hole.\n"
));
fprintf(stderr, "\n");
fprintf(stderr, _("Report bugs to authors.\n"));
fprintf(stderr, "\n");

print_report_bugs();

exit(rc);
}
Expand Down
25 changes: 2 additions & 23 deletions src/fgconsole.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,10 @@
static void __attribute__((noreturn))
usage(int rc, const struct kbd_help *options)
{
const struct kbd_help *h;

fprintf(stderr, _("Usage: %s [option...]\n"), get_progname());

if (options) {
int max = 0;

fprintf(stderr, "\n");
fprintf(stderr, _("Options:"));
fprintf(stderr, "\n");

for (h = options; h && h->opts; h++) {
int len = (int) strlen(h->opts);
if (max < len)
max = len;
}
max += 2;

for (h = options; h && h->opts; h++)
fprintf(stderr, " %-*s %s\n", max, h->opts, h->desc);
}

fprintf(stderr, "\n");
fprintf(stderr, _("Report bugs to authors.\n"));
fprintf(stderr, "\n");
print_options(options);
print_report_bugs();

exit(rc);
}
Expand Down
23 changes: 2 additions & 21 deletions src/getkeycodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,10 @@
static void __attribute__((noreturn))
usage(int rc, const struct kbd_help *options)
{
const struct kbd_help *h;
fprintf(stderr, _("Usage: %s [option...]\n"), get_progname());
if (options) {
int max = 0;

fprintf(stderr, "\n");
fprintf(stderr, _("Options:"));
fprintf(stderr, "\n");

for (h = options; h && h->opts; h++) {
int len = (int) strlen(h->opts);
if (max < len)
max = len;
}
max += 2;

for (h = options; h && h->opts; h++)
fprintf(stderr, " %-*s %s\n", max, h->opts, h->desc);
}

fprintf(stderr, "\n");
fprintf(stderr, _("Report bugs to authors.\n"));
fprintf(stderr, "\n");
print_options(options);
print_report_bugs();

exit(rc);
}
Expand Down
23 changes: 2 additions & 21 deletions src/getunimap.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,10 @@ ud_compar(const void *u1, const void *u2)
static void __attribute__((noreturn))
usage(int rc, const struct kbd_help *options)
{
const struct kbd_help *h;
fprintf(stderr, _("Usage: %s [option...]\n"), get_progname());
if (options) {
int max = 0;

fprintf(stderr, "\n");
fprintf(stderr, _("Options:"));
fprintf(stderr, "\n");

for (h = options; h && h->opts; h++) {
int len = (int) strlen(h->opts);
if (max < len)
max = len;
}
max += 2;

for (h = options; h && h->opts; h++)
fprintf(stderr, " %-*s %s\n", max, h->opts, h->desc);
}

fprintf(stderr, "\n");
fprintf(stderr, _("Report bugs to authors.\n"));
fprintf(stderr, "\n");
print_options(options);
print_report_bugs();

exit(rc);
}
Expand Down
24 changes: 2 additions & 22 deletions src/kbd_mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,12 @@
static void __attribute__((noreturn))
usage(int rc, const struct kbd_help *options)
{
const struct kbd_help *h;
fprintf(stderr, _("Usage: %s [option...]\n"), get_progname());
fprintf(stderr, "\n");
fprintf(stderr, _("This utility reports or sets the keyboard mode.\n"));

if (options) {
int max = 0;

fprintf(stderr, "\n");
fprintf(stderr, _("Options:"));
fprintf(stderr, "\n");

for (h = options; h && h->opts; h++) {
int len = (int) strlen(h->opts);
if (max < len)
max = len;
}
max += 2;

for (h = options; h && h->opts; h++)
fprintf(stderr, " %-*s %s\n", max, h->opts, h->desc);
}

fprintf(stderr, "\n");
fprintf(stderr, _("Report bugs to authors.\n"));
fprintf(stderr, "\n");
print_options(options);
print_report_bugs();

exit(rc);
}
Expand Down
25 changes: 2 additions & 23 deletions src/kbdinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ static const char *value = NULL;
static void __attribute__((noreturn))
usage(int rc, const struct kbd_help *options)
{
const struct kbd_help *h;

fprintf(stderr,
_("Usage: %1$s [option...] getmode [text|graphics]\n"
" or: %1$s [option...] gkbmode [raw|xlate|mediumraw|unicode]\n"
Expand All @@ -31,27 +29,8 @@ usage(int rc, const struct kbd_help *options)
"The utility allows to read and check various parameters\n"
"of the keyboard and virtual console.\n"));

if (options) {
int max = 0;

fprintf(stderr, "\n");
fprintf(stderr, _("Options:"));
fprintf(stderr, "\n");

for (h = options; h && h->opts; h++) {
int len = (int) strlen(h->opts);
if (max < len)
max = len;
}
max += 2;

for (h = options; h && h->opts; h++)
fprintf(stderr, " %-*s %s\n", max, h->opts, h->desc);
}

fprintf(stderr, "\n");
fprintf(stderr, _("Report bugs to authors.\n"));
fprintf(stderr, "\n");
print_options(options);
print_report_bugs();

exit(rc);
}
Expand Down
25 changes: 2 additions & 23 deletions src/kbdrate.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,33 +318,12 @@ static int delay = 250; /* Default delay */
static void __attribute__((noreturn))
usage(int rc, const struct kbd_help *options)
{
const struct kbd_help *h;

fprintf(stderr, _("Usage: %s [option...]\n"), get_progname());
fprintf(stderr, "\n");
fprintf(stderr, _("The program sets the keyboard repeat rate and delay in user mode.\n"));

if (options) {
int max = 0;

fprintf(stderr, "\n");
fprintf(stderr, _("Options:"));
fprintf(stderr, "\n");

for (h = options; h && h->opts; h++) {
int len = (int) strlen(h->opts);
if (max < len)
max = len;
}
max += 2;

for (h = options; h && h->opts; h++)
fprintf(stderr, " %-*s %s\n", max, h->opts, h->desc);
}

fprintf(stderr, "\n");
fprintf(stderr, _("Report bugs to authors.\n"));
fprintf(stderr, "\n");
print_options(options);
print_report_bugs();

exit(rc);
}
Expand Down
3 changes: 3 additions & 0 deletions src/libcommon/libcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ void
__attribute__((noreturn))
print_version_and_exit(void);

void print_options(const struct kbd_help *options);
void print_report_bugs(void);

// error.c
void
__attribute__((format(printf, 2, 3)))
Expand Down
32 changes: 32 additions & 0 deletions src/libcommon/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,35 @@ print_version_and_exit(void)
printf(_("%s from %s\n"), progname, PACKAGE_STRING);
exit(0);
}

void
print_options(const struct kbd_help *options)
{
int max = 0;
const struct kbd_help *h;

if (!options)
return;

fprintf(stderr, "\n");
fprintf(stderr, _("Options:"));
fprintf(stderr, "\n");

for (h = options; h && h->opts; h++) {
int len = (int) strlen(h->opts);
if (max < len)
max = len;
}
max += 2;

for (h = options; h && h->opts; h++)
fprintf(stderr, " %-*s %s\n", max, h->opts, h->desc);
}

void
print_report_bugs(void)
{
fprintf(stderr, "\n");
fprintf(stderr, _("Report bugs to authors.\n"));
fprintf(stderr, "\n");
}
25 changes: 3 additions & 22 deletions src/loadkeys.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,14 @@ static const char *const suffixes[] = {
static void __attribute__((noreturn))
usage(int rc, const struct kbd_help *options)
{
const struct kbd_help *h;

fprintf(stderr, _("Usage: %s [option...] [mapfile...]\n"), get_progname());

if (options) {
int max = 0;

fprintf(stderr, "\n");
fprintf(stderr, _("Options:"));
fprintf(stderr, "\n");

for (h = options; h && h->opts; h++) {
int len = (int) strlen(h->opts);
if (max < len)
max = len;
}
max += 2;

for (h = options; h && h->opts; h++)
fprintf(stderr, " %-*s %s\n", max, h->opts, h->desc);
}
print_options(options);

fprintf(stderr, "\n");
fprintf(stderr, _("Default keymap: %s\n"), DEFMAP);
fprintf(stderr, "\n");
fprintf(stderr, _("Report bugs to authors.\n"));
fprintf(stderr, "\n");

print_report_bugs();

exit(rc);
}
Expand Down
Loading

0 comments on commit c5ad423

Please sign in to comment.