Ejemplo n.º 1
0
static gboolean
execute_find (MuStore *store, MuConfig *opts, GError **err)
{
	char *query_str;
	MuQuery *oracle;
	gboolean rv;

	oracle = get_query_obj(store, err);
	if (!oracle)
		return FALSE;

	query_str = get_query (opts, err);
	if (!query_str) {
		mu_query_destroy (oracle);
		return FALSE;
	}

	if (opts->format == MU_CONFIG_FORMAT_XQUERY)
		rv = print_xapian_query (oracle, query_str, err);
	else
		rv = process_query (oracle, query_str, opts, err);

	mu_query_destroy (oracle);
	g_free (query_str);

	return rv;
}
Ejemplo n.º 2
0
MuError
mu_cmd_server (MuStore *store, MuConfig *opts/*unused*/, GError **err)
{
	ServerContext ctx;
	gboolean do_quit;

	g_return_val_if_fail (store, MU_ERROR_INTERNAL);

	ctx.store = store;
	ctx.query = mu_query_new (store, err);
	if (!ctx.query)
		return MU_G_ERROR_CODE (err);

	srand (time(NULL)*getpid());

	install_sig_handler ();

	g_print (";; welcome to " PACKAGE_STRING "\n");

	/*  the main REPL */
	do_quit = FALSE;
	while (!MU_TERMINATE && !do_quit) {

		GHashTable	*args;
		GError		*my_err;

		/* args will receive a the command as a list of
		 * strings. returning NULL indicates an error */
		my_err = NULL;
		args   = read_command_line (&my_err);
		if (!args) {
			if (feof(stdin))
				break;
			if (my_err)
				print_and_clear_g_error (&my_err);
			continue;
		}

		switch (handle_args (&ctx, args, &my_err)) {
		case MU_OK:
			break;
		case MU_STOP:
			do_quit = TRUE;
			break;
		default: /* some error occurred */
			print_and_clear_g_error (&my_err);
		}

		g_hash_table_destroy (args);
	}

	mu_store_flush   (ctx.store);
	mu_query_destroy (ctx.query);

	return MU_OK;
}
Ejemplo n.º 3
0
static void
mu_guile_uninit_instance (void)
{
	g_return_if_fail (_singleton);

	mu_query_destroy (_singleton->query);
	g_free (_singleton);

	_singleton = NULL;

	mu_runtime_uninit ();
}
Ejemplo n.º 4
0
static MuMsgIter *
run_query (const char *xpath, const char *query, MugMsgListView * self)
{
	GError *err;
	MuQuery *xapian;
	MuMsgIter *iter;
	MuStore *store;
	MuQueryFlags qflags;

	err = NULL;
	if (! (store = mu_store_new_read_only (xpath, &err)) ||
	    ! (xapian = mu_query_new (store, &err))) {
		if (store)
			mu_store_unref (store);
		g_warning ("Error: %s", err->message);
		g_signal_emit (G_OBJECT (self),
			       signals[MUG_ERROR_OCCURED], 0,
			       mu_result_to_mug_error (err->code));
		g_error_free (err);
		return NULL;
	}
	mu_store_unref (store);

	qflags =
		MU_QUERY_FLAG_DESCENDING         |
		MU_QUERY_FLAG_SKIP_UNREADABLE    |
		MU_QUERY_FLAG_SKIP_DUPS          |
		MU_QUERY_FLAG_THREADS;

	iter = mu_query_run (xapian, query, MU_MSG_FIELD_ID_DATE,
			     -1, qflags, &err);
	mu_query_destroy (xapian);
	if (!iter) {
		g_warning ("Error: %s", err->message);
		g_signal_emit (G_OBJECT (self),
			       signals[MUG_ERROR_OCCURED], 0,
			       mu_result_to_mug_error (err->code));
		g_error_free (err);
		return NULL;
	}

	return iter;
}