ReactOS 0.4.16-dev-2491-g3dc6630
inifile.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  INI_SECTION_ITEM
 
struct  INI_SECTION
 

Macros

#define INI_FILE_COMMENT_CHAR   ';'
 
#define TAG_INI_FILE   'FinI'
 
#define TAG_INI_SECTION   'SinI'
 
#define TAG_INI_SECTION_ITEM   'IinI'
 
#define TAG_INI_NAME   'NinI'
 
#define TAG_INI_VALUE   'VinI'
 

Typedefs

typedef struct INI_SECTION_ITEMPINI_SECTION_ITEM
 
typedef struct INI_SECTIONPINI_SECTION
 

Functions

BOOLEAN IniParseFile (PCSTR IniFileData, ULONG IniFileSize)
 
ULONG IniGetNextLineSize (PCSTR IniFileData, ULONG IniFileSize, ULONG CurrentOffset)
 
ULONG IniGetNextLine (PCSTR IniFileData, ULONG IniFileSize, PCHAR Buffer, ULONG BufferSize, ULONG CurrentOffset)
 
BOOLEAN IniIsLineEmpty (PCSTR TextLine, ULONG TextLength)
 
BOOLEAN IniIsCommentLine (PCSTR TextLine, ULONG TextLength)
 
BOOLEAN IniIsSectionName (PCSTR TextLine, ULONG TextLength)
 
ULONG IniGetSectionNameSize (PCSTR SectionNameLine, ULONG LineLength)
 
VOID IniExtractSectionName (PSTR SectionName, PCSTR SectionNameLine, ULONG LineLength)
 
BOOLEAN IniIsSetting (PCSTR TextLine, ULONG TextLength)
 
ULONG IniGetSettingNameSize (PCSTR SettingNameLine, ULONG LineLength)
 
ULONG IniGetSettingValueSize (PCSTR SettingValueLine, ULONG LineLength)
 
VOID IniExtractSettingName (PSTR SettingName, PCSTR SettingNameLine, ULONG LineLength)
 
VOID IniExtractSettingValue (PSTR SettingValue, PCSTR SettingValueLine, ULONG LineLength)
 
BOOLEAN IniFileInitialize (VOID)
 
BOOLEAN IniOpenSection (PCSTR SectionName, ULONG_PTR *SectionId)
 
ULONG IniGetNumSectionItems (ULONG_PTR SectionId)
 
ULONG IniGetSectionSettingNameSize (ULONG_PTR SectionId, ULONG SettingIndex)
 
ULONG IniGetSectionSettingValueSize (ULONG_PTR SectionId, ULONG SettingIndex)
 
BOOLEAN IniReadSettingByNumber (ULONG_PTR SectionId, ULONG SettingNumber, PCHAR SettingName, ULONG NameSize, PCHAR SettingValue, ULONG ValueSize)
 
BOOLEAN IniReadSettingByName (ULONG_PTR SectionId, PCSTR SettingName, PCHAR Buffer, ULONG BufferSize)
 
BOOLEAN IniAddSection (PCSTR SectionName, ULONG_PTR *SectionId)
 
BOOLEAN IniAddSettingValueToSection (ULONG_PTR SectionId, PCSTR SettingName, PCSTR SettingValue)
 
BOOLEAN IniModifySettingValue (ULONG_PTR SectionId, PCSTR SettingName, PCSTR SettingValue)
 
VOID IniCleanup (VOID)
 
PLIST_ENTRY IniGetFileSectionListHead (VOID)
 

Variables

LIST_ENTRY IniFileSectionListHead
 
BOOLEAN IniFileSectionInitialized
 
ULONG IniFileSectionCount
 
ULONG IniFileSettingCount
 

Macro Definition Documentation

◆ INI_FILE_COMMENT_CHAR

#define INI_FILE_COMMENT_CHAR   ';'

Definition at line 22 of file inifile.h.

◆ TAG_INI_FILE

#define TAG_INI_FILE   'FinI'

Definition at line 24 of file inifile.h.

◆ TAG_INI_NAME

#define TAG_INI_NAME   'NinI'

Definition at line 27 of file inifile.h.

◆ TAG_INI_SECTION

#define TAG_INI_SECTION   'SinI'

Definition at line 25 of file inifile.h.

◆ TAG_INI_SECTION_ITEM

#define TAG_INI_SECTION_ITEM   'IinI'

Definition at line 26 of file inifile.h.

◆ TAG_INI_VALUE

#define TAG_INI_VALUE   'VinI'

Definition at line 28 of file inifile.h.

Typedef Documentation

◆ PINI_SECTION

◆ PINI_SECTION_ITEM

Function Documentation

◆ IniAddSection()

BOOLEAN IniAddSection ( PCSTR  SectionName,
ULONG_PTR SectionId 
)

Definition at line 187 of file inifile.c.

