ReactOS  0.4.13-dev-73-gcfe54aa
inffile.c File Reference
#include <freeldr.h>
Include dependency graph for inffile.c:

Go to the source code of this file.

Classes

struct  _INFCACHEFIELD
 
struct  _INFCACHELINE
 
struct  _INFCACHESECTION
 
struct  _INFCACHE
 
struct  parser
 

Macros

#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)
 
#define TAG_INF_KEY   'KfnI'
 
#define TAG_INF_FIELD   'ffnI'
 
#define TAG_INF_LINE   'LfnI'
 
#define TAG_INF_SECTION   'SfnI'
 
#define TAG_INF_CACHE   'CfnI'
 
#define TAG_INF_FILE   'FfnI'
 

Typedefs

typedef struct _INFCACHEFIELD INFCACHEFIELD
 
typedef struct _INFCACHEFIELDPINFCACHEFIELD
 
typedef struct _INFCACHELINE INFCACHELINE
 
typedef struct _INFCACHELINEPINFCACHELINE
 
typedef struct _INFCACHESECTION INFCACHESECTION
 
typedef struct _INFCACHESECTIONPINFCACHESECTION
 
typedef struct _INFCACHE INFCACHE
 
typedef struct _INFCACHEPINFCACHE
 
typedef const CHAR *(* parser_state_func) (struct parser *parser, const CHAR *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, 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 CHARline_start_state (struct parser *parser, const CHAR *pos)
 
static const CHARsection_name_state (struct parser *parser, const CHAR *pos)
 
static const CHARkey_name_state (struct parser *parser, const CHAR *pos)
 
static const CHARvalue_name_state (struct parser *parser, const CHAR *pos)
 
static const CHAReol_backslash_state (struct parser *parser, const CHAR *pos)
 
static const CHARquotes_state (struct parser *parser, const CHAR *pos)
 
static const CHARleading_spaces_state (struct parser *parser, const CHAR *pos)
 
static const CHARtrailing_spaces_state (struct parser *parser, const CHAR *pos)
 
static const CHARcomment_state (struct parser *parser, const CHAR *pos)
 
static PINFCACHELINE InfpCacheFreeLine (PINFCACHELINE Line)
 
static PINFCACHESECTION InfpCacheFreeSection (PINFCACHESECTION Section)
 
static PINFCACHESECTION InfpCacheFindSection (PINFCACHE Cache, PCSTR Name)
 
static PINFCACHESECTION InfpCacheAddSection (PINFCACHE Cache, PCHAR Name)
 
static PINFCACHELINE InfpCacheAddLine (PINFCACHESECTION Section)
 
static PVOID InfpAddKeyToLine (PINFCACHELINE Line, PCHAR Key)
 
static PVOID InfpAddFieldToLine (PINFCACHELINE Line, PCHAR Data)
 
static PINFCACHELINE InfpCacheFindKeyLine (PINFCACHESECTION Section, PCSTR 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 CHAR *ptr)
 
static __inline int is_eol (struct parser *parser, const CHAR *ptr)
 
static int push_token (struct parser *parser, const CHAR *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)
 
static BOOLEAN InfpParseBuffer (PINFCACHE file, PCCHAR buffer, PCCHAR end, PULONG error_line)
 
BOOLEAN InfOpenFile (PHINF InfHandle, PCSTR FileName, PULONG ErrorLine)
 
VOID InfCloseFile (HINF InfHandle)
 
BOOLEAN InfFindFirstLine (HINF InfHandle, PCSTR Section, PCSTR Key, PINFCONTEXT Context)
 
BOOLEAN InfFindNextLine (PINFCONTEXT ContextIn, PINFCONTEXT ContextOut)
 
BOOLEAN InfFindFirstMatchLine (PINFCONTEXT ContextIn, PCHAR Key, PINFCONTEXT ContextOut)
 
BOOLEAN InfFindNextMatchLine (PINFCONTEXT ContextIn, PCHAR Key, PINFCONTEXT ContextOut)
 
LONG InfGetLineCount (HINF InfHandle, PCHAR Section)
 
LONG InfGetFieldCount (PINFCONTEXT Context)
 
BOOLEAN InfGetBinaryField (PINFCONTEXT Context, ULONG FieldIndex, PUCHAR ReturnBuffer, ULONG ReturnBufferSize, PULONG RequiredSize)
 
BOOLEAN InfGetIntField (PINFCONTEXT Context, ULONG FieldIndex, PLONG IntegerValue)
 
BOOLEAN InfGetMultiSzField (PINFCONTEXT Context, ULONG FieldIndex, PCHAR ReturnBuffer, ULONG ReturnBufferSize, PULONG RequiredSize)
 
BOOLEAN InfGetStringField (PINFCONTEXT Context, ULONG FieldIndex, PCHAR ReturnBuffer, ULONG ReturnBufferSize, PULONG RequiredSize)
 
BOOLEAN InfGetData (PINFCONTEXT Context, PCHAR *Key, PCHAR *Data)
 
BOOLEAN InfGetDataField (PINFCONTEXT Context, ULONG FieldIndex, PCSTR *Data)
 

Variables

static const parser_state_func parser_funcs [NB_PARSER_STATES]
 

Macro Definition Documentation

◆ CONTROL_Z

#define CONTROL_Z   '\x1a'

Definition at line 32 of file inffile.c.

◆ MAX_FIELD_LEN

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

Definition at line 34 of file inffile.c.

◆ MAX_SECTION_NAME_LEN

#define MAX_SECTION_NAME_LEN   255

Definition at line 33 of file inffile.c.

◆ MAX_STRING_LEN

#define MAX_STRING_LEN   (MAX_INF_STRING_LENGTH+1)

Definition at line 36 of file inffile.c.

◆ TAG_INF_CACHE

#define TAG_INF_CACHE   'CfnI'

Definition at line 42 of file inffile.c.

◆ TAG_INF_FIELD

#define TAG_INF_FIELD   'ffnI'

Definition at line 39 of file inffile.c.

◆ TAG_INF_FILE

#define TAG_INF_FILE   'FfnI'

Definition at line 43 of file inffile.c.

◆ TAG_INF_KEY

#define TAG_INF_KEY   'KfnI'

Definition at line 38 of file inffile.c.

◆ TAG_INF_LINE

#define TAG_INF_LINE   'LfnI'

Definition at line 40 of file inffile.c.

◆ TAG_INF_SECTION

#define TAG_INF_SECTION   'SfnI'

Definition at line 41 of file inffile.c.

Typedef Documentation

◆ INFCACHE

◆ INFCACHEFIELD

◆ INFCACHELINE

◆ INFCACHESECTION

◆ parser_state_func

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

Definition at line 120 of file inffile.c.

◆ PINFCACHE

◆ PINFCACHEFIELD

◆ PINFCACHELINE

◆ PINFCACHESECTION

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 
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 89 of file inffile.c.

90 {
91  LINE_START, /* at beginning of a line */
92  SECTION_NAME, /* parsing a section name */
93  KEY_NAME, /* parsing a key name */
94  VALUE_NAME, /* parsing a value name */
95  EOL_BACKSLASH, /* backslash at end of line */
96  QUOTES, /* inside quotes */
97  LEADING_SPACES, /* leading spaces */
98  TRAILING_SPACES, /* trailing spaces */
99  COMMENT, /* inside a comment */
101 };
Definition: inffile.c:96

Function Documentation

◆ add_field_from_token()

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

Definition at line 508 of file inffile.c.

511 {
512  PVOID field;
513 
514  if (!parser->line) /* need to start a new line */
515  {
516  if (parser->cur_section == NULL) /* got a line before the first section */
517  {
519  return NULL;
520  }
521 
523  if (parser->line == NULL)
524  goto error;
525  }
526  else
527  {
528 // assert(!is_key);
529  }
530 
531  if (is_key)
532  {
534  }
535  else
536  {
538  }
539 
540  if (field != NULL)
541  {
542  parser->token_len = 0;
543  return field;
544  }
545 
546 error:
547  parser->error = FALSE;
548  return NULL;
549 }
#define error(str)
Definition: mkdosfs.c:1605
static PINFCACHELINE InfpCacheAddLine(PINFCACHESECTION Section)
Definition: inffile.c:289
static PVOID InfpAddFieldToLine(PINFCACHELINE Line, PCHAR Data)
Definition: inffile.c:349
PINFCACHELINE line
Definition: inffile.c:113
smooth NULL
Definition: ftsmooth.c:416
Definition: parser.c:43
unsigned int token_len
Definition: inffile.c:116
unsigned int error
Definition: inffile.c:115
PINFCACHESECTION cur_section
Definition: inffile.c:112
CHAR token[MAX_FIELD_LEN+1]
Definition: inffile.c:117
Definition: import.c:86
static PVOID InfpAddKeyToLine(PINFCACHELINE Line, PCHAR Key)
Definition: inffile.c:327
#define STATUS_WRONG_INF_STYLE
Definition: inffile.h:32

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 476 of file inffile.c.

477 {
478  PINFCACHESECTION Section;
479 
481  {
482  parser->error = FALSE;
483  return NULL;
484  }
485 
487  if (Section == NULL)
488  {
489  /* need to create a new one */
491  if (Section == NULL)
492  {
493  parser->error = FALSE;
494  return NULL;
495  }
496  }
497 
498  parser->token_len = 0;
499  parser->cur_section = Section;
500 
501  return (PVOID)Section;
502 }
static PINFCACHESECTION InfpCacheAddSection(PINFCACHE Cache, PCHAR Name)
Definition: inffile.c:244
static PINFCACHESECTION InfpCacheFindSection(PINFCACHE Cache, PCSTR Name)
Definition: inffile.c:214
smooth NULL
Definition: ftsmooth.c:416
#define MAX_SECTION_NAME_LEN
Definition: inffile.c:33
unsigned int token_len
Definition: inffile.c:116
unsigned int error
Definition: inffile.c:115
FILE * file
Definition: import.c:88
PINFCACHESECTION cur_section
Definition: inffile.c:112
CHAR token[MAX_FIELD_LEN+1]
Definition: inffile.c:117
Definition: import.c:86

Referenced by section_name_state().

◆ close_current_line()

static VOID close_current_line ( struct parser parser)
static

Definition at line 555 of file inffile.c.

556 {
557  parser->line = NULL;
558 }
PINFCACHELINE line
Definition: inffile.c:113
smooth NULL
Definition: ftsmooth.c:416
Definition: import.c:86

Referenced by line_start_state().

◆ comment_state()

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

Definition at line 880 of file inffile.c.

883 {
884  const CHAR *p = pos;
885 
886  while (!is_eol(parser, p))
887  p++;
888  pop_state(parser);
889  return p;
890 }
char CHAR
Definition: xmlstorage.h:175
static __inline int is_eol(struct parser *parser, const CHAR *ptr)
Definition: inffile.c:440
static __inline void pop_state(struct parser *parser)
Definition: inffile.c:416
Definition: import.c:86
GLfloat GLfloat p
Definition: glext.h:8902

◆ eol_backslash_state()

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

Definition at line 751 of file inffile.c.

754 {
755  const CHAR *p;
756 
757  for (p = pos; !is_eof(parser, p); p++)
758  {
759  switch(*p)
760  {
761  case '\r':
762  continue;
763 
764  case '\n':
765  parser->line_pos++;
766  parser->start = p + 1;
768  return p + 1;
769 
770  case '\\':
771  continue;
772 
773  case ';':
776  return p + 1;
777 
778  default:
779  if (isspace((unsigned char)*p))
780  continue;
781  push_token(parser, p);
782  pop_state(parser);
783  return p;
784  }
785  }
786  parser->start = p;
787  pop_state(parser);
788 
789  return p;
790 }
#define isspace(c)
Definition: acclib.h:69
const CHAR * start
Definition: inffile.c:105
char CHAR
Definition: xmlstorage.h:175
static __inline enum parser_state set_state(struct parser *parser, enum parser_state state)
Definition: inffile.c:424
static __inline void push_state(struct parser *parser, enum parser_state state)
Definition: inffile.c:408
static int push_token(struct parser *parser, const CHAR *pos)
Definition: inffile.c:452
static __inline int is_eof(struct parser *parser, const CHAR *ptr)
Definition: inffile.c:433
static __inline void pop_state(struct parser *parser)
Definition: inffile.c:416
Definition: import.c:86
GLfloat GLfloat p
Definition: glext.h:8902
unsigned int line_pos
Definition: inffile.c:114

◆ InfCloseFile()

VOID InfCloseFile ( HINF  InfHandle)

Definition at line 1046 of file inffile.c.

1047 {
1048  PINFCACHE Cache;
1049 
1050  Cache = (PINFCACHE)InfHandle;
1051 
1052  if (Cache == NULL)
1053  {
1054  return;
1055  }
1056 
1057  while (Cache->FirstSection != NULL)
1058  {
1059  Cache->FirstSection = InfpCacheFreeSection(Cache->FirstSection);
1060  }
1061  Cache->LastSection = NULL;
1062 
1064 }
#define TAG_INF_CACHE
Definition: inffile.c:42
Definition: fatfs.h:173
smooth NULL
Definition: ftsmooth.c:416
struct _INFCACHE * PINFCACHE
static PINFCACHESECTION InfpCacheFreeSection(PINFCACHESECTION Section)
Definition: inffile.c:188
FORCEINLINE VOID FrLdrTempFree(PVOID Allocation, ULONG Tag)
Definition: mm.h:186

◆ InfFindFirstLine()

BOOLEAN InfFindFirstLine ( HINF  InfHandle,
PCSTR  Section,
PCSTR  Key,
PINFCONTEXT  Context 
)

Definition at line 1068 of file inffile.c.

1073 {
1074  PINFCACHE Cache;
1075  PINFCACHESECTION CacheSection;
1076  PINFCACHELINE CacheLine;
1077 
1078  if ((InfHandle == NULL) || (Section == NULL) || (Context == NULL))
1079  {
1080 // DPRINT("Invalid parameter\n");
1081  return FALSE;
1082  }
1083 
1084  Cache = (PINFCACHE)InfHandle;
1085 
1086  /* Iterate through list of sections */
1087  CacheSection = Cache->FirstSection;
1088  while (Section != NULL)
1089  {
1090 // DPRINT("Comparing '%S' and '%S'\n", CacheSection->Name, Section);
1091 
1092  /* Are the section names the same? */
1093  if (_stricmp(CacheSection->Name, Section) == 0)
1094  {
1095  if (Key != NULL)
1096  {
1097  CacheLine = InfpCacheFindKeyLine(CacheSection, Key);
1098  }
1099  else
1100  {
1101  CacheLine = CacheSection->FirstLine;
1102  }
1103 
1104  if (CacheLine == NULL)
1105  return FALSE;
1106 
1107  Context->Inf = (PVOID)Cache;
1108  Context->Section = (PVOID)CacheSection;
1109  Context->Line = (PVOID)CacheLine;
1110 
1111  return TRUE;
1112  }
1113 
1114  /* Get the next section */
1115  CacheSection = CacheSection->Next;
1116  }
1117 
1118 // DPRINT("Section not found\n");
1119 
1120  return FALSE;
1121 }
CHAR Name[1]
Definition: inffile.c:77
#define TRUE
Definition: types.h:120
Definition: fatfs.h:173
#define _stricmp
Definition: cat.c:22
struct _INFCACHESECTION * Next
Definition: inffile.c:69
smooth NULL
Definition: ftsmooth.c:416
void * PVOID
Definition: retypes.h:9
struct _INFCACHE * PINFCACHE
PINFCACHELINE FirstLine
Definition: inffile.c:72
static PINFCACHELINE InfpCacheFindKeyLine(PINFCACHESECTION Section, PCSTR Key)
Definition: inffile.c:386

Referenced by LoadReactOSSetup(), SetupFindFirstLineW(), SetupLdrLoadNlsData(), and SetupLdrScanBootDrivers().

◆ InfFindFirstMatchLine()

BOOLEAN InfFindFirstMatchLine ( PINFCONTEXT  ContextIn,
PCHAR  Key,
PINFCONTEXT  ContextOut 
)

Definition at line 1153 of file inffile.c.

1157 {
1158  PINFCACHELINE CacheLine;
1159 
1160  if ((ContextIn == NULL) || (ContextOut == NULL) || (Key == NULL) || (*Key == 0))
1161  return FALSE;
1162 
1163  if (ContextIn->Inf == NULL || ContextIn->Section == NULL)
1164  return FALSE;
1165 
1166  CacheLine = ((PINFCACHESECTION)(ContextIn->Section))->FirstLine;
1167  while (CacheLine != NULL)
1168  {
1169  if ((CacheLine->Key != NULL) && (_stricmp(CacheLine->Key, Key) == 0))
1170  {
1171 
1172  if (ContextIn != ContextOut)
1173  {
1174  ContextOut->Inf = ContextIn->Inf;
1175  ContextOut->Section = ContextIn->Section;
1176  }
1177  ContextOut->Line = (PVOID)CacheLine;
1178 
1179  return TRUE;
1180  }
1181 
1182  CacheLine = CacheLine->Next;
1183  }
1184 
1185  return FALSE;
1186 }
#define TRUE
Definition: types.h:120
struct _INFCACHESECTION * PINFCACHESECTION
#define _stricmp
Definition: cat.c:22
smooth NULL
Definition: ftsmooth.c:416
void * PVOID
Definition: retypes.h:9
UINT Section
Definition: infsupp.h:26
struct _INFCACHELINE * Next
Definition: inffile.c:55
HINF Inf
Definition: infsupp.h:24
UINT Line
Definition: infsupp.h:27
PCHAR Key
Definition: inffile.c:60

◆ InfFindNextLine()

BOOLEAN InfFindNextLine ( PINFCONTEXT  ContextIn,
PINFCONTEXT  ContextOut 
)

Definition at line 1125 of file inffile.c.

1128 {
1129  PINFCACHELINE CacheLine;
1130 
1131  if ((ContextIn == NULL) || (ContextOut == NULL))
1132  return FALSE;
1133 
1134  if (ContextIn->Line == NULL)
1135  return FALSE;
1136 
1137  CacheLine = (PINFCACHELINE)ContextIn->Line;
1138  if (CacheLine->Next == NULL)
1139  return FALSE;
1140 
1141  if (ContextIn != ContextOut)
1142  {
1143  ContextOut->Inf = ContextIn->Inf;
1144  ContextOut->Section = ContextIn->Section;
1145  }
1146  ContextOut->Line = (PVOID)(CacheLine->Next);
1147 
1148  return TRUE;
1149 }
#define TRUE
Definition: types.h:120
struct _INFCACHELINE * PINFCACHELINE
smooth NULL
Definition: ftsmooth.c:416
void * PVOID
Definition: retypes.h:9
if(!(yy_init))
Definition: macro.lex.yy.c:714
UINT Section
Definition: infsupp.h:26
struct _INFCACHELINE * Next
Definition: inffile.c:55
HINF Inf
Definition: infsupp.h:24
UINT Line
Definition: infsupp.h:27

◆ InfFindNextMatchLine()

BOOLEAN InfFindNextMatchLine ( PINFCONTEXT  ContextIn,
PCHAR  Key,
PINFCONTEXT  ContextOut 
)

Definition at line 1190 of file inffile.c.

1194 {
1195  PINFCACHELINE CacheLine;
1196 
1197  if ((ContextIn == NULL) || (ContextOut == NULL) || (Key == NULL) || (*Key == 0))
1198  return FALSE;
1199 
1200  if ((ContextIn->Inf == NULL) || (ContextIn->Section == NULL) || (ContextIn->Line == NULL))
1201  return FALSE;
1202 
1203  CacheLine = (PINFCACHELINE)ContextIn->Line;
1204  while (CacheLine != NULL)
1205  {
1206  if ((CacheLine->Key != NULL) && (_stricmp(CacheLine->Key, Key) == 0))
1207  {
1208 
1209  if (ContextIn != ContextOut)
1210  {
1211  ContextOut->Inf = ContextIn->Inf;
1212  ContextOut->Section = ContextIn->Section;
1213  }
1214  ContextOut->Line = (PVOID)CacheLine;
1215 
1216  return TRUE;
1217  }
1218 
1219  CacheLine = CacheLine->Next;
1220  }
1221 
1222  return FALSE;
1223 }
#define TRUE
Definition: types.h:120
struct _INFCACHELINE * PINFCACHELINE
#define _stricmp
Definition: cat.c:22
while(1)
Definition: macro.lex.yy.c:740
smooth NULL
Definition: ftsmooth.c:416
void * PVOID
Definition: retypes.h:9
UINT Section
Definition: infsupp.h:26
struct _INFCACHELINE * Next
Definition: inffile.c:55
HINF Inf
Definition: infsupp.h:24
UINT Line
Definition: infsupp.h:27
PCHAR Key
Definition: inffile.c:60

◆ InfGetBinaryField()

BOOLEAN InfGetBinaryField ( PINFCONTEXT  Context,
ULONG  FieldIndex,
PUCHAR  ReturnBuffer,
ULONG  ReturnBufferSize,
PULONG  RequiredSize 
)

Definition at line 1278 of file inffile.c.

1284 {
1285  PINFCACHELINE CacheLine;
1286  PINFCACHEFIELD CacheField;
1287  ULONG Index;
1288  ULONG Size;
1289  PUCHAR Ptr;
1290 
1291  if ((Context == NULL) || (Context->Line == NULL) || (FieldIndex == 0))
1292  {
1293 // DPRINT("Invalid parameter\n");
1294  return FALSE;
1295  }
1296 
1297  if (RequiredSize != NULL)
1298  *RequiredSize = 0;
1299 
1300  CacheLine = (PINFCACHELINE)Context->Line;
1301 
1302  if (FieldIndex > CacheLine->FieldCount)
1303  return FALSE;
1304 
1305  CacheField = CacheLine->FirstField;
1306  for (Index = 1; Index < FieldIndex; Index++)
1307  CacheField = CacheField->Next;
1308 
1309  Size = CacheLine->FieldCount - FieldIndex + 1;
1310 
1311  if (RequiredSize != NULL)
1312  *RequiredSize = Size;
1313 
1314  if (ReturnBuffer != NULL)
1315  {
1316  if (ReturnBufferSize < Size)
1317  return FALSE;
1318 
1319  /* Copy binary data */
1320  Ptr = ReturnBuffer;
1321  while (CacheField != NULL)
1322  {
1323  *Ptr = (UCHAR)atoi(CacheField->Data); //strtoul(CacheField->Data, NULL, 16);
1324 
1325  Ptr++;
1326  CacheField = CacheField->Next;
1327  }
1328  }
1329 
1330  return TRUE;
1331 }
#define TRUE
Definition: types.h:120
struct _INFCACHELINE * PINFCACHELINE
struct _INFCACHEFIELD * Next
Definition: inffile.c:47
unsigned char * PUCHAR
Definition: retypes.h:3
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
ULONG FieldCount
Definition: inffile.c:58
_In_ DWORD _In_ DWORD ReturnBufferSize
Definition: setupapi.h:1891
PINFCACHEFIELD FirstField
Definition: inffile.c:62
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PRTL_BUFFER _In_ SIZE_T RequiredSize
if(!(yy_init))
Definition: macro.lex.yy.c:714
_In_ DWORD FieldIndex
Definition: setupapi.h:1889
static const UCHAR Index[8]
Definition: usbohci.c:18
unsigned char UCHAR
Definition: xmlstorage.h:181
CHAR Data[1]
Definition: inffile.c:50
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
unsigned int ULONG
Definition: retypes.h:1

◆ InfGetData()

BOOLEAN InfGetData ( PINFCONTEXT  Context,
PCHAR Key,
PCHAR Data 
)

Definition at line 1509 of file inffile.c.

1513 {
1514  PINFCACHELINE CacheKey;
1515 
1516  if ((Context == NULL) || (Context->Line == NULL) || (Data == NULL))
1517  {
1518 // DPRINT("Invalid parameter\n");
1519  return FALSE;
1520  }
1521 
1522  CacheKey = (PINFCACHELINE)Context->Line;
1523  if (Key != NULL)
1524  *Key = CacheKey->Key;
1525 
1526  if (Data != NULL)
1527  {
1528  if (CacheKey->FirstField == NULL)
1529  {
1530  *Data = NULL;
1531  }
1532  else
1533  {
1534  *Data = CacheKey->FirstField->Data;
1535  }
1536  }
1537 
1538  return TRUE;
1539 }
#define TRUE
Definition: types.h:120
struct _INFCACHELINE * PINFCACHELINE
PINFCACHEFIELD FirstField
Definition: inffile.c:62
smooth NULL
Definition: ftsmooth.c:416
if(!(yy_init))
Definition: macro.lex.yy.c:714
CHAR Data[1]
Definition: inffile.c:50
PCHAR Key
Definition: inffile.c:60

◆ InfGetDataField()

BOOLEAN InfGetDataField ( PINFCONTEXT  Context,
ULONG  FieldIndex,
PCSTR Data 
)

Definition at line 1543 of file inffile.c.

1547 {
1548  PINFCACHELINE CacheLine;
1549  PINFCACHEFIELD CacheField;
1550  ULONG Index;
1551 
1552  if ((Context == NULL) || (Context->Line == NULL) || (Data == NULL))
1553  {
1554 // DPRINT("Invalid parameter\n");
1555  return FALSE;
1556  }
1557 
1558  CacheLine = (PINFCACHELINE)Context->Line;
1559 
1560  if (FieldIndex > CacheLine->FieldCount)
1561  return FALSE;
1562 
1563  if (FieldIndex == 0)
1564  {
1565  *Data = CacheLine->Key;
1566  }
1567  else
1568  {
1569  CacheField = CacheLine->FirstField;
1570  for (Index = 1; Index < FieldIndex; Index++)
1571  CacheField = CacheField->Next;
1572 
1573  *Data = CacheField->Data;
1574  }
1575 
1576  return TRUE;
1577 }
#define TRUE
Definition: types.h:120
struct _INFCACHELINE * PINFCACHELINE
struct _INFCACHEFIELD * Next
Definition: inffile.c:47
ULONG FieldCount
Definition: inffile.c:58
PINFCACHEFIELD FirstField
Definition: inffile.c:62
smooth NULL
Definition: ftsmooth.c:416
if(!(yy_init))
Definition: macro.lex.yy.c:714
_In_ DWORD FieldIndex
Definition: setupapi.h:1889
static const UCHAR Index[8]
Definition: usbohci.c:18
CHAR Data[1]
Definition: inffile.c:50
unsigned int ULONG
Definition: retypes.h:1
PCHAR Key
Definition: inffile.c:60

◆ InfGetFieldCount()

LONG InfGetFieldCount ( PINFCONTEXT  Context)

Definition at line 1268 of file inffile.c.

1269 {
1270  if ((Context == NULL) || (Context->Line == NULL))
1271  return 0;
1272 
1273  return ((PINFCACHELINE)Context->Line)->FieldCount;
1274 }
smooth NULL
Definition: ftsmooth.c:416

◆ InfGetIntField()

BOOLEAN InfGetIntField ( PINFCONTEXT  Context,
ULONG  FieldIndex,
PLONG  IntegerValue 
)

Definition at line 1335 of file inffile.c.

1339 {
1340  PINFCACHELINE CacheLine;
1341  PINFCACHEFIELD CacheField;
1342  ULONG Index;
1343  PCHAR Ptr;
1344 
1345  if ((Context == NULL) || (Context->Line == NULL) || (IntegerValue == NULL))
1346  {
1347 // DPRINT("Invalid parameter\n");
1348  return FALSE;
1349  }
1350 
1351  CacheLine = (PINFCACHELINE)Context->Line;
1352 
1353  if (FieldIndex > CacheLine->FieldCount)
1354  {
1355 // DPRINT("Invalid parameter\n");
1356  return FALSE;
1357  }
1358 
1359  if (FieldIndex == 0)
1360  {
1361  Ptr = CacheLine->Key;
1362  }
1363  else
1364  {
1365  CacheField = CacheLine->FirstField;
1366  for (Index = 1; Index < FieldIndex; Index++)
1367  CacheField = CacheField->Next;
1368 
1369  Ptr = CacheField->Data;
1370  }
1371 
1372  *IntegerValue = atoi(Ptr); //strtol(Ptr, NULL, 0);
1373 
1374  return TRUE;
1375 }
signed char * PCHAR
Definition: retypes.h:7
#define TRUE
Definition: types.h:120
struct _INFCACHELINE * PINFCACHELINE
struct _INFCACHEFIELD * Next
Definition: inffile.c:47
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
ULONG FieldCount
Definition: inffile.c:58
PINFCACHEFIELD FirstField
Definition: inffile.c:62
smooth NULL
Definition: ftsmooth.c:416
if(!(yy_init))
Definition: macro.lex.yy.c:714
_In_ DWORD FieldIndex
Definition: setupapi.h:1889
static const UCHAR Index[8]
Definition: usbohci.c:18
CHAR Data[1]
Definition: inffile.c:50
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
unsigned int ULONG
Definition: retypes.h:1
PCHAR Key
Definition: inffile.c:60

◆ InfGetLineCount()

LONG InfGetLineCount ( HINF  InfHandle,
PCHAR  Section 
)

Definition at line 1227 of file inffile.c.

1230 {
1231  PINFCACHE Cache;
1232  PINFCACHESECTION CacheSection;
1233 
1234  if ((InfHandle == NULL) || (Section == NULL))
1235  {
1236 // DPRINT("Invalid parameter\n");
1237  return -1;
1238  }
1239 
1240  Cache = (PINFCACHE)InfHandle;
1241 
1242  /* Iterate through list of sections */
1243  CacheSection = Cache->FirstSection;
1244  while (Section != NULL)
1245  {
1246 // DPRINT("Comparing '%S' and '%S'\n", CacheSection->Name, Section);
1247 
1248  /* Are the section names the same? */
1249  if (_stricmp(CacheSection->Name, Section) == 0)
1250  {
1251  return CacheSection->LineCount;
1252  }
1253 
1254  /* Get the next section */
1255  CacheSection = CacheSection->Next;
1256  }
1257 
1258 // DPRINT("Section not found\n");
1259 
1260  return -1;
1261 }
LONG LineCount
Definition: inffile.c:75
CHAR Name[1]
Definition: inffile.c:77
Definition: fatfs.h:173
#define _stricmp
Definition: cat.c:22
struct _INFCACHESECTION * Next
Definition: inffile.c:69
smooth NULL
Definition: ftsmooth.c:416
struct _INFCACHE * PINFCACHE

◆ InfGetMultiSzField()

BOOLEAN InfGetMultiSzField ( PINFCONTEXT  Context,
ULONG  FieldIndex,
PCHAR  ReturnBuffer,
ULONG  ReturnBufferSize,
PULONG  RequiredSize 
)

Definition at line 1379 of file inffile.c.

1385 {
1386  PINFCACHELINE CacheLine;
1387  PINFCACHEFIELD CacheField;
1388  PINFCACHEFIELD FieldPtr;
1389  ULONG Index;
1390  SIZE_T Size;
1391  PCHAR Ptr;
1392 
1393  if ((Context == NULL) || (Context->Line == NULL) || (FieldIndex == 0))
1394  {
1395 // DPRINT("Invalid parameter\n");
1396  return FALSE;
1397  }
1398 
1399  if (RequiredSize != NULL)
1400  *RequiredSize = 0;
1401 
1402  CacheLine = (PINFCACHELINE)Context->Line;
1403 
1404  if (FieldIndex > CacheLine->FieldCount)
1405  return FALSE;
1406 
1407  CacheField = CacheLine->FirstField;
1408  for (Index = 1; Index < FieldIndex; Index++)
1409  CacheField = CacheField->Next;
1410 
1411  /* Calculate the required buffer size */
1412  FieldPtr = CacheField;
1413  Size = 0;
1414  while (FieldPtr != NULL)
1415  {
1416  Size += (strlen(FieldPtr->Data) + 1);
1417  FieldPtr = FieldPtr->Next;
1418  }
1419  Size++;
1420 
1421  if (RequiredSize != NULL)
1422  *RequiredSize = (ULONG)Size;
1423 
1424  if (ReturnBuffer != NULL)
1425  {
1426  if (ReturnBufferSize < Size)
1427  return FALSE;
1428 
1429  /* Copy multi-sz string */
1430  Ptr = ReturnBuffer;
1431  FieldPtr = CacheField;
1432  while (FieldPtr != NULL)
1433  {
1434  Size = strlen(FieldPtr->Data) + 1;
1435 
1436  strcpy(Ptr, FieldPtr->Data);
1437 
1438  Ptr = Ptr + Size;
1439  FieldPtr = FieldPtr->Next;
1440  }
1441  *Ptr = 0;
1442  }
1443 
1444  return TRUE;
1445 }
signed char * PCHAR
Definition: retypes.h:7
#define TRUE
Definition: types.h:120
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
struct _INFCACHELINE * PINFCACHELINE
struct _INFCACHEFIELD * Next
Definition: inffile.c:47
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
ULONG FieldCount
Definition: inffile.c:58
_In_ DWORD _In_ DWORD ReturnBufferSize
Definition: setupapi.h:1891
while(1)
Definition: macro.lex.yy.c:740
PINFCACHEFIELD FirstField
Definition: inffile.c:62
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PRTL_BUFFER _In_ SIZE_T RequiredSize
if(!(yy_init))
Definition: macro.lex.yy.c:714
_In_ DWORD FieldIndex
Definition: setupapi.h:1889
static const UCHAR Index[8]
Definition: usbohci.c:18
CHAR Data[1]
Definition: inffile.c:50
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
ULONG_PTR SIZE_T
Definition: typedefs.h:78
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
unsigned int ULONG
Definition: retypes.h:1

◆ InfGetStringField()

BOOLEAN InfGetStringField ( PINFCONTEXT  Context,
ULONG  FieldIndex,
PCHAR  ReturnBuffer,
ULONG  ReturnBufferSize,
PULONG  RequiredSize 
)

Definition at line 1449 of file inffile.c.

1455 {
1456  PINFCACHELINE CacheLine;
1457  PINFCACHEFIELD CacheField;
1458  ULONG Index;
1459  PCHAR Ptr;
1460  SIZE_T Size;
1461 
1462  if ((Context == NULL) || (Context->Line == NULL))
1463  {
1464 // DPRINT("Invalid parameter\n");
1465  return FALSE;
1466  }
1467 
1468  if (RequiredSize != NULL)
1469  *RequiredSize = 0;
1470 
1471  CacheLine = (PINFCACHELINE)Context->Line;
1472 
1473  if (FieldIndex > CacheLine->FieldCount)
1474  return FALSE;
1475 
1476  if (FieldIndex == 0)
1477  {
1478  Ptr = CacheLine->Key;
1479  }
1480  else
1481  {
1482  CacheField = CacheLine->FirstField;
1483  for (Index = 1; Index < FieldIndex; Index++)
1484  CacheField = CacheField->Next;
1485 
1486  Ptr = CacheField->Data;
1487  }
1488 
1489  Size = strlen(Ptr) + 1;
1490 
1491  if (RequiredSize != NULL)
1492  *RequiredSize = (ULONG)Size;
1493 
1494  if (ReturnBuffer != NULL)
1495  {
1496  if (ReturnBufferSize < Size)
1497  return FALSE;
1498 
1499  strcpy(ReturnBuffer, Ptr);
1500  }
1501 
1502  return TRUE;
1503 }
signed char * PCHAR
Definition: retypes.h:7
#define TRUE
Definition: types.h:120
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
struct _INFCACHELINE * PINFCACHELINE
struct _INFCACHEFIELD * Next
Definition: inffile.c:47
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
ULONG FieldCount
Definition: inffile.c:58
_In_ DWORD _In_ DWORD ReturnBufferSize
Definition: setupapi.h:1891
PINFCACHEFIELD FirstField
Definition: inffile.c:62
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PRTL_BUFFER _In_ SIZE_T RequiredSize
if(!(yy_init))
Definition: macro.lex.yy.c:714
_In_ DWORD FieldIndex
Definition: setupapi.h:1889
static const UCHAR Index[8]
Definition: usbohci.c:18
CHAR Data[1]
Definition: inffile.c:50
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
ULONG_PTR SIZE_T
Definition: typedefs.h:78
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
unsigned int ULONG
Definition: retypes.h:1
PCHAR Key
Definition: inffile.c:60

◆ InfOpenFile()

BOOLEAN InfOpenFile ( PHINF  InfHandle,
PCSTR  FileName,
PULONG  ErrorLine 
)

Definition at line 936 of file inffile.c.

940 {
942  ULONG FileId;
943  PCHAR FileBuffer;
948 
949  *InfHandle = NULL;
950  *ErrorLine = (ULONG) - 1;
951 
952  //
953  // Open the .inf file
954  //
955  Status = ArcOpen((PCHAR)FileName, OpenReadOnly, &FileId);
956  if (Status != ESUCCESS)
957  {
958  return FALSE;
959  }
960 
961  //
962  // Query file size
963  //
965  if ((Status != ESUCCESS) || (Information.EndingAddress.HighPart != 0))
966  {
967  ArcClose(FileId);
968  return FALSE;
969  }
970  FileSize = Information.EndingAddress.LowPart;
971 
972  //
973  // Allocate buffer to cache the file
974  //
975  FileBuffer = FrLdrTempAlloc(FileSize + 1, TAG_INF_FILE);
976  if (!FileBuffer)
977  {
978  ArcClose(FileId);
979  return FALSE;
980  }
981 
982  //
983  // Read file into memory
984  //
985  Status = ArcRead(FileId, FileBuffer, FileSize, &Count);
986  if ((Status != ESUCCESS) || (Count != FileSize))
987  {
988  ArcClose(FileId);
989  FrLdrTempFree(FileBuffer, TAG_INF_FILE);
990  return FALSE;
991  }
992 
993  //
994  // We don't need the file anymore. Close it
995  //
996  ArcClose(FileId);
997 
998  //
999  // Append string terminator
1000  //
1001  FileBuffer[FileSize] = 0;
1002 
1003  //
1004  // Allocate infcache header
1005  //
1007  if (!Cache)
1008  {
1009  FrLdrTempFree(FileBuffer, TAG_INF_FILE);
1010  return FALSE;
1011  }
1012 
1013  //
1014  // Initialize inicache header
1015  //
1016  RtlZeroMemory(Cache, sizeof(INFCACHE));
1017 
1018  //
1019  // Parse the inf buffer
1020  //
1022  FileBuffer,
1023  FileBuffer + FileSize,
1024  ErrorLine);
1025  if (!Success)
1026  {
1028  Cache = NULL;
1029  }
1030 
1031  //
1032  // Free file buffer, as it has been parsed
1033  //
1034  FrLdrTempFree(FileBuffer, TAG_INF_FILE);
1035 
1036  //
1037  // Return .inf parsed contents
1038  //
1039  *InfHandle = (HINF)Cache;
1040 
1041  return Success;
1042 }
signed char * PCHAR
Definition: retypes.h:7
#define TAG_INF_CACHE
Definition: inffile.c:42
Definition: arc.h:32
Definition: fatfs.h:173
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
ULONG ARC_STATUS
Definition: arc.h:4
PVOID HINF
Definition: infsupp.h:21
FORCEINLINE PVOID FrLdrTempAlloc(_In_ SIZE_T Size, _In_ ULONG Tag)
Definition: mm.h:177
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
struct _INFCACHE * PINFCACHE
ARC_STATUS ArcRead(ULONG FileId, VOID *Buffer, ULONG N, ULONG *Count)
Definition: fs.c:237
_Must_inspect_result_ _Out_ PLARGE_INTEGER FileSize
Definition: fsrtlfuncs.h:108
Status
Definition: gdiplustypes.h:24
ARC_STATUS ArcClose(ULONG FileId)
Definition: fs.c:219
ARC_STATUS ArcGetFileInformation(ULONG FileId, FILEINFORMATION *Information)
Definition: fs.c:251
ARC_STATUS ArcOpen(CHAR *Path, OPENMODE OpenMode, ULONG *FileId)
Definition: fs.c:57
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
static BOOLEAN InfpParseBuffer(PINFCACHE file, PCCHAR buffer, PCCHAR end, PULONG error_line)
Definition: inffile.c:896
Iosb Information
Definition: create.c:4377
#define TAG_INF_FILE
Definition: inffile.c:43
FORCEINLINE VOID FrLdrTempFree(PVOID Allocation, ULONG Tag)
Definition: mm.h:186

