| 1 | /* |
| 2 | * Copyright (C) 1998,1999,2000 Ross Combs ([email protected]) |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; either version 2 |
| 7 | * of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 | */ |
| 18 | #include "common/setup_before.h"cxx . . $ `<file>/src/common/setup_before.h`/ |
| 19 | #define LIST_INTERNAL_ACCESScxx . . $ `src/common/list.cpp:19:9`! |
| 20 | #include "common/list.h"cxx . . $ `<file>/src/common/list.h`/ |
| 21 | |
| 22 | #include <cassert> |
| 23 | |
| 24 | #include "common/eventlog.h"cxx . . $ `<file>/src/common/eventlog.h`/ |
| 25 | #include "common/xalloc.h"cxx . . $ `<file>/src/common/xalloc.h`/ |
| 26 | #include "common/setup_after.h"cxx . . $ `<file>/src/common/setup_after.h`/ |
| 27 | |
| 28 | |
| 29 | namespace pvpgncxx . . $ pvpgn/ |
| 30 | { |
| 31 | |
| 32 | static t_elemcxx . . $ pvpgn/t_elem# listheadcxx . . $ pvpgn/listhead.; |
| 33 | |
| 34 | |
| 35 | extern t_listcxx . . $ pvpgn/t_list# * list_createcxx . . $ pvpgn/list_create(7a6cb11de248e2c9).(void) |
| 36 | { |
| 37 | t_listcxx . . $ pvpgn/t_list# * newl; |
| 38 | |
| 39 | newl = (t_listcxx . . $ pvpgn/t_list#*)xmalloccxx . . $ `src/common/xalloc.h:43:9`!(sizeof(t_list)); |
| 40 | newl->headcxx . . $ pvpgn/list#head. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 41 | newl->tailcxx . . $ pvpgn/list#tail. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 42 | newl->lencxx . . $ pvpgn/list#len. = 0; |
| 43 | |
| 44 | return newl; |
| 45 | } |
| 46 | |
| 47 | |
| 48 | extern int list_destroycxx . . $ pvpgn/list_destroy(20db0232078327de).(t_listcxx . . $ pvpgn/t_list# * list) |
| 49 | { |
| 50 | if (!list) |
| 51 | { |
| 52 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL list"); |
| 53 | return -1; |
| 54 | } |
| 55 | |
| 56 | if (list->headcxx . . $ pvpgn/list#head.) |
| 57 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got non-empty list"); |
| 58 | |
| 59 | xfreecxx . . $ `src/common/xalloc.h:51:9`!(list); |
| 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | extern unsigned int list_get_lengthcxx . . $ pvpgn/list_get_length(ff288adc7992d0f0).(t_listcxx . . $ pvpgn/t_list# const * list) |
| 65 | { |
| 66 | if (!list) |
| 67 | { |
| 68 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL list"); |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | return list->lencxx . . $ pvpgn/list#len.; |
| 73 | } |
| 74 | |
| 75 | |
| 76 | extern int list_prepend_datacxx . . $ pvpgn/list_prepend_data(4e1348bd294d996f).(t_listcxx . . $ pvpgn/t_list# * list, void * data) |
| 77 | { |
| 78 | t_elemcxx . . $ pvpgn/t_elem# * elem; |
| 79 | |
| 80 | assertcxx . . $ `/usr/include/assert.h:102:11`!(list != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!); |
| 81 | |
| 82 | elem = (t_elemcxx . . $ pvpgn/t_elem#*)xmalloccxx . . $ `src/common/xalloc.h:43:9`!(sizeof(t_elem)); |
| 83 | elem->datacxx . . $ pvpgn/elem#data. = data; |
| 84 | |
| 85 | if (list->headcxx . . $ pvpgn/list#head.) |
| 86 | list->headcxx . . $ pvpgn/list#head.->prevcxx . . $ pvpgn/elem#prev. = elem; |
| 87 | elem->nextcxx . . $ pvpgn/elem#next. = list->headcxx . . $ pvpgn/list#head.; |
| 88 | elem->prevcxx . . $ pvpgn/elem#prev. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 89 | list->headcxx . . $ pvpgn/list#head. = elem; |
| 90 | if (!list->tailcxx . . $ pvpgn/list#tail.) |
| 91 | list->tailcxx . . $ pvpgn/list#tail. = elem; |
| 92 | list->lencxx . . $ pvpgn/list#len.++; |
| 93 | |
| 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | |
| 98 | extern int list_append_datacxx . . $ pvpgn/list_append_data(4e1348bd294d996f).(t_listcxx . . $ pvpgn/t_list# * list, void * data) |
| 99 | { |
| 100 | t_elemcxx . . $ pvpgn/t_elem# * elem; |
| 101 | |
| 102 | assertcxx . . $ `/usr/include/assert.h:102:11`!(list != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!); |
| 103 | |
| 104 | elem = (t_elemcxx . . $ pvpgn/t_elem#*)xmalloccxx . . $ `src/common/xalloc.h:43:9`!(sizeof(t_elem)); |
| 105 | elem->datacxx . . $ pvpgn/elem#data. = data; |
| 106 | |
| 107 | elem->nextcxx . . $ pvpgn/elem#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 108 | if (!list->headcxx . . $ pvpgn/list#head.) |
| 109 | { |
| 110 | list->headcxx . . $ pvpgn/list#head. = elem; |
| 111 | elem->prevcxx . . $ pvpgn/elem#prev. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 112 | } |
| 113 | if (list->tailcxx . . $ pvpgn/list#tail.) |
| 114 | { |
| 115 | elem->prevcxx . . $ pvpgn/elem#prev. = list->tailcxx . . $ pvpgn/list#tail.; |
| 116 | list->tailcxx . . $ pvpgn/list#tail.->nextcxx . . $ pvpgn/elem#next. = elem; |
| 117 | } |
| 118 | list->tailcxx . . $ pvpgn/list#tail. = elem; |
| 119 | list->lencxx . . $ pvpgn/list#len.++; |
| 120 | |
| 121 | return 0; |
| 122 | } |
| 123 | |
| 124 | |
| 125 | extern t_elemcxx . . $ pvpgn/t_elem# * list_get_elem_by_datacxx . . $ pvpgn/list_get_elem_by_data(40e7e4c5deb9256f).(t_listcxx . . $ pvpgn/t_list# const * list, void const * data) |
| 126 | { |
| 127 | t_elemcxx . . $ pvpgn/t_elem# * curr; |
| 128 | |
| 129 | if (!list) |
| 130 | { |
| 131 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL list"); |
| 132 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 133 | } |
| 134 | |
| 135 | LIST_TRAVERSEcxx . . $ `src/common/list.h:94:9`!(list, curr) |
| 136 | if (curr->datacxx . . $ pvpgn/elem#data. == data) |
| 137 | return curr; |
| 138 | |
| 139 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 140 | } |
| 141 | |
| 142 | |
| 143 | extern t_elemcxx . . $ pvpgn/t_elem# const * list_get_elem_by_data_constcxx . . $ pvpgn/list_get_elem_by_data_const(67eec86352770251).(t_listcxx . . $ pvpgn/t_list# const * list, void const * data) |
| 144 | { |
| 145 | t_elemcxx . . $ pvpgn/t_elem# const * curr; |
| 146 | |
| 147 | if (!list) |
| 148 | { |
| 149 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL list"); |
| 150 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 151 | } |
| 152 | |
| 153 | LIST_TRAVERSE_CONSTcxx . . $ `src/common/list.h:95:9`!(list, curr) |
| 154 | if (curr->datacxx . . $ pvpgn/elem#data. == data) |
| 155 | return curr; |
| 156 | |
| 157 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 158 | } |
| 159 | |
| 160 | |
| 161 | extern int list_remove_elemcxx . . $ pvpgn/list_remove_elem(17f7246ce0d3563b).(t_listcxx . . $ pvpgn/t_list# * list, t_elemcxx . . $ pvpgn/t_elem# ** elem) |
| 162 | { |
| 163 | t_elemcxx . . $ pvpgn/t_elem# * target; |
| 164 | |
| 165 | if (!list) |
| 166 | { |
| 167 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL list"); |
| 168 | return -1; |
| 169 | } |
| 170 | |
| 171 | if (!elem) |
| 172 | { |
| 173 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL *elem"); |
| 174 | return -1; |
| 175 | } |
| 176 | |
| 177 | target = *elem; |
| 178 | |
| 179 | if (target->prevcxx . . $ pvpgn/elem#prev.) |
| 180 | { |
| 181 | target->prevcxx . . $ pvpgn/elem#prev.->nextcxx . . $ pvpgn/elem#next. = target->nextcxx . . $ pvpgn/elem#next.; |
| 182 | } |
| 183 | if (target->nextcxx . . $ pvpgn/elem#next.) |
| 184 | { |
| 185 | target->nextcxx . . $ pvpgn/elem#next.->prevcxx . . $ pvpgn/elem#prev. = target->prevcxx . . $ pvpgn/elem#prev.; |
| 186 | } |
| 187 | |
| 188 | if (target == list->tailcxx . . $ pvpgn/list#tail.) |
| 189 | { |
| 190 | list->tailcxx . . $ pvpgn/list#tail. = target->prevcxx . . $ pvpgn/elem#prev.; |
| 191 | } |
| 192 | if (target == list->headcxx . . $ pvpgn/list#head.) |
| 193 | { |
| 194 | list->headcxx . . $ pvpgn/list#head. = target->nextcxx . . $ pvpgn/elem#next.; |
| 195 | *elem = &listheadcxx . . $ pvpgn/listhead.; |
| 196 | } |
| 197 | else |
| 198 | *elem = target->prevcxx . . $ pvpgn/elem#prev.; |
| 199 | |
| 200 | target->nextcxx . . $ pvpgn/elem#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 201 | target->prevcxx . . $ pvpgn/elem#prev. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 202 | xfreecxx . . $ `src/common/xalloc.h:51:9`!(target); |
| 203 | |
| 204 | list->lencxx . . $ pvpgn/list#len.--; |
| 205 | |
| 206 | return 0; |
| 207 | } |
| 208 | |
| 209 | |
| 210 | extern int list_remove_datacxx . . $ pvpgn/list_remove_data(9d29d8ce7cabbadf).(t_listcxx . . $ pvpgn/t_list# * list, void const * data, t_elemcxx . . $ pvpgn/t_elem# ** elem) |
| 211 | { |
| 212 | if (!list) |
| 213 | { |
| 214 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL list"); |
| 215 | return -1; |
| 216 | } |
| 217 | |
| 218 | if (!(*elem = list_get_elem_by_datacxx . . $ pvpgn/list_get_elem_by_data(40e7e4c5deb9256f).(list, data))) |
| 219 | return -1; |
| 220 | |
| 221 | return list_remove_elemcxx . . $ pvpgn/list_remove_elem(17f7246ce0d3563b).(list, elem); |
| 222 | } |
| 223 | |
| 224 | |
| 225 | extern int elem_set_datacxx . . $ pvpgn/elem_set_data(2e15c5bce6954e6f).(t_elemcxx . . $ pvpgn/t_elem# * elem, void * data) |
| 226 | { |
| 227 | if (!elem) |
| 228 | { |
| 229 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL elem"); |
| 230 | return -1; |
| 231 | } |
| 232 | |
| 233 | elem->datacxx . . $ pvpgn/elem#data. = data; |
| 234 | |
| 235 | return 0; |
| 236 | } |
| 237 | |
| 238 | |
| 239 | extern void * elem_get_datacxx . . $ pvpgn/elem_get_data(317ff0e7f02bf2b).(t_elemcxx . . $ pvpgn/t_elem# const * elem) |
| 240 | { |
| 241 | if (!elem) |
| 242 | { |
| 243 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL elem"); |
| 244 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 245 | } |
| 246 | |
| 247 | return elem->datacxx . . $ pvpgn/elem#data.; |
| 248 | } |
| 249 | |
| 250 | |
| 251 | extern void * list_get_data_by_poscxx . . $ pvpgn/list_get_data_by_pos(d30ef5e498f6a2b5).(t_listcxx . . $ pvpgn/t_list# const * list, unsigned int pos) |
| 252 | { |
| 253 | t_elemcxx . . $ pvpgn/t_elem# const * curr; |
| 254 | unsigned int len; |
| 255 | |
| 256 | len = 0; |
| 257 | LIST_TRAVERSE_CONSTcxx . . $ `src/common/list.h:95:9`!(list, curr) |
| 258 | if (len++ == pos) |
| 259 | return curr->datacxx . . $ pvpgn/elem#data.; |
| 260 | |
| 261 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "requested position {} but len={}", pos, len); |
| 262 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 263 | } |
| 264 | |
| 265 | |
| 266 | #ifdef LIST_DEBUG |
| 267 | extern t_elem * list_get_first_real(t_list const * list, char const * fn, unsigned int ln) |
| 268 | #else |
| 269 | extern t_elemcxx . . $ pvpgn/t_elem# * list_get_firstcxx . . $ pvpgn/list_get_first(3c68161990c025).(t_listcxx . . $ pvpgn/t_list# const * list) |
| 270 | #endif |
| 271 | { |
| 272 | if (!list) |
| 273 | { |
| 274 | #ifdef LIST_DEBUG |
| 275 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL list from {}:{}", fn, ln); |
| 276 | #else |
| 277 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL list"); |
| 278 | #endif |
| 279 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 280 | } |
| 281 | |
| 282 | |
| 283 | return list->headcxx . . $ pvpgn/list#head.; |
| 284 | } |
| 285 | |
| 286 | |
| 287 | #ifdef LIST_DEBUG |
| 288 | extern t_elem const * list_get_first_const_real(t_list const * list, char const * fn, unsigned int ln) |
| 289 | #else |
| 290 | extern t_elemcxx . . $ pvpgn/t_elem# const * list_get_first_constcxx . . $ pvpgn/list_get_first_const(261bb17b741dc343).(t_listcxx . . $ pvpgn/t_list# const * list) |
| 291 | #endif |
| 292 | { |
| 293 | if (!list) |
| 294 | { |
| 295 | #ifdef LIST_DEBUG |
| 296 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL list from {}:{}", fn, ln); |
| 297 | #else |
| 298 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL list"); |
| 299 | #endif |
| 300 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 301 | } |
| 302 | |
| 303 | return list->headcxx . . $ pvpgn/list#head.; |
| 304 | } |
| 305 | |
| 306 | |
| 307 | extern t_elemcxx . . $ pvpgn/t_elem# * elem_get_next_realcxx . . $ pvpgn/elem_get_next_real(fc7553926d64b7c4).(t_listcxx . . $ pvpgn/t_list# const * list, t_elemcxx . . $ pvpgn/t_elem# const * elem, char const * fn, unsigned int ln) |
| 308 | { |
| 309 | if (!elem) |
| 310 | { |
| 311 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL elem from {}:{}", fn, ln); |
| 312 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 313 | } |
| 314 | |
| 315 | if (elem == &listheadcxx . . $ pvpgn/listhead.) |
| 316 | return list->headcxx . . $ pvpgn/list#head.; |
| 317 | else |
| 318 | return elem->nextcxx . . $ pvpgn/elem#next.; |
| 319 | } |
| 320 | |
| 321 | |
| 322 | extern t_elemcxx . . $ pvpgn/t_elem# const * elem_get_next_constcxx . . $ pvpgn/elem_get_next_const(80a79b023e17a464).(t_listcxx . . $ pvpgn/t_list# const * list, t_elemcxx . . $ pvpgn/t_elem# const * elem) |
| 323 | { |
| 324 | if (!elem) |
| 325 | { |
| 326 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL elem"); |
| 327 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 328 | } |
| 329 | |
| 330 | if (elem == &listheadcxx . . $ pvpgn/listhead.) |
| 331 | return list->headcxx . . $ pvpgn/list#head.; |
| 332 | else |
| 333 | return elem->nextcxx . . $ pvpgn/elem#next.; |
| 334 | } |
| 335 | |
| 336 | } |