1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 Copyright (C) 2004 Sebastien Granjoux
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 * File data read in .wiz file
24 *---------------------------------------------------------------------------*/
30 #include <glib/gdir.h>
32 /*---------------------------------------------------------------------------*/
34 #define STRING_CHUNK_SIZE 256
36 /*---------------------------------------------------------------------------*/
41 GStringChunk
* string_pool
;
55 NPW_EXECUTE_FILE
= 1 << 0,
56 NPW_PROJECT_FILE
= 1 << 1,
57 NPW_AUTOGEN_SET
= 1 << 2,
58 NPW_AUTOGEN_FILE
= 1 << 3
62 *---------------------------------------------------------------------------*/
65 npw_file_new (NPWFileList
* owner
)
69 g_return_val_if_fail (owner
, NULL
);
71 this = g_chunk_new0(NPWFile
, owner
->data_pool
);
73 this->node
= g_node_append_data (owner
->list
, this);
80 npw_file_free (NPWFile
* this)
84 node
= g_node_find_child (this->owner
->list
, G_TRAVERSE_ALL
, this);
87 g_node_destroy (node
);
88 /* Memory allocated in string pool and project pool is not free */
93 npw_file_set_type (NPWFile
* this, NPWFileType type
)
99 npw_file_get_type (const NPWFile
* this)
105 npw_file_set_destination (NPWFile
* this, const gchar
* destination
)
107 this->destination
= g_string_chunk_insert (this->owner
->string_pool
, destination
);
111 npw_file_get_destination (const NPWFile
* this)
113 return this->destination
;
117 npw_file_set_source (NPWFile
* this, const gchar
* source
)
119 this->source
= g_string_chunk_insert (this->owner
->string_pool
, source
);
123 npw_file_get_source (const NPWFile
* this)
129 npw_file_set_execute (NPWFile
* this, gboolean value
)
133 this->attribute
|= NPW_EXECUTE_FILE
;
137 this->attribute
&= ~NPW_EXECUTE_FILE
;
142 npw_file_get_execute (const NPWFile
* this)
144 return this->attribute
& NPW_EXECUTE_FILE
;
148 npw_file_set_project (NPWFile
* this, gboolean value
)
152 this->attribute
|= NPW_PROJECT_FILE
;
156 this->attribute
&= ~NPW_PROJECT_FILE
;
161 npw_file_get_project (const NPWFile
* this)
163 return this->attribute
& NPW_PROJECT_FILE
;
167 npw_file_set_autogen (NPWFile
* this, NPWFileBooleanValue value
)
172 this->attribute
|= NPW_AUTOGEN_FILE
| NPW_AUTOGEN_SET
;
175 this->attribute
|= NPW_AUTOGEN_SET
;
176 this->attribute
&= ~NPW_AUTOGEN_FILE
;
178 case NPW_FILE_DEFAULT
:
179 this->attribute
&= ~(NPW_AUTOGEN_SET
| NPW_AUTOGEN_FILE
);
185 npw_file_get_autogen (const NPWFile
* this)
187 return this->attribute
& NPW_AUTOGEN_SET
? (this->attribute
& NPW_AUTOGEN_FILE
? NPW_FILE_TRUE
: NPW_FILE_FALSE
) : NPW_FILE_DEFAULT
;
191 npw_file_next (const NPWFile
* this)
193 GNode
* node
= this->node
->next
;
195 return node
== NULL
? NULL
: (NPWFile
*)node
->data
;
199 *---------------------------------------------------------------------------*/
202 npw_file_list_new (void)
206 this = g_new (NPWFileList
, 1);
207 this->string_pool
= g_string_chunk_new (STRING_CHUNK_SIZE
);
208 this->data_pool
= g_mem_chunk_new ("file pool", sizeof (NPWFile
), STRING_CHUNK_SIZE
* sizeof (NPWFile
) / 4, G_ALLOC_ONLY
);
209 this->list
= g_node_new (NULL
);
215 npw_file_list_free (NPWFileList
* this)
217 g_return_if_fail (this != NULL
);
219 g_string_chunk_free (this->string_pool
);
220 g_mem_chunk_destroy (this->data_pool
);
221 g_node_destroy (this->list
);
226 cb_file_list_foreach_file (GNode
* node
, gpointer data
)
228 ((NPWFileForeachFunc
)data
)((NPWFile
*)node
->data
);
232 npw_file_list_foreach_file (const NPWFileList
* this, NPWFileForeachFunc func
)
234 g_node_children_foreach (this->list
, G_TRAVERSE_LEAFS
, cb_file_list_foreach_file
, (gpointer
)func
);
238 npw_file_list_first (const NPWFileList
* this)
240 /* Should work even if first child is NULL (empty list) */
241 GNode
* node
= g_node_first_child (this->list
);
243 return node
== NULL
? NULL
: (NPWFile
*)node
->data
;