188{
189 PINI_SECTION Section;
190
191 // Allocate a new section structure
192 Section = FrLdrTempAlloc(sizeof(INI_SECTION), TAG_INI_SECTION);
193 if (!Section)
194 {
195 return FALSE;
196 }
197
198 RtlZeroMemory(Section, sizeof(INI_SECTION));
199
200 // Allocate the section name buffer
201 Section->SectionName = FrLdrTempAlloc(strlen(SectionName) + sizeof(CHAR), TAG_INI_NAME);
202 if (!Section->SectionName)
203 {
205 return FALSE;
206 }
207
208 // Get the section name
209 strcpy(Section->SectionName, SectionName);
210 InitializeListHead(&Section->SectionItemList);
211
212 // Add it to the section list head
215
216 *SectionId = (ULONG_PTR)Section;
217
218 return TRUE;
219}
VOID FrLdrTempFree(PVOID Allocation, ULONG Tag)
Definition: heap.c:553
PVOID FrLdrTempAlloc(_In_ SIZE_T Size, _In_ ULONG Tag)
Definition: heap.c:545
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1592
#define ULONG_PTR
Definition: config.h:101
#define InsertHeadList(ListHead, Entry)
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
ULONG IniFileSectionCount
Definition: parse.c:27
#define TAG_INI_SECTION
Definition: inifile.h:25
#define TAG_INI_NAME
Definition: inifile.h:27
LIST_ENTRY IniFileSectionListHead
Definition: parse.c:25
strcpy
Definition: string.h:131
LIST_ENTRY ListEntry
Definition: inicache.h:21
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
char CHAR
Definition: xmlstorage.h:175

◆ IniAddSettingValueToSection()

BOOLEAN IniAddSettingValueToSection ( ULONG_PTR  SectionId,
PCSTR  SettingName,
PCSTR  SettingValue 
)

Definition at line 260 of file inifile.c.

261{
262 PINI_SECTION Section = (PINI_SECTION)SectionId;
263 PINI_SECTION_ITEM SectionItem;
264
265 // Allocate a new item structure
267 if (!SectionItem)
268 {
269 return FALSE;
270 }
271
272 RtlZeroMemory(SectionItem, sizeof(INI_SECTION_ITEM));
273
274 // Allocate the setting name buffer
275 SectionItem->ItemName = FrLdrTempAlloc(strlen(SettingName) + 1, TAG_INI_NAME);
276 if (!SectionItem->ItemName)
277 {
279 return FALSE;
280 }
281
282 // Allocate the setting value buffer
283 SectionItem->ItemValue = FrLdrTempAlloc(strlen(SettingValue) + 1, TAG_INI_VALUE);
284 if (!SectionItem->ItemValue)
285 {
286 FrLdrTempFree(SectionItem->ItemName, TAG_INI_NAME);
288 return FALSE;
289 }
290
291 strcpy(SectionItem->ItemName, SettingName);
292 strcpy(SectionItem->ItemValue, SettingValue);
293
294 // Add it to the current section
295 Section->SectionItemCount++;
296 InsertTailList(&Section->SectionItemList, &SectionItem->ListEntry);
297
298 return TRUE;
299}
#define InsertTailList(ListHead, Entry)
struct _INI_SECTION * PINI_SECTION
#define TAG_INI_VALUE
Definition: inifile.h:28
#define TAG_INI_SECTION_ITEM
Definition: inifile.h:26
LIST_ENTRY ListEntry
Definition: inifile.h:35
PSTR ItemValue
Definition: inifile.h:37

Referenced by EditCustomBootReactOS(), IniModifySettingValue(), and InitOperatingSystemList().

◆ IniCleanup()

VOID IniCleanup ( VOID  )

Definition at line 243 of file inifile.c.

244{
245 PLIST_ENTRY ListEntry;
246 PINI_SECTION Section;
247
248 // Loop while there are sections
250 {
251 // Remove the section
253 Section = CONTAINING_RECORD(ListEntry, INI_SECTION, ListEntry);
254
255 // Free it
256 IniFreeSection(Section);
257 }
258}
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
#define RemoveHeadList(ListHead)
Definition: env_spec_w32.h:964
VOID IniFreeSection(PINI_SECTION Section)
Definition: inifile.c:221
Definition: typedefs.h:120
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Referenced by LoadAndBootWindowsCommon(), and RunLoader().

◆ IniExtractSectionName()

VOID IniExtractSectionName ( PSTR  SectionName,
PCSTR  SectionNameLine,
ULONG  LineLength 
)

Definition at line 315 of file parse.c.

316{
317 ULONG Idx, DestIdx;
318
319 // Find the opening bracket (skipping whitespace)
320 for (Idx = 0; Idx < LineLength; ++Idx)
321 {
322 if ((SectionNameLine[Idx] == ' ') || (SectionNameLine[Idx] == '\t'))
323 continue;
324
325 //if (SectionNameLine[Idx] == '[')
326 break;
327 }
328 // Skip past the opening bracket
329 ++Idx;
330
331 // Count the characters up until the closing bracket or EOL
332 for (DestIdx = 0; Idx < LineLength; ++Idx)
333 {
334 if ((SectionNameLine[Idx] == ']') || (SectionNameLine[Idx] == '\0'))
335 break;
336
337 // Copy the character
338 SectionName[DestIdx] = SectionNameLine[Idx];
339 ++DestIdx;
340 }
341
342 // Terminate the string
343 SectionName[DestIdx] = '\0';
344}
uint32_t ULONG
Definition: typedefs.h:59

Referenced by IniParseFile().

◆ IniExtractSettingName()

VOID IniExtractSettingName ( PSTR  SettingName,
PCSTR  SettingNameLine,
ULONG  LineLength 
)

Definition at line 423 of file parse.c.

