1 /* Copyright (c) 2007 Mark Nevill
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
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.
29 #include <basedir_fs.h>
31 void printAndFreeString(const char *string
)
33 printf("%s\n", string
);
37 void printAndFreeStringList(const char * const *strings
)
39 const char * const *item
;
40 for (item
= strings
; *item
; ++item
)
42 printf("%s\n", *item
);
45 free((const char **)strings
);
48 int main(int argc
, char *argv
[])
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
));
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
));
80 else if (strcmp(datatype
, "cache") == 0)
82 if (strcmp(querytype
, "home") == 0)
83 printAndFreeString(xdgCacheHome(NULL
));
87 else if (strcmp(datatype
, "runtime") == 0)
89 if (strcmp(querytype
, "directory") == 0)
91 char *rd
= xdgRuntimeDirectory(NULL
);
92 if (!rd
) printf("(null)\n");
93 else printAndFreeString(rd
);