diff --git a/src/utils/conftree.cpp b/src/utils/conftree.cpp index 16babf80..236ea2c0 100755 --- a/src/utils/conftree.cpp +++ b/src/utils/conftree.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid [] = "@(#$Id: conftree.cpp,v 1.6 2006-03-22 14:25:46 dockes Exp $ (C) 2003 J.F.Dockes"; +static char rcsid [] = "@(#$Id: conftree.cpp,v 1.7 2006-11-08 06:56:41 dockes Exp $ (C) 2003 J.F.Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -126,6 +126,13 @@ void ConfSimple::parseinput(istream &input) } +ConfSimple::ConfSimple(int readonly, bool tildexp) +{ + data = 0; + dotildexpand = tildexp; + status = readonly ? STATUS_RO : STATUS_RW; +} + ConfSimple::ConfSimple(string *d, int readonly, bool tildexp) { data = d; @@ -265,8 +272,8 @@ int ConfSimple::set(const std::string &nm, const std::string &value, } return 1; } else { - // ?? - return 0; + // No backing store, no writing + return 1; } } @@ -298,8 +305,7 @@ int ConfSimple::erase(const string &nm, const string &sk) } return 1; } else { - // ?? - return 0; + return 1; } } @@ -422,10 +428,8 @@ const char *longvalue = "0123456789012345678901234567890123456789012345678901234567890123456789FIN" ; -void stringtest() +void memtest(ConfSimple &c) { - string s; - ConfSimple c(&s); cout << "Initial:" << endl; c.list(); if (c.set("nom", "avec nl \n 2eme ligne", "")) { @@ -456,6 +460,7 @@ static char usage [] = "[-q] nm sect : subsection test: look for nm in 'sect' which can be ''\n" "[-d] nm sect : delete nm in 'sect' which can be ''\n" "[-S] : string io test. No filename in this case\n" + "[-V] : volatile config test. No filename in this case\n" ; void Usage() { @@ -469,6 +474,7 @@ static int op_flags; #define OPT_s 0x8 #define OPT_S 0x10 #define OPT_d 0x20 +#define OPT_V 0x40 int main(int argc, char **argv) { @@ -485,9 +491,6 @@ int main(int argc, char **argv) Usage(); while (**argv) switch (*(*argv)++) { - case 'w': op_flags |= OPT_w; break; - case 's': op_flags |= OPT_s; break; - case 'S': op_flags |= OPT_S; break; case 'd': op_flags |= OPT_d; if (argc < 3) @@ -502,6 +505,10 @@ int main(int argc, char **argv) nm = *(++argv);argc--; sub = *(++argv);argc--; goto b1; + case 's': op_flags |= OPT_s; break; + case 'S': op_flags |= OPT_S; break; + case 'V': op_flags |= OPT_S; break; + case 'w': op_flags |= OPT_w; break; default: Usage(); break; } @@ -511,7 +518,15 @@ int main(int argc, char **argv) if ((op_flags & OPT_S)) { if (argc != 0) Usage(); - stringtest(); + string s; + ConfSimple c(&s); + memtest(c); + } else if ((op_flags & OPT_V)) { + if (argc != 0) + Usage(); + string s; + ConfSimple c; + memtest(c); } else { if (argc < 1) Usage(); diff --git a/src/utils/conftree.h b/src/utils/conftree.h index ac41a945..90608ae5 100755 --- a/src/utils/conftree.h +++ b/src/utils/conftree.h @@ -27,10 +27,16 @@ * * Whitespace around name and value is insignificant. * - * Values can be queried for, or set. (the file is then rewritten). - * The names are case-sensitive but don't count on it either. + * The names are case-sensitive but don't count on it. + * + * Values can be queried for, or set. * Any line without a '=' is discarded when rewriting the file. - * All 'set' calls currently cause an immediate file rewrite. + * A configuration object can be created empty or by reading from a file or + * a string. + * All 'set' calls cause an immediate rewrite of the backing object if any + * (file or string) + * + * Config objects can be stacked (overlayed). */ #include @@ -72,6 +78,13 @@ class ConfSimple { */ ConfSimple(string *data, int readonly = 0, bool tildexp = false); + /** + * Build an empty object. This will be memory only, with no backing store. + * @param readonly if true open read only, else rw + * @param tildexp try tilde (home dir) expansion for subsection names + */ + ConfSimple(int readonly = 0, bool tildexp = false); + virtual ~ConfSimple() {}; /**