mu: convert command-line tools to c++
This commit is contained in:
@ -447,6 +447,7 @@ Store::in_transaction () const
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// C compat
|
||||
extern "C" {
|
||||
@ -1390,44 +1391,4 @@ mu_store_get_dirstamp (const MuStore *store, const char *dirpath, GError **err)
|
||||
return self(store)->dirstamp(dirpath);
|
||||
}
|
||||
|
||||
void
|
||||
mu_store_print_info (const MuStore *store, gboolean nocolor)
|
||||
{
|
||||
const auto green{nocolor ? "" : MU_COLOR_GREEN};
|
||||
const auto def{nocolor ? "" : MU_COLOR_DEFAULT};
|
||||
|
||||
std::cout << "database-path : "
|
||||
<< green << self(store)->database_path() << def << "\n"
|
||||
<< "messages in store : "
|
||||
<< green << self(store)->size() << def << "\n"
|
||||
<< "schema-version : "
|
||||
<< green << self(store)->schema_version() << def << "\n";
|
||||
|
||||
const auto created{mu_store_created (store)};
|
||||
const auto tstamp{localtime (&created)};
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-y2k"
|
||||
char tbuf[64];
|
||||
strftime (tbuf, sizeof(tbuf), "%c", tstamp);
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
std::cout << "created : " << green << tbuf << def << "\n"
|
||||
<< "maildir : "
|
||||
<< green << self(store)->root_maildir() << def << "\n";
|
||||
|
||||
std::cout << ("personal-addresses : ");
|
||||
|
||||
auto addrs{mu_store_personal_addresses (store)};
|
||||
if (!addrs || g_strv_length(addrs) == 0)
|
||||
std::cout << green << "<none>" << def << "\n";
|
||||
else {
|
||||
for (auto i = 0U; addrs[i]; ++i) {
|
||||
std::cout << (i != 0 ? " " : "")
|
||||
<< green << addrs[i] << def << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
g_strfreev(addrs);
|
||||
}
|
||||
}
|
||||
|
||||
@ -195,18 +195,8 @@ Sexp::Node::to_string () const
|
||||
break;
|
||||
}
|
||||
case Type::String:
|
||||
//sstrm << quote(value());
|
||||
sstrm << "\"";
|
||||
for (auto&& k: value()) {
|
||||
switch (k) {
|
||||
case '"' : sstrm << "\\\""; break;
|
||||
case '\\': sstrm << "\\\\"; break;
|
||||
default: sstrm << k;
|
||||
}
|
||||
}
|
||||
sstrm << "\"";
|
||||
sstrm << quote(value());
|
||||
break;
|
||||
|
||||
case Type::Number:
|
||||
case Type::Symbol:
|
||||
default:
|
||||
|
||||
@ -309,7 +309,7 @@ typedef gpointer XapianEnquire;
|
||||
} while (0)
|
||||
|
||||
|
||||
#define MU_G_ERROR_CODE(GE) ((GE)&&(*(GE))?(*(GE))->code:MU_ERROR)
|
||||
#define MU_G_ERROR_CODE(GE) ((GE)&&(*(GE))?(MuError)(*(GE))->code:MU_ERROR)
|
||||
|
||||
|
||||
enum _MuError {
|
||||
|
||||
@ -165,14 +165,17 @@ Mu::split (const std::string& str, const std::string& sepa)
|
||||
std::string
|
||||
Mu::quote (const std::string& str)
|
||||
{
|
||||
char *s = g_strescape (str.c_str(), NULL);
|
||||
if (!s)
|
||||
return {};
|
||||
std::string res{"\""};
|
||||
|
||||
std::string res (s);
|
||||
g_free (s);
|
||||
for (auto&& k: str) {
|
||||
switch (k) {
|
||||
case '"' : res += "\\\""; break;
|
||||
case '\\': res += "\\\\"; break;
|
||||
default: res += k;
|
||||
}
|
||||
}
|
||||
|
||||
return "\"" + res + "\"";
|
||||
return res + "\"";
|
||||
}
|
||||
|
||||
std::string
|
||||
|
||||
@ -65,7 +65,7 @@ std::vector<std::string> split (const std::string& str,
|
||||
const std::string& sepa);
|
||||
|
||||
/**
|
||||
* Quote & escape a string
|
||||
* Quote & escape a string for " and \
|
||||
*
|
||||
* @param str a string
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user