1 /****************************************************************************
2 ** ircat.c *****************************************************************
3 ****************************************************************************
5 * ircat - prints config strings to standard output, can be used to
6 * provide remote control input to scripts
8 * The first agrument to the program is the program name, as it
9 * appears in the prog entries in .lircrc.
11 * For example if .lircrc contains:
23 * will print "next_file" (followed by newline) every time the
24 * button tv_p+ is pressed.
27 * Copyright (C) 2002 Bjorn Bringert <bjorn@bringert.net>
45 #include "lirc_client.h"
47 #define PROG_NAME "ircat"
48 #define PROG_VERSION PROG_NAME " " VERSION
51 void print_usage (char *prog_name
)
53 printf("Usage: %s [options] <prog>\n", prog_name
);
54 printf("\t -h --help\t\tdisplay usage summary\n");
55 printf("\t -v --version\t\tdisplay version\n");
56 printf("\t -c --config=<file>\tset config file\n");
59 int main(int argc
, char *argv
[])
61 struct lirc_config
*config
;
62 char *config_file
= NULL
;
66 static struct option long_options
[] = {
67 {"config", required_argument
, NULL
, 'c'},
68 {"help", no_argument
, NULL
, 'h'},
69 {"version", no_argument
, NULL
, 'v'},
72 c
= getopt_long(argc
, argv
, "chv", long_options
, NULL
);
83 printf("%s\n", PROG_VERSION
);
91 if (optind
!= argc
- 1) {
96 if (lirc_init(argv
[argc
-1], 1) == -1) exit(EXIT_FAILURE
);
98 if (lirc_readconfig(config_file
, &config
, NULL
) == 0) {
103 while (lirc_nextcode(&code
) == 0) {
104 if (code
== NULL
) continue;
105 while ((ret
= lirc_code2char(config
, code
, &c
)) == 0 &&
111 if (ret
== -1) break;
113 lirc_freeconfig(config
);