#define XML_BUFFER_SIZE 4096
+struct location {
+ const char *filename;
+ int line_number;
+};
+
struct description {
char *summary;
char *text;
};
struct parse_context {
- const char *filename;
+ struct location loc;
XML_Parser parser;
struct protocol *protocol;
struct interface *interface;
}
static void
-fail(struct parse_context *ctx, const char *msg)
+fail(struct location *loc, const char *msg)
{
- fprintf(stderr, "%s:%ld: %s\n",
- ctx->filename, XML_GetCurrentLineNumber(ctx->parser), msg);
+ fprintf(stderr, "%s:%d: error: %s\n",
+ loc->filename, loc->line_number, msg);
exit(EXIT_FAILURE);
}
char *end;
int i, version;
+ ctx->loc.line_number = XML_GetCurrentLineNumber(ctx->parser);
name = NULL;
type = NULL;
version = 0;
ctx->character_data_length = 0;
if (strcmp(element_name, "protocol") == 0) {
if (name == NULL)
- fail(ctx, "no protocol name given");
+ fail(&ctx->loc, "no protocol name given");
ctx->protocol->name = xstrdup(name);
ctx->protocol->uppercase_name = uppercase_dup(name);
} else if (strcmp(element_name, "interface") == 0) {
if (name == NULL)
- fail(ctx, "no interface name given");
+ fail(&ctx->loc, "no interface name given");
if (version == 0)
- fail(ctx, "no interface version given");
+ fail(&ctx->loc, "no interface version given");
interface = xmalloc(sizeof *interface);
interface->name = xstrdup(name);
} else if (strcmp(element_name, "request") == 0 ||
strcmp(element_name, "event") == 0) {
if (name == NULL)
- fail(ctx, "no request name given");
+ fail(&ctx->loc, "no request name given");
message = xmalloc(sizeof *message);
message->name = xstrdup(name);
if (since != NULL) {
version = strtol(since, &end, 0);
if (errno == EINVAL || end == since || *end != '\0')
- fail(ctx, "invalid integer\n");
+ fail(&ctx->loc, "invalid integer\n");
if (version < ctx->interface->since)
- fail(ctx, "since version not increasing\n");
+ fail(&ctx->loc, "since version not increasing\n");
ctx->interface->since = version;
}
message->since = ctx->interface->since;
if (strcmp(name, "destroy") == 0 && !message->destructor)
- fail(ctx, "destroy request should be destructor type");
+ fail(&ctx->loc, "destroy request should be destructor type");
ctx->message = message;
} else if (strcmp(element_name, "arg") == 0) {
if (name == NULL)
- fail(ctx, "no argument name given");
+ fail(&ctx->loc, "no argument name given");
arg = xmalloc(sizeof *arg);
arg->name = xstrdup(name);
} else if (strcmp(type, "object") == 0) {
arg->type = OBJECT;
} else {
- fail(ctx, "unknown type");
+ fail(&ctx->loc, "unknown type");
}
switch (arg->type) {
break;
default:
if (interface_name != NULL)
- fail(ctx, "interface not allowed");
+ fail(&ctx->loc, "interface not allowed");
break;
}
else if (strcmp(allow_null, "true") == 0)
arg->nullable = 1;
else
- fail(ctx, "invalid value for allow-null attribute");
+ fail(&ctx->loc, "invalid value for allow-null attribute");
if (allow_null != NULL && !is_nullable_type(arg))
- fail(ctx, "allow-null is only valid for objects, strings, and arrays");
+ fail(&ctx->loc, "allow-null is only valid for objects, strings, and arrays");
arg->summary = NULL;
if (summary)
ctx->message->arg_count++;
} else if (strcmp(element_name, "enum") == 0) {
if (name == NULL)
- fail(ctx, "no enum name given");
+ fail(&ctx->loc, "no enum name given");
enumeration = xmalloc(sizeof *enumeration);
enumeration->name = xstrdup(name);
ctx->enumeration = enumeration;
} else if (strcmp(element_name, "entry") == 0) {
if (name == NULL)
- fail(ctx, "no entry name given");
+ fail(&ctx->loc, "no entry name given");
entry = xmalloc(sizeof *entry);
entry->name = xstrdup(name);
&entry->link);
} else if (strcmp(element_name, "description") == 0) {
if (summary == NULL)
- fail(ctx, "description without summary");
+ fail(&ctx->loc, "description without summary");
description = xmalloc(sizeof *description);
description->summary = xstrdup(summary);
memset(&ctx, 0, sizeof ctx);
ctx.protocol = &protocol;
- ctx.filename = "<stdin>";
+ ctx.loc.filename = "<stdin>";
ctx.parser = XML_ParserCreate(NULL);
XML_SetUserData(ctx.parser, &ctx);
if (ctx.parser == NULL) {