Skip to content

Commit

Permalink
Tcl: Use relative names for key names
Browse files Browse the repository at this point in the history
This update addresses part of issue ElektraInitiative#51.
  • Loading branch information
sanssecours committed Jun 9, 2018
1 parent 0c27dab commit 77b96f0
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/plugins/ccode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ sudo kdb mount config.tcl user/tests/ccode tcl ccode base64
kdb set user/tests/ccode/multiline "`printf 'one\ntwo\nthree'`"
# By default the plugin uses `\n` to escape newline characters
grep 'multiline' `kdb file user/tests/ccode/multiline` | sed 's/[[:space:]]*//'
#> user/tests/ccode/multiline = one\ntwo\nthree
#> multiline = one\ntwo\nthree

# The `ccode` plugin escapes and unescapes the data. The `tcl` plugin
# returns the unescaped values.
Expand Down
1 change: 1 addition & 0 deletions src/plugins/tcl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ add_plugin (tcl
action.cpp
printer.hpp
printer.cpp
LINK_ELEKTRA elektra-ease
TEST_README)
2 changes: 1 addition & 1 deletion src/plugins/tcl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ kdb getmeta user/tests/tcl/key comment
kdb export user/tests/tcl tcl
#> {
#> {
#> user/tests/tcl/key = value
#> key = value
#> {
#> comment = Thiskeycontainsexampledata.
#> }
Expand Down
11 changes: 7 additions & 4 deletions src/plugins/tcl/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,25 @@

#include "action.hpp"

#include <kdbease.h>

using namespace std;

namespace elektra
{

using namespace kdb;

void serialise (ostream & ofs, KeySet & output)
void serialise (ostream & ofs, KeySet & output, Key & parent)
{

ofs << '{' << endl;
output.rewind ();
while (Key k = output.next ())
{
ofs << "\t{" << endl;
ofs << "\t\t" << k.getName () << " = " << k.getString () << endl;
string const name = elektraKeyGetRelativeName (*k, *parent);
ofs << "\t\t" << name << " = " << k.getString () << endl;
k.rewindMeta ();
while (const Key m = k.nextMeta ())
{
Expand All @@ -47,7 +50,7 @@ void serialise (ostream & ofs, KeySet & output)
ofs << '}' << endl;
}

void unserialise (istream & in, KeySet & input)
void unserialise (istream & in, KeySet & input, Key & parent)
{
namespace qi = boost::spirit::qi;

Expand All @@ -57,7 +60,7 @@ void unserialise (istream & in, KeySet & input)
boost::spirit::istream_iterator begin (in);
boost::spirit::istream_iterator end;

Action<boost::spirit::istream_iterator> p (input);
Action<boost::spirit::istream_iterator> p (input, parent);

if (!boost::spirit::qi::phrase_parse (begin, end, p, space))
{
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/tcl/action.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace unicode = boost::spirit::standard;
template <typename Iterator>
struct Action : qi::grammar<Iterator, unicode::space_type>
{
Action (kdb::KeySet & ks) : Action::base_type (query), p (ks)
Action (kdb::KeySet & ks, kdb::Key & parent) : Action::base_type (query), p (ks, parent)
{
query = '{' >> *(pair) > '}';
pair = '{' >> key > '=' >> val >> *('{' >> metakey > '=' >> metaval > '}') > '}';
Expand Down
6 changes: 4 additions & 2 deletions src/plugins/tcl/printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ using namespace kdb;
namespace elektra
{

Printer::Printer (KeySet & ks) : nr_keys (0), nr_meta (0), current (ks)
Printer::Printer (KeySet & ks, Key & parentKey) : nr_keys (0), nr_meta (0), current (ks), parent (parentKey)
{
}

Expand All @@ -30,7 +30,9 @@ void Printer::add_key (std::vector<char> const & c)

keyname = s;

Key k (keyname, KEY_END);
Key k (parent.getName (), KEY_END);
k.addName (keyname);

current.append (k);

// cout << "current key is: " << current.current().getName() << endl;
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/tcl/printer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ struct Printer
int nr_meta;

kdb::KeySet & current;
kdb::Key & parent;

std::string keyname;
std::string metaname;

Printer (kdb::KeySet & ks);
Printer (kdb::KeySet & ks, kdb::Key & parent);

void add_key (std::vector<char> const & c);
void add_val (std::vector<char> const & c);
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/tcl/tcl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ int elektraTclGet (Plugin *, KeySet * returned, Key * parentKey)
int ret = 0;
try
{
elektra::unserialise (in, input);
elektra::unserialise (in, input, parent);
}
catch (boost::spirit::qi::expectation_failure<boost::spirit::istream_iterator> const & e)
{
Expand Down Expand Up @@ -100,7 +100,7 @@ int elektraTclSet (Plugin *, KeySet * returned, Key * parentKey)

kdb::KeySet output (returned);

elektra::serialise (ofs, output);
elektra::serialise (ofs, output, parent);
parent.release ();
output.release ();

Expand Down
4 changes: 2 additions & 2 deletions src/plugins/tcl/tcl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
namespace elektra
{

void serialise (std::ostream & os, kdb::KeySet & output);
void unserialise (std::istream & os, kdb::KeySet & output);
void serialise (std::ostream & os, kdb::KeySet & output, kdb::Key & parent);
void unserialise (std::istream & os, kdb::KeySet & output, kdb::Key & parent);
} // namespace elektra

extern "C" {
Expand Down

0 comments on commit 77b96f0

Please sign in to comment.