Skip to content

Commit

Permalink
* mu: small cleanups to pass 'make cc10', 'make line35'
Browse files Browse the repository at this point in the history
  • Loading branch information
djcb committed Oct 23, 2012
1 parent 924e3c6 commit 94fcf1c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 33 deletions.
20 changes: 6 additions & 14 deletions lib/mu-script.c
Expand Up @@ -156,30 +156,23 @@ get_descriptions (MuScriptInfo *msi, const char *prefix)
return FALSE;
}

descr = oneline = NULL;
line = NULL;
while (getline (&line, &n, script) != -1) {
for (descr = oneline = NULL, line = NULL;
getline (&line, &n, script) != -1; free (line), line = NULL) {

if (!g_str_has_prefix(line, prefix)) {
free (line);
line = NULL;
if (!g_str_has_prefix(line, prefix))
continue;
}

if (!oneline)
oneline = g_strdup (line + strlen (prefix));
else {
char *tmp;
tmp = descr;
descr = g_strdup_printf (
"%s%s", descr ? descr : "",
line + strlen(prefix));
descr = g_strdup_printf ("%s%s", descr ? descr : "",
line + strlen(prefix));
g_free (tmp);
}

free (line);
line = NULL;
}

fclose (script);

msi->_oneline = oneline;
Expand Down Expand Up @@ -286,7 +279,6 @@ mu_script_guile_run (MuScriptInfo *msi, const char *muhome,
mu_script_info_name (msi),
muhome,
mainargs ? mainargs : "");
g_print ("[%s]\n", mainargs);

g_free (mainargs);
argv[4] = expr;
Expand Down
32 changes: 17 additions & 15 deletions mu/mu-cmd-script.c
Expand Up @@ -38,12 +38,26 @@
#define MU_GUILE_EXT ".scm"
#define MU_GUILE_DESCR_PREFIX ";; INFO: "

static void
print_script (const char *name, const char *oneline, const char *descr,
gboolean verbose)
{
g_print ("%s%s%s%s",
verbose ? "\n" : " * ",
name,
oneline ? ": " : "",
oneline ? oneline :"");

if (verbose && descr)
g_print ("%s", descr);
}


static gboolean
print_scripts (GSList *scripts, gboolean verbose, const char *rxstr,
GError **err)
{
GSList *cur;
gboolean first;

if (!scripts) {
g_print ("No scripts available\n");
Expand All @@ -55,7 +69,7 @@ print_scripts (GSList *scripts, gboolean verbose, const char *rxstr,
else
g_print ("Available scripts:\n");

for (cur = scripts, first = TRUE; cur; cur = g_slist_next (cur)) {
for (cur = scripts; cur; cur = g_slist_next (cur)) {

MuScriptInfo *msi;
const char* descr, *oneline, *name;
Expand All @@ -72,19 +86,7 @@ print_scripts (GSList *scripts, gboolean verbose, const char *rxstr,
continue;
}

/* whitespace between */
if (verbose && !first)
g_print ("\n");
first = FALSE;

g_print ("%s%s%s%s",
verbose ? "" : " * ",
name,
oneline ? ": " : "",
oneline ? oneline :"");

if (verbose && descr)
g_print ("%s", descr);
print_script (name, oneline, descr, verbose);
}

return TRUE;
Expand Down
7 changes: 3 additions & 4 deletions mu/mu-config.c
Expand Up @@ -640,13 +640,14 @@ parse_params (int *argcp, char ***argvp)
err = NULL;
rv = TRUE;

g_option_context_set_main_group(context,
config_options_group_mu());

switch (MU_CONFIG.cmd) {
case MU_CONFIG_CMD_NONE: show_usage(); break;
case MU_CONFIG_CMD_HELP:
/* 'help' is special; sucks in the options of the
* command after it */
g_option_context_set_main_group(context,
config_options_group_mu());
rv = g_option_context_parse (context, argcp, argvp, &err) &&
cmd_help ();
break;
Expand All @@ -656,8 +657,6 @@ parse_params (int *argcp, char ***argvp)
g_option_context_set_ignore_unknown_options (context, TRUE);
/* fall through */
default:
g_option_context_set_main_group(context,
config_options_group_mu());
group = get_option_group (MU_CONFIG.cmd);
if (group)
g_option_context_add_group(context, group);
Expand Down

0 comments on commit 94fcf1c

Please sign in to comment.