clang-format: update c/cc coding style

Update all cc code using .clang-format; please do so as well for future PRs
etc.; emacs has a handy 'clang-format' mode to make this automatic.

For comparing old changes with git blame, we can disregard this one using
--ignore-rev

(see https://www.moxio.com/blog/43/ignoring-bulk-change-commits-with-git-blame )
This commit is contained in:
Dirk-Jan C. Binnema
2021-10-20 12:18:15 +03:00
parent 09935cc4b3
commit 3dd721d5a3
111 changed files with 13851 additions and 14579 deletions

View File

@ -27,32 +27,31 @@
#include <glib/gprintf.h>
#ifdef HAVE_LIBREADLINE
# if defined(HAVE_READLINE_READLINE_H)
# include <readline/readline.h>
# elif defined(HAVE_READLINE_H)
# include <readline.h>
# else /* !defined(HAVE_READLINE_H) */
extern char *readline ();
# endif /* !defined(HAVE_READLINE_H) */
char *cmdline = NULL;
#else /* !defined(HAVE_READLINE_READLINE_H) */
#if defined(HAVE_READLINE_READLINE_H)
#include <readline/readline.h>
#elif defined(HAVE_READLINE_H)
#include <readline.h>
#else /* !defined(HAVE_READLINE_H) */
extern char* readline();
#endif /* !defined(HAVE_READLINE_H) */
char* cmdline = NULL;
#else /* !defined(HAVE_READLINE_READLINE_H) */
/* no readline */
#endif /* HAVE_LIBREADLINE */
#ifdef HAVE_READLINE_HISTORY
# if defined(HAVE_READLINE_HISTORY_H)
# include <readline/history.h>
# elif defined(HAVE_HISTORY_H)
# include <history.h>
# else /* !defined(HAVE_HISTORY_H) */
extern void add_history ();
extern int write_history ();
extern int read_history ();
# endif /* defined(HAVE_READLINE_HISTORY_H) */
#if defined(HAVE_READLINE_HISTORY_H)
#include <readline/history.h>
#elif defined(HAVE_HISTORY_H)
#include <history.h>
#else /* !defined(HAVE_HISTORY_H) */
extern void add_history();
extern int write_history();
extern int read_history();
#endif /* defined(HAVE_READLINE_HISTORY_H) */
/* no history */
#endif /* HAVE_READLINE_HISTORY */
#if defined(HAVE_LIBREADLINE) && defined(HAVE_READLINE_HISTORY)
#define HAVE_READLINE (1)
#else
@ -66,66 +65,64 @@ static std::string hist_path;
static size_t max_lines{};
void
Mu::setup_readline (const std::string& histpath, size_t maxlines)
Mu::setup_readline(const std::string& histpath, size_t maxlines)
{
is_a_tty = !!::isatty(::fileno(stdout));
hist_path = histpath;
max_lines = maxlines;
is_a_tty = !!::isatty(::fileno(stdout));
hist_path = histpath;
max_lines = maxlines;
#if HAVE_READLINE
rl_bind_key('\t', rl_insert); // default (filenames) is not useful
using_history();
read_history(hist_path.c_str());
rl_bind_key('\t', rl_insert); // default (filenames) is not useful
using_history();
read_history(hist_path.c_str());
if (max_lines > 0)
stifle_history(max_lines);
if (max_lines > 0)
stifle_history(max_lines);
#endif /*HAVE_READLINE*/
}
void
Mu::shutdown_readline ()
Mu::shutdown_readline()
{
#if HAVE_READLINE
if (!is_a_tty)
return;
if (!is_a_tty)
return;
write_history(hist_path.c_str());
if (max_lines > 0)
history_truncate_file (hist_path.c_str(), max_lines);
write_history(hist_path.c_str());
if (max_lines > 0)
history_truncate_file(hist_path.c_str(), max_lines);
#endif /*HAVE_READLINE*/
}
std::string
Mu::read_line(bool& do_quit)
{
#if HAVE_READLINE
if (is_a_tty) {
auto buf = readline(";; mu% ");
if (!buf) {
do_quit = true;
return {};
}
std::string line{buf};
::free(buf);
return line;
}
if (is_a_tty) {
auto buf = readline(";; mu% ");
if (!buf) {
do_quit = true;
return {};
}
std::string line{buf};
::free(buf);
return line;
}
#endif /*HAVE_READLINE*/
std::string line;
std::cout << ";; mu> ";
if (!std::getline(std::cin, line))
do_quit = true;
std::string line;
std::cout << ";; mu> ";
if (!std::getline(std::cin, line))
do_quit = true;
return line;
return line;
}
void
Mu::save_line(const std::string& line) {
Mu::save_line(const std::string& line)
{
#if HAVE_READLINE
if (is_a_tty)
add_history(line.c_str());
if (is_a_tty)
add_history(line.c_str());
#endif /*HAVE_READLINE*/
}