Referenced by LoadReactOSSetup(), and SetupOpenInfFileExW().

◆ InfpAddFieldToLine()

static PVOID InfpAddFieldToLine ( PINFCACHELINE  Line,
PCHAR  Data 
)
static

Definition at line 349 of file inffile.c.

352 {
353  PINFCACHEFIELD Field;
354  SIZE_T Size;
355 
356  Size = sizeof(INFCACHEFIELD) + strlen(Data);
358  if (Field == NULL)
359  {
360  return NULL;
361  }
362  memset(Field, 0, Size);
363 
364  strcpy(Field->Data, Data);
365 
366  /* Append key */
367  if (Line->FirstField == NULL)
368  {
369  Line->FirstField = Field;
370  Line->LastField = Field;
371  }
372  else
373  {
374  Line->LastField->Next = Field;
375  Field->Prev = Line->LastField;
376  Line->LastField = Field;
377  }
378  Line->FieldCount++;
379 
380  return (PVOID)Field;
381 }
struct _INFCACHEFIELD * Prev
Definition: inffile.c:48
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
struct _INFCACHEFIELD * PINFCACHEFIELD
FORCEINLINE PVOID FrLdrTempAlloc(_In_ SIZE_T Size, _In_ ULONG Tag)
Definition: mm.h:177
smooth NULL
Definition: ftsmooth.c:416
struct _INFCACHEFIELD INFCACHEFIELD
Definition: ncftp.h:79
CHAR Data[1]
Definition: inffile.c:50
#define TAG_INF_FIELD
Definition: inffile.c:39
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
ULONG_PTR SIZE_T
Definition: typedefs.h:78
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define memset(x, y, z)
Definition: compat.h:39

