utils: get rid of mu-util.[ch]

It was getting old...
Remove the unused parts, refactor the few parts still in use.
This commit is contained in:
Dirk-Jan C. Binnema
2023-01-14 17:11:36 +02:00
parent a86ed97f66
commit 6979a66630
23 changed files with 695 additions and 1302 deletions

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2022 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2022-2023 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the
@ -27,7 +27,6 @@
#include <utils/mu-utils.hh>
#include <utils/mu-regex.hh>
#include <utils/mu-util.h>
#include <utils/mu-option.hh>
using namespace Mu;
@ -113,14 +112,14 @@ output_plain(ItemType itype, OptContact contact, const Options& opts)
const auto col2{opts.nocolor ? "" : MU_COLOR_GREEN};
const auto coldef{opts.nocolor ? "" : MU_COLOR_DEFAULT};
mu_util_print_encoded("%s%s%s%s%s%s%s\n",
col1,
contact->name.c_str(),
coldef,
contact->name.empty() ? "" : " ",
col2,
contact->email.c_str(),
coldef);
print_encoded("%s%s%s%s%s%s%s\n",
col1,
contact->name.c_str(),
coldef,
contact->name.empty() ? "" : " ",
col2,
contact->email.c_str(),
coldef);
}
static void
@ -130,8 +129,8 @@ output_mutt_alias(ItemType itype, OptContact contact, const Options& opts)
return;
const auto nick{guess_nick(*contact)};
mu_util_print_encoded("alias %s %s <%s>\n", nick.c_str(),
contact->name.c_str(), contact->email.c_str());
print_encoded("alias %s %s <%s>\n", nick.c_str(),
contact->name.c_str(), contact->email.c_str());
}
static void
@ -143,9 +142,9 @@ output_mutt_address_book(ItemType itype, OptContact contact, const Options& opts
if (!contact)
return;
mu_util_print_encoded("%s\t%s\t\n",
contact->email.c_str(),
contact->name.c_str());
print_encoded("%s\t%s\t\n",
contact->email.c_str(),
contact->name.c_str());
}
static void
@ -156,10 +155,10 @@ output_wanderlust(ItemType itype, OptContact contact, const Options& opts)
auto nick=guess_nick(*contact);
mu_util_print_encoded("%s \"%s\" \"%s\"\n",
contact->email.c_str(),
nick.c_str(),
contact->name.c_str());
print_encoded("%s \"%s\" \"%s\"\n",
contact->email.c_str(),
nick.c_str(),
contact->name.c_str());
}
static void
@ -168,9 +167,9 @@ output_org_contact(ItemType itype, OptContact contact, const Options& opts)
if (!contact || contact->name.empty())
return;
mu_util_print_encoded("* %s\n:PROPERTIES:\n:EMAIL: %s\n:END:\n\n",
contact->name.c_str(),
contact->email.c_str());
print_encoded("* %s\n:PROPERTIES:\n:EMAIL: %s\n:END:\n\n",
contact->name.c_str(),
contact->email.c_str());
}
static void
@ -201,9 +200,9 @@ output_csv(ItemType itype, OptContact contact, const Options& opts)
if (!contact)
return;
mu_util_print_encoded("%s,%s\n",
contact->name.empty() ? "" : Mu::quote(contact->name).c_str(),
Mu::quote(contact->email).c_str());
print_encoded("%s,%s\n",
contact->name.empty() ? "" : Mu::quote(contact->name).c_str(),
Mu::quote(contact->email).c_str());
}
static void
@ -216,7 +215,7 @@ output_json(ItemType itype, OptContact contact, const Options& opts)
g_print (" {\n");
const std::string name = contact->name.empty() ? "null" : Mu::quote(contact->name);
mu_util_print_encoded(
print_encoded(
" \"email\" : \"%s\",\n"
" \"name\" : %s,\n"
" \"display\" : %s,\n"

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2010-2022 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2010-2023 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the
@ -19,8 +19,8 @@
#include "config.h"
#include "mu-cmd.hh"
#include "utils/mu-util.h"
#include "utils/mu-utils.hh"
#include "utils/mu-utils-file.hh"
#include "utils/mu-regex.hh"
#include <message/mu-message.hh>
@ -38,16 +38,10 @@ save_part(const Message::Part& part, size_t idx, const Options& opts)
if (auto&& res{part.to_file(path, opts.extract.overwrite)}; !res)
return Err(res.error());
if (opts.extract.play) {
GError *err{};
if (auto res{mu_util_play(path.c_str(), &err)};
res != MU_OK)
return Err(Error::Code::Play, &err, "playing '%s' failed",
path.c_str());
}
return Ok();
else if (opts.extract.play)
return play(path);
else
return Ok();
}
static Result<void>
@ -113,19 +107,18 @@ show_part(const MessagePart& part, size_t index, bool color)
/* filename */
color_maybe(MU_COLOR_GREEN);
const auto fname{part.raw_filename()};
mu_util_fputs_encoded(fname ? fname->c_str() : "<none>", stdout);
mu_util_fputs_encoded(" ", stdout);
fputs_encoded(fname.value_or("<none>"), stdout);
fputs_encoded(" ", stdout);
/* content-type */
color_maybe(MU_COLOR_BLUE);
const auto ctype{part.mime_type()};
mu_util_fputs_encoded(ctype ? ctype->c_str() : "<none>", stdout);
fputs_encoded(ctype.value_or("<none>"), stdout);
/* /\* disposition *\/ */
color_maybe(MU_COLOR_MAGENTA);
mu_util_print_encoded(" [%s]", part.is_attachment() ?
"attachment" : "inline");
print_encoded(" [%s]", part.is_attachment() ?
"attachment" : "inline");
/* size */
if (part.size() > 0) {
color_maybe(MU_COLOR_CYAN);
@ -159,7 +152,7 @@ Mu::mu_cmd_extract(const Options& opts)
opts.extract.filename_rx.empty())
return show_parts(opts.extract.message, opts); /* show, don't save */
if (!mu_util_check_dir(opts.extract.targetdir.c_str(), FALSE, TRUE))
if (!check_dir(opts.extract.targetdir, false/*!readable*/, true/*writeable*/))
return Err(Error::Code::File,
"target '%s' is not a writable directory",
opts.extract.targetdir.c_str());

View File

@ -36,7 +36,6 @@
#include "message/mu-message.hh"
#include "utils/mu-option.hh"
#include "utils/mu-util.h"
#include "mu-cmd.hh"
#include "utils/mu-utils.hh"
@ -258,12 +257,10 @@ print_summary(const Message& msg, const Options& opts)
if (!body)
return;
const auto summ{to_string_opt_gchar(
mu_str_summarize(body->c_str(),
opts.find.summary_len.value_or(0)))};
const auto summ{summarize(body->c_str(), opts.find.summary_len.value_or(0))};
g_print("Summary: ");
mu_util_fputs_encoded(summ ? summ->c_str() : "<none>", stdout);
fputs_encoded(summ, stdout);
g_print("\n");
}
@ -311,8 +308,8 @@ output_plain_fields(const Message& msg, const std::string& fields,
else {
ansi_color_maybe(field_opt->id, color);
nonempty += mu_util_fputs_encoded(
display_field(msg, field_opt->id).c_str(), stdout);
nonempty += fputs_encoded(
display_field(msg, field_opt->id), stdout);
ansi_reset_maybe(field_opt->id, color);
}
}

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2008-2022 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2008-2023 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the
@ -33,8 +33,6 @@
#include "index/mu-indexer.hh"
#include "mu-store.hh"
#include "utils/mu-util.h"
using namespace Mu;
static std::atomic<bool> caught_signal;

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2010-2022 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2010-2023 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the
@ -35,8 +35,6 @@
#include "message/mu-message.hh"
#include "message/mu-mime-object.hh"
#include "utils/mu-util.h"
#include "utils/mu-error.hh"
#include "utils/mu-utils.hh"
#include "message/mu-message.hh"
@ -86,12 +84,12 @@ print_field(const std::string& field, const std::string& val, bool color)
return;
color_maybe(MU_COLOR_MAGENTA);
mu_util_fputs_encoded(field.c_str(), stdout);
fputs_encoded(field, stdout);
color_maybe(MU_COLOR_DEFAULT);
fputs(": ", stdout);
color_maybe(MU_COLOR_GREEN);
mu_util_fputs_encoded(val.c_str(), stdout);
fputs_encoded(val, stdout);
color_maybe(MU_COLOR_DEFAULT);
fputs("\n", stdout);
@ -120,12 +118,10 @@ body_or_summary(const Message& message, const Options& opts)
}
if (opts.view.summary_len) {
gchar* summ;
summ = mu_str_summarize(body->c_str(), *opts.view.summary_len);
const auto summ{summarize(body->c_str(), *opts.view.summary_len)};
print_field("Summary", summ, color);
g_free(summ);
} else {
mu_util_print_encoded("%s", body->c_str());
print_encoded("%s", body->c_str());
if (!g_str_has_suffix(body->c_str(), "\n"))
g_print("\n");
}

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2022 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2022-2023 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the
@ -26,6 +26,8 @@
#include <utils/mu-option.hh>
#include <utils/mu-result.hh>
#include <utils/mu-utils.hh>
#include <utils/mu-utils-file.hh>
#include <message/mu-fields.hh>
#include <mu-script.hh>
#include <ctime>