ReactOS 0.4.15-dev-8348-gc1b9bb5
infcore.c File Reference
#include "inflib.h"
#include <debug.h>
Include dependency graph for infcore.c:

Go to the source code of this file.

Classes

struct  parser
 

Macros

#define NDEBUG
 
#define CONTROL_Z   '\x1a'
 
#define MAX_SECTION_NAME_LEN   255
 
#define MAX_FIELD_LEN   511 /* larger fields get silently truncated */
 
#define MAX_STRING_LEN   (MAX_INF_STRING_LENGTH+1)
 

Typedefs

typedef const WCHAR *(* parser_state_func) (struct parser *parser, const WCHAR *pos)
 

Enumerations

enum  parser_state {
  HEADER , PARSE_WIN31_LINE , LINE_START , KEY_NAME ,
  DELETE_KEY , DEFAULT_VALUE_NAME , QUOTED_VALUE_NAME , DATA_START ,
  DELETE_VALUE , DATA_TYPE , STRING_DATA , DWORD_DATA ,
  HEX_DATA , EOL_BACKSLASH , HEX_MULTILINE , UNKNOWN_DATA ,
  SET_VALUE , NB_PARSER_STATES , HEADER , PARSE_WIN31_LINE ,
  LINE_START , KEY_NAME , DELETE_KEY , DEFAULT_VALUE_NAME ,
  QUOTED_VALUE_NAME , DATA_START , DELETE_VALUE , DATA_TYPE ,
  STRING_DATA , DWORD_DATA , HEX_DATA , EOL_BACKSLASH ,
  HEX_MULTILINE , UNKNOWN_DATA , SET_VALUE , NB_PARSER_STATES ,
  LINE_START , SECTION_NAME , KEY_NAME , VALUE_NAME ,
  EOL_BACKSLASH , QUOTES , LEADING_SPACES , TRAILING_SPACES ,
  COMMENT , NB_PARSER_STATES , LINE_START , SECTION_NAME ,
  KEY_NAME , VALUE_NAME , EOL_BACKSLASH , QUOTES ,
  LEADING_SPACES , TRAILING_SPACES , COMMENT , NB_PARSER_STATES ,
  LINE_START , SECTION_NAME , KEY_NAME , VALUE_NAME ,
  EOL_BACKSLASH , QUOTES , LEADING_SPACES , TRAILING_SPACES ,
  COMMENT , NB_PARSER_STATES
}
 

Functions

static const WCHARline_start_state (struct parser *parser, const WCHAR *pos)
 
static const WCHARsection_name_state (struct parser *parser, const WCHAR *pos)
 
static const WCHARkey_name_state (struct parser *parser, const WCHAR *pos)
 
static const WCHARvalue_name_state (struct parser *parser, const WCHAR *pos)
 
static const WCHAReol_backslash_state (struct parser *parser, const WCHAR *pos)
 
static const WCHARquotes_state (struct parser *parser, const WCHAR *pos)
 
static const WCHARleading_spaces_state (struct parser *parser, const WCHAR *pos)
 
static const WCHARtrailing_spaces_state (struct parser *parser, const WCHAR *pos)
 
static const WCHARcomment_state (struct parser *parser, const WCHAR *pos)
 
static PINFCACHELINE InfpFreeLine (PINFCACHELINE Line)
 
PINFCACHESECTION InfpFreeSection (PINFCACHESECTION Section)
 
PINFCACHESECTION InfpFindSection (PINFCACHE Cache, PCWSTR Name)
 
PINFCACHESECTION InfpAddSection (PINFCACHE Cache, PCWSTR Name)
 
PINFCACHELINE InfpAddLine (PINFCACHESECTION Section)
 
PINFCACHESECTION InfpFindSectionById (PINFCACHE Cache, UINT Id)
 
PINFCACHESECTION InfpGetSectionForContext (PINFCONTEXT Context)
 
PINFCACHELINE InfpFindLineById (PINFCACHESECTION Section, UINT Id)
 
PINFCACHELINE InfpGetLineForContext (PINFCONTEXT Context)
 
PVOID InfpAddKeyToLine (PINFCACHELINE Line, PCWSTR Key)
 
PVOID InfpAddFieldToLine (PINFCACHELINE Line, PCWSTR Data)
 
PINFCACHELINE InfpFindKeyLine (PINFCACHESECTION Section, PCWSTR Key)
 
static __inline void push_state (struct parser *parser, enum parser_state state)
 
static __inline void pop_state (struct parser *parser)
 
static __inline enum parser_state set_state (struct parser *parser, enum parser_state state)
 