Referenced by add_field_from_token(), and InfpAddField().

◆ InfpAddKeyToLine()

static PVOID InfpAddKeyToLine ( PINFCACHELINE  Line,
PCHAR  Key 
)
static

Definition at line 327 of file inffile.c.

330 {
331  if (Line == NULL)
332  return NULL;
333 
334  if (Line->Key != NULL)
335  return NULL;
336 
337  Line->Key = FrLdrTempAlloc(strlen(Key) + 1, TAG_INF_KEY);
338  if (Line->Key == NULL)
339  return NULL;
340 
341  strcpy(Line->Key, Key);
342 
343  return (PVOID)Line->Key;
344 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
FORCEINLINE PVOID FrLdrTempAlloc(_In_ SIZE_T Size, _In_ ULONG Tag)
Definition: mm.h:177
smooth NULL
Definition: ftsmooth.c:416
Definition: ncftp.h:79
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define TAG_INF_KEY
Definition: inffile.c:38

Referenced by add_field_from_token(), and InfpAddLineWithKey().

◆ InfpCacheAddLine()

static PINFCACHELINE InfpCacheAddLine ( PINFCACHESECTION  Section)
static

Definition at line 289 of file inffile.c.

290 {
292 
293  if (Section == NULL)
294  {
295 // DPRINT("Invalid parameter\n");
296  return NULL;
297  }
298 
300  if (Line == NULL)
301  {
302 // DPRINT("RtlAllocateHeap() failed\n");
303  return NULL;
304  }
305  memset(Line, 0, sizeof(INFCACHELINE));
306 
307  /* Append line */
308  if (Section->FirstLine == NULL)
309  {
310  Section->FirstLine = Line;
311  Section->LastLine = Line;
312  }
313  else
314  {
315  Section->LastLine->Next = Line;
316  Line->Prev = Section->LastLine;
317  Section->LastLine = Line;
318  }
319  Section->LineCount++;
320 
321  return Line;
322 }
LONG LineCount
Definition: inffile.c:75
struct _INFCACHELINE * PINFCACHELINE
#define TAG_INF_LINE
Definition: inffile.c:40
FORCEINLINE PVOID FrLdrTempAlloc(_In_ SIZE_T Size, _In_ ULONG Tag)
Definition: mm.h:177
smooth NULL
Definition: ftsmooth.c:416
Definition: ncftp.h:79
PINFCACHELINE FirstLine
Definition: inffile.c:72
struct _INFCACHELINE * Next
Definition: inffile.c:55
PINFCACHELINE LastLine
Definition: inffile.c:73
#define memset(x, y, z)
Definition: compat.h:39
struct Line Line

Referenced by add_field_from_token().

◆ InfpCacheAddSection()

static PINFCACHESECTION InfpCacheAddSection ( PINFCACHE  Cache,
PCHAR  Name 
)
static

Definition at line 244 of file inffile.c.

247 {
248  PINFCACHESECTION Section = NULL;
249  SIZE_T Size;
250 
251  if ((Cache == NULL) || (Name == NULL))
252  {
253 // DPRINT("Invalid parameter\n");
254  return NULL;
255  }
256 
257  /* Allocate and initialize the new section */
258  Size = sizeof(INFCACHESECTION) + strlen(Name);
260  if (Section == NULL)
261  {
262 // DPRINT("RtlAllocateHeap() failed\n");
263  return NULL;
264  }
265  memset(Section, 0, Size);
266 
267  /* Copy section name */
268  strcpy(Section->Name, Name);
269 
270  /* Append section */
271  if (Cache->FirstSection == NULL)
272  {
273  Cache->FirstSection = Section;
274  Cache->LastSection = Section;
275  }
276  else
277  {
278  Cache->LastSection->Next = Section;
279  Section->Prev = Cache->LastSection;
280  Cache->LastSection = Section;
281  }
282 
283  return Section;
284 }
#define TAG_INF_SECTION
Definition: inffile.c:41
CHAR Name[1]
Definition: inffile.c:77
struct _INFCACHESECTION * PINFCACHESECTION
Definition: fatfs.h:173
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
FORCEINLINE PVOID FrLdrTempAlloc(_In_ SIZE_T Size, _In_ ULONG Tag)
Definition: mm.h:177
smooth NULL
Definition: ftsmooth.c:416
struct _INFCACHESECTION * Prev
Definition: inffile.c:70
struct _INFCACHESECTION INFCACHESECTION
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
ULONG_PTR SIZE_T
Definition: typedefs.h:78
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define memset(x, y, z)
Definition: compat.h:39

Referenced by add_section_from_token().

◆ InfpCacheFindKeyLine()

static PINFCACHELINE InfpCacheFindKeyLine ( PINFCACHESECTION  Section,
PCSTR  Key 
)
static

Definition at line 386 of file inffile.c.

389 {
391 
392  Line = Section->FirstLine;
393  while (Line != NULL)
394  {
395  if ((Line->Key != NULL) && (_stricmp(Line->Key, Key) == 0))
396  {
397  return Line;
398  }
399 
400  Line = Line->Next;
401  }
402 
403  return NULL;
404 }
#define _stricmp
Definition: cat.c:22
smooth NULL
Definition: ftsmooth.c:416
Definition: ncftp.h:79
PINFCACHELINE FirstLine
Definition: inffile.c:72
struct Line Line

Referenced by InfFindFirstLine().

◆ InfpCacheFindSection()

static PINFCACHESECTION InfpCacheFindSection ( PINFCACHE  Cache,
PCSTR  Name 
)
static

Definition at line 214 of file inffile.c.

217 {
218  PINFCACHESECTION Section = NULL;
219 
220  if (Cache == NULL || Name == NULL)
221  {
222  return NULL;
223  }
224 
225  /* iterate through list of sections */
226  Section = Cache->FirstSection;
227  while (Section != NULL)
228  {
229  if (_stricmp(Section->Name, Name) == 0)
230  {
231  return Section;
232  }
233 
234  /* get the next section*/
235  Section = Section->Next;
236  }
237 
238  return NULL;
239 }
CHAR Name[1]
Definition: inffile.c:77
Definition: fatfs.h:173
#define _stricmp
Definition: cat.c:22
struct _INFCACHESECTION * Next
Definition: inffile.c:69
smooth NULL
Definition: ftsmooth.c:416

Referenced by add_section_from_token(), and InfpParseBuffer().

◆ InfpCacheFreeLine()

static PINFCACHELINE InfpCacheFreeLine ( PINFCACHELINE  Line)
static

Definition at line 153 of file inffile.c.

155 {
156  PINFCACHELINE Next;
157  PINFCACHEFIELD Field;
158 
159  if (Line == NULL)
160  {
161  return NULL;
162  }
163 
164  Next = Line->Next;
165  if (Line->Key != NULL)
166  {
168  Line->Key = NULL;
169  }
170 
171  /* Remove data fields */
172  while (Line->FirstField != NULL)
173  {
174  Field = Line->FirstField->Next;
175  FrLdrTempFree(Line->FirstField, TAG_INF_FIELD);
176  Line->FirstField = Field;
177  }
178  Line->LastField = NULL;
179 
181 
182  return Next;
183 }
#define TAG_INF_LINE
Definition: inffile.c:40
smooth NULL
Definition: ftsmooth.c:416
Definition: ncftp.h:79
#define TAG_INF_FIELD
Definition: inffile.c:39
#define TAG_INF_KEY
Definition: inffile.c:38
FORCEINLINE VOID FrLdrTempFree(PVOID Allocation, ULONG Tag)
Definition: mm.h:186

Referenced by InfpCacheFreeSection().

◆ InfpCacheFreeSection()

static PINFCACHESECTION InfpCacheFreeSection ( PINFCACHESECTION  Section)
static

Definition at line 188 of file inffile.c.

190 {
191  PINFCACHESECTION Next;
192 
193  if (Section == NULL)
194  {
195  return NULL;
196  }
197 
198  /* Release all keys */
199  Next = Section->Next;
200  while (Section->FirstLine != NULL)
201  {
202  Section->FirstLine = InfpCacheFreeLine(Section->FirstLine);
203  }
204  Section->LastLine = NULL;
205 
206  FrLdrTempFree(Section, TAG_INF_SECTION);
207 
208  return Next;
209 }
#define TAG_INF_SECTION
Definition: inffile.c:41
static PINFCACHELINE InfpCacheFreeLine(PINFCACHELINE Line)
Definition: inffile.c:153
struct _INFCACHESECTION * Next
Definition: inffile.c:69
smooth NULL
Definition: ftsmooth.c:416
PINFCACHELINE FirstLine
Definition: inffile.c:72
PINFCACHELINE LastLine
Definition: inffile.c:73
FORCEINLINE VOID FrLdrTempFree(PVOID Allocation, ULONG Tag)
Definition: mm.h:186

Referenced by InfCloseFile().

◆ InfpParseBuffer()

static BOOLEAN InfpParseBuffer ( PINFCACHE  file,
PCCHAR  buffer,
PCCHAR  end,
PULONG  error_line 
)
static

Definition at line 896 of file inffile.c.

901 {
902  struct parser parser;
903  const CHAR* pos = buffer;
904 
905  parser.start = buffer;
906  parser.end = end;
907  parser.file = file;
908  parser.line = NULL;
910  parser.stack_pos = 0;
912  parser.line_pos = 1;
913  parser.error = TRUE;
914  parser.token_len = 0;
915 
916  /* parser main loop */
917  while (pos)
919 
920  if (parser.error)
921  {
922  if (error_line)
923  *error_line = parser.line_pos;
924  return parser.error;
925  }
926 
927  /* find the [strings] section */
928  file->StringsSection = InfpCacheFindSection(file, "Strings");
929 
930  return TRUE;
931 }
int stack_pos
Definition: inffile.c:110
const CHAR * start
Definition: inffile.c:105
#define TRUE
Definition: types.h:120
char CHAR
Definition: xmlstorage.h:175
enum parser_state state
Definition: import.c:100
GLuint buffer
Definition: glext.h:5915
GLuint GLuint end
Definition: gl.h:1545
static PINFCACHESECTION InfpCacheFindSection(PINFCACHE Cache, PCSTR Name)
Definition: inffile.c:214
PINFCACHELINE line
Definition: inffile.c:113
smooth NULL
Definition: ftsmooth.c:416
const char file[]
Definition: icontest.c:11
unsigned int token_len
Definition: inffile.c:116
unsigned int error
Definition: inffile.c:115
FILE * file
Definition: import.c:88
PINFCACHESECTION cur_section
Definition: inffile.c:112
const CHAR * end
Definition: inffile.c:106
Definition: import.c:86
static const parser_state_func parser_funcs[NB_PARSER_STATES]
Definition: inffile.c:135
unsigned int line_pos
Definition: inffile.c:114
Definition: fci.c:126

Referenced by InfHostOpenBufferedFile(), InfHostOpenFile(), InfOpenBufferedFile(), and InfOpenFile().

◆ is_eof()

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

Definition at line 433 of file inffile.c.

434 {
435  return (ptr >= parser->end || *ptr == CONTROL_Z);
436 }
static PVOID ptr
Definition: dispmode.c:27
const CHAR * end
Definition: inffile.c:106
Definition: import.c:86
#define CONTROL_Z
Definition: inffile.c:32

Referenced by eol_backslash_state(), and line_start_state().

◆ is_eol()

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

Definition at line 440 of file inffile.c.

441 {
442  return ((ptr >= parser->end) ||
443  (*ptr == CONTROL_Z) ||
444  (*ptr == '\n') ||
445  ((*ptr == '\r') && (*(ptr + 1) == '\n')));
446 }
static PVOID ptr
Definition: dispmode.c:27
const CHAR * end
Definition: inffile.c:106
Definition: import.c:86
#define CONTROL_Z
Definition: inffile.c:32

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

◆ key_name_state()

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

Definition at line 636 of file inffile.c.

639 {
640  const CHAR *p, *token_end = parser->start;
641 
642  for (p = pos; !is_eol(parser, p); p++)
643  {
644  if (*p == ',') break;
645  switch(*p)
646  {
647 
648  case '=':
649  push_token(parser, token_end);
650  if (!add_field_from_token(parser, 1)) return NULL;
651  parser->start = p + 1;
654  return p + 1;
655  case ';':
656  push_token(parser, token_end);
657  if (!add_field_from_token(parser, 0)) return NULL;
660  return p + 1;
661  case '"':
662  push_token(parser, token_end);
663  parser->start = p + 1;
666  return p + 1;
667  case '\\':
668  push_token(parser, token_end);
669  parser->start = p;
672  return p;
673  default:
674  if (!isspace((unsigned char)*p)) token_end = p + 1;
675  else
676  {
677  push_token(parser, p);
680  return p;
681  }
682  break;
683  }
684  }
685  push_token(parser, token_end);
687  return p;
688 }
#define isspace(c)
Definition: acclib.h:69
const CHAR * start
Definition: inffile.c:105
char CHAR
Definition: xmlstorage.h:175
static __inline enum parser_state set_state(struct parser *parser, enum parser_state state)
Definition: inffile.c:424
smooth NULL
Definition: ftsmooth.c:416
static struct field * add_field_from_token(struct parser *parser, int is_key)
Definition: inffile.c:508
static __inline void push_state(struct parser *parser, enum parser_state state)
Definition: inffile.c:408
static __inline int is_eol(struct parser *parser, const CHAR *ptr)
Definition: inffile.c:440
Definition: inffile.c:96
static int push_token(struct parser *parser, const CHAR *pos)
Definition: inffile.c:452
Definition: import.c:86
GLfloat GLfloat p
Definition: glext.h:8902

◆ leading_spaces_state()

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

Definition at line 830 of file inffile.c.

833 {
834  const CHAR *p;
835 
836  for (p = pos; !is_eol(parser, p); p++)
837  {
838  if (*p == '\\')
839  {
840  parser->start = p;
842  return p;
843  }
844  if (!isspace((unsigned char)*p))
845  break;
846  }
847  parser->start = p;
848  pop_state(parser);
849  return p;
850 }
#define isspace(c)
Definition: acclib.h:69
const CHAR * start
Definition: inffile.c:105
char CHAR
Definition: xmlstorage.h:175
static __inline enum parser_state set_state(struct parser *parser, enum parser_state state)
Definition: inffile.c:424
static __inline int is_eol(struct parser *parser, const CHAR *ptr)
Definition: inffile.c:440
static __inline void pop_state(struct parser *parser)
Definition: inffile.c:416
Definition: import.c:86
GLfloat GLfloat p
Definition: glext.h:8902

◆ line_start_state()

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

Definition at line 564 of file inffile.c.

567 {
568  const CHAR *p;
569 
570  for (p = pos; !is_eof(parser, p); p++)
571  {
572  switch(*p)
573  {
574  case '\r':
575  continue;
576 
577  case '\n':
578  parser->line_pos++;
580  break;
581 
582  case ';':
585  return p + 1;
586 
587  case '[':
588  parser->start = p + 1;
590  return p + 1;
591 
592  default:
593  if (!isspace((unsigned char)*p))
594  {
595  parser->start = p;
597  return p;
598  }
599  break;
600  }
601  }
603  return NULL;
604 }
#define isspace(c)
Definition: acclib.h:69
const CHAR * start
Definition: inffile.c:105
char CHAR
Definition: xmlstorage.h:175
static __inline enum parser_state set_state(struct parser *parser, enum parser_state state)
Definition: inffile.c:424
static VOID close_current_line(struct parser *parser)
Definition: inffile.c:555
smooth NULL
Definition: ftsmooth.c:416
static __inline void push_state(struct parser *parser, enum parser_state state)
Definition: inffile.c:408
static __inline int is_eof(struct parser *parser, const CHAR *ptr)
Definition: inffile.c:433
Definition: import.c:86
GLfloat GLfloat p
Definition: glext.h:8902
unsigned int line_pos
Definition: inffile.c:114

◆ pop_state()

static __inline void pop_state ( struct parser parser)
static

Definition at line 416 of file inffile.c.

417 {
418 // assert( parser->stack_pos );
420 }
int stack_pos
Definition: inffile.c:110
enum parser_state state
Definition: import.c:100
enum parser_state stack[4]
Definition: inffile.c:109
Definition: import.c:86

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 408 of file inffile.c.

409 {
410 // assert(parser->stack_pos < sizeof(parser->stack)/sizeof(parser->stack[0]));
412 }
int stack_pos
Definition: inffile.c:110
enum parser_state stack[4]
Definition: inffile.c:109
static int state
Definition: maze.c:121
Definition: import.c:86

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 CHAR pos 
)
static

