* updates for new mu_str escaping function, better error handling

This commit is contained in:
djcb 2012-03-30 19:02:46 +03:00
parent 2a105f1612
commit e7e84ed08a
3 changed files with 15 additions and 7 deletions

View File

@ -216,7 +216,7 @@ cmd_from_string (const char *str)
static Cmd
parse_line (const gchar *line, GSList **args)
parse_line (const gchar *line, GSList **args, GError **err)
{
Cmd cmd;
GSList *lst;
@ -226,7 +226,7 @@ parse_line (const gchar *line, GSList **args)
if (!line)
return CMD_IGNORE;
lst = mu_str_esc_to_list (line);
lst = mu_str_esc_to_list (line, err);
if (!lst)
return CMD_INVALID;
@ -1014,9 +1014,12 @@ mu_cmd_server (MuStore *store, MuConfig *opts, GError **err)
GError *my_err;
line = my_readline (MU_PROMPT);
cmd = parse_line (line, &args);
cmd = parse_line (line, &args, err);
g_free (line);
if (cmd == CMD_INVALID)
my_err = NULL;
if (!handle_command (cmd, store, query, args, &my_err))
g_clear_error (&my_err);

View File

@ -194,7 +194,10 @@ get_query (MuQuery *mqx, const char* searchexpr, GError **err)
Xapian::Query query;
char *preprocessed;
preprocessed = mu_query_preprocess (searchexpr);
preprocessed = mu_query_preprocess (searchexpr, err);
if (!preprocessed)
throw std::runtime_error
("parse error while preprocessing query");
try {
query = mqx->query_parser().parse_query
@ -278,7 +281,7 @@ mu_query_destroy (MuQuery *self)
/* preprocess a query to make them a bit more promiscuous */
char*
mu_query_preprocess (const char *query)
mu_query_preprocess (const char *query, GError **err)
{
GSList *parts, *cur;
gchar *myquery;
@ -287,7 +290,9 @@ mu_query_preprocess (const char *query)
/* convert the query to a list of query terms, and escape them
* separately */
parts = mu_str_esc_to_list (query);
parts = mu_str_esc_to_list (query, err);
if (!parts)
return NULL;
for (cur = parts; cur; cur = g_slist_next(cur)) {
/* remove accents and turn to lower-case */

View File

@ -113,7 +113,7 @@ char* mu_query_as_string (MuQuery *self, const char* searchexpr, GError **err)
*
* @return a pre-processed query, free it with g_free
*/
char* mu_query_preprocess (const char *query)
char* mu_query_preprocess (const char *query, GError **err)
G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
G_END_DECLS