refactoring: apply clang-format rules

This commit is contained in:
Evgeniy A. Dushistov
2017-08-09 07:46:27 +03:00
parent d0c0a0837f
commit 8f16ceae59
14 changed files with 2587 additions and 2537 deletions

View File

@@ -19,14 +19,14 @@
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#include "config.h"
#endif
#include <cstdio>
#include <cstdlib>
#ifdef WITH_READLINE
# include <readline/readline.h>
# include <readline/history.h>
#include <readline/history.h>
#include <readline/readline.h>
#endif
#include <glib.h>
@@ -34,73 +34,82 @@
#include "readline.hpp"
bool stdio_getline(FILE *in, std::string & str)
bool stdio_getline(FILE *in, std::string &str)
{
assert(in != nullptr);
str.clear();
int ch;
while ((ch=fgetc(in)) != EOF && ch != '\n')
while ((ch = fgetc(in)) != EOF && ch != '\n')
str += ch;
return EOF != ch;
}
#ifndef WITH_READLINE
namespace {
class dummy_readline : public IReadLine {
public:
bool read(const std::string &banner, std::string &line) override {
printf("%s", banner.c_str());
return stdio_getline(stdin, line);
}
};
namespace
{
class dummy_readline : public IReadLine
{
public:
bool read(const std::string &banner, std::string &line) override
{
printf("%s", banner.c_str());
return stdio_getline(stdin, line);
}
};
}
#else
namespace {
class real_readline : public IReadLine {
namespace
{
class real_readline : public IReadLine
{
public:
real_readline() {
rl_readline_name = "sdcv";
using_history();
const std::string histname = std::string(g_get_home_dir()) + G_DIR_SEPARATOR + ".sdcv_history";
read_history(histname.c_str());
}
public:
real_readline()
{
rl_readline_name = "sdcv";
using_history();
const std::string histname = std::string(g_get_home_dir()) + G_DIR_SEPARATOR + ".sdcv_history";
read_history(histname.c_str());
}
~real_readline() {
const std::string histname = std::string(g_get_home_dir()) + G_DIR_SEPARATOR + ".sdcv_history";
write_history(histname.c_str());
const gchar *hist_size_str=g_getenv("SDCV_HISTSIZE");
int hist_size;
if (!hist_size_str || sscanf(hist_size_str, "%d", &hist_size)<1)
hist_size = 2000;
history_truncate_file(histname.c_str(), hist_size);
}
~real_readline()
{
const std::string histname = std::string(g_get_home_dir()) + G_DIR_SEPARATOR + ".sdcv_history";
write_history(histname.c_str());
const gchar *hist_size_str = g_getenv("SDCV_HISTSIZE");
int hist_size;
if (!hist_size_str || sscanf(hist_size_str, "%d", &hist_size) < 1)
hist_size = 2000;
history_truncate_file(histname.c_str(), hist_size);
}
bool read(const std::string &banner, std::string& line) override {
char *phrase = nullptr;
phrase = readline(banner.c_str());
if (phrase) {
line = phrase;
free(phrase);
return true;
}
return false;
bool read(const std::string &banner, std::string &line) override
{
char *phrase = nullptr;
phrase = readline(banner.c_str());
if (phrase) {
line = phrase;
free(phrase);
return true;
}
return false;
}
void add_to_history(const std::string& phrase) override {
add_history(phrase.c_str());
}
};
void add_to_history(const std::string &phrase) override
{
add_history(phrase.c_str());
}
};
}
#endif//WITH_READLINE
#endif //WITH_READLINE
IReadLine *create_readline_object()
{
#ifdef WITH_READLINE
return new real_readline;
return new real_readline;
#else
return new dummy_readline;
return new dummy_readline;
#endif
}