Definition at line 452 of file inffile.c.

455 {
456  SIZE_T len = pos - parser->start;
457  const CHAR *src = parser->start;
459 
462 
463  parser->token_len += (ULONG)len;
464  for ( ; len > 0; len--, dst++, src++)
465  *dst = *src ? (CHAR)*src : L' ';
466  *dst = 0;
467  parser->start = pos;
468 
469  return 0;
470 }
const CHAR * start
Definition: inffile.c:105
char CHAR
Definition: xmlstorage.h:175
#define MAX_FIELD_LEN
Definition: inffile.c:34
unsigned int token_len
Definition: inffile.c:116
static const WCHAR L[]
Definition: oid.c:1250
GLenum GLsizei len
Definition: glext.h:6722
GLenum src
Definition: glext.h:6340
ULONG_PTR SIZE_T
Definition: typedefs.h:78
CHAR token[MAX_FIELD_LEN+1]
Definition: inffile.c:117
GLenum GLenum dst
Definition: glext.h:6340
Definition: import.c:86
unsigned int ULONG
Definition: retypes.h:1

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

◆ quotes_state()

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

Definition at line 796 of file inffile.c.

799 {
800  const CHAR *p, *token_end = parser->start;
801 
802  for (p = pos; !is_eol(parser, p); p++)
803  {
804  if (*p == '"')
805  {
806  if (p + 1 < parser->end && p[1] == '"') /* double quotes */
807  {
808  push_token(parser, p + 1);
809  parser->start = token_end = p + 2;
810  p++;
811  }
812  else /* end of quotes */
813  {
814  push_token(parser, p);
815  parser->start = p + 1;
816  pop_state(parser);
817  return p + 1;
818  }
819  }
820  }
821  push_token(parser, p);
822  pop_state(parser);
823  return p;
824 }
const CHAR * start
Definition: inffile.c:105
char CHAR
Definition: xmlstorage.h:175
static __inline int is_eol(struct parser *parser, const CHAR *ptr)
Definition: inffile.c:440
const CHAR * end
Definition: inffile.c:106
static int push_token(struct parser *parser, const CHAR *pos)
Definition: inffile.c:452
static __inline void pop_state(struct parser *parser)
Definition: inffile.c:416
Definition: import.c:86
GLfloat GLfloat p
Definition: glext.h:8902

