Permalink
Newer
Older
100644 57 lines (49 sloc) 1.68 KB
1
/* notmuch - Not much of an email program, (just index and search)
2
*
3
* Copyright © 2009 Carl Worth
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see http://www.gnu.org/licenses/ .
17
*
18
* Author: Carl Worth <cworth@cworth.org>
19
*/
20
21
#include "notmuch-client.h"
22
23
/* Construct a single query string from the passed arguments, using
24
* 'ctx' as the talloc owner for all allocations.
25
*
26
* Currently, the arguments are just connected with space characters,
27
* but we might do more processing in the future, (such as inserting
28
* any AND operators needed to work around Xapian QueryParser bugs).
29
*
30
* This function returns NULL in case of insufficient memory.
31
*/
32
char *
33
query_string_from_args (void *ctx, int argc, char *argv[])
34
{
35
char *query_string;
36
int i;
37
38
query_string = talloc_strdup (ctx, "");
39
if (query_string == NULL)
40
return NULL;
41
42
for (i = 0; i < argc; i++) {
43
if (i != 0) {
44
query_string = talloc_strdup_append (query_string, " ");
45
if (query_string == NULL)
46
return NULL;
47
}
48
49
query_string = talloc_strdup_append (query_string, argv[i]);
50
if (query_string == NULL)
51
return NULL;
52
}
53
54
return query_string;
55
}
56