X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fovsdb-data.c;fp=lib%2Fovsdb-data.c;h=5b91ea0b80cc330c4873a2e3bce9bf712b07facb;hb=c6a4125250b97d41d18dbeeea13043a86e9b8f55;hp=20d333eff177f6b93633f4b81d3bd627350d7acf;hpb=3a3eb9daef012e58d6604a6fc726a5115b25945f;p=openvswitch diff --git a/lib/ovsdb-data.c b/lib/ovsdb-data.c index 20d333ef..5b91ea0b 100644 --- a/lib/ovsdb-data.c +++ b/lib/ovsdb-data.c @@ -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