1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
/*
Scriver
Copyright (c) 2000-09 Miranda ICQ/IM project,
all portions of this codebase are copyrighted to the people
listed in contributors.txt.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "stdafx.h"
TCmdList* tcmdlist_append(TCmdList *list, char *data, int maxSize, BOOL temporary)
{
if (!data)
return list;
TCmdList *new_list = (TCmdList *)mir_calloc(sizeof(TCmdList));
new_list->temporary = temporary;
new_list->szCmd = data;
TCmdList *attach_to = nullptr;
for (TCmdList *n = list; n != nullptr; n = n->next)
attach_to = n;
if (attach_to == nullptr)
return new_list;
new_list->prev = attach_to;
attach_to->next = new_list;
if (tcmdlist_len(list) > maxSize)
list = tcmdlist_remove_first(list);
return list;
}
TCmdList* tcmdlist_remove_first(TCmdList *list)
{
TCmdList *n = list;
if (n->next) n->next->prev = n->prev;
if (n->prev) n->prev->next = n->next;
list = n->next;
mir_free(n->szCmd);
mir_free(n);
return list;
}
TCmdList* tcmdlist_remove(TCmdList *list, TCmdList *n)
{
if (n->next) n->next->prev = n->prev;
if (n->prev) n->prev->next = n->next;
if (n == list) list = n->next;
mir_free(n->szCmd);
mir_free(n);
return list;
}
int tcmdlist_len(TCmdList *list)
{
int i = 0;
for (TCmdList *n = list; n != nullptr; n = n->next)
i++;
return i;
}
TCmdList* tcmdlist_last(TCmdList *list)
{
for (TCmdList *n = list; n != nullptr; n = n->next)
if (!n->next)
return n;
return nullptr;
}
void tcmdlist_free(TCmdList *&list)
{
TCmdList *n = list;
while (n != nullptr) {
auto *next = n->next;
mir_free(n->szCmd);
mir_free(n);
n = next;
}
list = nullptr;
}
|