diff options
| author | Jussi Pakkanen <jpakkane@gmail.com> | 2015-03-02 16:08:00 +0200 |
|---|---|---|
| committer | Pekka Paalanen <pekka.paalanen@collabora.co.uk> | 2015-03-27 15:02:38 +0200 |
| commit | 2d46da10d84eb16b810e6b181e084ceff1818f38 (patch) | |
| tree | fc1048428a2309bcb32cbbf5c011aa36708538e2 /src/scanner.c | |
| parent | Spelling fixes (cosmetic) (diff) | |
| download | wayland-2d46da10d84eb16b810e6b181e084ceff1818f38.tar wayland-2d46da10d84eb16b810e6b181e084ceff1818f38.tar.gz wayland-2d46da10d84eb16b810e6b181e084ceff1818f38.tar.bz2 wayland-2d46da10d84eb16b810e6b181e084ceff1818f38.tar.lz wayland-2d46da10d84eb16b810e6b181e084ceff1818f38.tar.xz wayland-2d46da10d84eb16b810e6b181e084ceff1818f38.tar.zst wayland-2d46da10d84eb16b810e6b181e084ceff1818f38.zip | |
Add support for direct file reading and writing in wayland-scanner.
Add support for direct file reading and writing in wayland-scanner.
Signed-off-by: Jussi Pakkanen <jpakkane@gmail.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Acked-by: David Fort <rdp.effort@gmail.com>
Diffstat (limited to 'src/scanner.c')
| -rw-r--r-- | src/scanner.c | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/scanner.c b/src/scanner.c index 1f1e59a..efdc69c 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -39,11 +39,12 @@ enum side { static int usage(int ret) { - fprintf(stderr, "usage: ./scanner [client-header|server-header|code]\n"); + fprintf(stderr, "usage: ./scanner [client-header|server-header|code]" + " [input_file output_file]\n"); fprintf(stderr, "\n"); fprintf(stderr, "Converts XML protocol descriptions supplied on " - "stdin to client headers,\n" - "server headers, or protocol marshalling code.\n"); + "stdin or input file to client\n" + "headers, server headers, or protocol marshalling code.\n"); exit(ret); } @@ -1252,6 +1253,7 @@ int main(int argc, char *argv[]) { struct parse_context ctx; struct protocol protocol; + FILE *input = stdin; int len; void *buf; enum { @@ -1260,7 +1262,7 @@ int main(int argc, char *argv[]) CODE, } mode; - if (argc != 2) + if (argc != 2 && argc != 4) usage(EXIT_FAILURE); else if (strcmp(argv[1], "help") == 0 || strcmp(argv[1], "--help") == 0) usage(EXIT_SUCCESS); @@ -1273,6 +1275,20 @@ int main(int argc, char *argv[]) else usage(EXIT_FAILURE); + if (argc == 4) { + input = fopen(argv[2], "r"); + if (input == NULL) { + fprintf(stderr, "Could not open input file: %s\n", + strerror(errno)); + exit(EXIT_FAILURE); + } + if (freopen(argv[3], "w", stdout) == NULL) { + fprintf(stderr, "Could not open output file: %s\n", + strerror(errno)); + exit(EXIT_FAILURE); + } + } + wl_list_init(&protocol.interface_list); protocol.type_index = 0; protocol.null_run_length = 0; @@ -1293,7 +1309,7 @@ int main(int argc, char *argv[]) do { buf = XML_GetBuffer(ctx.parser, XML_BUFFER_SIZE); - len = fread(buf, 1, XML_BUFFER_SIZE, stdin); + len = fread(buf, 1, XML_BUFFER_SIZE, input); if (len < 0) { fprintf(stderr, "fread: %m\n"); exit(EXIT_FAILURE); |
