mirror of
https://github.com/Dushistov/sdcv.git
synced 2025-12-16 09:51:56 +00:00
refactoring: apply clang-format rules
This commit is contained in:
73
src/sdcv.cpp
73
src/sdcv.cpp
@@ -22,16 +22,16 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include <cerrno>
|
||||
#include <clocale>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib/gi18n.h>
|
||||
@@ -56,7 +56,7 @@ static void free_str_array(gchar **arr)
|
||||
}
|
||||
namespace glib
|
||||
{
|
||||
using StrArr = ResourceWrapper<gchar *, gchar *, free_str_array>;
|
||||
using StrArr = ResourceWrapper<gchar *, gchar *, free_str_array>;
|
||||
}
|
||||
|
||||
static void list_dicts(const std::list<std::string> &dicts_dir_list, bool use_json);
|
||||
@@ -131,12 +131,12 @@ int main(int argc, char *argv[]) try {
|
||||
const gchar *stardict_data_dir = g_getenv("STARDICT_DATA_DIR");
|
||||
std::string data_dir;
|
||||
if (!opt_data_dir) {
|
||||
if (!only_data_dir) {
|
||||
if (stardict_data_dir)
|
||||
data_dir = stardict_data_dir;
|
||||
else
|
||||
data_dir = "/usr/share/stardict/dic";
|
||||
}
|
||||
if (!only_data_dir) {
|
||||
if (stardict_data_dir)
|
||||
data_dir = stardict_data_dir;
|
||||
else
|
||||
data_dir = "/usr/share/stardict/dic";
|
||||
}
|
||||
} else {
|
||||
data_dir = get_impl(opt_data_dir);
|
||||
}
|
||||
@@ -146,8 +146,8 @@ int main(int argc, char *argv[]) try {
|
||||
homedir = g_get_home_dir();
|
||||
|
||||
std::list<std::string> dicts_dir_list;
|
||||
if(!only_data_dir)
|
||||
dicts_dir_list.push_back(std::string(homedir) + G_DIR_SEPARATOR + ".stardict" + G_DIR_SEPARATOR + "dic");
|
||||
if (!only_data_dir)
|
||||
dicts_dir_list.push_back(std::string(homedir) + G_DIR_SEPARATOR + ".stardict" + G_DIR_SEPARATOR + "dic");
|
||||
dicts_dir_list.push_back(data_dir);
|
||||
if (show_list_dicts) {
|
||||
list_dicts(dicts_dir_list, json_output);
|
||||
@@ -215,7 +215,7 @@ int main(int argc, char *argv[]) try {
|
||||
|
||||
std::string phrase;
|
||||
while (io->read(_("Enter word or phrase: "), phrase)) {
|
||||
if (!lib.process_phrase(phrase.c_str(), *io))
|
||||
if (!lib.process_phrase(phrase.c_str(), *io))
|
||||
return EXIT_FAILURE;
|
||||
phrase.clear();
|
||||
}
|
||||
@@ -232,30 +232,29 @@ int main(int argc, char *argv[]) try {
|
||||
|
||||
static void list_dicts(const std::list<std::string> &dicts_dir_list, bool use_json)
|
||||
{
|
||||
bool first_entry = true;
|
||||
if(!use_json)
|
||||
printf(_("Dictionary's name Word count\n"));
|
||||
else
|
||||
fputc('[', stdout);
|
||||
std::list<std::string> order_list, disable_list;
|
||||
for_each_file(dicts_dir_list, ".ifo", order_list,
|
||||
disable_list, [use_json, &first_entry](const std::string &filename, bool) -> void {
|
||||
DictInfo dict_info;
|
||||
if (dict_info.load_from_ifo_file(filename, false)) {
|
||||
const std::string bookname = utf8_to_locale_ign_err(dict_info.bookname);
|
||||
if(use_json) {
|
||||
if(first_entry) {
|
||||
first_entry=false;
|
||||
} else {
|
||||
fputc(',', stdout); // comma between entries
|
||||
bool first_entry = true;
|
||||
if (!use_json)
|
||||
printf(_("Dictionary's name Word count\n"));
|
||||
else
|
||||
fputc('[', stdout);
|
||||
std::list<std::string> order_list, disable_list;
|
||||
for_each_file(dicts_dir_list, ".ifo", order_list,
|
||||
disable_list, [use_json, &first_entry](const std::string &filename, bool) -> void {
|
||||
DictInfo dict_info;
|
||||
if (dict_info.load_from_ifo_file(filename, false)) {
|
||||
const std::string bookname = utf8_to_locale_ign_err(dict_info.bookname);
|
||||
if (use_json) {
|
||||
if (first_entry) {
|
||||
first_entry = false;
|
||||
} else {
|
||||
fputc(',', stdout); // comma between entries
|
||||
}
|
||||
printf("{\"name\": \"%s\", \"wordcount\": \"%d\"}", json_escape_string(bookname).c_str(), dict_info.wordcount);
|
||||
} else {
|
||||
printf("%s %d\n", bookname.c_str(), dict_info.wordcount);
|
||||
}
|
||||
}
|
||||
printf("{\"name\": \"%s\", \"wordcount\": \"%d\"}", json_escape_string(bookname).c_str(), dict_info.wordcount);
|
||||
} else {
|
||||
printf("%s %d\n", bookname.c_str(), dict_info.wordcount);
|
||||
}
|
||||
}
|
||||
});
|
||||
if(use_json)
|
||||
fputs("]\n", stdout);
|
||||
|
||||
});
|
||||
if (use_json)
|
||||
fputs("]\n", stdout);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user