Merge branch 'development', bumped version to 1.1.1, adjusted libtool version info.
[libxdg-basedir.git] / tests / testquery.c
blob75359aface9a0c3c09c7875a4539d456abb85455
1 /* Copyright (c) 2007 Mark Nevill
2 *
3 * Permission is hereby granted, free of charge, to any person
4 * obtaining a copy of this software and associated documentation
5 * files (the "Software"), to deal in the Software without
6 * restriction, including without limitation the rights to use,
7 * copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following
10 * conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include <string.h>
28 #include <basedir.h>
29 #include <basedir_fs.h>
31 void printAndFreeString(const char *string)
33 printf("%s\n", string);
34 free((char*)string);
37 void printAndFreeStringList(const char * const *strings)
39 const char * const *item;
40 for (item = strings; *item; ++item)
42 printf("%s\n", *item);
43 free((char*)*item);
45 free((const char **)strings);
48 int main(int argc, char *argv[])
50 if (argc < 3)
51 return 1;
52 char *datatype = argv[1];
53 char *querytype = argv[2];
54 if (strcmp(datatype, "data") == 0)
56 if (strcmp(querytype, "home") == 0)
57 printAndFreeString(xdgDataHome(NULL));
58 else if (strcmp(querytype, "dirs") == 0)
59 printAndFreeStringList(xdgDataDirectories(NULL));
60 else if (strcmp(querytype, "search") == 0)
61 printAndFreeStringList(xdgSearchableDataDirectories(NULL));
62 else if (strcmp(querytype, "find") == 0 && argc == 4)
63 printAndFreeString(xdgDataFind(argv[3], NULL));
64 else
65 return 1;
67 else if (strcmp(datatype, "config") == 0)
69 if (strcmp(querytype, "home") == 0)
70 printAndFreeString(xdgConfigHome(NULL));
71 else if (strcmp(querytype, "dirs") == 0)
72 printAndFreeStringList(xdgConfigDirectories(NULL));
73 else if (strcmp(querytype, "search") == 0)
74 printAndFreeStringList(xdgSearchableConfigDirectories(NULL));
75 else if (strcmp(querytype, "find") == 0 && argc == 4)
76 printAndFreeString(xdgConfigFind(argv[3], NULL));
77 else
78 return 1;
80 else if (strcmp(datatype, "cache") == 0)
82 if (strcmp(querytype, "home") == 0)
83 printAndFreeString(xdgCacheHome(NULL));
84 else
85 return 1;
87 else
88 return 1;
89 return 0;