ReactOS 0.4.15-dev-8096-ga0eec98
inf.c File Reference
#include <stdarg.h>
#include <string.h>
#include "windef.h"
#include "winbase.h"
#include "winuser.h"
#include "inseng_private.h"
#include "wine/list.h"
Include dependency graph for inf.c:

Go to the source code of this file.

Classes

struct  inf_value
 
struct  inf_section
 
struct  inf_file
 

Functions

static void inf_value_free (struct inf_value *value)
 
static void inf_section_free (struct inf_section *section)
 
static const charget_substitution (struct inf_file *inf, const char *name, int len)
 
static int expand_variables_buffer (struct inf_file *inf, const char *str, char *output)
 
static charexpand_variables (struct inf_file *inf, const char *str)
 
void inf_free (struct inf_file *inf)
 
BOOL inf_next_section (struct inf_file *inf, struct inf_section **sec)
 
struct inf_sectioninf_get_section (struct inf_file *inf, const char *name)
 
charinf_section_get_name (struct inf_section *section)
 
BOOL inf_section_next_value (struct inf_section *sec, struct inf_value **value)
 
struct inf_valueinf_get_value (struct inf_section *sec, const char *key)
 
charinf_value_get_key (struct inf_value *value)
 
charinf_value_get_value (struct inf_value *value)
 
chartrim (char *str, char **last_chr, BOOL strip_quotes)
 
static charget_next_line (char **str, char **last_chr)
 
static HRESULT inf_section_parse (struct inf_file *inf, char *line, char *last_chr, struct inf_section **section)
 
static HRESULT inf_value_parse (struct inf_section *sec, char *line)
 
static HRESULT inf_process_content (struct inf_file *inf)
 
HRESULT inf_load (const char *path, struct inf_file **inf_file)
 

Function Documentation

◆ expand_variables()

static char * expand_variables ( struct inf_file inf,
const char str 
)
static

Definition at line 159 of file inf.c.

160{
161 char *buffer;
162 int len;
163
166 if (!len) return NULL;
167
169 return buffer;
170}
static void * heap_alloc(size_t len)
Definition: appwiz.h:66
#define NULL
Definition: types.h:112
GLuint buffer
Definition: glext.h:5915
GLenum GLsizei len
Definition: glext.h:6722
static int expand_variables_buffer(struct inf_file *inf, const char *str, char *output)
Definition: inf.c:89
const WCHAR * str

Referenced by inf_value_get_value().

◆ expand_variables_buffer()

static int expand_variables_buffer ( struct inf_file inf,
const char str,
char output 
)
static

Definition at line 89 of file inf.c.

90{
91 const char *p, *var_start = NULL;
92 int var_len = 0, len = 0;
93 const char *substitution;
94
95 for (p = str; *p; p++)
96 {
97 if (*p != '%')
98 {
99 if (var_start)
100 var_len++;
101 else
102 {
103 if (output)
104 *output++ = *p;
105 len++;
106 }
107
108 continue;
109 }
110
111 if (!var_start)
112 {
113 var_start = p;
114 var_len = 0;
115
116 continue;
117 }
118
119 if (!var_len)
120 {
121 /* just an escaped % */
122 if (output)
123 *output++ = '%';
124 len += 1;
125
126 var_start = NULL;
127 continue;
128 }
129
130 substitution = get_substitution(inf, var_start + 1, var_len);
131 if (!substitution)
132 {
133 if (output)
134 {
135 memcpy(output, var_start, var_len + 2);
136 output += var_len + 2;
137 }
138 len += var_len + 2;
139 }
140 else
141 {
142 int sub_len = strlen(substitution);
143
144 if (output)
145 {
146 memcpy(output, substitution, sub_len);
147 output += sub_len;
148 }
149 len += sub_len;
150 }
151
152 var_start = NULL;
153 }
154
155 if (output) *output = 0;
156 return len + 1;
157}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLfloat GLfloat p
Definition: glext.h:8902
static const char * get_substitution(struct inf_file *inf, const char *name, int len)
Definition: inf.c:72
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878

Referenced by expand_variables().

◆ get_next_line()

static char * get_next_line ( char **  str,
char **  last_chr 
)
static

Definition at line 296 of file inf.c.