◆ section_name_state()

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

Definition at line 610 of file inffile.c.

613 {
614  const CHAR *p;
615 
616  for (p = pos; !is_eol(parser, p); p++)
617  {
618  if (*p == ']')
619  {
620  push_token(parser, p);
622  return NULL;
624  set_state(parser, COMMENT); /* ignore everything else on the line */
625  return p + 1;
626  }
627  }
628  parser->error = STATUS_BAD_SECTION_NAME_LINE; /* unfinished section name */
629  return NULL;
630 }
char CHAR
Definition: xmlstorage.h:175
static __inline enum parser_state set_state(struct parser *parser, enum parser_state state)
Definition: inffile.c:424
smooth NULL
Definition: ftsmooth.c:416
#define STATUS_BAD_SECTION_NAME_LINE
Definition: inffile.h:30
unsigned int error
Definition: inffile.c:115
static __inline void push_state(struct parser *parser, enum parser_state state)
Definition: inffile.c:408
static __inline int is_eol(struct parser *parser, const CHAR *ptr)
Definition: inffile.c:440
static int push_token(struct parser *parser, const CHAR *pos)
Definition: inffile.c:452
Definition: import.c:86
GLfloat GLfloat p
Definition: glext.h:8902
static PVOID add_section_from_token(struct parser *parser)
Definition: inffile.c:476

