1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
---|
2 | /* This file is part of the GtkHTML widget. |
---|
3 | |
---|
4 | Copyright (C) 1999 Helix Code, Inc. |
---|
5 | |
---|
6 | This library is free software; you can redistribute it and/or |
---|
7 | modify it under the terms of the GNU Library General Public |
---|
8 | License as published by the Free Software Foundation; either |
---|
9 | version 2 of the License, or (at your option) any later version. |
---|
10 | |
---|
11 | This library 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 GNU |
---|
14 | Library General Public License for more details. |
---|
15 | |
---|
16 | You should have received a copy of the GNU Library General Public License |
---|
17 | along with this library; see the file COPYING.LIB. If not, write to |
---|
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
19 | Boston, MA 02111-1307, USA. |
---|
20 | |
---|
21 | Author: Ettore Perazzoli <ettore@gnu.org> |
---|
22 | */ |
---|
23 | |
---|
24 | #include <config.h> |
---|
25 | #include "htmlengine.h" |
---|
26 | #include "htmlstack.h" |
---|
27 | |
---|
28 | |
---|
29 | HTMLStack * |
---|
30 | html_stack_new (HTMLStackFreeFunc free_func) |
---|
31 | { |
---|
32 | HTMLStack *new; |
---|
33 | |
---|
34 | new = g_new (HTMLStack, 1); |
---|
35 | new->free_func = free_func; |
---|
36 | new->list = NULL; |
---|
37 | |
---|
38 | return new; |
---|
39 | } |
---|
40 | |
---|
41 | void |
---|
42 | html_stack_clear (HTMLStack *stack) |
---|
43 | { |
---|
44 | GList *p; |
---|
45 | |
---|
46 | if (stack->free_func != NULL) |
---|
47 | for (p = stack->list; p != NULL; p = p->next) |
---|
48 | (* stack->free_func) (p->data); |
---|
49 | |
---|
50 | g_list_free (stack->list); |
---|
51 | stack->list = NULL; |
---|
52 | } |
---|
53 | |
---|
54 | void |
---|
55 | html_stack_destroy (HTMLStack *stack) |
---|
56 | { |
---|
57 | html_stack_clear (stack); |
---|
58 | g_free (stack); |
---|
59 | } |
---|
60 | |
---|
61 | gpointer |
---|
62 | html_stack_pop (HTMLStack *stack) |
---|
63 | { |
---|
64 | GList *first; |
---|
65 | gpointer data; |
---|
66 | |
---|
67 | g_return_val_if_fail (! html_stack_is_empty (stack), NULL); |
---|
68 | |
---|
69 | first = stack->list; |
---|
70 | stack->list = g_list_remove_link (stack->list, first); |
---|
71 | |
---|
72 | data = first->data; |
---|
73 | g_list_free (first); |
---|
74 | |
---|
75 | return data; |
---|
76 | } |
---|
77 | |
---|
78 | gpointer |
---|
79 | html_stack_top (HTMLStack *stack) |
---|
80 | { |
---|
81 | if (stack->list == NULL) |
---|
82 | return NULL; |
---|
83 | |
---|
84 | return stack->list->data; |
---|
85 | } |
---|
86 | |
---|
87 | void |
---|
88 | html_stack_push (HTMLStack *stack, |
---|
89 | gpointer data) |
---|
90 | { |
---|
91 | stack->list = g_list_prepend (stack->list, data); |
---|
92 | } |
---|
93 | |
---|
94 | gboolean |
---|
95 | html_stack_is_empty (HTMLStack *stack) |
---|
96 | { |
---|
97 | return stack->list == NULL; |
---|
98 | } |
---|
99 | |
---|
100 | guint |
---|
101 | html_stack_count (HTMLStack *stack) |
---|
102 | { |
---|
103 | return g_list_length (stack->list); |
---|
104 | } |
---|