projects
/
openvswitch
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
vswitch: Generate text file documenting the vswitch schema.
[openvswitch]
/
lib
/
json.c
diff --git
a/lib/json.c
b/lib/json.c
index cdcfba598374ba9b59466f8f91764594010107f8..d162fd5143bfc9e8cd3994007655c46ccca989f8 100644
(file)
--- a/
lib/json.c
+++ b/
lib/json.c
@@
-99,6
+99,9
@@
struct json_parser {
/* Lexical analysis. */
enum json_lex_state lex_state;
struct ds buffer; /* Buffer for accumulating token text. */
/* Lexical analysis. */
enum json_lex_state lex_state;
struct ds buffer; /* Buffer for accumulating token text. */
+ int line_number;
+ int column_number;
+ int byte_number;
/* Parsing. */
enum json_parse_state parse_state;
/* Parsing. */
enum json_parse_state parse_state;
@@
-219,6
+222,14
@@
json_array_create(struct json **elements, size_t n)
return json;
}
return json;
}
+struct json *
+json_array_create_1(struct json *elem0)
+{
+ struct json **elems = xmalloc(sizeof *elems);
+ elems[0] = elem0;
+ return json_array_create(elems, 1);
+}
+
struct json *
json_array_create_2(struct json *elem0, struct json *elem1)
{
struct json *
json_array_create_2(struct json *elem0, struct json *elem1)
{
@@
-869,10
+880,18
@@
exit:
}
static bool
}
static bool
-json_lex_input(struct json_parser *p,
int
c)
+json_lex_input(struct json_parser *p,
unsigned char
c)
{
struct json_token token;
{
struct json_token token;
+ p->byte_number++;
+ if (c == '\n') {
+ p->column_number = 0;
+ p->line_number++;
+ } else {
+ p->column_number++;
+ }
+
switch (p->lex_state) {
case JSON_LEX_START:
switch (c) {
switch (p->lex_state) {
case JSON_LEX_START:
switch (c) {
@@
-1340,12
+1359,18
@@
static void
json_error(struct json_parser *p, const char *format, ...)
{
if (!p->error) {
json_error(struct json_parser *p, const char *format, ...)
{
if (!p->error) {
+ struct ds msg;
va_list args;
va_list args;
+ ds_init(&msg);
+ ds_put_format(&msg, "line %d, column %d, byte %d: ",
+ p->line_number, p->column_number, p->byte_number);
va_start(args, format);
va_start(args, format);
-
p->error = xvasprintf(
format, args);
+
ds_put_format_valist(&msg,
format, args);
va_end(args);
va_end(args);
+ p->error = ds_steal_cstr(&msg);
+
p->done = true;
}
}
p->done = true;
}
}