On Fri, Mar 10, 2017 at 02:48:24PM +0000, Sami Kerola wrote: > Having day off and idea to generalize this did not go away from my mind, > so I decided to give it a shot. I'm not sure how many utils might need The problem I see is that you force code writers to use your option_argument although the option argument may be part of the bigger picture. This is reason why for example string_to_idarray() string_to_bitarray() parses use name2id() callback. Anyway, we have probably more places where a simple string to id conversion is used. My recommendation is to add to lib/strutils.c string_to_idx() and use array of strings and return array index: static int string_to_idx(const char **ary, size_t n, const char *name) { size_t i; for (i = 0; i < n; i++) { if (strcmp(ary[i], name) == 0) return i; } return -1; } such function you can use on many many places, not only for options arguments parsing. > +static inline int parse_arg_name(const struct option_arguments *valid_args, > + const char *arg) > +{ > + size_t i; > + > + for (i = 0; valid_args[i].name; i++) { > + if (strcmp(valid_args[i].name, arg) != 0) > + continue; > + switch (valid_args[i].status) { > + case arg_in_use: > + case arg_hide: > + return valid_args[i].id; > + case arg_deprecate: > + warnx(_("'%s' is deprecated"), arg); > + return valid_args[i].id; The warning is unacceptable. Let's imagine you use old udev and you call blkid in your udev rules... It's always better to minimize number of messages for tools executed from scripts. All the valid_args->status seems like over-engineering ;-) Karel -- Karel Zak <kzak@xxxxxxxxxx> http://karelzak.blogspot.com -- To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html