mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2025-11-03 09:01:42 -05:00
Print line numbers in scanner errors
This commit is contained in:
parent
06c2ebf6ec
commit
a0010d8f82
1 changed files with 33 additions and 38 deletions
|
|
@ -112,6 +112,8 @@ struct entry {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct parse_context {
|
struct parse_context {
|
||||||
|
const char *filename;
|
||||||
|
XML_Parser parser;
|
||||||
struct protocol *protocol;
|
struct protocol *protocol;
|
||||||
struct interface *interface;
|
struct interface *interface;
|
||||||
struct message *message;
|
struct message *message;
|
||||||
|
|
@ -132,6 +134,14 @@ uppercase_dup(const char *src)
|
||||||
return u;
|
return u;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
fail(struct parse_context *ctx, const char *msg)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s:%ld: %s\n",
|
||||||
|
ctx->filename, XML_GetCurrentLineNumber(ctx->parser), msg);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
start_element(void *data, const char *element_name, const char **atts)
|
start_element(void *data, const char *element_name, const char **atts)
|
||||||
{
|
{
|
||||||
|
|
@ -163,23 +173,17 @@ start_element(void *data, const char *element_name, const char **atts)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(element_name, "protocol") == 0) {
|
if (strcmp(element_name, "protocol") == 0) {
|
||||||
if (name == NULL) {
|
if (name == NULL)
|
||||||
fprintf(stderr, "no protocol name given\n");
|
fail(ctx, "no protocol name given");
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx->protocol->name = strdup(name);
|
ctx->protocol->name = strdup(name);
|
||||||
ctx->protocol->uppercase_name = uppercase_dup(name);
|
ctx->protocol->uppercase_name = uppercase_dup(name);
|
||||||
} else if (strcmp(element_name, "interface") == 0) {
|
} else if (strcmp(element_name, "interface") == 0) {
|
||||||
if (name == NULL) {
|
if (name == NULL)
|
||||||
fprintf(stderr, "no interface name given\n");
|
fail(ctx, "no interface name given");
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (version == 0) {
|
if (version == 0)
|
||||||
fprintf(stderr, "no interface version given\n");
|
fail(ctx, "no interface version given");
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
interface = malloc(sizeof *interface);
|
interface = malloc(sizeof *interface);
|
||||||
interface->name = strdup(name);
|
interface->name = strdup(name);
|
||||||
|
|
@ -193,10 +197,8 @@ start_element(void *data, const char *element_name, const char **atts)
|
||||||
ctx->interface = interface;
|
ctx->interface = interface;
|
||||||
} else if (strcmp(element_name, "request") == 0 ||
|
} else if (strcmp(element_name, "request") == 0 ||
|
||||||
strcmp(element_name, "event") == 0) {
|
strcmp(element_name, "event") == 0) {
|
||||||
if (name == NULL) {
|
if (name == NULL)
|
||||||
fprintf(stderr, "no request name given\n");
|
fail(ctx, "no request name given");
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
message = malloc(sizeof *message);
|
message = malloc(sizeof *message);
|
||||||
message->name = strdup(name);
|
message->name = strdup(name);
|
||||||
|
|
@ -231,30 +233,23 @@ start_element(void *data, const char *element_name, const char **atts)
|
||||||
else if (strcmp(type, "fd") == 0)
|
else if (strcmp(type, "fd") == 0)
|
||||||
arg->type = FD;
|
arg->type = FD;
|
||||||
else if (strcmp(type, "new_id") == 0) {
|
else if (strcmp(type, "new_id") == 0) {
|
||||||
if (interface_name == NULL) {
|
if (interface_name == NULL)
|
||||||
fprintf(stderr, "no interface name given\n");
|
fail(ctx, "no interface name given");
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
arg->type = NEW_ID;
|
arg->type = NEW_ID;
|
||||||
arg->interface_name = strdup(interface_name);
|
arg->interface_name = strdup(interface_name);
|
||||||
} else if (strcmp(type, "object") == 0) {
|
} else if (strcmp(type, "object") == 0) {
|
||||||
if (interface_name == NULL) {
|
if (interface_name == NULL)
|
||||||
fprintf(stderr, "no interface name given\n");
|
fail(ctx, "no interface name given");
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
arg->type = OBJECT;
|
arg->type = OBJECT;
|
||||||
arg->interface_name = strdup(interface_name);
|
arg->interface_name = strdup(interface_name);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "unknown type: %s\n", type);
|
fail(ctx, "unknown type");
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wl_list_insert(ctx->message->arg_list.prev, &arg->link);
|
wl_list_insert(ctx->message->arg_list.prev, &arg->link);
|
||||||
} else if (strcmp(element_name, "enum") == 0) {
|
} else if (strcmp(element_name, "enum") == 0) {
|
||||||
if (name == NULL) {
|
if (name == NULL)
|
||||||
fprintf(stderr, "no enum name given\n");
|
fail(ctx, "no enum name given");
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
enumeration = malloc(sizeof *enumeration);
|
enumeration = malloc(sizeof *enumeration);
|
||||||
enumeration->name = strdup(name);
|
enumeration->name = strdup(name);
|
||||||
|
|
@ -687,7 +682,6 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct parse_context ctx;
|
struct parse_context ctx;
|
||||||
struct protocol protocol;
|
struct protocol protocol;
|
||||||
XML_Parser parser;
|
|
||||||
int len;
|
int len;
|
||||||
void *buf;
|
void *buf;
|
||||||
|
|
||||||
|
|
@ -697,26 +691,27 @@ int main(int argc, char *argv[])
|
||||||
wl_list_init(&protocol.interface_list);
|
wl_list_init(&protocol.interface_list);
|
||||||
ctx.protocol = &protocol;
|
ctx.protocol = &protocol;
|
||||||
|
|
||||||
parser = XML_ParserCreate(NULL);
|
ctx.filename = "<stdin>";
|
||||||
XML_SetUserData(parser, &ctx);
|
ctx.parser = XML_ParserCreate(NULL);
|
||||||
if (parser == NULL) {
|
XML_SetUserData(ctx.parser, &ctx);
|
||||||
|
if (ctx.parser == NULL) {
|
||||||
fprintf(stderr, "failed to create parser\n");
|
fprintf(stderr, "failed to create parser\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
XML_SetElementHandler(parser, start_element, NULL);
|
XML_SetElementHandler(ctx.parser, start_element, NULL);
|
||||||
do {
|
do {
|
||||||
buf = XML_GetBuffer(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, stdin);
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
fprintf(stderr, "fread: %s\n", strerror(errno));
|
fprintf(stderr, "fread: %s\n", strerror(errno));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
XML_ParseBuffer(parser, len, len == 0);
|
XML_ParseBuffer(ctx.parser, len, len == 0);
|
||||||
|
|
||||||
} while (len > 0);
|
} while (len > 0);
|
||||||
|
|
||||||
XML_ParserFree(parser);
|
XML_ParserFree(ctx.parser);
|
||||||
|
|
||||||
if (strcmp(argv[1], "client-header") == 0) {
|
if (strcmp(argv[1], "client-header") == 0) {
|
||||||
emit_header(&protocol, 0);
|
emit_header(&protocol, 0);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue