[PATCH evemu 2/3] tools: play: use getopt

Benjamin Tissoires benjamin.tissoires at gmail.com
Thu Jan 9 14:38:05 PST 2014


On Thu, Jan 9, 2014 at 5:38 PM, Peter Hutterer <peter.hutterer at who-t.net> wrote:
> On Thu, Jan 09, 2014 at 05:17:43PM -0500, Benjamin Tissoires wrote:
>> On Thu, Jan 9, 2014 at 5:06 PM, Benjamin Tissoires
>> <benjamin.tissoires at gmail.com> wrote:
>> > On Thu, Jan 9, 2014 at 5:07 PM, Peter Hutterer <peter.hutterer at who-t.net> wrote:
>> >> On Thu, Jan 09, 2014 at 02:34:08PM -0500, Benjamin Tissoires wrote:
>> >>> Instead of relying on argc and hard coded values, use getopt framework.
>> >>>
>> >>> Signed-off-by: Benjamin Tissoires <benjamin.tissoires at gmail.com>
>> >>> ---
>> >>>  tools/evemu-play.c | 37 +++++++++++++++++++++++++++++++++----
>> >>>  1 file changed, 33 insertions(+), 4 deletions(-)
>> >>>
>> >>> diff --git a/tools/evemu-play.c b/tools/evemu-play.c
>> >>> index 8d14618..030e142 100644
>> >>> --- a/tools/evemu-play.c
>> >>> +++ b/tools/evemu-play.c
>> >>> @@ -45,10 +45,18 @@
>> >>>  #include <fcntl.h>
>> >>>  #include <string.h>
>> >>>  #include <unistd.h>
>> >>> +#include <getopt.h>
>> >>> +
>> >>> +static struct option opts[] = {
>> >>> +     { "help", no_argument, 0, 'h'},
>> >>> +};
>> >>>
>> >>>  static void usage(void)
>> >>>  {
>> >>> -     fprintf(stderr, "Usage: %s <device>\n", program_invocation_short_name);
>> >>> +     fprintf(stderr, "Usage: %s [OPTION] <device>\n", program_invocation_short_name);
>> >>> +     fprintf(stderr, "\n");
>> >>> +     fprintf(stderr, "Where OPTION is:\n");
>> >>> +     fprintf(stderr, "   -h or --help: print this message\n");
>> >>>       fprintf(stderr, "\n");
>> >>>       fprintf(stderr, "Event data is read from standard input.\n");
>> >>>  }
>> >>> @@ -56,11 +64,30 @@ static void usage(void)
>> >>>  int main(int argc, char *argv[])
>> >>>  {
>> >>>       int fd;
>> >>> -     if (argc != 2) {
>> >>> +
>> >>> +     while(1) {
>> >>> +             int option_index = 0;
>> >>> +             int c;
>> >>> +
>> >>> +             c = getopt_long(argc, argv, "h", opts, &option_index);
>> >>
>> >> don't you need GNU_SOURCE for getopt_long or is that pulled in from
>> >> elsewhere?
>> >
>> > Yes, I need it... :(
>> > I bet I missed my split between patches 2 and 3...
>>
>> Actually no. It was added in 1/3: tools: play: externalize usage() call
>
> oh right, read over that. just move it to here please.
>

Sorry, but I can not do that. In 1/3, I use
"program_invocation_short_name", instead of argv[0].
The best I can do for you is squashing 1/3 and 2/3.

Cheers,
Benjamin


More information about the Input-tools mailing list