◆ set_state()

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

Definition at line 424 of file inffile.c.

425 {
426  enum parser_state ret = parser->state;
427  parser->state = state;
428  return ret;
429 }
enum parser_state state
Definition: import.c:100
int ret
static int state
Definition: maze.c:121
parser_state
Definition: import.c:64
Definition: import.c:86

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

◆ trailing_spaces_state()

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

Definition at line 856 of file inffile.c.

859 {
860  const CHAR *p;
861 
862  for (p = pos; !is_eol(parser, p); p++)
863  {
864  if (*p == '\\')
865  {
867  return p;
868  }
869  if (!isspace((unsigned char)*p))
870  break;
871  }
872  pop_state(parser);
873  return p;
874 }
#define isspace(c)
Definition: acclib.h:69
char CHAR
Definition: xmlstorage.h:175
static __inline enum parser_state set_state(struct parser *parser, enum parser_state state)
Definition: inffile.c:424
static __inline int is_eol(struct parser *parser, const CHAR *ptr)
Definition: inffile.c:440
static __inline void pop_state(struct parser *parser)
Definition: inffile.c:416
Definition: import.c:86
GLfloat GLfloat p
Definition: glext.h:8902

◆ value_name_state()

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

Definition at line 694 of file inffile.c.

697 {
698  const CHAR *p, *token_end = parser->start;
699 
700  for (p = pos; !is_eol(parser, p); p++)
701  {
702  switch(*p)
703  {
704  case ';':
705  push_token(parser, token_end);
706  if (!add_field_from_token(parser, 0)) return NULL;
709  return p + 1;
710  case ',':
711  push_token(parser, token_end);
712  if (!add_field_from_token(parser, 0)) return NULL;
713  parser->start = p + 1;
716  return p + 1;
717  case '"':
718  push_token(parser, token_end);
719  parser->start = p + 1;
722  return p + 1;
723  case '\\':
724  push_token(parser, token_end);
725  parser->start = p;
728  return p;
729  default:
730  if (!isspace((unsigned char)*p)) token_end = p + 1;
731  else
732  {
733  push_token(parser, p);
736  return p;
737  }
738  break;
739  }
740  }
741  push_token(parser, token_end);
742  if (!add_field_from_token(parser, 0)) return NULL;
744  return p;
745 }
#define isspace(c)
Definition: acclib.h:69
const CHAR * start
Definition: inffile.c:105
char CHAR
Definition: xmlstorage.h:175
static __inline enum parser_state set_state(struct parser *parser, enum parser_state state)
Definition: inffile.c:424
smooth NULL
Definition: ftsmooth.c:416
static struct field * add_field_from_token(struct parser *parser, int is_key)
Definition: inffile.c:508
static __inline void push_state(struct parser *parser, enum parser_state state)
Definition: inffile.c:408
static __inline int is_eol(struct parser *parser, const CHAR *ptr)
Definition: inffile.c:440
Definition: inffile.c:96
static int push_token(struct parser *parser, const CHAR *pos)
Definition: inffile.c:452
Definition: import.c:86
GLfloat GLfloat p
Definition: glext.h:8902

Variable Documentation

◆ parser_funcs

Initial value:
=
{
}
static const CHAR * trailing_spaces_state(struct parser *parser, const CHAR *pos)
Definition: inffile.c:856
static const CHAR * key_name_state(struct parser *parser, const CHAR *pos)
Definition: inffile.c:636
static const CHAR * leading_spaces_state(struct parser *parser, const CHAR *pos)
Definition: inffile.c:830
static const CHAR * value_name_state(struct parser *parser, const CHAR *pos)
Definition: inffile.c:694
static const CHAR * comment_state(struct parser *parser, const CHAR *pos)
Definition: inffile.c:880
static const CHAR * section_name_state(struct parser *parser, const CHAR *pos)
Definition: inffile.c:610
static const CHAR * quotes_state(struct parser *parser, const CHAR *pos)
Definition: inffile.c:796
static const CHAR * line_start_state(struct parser *parser, const CHAR *pos)
Definition: inffile.c:564
static const CHAR * eol_backslash_state(struct parser *parser, const CHAR *pos)
Definition: inffile.c:751

Definition at line 135 of file inffile.c.

Referenced by InfpParseBuffer().