ReactOS 0.4.16-dev-122-g325d74c
list.c File Reference
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "config.h"
#include "compat.h"
#include "list.h"
#include "util.h"
#include "options.h"
Include dependency graph for list.c:

Go to the source code of this file.

Functions

PLIST_MEMBER entry_lookup (PLIST list, char *name)
 
PLIST_MEMBER entry_delete (PLIST_MEMBER pentry)
 
PLIST_MEMBER entry_insert (PLIST list, PLIST_MEMBER pentry)
 
void list_clear (PLIST list)
 
PLIST_MEMBER cache_entry_create (char *Line)
 
PLIST_MEMBER sources_entry_create (PLIST list, char *path, char *prefix)
 

Function Documentation

◆ cache_entry_create()

PLIST_MEMBER cache_entry_create ( char Line)

Definition at line 119 of file list.c.

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}
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
#define malloc
Definition: debug_ros.c:4
#define NULL
Definition: types.h:112
GLdouble s
Definition: gl.h:2039
_Check_return_ _CRTIMP int __cdecl sscanf(_In_z_ const char *_Src, _In_z_ _Scanf_format_string_ const char *_Format,...)
#define INVALID_BASE
Definition: config.h:5
PLIST_MEMBER entry_delete(PLIST_MEMBER pentry)
Definition: list.c:47
#define l2l_dbg(level,...)
Definition: util.h:35
Definition: ncftp.h:79
size_t ImageBase
Definition: list.h:8
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

Referenced by read_cache().

◆ entry_delete()

PLIST_MEMBER entry_delete ( PLIST_MEMBER  pentry)

Definition at line 47 of file list.c.

48{
49 if (!pentry)
50 return NULL;
51 if (pentry->buf)
52 free(pentry->buf);
53 free(pentry);
54 return NULL;
55}
#define free
Definition: debug_ros.c:5

Referenced by cache_entry_create(), list_clear(), and sources_entry_create().

◆ entry_insert()

PLIST_MEMBER entry_insert ( PLIST  list,
PLIST_MEMBER  pentry 
)

Definition at line 58 of file list.c.

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}
Definition: list.h:37
struct entry_struct * pnext
Definition: list.h:11

Referenced by read_cache(), and sources_entry_create().

◆ entry_lookup()

PLIST_MEMBER entry_lookup ( PLIST  list,
char name 
)

Definition at line 19 of file list.c.

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}
#define PATHCMP
Definition: compat.h:32
Definition: name.c:39

Referenced by handle_address_cmd(), match_mod(), sources_entry_create(), and translate_file().

◆ list_clear()

void list_clear ( PLIST  list)

Definition at line 70 of file list.c.

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}

Referenced by main().

◆ sources_entry_create()

PLIST_MEMBER sources_entry_create ( PLIST  list,
char path,
char prefix 
)

Definition at line 173 of file list.c.

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}
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
PLIST_MEMBER entry_insert(PLIST list, PLIST_MEMBER pentry)
Definition: list.c:58
PLIST_MEMBER entry_lookup(PLIST list, char *name)
Definition: list.c:19

Referenced by print_offset().