static __inline int is_eof (struct parser *parser, const WCHAR *ptr)
 
static __inline int is_eol (struct parser *parser, const WCHAR *ptr)
 
static int push_token (struct parser *parser, const WCHAR *pos)
 
static PVOID add_section_from_token (struct parser *parser)
 
static struct fieldadd_field_from_token (struct parser *parser, int is_key)
 
static void close_current_line (struct parser *parser)
 
INFSTATUS InfpParseBuffer (PINFCACHE file, const WCHAR *buffer, const WCHAR *end, PULONG error_line)
 

Variables

static const parser_state_func parser_funcs [NB_PARSER_STATES]
 

Macro Definition Documentation

◆ CONTROL_Z

#define CONTROL_Z   '\x1a'

Definition at line 16 of file infcore.c.

◆ MAX_FIELD_LEN

#define MAX_FIELD_LEN   511 /* larger fields get silently truncated */

Definition at line 18 of file infcore.c.

◆ MAX_SECTION_NAME_LEN

#define MAX_SECTION_NAME_LEN   255

Definition at line 17 of file infcore.c.

◆ MAX_STRING_LEN

#define MAX_STRING_LEN   (MAX_INF_STRING_LENGTH+1)

Definition at line 20 of file infcore.c.

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file infcore.c.

Typedef Documentation

◆ parser_state_func

typedef const WCHAR *(* parser_state_func) (struct parser *parser, const WCHAR *pos)

Definition at line 56 of file infcore.c.

Enumeration Type Documentation

◆ parser_state

Enumerator
HEADER 
PARSE_WIN31_LINE 
LINE_START 
KEY_NAME 
DELETE_KEY 
DEFAULT_VALUE_NAME 
QUOTED_VALUE_NAME 
DATA_START 
DELETE_VALUE 
DATA_TYPE 
STRING_DATA 
DWORD_DATA 
HEX_DATA 
EOL_BACKSLASH 
HEX_MULTILINE 
UNKNOWN_DATA 
SET_VALUE 
NB_PARSER_STATES 
HEADER 
PARSE_WIN31_LINE 
LINE_START 
KEY_NAME 
DELETE_KEY 
DEFAULT_VALUE_NAME 
QUOTED_VALUE_NAME 
DATA_START 
DELETE_VALUE 
DATA_TYPE 
STRING_DATA 
DWORD_DATA 
HEX_DATA 
EOL_BACKSLASH 
HEX_MULTILINE 
UNKNOWN_DATA 
SET_VALUE 
NB_PARSER_STATES 
LINE_START 
SECTION_NAME 
KEY_NAME 
VALUE_NAME 
EOL_BACKSLASH 
QUOTES 
LEADING_SPACES 
TRAILING_SPACES 
COMMENT 
NB_PARSER_STATES 
LINE_START 
SECTION_NAME 
KEY_NAME 
VALUE_NAME 
EOL_BACKSLASH 
QUOTES 
LEADING_SPACES 
TRAILING_SPACES 
COMMENT 
NB_PARSER_STATES 
LINE_START 
SECTION_NAME 
KEY_NAME 
VALUE_NAME 
EOL_BACKSLASH 
QUOTES 
LEADING_SPACES 
TRAILING_SPACES 
COMMENT 
NB_PARSER_STATES 

Definition at line 25 of file infcore.c.

26{
27 LINE_START, /* at beginning of a line */
28 SECTION_NAME, /* parsing a section name */
29 KEY_NAME, /* parsing a key name */
30 VALUE_NAME, /* parsing a value name */
31 EOL_BACKSLASH, /* backslash at end of line */
32 QUOTES, /* inside quotes */
33 LEADING_SPACES, /* leading spaces */
34 TRAILING_SPACES, /* trailing spaces */
35 COMMENT, /* inside a comment */
37};
@ NB_PARSER_STATES
Definition: infcore.c:36
@ SECTION_NAME
Definition: infcore.c:28
@ TRAILING_SPACES
Definition: infcore.c:34
@ QUOTES
Definition: infcore.c:32
@ LINE_START
Definition: infcore.c:27
@ EOL_BACKSLASH
Definition: infcore.c:31
@ COMMENT
Definition: infcore.c:35
@ LEADING_SPACES
Definition: infcore.c:33
@ KEY_NAME
Definition: infcore.c:29
@ VALUE_NAME
Definition: infcore.c:30

Function Documentation

◆ add_field_from_token()

static struct field * add_field_from_token ( struct parser parser,
int  is_key 
)
static

