This is an automatic generated email to let you know that the following patch 
were queued at the 
http://git.linuxtv.org/cgit.cgi/v4l-utils.git tree:

Subject: ir-ctl: remove quirky -rmw command line parsing
Author:  Sean Young <s...@mess.org>
Date:    Sun May 25 14:57:26 2025 +0100

The --receive option takes an optional file name, even when specified as
a short option without an `='. So, ir-ctl -rmw saves the output to a file
called mw. You would expect the -r, -m, and -w options to be specified.

This commit removes the file argument completely. Saving to a file is
confusing and does not really have a good use-case. I've never heard of
anyone using this feature.

On top of that, I'm implementing a ir-ctl compatibility mode in cir[1],
and clap does not support short options with an optional value without
`='[2].

[1] https://gitlab.freedesktop.org/linux-media/tools/cir
[2] 
https://docs.rs/clap/latest/clap/struct.Arg.html#method.default_missing_value

Signed-off-by: Sean Young <s...@mess.org>

 utils/ir-ctl/ir-ctl.1.in |  9 +++------
 utils/ir-ctl/ir-ctl.c    | 46 ++++++++++++++--------------------------------
 2 files changed, 17 insertions(+), 38 deletions(-)

---

http://git.linuxtv.org/cgit.cgi/v4l-utils.git/commit/?id=b8c26bb16d7589b0593ebb79a423e704c96d9d1d
diff --git a/utils/ir-ctl/ir-ctl.1.in b/utils/ir-ctl/ir-ctl.1.in
index f1ed2640af02..8fe7467506c4 100644
--- a/utils/ir-ctl/ir-ctl.1.in
+++ b/utils/ir-ctl/ir-ctl.1.in
@@ -18,7 +18,7 @@ ir\-ctl \- a swiss\-knife tool to handle raw IR and to set 
lirc options
 [\fIOPTION\fR]... \fI\-\-keycode\fR [\fIkeycode to send\fR]
 .br
 .B ir\-ctl
-[\fIOPTION\fR]... \fI\-\-receive\fR [\fIsave to file\fR]
+[\fIOPTION\fR]... \fI\-\-receive\fR
 .SH DESCRIPTION
 ir\-ctl is a tool that allows one to list the features of a lirc device,
 set its options, receive raw IR, and send IR.
@@ -36,9 +36,8 @@ lirc device to control, /dev/lirc0 by default
 \fB\-f\fR, \fB\-\-features\fR
 List the features of the lirc device.
 .TP
-\fB\-r\fR, \fB\-\-receive\fR[=\fIFILE\fR]
-Receive IR and print to standard output if no file is specified, else
-save to the filename.
+\fB\-r\fR, \fB\-\-receive\fR
+Receive IR and print to standard output.
 .TP
 \fB\-s\fR, \fB\-\-send\fR=\fIFILE\fR
 Send IR in text file. It must be in the format described below. If this
@@ -238,8 +237,6 @@ To show the IR of the first button press on a remote in 
learning mode:
 .br
        \fBir\-ctl \-r \-m \-w\fR
 .PP
-Note that \fBir\-ctl \-rmw\fR would receive to a file called \fBmw\fR.
-.PP
 To restore the normal (longer distance) receiver:
 .br
        \fBir\-ctl \-n \-M\fR
