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:
@ -31,97 +31,100 @@
|
||||
#include "mu-script.hh"
|
||||
#include "mu-runtime.hh"
|
||||
|
||||
|
||||
#include "utils/mu-util.h"
|
||||
#include "utils/mu-str.h"
|
||||
|
||||
|
||||
#define MU_GUILE_EXT ".scm"
|
||||
#define MU_GUILE_DESCR_PREFIX ";; INFO: "
|
||||
|
||||
#define COL(C) ((color)?C:"")
|
||||
#define COL(C) ((color) ? C : "")
|
||||
|
||||
using namespace Mu;
|
||||
|
||||
static void
|
||||
print_script (const char *name, const char *oneline, const char *descr,
|
||||
gboolean color, gboolean verbose)
|
||||
print_script(const char* name,
|
||||
const char* oneline,
|
||||
const char* descr,
|
||||
gboolean color,
|
||||
gboolean verbose)
|
||||
{
|
||||
g_print ("%s%s%s%s%s%s%s%s",
|
||||
verbose ? "\n" : " * ",
|
||||
COL(MU_COLOR_GREEN),name,COL(MU_COLOR_DEFAULT),
|
||||
oneline ? ": " : "",
|
||||
COL(MU_COLOR_BLUE),oneline ? oneline :"",MU_COLOR_DEFAULT);
|
||||
g_print("%s%s%s%s%s%s%s%s",
|
||||
verbose ? "\n" : " * ",
|
||||
COL(MU_COLOR_GREEN),
|
||||
name,
|
||||
COL(MU_COLOR_DEFAULT),
|
||||
oneline ? ": " : "",
|
||||
COL(MU_COLOR_BLUE),
|
||||
oneline ? oneline : "",
|
||||
MU_COLOR_DEFAULT);
|
||||
|
||||
if (verbose && descr)
|
||||
g_print ("%s%s%s",
|
||||
COL(MU_COLOR_MAGENTA),descr,COL(MU_COLOR_DEFAULT));
|
||||
g_print("%s%s%s", COL(MU_COLOR_MAGENTA), descr, COL(MU_COLOR_DEFAULT));
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
print_scripts (GSList *scripts, gboolean color,
|
||||
gboolean verbose, const char *rxstr, GError **err)
|
||||
print_scripts(GSList* scripts, gboolean color, gboolean verbose, const char* rxstr, GError** err)
|
||||
{
|
||||
GSList *cur;
|
||||
const char *verb;
|
||||
GSList* cur;
|
||||
const char* verb;
|
||||
|
||||
if (!scripts) {
|
||||
g_print ("No scripts available\n");
|
||||
g_print("No scripts available\n");
|
||||
return TRUE; /* not an error */
|
||||
}
|
||||
|
||||
verb = verbose ? "" : " (use --verbose for details)";
|
||||
|
||||
if (rxstr)
|
||||
g_print ("Available scripts matching '%s'%s:\n",
|
||||
rxstr, verb);
|
||||
g_print("Available scripts matching '%s'%s:\n", rxstr, verb);
|
||||
else
|
||||
g_print ("Available scripts%s:\n", verb);
|
||||
g_print("Available scripts%s:\n", verb);
|
||||
|
||||
for (cur = scripts; cur; cur = g_slist_next (cur)) {
|
||||
|
||||
MuScriptInfo *msi;
|
||||
const char* descr, *oneline, *name;
|
||||
for (cur = scripts; cur; cur = g_slist_next(cur)) {
|
||||
MuScriptInfo* msi;
|
||||
const char * descr, *oneline, *name;
|
||||
|
||||
msi = (MuScriptInfo*)cur->data;
|
||||
name = mu_script_info_name (msi);
|
||||
oneline = mu_script_info_one_line (msi);
|
||||
descr = mu_script_info_description (msi);
|
||||
name = mu_script_info_name(msi);
|
||||
oneline = mu_script_info_one_line(msi);
|
||||
descr = mu_script_info_description(msi);
|
||||
|
||||
/* if rxstr is provide, only consider matching scriptinfos */
|
||||
if (rxstr && !mu_script_info_matches_regex (msi, rxstr, err)) {
|
||||
if (rxstr && !mu_script_info_matches_regex(msi, rxstr, err)) {
|
||||
if (err && *err)
|
||||
return FALSE;
|
||||
continue;
|
||||
}
|
||||
|
||||
print_script (name, oneline, descr, color, verbose);
|
||||
print_script(name, oneline, descr, color, verbose);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static char*
|
||||
get_userpath (const char *muhome)
|
||||
get_userpath(const char* muhome)
|
||||
{
|
||||
if (muhome)
|
||||
return g_build_path (G_DIR_SEPARATOR_S, muhome, "scripts", NULL);
|
||||
return g_build_path(G_DIR_SEPARATOR_S, muhome, "scripts", NULL);
|
||||
else
|
||||
return g_build_path (G_DIR_SEPARATOR_S, g_get_user_data_dir(),
|
||||
"mu", "scripts", NULL);
|
||||
return g_build_path(G_DIR_SEPARATOR_S,
|
||||
g_get_user_data_dir(),
|
||||
"mu",
|
||||
"scripts",
|
||||
NULL);
|
||||
}
|
||||
|
||||
static GSList*
|
||||
get_script_info_list (const char *muhome, GError **err)
|
||||
get_script_info_list(const char* muhome, GError** err)
|
||||
{
|
||||
GSList *scripts, *userscripts, *last;
|
||||
char *userpath;
|
||||
char* userpath;
|
||||
|
||||
scripts = mu_script_get_script_info_list
|
||||
(MU_SCRIPTS_DIR, MU_GUILE_EXT,
|
||||
MU_GUILE_DESCR_PREFIX,
|
||||
err);
|
||||
scripts = mu_script_get_script_info_list(MU_SCRIPTS_DIR,
|
||||
MU_GUILE_EXT,
|
||||
MU_GUILE_DESCR_PREFIX,
|
||||
err);
|
||||
|
||||
if (err && *err)
|
||||
return NULL;
|
||||
@ -129,26 +132,25 @@ get_script_info_list (const char *muhome, GError **err)
|
||||
userpath = get_userpath(muhome);
|
||||
|
||||
/* is there are userdir for scripts? */
|
||||
if (!mu_util_check_dir (userpath, TRUE, FALSE)) {
|
||||
g_free (userpath);
|
||||
if (!mu_util_check_dir(userpath, TRUE, FALSE)) {
|
||||
g_free(userpath);
|
||||
return scripts;
|
||||
}
|
||||
|
||||
/* append it to the list we already have */
|
||||
userscripts = mu_script_get_script_info_list (userpath, MU_GUILE_EXT,
|
||||
MU_GUILE_DESCR_PREFIX,
|
||||
err);
|
||||
g_free (userpath);
|
||||
userscripts =
|
||||
mu_script_get_script_info_list(userpath, MU_GUILE_EXT, MU_GUILE_DESCR_PREFIX, err);
|
||||
g_free(userpath);
|
||||
|
||||
/* some error, return nothing */
|
||||
if (err && *err) {
|
||||
mu_script_info_list_destroy (userscripts);
|
||||
mu_script_info_list_destroy (scripts);
|
||||
mu_script_info_list_destroy(userscripts);
|
||||
mu_script_info_list_destroy(scripts);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* append the user scripts */
|
||||
last = g_slist_last (scripts);
|
||||
last = g_slist_last(scripts);
|
||||
if (last) {
|
||||
last->next = userscripts;
|
||||
return scripts;
|
||||
@ -156,57 +158,51 @@ get_script_info_list (const char *muhome, GError **err)
|
||||
return userscripts; /* apparently, scripts was NULL */
|
||||
}
|
||||
|
||||
|
||||
|
||||
static gboolean
|
||||
check_params (const MuConfig *opts, GError **err)
|
||||
check_params(const MuConfig* opts, GError** err)
|
||||
{
|
||||
if (!mu_util_supports (MU_FEATURE_GUILE)) {
|
||||
mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS,
|
||||
"the 'script' command is not available "
|
||||
"in this version of mu");
|
||||
if (!mu_util_supports(MU_FEATURE_GUILE)) {
|
||||
mu_util_g_set_error(err,
|
||||
MU_ERROR_IN_PARAMETERS,
|
||||
"the 'script' command is not available "
|
||||
"in this version of mu");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
MuError
|
||||
Mu::mu_cmd_script (const MuConfig *opts, GError **err)
|
||||
Mu::mu_cmd_script(const MuConfig* opts, GError** err)
|
||||
{
|
||||
MuScriptInfo *msi;
|
||||
GSList *scripts;
|
||||
MuScriptInfo* msi;
|
||||
GSList* scripts;
|
||||
|
||||
g_return_val_if_fail (opts, MU_ERROR_INTERNAL);
|
||||
g_return_val_if_fail (opts->cmd == MU_CONFIG_CMD_SCRIPT,
|
||||
MU_ERROR_INTERNAL);
|
||||
g_return_val_if_fail(opts, MU_ERROR_INTERNAL);
|
||||
g_return_val_if_fail(opts->cmd == MU_CONFIG_CMD_SCRIPT, MU_ERROR_INTERNAL);
|
||||
|
||||
if (!check_params (opts, err))
|
||||
if (!check_params(opts, err))
|
||||
return MU_ERROR;
|
||||
|
||||
scripts = get_script_info_list (opts->muhome, err);
|
||||
scripts = get_script_info_list(opts->muhome, err);
|
||||
if (err && *err)
|
||||
goto leave;
|
||||
|
||||
if (g_strcmp0 (opts->cmdstr, "script") == 0) {
|
||||
print_scripts (scripts, !opts->nocolor, opts->verbose,
|
||||
opts->script_params[0], err);
|
||||
if (g_strcmp0(opts->cmdstr, "script") == 0) {
|
||||
print_scripts(scripts, !opts->nocolor, opts->verbose, opts->script_params[0], err);
|
||||
goto leave;
|
||||
}
|
||||
|
||||
msi = mu_script_find_script_with_name (scripts, opts->script);
|
||||
msi = mu_script_find_script_with_name(scripts, opts->script);
|
||||
if (!msi) {
|
||||
mu_util_g_set_error (err, MU_ERROR_SCRIPT_NOT_FOUND,
|
||||
"command or script not found");
|
||||
mu_util_g_set_error(err, MU_ERROR_SCRIPT_NOT_FOUND, "command or script not found");
|
||||
goto leave;
|
||||
}
|
||||
|
||||
/* do it! */
|
||||
mu_script_guile_run (msi, mu_runtime_path(MU_RUNTIME_PATH_CACHE),
|
||||
opts->script_params, err);
|
||||
mu_script_guile_run(msi, mu_runtime_path(MU_RUNTIME_PATH_CACHE), opts->script_params, err);
|
||||
leave:
|
||||
/* this won't be reached, unless there is some error */
|
||||
mu_script_info_list_destroy (scripts);
|
||||
mu_script_info_list_destroy(scripts);
|
||||
return (err && *err) ? MU_ERROR : MU_OK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user