Definition at line 517 of file infcore.c.

518{
519 PVOID field;
520
521 if (!parser->line) /* need to start a new line */
522 {
523 if (parser->cur_section == NULL) /* got a line before the first section */
524 {
526 return NULL;
527 }
528
530 if (parser->line == NULL)
531 goto error;
532 }
533 else
534 {
535// assert(!is_key);
536 }
537
538 if (is_key)
539 {
541 }
542 else
543 {
545 }
546
547 if (field != NULL)
548 {
549 parser->token_len = 0;
550 return field;
551 }
552
553error:
555 return NULL;
556}
#define NULL
Definition: types.h:112
PVOID InfpAddKeyToLine(PINFCACHELINE Line, PCWSTR Key)
Definition: infcore.c:324
PVOID InfpAddFieldToLine(PINFCACHELINE Line, PCWSTR Data)
Definition: infcore.c:353
PINFCACHELINE InfpAddLine(PINFCACHESECTION Section)
Definition: infcore.c:217
#define INF_STATUS_WRONG_INF_STYLE
Definition: infpriv.h:18
#define INF_STATUS_NOT_ENOUGH_MEMORY
Definition: infpriv.h:19
#define error(str)
Definition: mkdosfs.c:1605
Definition: parser.c:44
Definition: import.c:81
PINFCACHESECTION cur_section
Definition: inffile.c:94
CHAR token[MAX_FIELD_LEN+1]
Definition: inffile.c:99
unsigned int token_len
Definition: inffile.c:98
unsigned int error
Definition: inffile.c:97
PINFCACHELINE line
Definition: inffile.c:95

Referenced by key_name_state(), and value_name_state().

◆ add_section_from_token()

static PVOID add_section_from_token ( struct parser parser)
static

Definition at line 485 of file infcore.c.

486{
487 PINFCACHESECTION Section;
488
490 {
492 return NULL;
493 }
494
495 Section = InfpFindSection(parser->file,
496 parser->token);
497 if (Section == NULL)
498 {
499 /* need to create a new one */
500 Section= InfpAddSection(parser->file,
501 parser->token);
502 if (Section == NULL)
503 {
505 return NULL;
506 }
507 }
508
509 parser->token_len = 0;
510 parser->cur_section = Section;
511
512 return (PVOID)Section;
513}
PINFCACHESECTION InfpFindSection(PINFCACHE Cache, PCWSTR Name)
Definition: infcore.c:143
#define MAX_SECTION_NAME_LEN
Definition: infcore.c:17
PINFCACHESECTION InfpAddSection(PINFCACHE Cache, PCWSTR Name)
Definition: infcore.c:171
#define INF_STATUS_SECTION_NAME_TOO_LONG
Definition: infpriv.h:17
FILE * file
Definition: import.c:82

Referenced by section_name_state().

◆ close_current_line()

static void close_current_line ( struct parser parser)
static

Definition at line 560 of file infcore.c.

561{
562 parser->line = NULL;
563}

Referenced by line_start_state().

◆ comment_state()

static const WCHAR * comment_state ( struct parser parser,
const WCHAR pos 
)
static

Definition at line 852 of file infcore.c.

853{
854 const WCHAR *p = pos;
855
856 while (!is_eol( parser, p ))
857 p++;
858 pop_state( parser );
859 return p;
860}
GLfloat GLfloat p
Definition: glext.h:8902
static __inline int is_eol(struct parser *parser, const WCHAR *ptr)
Definition: infcore.c:443
static __inline void pop_state(struct parser *parser)
Definition: infcore.c:419
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ eol_backslash_state()

static const WCHAR * eol_backslash_state ( struct parser parser,
const WCHAR pos 
)
static

Definition at line 739 of file infcore.c.

740{
741 const WCHAR *p;
742
743 for (p = pos; !is_eof( parser, p ); p++)
744 {
745 switch(*p)
746 {
747 case '\r':
748 continue;
749
750 case '\n':
751 parser->line_pos++;
752 parser->start = p + 1;
754 return p + 1;
755
756 case '\\':
757 continue;
758
759 case ';':
762 return p + 1;
763
764 default:
765 if (isspaceW(*p))
766 continue;
767 push_token( parser, p );
768 pop_state( parser );
769 return p;
770 }
771 }
772 parser->start = p;
773 pop_state( parser );
774
775 return p;
776}
static __inline enum parser_state set_state(struct parser *parser, enum parser_state state)
Definition: infcore.c:427
static __inline int is_eof(struct parser *parser, const WCHAR *ptr)
Definition: infcore.c:436
static __inline void push_state(struct parser *parser, enum parser_state state)
Definition: infcore.c:411
static int push_token(struct parser *parser, const WCHAR *pos)
Definition: infcore.c:454
#define isspaceW(n)
Definition: unicode.h:58
unsigned int line_pos
Definition: inffile.c:96
const CHAR * start
Definition: inffile.c:87

