Merged older cs.po file with newest pot file.
[gliv/czech_localization.git] / src / pathset.c
blob72ca2816927135f59cf0f0fd504891b3c4f402bc
1 /*
2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License
4 * as published by the Free Software Foundation; either version 2
5 * of the License, or (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 * See the COPYING file for license information.
18 * Guillaume Chazarain <guichaz@yahoo.fr>
21 /***************************************************
22 * A data structure to keep track of visited files *
23 ***************************************************/
25 #include <sys/types.h> /* dev_t, ino_t */
26 #include <sys/stat.h> /* struct stat, stat() */
27 #include <stdio.h> /* perror() */
29 #include "gliv.h"
30 #include "pathset.h"
33 * Files informations saved into
34 * the AVL to uniquely identify them.
36 typedef struct {
37 dev_t dev;
38 ino_t ino;
39 } file_info;
41 /* To build and search the AVL. */
42 static gint cmp_func(const file_info * file1, const file_info * file2)
44 if (file1->ino < file2->ino)
45 return -1;
47 if (file1->ino > file2->ino)
48 return 1;
50 if (file1->dev < file2->dev)
51 return -1;
53 return file1->dev > file2->dev;
56 struct pathset *pathset_new(void)
58 struct pathset *set = g_new(struct pathset, 1);
60 set->tree = g_tree_new_full((GCompareDataFunc) cmp_func, NULL,
61 g_free, NULL);
63 return set;
66 /* Return TRUE if the file has been correctly inserted. */
67 gboolean pathset_add(struct pathset * set, const gchar * path)
69 struct stat st;
70 file_info *file;
72 if (stat(path, &st) < 0) {
73 perror(path);
74 return FALSE;
77 file = g_new(file_info, 1);
79 file->dev = st.st_dev;
80 file->ino = st.st_ino;
82 if (g_tree_lookup(set->tree, file) != NULL) {
83 g_free(file);
84 return FALSE;
87 g_tree_insert(set->tree, file, file);
88 return TRUE;
91 void pathset_free(struct pathset *set)
93 g_tree_destroy(set->tree);
94 g_free(set);