From c60e03a16da23b582dc643f0102c7e793918e0aa Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Thu, 26 May 2011 23:35:34 +0300 Subject: [PATCH] * mu-config.[ch]: do tty-checking here (for --color), add mu_config_param_num (for param-checking) --- src/mu-config.c | 24 +++++++++++++++++++++++- src/mu-config.h | 12 ++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/mu-config.c b/src/mu-config.c index cdd50d55..a14cc08c 100644 --- a/src/mu-config.c +++ b/src/mu-config.c @@ -24,6 +24,8 @@ #include #include /* memset */ +#include +#include #include "mu-util.h" #include "mu-config.h" @@ -43,8 +45,16 @@ set_group_mu_defaults (MuConfig *opts) opts->muhome = exp; } + + /* check for the MU_COLORS env var; but in any case don't use + * colors unless we're writing to a tty */ + if (g_getenv (MU_COLORS) != NULL) opts->color = TRUE; + + if (!isatty(fileno(stdout))) + opts->color = FALSE; + } static GOptionGroup* @@ -363,7 +373,7 @@ parse_params (MuConfig *opts, int *argcp, char ***argvp) add_context_group (context, opts); - rv = g_option_context_parse(context, argcp, argvp, &err); + rv = g_option_context_parse (context, argcp, argvp, &err); g_option_context_free (context); if (!rv) { g_printerr ("mu: error in options: %s\n", err->message); @@ -470,3 +480,15 @@ mu_config_execute (MuConfig *opts) g_return_val_if_reached (MU_EXITCODE_ERROR); } } + +guint +mu_config_param_num (MuConfig *conf) +{ + guint u; + + g_return_val_if_fail (conf, 0); + + for (u = 0; conf->params[u]; ++u); + + return u; +} diff --git a/src/mu-config.h b/src/mu-config.h index 92dee45e..bd92c77a 100644 --- a/src/mu-config.h +++ b/src/mu-config.h @@ -150,6 +150,18 @@ void mu_config_destroy (MuConfig *opts); */ MuExitCode mu_config_execute (MuConfig *opts); + +/** + * count the number of non-option parameters + * + * @param conf a MuConfig instance + * + * @return the number of non-option parameters, or 0 in case of error + */ +guint mu_config_param_num (MuConfig *conf); + + + G_END_DECLS #endif /*__MU_CONFIG_H__*/