◆ InfpAddFieldToLine()

PVOID InfpAddFieldToLine ( PINFCACHELINE  Line,
PCWSTR  Data 
)

Definition at line 353 of file infcore.c.

355{
356 PINFCACHEFIELD Field;
357 ULONG Size;
358
360 Data[strlenW(Data) + 1]);
361 Field = (PINFCACHEFIELD)MALLOC(Size);
362 if (Field == NULL)
363 {
364 DPRINT1("MALLOC() failed\n");
365 return NULL;
366 }
367 ZEROMEMORY (Field,
368 Size);
369 strcpyW(Field->Data, Data);
370
371 /* Append key */
372 if (Line->FirstField == NULL)
373 {
374 Line->FirstField = Field;
375 Line->LastField = Field;
376 }
377 else
378 {
379 Line->LastField->Next = Field;
380 Field->Prev = Line->LastField;
381 Line->LastField = Field;
382 }
383 Line->FieldCount++;
384
385 return (PVOID)Field;
386}
#define DPRINT1
Definition: precomp.h:8
#define MALLOC(Size)
Definition: builddep.h:73
#define ZEROMEMORY(Area, Size)
Definition: builddep.h:74
struct _INFCACHEFIELD * PINFCACHEFIELD
#define strlenW(s)
Definition: unicode.h:34
#define strcpyW(d, s)
Definition: unicode.h:35
Definition: ncftp.h:79
struct _INFCACHEFIELD * Prev
Definition: inffile.c:30
CHAR Data[1]
Definition: inffile.c:32
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533

Referenced by add_field_from_token().

◆ InfpAddKeyToLine()

PVOID InfpAddKeyToLine ( PINFCACHELINE  Line,
PCWSTR  Key 
)

Definition at line 324 of file infcore.c.

326{
327 if (Line == NULL)
328 {
329 DPRINT1("Invalid Line\n");
330 return NULL;
331 }
332
333 if (Line->Key != NULL)
334 {
335 DPRINT1("Line already has a key\n");
336 return NULL;
337 }
338
339 Line->Key = (PWCHAR)MALLOC((strlenW(Key) + 1) * sizeof(WCHAR));
340 if (Line->Key == NULL)
341 {
342 DPRINT1("MALLOC() failed\n");
343 return NULL;
344 }
345
346 strcpyW(Line->Key, Key);
347
348 return (PVOID)Line->Key;
349}
uint16_t * PWCHAR
Definition: typedefs.h:56

Referenced by add_field_from_token().

◆ InfpAddLine()

PINFCACHELINE InfpAddLine ( PINFCACHESECTION  Section)

Definition at line 217 of file infcore.c.

218{
220
221 if (Section == NULL)
222 {
223 DPRINT("Invalid parameter\n");
224 return NULL;
225 }
226
228 if (Line == NULL)
229 {
230 DPRINT("MALLOC() failed\n");
231 return NULL;
232 }
234 sizeof(INFCACHELINE));
235 Line->Id = ++Section->NextLineId;
236
237 /* Append line */
238 if (Section->FirstLine == NULL)
239 {
240 Section->FirstLine = Line;
241 Section->LastLine = Line;
242 }
243 else
244 {
245 Section->LastLine->Next = Line;
246 Line->Prev = Section->LastLine;
247 Section->LastLine = Line;
248 }
249 Section->LineCount++;
250
251 return Line;
252}
struct _INFCACHELINE * PINFCACHELINE
#define DPRINT
Definition: sndvol32.h:73
struct _INFCACHELINE * Next
Definition: inffile.c:37
PINFCACHELINE LastLine
Definition: inffile.c:55
PINFCACHELINE FirstLine
Definition: inffile.c:54
UINT NextLineId
Definition: infpriv.h:54
LONG LineCount
Definition: inffile.c:57

Referenced by add_field_from_token(), and InfpAddLineWithKey().

◆ InfpAddSection()

PINFCACHESECTION InfpAddSection ( PINFCACHE  Cache,
PCWSTR  Name 
)

Definition at line 171 of file infcore.c.