297{
298 BOOL in_next_line = FALSE;
299 char *start, *next;
300
301 start = *str;
302 if (!start || !*start) return NULL;
303
304 for (next = start; *next; next++)
305 {
306 if (*next == '\n' || *next == '\r')
307 {
308 *next = 0;
309 in_next_line = TRUE;
310 }
311 else if (in_next_line)
312 {
313 break;
314 }
315 }
316
317 *str = next;
318 return trim(start, last_chr, FALSE);
319}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
GLuint start
Definition: gl.h:1545
char * trim(char *str, char **last_chr, BOOL strip_quotes)
Definition: inf.c:258
static unsigned __int64 next
Definition: rand_nt.c:6

Referenced by inf_process_content().

◆ get_substitution()

static const char * get_substitution ( struct inf_file inf,
const char name,
int  len 
)
static

Definition at line 72 of file inf.c.

73{
74 struct inf_section *sec;
75 struct inf_value *value = NULL;
76
77 sec = inf_get_section(inf, "Strings");
78 if (!sec) return NULL;
79
80 while (inf_section_next_value(sec, &value))
81 {
82 if (strlen(value->key) == len && !strncasecmp(value->key, name, len))
83 return value->value;
84 }
85
86 return NULL;
87}
#define strncasecmp
Definition: fake.h:10
BOOL inf_section_next_value(struct inf_section *sec, struct inf_value **value)
Definition: inf.c:219
struct inf_section * inf_get_section(struct inf_file *inf, const char *name)
Definition: inf.c:201
Definition: inf.c:31
Definition: name.c:39
Definition: pdh_main.c:94

Referenced by expand_variables_buffer().

◆ inf_free()

void inf_free ( struct inf_file inf)

Definition at line 172 of file inf.c.

173{
174 struct inf_section *sec, *sec_next;
175 LIST_FOR_EACH_ENTRY_SAFE(sec, sec_next, &inf->sections, struct inf_section, entry)
176 {
177 list_remove(&sec->entry);
178 inf_section_free(sec);
179 }
180
181 heap_free(inf->content);
182 heap_free(inf);
183}
static BOOL heap_free(void *mem)
Definition: appwiz.h:76
static void list_remove(struct list_entry *entry)
Definition: list.h:90
static void inf_section_free(struct inf_section *section)
Definition: inf.c:60
uint32_t entry
Definition: isohybrid.c:63
#define LIST_FOR_EACH_ENTRY_SAFE(cursor, cursor2, list, type, field)
Definition: list.h:204
struct list sections
Definition: inf.c:52
char * content
Definition: inf.c:50
struct list entry
Definition: inf.c:41

Referenced by inf_load(), and load_ciffile().

◆ inf_get_section()

struct inf_section * inf_get_section ( struct inf_file inf,
const char name 
)

Definition at line 201 of file inf.c.

202{
203 struct inf_section *sec = NULL;
204
205 while (inf_next_section(inf, &sec))
206 {
207 if (!strcasecmp(sec->name, name))
208 return sec;
209 }
210
211 return NULL;
212}
#define strcasecmp
Definition: fake.h:9
BOOL inf_next_section(struct inf_file *inf, struct inf_section **sec)
Definition: inf.c:185
char * name
Definition: inf.c:42

Referenced by get_substitution().

◆ inf_get_value()

struct inf_value * inf_get_value ( struct inf_section sec,
const char key 
)

Definition at line 235 of file inf.c.

236{
237 struct inf_value *value = NULL;
238
239 while (inf_section_next_value(sec, &value))
240 {
241 if (!strcasecmp(value->key, key))
242 return value;
243 }
244
245 return NULL;
246}
char * value
Definition: inf.c:34
Definition: copy.c:22

Referenced by section_get_dword(), section_get_dword_field(), and section_get_str().

◆ inf_load()

HRESULT inf_load ( const char path,
struct inf_file **  inf_file 
)

Definition at line 405 of file inf.c.

