mirror of https://github.com/djcb/mu.git
* mu: update mu script
This commit is contained in:
parent
34f47ae5ca
commit
5c301f71ec
136
lib/mu-script.c
136
lib/mu-script.c
|
@ -34,6 +34,7 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "mu-str.h"
|
||||||
#include "mu-script.h"
|
#include "mu-script.h"
|
||||||
#include "mu-util.h"
|
#include "mu-util.h"
|
||||||
|
|
||||||
|
@ -42,9 +43,10 @@
|
||||||
* the values will be *freed* when MuScriptInfo is freed
|
* the values will be *freed* when MuScriptInfo is freed
|
||||||
*/
|
*/
|
||||||
struct _MuScriptInfo {
|
struct _MuScriptInfo {
|
||||||
char *_name; /* filename-sans-extension */
|
char *_name; /* filename-sans-extension */
|
||||||
char *_path; /* full path to script */
|
char *_path; /* full path to script */
|
||||||
char *_descr; /* one-line description */
|
char *_oneline; /* one-line description */
|
||||||
|
char *_descr; /* longer description */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -64,6 +66,7 @@ script_info_destroy (MuScriptInfo *msi)
|
||||||
|
|
||||||
g_free (msi->_name);
|
g_free (msi->_name);
|
||||||
g_free (msi->_path);
|
g_free (msi->_path);
|
||||||
|
g_free (msi->_oneline);
|
||||||
g_free (msi->_descr);
|
g_free (msi->_descr);
|
||||||
|
|
||||||
g_slice_free (MuScriptInfo, msi);
|
g_slice_free (MuScriptInfo, msi);
|
||||||
|
@ -91,6 +94,13 @@ mu_script_info_path (MuScriptInfo *msi)
|
||||||
return msi->_path;
|
return msi->_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char*
|
||||||
|
mu_script_info_one_line (MuScriptInfo *msi)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (msi, NULL);
|
||||||
|
return msi->_oneline;
|
||||||
|
}
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
mu_script_info_description (MuScriptInfo *msi)
|
mu_script_info_description (MuScriptInfo *msi)
|
||||||
{
|
{
|
||||||
|
@ -98,6 +108,30 @@ mu_script_info_description (MuScriptInfo *msi)
|
||||||
return msi->_descr;
|
return msi->_descr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
mu_script_info_matches_regex (MuScriptInfo *msi, const char *rxstr,
|
||||||
|
GError **err)
|
||||||
|
{
|
||||||
|
GRegex *rx;
|
||||||
|
gboolean match;
|
||||||
|
|
||||||
|
g_return_val_if_fail (msi, FALSE);
|
||||||
|
g_return_val_if_fail (rxstr, FALSE);
|
||||||
|
|
||||||
|
rx = g_regex_new (rxstr, G_REGEX_CASELESS|G_REGEX_OPTIMIZE, 0, err);
|
||||||
|
if (!rx)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
match = FALSE;
|
||||||
|
if (msi->_name)
|
||||||
|
match = g_regex_match (rx, msi->_name, 0, NULL);
|
||||||
|
if (!match && msi->_oneline)
|
||||||
|
match = g_regex_match (rx, msi->_oneline, 0, NULL);
|
||||||
|
|
||||||
|
return match;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
mu_script_info_list_destroy (GSList *lst)
|
mu_script_info_list_destroy (GSList *lst)
|
||||||
{
|
{
|
||||||
|
@ -105,38 +139,53 @@ mu_script_info_list_destroy (GSList *lst)
|
||||||
g_slist_free (lst);
|
g_slist_free (lst);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gchar*
|
static gboolean
|
||||||
get_description (const char *path, const char *prefix)
|
get_descriptions (MuScriptInfo *msi, const char *prefix)
|
||||||
{
|
{
|
||||||
FILE *script;
|
FILE *script;
|
||||||
char *line, *descr;
|
char *line, *descr, *oneline;
|
||||||
size_t n;
|
size_t n;
|
||||||
|
|
||||||
if (!prefix)
|
if (!prefix)
|
||||||
return NULL; /* not an error */
|
return TRUE; /* not an error */
|
||||||
|
|
||||||
script = fopen (path, "r");
|
script = fopen (msi->_path, "r");
|
||||||
if (!script) {
|
if (!script) {
|
||||||
g_warning ("failed to open %s: %s",
|
g_warning ("failed to open %s: %s",
|
||||||
path, strerror(errno));
|
msi->_path, strerror(errno));
|
||||||
return NULL;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
descr = NULL;
|
descr = oneline = NULL;
|
||||||
line = NULL;
|
line = NULL;
|
||||||
while (!descr && getline (&line, &n, script) != -1) {
|
while (getline (&line, &n, script) != -1) {
|
||||||
if (g_str_has_prefix(line, prefix)) {
|
|
||||||
descr = g_strdup (line + strlen(prefix));
|
if (!g_str_has_prefix(line, prefix)) {
|
||||||
/* remove trailing '\n' */
|
free (line);
|
||||||
descr[strlen(descr) - 1] = '\0';
|
line = NULL;
|
||||||
|
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));
|
||||||
|
g_free (tmp);
|
||||||
|
}
|
||||||
|
|
||||||
free (line);
|
free (line);
|
||||||
line = NULL;
|
line = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose (script);
|
fclose (script);
|
||||||
|
|
||||||
return descr;
|
msi->_oneline = oneline;
|
||||||
|
msi->_descr = descr;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -163,7 +212,6 @@ mu_script_get_script_info_list (const char *path, const char *ext,
|
||||||
lst = NULL;
|
lst = NULL;
|
||||||
while ((dentry = readdir (dir))) {
|
while ((dentry = readdir (dir))) {
|
||||||
MuScriptInfo *msi;
|
MuScriptInfo *msi;
|
||||||
|
|
||||||
/* only consider files with certain extensions,
|
/* only consider files with certain extensions,
|
||||||
* if ext != NULL */
|
* if ext != NULL */
|
||||||
if (ext && !g_str_has_suffix (dentry->d_name, ext))
|
if (ext && !g_str_has_suffix (dentry->d_name, ext))
|
||||||
|
@ -174,7 +222,8 @@ mu_script_get_script_info_list (const char *path, const char *ext,
|
||||||
msi->_name[strlen(msi->_name) - strlen(ext)] = '\0';
|
msi->_name[strlen(msi->_name) - strlen(ext)] = '\0';
|
||||||
msi->_path = g_strdup_printf ("%s%c%s", path, G_DIR_SEPARATOR,
|
msi->_path = g_strdup_printf ("%s%c%s", path, G_DIR_SEPARATOR,
|
||||||
dentry->d_name);
|
dentry->d_name);
|
||||||
msi->_descr = get_description (msi->_path, descprefix);
|
/* set the one-line and long description */
|
||||||
|
get_descriptions (msi, descprefix);
|
||||||
lst = g_slist_prepend (lst, msi);
|
lst = g_slist_prepend (lst, msi);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,32 +263,35 @@ guile_shell (void *closure, int argc, char **argv)
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
mu_script_guile_run (MuScriptInfo *msi, const char *muhome,
|
mu_script_guile_run (MuScriptInfo *msi, const char *muhome,
|
||||||
const char *query, gboolean textonly, GError **err)
|
const char **args, GError **err)
|
||||||
{
|
{
|
||||||
char *expr;
|
char *mainargs, *expr;
|
||||||
char *argv[] = {
|
char *argv[] = {
|
||||||
"guile", "-l", NULL, "-c", NULL, NULL
|
"guile", "-l", NULL, "-c", NULL, NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
g_return_val_if_fail (msi, FALSE);
|
g_return_val_if_fail (msi, FALSE);
|
||||||
g_return_val_if_fail (muhome, FALSE);
|
g_return_val_if_fail (muhome, FALSE);
|
||||||
|
|
||||||
if (access (mu_script_info_path (msi), R_OK) != 0) {
|
if (access (mu_script_info_path (msi), R_OK) != 0) {
|
||||||
mu_util_g_set_error (err, MU_ERROR_FILE_CANNOT_READ,
|
mu_util_g_set_error (err, MU_ERROR_FILE_CANNOT_READ,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
argv[2] = (char*)mu_script_info_path (msi);
|
argv[2] = (char*)mu_script_info_path (msi);
|
||||||
|
|
||||||
expr = g_strdup_printf (
|
mainargs = mu_str_quoted_from_strv (args);
|
||||||
"(main '(\"%s\" \"--muhome=%s\" %s %s))",
|
expr = g_strdup_printf (
|
||||||
mu_script_info_name (msi),
|
"(main '(\"%s\" \"--muhome=%s\" %s))",
|
||||||
muhome,
|
mu_script_info_name (msi),
|
||||||
textonly ? "\"--textonly\"" : "",
|
muhome,
|
||||||
query ? query : "");
|
mainargs ? mainargs : "");
|
||||||
argv[4] = expr;
|
g_print ("[%s]\n", mainargs);
|
||||||
|
|
||||||
scm_boot_guile (5, argv, guile_shell, NULL);
|
g_free (mainargs);
|
||||||
|
argv[4] = expr;
|
||||||
|
|
||||||
|
scm_boot_guile (5, argv, guile_shell, NULL);
|
||||||
|
|
||||||
/* never reached but let's be correct(TM)*/
|
/* never reached but let's be correct(TM)*/
|
||||||
g_free (expr);
|
g_free (expr);
|
||||||
|
|
|
@ -55,8 +55,29 @@ const char* mu_script_info_path (MuScriptInfo *msi);
|
||||||
*
|
*
|
||||||
* @return the description, or NULL if there was none
|
* @return the description, or NULL if there was none
|
||||||
*/
|
*/
|
||||||
|
const char* mu_script_info_one_line (MuScriptInfo *msi);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get a full description for the script
|
||||||
|
*
|
||||||
|
* @param msi a MuScriptInfo structure
|
||||||
|
*
|
||||||
|
* @return the description, or NULL if there was none
|
||||||
|
*/
|
||||||
const char* mu_script_info_description (MuScriptInfo *msi);
|
const char* mu_script_info_description (MuScriptInfo *msi);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check whether either the name or one-line description of a
|
||||||
|
* MuScriptInfo matches regular expression rxstr
|
||||||
|
*
|
||||||
|
* @param msi a MuScriptInfo
|
||||||
|
* @param rxstr a regular expression string
|
||||||
|
* @param err receives error information
|
||||||
|
*
|
||||||
|
* @return TRUE if it matches, FALSE if not or in case of error
|
||||||
|
*/
|
||||||
|
gboolean mu_script_info_matches_regex (MuScriptInfo *msi, const char *rxstr,
|
||||||
|
GError **err);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the list of all scripts in path with extension ext
|
* Get the list of all scripts in path with extension ext
|
||||||
|
@ -96,17 +117,15 @@ MuScriptInfo* mu_script_find_script_with_name (GSList *lst, const char *name);
|
||||||
* run the guile script at path
|
* run the guile script at path
|
||||||
*
|
*
|
||||||
* @param msi MuScriptInfo object for the script
|
* @param msi MuScriptInfo object for the script
|
||||||
* @param muhome mu home directory
|
* @param muhome path to the mu home dir
|
||||||
* @param query query for this script (or NULL)
|
* @param args NULL-terminated array of strings (argv for the script)
|
||||||
* @param textonly whether to not use a graphical display
|
|
||||||
* @param err receives error information
|
* @param err receives error information
|
||||||
*
|
*
|
||||||
* @return FALSE in case of error -- otherwise, this function will
|
* @return FALSE in case of error -- otherwise, this function will
|
||||||
* _not return_
|
* _not return_
|
||||||
*/
|
*/
|
||||||
gboolean mu_script_guile_run (MuScriptInfo *msi, const char *muhome,
|
gboolean mu_script_guile_run (MuScriptInfo *msi, const char *muhome,
|
||||||
const char* query, gboolean textonly,
|
const char **args, GError **err);
|
||||||
GError **err);
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ INCLUDES=-I${top_srcdir}/lib $(GLIB_CFLAGS)
|
||||||
# really need all the params they get
|
# really need all the params they get
|
||||||
AM_CFLAGS=-Wall -Wextra -Wno-unused-parameter -Wdeclaration-after-statement \
|
AM_CFLAGS=-Wall -Wextra -Wno-unused-parameter -Wdeclaration-after-statement \
|
||||||
-pedantic -Wno-variadic-macros \
|
-pedantic -Wno-variadic-macros \
|
||||||
-DMU_STATSDIR="\"$(pkgdatadir)/scripts/stats\""
|
-DMU_SCRIPTS_DIR="\"$(pkgdatadir)/scripts/\""
|
||||||
AM_CXXFLAGS=-Wall -Wextra -Wno-unused-parameter
|
AM_CXXFLAGS=-Wall -Wextra -Wno-unused-parameter
|
||||||
|
|
||||||
bin_PROGRAMS= \
|
bin_PROGRAMS= \
|
||||||
|
|
|
@ -35,33 +35,56 @@
|
||||||
#include "mu-script.h"
|
#include "mu-script.h"
|
||||||
|
|
||||||
#define MU_GUILE_EXT ".scm"
|
#define MU_GUILE_EXT ".scm"
|
||||||
#define MU_GUILE_DESCR_PREFIX ";; DESCRIPTION: "
|
#define MU_GUILE_DESCR_PREFIX ";; INFO: "
|
||||||
|
|
||||||
static void
|
static gboolean
|
||||||
print_stats (GSList *scripts)
|
print_scripts (GSList *scripts, gboolean verbose, const char *rxstr,
|
||||||
|
GError **err)
|
||||||
{
|
{
|
||||||
GSList *cur;
|
GSList *cur;
|
||||||
|
gboolean first;
|
||||||
|
|
||||||
if (!scripts) {
|
if (!scripts) {
|
||||||
g_print ("No statistics available\n");
|
g_print ("No scripts available\n");
|
||||||
return;
|
return TRUE; /* not an error */
|
||||||
}
|
}
|
||||||
|
|
||||||
g_print ("Available statistics "
|
if (rxstr)
|
||||||
"(use with --stat=<stastistic>):\n");
|
g_print ("Available scripts matching '%s':\n", rxstr);
|
||||||
for (cur = scripts; cur; cur = g_slist_next (cur)) {
|
else
|
||||||
|
g_print ("Available scripts:\n");
|
||||||
|
|
||||||
|
for (cur = scripts, first = TRUE; cur; cur = g_slist_next (cur)) {
|
||||||
|
|
||||||
MuScriptInfo *msi;
|
MuScriptInfo *msi;
|
||||||
const char* descr;
|
const char* descr, *oneline, *name;
|
||||||
|
|
||||||
msi = (MuScriptInfo*)cur->data;
|
msi = (MuScriptInfo*)cur->data;
|
||||||
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);
|
||||||
|
|
||||||
g_print ("\t%s%s%s\n",
|
/* if rxstr is provide, only consider matching scriptinfos */
|
||||||
mu_script_info_name (msi),
|
if (rxstr && !mu_script_info_matches_regex (msi, rxstr, err)) {
|
||||||
descr ? ": " : "",
|
if (err && *err)
|
||||||
descr ? descr : "");
|
return FALSE;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* whitespace between */
|
||||||
|
if (verbose && !first)
|
||||||
|
g_print ("\n");
|
||||||
|
first = FALSE;
|
||||||
|
|
||||||
|
g_print ("%s%s%s", name,
|
||||||
|
oneline ? ": " : "",
|
||||||
|
oneline ? oneline :"");
|
||||||
|
|
||||||
|
if (verbose && descr)
|
||||||
|
g_print ("%s", descr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -71,9 +94,11 @@ get_script_info_list (const char *muhome, GError **err)
|
||||||
GSList *scripts, *userscripts, *last;
|
GSList *scripts, *userscripts, *last;
|
||||||
char *userpath;
|
char *userpath;
|
||||||
|
|
||||||
scripts = mu_script_get_script_info_list (MU_STATSDIR, MU_GUILE_EXT,
|
scripts = mu_script_get_script_info_list
|
||||||
MU_GUILE_DESCR_PREFIX,
|
(MU_SCRIPTS_DIR, MU_GUILE_EXT,
|
||||||
err);
|
MU_GUILE_DESCR_PREFIX,
|
||||||
|
err);
|
||||||
|
|
||||||
if (err && *err)
|
if (err && *err)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -111,7 +136,7 @@ check_params (MuConfig *opts, GError **err)
|
||||||
{
|
{
|
||||||
if (!mu_util_supports (MU_FEATURE_GUILE | MU_FEATURE_GNUPLOT)) {
|
if (!mu_util_supports (MU_FEATURE_GUILE | MU_FEATURE_GNUPLOT)) {
|
||||||
mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS,
|
mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS,
|
||||||
"the 'stats' command is not supported");
|
"the 'script' command is not supported");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,18 +145,15 @@ check_params (MuConfig *opts, GError **err)
|
||||||
|
|
||||||
|
|
||||||
MuError
|
MuError
|
||||||
mu_cmd_stats (MuConfig *opts, GError **err)
|
mu_cmd_script (MuConfig *opts, GError **err)
|
||||||
{
|
{
|
||||||
MuScriptInfo *msi;
|
MuScriptInfo *msi;
|
||||||
GSList *scripts;
|
GSList *scripts;
|
||||||
gchar *query;
|
|
||||||
|
|
||||||
g_return_val_if_fail (opts, MU_ERROR_INTERNAL);
|
g_return_val_if_fail (opts, MU_ERROR_INTERNAL);
|
||||||
g_return_val_if_fail (opts->cmd == MU_CONFIG_CMD_STATS,
|
g_return_val_if_fail (opts->cmd == MU_CONFIG_CMD_SCRIPT,
|
||||||
MU_ERROR_INTERNAL);
|
MU_ERROR_INTERNAL);
|
||||||
|
|
||||||
query = NULL;
|
|
||||||
|
|
||||||
if (!check_params (opts, err))
|
if (!check_params (opts, err))
|
||||||
return MU_ERROR;
|
return MU_ERROR;
|
||||||
|
|
||||||
|
@ -139,29 +161,24 @@ mu_cmd_stats (MuConfig *opts, GError **err)
|
||||||
if (err && *err)
|
if (err && *err)
|
||||||
goto leave;
|
goto leave;
|
||||||
|
|
||||||
if (!opts->stat) {
|
if (!opts->script) {
|
||||||
print_stats (scripts);
|
print_scripts (scripts, opts->verbose,
|
||||||
|
opts->params[1], err);
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
|
|
||||||
msi = mu_script_find_script_with_name (scripts, opts->stat);
|
msi = mu_script_find_script_with_name (scripts, opts->script);
|
||||||
if (!msi) {
|
if (!msi) {
|
||||||
mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS,
|
mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS,
|
||||||
"script not found");
|
"script not found");
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
|
|
||||||
query = (opts->params[1]) ?
|
|
||||||
mu_str_quoted_from_strv ((const gchar**)&opts->params[1]) :
|
|
||||||
NULL;
|
|
||||||
|
|
||||||
/* do it! */
|
/* do it! */
|
||||||
mu_script_guile_run (msi, opts->muhome, query ? query : "",
|
mu_script_guile_run (msi, opts->muhome,
|
||||||
opts->textonly, err);
|
(const gchar**)&opts->params[1], err);
|
||||||
leave:
|
leave:
|
||||||
/* this won't be reached, unless there is some error */
|
/* this won't be reached, unless there is some error */
|
||||||
mu_script_info_list_destroy (scripts);
|
mu_script_info_list_destroy (scripts);
|
||||||
g_free (query);
|
|
||||||
|
|
||||||
return (err && *err) ? MU_ERROR : MU_OK;
|
return (err && *err) ? MU_ERROR : MU_OK;
|
||||||
}
|
}
|
||||||
|
|
10
mu/mu-cmd.c
10
mu/mu-cmd.c
|
@ -609,11 +609,11 @@ mu_cmd_execute (MuConfig *opts, GError **err)
|
||||||
/* already handled in mu-config.c */
|
/* already handled in mu-config.c */
|
||||||
case MU_CONFIG_CMD_HELP: return MU_OK;
|
case MU_CONFIG_CMD_HELP: return MU_OK;
|
||||||
|
|
||||||
case MU_CONFIG_CMD_CFIND: merr = mu_cmd_cfind (opts, err); break;
|
case MU_CONFIG_CMD_CFIND: merr = mu_cmd_cfind (opts, err); break;
|
||||||
case MU_CONFIG_CMD_MKDIR: merr = mu_cmd_mkdir (opts, err); break;
|
case MU_CONFIG_CMD_MKDIR: merr = mu_cmd_mkdir (opts, err); break;
|
||||||
case MU_CONFIG_CMD_STATS: merr = mu_cmd_stats (opts, err); break;
|
case MU_CONFIG_CMD_SCRIPT: merr = mu_cmd_script (opts, err); break;
|
||||||
case MU_CONFIG_CMD_VIEW: merr = mu_cmd_view (opts, err); break;
|
case MU_CONFIG_CMD_VIEW: merr = mu_cmd_view (opts, err); break;
|
||||||
case MU_CONFIG_CMD_VERIFY: merr = mu_cmd_verify (opts, err); break;
|
case MU_CONFIG_CMD_VERIFY: merr = mu_cmd_verify (opts, err); break;
|
||||||
case MU_CONFIG_CMD_EXTRACT: merr = mu_cmd_extract (opts, err); break;
|
case MU_CONFIG_CMD_EXTRACT: merr = mu_cmd_extract (opts, err); break;
|
||||||
|
|
||||||
case MU_CONFIG_CMD_FIND:
|
case MU_CONFIG_CMD_FIND:
|
||||||
|
|
|
@ -105,7 +105,7 @@ MuError mu_cmd_mv (MuConfig *opts, GError **err);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* execute the 'stats' command
|
* execute the 'script' command
|
||||||
*
|
*
|
||||||
* @param opts configuration options
|
* @param opts configuration options
|
||||||
* @param err receives error information, or NULL
|
* @param err receives error information, or NULL
|
||||||
|
@ -113,7 +113,7 @@ MuError mu_cmd_mv (MuConfig *opts, GError **err);
|
||||||
* @return MU_OK (0) if the command succeeds,
|
* @return MU_OK (0) if the command succeeds,
|
||||||
* some error code otherwise
|
* some error code otherwise
|
||||||
*/
|
*/
|
||||||
MuError mu_cmd_stats (MuConfig *opts, GError **err);
|
MuError mu_cmd_script (MuConfig *opts, GError **err);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* execute the cfind command
|
* execute the cfind command
|
||||||
|
|
|
@ -95,7 +95,7 @@ config_options_group_mu (void)
|
||||||
"print debug output to standard error (false)", NULL},
|
"print debug output to standard error (false)", NULL},
|
||||||
{"quiet", 'q', 0, G_OPTION_ARG_NONE, &MU_CONFIG.quiet,
|
{"quiet", 'q', 0, G_OPTION_ARG_NONE, &MU_CONFIG.quiet,
|
||||||
"don't give any progress information (false)", NULL},
|
"don't give any progress information (false)", NULL},
|
||||||
{"version", 'v', 0, G_OPTION_ARG_NONE, &MU_CONFIG.version,
|
{"version", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.version,
|
||||||
"display version and copyright information (false)", NULL},
|
"display version and copyright information (false)", NULL},
|
||||||
{"muhome", 0, 0, G_OPTION_ARG_FILENAME, &MU_CONFIG.muhome,
|
{"muhome", 0, 0, G_OPTION_ARG_FILENAME, &MU_CONFIG.muhome,
|
||||||
"specify an alternative mu directory", "<dir>"},
|
"specify an alternative mu directory", "<dir>"},
|
||||||
|
@ -292,18 +292,16 @@ config_options_group_cfind (void)
|
||||||
|
|
||||||
|
|
||||||
static GOptionGroup *
|
static GOptionGroup *
|
||||||
config_options_group_stats (void)
|
config_options_group_script (void)
|
||||||
{
|
{
|
||||||
GOptionGroup *og;
|
GOptionGroup *og;
|
||||||
GOptionEntry entries[] = {
|
GOptionEntry entries[] = {
|
||||||
{"stat", 0, 0, G_OPTION_ARG_STRING, &MU_CONFIG.stat,
|
{"script", 0, 0, G_OPTION_ARG_STRING, &MU_CONFIG.script,
|
||||||
"statistic to show (see `mu help stats')", "<statistic>"},
|
"script to run (see `mu help script')", "<script>"},
|
||||||
{"textonly", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.textonly,
|
|
||||||
"use text-only output", NULL},
|
|
||||||
{NULL, 0, 0, 0, NULL, NULL, NULL}
|
{NULL, 0, 0, 0, NULL, NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
og = g_option_group_new("stats", "Options for the 'stats' command",
|
og = g_option_group_new("script", "Options for the 'script' command",
|
||||||
"", NULL, NULL);
|
"", NULL, NULL);
|
||||||
g_option_group_add_entries(og, entries);
|
g_option_group_add_entries(og, entries);
|
||||||
|
|
||||||
|
@ -459,8 +457,8 @@ cmd_from_string (const char *str)
|
||||||
{ "index", MU_CONFIG_CMD_INDEX },
|
{ "index", MU_CONFIG_CMD_INDEX },
|
||||||
{ "mkdir", MU_CONFIG_CMD_MKDIR },
|
{ "mkdir", MU_CONFIG_CMD_MKDIR },
|
||||||
{ "remove", MU_CONFIG_CMD_REMOVE },
|
{ "remove", MU_CONFIG_CMD_REMOVE },
|
||||||
|
{ "script", MU_CONFIG_CMD_SCRIPT },
|
||||||
{ "server", MU_CONFIG_CMD_SERVER },
|
{ "server", MU_CONFIG_CMD_SERVER },
|
||||||
{ "stats", MU_CONFIG_CMD_STATS },
|
|
||||||
{ "verify", MU_CONFIG_CMD_VERIFY },
|
{ "verify", MU_CONFIG_CMD_VERIFY },
|
||||||
{ "view", MU_CONFIG_CMD_VIEW }
|
{ "view", MU_CONFIG_CMD_VIEW }
|
||||||
};
|
};
|
||||||
|
@ -514,8 +512,8 @@ get_option_group (MuConfigCmd cmd)
|
||||||
return config_options_group_mkdir();
|
return config_options_group_mkdir();
|
||||||
case MU_CONFIG_CMD_SERVER:
|
case MU_CONFIG_CMD_SERVER:
|
||||||
return config_options_group_server();
|
return config_options_group_server();
|
||||||
case MU_CONFIG_CMD_STATS:
|
case MU_CONFIG_CMD_SCRIPT:
|
||||||
return config_options_group_stats();
|
return config_options_group_script();
|
||||||
case MU_CONFIG_CMD_VERIFY:
|
case MU_CONFIG_CMD_VERIFY:
|
||||||
return config_options_group_verify();
|
return config_options_group_verify();
|
||||||
case MU_CONFIG_CMD_VIEW:
|
case MU_CONFIG_CMD_VIEW:
|
||||||
|
@ -628,25 +626,31 @@ parse_params (int *argcp, char ***argvp)
|
||||||
{
|
{
|
||||||
GError *err;
|
GError *err;
|
||||||
GOptionContext *context;
|
GOptionContext *context;
|
||||||
|
GOptionGroup *group;
|
||||||
gboolean rv;
|
gboolean rv;
|
||||||
|
|
||||||
context = g_option_context_new("- mu general options");
|
context = g_option_context_new("- mu general options");
|
||||||
g_option_context_set_main_group(context, config_options_group_mu());
|
|
||||||
g_option_context_set_help_enabled (context, TRUE);
|
g_option_context_set_help_enabled (context, TRUE);
|
||||||
|
|
||||||
err = NULL;
|
err = NULL;
|
||||||
|
rv = TRUE;
|
||||||
|
|
||||||
if (MU_CONFIG.cmd == MU_CONFIG_CMD_NONE) {
|
switch (MU_CONFIG.cmd) {
|
||||||
show_usage ();
|
case MU_CONFIG_CMD_NONE: show_usage(); break;
|
||||||
return TRUE;
|
case MU_CONFIG_CMD_HELP:
|
||||||
}
|
/* 'help' is special; sucks in the options of the
|
||||||
|
* command after it */
|
||||||
/* help is special */
|
|
||||||
if (MU_CONFIG.cmd == MU_CONFIG_CMD_HELP) {
|
|
||||||
rv = g_option_context_parse (context, argcp, argvp, &err) &&
|
rv = g_option_context_parse (context, argcp, argvp, &err) &&
|
||||||
cmd_help ();
|
cmd_help ();
|
||||||
} else {
|
break;
|
||||||
GOptionGroup *group;
|
case MU_CONFIG_CMD_SCRIPT:
|
||||||
|
/* script feeds the rest of the options to the script, so
|
||||||
|
* we accept all of them */
|
||||||
|
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);
|
group = get_option_group (MU_CONFIG.cmd);
|
||||||
if (group)
|
if (group)
|
||||||
g_option_context_add_group(context, group);
|
g_option_context_add_group(context, group);
|
||||||
|
@ -654,14 +658,14 @@ parse_params (int *argcp, char ***argvp)
|
||||||
}
|
}
|
||||||
|
|
||||||
g_option_context_free (context);
|
g_option_context_free (context);
|
||||||
if (!rv) {
|
|
||||||
g_printerr ("mu: error in options: %s\n",
|
|
||||||
err ? err->message : "?");
|
|
||||||
g_clear_error (&err);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
if (rv)
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
/* something when wrong */
|
||||||
|
g_printerr ("mu: option error: %s\n", err ? err->message : "?");
|
||||||
|
g_clear_error (&err);
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -72,8 +72,8 @@ enum _MuConfigCmd {
|
||||||
MU_CONFIG_CMD_INDEX,
|
MU_CONFIG_CMD_INDEX,
|
||||||
MU_CONFIG_CMD_MKDIR,
|
MU_CONFIG_CMD_MKDIR,
|
||||||
MU_CONFIG_CMD_REMOVE,
|
MU_CONFIG_CMD_REMOVE,
|
||||||
|
MU_CONFIG_CMD_SCRIPT,
|
||||||
MU_CONFIG_CMD_SERVER,
|
MU_CONFIG_CMD_SERVER,
|
||||||
MU_CONFIG_CMD_STATS,
|
|
||||||
MU_CONFIG_CMD_VERIFY,
|
MU_CONFIG_CMD_VERIFY,
|
||||||
MU_CONFIG_CMD_VIEW,
|
MU_CONFIG_CMD_VIEW,
|
||||||
|
|
||||||
|
@ -176,9 +176,8 @@ struct _MuConfig {
|
||||||
gboolean overwrite; /* should we overwrite same-named files */
|
gboolean overwrite; /* should we overwrite same-named files */
|
||||||
gboolean play; /* after saving, try to 'play'
|
gboolean play; /* after saving, try to 'play'
|
||||||
* (open) the attmnt using xdgopen */
|
* (open) the attmnt using xdgopen */
|
||||||
/* options for mu-stats */
|
/* options for mu-script */
|
||||||
gboolean textonly; /* no non-textual graphs */
|
gchar *script; /* script to run */
|
||||||
gchar *stat; /* statistic to show */
|
|
||||||
};
|
};
|
||||||
typedef struct _MuConfig MuConfig;
|
typedef struct _MuConfig MuConfig;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue