]>
Commit | Line | Data |
---|---|---|
4e0938ef | 1 | /* |
5b74111a | 2 | * Copyright (C) 1996-2018 The Squid Software Foundation and contributors |
4e0938ef AJ |
3 | * |
4 | * Squid software is distributed under GPLv2+ license and includes | |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
7 | */ | |
8 | ||
25f98340 | 9 | // XXX: This file is made of large pieces of src/tools.cc |
0d9a5f13 | 10 | // with only a few minor modifications. TODO: redesign or delete. |
11 | ||
582c2af2 FC |
12 | #include "squid.h" |
13 | #include "dlink.h" | |
21d845b1 | 14 | #include <iostream> |
4c50505b | 15 | |
16 | void | |
17 | xassert(const char *msg, const char *file, int line) | |
18 | { | |
19 | std::cout << "Assertion failed: (" << msg << ") at " << file << ":" << line << std::endl; | |
20 | exit (1); | |
21 | } | |
4c50505b | 22 | |
f5691f9c | 23 | void |
af6a12ee AJ |
24 | dlinkAdd(void *data, dlink_node * m, dlink_list * list) |
25 | { | |
f5691f9c | 26 | m->data = data; |
27 | m->prev = NULL; | |
28 | m->next = list->head; | |
29 | ||
30 | if (list->head) | |
31 | list->head->prev = m; | |
32 | ||
33 | list->head = m; | |
34 | ||
35 | if (list->tail == NULL) | |
36 | list->tail = m; | |
37 | } | |
38 | ||
39 | void | |
af6a12ee AJ |
40 | dlinkAddAfter(void *data, dlink_node * m, dlink_node * n, dlink_list * list) |
41 | { | |
f5691f9c | 42 | m->data = data; |
43 | m->prev = n; | |
44 | m->next = n->next; | |
45 | ||
46 | if (n->next) | |
47 | n->next->prev = m; | |
48 | else { | |
49 | assert(list->tail == n); | |
50 | list->tail = m; | |
51 | } | |
52 | ||
53 | n->next = m; | |
54 | } | |
55 | ||
56 | void | |
af6a12ee AJ |
57 | dlinkAddTail(void *data, dlink_node * m, dlink_list * list) |
58 | { | |
f5691f9c | 59 | m->data = data; |
60 | m->next = NULL; | |
61 | m->prev = list->tail; | |
62 | ||
63 | if (list->tail) | |
64 | list->tail->next = m; | |
65 | ||
66 | list->tail = m; | |
67 | ||
68 | if (list->head == NULL) | |
69 | list->head = m; | |
70 | } | |
71 | ||
72 | void | |
af6a12ee AJ |
73 | dlinkDelete(dlink_node * m, dlink_list * list) |
74 | { | |
f5691f9c | 75 | if (m->next) |
76 | m->next->prev = m->prev; | |
77 | ||
78 | if (m->prev) | |
79 | m->prev->next = m->next; | |
80 | ||
81 | if (m == list->head) | |
82 | list->head = m->next; | |
83 | ||
84 | if (m == list->tail) | |
85 | list->tail = m->prev; | |
86 | ||
87 | m->next = m->prev = NULL; | |
88 | } | |
f53969cc | 89 |