From: "Thomas Bächler" <thomas@archlinux.org>
To: linux-hotplug@vger.kernel.org
Subject: Re: [PATCH v3] tools: add static-nodes tool
Date: Tue, 16 Apr 2013 13:49:16 +0000 [thread overview]
Message-ID: <516D56DC.2030500@archlinux.org> (raw)
In-Reply-To: <1366117954-9272-1-git-send-email-teg@jklm.no>
[-- Attachment #1: Type: text/plain, Size: 1971 bytes --]
Am 16.04.2013 15:12, schrieb Tom Gundersen:
> +static void write_human(FILE *out, char module[], char devname[], char type, unsigned int maj, unsigned int min)
[...]
> +static void write_tmpfile(FILE *out, char devname[], char type, unsigned int maj, unsigned int min)
[...]
> +static int do_static_nodes(int argc, char *argv[])
> +{
> + struct utsname kernel;
> + char modules[PATH_MAX];
> + FILE *in = NULL, *out = stdout;
> + bool human_readable = 1;
This code emphasizes that there is actually only one format available
and needs to be changed again when another one is added. Why not
void (*write_output)((FILE *, char[], char[], char, unsigned int,
unsigned int) = write_human;
? Then ...
> + case 'f':
> + if (!streq(optarg, "tmpfiles")) {
> + fprintf(stderr, "Unknown format: '%s'.\n", argv[1]);
> + help();
> + ret = EXIT_FAILURE;
> + goto finish;
> + }
> + human_readable = 0;
> + break;
case 'f':
if (streq(optarg, "tmpfiles")) {
write_output = write_tmpfiles;
}
else {
fprintf(stderr, "Unknown format: '%s'.\n", argv[1]);
[...]
}
break;
And in the end:
> + if (human_readable)
> + write_human(out, module, devname, type, maj, min);
> + else
> + write_tmpfile(out, devname, type, maj, min);
write_output(out, module, devname, type, maj, min);
Maybe even add an array with output name and function pointer pairs, so
that we could get a list of available formats using --format=?. For
consistency, --format=human should also work. Just seems nicer to me, in
case someone actually plans to extend this later.
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 901 bytes --]
next prev parent reply other threads:[~2013-04-16 13:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-16 13:12 [PATCH v3] tools: add static-nodes tool Tom Gundersen
2013-04-16 13:49 ` Thomas Bächler [this message]
2013-04-16 18:51 ` Lucas De Marchi
2013-04-16 19:08 ` Kay Sievers
2013-04-16 20:32 ` Tom Gundersen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=516D56DC.2030500@archlinux.org \
--to=thomas@archlinux.org \
--cc=linux-hotplug@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.