173{
174 PINFCACHESECTION Section = NULL;
175 ULONG Size;
176
177 if (Cache == NULL || Name == NULL)
178 {
179 DPRINT("Invalid parameter\n");
180 return NULL;
181 }
182
183 /* Allocate and initialize the new section */
185 Name[strlenW(Name) + 1]);
186 Section = (PINFCACHESECTION)MALLOC(Size);
187 if (Section == NULL)
188 {
189 DPRINT("MALLOC() failed\n");
190 return NULL;
191 }
192 ZEROMEMORY (Section,
193 Size);
194 Section->Id = ++Cache->NextSectionId;
195
196 /* Copy section name */
197 strcpyW(Section->Name, Name);
198
199 /* Append section */
200 if (Cache->FirstSection == NULL)
201 {
202 Cache->FirstSection = Section;
203 Cache->LastSection = Section;
204 }
205 else
206 {
207 Cache->LastSection->Next = Section;
208 Section->Prev = Cache->LastSection;
209 Cache->LastSection = Section;
210 }
211
212 return Section;
213}
struct _INFCACHESECTION * PINFCACHESECTION
Definition: fatfs.h:173
struct _INFCACHESECTION * Prev
Definition: inffile.c:52
CHAR Name[1]
Definition: inffile.c:59

Referenced by add_section_from_token(), and InfpFindOrAddSection().

◆ InfpFindKeyLine()

PINFCACHELINE InfpFindKeyLine ( PINFCACHESECTION  Section,
PCWSTR  Key 
)

Definition at line 390 of file infcore.c.

392{
394
395 Line = Section->FirstLine;
396 while (Line != NULL)
397 {
398 if (Line->Key != NULL && strcmpiW(Line->Key, Key) == 0)
399 {
400 return Line;
401 }
402
403 Line = Line->Next;
404 }
405
406 return NULL;
407}
#define strcmpiW(s1, s2)
Definition: unicode.h:45

Referenced by InfpFindFirstLine().

◆ InfpFindLineById()

PINFCACHELINE InfpFindLineById ( PINFCACHESECTION  Section,
UINT  Id 
)

Definition at line 292 of file infcore.c.

293{
295
296 for (Line = Section->FirstLine;
297 Line != NULL;
298 Line = Line->Next)
299 {
300 if (Line->Id == Id)
301 {
302 return Line;
303 }
304 }
305
306 return NULL;
307}
DWORD Id

Referenced by InfpGetLineForContext().

◆ InfpFindSection()

PINFCACHESECTION InfpFindSection ( PINFCACHE  Cache,
PCWSTR  Name 
)

Definition at line 143 of file infcore.c.

145{
146 PINFCACHESECTION Section = NULL;
147
148 if (Cache == NULL || Name == NULL)
149 {
150 return NULL;
151 }
152
153 /* iterate through list of sections */
154 Section = Cache->FirstSection;
155 while (Section != NULL)
156 {
157 if (strcmpiW(Section->Name, Name) == 0)
158 {
159 return Section;
160 }
161
162 /* get the next section*/
163 Section = Section->Next;
164 }
165
166 return NULL;
167}
struct _INFCACHESECTION * Next
Definition: inffile.c:51

Referenced by add_section_from_token(), InfpFindFirstLine(), InfpFindOrAddSection(), and InfpParseBuffer().

◆ InfpFindSectionById()

PINFCACHESECTION InfpFindSectionById ( PINFCACHE  Cache,
UINT  Id 
)

Definition at line 255 of file infcore.c.

256{
257 PINFCACHESECTION Section;
258
259 for (Section = Cache->FirstSection;
260 Section != NULL;
261 Section = Section->Next)
262 {
263 if (Section->Id == Id)
264 {
265 return Section;
266 }
267 }
268
269 return NULL;
270}

Referenced by InfpGetSectionForContext().

◆ InfpFreeLine()

static PINFCACHELINE InfpFreeLine ( PINFCACHELINE  Line)
static

Definition at line 86 of file infcore.c.

87{
88 PINFCACHELINE Next;
89 PINFCACHEFIELD Field;
90
91 if (Line == NULL)
92 {
93 return NULL;
94 }
95
96 Next = Line->Next;
97 if (Line->Key != NULL)
98 {
99 FREE (Line->Key);
100 Line->Key = NULL;
101 }
102
103 /* Remove data fields */
104 while (Line->FirstField != NULL)
105 {
106 Field = Line->FirstField->Next;
107 FREE (Line->FirstField);
108 Line->FirstField = Field;
109 }
110 Line->LastField = NULL;
111
112 FREE (Line);
113
114 return Next;
115}
#define FREE(ptr, size)
Definition: auth_des.c:64

