ReactOS 0.4.16-dev-197-g92996da
list.c
Go to the documentation of this file.
1/*
2 * ReactOS log2lines
3 * Written by Jan Roeloffzen
4 *
5 * - List handling
6 */
7
8#include <stdio.h>
9#include <string.h>
10#include <stdlib.h>
11
12#include "config.h"
13#include "compat.h"
14#include "list.h"
15#include "util.h"
16#include "options.h"
17
20{
21 PLIST_MEMBER pprev = NULL;
22 PLIST_MEMBER pnext;
23
24 if (!name || !name[0])
25 return NULL;
26
27 pnext = list->phead;
28 while (pnext != NULL)
29 {
30 if (PATHCMP(name, pnext->name) == 0)
31 {
32 if (pprev)
33 { // move to head for faster lookup next time
34 pprev->pnext = pnext->pnext;
35 pnext->pnext = list->phead;
36 list->phead = pnext;
37 }
38 return pnext;
39 }
40 pprev = pnext;
41 pnext = pnext->pnext;
42 }
43 return NULL;
44}
45
48{
49 if (!pentry)
50 return NULL;
51 if (pentry->buf)
52 free(pentry->buf);
53 free(pentry);
54 return NULL;
55}
56
59{
60 if (!pentry)
61 return NULL;
62
63 pentry->pnext = list->phead;
64 list->phead = pentry;
65 if (!list->ptail)
66 list->ptail = pentry;
67 return pentry;
68}
69
71{
72 PLIST_MEMBER pentry = list->phead;
73 PLIST_MEMBER pnext;
74 while (pentry)
75 {
76 pnext = pentry->pnext;
77 entry_delete(pentry);
78 pentry = pnext;
79 }
80 list->phead = list->ptail = NULL;
81}
82
83#if 0
85entry_remove(LIST *list, LIST_MEMBER *pentry)
86{
87 LIST_MEMBER *pprev = NULL, *p = NULL;
88
89 if (!pentry)
90 return NULL;
91
92 if (pentry == list->phead)
93 {
94 list->phead = pentry->pnext;
95 p = pentry;
96 }
97 else
98 {
99 pprev = list->phead;
100 while (pprev->pnext)
101 {
102 if (pprev->pnext == pentry)
103 {
104 pprev->pnext = pentry->pnext;
105 p = pentry;
106 break;
107 }
108 pprev = pprev->pnext;
109 }
110 }
111 if (pentry == list->ptail)
112 list->ptail = pprev;
113
114 return p;
115}
116#endif
117
120{
121 PLIST_MEMBER pentry;
122 char *s = NULL;
123 int l;
124
125 if (!Line)
126 return NULL;
127
128 pentry = malloc(sizeof(LIST_MEMBER));
129 if (!pentry)
130 return NULL;
131
132 l = strlen(Line);
133 pentry->buf = s = malloc(l + 1);
134 if (!s)
135 {
136 l2l_dbg(1, "Alloc entry failed\n");
137 return entry_delete(pentry);
138 }
139
140 strcpy(s, Line);
141 if (s[l] == '\n')
142 s[l] = '\0';
143
144 pentry->name = s;
145 s = strchr(s, '|');
146 if (!s)
147 {
148 l2l_dbg(1, "Name field missing\n");
149 return entry_delete(pentry);
150 }
151 *s++ = '\0';
152
153 pentry->path = s;
154 s = strchr(s, '|');
155 if (!s)
156 {
157 l2l_dbg(1, "Path field missing\n");
158 return entry_delete(pentry);
159 }
160 *s++ = '\0';
161 if (1 != sscanf(s, "%x", (unsigned int *)(&pentry->ImageBase)))
162 {
163 l2l_dbg(1, "ImageBase field missing\n");
164 return entry_delete(pentry);
165 }
166 pentry->RelBase = INVALID_BASE;
167 pentry->Size = 0;
168 return pentry;
169}
170
171
173sources_entry_create(PLIST list, char *path, char *prefix)
174{
175 PLIST_MEMBER pentry;
176 char *s = NULL;
177 int l;
178
179 if (!path)
180 return NULL;
181 if (!prefix)
182 prefix = "";
183
184 pentry = malloc(sizeof(LIST_MEMBER));
185 if (!pentry)
186 return NULL;
187
188 l = strlen(path) + strlen(prefix);
189 pentry->buf = s = malloc(l + 1);
190 if (!s)
191 {
192 l2l_dbg(1, "Alloc entry failed\n");
193 return entry_delete(pentry);
194 }
195
196 strcpy(s, prefix);
197 strcat(s, path);
198 if (s[l] == '\n')
199 s[l] = '\0';
200
201 pentry->name = s;
202 if (list)
203 {
204 if (entry_lookup(list, pentry->name))
205 {
206 l2l_dbg(1, "Entry %s exists\n", pentry->name);
207 pentry = entry_delete(pentry);
208 }
209 else
210 {
211 l2l_dbg(1, "Inserting entry %s\n", pentry->name);
212 entry_insert(list, pentry);
213 }
214 }
215
216 return pentry;
217}
218
219/* EOF */
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
char * strchr(const char *String, int ch)
Definition: utclib.c:501
r l[0]
Definition: byte_order.h:168
Definition: list.h:37
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define NULL
Definition: types.h:112
GLdouble s
Definition: gl.h:2039
GLfloat GLfloat p
Definition: glext.h:8902
_Check_return_ _CRTIMP int __cdecl sscanf(_In_z_ const char *_Src, _In_z_ _Scanf_format_string_ const char *_Format,...)
#define PATHCMP
Definition: compat.h:32
#define INVALID_BASE
Definition: config.h:5
PLIST_MEMBER entry_insert(PLIST list, PLIST_MEMBER pentry)
Definition: list.c:58
PLIST_MEMBER cache_entry_create(char *Line)
Definition: list.c:119
PLIST_MEMBER entry_delete(PLIST_MEMBER pentry)
Definition: list.c:47
void list_clear(PLIST list)
Definition: list.c:70
PLIST_MEMBER entry_lookup(PLIST list, char *name)
Definition: list.c:19
PLIST_MEMBER sources_entry_create(PLIST list, char *path, char *prefix)
Definition: list.c:173
#define l2l_dbg(level,...)
Definition: util.h:35
Definition: ncftp.h:79
size_t ImageBase
Definition: list.h:8
struct entry_struct * pnext
Definition: list.h:11
size_t Size
Definition: list.h:10
char * buf
Definition: list.h:5
char * path
Definition: list.h:7
size_t RelBase
Definition: list.h:9
char * name
Definition: list.h:6
Definition: name.c:39