406{
408 struct inf_file *inf;
409 HRESULT hr = E_FAIL;
410 HANDLE file;
411 DWORD read;
412
414 if (file == INVALID_HANDLE_VALUE) return E_FAIL;
415
416 inf = heap_alloc_zero(sizeof(*inf));
417 if (!inf) goto error;
418
420 goto error;
421
422 inf->size = file_size.QuadPart;
423
424 inf->content = heap_alloc_zero(inf->size);
425 if (!inf->content) goto error;
426
427 list_init(&inf->sections);
428
429 if (!ReadFile(file, inf->content, inf->size, &read, NULL) || read != inf->size)
430 goto error;
431
432 hr = inf_process_content(inf);
433 if (FAILED(hr)) goto error;
434
436 *inf_file = inf;
437 return S_OK;
438
439error:
440 if (inf) inf_free(inf);
442 return hr;
443}
#define read
Definition: acwin.h:96
static void list_init(struct list_entry *head)
Definition: list.h:51
#define E_FAIL
Definition: ddrawi.h:102
#define CloseHandle
Definition: compat.h:739
#define OPEN_EXISTING
Definition: compat.h:775
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:740
#define GENERIC_READ
Definition: compat.h:135
#define GetFileSizeEx
Definition: compat.h:757
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
unsigned long DWORD
Definition: ntddk_ex.h:95
void inf_free(struct inf_file *inf)
Definition: inf.c:172
static HRESULT inf_process_content(struct inf_file *inf)
Definition: inf.c:387
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
#define error(str)
Definition: mkdosfs.c:1605
static unsigned int file_size
Definition: regtests2xml.c:47
HRESULT hr
Definition: shlfolder.c:183
Definition: fci.c:127
Definition: inf.c:49
DWORD size
Definition: inf.c:51

Referenced by load_ciffile().

◆ inf_next_section()

BOOL inf_next_section ( struct inf_file inf,
struct inf_section **  sec 
)

Definition at line 185 of file inf.c.

186{
187 struct list *next_entry, *cur_position;
188
189 if (*sec)
190 cur_position = &(*sec)->entry;
191 else
192 cur_position = &inf->sections;
193
194 next_entry = list_next(&inf->sections, cur_position);
195 if (!next_entry) return FALSE;
196
197 *sec = CONTAINING_RECORD(next_entry, struct inf_section, entry);
198 return TRUE;
199}
Definition: list.h:37
__WINE_SERVER_LIST_INLINE struct list * list_next(const struct list *list, const struct list *elem)
Definition: list.h:115
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Referenced by inf_get_section(), and process_inf().

◆ inf_process_content()

static HRESULT inf_process_content ( struct inf_file inf)
static

Definition at line 387 of file inf.c.

388{
389 struct inf_section *section = NULL;
390 char *content = inf->content;
391 char *line, *last_chr;
392 HRESULT hr = S_OK;
393
394 while (SUCCEEDED(hr) && (line = get_next_line(&content, &last_chr)))
395 {
396 if (*line == '[')
397 hr = inf_section_parse(inf, line, last_chr, &section);
398 else if (strchr(line, '=') && section)
400 }
401
402 return hr;
403}
char * strchr(const char *String, int ch)
Definition: utclib.c:501
content
Definition: atl_ax.c:994
static char * get_next_line(char **str, char **last_chr)
Definition: inf.c:296
static HRESULT inf_value_parse(struct inf_section *sec, char *line)
Definition: inf.c:361
static HRESULT inf_section_parse(struct inf_file *inf, char *line, char *last_chr, struct inf_section **section)
Definition: inf.c:323
#define SUCCEEDED(hr)
Definition: intsafe.h:50
Definition: parser.c:49
Definition: parser.c:56

Referenced by inf_load().

◆ inf_section_free()

static void inf_section_free ( struct inf_section section)
static

Definition at line 60 of file inf.c.

61{
62 struct inf_value *val, *val_next;
63 LIST_FOR_EACH_ENTRY_SAFE(val, val_next, &section->values, struct inf_value, entry)
64 {
65 list_remove(&val->entry);
67 }
68
70}
GLuint GLfloat * val
Definition: glext.h:7180
static void inf_value_free(struct inf_value *value)
Definition: inf.c:55

Referenced by inf_free().

◆ inf_section_get_name()

char * inf_section_get_name ( struct inf_section section)

Definition at line 214 of file inf.c.

215{
216 return strdupA(section->name);
217}
static LPSTR strdupA(LPCSTR str)
Definition: mimeole.c:482
const WCHAR * name
Definition: parser.c:57

Referenced by process_inf().

◆ inf_section_next_value()

BOOL inf_section_next_value ( struct inf_section sec,
struct inf_value **  value 
)

Definition at line 219 of file inf.c.

220{
221 struct list *next_entry, *cur_position;
222
223 if (*value)
224 cur_position = &(*value)->entry;
225 else
226 cur_position = &sec->values;
227
228 next_entry = list_next(&sec->values, cur_position);
229 if (!next_entry) return FALSE;
230
231 *value = CONTAINING_RECORD(next_entry, struct inf_value, entry);
232 return TRUE;
233}
struct list values
Definition: inf.c:43