Referenced by InfpFreeSection().

◆ InfpFreeSection()

PINFCACHESECTION InfpFreeSection ( PINFCACHESECTION  Section)

Definition at line 119 of file infcore.c.

120{
121 PINFCACHESECTION Next;
122
123 if (Section == NULL)
124 {
125 return NULL;
126 }
127
128 /* Release all keys */
129 Next = Section->Next;
130 while (Section->FirstLine != NULL)
131 {
132 Section->FirstLine = InfpFreeLine (Section->FirstLine);
133 }
134 Section->LastLine = NULL;
135
136 FREE (Section);
137
138 return Next;
139}
static PINFCACHELINE InfpFreeLine(PINFCACHELINE Line)
Definition: infcore.c:86

Referenced by InfCloseFile(), and InfHostCloseFile().

◆ InfpGetLineForContext()

PINFCACHELINE InfpGetLineForContext ( PINFCONTEXT  Context)

Definition at line 310 of file infcore.c.

311{
312 PINFCACHESECTION Section;
313
315 if (Section == NULL)
316 {
317 return NULL;
318 }
319
320 return InfpFindLineById(Section, Context->Line);
321}
PINFCACHELINE InfpFindLineById(PINFCACHESECTION Section, UINT Id)
Definition: infcore.c:292
PINFCACHESECTION InfpGetSectionForContext(PINFCONTEXT Context)
Definition: infcore.c:273

Referenced by InfpAddField(), InfpFindNextLine(), InfpFindNextMatchLine(), InfpGetBinaryField(), InfpGetData(), InfpGetDataField(), InfpGetFieldCount(), InfpGetIntField(), InfpGetMultiSzField(), and InfpGetStringField().

◆ InfpGetSectionForContext()

PINFCACHESECTION InfpGetSectionForContext ( PINFCONTEXT  Context)

Definition at line 273 of file infcore.c.

274{
276
277 if (Context == NULL)
278 {
279 return NULL;
280 }
281
282 Cache = (PINFCACHE)Context->Inf;
283 if (Cache == NULL)
284 {
285 return NULL;
286 }
287
288 return InfpFindSectionById(Cache, Context->Section);
289}
PINFCACHESECTION InfpFindSectionById(PINFCACHE Cache, UINT Id)
Definition: infcore.c:255
struct _INFCACHE * PINFCACHE
if(dx< 0)
Definition: linetemp.h:194

Referenced by InfpAddLineWithKey(), InfpFindFirstMatchLine(), InfpFindNextMatchLine(), and InfpGetLineForContext().

◆ InfpParseBuffer()

INFSTATUS InfpParseBuffer ( PINFCACHE  file,
const WCHAR buffer,
const WCHAR end,
PULONG  error_line 
)

Definition at line 865 of file infcore.c.

869{
870 struct parser parser;
871 const WCHAR *pos = buffer;
872
874 parser.end = end;
875 parser.file = file;
876 parser.line = NULL;
878 parser.stack_pos = 0;
880 parser.line_pos = 1;
881 parser.error = 0;
882 parser.token_len = 0;
883
884 /* parser main loop */
885 while (pos)
887
888 if (parser.error)
889 {
890 if (error_line)
891 *error_line = parser.line_pos;
892 return parser.error;
893 }
894
895 /* find the [strings] section */
896 file->StringsSection = InfpFindSection(file,
897 L"Strings");
898
899 return INF_STATUS_SUCCESS;
900}
#define INF_STATUS_SUCCESS
Definition: builddep.h:77
GLuint GLuint end
Definition: gl.h:1545
GLuint buffer
Definition: glext.h:5915
static const parser_state_func parser_funcs[NB_PARSER_STATES]
Definition: infcore.c:69
#define L(x)
Definition: ntvdm.h:50
Definition: fci.c:127
int stack_pos
Definition: inffile.c:92
const CHAR * end
Definition: inffile.c:88
enum parser_state state
Definition: import.c:95

◆ is_eof()

static __inline int is_eof ( struct parser parser,
const WCHAR ptr 
)
static

Definition at line 436 of file infcore.c.

437{
438 return (ptr >= parser->end || *ptr == CONTROL_Z || *ptr == 0);
439}
#define CONTROL_Z
Definition: infcore.c:16
static PVOID ptr
Definition: dispmode.c:27

Referenced by eol_backslash_state(), and line_start_state().

◆ is_eol()

static __inline int is_eol ( struct parser parser,
const WCHAR ptr 
)
static

Definition at line 443 of file infcore.c.

