update commands for new query parser

This commit is contained in:
djcb 2017-10-24 22:58:32 +03:00
parent 5e9cafea59
commit aa07c4a27c
6 changed files with 56 additions and 46 deletions

View File

@ -173,7 +173,7 @@ struct MuProc: public Mux::ProcIface {
const Xapian::Database& db_;
};
class _MuQuery {
struct _MuQuery {
public:
_MuQuery (MuStore *store): _store(mu_store_ref(store)) {}
~_MuQuery () { mu_store_unref (_store); }

View File

@ -25,44 +25,45 @@ AM_CPPFLAGS=-I${top_srcdir}/lib $(GLIB_CFLAGS)
# don't use -Werror, as it might break on other compilers
# use -Wno-unused-parameters, because some callbacks may not
# really need all the params they get
AM_CFLAGS= \
$(WARN_CFLAGS) \
-Wno-switch-enum \
AM_CFLAGS= \
$(WARN_CFLAGS) \
-Wno-switch-enum \
-DMU_SCRIPTS_DIR="\"$(pkgdatadir)/scripts/\""
AM_CXXFLAGS= \
AM_CXXFLAGS= \
$(WARN_CXXFLAGS)
bin_PROGRAMS= \
bin_PROGRAMS= \
mu
# note, mu.cc is only '.cc' and not '.c' because libmu must explicitly
# be linked as c++, not c.
mu_SOURCES= \
mu.cc \
mu-cmd-cfind.c \
mu-config.c \
mu-config.h \
mu-cmd-extract.c \
mu-cmd-find.c \
mu-cmd-index.c \
mu-cmd-server.c \
mu-cmd-script.c \
mu-cmd.c \
mu_SOURCES= \
mu.cc \
mu-cmd-cfind.c \
mu-config.c \
mu-config.h \
mu-cmd-extract.c \
mu-cmd-find.c \
mu-cmd-index.c \
mu-cmd-server.c \
mu-cmd-script.c \
mu-cmd.c \
mu-cmd.h
BUILT_SOURCES= \
BUILT_SOURCES= \
mu-help-strings.h
mu-help-strings.h: mu-help-strings.txt mu-help-strings.awk
$(AM_V_GEN) $(AWK) -f ${top_srcdir}/mu/mu-help-strings.awk < $< > $@
mu_LDADD= \
${top_builddir}/lib/libmu.la \
mu_LDADD= \
${top_builddir}/lib/libmu.la \
${top_builddir}/lib/parser/libmuxparser.la \
$(GLIB_LIBS)
EXTRA_DIST= \
mu-help-strings.awk \
EXTRA_DIST= \
mu-help-strings.awk \
mu-help-strings.txt
CLEANFILES=$(BUILT_SOURCES)

View File

@ -48,20 +48,26 @@ typedef gboolean (OutputFunc) (MuMsg *msg, MuMsgIter *iter,
MuConfig *opts, GError **err);
static gboolean
print_xapian_query (MuQuery *xapian, const gchar *query, GError **err)
print_internal (MuQuery *query, const gchar *expr, gboolean xapian,
gboolean warn, GError **err)
{
char *querystr;
char *str;
querystr = mu_query_as_string (xapian, query, err);
if (!querystr)
return FALSE;
if (xapian)
str = mu_query_internal_xapian (query, expr, err);
else
str = mu_query_internal (query, expr, warn, err);
g_print ("%s\n", querystr);
g_free (querystr);
if (str) {
g_print ("%s\n", str);
g_free (str);
}
return TRUE;
return str != NULL;
}
/* returns MU_MSG_FIELD_ID_NONE if there is an error */
static MuMsgFieldId
sort_field_from_string (const char* fieldstr, GError **err)
@ -187,7 +193,7 @@ resolve_bookmark (MuConfig *opts, GError **err)
static gchar*
get_query (MuConfig *opts, GError **err)
{
gchar *query, *bookmarkval;
gchar *query, *bookmarkval;
/* params[0] is 'find', actual search params start with [1] */
if (!opts->bookmark && !opts->params[1]) {
@ -203,7 +209,7 @@ get_query (MuConfig *opts, GError **err)
return NULL;
}
query = mu_str_quoted_from_strv ((const gchar**)&opts->params[1]);
query = g_strjoinv (" ", &opts->params[1]);
if (bookmarkval) {
gchar *tmp;
tmp = g_strdup_printf ("%s %s", bookmarkval, query);
@ -650,11 +656,11 @@ process_query (MuQuery *xapian, const gchar *query, MuConfig *opts, GError **err
static gboolean
execute_find (MuStore *store, MuConfig *opts, GError **err)
{
char *query_str;
MuQuery *oracle;
gboolean rv;
char *query_str;
MuQuery *oracle;
gboolean rv;
oracle = get_query_obj(store, err);
oracle = get_query_obj (store, err);
if (!oracle)
return FALSE;
@ -665,7 +671,10 @@ execute_find (MuStore *store, MuConfig *opts, GError **err)
}
if (opts->format == MU_CONFIG_FORMAT_XQUERY)
rv = print_xapian_query (oracle, query_str, err);
rv = print_internal (oracle, query_str, TRUE, FALSE, err);
else if (opts->format == MU_CONFIG_FORMAT_MQUERY)
rv = print_internal (oracle, query_str, FALSE,
opts->verbose, err);
else
rv = process_query (oracle, query_str, opts, err);
@ -687,6 +696,7 @@ format_params_valid (MuConfig *opts, GError **err)
case MU_CONFIG_FORMAT_LINKS:
case MU_CONFIG_FORMAT_XML:
case MU_CONFIG_FORMAT_XQUERY:
case MU_CONFIG_FORMAT_MQUERY:
if (opts->exec) {
mu_util_g_set_error
(err, MU_ERROR_IN_PARAMETERS,

View File

@ -275,7 +275,7 @@ get_docid_from_msgid (MuQuery *query, const char *str, GError **err)
unsigned docid;
MuMsgIter *iter;
querystr = g_strdup_printf ("msgid:\"%s\"", str);
querystr = g_strdup_printf ("msgid:%s", str);
iter = mu_query_run (query, querystr,
MU_MSG_FIELD_ID_NONE,
1, MU_QUERY_FLAG_NONE, err);
@ -310,7 +310,7 @@ get_docids_from_msgids (MuQuery *query, const char *str, GError **err)
MuMsgIter *iter;
GSList *lst;
querystr = g_strdup_printf ("msgid:\"%s\"", str);
querystr = g_strdup_printf ("msgid:%s", str);
iter = mu_query_run (query, querystr, MU_MSG_FIELD_ID_NONE,
-1 /*unlimited*/, MU_QUERY_FLAG_NONE,
err);
@ -360,7 +360,6 @@ determine_docid (MuQuery *query, GHashTable *args, GError **err)
}
#define DOCID_VALID_OR_ERROR_RETURN(DOCID,E) \
if ((DOCID)==MU_STORE_INVALID_DOCID) { \
mu_util_g_set_error((E),MU_ERROR_IN_PARAMETERS, \

View File

@ -52,7 +52,8 @@ get_output_format (const char *formatstr)
{"plain", MU_CONFIG_FORMAT_PLAIN},
{"sexp", MU_CONFIG_FORMAT_SEXP},
{"xml", MU_CONFIG_FORMAT_XML},
{"xquery", MU_CONFIG_FORMAT_XQUERY}
{"xquery", MU_CONFIG_FORMAT_XQUERY},
{"mquery", MU_CONFIG_FORMAT_MQUERY}
};
for (i = 0; i != G_N_ELEMENTS(formats); i++)

View File

@ -1,7 +1,7 @@
/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/
/*
** Copyright (C) 2008-2013 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2008-2017 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the
@ -55,6 +55,7 @@ enum _MuConfigFormat {
MU_CONFIG_FORMAT_LINKS, /* output as symlinks */
MU_CONFIG_FORMAT_XML, /* output xml */
MU_CONFIG_FORMAT_XQUERY, /* output the xapian query */
MU_CONFIG_FORMAT_MQUERY, /* output the mux query */
MU_CONFIG_FORMAT_EXEC /* execute some command */
};
@ -94,8 +95,8 @@ struct _MuConfig {
MuConfigCmd cmd; /* the command, or
* MU_CONFIG_CMD_NONE */
char *cmdstr; /* cmd string, for user
* info */
char *cmdstr; /* cmd string, for user
* info */
/* general options */
gboolean quiet; /* don't give any output */
gboolean debug; /* spew out debug info */
@ -166,7 +167,6 @@ struct _MuConfig {
* multiple messages in mu
* view */
/* options for cfind (and 'find' --> "after") */
gboolean personal; /* only show 'personal' addresses */
/* also 'after' --> see above */
@ -227,7 +227,6 @@ void mu_config_uninit (MuConfig *conf);
*/
MuError mu_config_execute (MuConfig *conf);
/**
* count the number of non-option parameters
*