424{
425 ULONG Idx, DestIdx;
426
427 // Skip whitespace
428 for (Idx = 0; Idx < LineLength; ++Idx)
429 {
430 if ((SettingNameLine[Idx] == ' ') || (SettingNameLine[Idx] == '\t'))
431 continue;
432 break;
433 }
434
435 // Get the characters up until the '=' equals sign or EOL
436 for (DestIdx = 0; Idx < LineLength; ++Idx)
437 {
438 if ((SettingNameLine[Idx] == '=') || (SettingNameLine[Idx] == '\0'))
439 {
440 // Before ending, trim any trailing whitespace
441 for (; DestIdx > 0; --DestIdx)
442 {
443 if ((SettingName[DestIdx-1] == ' ') || (SettingName[DestIdx-1] == '\t'))
444 continue;
445 break;
446 }
447 break;
448 }
449
450 // Copy the character
451 SettingName[DestIdx] = SettingNameLine[Idx];
452 ++DestIdx;
453 }
454
455 // Terminate the string
456 SettingName[DestIdx] = '\0';
457}

Referenced by IniParseFile().

◆ IniExtractSettingValue()

VOID IniExtractSettingValue ( PSTR  SettingValue,
PCSTR  SettingValueLine,
ULONG  LineLength 
)

Definition at line 459 of file parse.c.

460{
461 ULONG Idx, DestIdx;
462
463 // Skip whitespace
464 for (Idx = 0; Idx < LineLength; ++Idx)
465 {
466 if ((SettingValueLine[Idx] == ' ') || (SettingValueLine[Idx] == '\t'))
467 continue;
468 break;
469 }
470
471 // Skip the characters up until the '=' equals sign or EOL
472 for (; Idx < LineLength; ++Idx)
473 {
474 if (SettingValueLine[Idx] == '=')
475 {
476 ++Idx;
477 break;
478 }
479
480 // If we hit EOL then obviously the value size is zero
481 if (SettingValueLine[Idx] == '\0')
482 {
483 SettingValue[0] = '\0';
484 return;
485 }
486 }
487
488 // Get the characters up until the EOL
489 for (DestIdx = 0; Idx < LineLength; ++Idx)
490 {
491 if (SettingValueLine[Idx] == '\0')
492 break;
493
494 // Copy the character
495 SettingValue[DestIdx] = SettingValueLine[Idx];
496 ++DestIdx;
497 }
498
499 // Terminate the string
500 SettingValue[DestIdx] = '\0';
501}

Referenced by IniParseFile().

◆ IniFileInitialize()

BOOLEAN IniFileInitialize ( VOID  )

Definition at line 25 of file ini_init.c.

26{
28 ULONG FileId; // File handle for freeldr.ini
29 PCHAR FreeLoaderIniFileData;
30 ULONG FreeLoaderIniFileSize, Count;
33
34 TRACE("IniFileInitialize()\n");
35
36 /* Try to open freeldr.ini */
37 Status = FsOpenFile("freeldr.ini", FrLdrBootPath, OpenReadOnly, &FileId);
38 if (Status != ESUCCESS)
39 {
40 ERR("Error while opening freeldr.ini, Status: %d\n", Status);
41
42 /* Try to open boot.ini */
43 Status = FsOpenFile("boot.ini", FrLdrBootPath, OpenReadOnly, &FileId);
44 if (Status != ESUCCESS)
45 {
46 ERR("Error while opening boot.ini, Status: %d\n", Status);
47 UiMessageBoxCritical("Error opening freeldr.ini/boot.ini or file not found.\nYou need to re-install FreeLoader.");
48 return FALSE;
49 }
50 }
51
52 /* Get the file size */
54 if (Status != ESUCCESS || FileInformation.EndingAddress.HighPart != 0)
55 {
56 UiMessageBoxCritical("Error while getting informations about freeldr.ini.\nYou need to re-install FreeLoader.");
57 ArcClose(FileId);
58 return FALSE;
59 }
60 FreeLoaderIniFileSize = FileInformation.EndingAddress.LowPart;
61
62 /* Allocate memory to cache the whole freeldr.ini */
63 FreeLoaderIniFileData = FrLdrTempAlloc(FreeLoaderIniFileSize, TAG_INI_FILE);
64 if (!FreeLoaderIniFileData)
65 {
66 UiMessageBoxCritical("Out of memory while loading freeldr.ini.");
67 ArcClose(FileId);
68 return FALSE;
69 }
70
71 /* Load freeldr.ini from the disk */
72 Status = ArcRead(FileId, FreeLoaderIniFileData, FreeLoaderIniFileSize, &Count);
73 if (Status != ESUCCESS || Count != FreeLoaderIniFileSize)
74 {
75 ERR("Error while reading freeldr.ini, Status: %d\n", Status);
76 UiMessageBoxCritical("Error while reading freeldr.ini.");
77 ArcClose(FileId);
78 FrLdrTempFree(FreeLoaderIniFileData, TAG_INI_FILE);
79 return FALSE;
80 }
81
82 /* Parse the .ini file data */
83 Success = IniParseFile(FreeLoaderIniFileData, FreeLoaderIniFileSize);
84
85 /* Do some cleanup, and return */
86 ArcClose(FileId);
87 FrLdrTempFree(FreeLoaderIniFileData, TAG_INI_FILE);
88
89 return Success;
90}
unsigned char BOOLEAN
Definition: actypes.h:127
#define ERR(fmt,...)
Definition: precomp.h:57
ARC_STATUS ArcGetFileInformation(ULONG FileId, FILEINFORMATION *Information)
Definition: fs.c:462
ARC_STATUS FsOpenFile(IN PCSTR FileName, IN PCSTR DefaultPath OPTIONAL, IN OPENMODE OpenMode, OUT PULONG FileId)
Definition: fs.c:478
ARC_STATUS ArcClose(_In_ ULONG FileId)
Definition: fs.c:409
ARC_STATUS ArcRead(ULONG FileId, VOID *Buffer, ULONG N, ULONG *Count)
Definition: fs.c:448
VOID UiMessageBoxCritical(_In_ PCSTR MessageText)
Definition: ui.c:372
@ Success
Definition: eventcreate.c:712
CCHAR FrLdrBootPath[MAX_PATH]
Definition: freeldr.c:29
Status
Definition: gdiplustypes.h:25
#define TAG_INI_FILE
Definition: inifile.h:24
BOOLEAN IniParseFile(PCSTR IniFileData, ULONG IniFileSize)
Definition: parse.c:31
int Count
Definition: noreturn.cpp:7
static OUT PIO_STATUS_BLOCK OUT PVOID FileInformation
Definition: pipe.c:75
@ ESUCCESS
Definition: arc.h:32
ULONG ARC_STATUS
Definition: arc.h:4
@ OpenReadOnly
Definition: arc.h:65
#define TRACE(s)
Definition: solgame.cpp:4
char * PCHAR
Definition: typedefs.h:51