444{
445 return (ptr >= parser->end ||
446 *ptr == CONTROL_Z ||
447 *ptr == '\n' ||
448 (*ptr == '\r' && *(ptr + 1) == '\n') ||
449 *ptr == 0);
450}

Referenced by comment_state(), key_name_state(), leading_spaces_state(), quotes_state(), section_name_state(), trailing_spaces_state(), and value_name_state().

◆ key_name_state()

static const WCHAR * key_name_state ( struct parser parser,
const WCHAR pos 
)
static

Definition at line 632 of file infcore.c.

633{
634 const WCHAR *p, *token_end = parser->start;
635
636 for (p = pos; !is_eol( parser, p ); p++)
637 {
638 if (*p == ',') break;
639 switch(*p)
640 {
641
642 case '=':
643 push_token( parser, token_end );
644 if (!add_field_from_token( parser, 1 )) return NULL;
645 parser->start = p + 1;
648 return p + 1;
649 case ';':
650 push_token( parser, token_end );
651 if (!add_field_from_token( parser, 0 )) return NULL;
654 return p + 1;
655 case '"':
656 push_token( parser, token_end );
657 parser->start = p + 1;
660 return p + 1;
661 case '\\':
662 push_token( parser, token_end );
663 parser->start = p;
666 return p;
667 default:
668 if (!isspaceW(*p)) token_end = p + 1;
669 else
670 {
671 push_token( parser, p );
674 return p;
675 }
676 break;
677 }
678 }
679 push_token( parser, token_end );
681 return p;
682}
static struct field * add_field_from_token(struct parser *parser, int is_key)
Definition: infcore.c:517

◆ leading_spaces_state()

static const WCHAR * leading_spaces_state ( struct parser parser,
const WCHAR pos 
)
static

Definition at line 810 of file infcore.c.

811{
812 const WCHAR *p;
813
814 for (p = pos; !is_eol( parser, p ); p++)
815 {
816 if (*p == '\\')
817 {
818 parser->start = p;
820 return p;
821 }
822 if (!isspaceW(*p))
823 break;
824 }
825 parser->start = p;
826 pop_state( parser );
827 return p;
828}

◆ line_start_state()

static const WCHAR * line_start_state ( struct parser parser,
const WCHAR pos 
)
static

Definition at line 568 of file infcore.c.

569{
570 const WCHAR *p;
571
572 for (p = pos; !is_eof( parser, p ); p++)
573 {
574 switch(*p)
575 {
576 case '\r':
577 continue;
578
579 case '\n':
580 parser->line_pos++;
582 break;
583
584 case ';':
587 return p + 1;
588
589 case '[':
590 parser->start = p + 1;
592 return p + 1;
593
594 default:
595 if (!isspaceW(*p))
596 {
597 parser->start = p;
599 return p;
600 }
601 break;
602 }
603 }
605 return NULL;
606}
static void close_current_line(struct parser *parser)
Definition: infcore.c:560

◆ pop_state()

static __inline void pop_state ( struct parser parser)
static

Definition at line 419 of file infcore.c.

420{
421// assert( parser->stack_pos );
423}
enum parser_state stack[4]
Definition: inffile.c:91

Referenced by comment_state(), eol_backslash_state(), leading_spaces_state(), quotes_state(), and trailing_spaces_state().

◆ push_state()

static __inline void push_state ( struct parser parser,
enum parser_state  state 
)
static

Definition at line 411 of file infcore.c.

412{
413// assert( parser->stack_pos < sizeof(parser->stack)/sizeof(parser->stack[0]) );
415}
static int state
Definition: maze.c:121

Referenced by eol_backslash_state(), key_name_state(), line_start_state(), section_name_state(), and value_name_state().

◆ push_token()

static int push_token ( struct parser parser,
const WCHAR pos 
)
static

Definition at line 454 of file infcore.c.

455{
456 UINT len = (UINT)(pos - parser->start);
457 const WCHAR *src = parser->start;
459
462
463 parser->token_len += len;
464 for ( ; len > 0; len--, dst++, src++)
465 {
466 if (*src)
467 {
468 *dst = *src;
469 }
470 else
471 {
472 *dst = ' ';
473 }
474 }
475
476 *dst = 0;
477 parser->start = pos;
478
479 return 0;
480}
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340
GLenum GLsizei len
Definition: glext.h:6722
#define MAX_FIELD_LEN
Definition: infcore.c:18
unsigned int UINT
Definition: ndis.h:50

Referenced by eol_backslash_state(), key_name_state(), quotes_state(), section_name_state(), and value_name_state().

