Debian Codegraph @

src/main/refcache.c

raw symbols SCIP
1 /*
2 * Object cache for Gutenprint
3 *
4 * Copyright 2017 Robert Krawitz ([email protected])
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20 #include <gutenprint/gutenprint.h>cxx . . $ `<file>/include/gutenprint/gutenprint.h`/
21 #include "gutenprint-internal.h"cxx . . $ `<file>/src/main/gutenprint-internal.h`/
22 #include <gutenprint/gutenprint-intl-internal.h>cxx . . $ `<file>/include/gutenprint/gutenprint-intl-internal.h`/
23 #include <ctype.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <math.h>
28 #include <errno.h>
29
30 /*
31 * Lists aren't exactly the right data structure for this...if we start
32 * getting into enough items for it to matter, we'll reimplement it them.
33 */
34
35 static stp_list_tcxx . . $ stp_list_t# *global_cache_listcxx . . $ global_cache_list. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
36 static stp_string_list_tcxx . . $ stp_string_list_t# *global_cache_namescxx . . $ global_cache_names. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
37
38 typedef struct stp_cachecxx . . $ stp_cache#
39 {
40 char *namecxx . . $ stp_cache#name.;
41 stp_list_tcxx . . $ stp_list_t# *cachecxx . . $ stp_cache#cache.;
42 stp_string_list_tcxx . . $ stp_string_list_t# *cache_itemscxx . . $ stp_cache#cache_items.;
43 } stp_refcache_tcxx . . $ stp_refcache_t#;
44
45 typedef structcxx . . $ $anonymous_type_f9d94ba9ff0049fd_0#
46 {
47 char *namecxx . . $ $anonymous_type_f9d94ba9ff0049fd_0#name.;
48 void *contentcxx . . $ $anonymous_type_f9d94ba9ff0049fd_0#content.;
49 } stp_refcache_item_tcxx . . $ stp_refcache_item_t#;
50
51 static const char *
52 stp_refcache_namefunccxx . . $ stp_refcache_namefunc(6271d96ae060557f).(const void *cache)
53 {
54 return ((const stp_refcache_tcxx . . $ stp_refcache_t# *) cache)->namecxx . . $ stp_cache#name.;
55 }
56
57 static void
58 stp_refcache_freefunccxx . . $ stp_refcache_freefunc(5d22bdacc48458e8).(void *item)
59 {
60 stp_refcache_tcxx . . $ stp_refcache_t# *cache = (stp_refcache_tcxx . . $ stp_refcache_t# *) item;
61 STP_SAFE_FREEcxx . . $ `include/gutenprint/util.h:210:9`!(cache->name);
62 stp_list_destroycxx . . $ stp_list_destroy(29ae8ff464c7f7e5).(cache->cachecxx . . $ stp_cache#cache.);
63 stp_string_list_destroycxx . . $ stp_string_list_destroy(73d8582195bcdbb3).(cache->cache_itemscxx . . $ stp_cache#cache_items.);
64 STP_SAFE_FREEcxx . . $ `include/gutenprint/util.h:210:9`!(item);
65 }
66
67 static const char *
68 stp_refcache_item_namefunccxx . . $ stp_refcache_item_namefunc(6271d96ae060557f).(const void *item)
69 {
70 return ((const stp_refcache_item_tcxx . . $ stp_refcache_item_t# *) item)->namecxx . . $ $anonymous_type_f9d94ba9ff0049fd_0#name.;
71 }
72
73 static void
74 stp_refcache_item_freefunccxx . . $ stp_refcache_item_freefunc(5d22bdacc48458e8).(void *item)
75 {
76 stp_refcache_item_tcxx . . $ stp_refcache_item_t# *cache_item = (stp_refcache_item_tcxx . . $ stp_refcache_item_t# *) item;
77 STP_SAFE_FREEcxx . . $ `include/gutenprint/util.h:210:9`!(cache_item->name);
78 STP_SAFE_FREEcxx . . $ `include/gutenprint/util.h:210:9`!(item);
79 }
80
81 static void
82 check_stp_cachecxx . . $ check_stp_cache(49f6e7a06ebc5aa8).(void)
83 {
84 if (! global_cache_listcxx . . $ global_cache_list.)
85 {
86 global_cache_listcxx . . $ global_cache_list. = stp_list_createcxx . . $ stp_list_create(728167c67729d082).();
87 stp_list_set_namefunccxx . . $ stp_list_set_namefunc(83503c4472347457).(global_cache_listcxx . . $ global_cache_list., stp_refcache_namefunccxx . . $ stp_refcache_namefunc(6271d96ae060557f).);
88 stp_list_set_freefunccxx . . $ stp_list_set_freefunc(309a84c3f950ef37).(global_cache_listcxx . . $ global_cache_list., stp_refcache_freefunccxx . . $ stp_refcache_freefunc(5d22bdacc48458e8).);
89 global_cache_namescxx . . $ global_cache_names. = stp_string_list_createcxx . . $ stp_string_list_create(f262b3b5e10fad14).();
90 }
91 }
92
93 int
94 stp_refcache_createcxx . . $ stp_refcache_create(5c4306d8553b3696).(const char *name)
95 {
96 check_stp_cachecxx . . $ check_stp_cache(49f6e7a06ebc5aa8).();
97 if (stp_list_get_item_by_namecxx . . $ stp_list_get_item_by_name(27765cfe86595311).(global_cache_listcxx . . $ global_cache_list., name))
98 return 0;
99 else
100 {
101 stp_refcache_tcxx . . $ stp_refcache_t# *cache = stp_zalloccxx . . $ stp_zalloc(bfcfa4d6b7f7ef64).(sizeof(stp_refcache_tcxx . . $ stp_refcache_t#));
102 cache->namecxx . . $ stp_cache#name. = stp_strdupcxx . . $ stp_strdup(a8b8e32347182212).(name);
103 cache->cachecxx . . $ stp_cache#cache. = stp_list_createcxx . . $ stp_list_create(728167c67729d082).();
104 cache->cache_itemscxx . . $ stp_cache#cache_items. = stp_string_list_createcxx . . $ stp_string_list_create(f262b3b5e10fad14).();
105 stp_list_set_namefunccxx . . $ stp_list_set_namefunc(83503c4472347457).(cache->cachecxx . . $ stp_cache#cache., stp_refcache_item_namefunccxx . . $ stp_refcache_item_namefunc(6271d96ae060557f).);
106 stp_list_set_freefunccxx . . $ stp_list_set_freefunc(309a84c3f950ef37).(cache->cachecxx . . $ stp_cache#cache., stp_refcache_item_freefunccxx . . $ stp_refcache_item_freefunc(5d22bdacc48458e8).);
107 stp_list_item_createcxx . . $ stp_list_item_create(54f08bf465e39eec).(global_cache_listcxx . . $ global_cache_list., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, cache);
108 stp_string_list_add_string_unsafecxx . . $ stp_string_list_add_string_unsafe(61ec312b340c2952).(global_cache_namescxx . . $ global_cache_names., name, name);
109 return 1;
110 }
111 }
112
113 static stp_refcache_tcxx . . $ stp_refcache_t# *
114 find_cache_namedcxx . . $ find_cache_named(349d3f0425e15b35).(const char *cache)
115 {
116 check_stp_cachecxx . . $ check_stp_cache(49f6e7a06ebc5aa8).();
117 stp_list_item_tcxx . . $ stp_list_item_t# *item = stp_list_get_item_by_namecxx . . $ stp_list_get_item_by_name(27765cfe86595311).(global_cache_listcxx . . $ global_cache_list., cache);
118 if (item)
119 return (stp_refcache_tcxx . . $ stp_refcache_t# *) stp_list_item_get_datacxx . . $ stp_list_item_get_data(9a5daa75441a53b5).(item);
120 else
121 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
122 }
123
124 static stp_refcache_tcxx . . $ stp_refcache_t# *
125 find_or_create_cache_namedcxx . . $ find_or_create_cache_named(349d3f0425e15b35).(const char *cache)
126 {
127 check_stp_cachecxx . . $ check_stp_cache(49f6e7a06ebc5aa8).();
128 stp_list_item_tcxx . . $ stp_list_item_t# *item = stp_list_get_item_by_namecxx . . $ stp_list_get_item_by_name(27765cfe86595311).(global_cache_listcxx . . $ global_cache_list., cache);
129 if (!item)
130 {
131 stp_refcache_createcxx . . $ stp_refcache_create(5c4306d8553b3696).(cache);
132 item = stp_list_get_item_by_namecxx . . $ stp_list_get_item_by_name(27765cfe86595311).(global_cache_listcxx . . $ global_cache_list., cache);
133 }
134 return (stp_refcache_tcxx . . $ stp_refcache_t# *) stp_list_item_get_datacxx . . $ stp_list_item_get_data(9a5daa75441a53b5).(item);
135 }
136
137 void *
138 stp_refcache_find_itemcxx . . $ stp_refcache_find_item(12e6862c879384a7).(const char *cache, const char *item)
139 {
140 stp_refcache_tcxx . . $ stp_refcache_t# *cache_impl = find_cache_namedcxx . . $ find_cache_named(349d3f0425e15b35).(cache);
141 if (cache_impl)
142 {
143 stp_list_item_tcxx . . $ stp_list_item_t# *item_impl =
144 stp_list_get_item_by_namecxx . . $ stp_list_get_item_by_name(27765cfe86595311).(cache_impl->cachecxx . . $ stp_cache#cache., item);
145 if (item_impl)
146 return ((stp_refcache_item_tcxx . . $ stp_refcache_item_t# *)stp_list_item_get_datacxx . . $ stp_list_item_get_data(9a5daa75441a53b5).(item_impl))->contentcxx . . $ $anonymous_type_f9d94ba9ff0049fd_0#content.;
147 }
148 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
149 }
150
151 static void
152 add_item_to_cachecxx . . $ add_item_to_cache(3a3fd35c66055ffc).(stp_refcache_tcxx . . $ stp_refcache_t# *cache, const char *item, void *data)
153 {
154 stp_refcache_item_tcxx . . $ stp_refcache_item_t# *item_impl = stp_zalloccxx . . $ stp_zalloc(bfcfa4d6b7f7ef64).(sizeof(stp_refcache_item_tcxx . . $ stp_refcache_item_t#));
155 item_impl->namecxx . . $ $anonymous_type_f9d94ba9ff0049fd_0#name. = stp_strdupcxx . . $ stp_strdup(a8b8e32347182212).(item);
156 item_impl->contentcxx . . $ $anonymous_type_f9d94ba9ff0049fd_0#content. = data;
157 stp_list_item_createcxx . . $ stp_list_item_create(54f08bf465e39eec).(cache->cachecxx . . $ stp_cache#cache., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, item_impl);
158 stp_string_list_add_string_unsafecxx . . $ stp_string_list_add_string_unsafe(61ec312b340c2952).(cache->cache_itemscxx . . $ stp_cache#cache_items., item, item);
159 }
160
161 int
162 stp_refcache_add_itemcxx . . $ stp_refcache_add_item(285a709643be31b2).(const char *cache, const char *item, void *data)
163 {
164 stp_refcache_tcxx . . $ stp_refcache_t# *cache_impl = find_or_create_cache_namedcxx . . $ find_or_create_cache_named(349d3f0425e15b35).(cache);
165 if (!stp_list_get_item_by_namecxx . . $ stp_list_get_item_by_name(27765cfe86595311).(cache_impl->cachecxx . . $ stp_cache#cache., item))
166 {
167 add_item_to_cachecxx . . $ add_item_to_cache(3a3fd35c66055ffc).(cache_impl, item, data);
168 return 1;
169 }
170 return 0;
171 }
172
173 void
174 stp_refcache_remove_itemcxx . . $ stp_refcache_remove_item(2fa786934fe80e24).(const char *cache, const char *item)
175 {
176 stp_refcache_tcxx . . $ stp_refcache_t# *cache_impl = find_cache_namedcxx . . $ find_cache_named(349d3f0425e15b35).(cache);
177 if (cache_impl)
178 {
179 stp_list_item_tcxx . . $ stp_list_item_t# *item_impl =
180 stp_list_get_item_by_namecxx . . $ stp_list_get_item_by_name(27765cfe86595311).(cache_impl->cachecxx . . $ stp_cache#cache., item);
181 if (item_impl)
182 {
183 stp_list_item_destroycxx . . $ stp_list_item_destroy(e8436428ff1ae51).(cache_impl->cachecxx . . $ stp_cache#cache., item_impl);
184 stp_string_list_remove_stringcxx . . $ stp_string_list_remove_string(24ca7d3bba3c474e).(cache_impl->cache_itemscxx . . $ stp_cache#cache_items., item);
185 }
186 }
187 }
188
189 void
190 stp_refcache_replace_itemcxx . . $ stp_refcache_replace_item(df89878491499fa2).(const char *cache, const char *item, void *data)
191 {
192 stp_refcache_tcxx . . $ stp_refcache_t# *cache_impl = find_or_create_cache_namedcxx . . $ find_or_create_cache_named(349d3f0425e15b35).(cache);
193 stp_list_item_tcxx . . $ stp_list_item_t# *item_item =
194 stp_list_get_item_by_namecxx . . $ stp_list_get_item_by_name(27765cfe86595311).(cache_impl->cachecxx . . $ stp_cache#cache., item);
195 if (item_item)
196 {
197 stp_refcache_item_tcxx . . $ stp_refcache_item_t# *item_impl =
198 (stp_refcache_item_tcxx . . $ stp_refcache_item_t# *) stp_list_item_get_datacxx . . $ stp_list_item_get_data(9a5daa75441a53b5).(item_item);
199 item_impl->contentcxx . . $ $anonymous_type_f9d94ba9ff0049fd_0#content. = data;
200 }
201 else
202 {
203 add_item_to_cachecxx . . $ add_item_to_cache(3a3fd35c66055ffc).(cache_impl, item, data);
204 }
205 }
206
207 void
208 stp_refcache_destroycxx . . $ stp_refcache_destroy(85c52e162fed56f9).(const char *cache)
209 {
210 check_stp_cachecxx . . $ check_stp_cache(49f6e7a06ebc5aa8).();
211 stp_list_item_tcxx . . $ stp_list_item_t# *item = stp_list_get_item_by_namecxx . . $ stp_list_get_item_by_name(27765cfe86595311).(global_cache_listcxx . . $ global_cache_list., cache);
212 if (item)
213 {
214 stp_list_item_destroycxx . . $ stp_list_item_destroy(e8436428ff1ae51).(global_cache_listcxx . . $ global_cache_list., item);
215 stp_string_list_remove_stringcxx . . $ stp_string_list_remove_string(24ca7d3bba3c474e).(global_cache_namescxx . . $ global_cache_names., cache);
216 }
217 }
218
219 const stp_string_list_tcxx . . $ stp_string_list_t# *
220 stp_refcache_list_cachescxx . . $ stp_refcache_list_caches(d2430923a0b59d05).(void)
221 {
222 check_stp_cachecxx . . $ check_stp_cache(49f6e7a06ebc5aa8).();
223 return global_cache_namescxx . . $ global_cache_names.;
224 }
225
226 const stp_string_list_tcxx . . $ stp_string_list_t# *
227 stp_refcache_list_cache_itemscxx . . $ stp_refcache_list_cache_items(f2f2e30b05a373a0).(const char *cache)
228 {
229 stp_refcache_tcxx . . $ stp_refcache_t# *cache_impl = find_cache_namedcxx . . $ find_cache_named(349d3f0425e15b35).(cache);
230 return cache_impl ? cache_impl->cache_itemscxx . . $ stp_cache#cache_items. : NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
231 }