Referenced by RunLoader().

◆ IniGetFileSectionListHead()

PLIST_ENTRY IniGetFileSectionListHead ( VOID  )

Definition at line 25 of file inifile.c.

26{
28}

Referenced by LoadSettings().

◆ IniGetNextLine()

ULONG IniGetNextLine ( PCSTR  IniFileData,
ULONG  IniFileSize,
PCHAR  Buffer,
ULONG  BufferSize,
ULONG  CurrentOffset 
)

Definition at line 202 of file parse.c.

203{
204 ULONG Idx;
205
206 // Loop through grabbing chars until we hit the end
207 // of the file or we encounter a newline character
208 for (Idx = 0; (CurrentOffset < IniFileSize); ++CurrentOffset)
209 {
210 // If we haven't exceeded our buffer size yet
211 // then store another character
212 if (Idx < (BufferSize - 1))
213 Buffer[Idx++] = IniFileData[CurrentOffset];
214
215 // Check for newline character
216 if (IniFileData[CurrentOffset] == '\n')
217 {
218 ++CurrentOffset;
219 break;
220 }
221 }
222
223 // Terminate the string
224 Buffer[Idx] = '\0';
225
226 // Get rid of newline & linefeed characters (if any)
227 while (Idx && (Buffer[--Idx] == '\n' || Buffer[Idx] == '\r'))
228 Buffer[Idx] = '\0';
229
230 return CurrentOffset;
231}
Definition: bufpool.h:45
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254

Referenced by IniParseFile().

◆ IniGetNextLineSize()

ULONG IniGetNextLineSize ( PCSTR  IniFileData,
ULONG  IniFileSize,
ULONG  CurrentOffset 
)

Definition at line 181 of file parse.c.

182{
183 ULONG LineCharCount = 0;
184
185 // Loop through counting chars until we hit the end
186 // of the file or we encounter a newline character
187 for (; (CurrentOffset < IniFileSize); ++CurrentOffset)
188 {
189 // Increment the line character count
190 ++LineCharCount;
191
192 // Check for newline character
193 if (IniFileData[CurrentOffset] == '\n')
194 break;
195 }
196 // Count the NUL-terminator
197 ++LineCharCount;
198
199 return LineCharCount;
200}

Referenced by IniParseFile().

◆ IniGetNumSectionItems()

ULONG IniGetNumSectionItems ( ULONG_PTR  SectionId)

Definition at line 60 of file inifile.c.

61{
62 PINI_SECTION Section = (PINI_SECTION)SectionId;
63
64 TRACE("IniGetNumSectionItems() SectionId = 0x%x\n", SectionId);
65 TRACE("IniGetNumSectionItems() Item count = %d\n", Section->SectionItemCount);
66
67 return Section->SectionItemCount;
68}

Referenced by BuildArgvForOsLoader(), InitOperatingSystemList(), and UiShowMessageBoxesInSection().

◆ IniGetSectionNameSize()

ULONG IniGetSectionNameSize ( PCSTR  SectionNameLine,
ULONG  LineLength 
)

Definition at line 286 of file parse.c.

287{
288 ULONG Idx, NameSize;
289
290 // Find the opening bracket (skipping whitespace)
291 for (Idx = 0; Idx < LineLength; ++Idx)
292 {
293 if ((SectionNameLine[Idx] == ' ') || (SectionNameLine[Idx] == '\t'))
294 continue;
295
296 //if (SectionNameLine[Idx] == '[')
297 break;
298 }
299 // Skip past the opening bracket
300 ++Idx;
301
302 // Count the characters up until the closing bracket or EOL
303 for (NameSize = 0; Idx < LineLength; ++Idx)
304 {
305 if ((SectionNameLine[Idx] == ']') || (SectionNameLine[Idx] == '\0'))
306 break;
307 ++NameSize;
308 }
309 // Count the NUL-terminator
310 ++NameSize;
311
312 return NameSize;
313}

Referenced by IniParseFile().

◆ IniGetSectionSettingNameSize()

ULONG IniGetSectionSettingNameSize ( ULONG_PTR  SectionId,
ULONG  SettingIndex 
)

Definition at line 95 of file inifile.c.

96{
97 PINI_SECTION_ITEM SectionItem;
98
99 // Retrieve requested setting
100 SectionItem = IniGetSettingByNumber(SectionId, SettingIndex);
101 if (!SectionItem)
102 return 0;
103
104 // Return the size of the string plus 1 for the null-terminator
105 return (ULONG)(strlen(SectionItem->ItemName) + 1);
106}
PINI_SECTION_ITEM IniGetSettingByNumber(ULONG_PTR SectionId, ULONG SettingNumber)
Definition: inifile.c:70
_In_ WDFUSBINTERFACE _In_ UCHAR SettingIndex
Definition: wdfusb.h:2303

Referenced by BuildArgvForOsLoader().

◆ IniGetSectionSettingValueSize()

ULONG IniGetSectionSettingValueSize ( ULONG_PTR  SectionId,
ULONG  SettingIndex 
)

Definition at line 108 of file inifile.c.

109{
110 PINI_SECTION_ITEM SectionItem;
111
112 // Retrieve requested setting
113 SectionItem = IniGetSettingByNumber(SectionId, SettingIndex);
114 if (!SectionItem)
115 return 0;
116
117 // Return the size of the string plus 1 for the null-terminator
118 return (ULONG)(strlen(SectionItem->ItemValue) + 1);
119}

Referenced by BuildArgvForOsLoader(), and UiShowMessageBoxesInSection().

◆ IniGetSettingNameSize()

ULONG IniGetSettingNameSize ( PCSTR  SettingNameLine,
ULONG  LineLength 
)

Definition at line 359 of file parse.c.

360{
361 ULONG Idx, NameSize;
362
363 // Skip whitespace
364 for (Idx = 0; Idx < LineLength; ++Idx)
365 {
366 if ((SettingNameLine[Idx] == ' ') || (SettingNameLine[Idx] == '\t'))
367 continue;
368 break;
369 }
370
371 // Count the characters up until the '=' equals sign or EOL
372 for (NameSize = 0; Idx < LineLength; ++Idx)
373 {
374 if ((SettingNameLine[Idx] == '=') || (SettingNameLine[Idx] == '\0'))
375 break;
376 ++NameSize;
377 }
378 // Count the NUL-terminator
379 ++NameSize;
380
381 return NameSize;
382}

Referenced by IniParseFile().

◆ IniGetSettingValueSize()

ULONG IniGetSettingValueSize ( PCSTR  SettingValueLine,
ULONG  LineLength 
)

Definition at line 384 of file parse.c.

385{
386 ULONG Idx, ValueSize;
387
388 // Skip whitespace
389 for (Idx = 0; Idx < LineLength; ++Idx)
390 {
391 if ((SettingValueLine[Idx] == ' ') || (SettingValueLine[Idx] == '\t'))
392 continue;
393 break;
394 }
395
396 // Skip the characters up until the '=' equals sign or EOL
397 for (; Idx < LineLength; ++Idx)
398 {
399 if (SettingValueLine[Idx] == '=')
400 {
401 ++Idx;
402 break;
403 }
404
405 // If we hit EOL then obviously the value size is zero
406 if (SettingValueLine[Idx] == '\0')
407 return 0;
408 }
409
410 // Count the characters up until the EOL
411 for (ValueSize = 0; Idx < LineLength; ++Idx)
412 {
413 if (SettingValueLine[Idx] == '\0')
414 break;
415 ++ValueSize;
416 }
417 // Count the NUL-terminator
418 ++ValueSize;
419
420 return ValueSize;
421}

Referenced by IniParseFile().

◆ IniIsCommentLine()

BOOLEAN IniIsCommentLine ( PCSTR  TextLine,
ULONG  TextLength 
)

Definition at line 250 of file parse.c.

251{
252 ULONG Idx;
253
254 // Check the first character (skipping whitespace)
255 // and make sure that it is a comment character
256 for (Idx = 0; Idx < TextLength; ++Idx)
257 {
258 if ((TextLine[Idx] == ' ') || (TextLine[Idx] == '\t'))
259 continue;
260
261 if (TextLine[Idx] == INI_FILE_COMMENT_CHAR)
262 return TRUE;
263 break;
264 }
265 return FALSE;
266}
#define INI_FILE_COMMENT_CHAR
Definition: inifile.h:22

Referenced by IniParseFile().

◆ IniIsLineEmpty()

BOOLEAN IniIsLineEmpty ( PCSTR  TextLine,
ULONG  TextLength 
)

Definition at line 233 of file parse.c.

234{
235 ULONG Idx;
236
237 // Check for text (skipping whitespace)
238 for (Idx = 0; Idx < TextLength; ++Idx)
239 {
240 if ((TextLine[Idx] == ' ') || (TextLine[Idx] == '\t') ||
241 (TextLine[Idx] == '\n') || (TextLine[Idx] == '\r'))
242 {
243 continue;
244 }
245 return FALSE;
246 }
247 return TRUE;
248}

Referenced by IniParseFile().

◆ IniIsSectionName()

BOOLEAN IniIsSectionName ( PCSTR  TextLine,
ULONG  TextLength 
)

Definition at line 268 of file parse.c.