◆ quotes_state()

static const WCHAR * quotes_state ( struct parser parser,
const WCHAR pos 
)
static

Definition at line 780 of file infcore.c.

781{
782 const WCHAR *p, *token_end = parser->start;
783
784 for (p = pos; !is_eol( parser, p ); p++)
785 {
786 if (*p == '"')
787 {
788 if (p+1 < parser->end && p[1] == '"') /* double quotes */
789 {
790 push_token( parser, p + 1 );
791 parser->start = token_end = p + 2;
792 p++;
793 }
794 else /* end of quotes */
795 {
796 push_token( parser, p );
797 parser->start = p + 1;
798 pop_state( parser );
799 return p + 1;
800 }
801 }
802 }
803 push_token( parser, p );
804 pop_state( parser );
805 return p;
806}

◆ section_name_state()

static const WCHAR * section_name_state ( struct parser parser,
const WCHAR pos 
)
static

Definition at line 610 of file infcore.c.

611{
612 const WCHAR *p;
613
614 for (p = pos; !is_eol( parser, p ); p++)
615 {
616 if (*p == ']')
617 {
618 push_token( parser, p );
620 return NULL;
622 set_state( parser, COMMENT ); /* ignore everything else on the line */
623 return p + 1;
624 }
625 }
626 parser->error = INF_STATUS_BAD_SECTION_NAME_LINE; /* unfinished section name */
627 return NULL;
628}
static PVOID add_section_from_token(struct parser *parser)
Definition: infcore.c:485
#define INF_STATUS_BAD_SECTION_NAME_LINE
Definition: infpriv.h:16

◆ set_state()

static __inline enum parser_state set_state ( struct parser parser,
enum parser_state  state 
)
static

◆ trailing_spaces_state()

static const WCHAR * trailing_spaces_state ( struct parser parser,
const WCHAR pos 
)
static

Definition at line 832 of file infcore.c.

833{
834 const WCHAR *p;
835
836 for (p = pos; !is_eol( parser, p ); p++)
837 {
838 if (*p == '\\')
839 {
841 return p;
842 }
843 if (!isspaceW(*p))
844 break;
845 }
846 pop_state( parser );
847 return p;
848}

◆ value_name_state()

static const WCHAR * value_name_state ( struct parser parser,
const WCHAR pos 
)
static

Definition at line 686 of file infcore.c.

687{
688 const WCHAR *p, *token_end = parser->start;
689
690 for (p = pos; !is_eol( parser, p ); p++)
691 {
692 switch(*p)
693 {
694 case ';':
695 push_token( parser, token_end );
696 if (!add_field_from_token( parser, 0 )) return NULL;
699 return p + 1;
700 case ',':
701 push_token( parser, token_end );
702 if (!add_field_from_token( parser, 0 )) return NULL;
703 parser->start = p + 1;
706 return p + 1;
707 case '"':
708 push_token( parser, token_end );
709 parser->start = p + 1;
712 return p + 1;
713 case '\\':
714 push_token( parser, token_end );
715 parser->start = p;
718 return p;
719 default:
720 if (!isspaceW(*p)) token_end = p + 1;
721 else
722 {
723 push_token( parser, p );
726 return p;
727 }
728 break;
729 }
730 }
731 push_token( parser, token_end );
732 if (!add_field_from_token( parser, 0 )) return NULL;
734 return p;
735}

Variable Documentation

◆ parser_funcs

Initial value:
=
{
}
static const WCHAR * key_name_state(struct parser *parser, const WCHAR *pos)
Definition: infcore.c:632
static const WCHAR * value_name_state(struct parser *parser, const WCHAR *pos)
Definition: infcore.c:686
static const WCHAR * section_name_state(struct parser *parser, const WCHAR *pos)
Definition: infcore.c:610
static const WCHAR * leading_spaces_state(struct parser *parser, const WCHAR *pos)
Definition: infcore.c:810
static const WCHAR * line_start_state(struct parser *parser, const WCHAR *pos)
Definition: infcore.c:568
static const WCHAR * eol_backslash_state(struct parser *parser, const WCHAR *pos)
Definition: infcore.c:739
static const WCHAR * quotes_state(struct parser *parser, const WCHAR *pos)
Definition: infcore.c:780
static const WCHAR * comment_state(struct parser *parser, const WCHAR *pos)
Definition: infcore.c:852
static const WCHAR * trailing_spaces_state(struct parser *parser, const WCHAR *pos)
Definition: infcore.c:832

Definition at line 69 of file infcore.c.

Referenced by InfpParseBuffer().