mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2025-11-03 09:01:42 -05:00
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>
This commit is contained in:
parent
439b0a3863
commit
2d46da10d8
1 changed files with 21 additions and 5 deletions
|
|
@ -39,11 +39,12 @@ enum side {
|
||||||
static int
|
static int
|
||||||
usage(int ret)
|
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, "\n");
|
||||||
fprintf(stderr, "Converts XML protocol descriptions supplied on "
|
fprintf(stderr, "Converts XML protocol descriptions supplied on "
|
||||||
"stdin to client headers,\n"
|
"stdin or input file to client\n"
|
||||||
"server headers, or protocol marshalling code.\n");
|
"headers, server headers, or protocol marshalling code.\n");
|
||||||
exit(ret);
|
exit(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1252,6 +1253,7 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct parse_context ctx;
|
struct parse_context ctx;
|
||||||
struct protocol protocol;
|
struct protocol protocol;
|
||||||
|
FILE *input = stdin;
|
||||||
int len;
|
int len;
|
||||||
void *buf;
|
void *buf;
|
||||||
enum {
|
enum {
|
||||||
|
|
@ -1260,7 +1262,7 @@ int main(int argc, char *argv[])
|
||||||
CODE,
|
CODE,
|
||||||
} mode;
|
} mode;
|
||||||
|
|
||||||
if (argc != 2)
|
if (argc != 2 && argc != 4)
|
||||||
usage(EXIT_FAILURE);
|
usage(EXIT_FAILURE);
|
||||||
else if (strcmp(argv[1], "help") == 0 || strcmp(argv[1], "--help") == 0)
|
else if (strcmp(argv[1], "help") == 0 || strcmp(argv[1], "--help") == 0)
|
||||||
usage(EXIT_SUCCESS);
|
usage(EXIT_SUCCESS);
|
||||||
|
|
@ -1273,6 +1275,20 @@ int main(int argc, char *argv[])
|
||||||
else
|
else
|
||||||
usage(EXIT_FAILURE);
|
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);
|
wl_list_init(&protocol.interface_list);
|
||||||
protocol.type_index = 0;
|
protocol.type_index = 0;
|
||||||
protocol.null_run_length = 0;
|
protocol.null_run_length = 0;
|
||||||
|
|
@ -1293,7 +1309,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
do {
|
do {
|
||||||
buf = XML_GetBuffer(ctx.parser, XML_BUFFER_SIZE);
|
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) {
|
if (len < 0) {
|
||||||
fprintf(stderr, "fread: %m\n");
|
fprintf(stderr, "fread: %m\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue