2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-31 06:15:47 +00:00

table: Add new "bare" output formatting options.

--format=list corresponds to the output format that "ovs-vsctl list" has
always used.

--bare is easier for scripts to parse.
This commit is contained in:
Ben Pfaff
2011-02-02 11:24:35 -08:00
parent 3a3eb9daef
commit c6a4125250
7 changed files with 110 additions and 11 deletions

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2009, 2010 Nicira Networks
/* Copyright (c) 2009, 2010, 2011 Nicira Networks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -625,6 +625,20 @@ ovsdb_atom_to_string(const union ovsdb_atom *atom, enum ovsdb_atomic_type type,
}
}
/* Appends 'atom' (which has the given 'type') to 'out', in a bare string
* format that cannot be parsed uniformly back into a datum but is easier for
* shell scripts, etc., to deal with. */
void
ovsdb_atom_to_bare(const union ovsdb_atom *atom, enum ovsdb_atomic_type type,
struct ds *out)
{
if (type == OVSDB_TYPE_STRING) {
ds_put_cstr(out, atom->string);
} else {
ovsdb_atom_to_string(atom, type, out);
}
}
static struct ovsdb_error *
check_string_constraints(const char *s,
const struct ovsdb_string_constraints *c)
@@ -1445,6 +1459,29 @@ ovsdb_datum_to_string(const struct ovsdb_datum *datum,
}
}
/* Appends to 'out' the 'datum' (with the given 'type') in a bare string format
* that cannot be parsed uniformly back into a datum but is easier for shell
* scripts, etc., to deal with. */
void
ovsdb_datum_to_bare(const struct ovsdb_datum *datum,
const struct ovsdb_type *type, struct ds *out)
{
bool is_map = ovsdb_type_is_map(type);
size_t i;
for (i = 0; i < datum->n; i++) {
if (i > 0) {
ds_put_cstr(out, " ");
}
ovsdb_atom_to_bare(&datum->keys[i], type->key.type, out);
if (is_map) {
ds_put_char(out, '=');
ovsdb_atom_to_bare(&datum->values[i], type->value.type, out);
}
}
}
/* Initializes 'datum' as a string-to-string map whose contents are taken from
* 'sh'. Destroys 'sh'. */
void