From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?ISO-8859-15?Q?Thomas_B=E4chler?= Date: Tue, 16 Apr 2013 13:49:16 +0000 Subject: Re: [PATCH v3] tools: add static-nodes tool Message-Id: <516D56DC.2030500@archlinux.org> MIME-Version: 1 Content-Type: multipart/mixed; boundary="----enig2MEIQBBGAGNDTWOQEAUGN" List-Id: References: <1366117954-9272-1-git-send-email-teg@jklm.no> In-Reply-To: <1366117954-9272-1-git-send-email-teg@jklm.no> To: linux-hotplug@vger.kernel.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) ------enig2MEIQBBGAGNDTWOQEAUGN Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable 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, unsign= ed int maj, unsigned int min) [...] > +static int do_static_nodes(int argc, char *argv[]) > +{ > + struct utsname kernel; > + char modules[PATH_MAX]; > + FILE *in =3D NULL, *out =3D stdout; > + bool human_readable =3D 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) =3D write_human; ? Then ... > + case 'f': > + if (!streq(optarg, "tmpfiles")) { > + fprintf(stderr, "Unknown format: '%s'.= \n", argv[1]); > + help(); > + ret =3D EXIT_FAILURE; > + goto finish; > + } > + human_readable =3D 0; > + break; case 'f': if (streq(optarg, "tmpfiles")) { write_output =3D 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, m= in); > + 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=3D?. For consistency, --format=3Dhuman should also work. Just seems nicer to me, i= n case someone actually plans to extend this later. ------enig2MEIQBBGAGNDTWOQEAUGN Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQIcBAEBCAAGBQJRbVbfAAoJEChPw0yOSxolIKcP/0aH6YYCyGQRQi28w4jMyp3/ 67Ah8hOd6ppEbFSFG9GHCNBkpa11SNsV7jYUkw1XLNipUiXrAgI6rF6t8/PxV62a CI49ShXSDZxH6iStKIJKw1B6fBMArva2htZzp1zDY4EmtxSiWoIn7ovQ+G5Gvua0 LWZQ/p3XfFFlfu4NtoIyFCHwWVu4Xw2c7iZCJNvegT038ETlpg2G2a9nUtoz0DrS iKhec7bP2AkZDYy1epOUYHOI4wHfo4GQ+i+tGlVtGpuglr+mc5UoFT8AV7qYa4Kj 7oaIm6Dh5j6pup7x3jTWqOS2MKgWxqRC0wfFRfcE4WEnJS9mPYG2ds1xBnaA+4QM EVw4IgRjL7yKwq2cHR19h6KoGMxpIoWKNbSgFEZCcm6ySQcEV3TOJ+EzyrMzZOu+ G77IL7rfAGv+8wh5x9Lp2pnEZazBE423ZVgVqPSGooax5bQJXvECNhnCvX6oyG6R 7npIk4o7qy/6zNtn7nAgL67AU62bR+fCQnjc9wi3l6kTR8aTdWshfV65t82H+D7+ 4HG4k7UUE5P8WuK/LO/1vkNEeGJNvzZSjVs1c1afc31AGTrb9WORAHdXSlPe6hk2 dTIaRdFSyK0HNPcAGVKzrrcTrTsuXL1LGqOtUvKnwkSz8Y66yVEoJt7eHOr/aPbF sYehngEcXEF3aa9rUw2r =xL2M -----END PGP SIGNATURE----- ------enig2MEIQBBGAGNDTWOQEAUGN--