diff --git a/utils/ir-ctl/ir-ctl.c b/utils/ir-ctl/ir-ctl.c
index e662651e4261..8600fbe61b74 100644
--- a/utils/ir-ctl/ir-ctl.c
+++ b/utils/ir-ctl/ir-ctl.c
@@ -100,7 +100,6 @@ struct arguments {
        struct keymap *keymap;
        struct send *send;
        bool oneshot;
-       char *savetofile;
        int wideband;
        unsigned carrier_low, carrier_high;
        unsigned timeout;
@@ -115,7 +114,7 @@ struct arguments {
 static const struct argp_option options[] = {
        { "device",     'd',    N_("DEV"),      0,      N_("lirc device to 
use") },
        { "features",   'f',    0,              0,      N_("list lirc device 
features") },
-       { "receive",    'r',    N_("FILE"),     OPTION_ARG_OPTIONAL,    
N_("receive IR to stdout or file") },
+       { "receive",    'r',    0,              0,      N_("receive IR to 
stdout") },
        { "send",       's',    N_("FILE"),     0,      N_("send IR pulse and 
space file") },
        { "scancode",   'S',    N_("SCANCODE"), 0,      N_("send IR scancode in 
protocol specified") },
        { "keycode",    'K',    N_("KEYCODE"),  0,      N_("send IR keycode 
from keymap") },
@@ -140,7 +139,7 @@ static const struct argp_option options[] = {
 
 static const char args_doc[] = N_(
        "--features\n"
-       "--receive [save to file]\n"
+       "--receive\n"
        "--send [file to send]\n"
        "--scancode [scancode to send]\n"
        "--keycode [keycode to send]\n"
@@ -602,12 +601,6 @@ static error_t parse_opt(int k, char *arg, struct 
argp_state *state)
                        argp_error(state, _("receive can not be combined with 
features or send option"));
 
                arguments->receive = true;
-               if (arg) {
-                       if (arguments->savetofile)
-                               argp_error(state, _("receive filename already 
set"));
-
-                       arguments->savetofile = arg;
-               }
                break;
        case '1':
                arguments->oneshot = true;
@@ -1126,7 +1119,6 @@ static int lirc_send(struct arguments *args, int fd, 
unsigned features, struct s
 int lirc_receive(struct arguments *args, int fd, unsigned features)
 {
        char *dev = args->device;
-       FILE *out = stdout;
        int rc = EX_IOERR;
        int mode = LIRC_MODE_MODE2;
 
@@ -1141,13 +1133,6 @@ int lirc_receive(struct arguments *args, int fd, 
unsigned features)
                return EX_IOERR;
        }
 
-       if (args->savetofile) {
-               out = fopen(args->savetofile, "w");
-               if (!out) {
-                       fprintf(stderr, _("%s: failed to open for writing: 
%m\n"), args->savetofile);
-                       return EX_CANTCREAT;
-               }
-       }
        unsigned buf[LIRCBUF_SIZE];
 
        bool keep_reading = true;
@@ -1188,20 +1173,20 @@ int lirc_receive(struct arguments *args, int fd, 
unsigned features)
                        if (args->mode2) {
                                switch (msg) {
                                case LIRC_MODE2_TIMEOUT:
-                                       fprintf(out, "timeout %u\n", val);
+                                       printf("timeout %u\n", val);
                                        leading_space = true;
                                        break;
                                case LIRC_MODE2_PULSE:
-                                       fprintf(out, "pulse %u\n", val);
+                                       printf("pulse %u\n", val);
                                        break;
                                case LIRC_MODE2_SPACE:
-                                       fprintf(out, "space %u\n", val);
+                                       printf("space %u\n", val);
                                        break;
                                case LIRC_MODE2_FREQUENCY:
-                                       fprintf(out, "carrier %u\n", val);
+                                       printf("carrier %u\n", val);
                                        break;
                                case LIRC_MODE2_OVERFLOW:
-                                       fprintf(out, "overflow\n");
+                                       printf("overflow\n");
                                        leading_space = true;
                                        break;
                                }
@@ -1209,41 +1194,38 @@ int lirc_receive(struct arguments *args, int fd, 
unsigned features)
                                switch (msg) {
                                case LIRC_MODE2_TIMEOUT:
                                        if (carrier)
-                                               fprintf(out, "-%u # carrier 
%uHz\n", val, carrier);
+                                               printf("-%u # carrier %uHz\n", 
val, carrier);
                                        else
-                                               fprintf(out, "-%u\n", val);
+                                               printf("-%u\n", val);
                                        leading_space = true;
                                        carrier = 0;
                                        break;
                                case LIRC_MODE2_PULSE:
-                                       fprintf(out, "+%u ", val);
+                                       printf("+%u ", val);
                                        break;
                                case LIRC_MODE2_SPACE:
-                                       fprintf(out, "-%u ", val);
+                                       printf("-%u ", val);
                                        break;
                                case LIRC_MODE2_FREQUENCY:
                                        carrier = val;
                                        break;
                                case LIRC_MODE2_OVERFLOW:
                                        if (carrier)
-                                               fprintf(out, "# carrier %uHz, 
overflow\n", carrier);
+                                               printf("# carrier %uHz, 
overflow\n", carrier);
                                        else
-                                               fprintf(out, "# overflow\n");
+                                               printf("# overflow\n");
                                        leading_space = true;
                                        carrier = 0;
                                        break;
                                }
                        }
 
-                       fflush(out);
+                       fflush(stdout);
                }
        }
 
        rc = 0;
 err:
-       if (args->savetofile)
-               fclose(out);
-
        return rc;
 }
 

Reply via email to