269{
270 ULONG Idx;
271
272 // Check the first character (skipping whitespace)
273 // and make sure that it is an opening bracket
274 for (Idx = 0; Idx < TextLength; ++Idx)
275 {
276 if ((TextLine[Idx] == ' ') || (TextLine[Idx] == '\t'))
277 continue;
278
279 if (TextLine[Idx] == '[')
280 return TRUE;
281 break;
282 }
283 return FALSE;
284}

Referenced by IniParseFile().

◆ IniIsSetting()

BOOLEAN IniIsSetting ( PCSTR  TextLine,
ULONG  TextLength 
)

Definition at line 346 of file parse.c.

347{
348 ULONG Idx;
349
350 // Just check for an '=' equals sign
351 for (Idx = 0; Idx < TextLength; ++Idx)
352 {
353 if (TextLine[Idx] == '=')
354 return TRUE;
355 }
356 return FALSE;
357}

Referenced by IniParseFile().

◆ IniModifySettingValue()

BOOLEAN IniModifySettingValue ( ULONG_PTR  SectionId,
PCSTR  SettingName,
PCSTR  SettingValue 
)

Definition at line 301 of file inifile.c.

302{
303 PINI_SECTION Section = (PINI_SECTION)SectionId;
305 PINI_SECTION_ITEM SectionItem;
306 PCHAR NewItemValue;
307
308 // Loop through each section item and find the one we want
309 for (Entry = Section->SectionItemList.Flink;
310 Entry != &Section->SectionItemList;
311 Entry = Entry->Flink)
312 {
313 SectionItem = CONTAINING_RECORD(Entry, INI_SECTION_ITEM, ListEntry);
314
315 // Check to see if this is the setting we want
316 if (_stricmp(SectionItem->ItemName, SettingName) == 0)
317 {
318 break;
319 }
320 // Nope, keep going
321 }
322 // If the section item does not exist, create it
323 if (Entry == &Section->SectionItemList)
324 {
325 return IniAddSettingValueToSection(SectionId, SettingName, SettingValue);
326 }
327
328 // Reallocate the new setting value buffer
329 NewItemValue = FrLdrTempAlloc(strlen(SettingValue) + 1, TAG_INI_VALUE);
330 if (!NewItemValue)
331 {
332 // We failed, bail out
333 return FALSE;
334 }
336 SectionItem->ItemValue = NewItemValue;
337
338 strcpy(SectionItem->ItemValue, SettingValue);
339
340 return TRUE;
341}
#define _stricmp
Definition: cat.c:22
BOOLEAN IniAddSettingValueToSection(ULONG_PTR SectionId, PCSTR SettingName, PCSTR SettingValue)
Definition: inifile.c:260
base of all file and directory entries
Definition: entries.h:83

Referenced by EditCustomBootReactOS(), GetOSLoadingMethod(), and InitOperatingSystemList().

◆ IniOpenSection()

BOOLEAN IniOpenSection ( PCSTR  SectionName,
ULONG_PTR SectionId 
)

Definition at line 30 of file inifile.c.

31{
33 PINI_SECTION Section;
34
35 TRACE("IniOpenSection() SectionName = %s\n", SectionName);
36
37 // Loop through each section and find the one we want
40 Entry = Entry->Flink)
41 {
42 Section = CONTAINING_RECORD(Entry, INI_SECTION, ListEntry);
43
44 // Compare against the section name
45 if (_stricmp(SectionName, Section->SectionName) == 0)
46 {
47 // We found it
48 if (SectionId)
49 *SectionId = (ULONG_PTR)Section;
50 TRACE("IniOpenSection() Found it! SectionId = 0x%x\n", SectionId);
51 return TRUE;
52 }
53 }
54
55 TRACE("IniOpenSection() Section not found.\n");
56
57 return FALSE;
58}
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121

Referenced by InitOperatingSystemList(), LoadSettings(), and UiInitialize().

◆ IniParseFile()

BOOLEAN IniParseFile ( PCSTR  IniFileData,
ULONG  IniFileSize 
)

Definition at line 31 of file parse.c.