Referenced by get_substitution(), inf_get_value(), and read_urls().

◆ inf_section_parse()

static HRESULT inf_section_parse ( struct inf_file inf,
char line,
char last_chr,
struct inf_section **  section 
)
static

Definition at line 323 of file inf.c.

324{
325 struct inf_section *sec;
326 char *comment;
327 char *name;
328
329 if (*line != '[')
330 return S_OK;
331
332 line++;
333
334 comment = strchr(line, ';');
335 if (comment)
336 {
337 *comment = 0;
338 line = trim(line, &last_chr, FALSE);
339 }
340
341 if (*last_chr != ']')
342 return S_OK;
343
344 *last_chr = 0;
345 name = trim(line, NULL, FALSE);
346 if (!name) return S_OK;
347
348 sec = heap_alloc_zero(sizeof(*sec));
349 if (!sec) return E_OUTOFMEMORY;
350
351 sec->name = name;
352 sec->file = inf;
353 list_init(&sec->values);
354
355 list_add_tail(&inf->sections, &sec->entry);
356
357 *section = sec;
358 return S_OK;
359}
static void list_add_tail(struct list_entry *head, struct list_entry *entry)
Definition: list.h:83
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define comment(fmt, arg1)
Definition: rebar.c:820
struct inf_file * file
Definition: inf.c:45

Referenced by inf_process_content().

◆ inf_value_free()

static void inf_value_free ( struct inf_value value)
static

Definition at line 55 of file inf.c.

56{
58}

Referenced by inf_section_free().

◆ inf_value_get_key()

char * inf_value_get_key ( struct inf_value value)

Definition at line 248 of file inf.c.

249{
250 return strdupA(value->key);
251}

Referenced by read_urls().

◆ inf_value_get_value()

char * inf_value_get_value ( struct inf_value value)

Definition at line 253 of file inf.c.

254{
255 return expand_variables(value->section->file, value->value);
256}
static char * expand_variables(struct inf_file *inf, const char *str)
Definition: inf.c:159

Referenced by section_get_dword(), section_get_str(), and value_get_str_field().

◆ inf_value_parse()

static HRESULT inf_value_parse ( struct inf_section sec,
char line 
)
static

Definition at line 361 of file inf.c.

362{
363 struct inf_value *key_val;
364 char *key, *value, *del;
365
366 del = strchr(line, '=');
367 if (!del) return S_OK;
368
369 *del = 0;
370 key = line;
371 value = del + 1;
372
373 key = trim(key, NULL, FALSE);
374 value = trim(value, NULL, TRUE);
375
376 key_val = heap_alloc_zero(sizeof(*key_val));
377 if (!key_val) return E_OUTOFMEMORY;
378
379 key_val->key = key;
380 key_val->value = value;
381 key_val->section = sec;
382
383 list_add_tail(&sec->values, &key_val->entry);
384 return S_OK;
385}
static VOID del(LPHIST_ENTRY item)
Definition: history.c:199
struct list entry
Definition: inf.c:32
char * key
Definition: inf.c:33
struct inf_section * section
Definition: inf.c:36

Referenced by inf_process_content().

◆ trim()

char * trim ( char str,
char **  last_chr,
BOOL  strip_quotes 
)

Definition at line 258 of file inf.c.

259{
260 char *last;
261
262 for (; *str; str++)
263 {
264 if (*str != '\t' && *str != ' ')
265 break;
266 }
267
268 if (!*str)
269 {
270 if (last_chr) *last_chr = str;
271 return str;
272 }
273
274 last = str + strlen(str) - 1;
275
276 for (; last > str; last--)
277 {
278 if (*last != '\t' && *last != ' ')
279 break;
280 *last = 0;
281 }
282
283 if (strip_quotes && last != str)
284 {
285 if (*last == '"' && *str == '"')
286 {
287 str++;
288 *last = 0;
289 }
290 }
291
292 if (last_chr) *last_chr = last;
293 return str;
294}
static void strip_quotes(WCHAR *word, WCHAR **end)
Definition: xcopy.c:701
static UINT UINT last
Definition: font.c:45

Referenced by NurbsTessellator::do_endsurface(), get_next_line(), inf_section_parse(), inf_value_parse(), next_part(), and o_trim_to_DLineLoops().