GCC Code Coverage Report


Directory: ./
File: panels/applications/globs.c
Date: 2024-05-04 07:58:27
Exec Total Coverage
Lines: 0 16 0.0%
Functions: 0 1 0.0%
Branches: 0 12 0.0%

Line Branch Exec Source
1 /* globs.c
2 *
3 * Copyright 2018 Matthias Clasen <matthias.clasen@gmail.com>
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 * SPDX-License-Identifier: GPL-3.0-or-later
19 */
20
21 #include <config.h>
22
23 #include "globs.h"
24
25 /* parse mime/globs and return a string->string hash table */
26 GHashTable *
27 parse_globs (void)
28 {
29 GHashTable *globs;
30 const gchar * const *dirs;
31 gint i;
32
33 globs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
34
35 dirs = g_get_system_data_dirs ();
36
37 for (i = 0; dirs[i]; i++)
38 {
39 g_autofree gchar *file = g_build_filename (dirs[i], "mime", "globs", NULL);
40 g_autofree gchar *contents = NULL;
41
42 if (g_file_get_contents (file, &contents, NULL, NULL))
43 {
44 g_auto(GStrv) strv = NULL;
45 int i;
46
47 strv = g_strsplit (contents, "\n", 0);
48 for (i = 0; strv[i]; i++)
49 {
50 g_auto(GStrv) parts = NULL;
51
52 if (strv[i][0] == '#' || strv[i][0] == '\0')
53 continue;
54
55 parts = g_strsplit (strv[i], ":", 2);
56 g_hash_table_insert (globs, g_strdup (parts[0]), g_strdup (parts[1]));
57 }
58 }
59 }
60
61 return globs;
62 }
63