32{
33 ULONG CurrentOffset;
34 ULONG CurrentLineNumber;
35 PCHAR IniFileLine;
36 ULONG IniFileLineSize;
37 ULONG LineLength;
38 PINI_SECTION CurrentSection = NULL;
39 PINI_SECTION_ITEM CurrentItem = NULL;
40
41 TRACE("IniParseFile() IniFileSize: %d\n", IniFileSize);
42
44 {
47 }
48
49 // Start with an 80-byte buffer
50 IniFileLineSize = 80;
51 IniFileLine = FrLdrTempAlloc(IniFileLineSize, TAG_INI_FILE);
52 if (!IniFileLine)
53 return FALSE;
54
55 // Loop through each line and parse it
56 CurrentLineNumber = 0;
57 CurrentOffset = 0;
58 while (CurrentOffset < IniFileSize)
59 {
60 // First check the line size and increase our buffer if necessary
61 if (IniFileLineSize < IniGetNextLineSize(IniFileData, IniFileSize, CurrentOffset))
62 {
63 IniFileLineSize = IniGetNextLineSize(IniFileData, IniFileSize, CurrentOffset);
64 FrLdrTempFree(IniFileLine, TAG_INI_FILE);
65 IniFileLine = FrLdrTempAlloc(IniFileLineSize, TAG_INI_FILE);
66 if (!IniFileLine)
67 return FALSE;
68 }
69
70 // Get the line of data
71 CurrentOffset = IniGetNextLine(IniFileData, IniFileSize, IniFileLine, IniFileLineSize, CurrentOffset);
72 LineLength = (ULONG)strlen(IniFileLine);
73
74 // If it is a blank line or a comment then skip it
75 if (IniIsLineEmpty(IniFileLine, LineLength) || IniIsCommentLine(IniFileLine, LineLength))
76 {
77 CurrentLineNumber++;
78 continue;
79 }
80
81 // Check if it is a new section
82 if (IniIsSectionName(IniFileLine, LineLength))
83 {
84 // Allocate a new section structure
85 CurrentSection = FrLdrTempAlloc(sizeof(INI_SECTION), TAG_INI_SECTION);
86 if (!CurrentSection)
87 {
88 FrLdrTempFree(IniFileLine, TAG_INI_FILE);
89 return FALSE;
90 }
91
92 RtlZeroMemory(CurrentSection, sizeof(INI_SECTION));
93
94 // Allocate the section name buffer
95 CurrentSection->SectionName = FrLdrTempAlloc(IniGetSectionNameSize(IniFileLine, LineLength), TAG_INI_NAME);
96 if (!CurrentSection->SectionName)
97 {
98 FrLdrTempFree(CurrentSection, TAG_INI_FILE);
99 FrLdrTempFree(IniFileLine, TAG_INI_FILE);
100 return FALSE;
101 }
102
103 // Get the section name
104 IniExtractSectionName(CurrentSection->SectionName, IniFileLine, LineLength);
105 InitializeListHead(&CurrentSection->SectionItemList);
106
107 // Add it to the section list head
110
111 CurrentLineNumber++;
112 continue;
113 }
114
115 // Check if it is a setting
116 if (IniIsSetting(IniFileLine, LineLength))
117 {
118 // First check to make sure we're inside a [section]
119 if (CurrentSection == NULL)
120 {
121 ERR("Error: freeldr.ini:%lu: Setting '%s' found outside of a [section].\n", CurrentLineNumber, IniFileLine);
122
123 // Skip it
124 CurrentLineNumber++;
125 continue;
126 }
127
128 // Allocate a new item structure
130 if (!CurrentItem)
131 {
132 FrLdrTempFree(IniFileLine, TAG_INI_FILE);
133 return FALSE;
134 }
135
136 RtlZeroMemory(CurrentItem, sizeof(INI_SECTION_ITEM));
137
138 // Allocate the setting name buffer
139 CurrentItem->ItemName = FrLdrTempAlloc(IniGetSettingNameSize(IniFileLine, LineLength), TAG_INI_NAME);
140 if (!CurrentItem->ItemName)
141 {
143 FrLdrTempFree(IniFileLine, TAG_INI_FILE);
144 return FALSE;
145 }
146
147 // Allocate the setting value buffer
148 CurrentItem->ItemValue = FrLdrTempAlloc(IniGetSettingValueSize(IniFileLine, LineLength), TAG_INI_VALUE);
149 if (!CurrentItem->ItemValue)
150 {
151 FrLdrTempFree(CurrentItem->ItemName, TAG_INI_NAME);
153 FrLdrTempFree(IniFileLine, TAG_INI_FILE);
154 return FALSE;
155 }
156
157 // Get the section name
158 IniExtractSettingName(CurrentItem->ItemName, IniFileLine, LineLength);
159 IniExtractSettingValue(CurrentItem->ItemValue, IniFileLine, LineLength);
160
161 // Add it to the current section
163 CurrentSection->SectionItemCount++;
164 InsertTailList(&CurrentSection->SectionItemList, &CurrentItem->ListEntry);
165
166 CurrentLineNumber++;
167 continue;
168 }
169
170 CurrentLineNumber++;
171 }
172
173 FrLdrTempFree(IniFileLine, TAG_INI_FILE);
174
175 TRACE("Parsed %d sections and %d settings.\n", IniFileSectionCount, IniFileSettingCount);
176 TRACE("IniParseFile() done.\n");
177
178 return TRUE;
179}
ULONG IniFileSectionCount
Definition: parse.c:27
VOID IniExtractSettingValue(PSTR SettingValue, PCSTR SettingValueLine, ULONG LineLength)
Definition: parse.c:459
ULONG IniGetSectionNameSize(PCSTR SectionNameLine, ULONG LineLength)
Definition: parse.c:286
VOID IniExtractSectionName(PSTR SectionName, PCSTR SectionNameLine, ULONG LineLength)
Definition: parse.c:315
ULONG IniGetSettingValueSize(PCSTR SettingValueLine, ULONG LineLength)
Definition: parse.c:384
BOOLEAN IniIsLineEmpty(PCSTR TextLine, ULONG TextLength)
Definition: parse.c:233
ULONG IniGetSettingNameSize(PCSTR SettingNameLine, ULONG LineLength)
Definition: parse.c:359
ULONG IniFileSettingCount
Definition: parse.c:28
LIST_ENTRY IniFileSectionListHead
Definition: parse.c:25
BOOLEAN IniIsSectionName(PCSTR TextLine, ULONG TextLength)
Definition: parse.c:268
ULONG IniGetNextLine(PCSTR IniFileData, ULONG IniFileSize, PCHAR Buffer, ULONG BufferSize, ULONG CurrentOffset)
Definition: parse.c:202
VOID IniExtractSettingName(PSTR SettingName, PCSTR SettingNameLine, ULONG LineLength)
Definition: parse.c:423
BOOLEAN IniIsCommentLine(PCSTR TextLine, ULONG TextLength)
Definition: parse.c:250
ULONG IniGetNextLineSize(PCSTR IniFileData, ULONG IniFileSize, ULONG CurrentOffset)
Definition: parse.c:181
BOOLEAN IniIsSetting(PCSTR TextLine, ULONG TextLength)
Definition: parse.c:346
BOOLEAN IniFileSectionInitialized
Definition: parse.c:26
#define NULL
Definition: types.h:112

Referenced by IniFileInitialize().

◆ IniReadSettingByName()

BOOLEAN IniReadSettingByName ( ULONG_PTR  SectionId,
PCSTR  SettingName,
PCHAR  Buffer,
ULONG  BufferSize 
)

Definition at line 154 of file inifile.c.

155{
156 PINI_SECTION Section = (PINI_SECTION)SectionId;
158 PINI_SECTION_ITEM SectionItem;
159
160 TRACE("IniReadSettingByName() SectionId = 0x%x\n", SectionId);
161
162 // Loop through each section item and find the one we want
163 for (Entry = Section->SectionItemList.Flink;
164 Entry != &Section->SectionItemList;
165 Entry = Entry->Flink)
166 {
167 SectionItem = CONTAINING_RECORD(Entry, INI_SECTION_ITEM, ListEntry);
168
169 // Check to see if this is the setting we want
170 if (_stricmp(SettingName, SectionItem->ItemName) == 0)
171 {
172 TRACE("IniReadSettingByName() Setting \'%s\' found.\n", SettingName);
173 TRACE("IniReadSettingByName() Setting value = %s\n", SectionItem->ItemValue);
174
175 strncpy(Buffer, SectionItem->ItemValue, BufferSize - 1);
176 Buffer[BufferSize - 1] = '\0';
177
178 return TRUE;
179 }
180 }
181
182 WARN("IniReadSettingByName() Setting \'%s\' not found.\n", SettingName);
183
184 return FALSE;
185}
#define WARN(fmt,...)
Definition: precomp.h:61
strncpy
Definition: string.h:335

Referenced by EditCustomBootReactOS(), GetOSLoadingMethod(), InitOperatingSystemList(), LoadSettings(), and UiInitialize().

◆ IniReadSettingByNumber()

BOOLEAN IniReadSettingByNumber ( ULONG_PTR  SectionId,
ULONG  SettingNumber,
PCHAR  SettingName,
ULONG  NameSize,
PCHAR  SettingValue,
ULONG  ValueSize 
)

Definition at line 121 of file inifile.c.

122{
123 PINI_SECTION_ITEM SectionItem;
124 TRACE(".001 NameSize = %d ValueSize = %d\n", NameSize, ValueSize);
125
126 TRACE("IniReadSettingByNumber() SectionId = 0x%x\n", SectionId);
127
128 // Retrieve requested setting
129 SectionItem = IniGetSettingByNumber(SectionId, SettingNumber);
130 if (!SectionItem)
131 {
132 TRACE("IniReadSettingByNumber() Setting number %d not found.\n", SettingNumber);
133 return FALSE;
134 }
135
136 TRACE("IniReadSettingByNumber() Setting number %d found.\n", SettingNumber);
137 TRACE("IniReadSettingByNumber() Setting name = %s\n", SectionItem->ItemName);
138 TRACE("IniReadSettingByNumber() Setting value = %s\n", SectionItem->ItemValue);
139
140 TRACE("1 NameSize = %d ValueSize = %d\n", NameSize, ValueSize);
141 TRACE("2 NameSize = %d ValueSize = %d\n", NameSize, ValueSize);
142 strncpy(SettingName, SectionItem->ItemName, NameSize - 1);
143 SettingName[NameSize - 1] = '\0';
144 TRACE("3 NameSize = %d ValueSize = %d\n", NameSize, ValueSize);
145 strncpy(SettingValue, SectionItem->ItemValue, ValueSize - 1);
146 SettingValue[ValueSize - 1] = '\0';
147 TRACE("4 NameSize = %d ValueSize = %d\n", NameSize, ValueSize);
148 DbgDumpBuffer(DPRINT_INIFILE, SettingName, NameSize);
149 DbgDumpBuffer(DPRINT_INIFILE, SettingValue, ValueSize);
150
151 return TRUE;
152}
#define DbgDumpBuffer(mask, buf, len)
Definition: debug.h:122
#define DPRINT_INIFILE
Definition: debug.h:27

Referenced by BuildArgvForOsLoader(), InitOperatingSystemList(), and UiShowMessageBoxesInSection().

Variable Documentation

◆ IniFileSectionCount

ULONG IniFileSectionCount
extern

Definition at line 27 of file parse.c.

Referenced by IniAddSection(), and IniParseFile().

◆ IniFileSectionInitialized

BOOLEAN IniFileSectionInitialized
extern

Definition at line 26 of file parse.c.

Referenced by IniParseFile().

◆ IniFileSectionListHead

LIST_ENTRY IniFileSectionListHead
extern

◆ IniFileSettingCount

ULONG IniFileSettingCount
extern

Definition at line 28 of file parse.c.

Referenced by IniParseFile().