ReactOS 0.4.15-dev-7931-gfd331f1
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 (PCHAR IniFileData, ULONG IniFileSize)
 
ULONG IniGetNextLineSize (PCHAR IniFileData, ULONG IniFileSize, ULONG CurrentOffset)
 
ULONG IniGetNextLine (PCHAR IniFileData, ULONG IniFileSize, PCHAR Buffer, ULONG BufferSize, ULONG CurrentOffset)
 
BOOLEAN IniIsLineEmpty (PCHAR LineOfText, ULONG TextLength)
 
BOOLEAN IniIsCommentLine (PCHAR LineOfText, ULONG TextLength)
 
BOOLEAN IniIsSectionName (PCHAR LineOfText, ULONG TextLength)
 
ULONG IniGetSectionNameSize (PCHAR SectionNameLine, ULONG LineLength)
 
VOID IniExtractSectionName (PCHAR SectionName, PCHAR SectionNameLine, ULONG LineLength)
 
BOOLEAN IniIsSetting (PCHAR LineOfText, ULONG TextLength)
 
ULONG IniGetSettingNameSize (PCHAR SettingNameLine, ULONG LineLength)
 
ULONG IniGetSettingValueSize (PCHAR SettingValueLine, ULONG LineLength)
 
VOID IniExtractSettingName (PCHAR SettingName, PCHAR SettingNameLine, ULONG LineLength)
 
VOID IniExtractSettingValue (PCHAR SettingValue, PCHAR 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)
 

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 182 of file inifile.c.

183{
184 PINI_SECTION Section;
185
186 // Allocate a new section structure
187 Section = FrLdrTempAlloc(sizeof(INI_SECTION), TAG_INI_SECTION);
188 if (!Section)
189 {
190 return FALSE;
191 }
192
193 RtlZeroMemory(Section, sizeof(INI_SECTION));
194
195 // Allocate the section name buffer
196 Section->SectionName = FrLdrTempAlloc(strlen(SectionName) + sizeof(CHAR), TAG_INI_NAME);
197 if (!Section->SectionName)
198 {
200 return FALSE;
201 }
202
203 // Get the section name
204 strcpy(Section->SectionName, SectionName);
206
207 // Add it to the section list head
210
211 *SectionId = (ULONG_PTR)Section;
212
213 return TRUE;
214}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
FORCEINLINE PVOID FrLdrTempAlloc(_In_ SIZE_T Size, _In_ ULONG Tag)
Definition: mm.h:188
FORCEINLINE VOID FrLdrTempFree(PVOID Allocation, ULONG Tag)
Definition: mm.h:197
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#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
LIST_ENTRY ListEntry
Definition: inifile.h:48
LIST_ENTRY SectionItemList
Definition: inifile.h:51
PCHAR SectionName
Definition: inifile.h:49
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
char CHAR
Definition: xmlstorage.h:175

Referenced by EditCustomBootReactOS(), and InitOperatingSystemList().

◆ IniAddSettingValueToSection()

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

Definition at line 255 of file inifile.c.

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

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

◆ IniCleanup()

VOID IniCleanup ( VOID  )

Definition at line 238 of file inifile.c.

239{
240 PLIST_ENTRY ListEntry;
241 PINI_SECTION Section;
242
243 // Loop while there are sections
245 {
246 // Remove the section
248 Section = CONTAINING_RECORD(ListEntry, INI_SECTION, ListEntry);
249
250 // Free it
251 IniFreeSection(Section);
252 }
253}
#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:216
Definition: typedefs.h:120
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Referenced by LoadAndBootWindowsCommon(), and RunLoader().

◆ IniExtractSectionName()

VOID IniExtractSectionName ( PCHAR  SectionName,
PCHAR  SectionNameLine,
ULONG  LineLength 
)

Definition at line 360 of file parse.c.

361{
362 ULONG Idx;
363 ULONG DestIdx;
364
365 // Find the opening bracket (skipping whitespace)
366 for (Idx=0; Idx<LineLength; Idx++)
367 {
368 if ((SectionNameLine[Idx] == ' ') ||
369 (SectionNameLine[Idx] == '\t'))
370 {
371 continue;
372 }
373 else //if (SectionNameLine[Idx] == '[')
374 {
375 break;
376 }
377 }
378
379 // Skip past the opening bracket
380 Idx++;
381
382 // Count the characters up until the closing bracket or EOL
383 for (DestIdx=0; Idx<LineLength; Idx++)
384 {
385 if ((SectionNameLine[Idx] == ']') ||
386 (SectionNameLine[Idx] == '\0'))
387 {
388 break;
389 }
390
391 // Grab a character and increment DestIdx
392 SectionName[DestIdx] = SectionNameLine[Idx];
393 DestIdx++;
394 }
395
396 // Terminate the string
397 SectionName[DestIdx] = '\0';
398}
uint32_t ULONG
Definition: typedefs.h:59

Referenced by IniParseFile().

◆ IniExtractSettingName()

VOID IniExtractSettingName ( PCHAR  SettingName,
PCHAR  SettingNameLine,
ULONG  LineLength 
)

Definition at line 507 of file parse.c.

508{
509 ULONG Idx;
510 ULONG DestIdx;
511
512 // Skip whitespace
513 for (Idx=0; Idx<LineLength; Idx++)
514 {
515 if ((SettingNameLine[Idx] == ' ') ||
516 (SettingNameLine[Idx] == '\t'))
517 {
518 continue;
519 }
520 else
521 {
522 break;
523 }
524 }
525
526 // Get the characters up until the '=' equals sign or EOL
527 for (DestIdx=0; Idx<LineLength; Idx++)
528 {
529 if ((SettingNameLine[Idx] == '=') ||
530 (SettingNameLine[Idx] == '\0'))
531 {
532 break;
533 }
534
535 // Grab a character and increment DestIdx
536 SettingName[DestIdx] = SettingNameLine[Idx];
537 DestIdx++;
538 }
539
540 // Terminate the string
541 SettingName[DestIdx] = '\0';
542}

Referenced by IniParseFile().

◆ IniExtractSettingValue()

VOID IniExtractSettingValue ( PCHAR  SettingValue,
PCHAR  SettingValueLine,
ULONG  LineLength 
)

Definition at line 544 of file parse.c.

545{
546 ULONG Idx;
547 ULONG DestIdx;
548
549 // Skip whitespace
550 for (Idx=0; Idx<LineLength; Idx++)
551 {
552 if ((SettingValueLine[Idx] == ' ') ||
553 (SettingValueLine[Idx] == '\t'))
554 {
555 continue;
556 }
557 else
558 {
559 break;
560 }
561 }
562
563 // Skip the characters up until the '=' equals sign or EOL
564 for (; Idx<LineLength; Idx++)
565 {
566 if (SettingValueLine[Idx] == '=')
567 {
568 Idx++;
569 break;
570 }
571
572 // If we hit EOL then obviously the value size is zero
573 if (SettingValueLine[Idx] == '\0')
574 {
575 SettingValue[0] = '\0';
576 return;
577 }
578 }
579
580 // Get the characters up until the EOL
581 for (DestIdx=0; Idx<LineLength; Idx++)
582 {
583 if (SettingValueLine[Idx] == '\0')
584 {
585 break;
586 }
587
588 // Grab a character and increment DestIdx
589 SettingValue[DestIdx] = SettingValueLine[Idx];
590 DestIdx++;
591 }
592
593 // Terminate the string
594 SettingValue[DestIdx] = '\0';
595}

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 UiMessageBoxCritical("Error opening freeldr.ini or file not found.\nYou need to re-install FreeLoader.");
42 return FALSE;
43 }
44
45 /* Get the file size */
47 if (Status != ESUCCESS || FileInformation.EndingAddress.HighPart != 0)
48 {
49 UiMessageBoxCritical("Error while getting informations about freeldr.ini.\nYou need to re-install FreeLoader.");
50 ArcClose(FileId);
51 return FALSE;
52 }
53 FreeLoaderIniFileSize = FileInformation.EndingAddress.LowPart;
54
55 /* Allocate memory to cache the whole freeldr.ini */
56 FreeLoaderIniFileData = FrLdrTempAlloc(FreeLoaderIniFileSize, TAG_INI_FILE);
57 if (!FreeLoaderIniFileData)
58 {
59 UiMessageBoxCritical("Out of memory while loading freeldr.ini.");
60 ArcClose(FileId);
61 return FALSE;
62 }
63
64 /* Load freeldr.ini from the disk */
65 Status = ArcRead(FileId, FreeLoaderIniFileData, FreeLoaderIniFileSize, &Count);
66 if (Status != ESUCCESS || Count != FreeLoaderIniFileSize)
67 {
68 ERR("Error while reading freeldr.ini, Status: %d\n", Status);
69 UiMessageBoxCritical("Error while reading freeldr.ini.");
70 ArcClose(FileId);
71 FrLdrTempFree(FreeLoaderIniFileData, TAG_INI_FILE);
72 return FALSE;
73 }
74
75 /* Parse the .ini file data */
76 Success = IniParseFile(FreeLoaderIniFileData, FreeLoaderIniFileSize);
77
78 /* Do some cleanup, and return */
79 ArcClose(FileId);
80 FrLdrTempFree(FreeLoaderIniFileData, TAG_INI_FILE);
81
82 return Success;
83}
unsigned char BOOLEAN
#define ERR(fmt,...)
Definition: debug.h:110
ARC_STATUS ArcClose(ULONG FileId)
Definition: fs.c:220
ARC_STATUS ArcGetFileInformation(ULONG FileId, FILEINFORMATION *Information)
Definition: fs.c:252
ARC_STATUS FsOpenFile(IN PCSTR FileName, IN PCSTR DefaultPath OPTIONAL, IN OPENMODE OpenMode, OUT PULONG FileId)
Definition: fs.c:268
ARC_STATUS ArcRead(ULONG FileId, VOID *Buffer, ULONG N, ULONG *Count)
Definition: fs.c:238
VOID UiMessageBoxCritical(_In_ PCSTR MessageText)
Definition: ui.c:372
@ Success
Definition: eventcreate.c:712
CCHAR FrLdrBootPath[MAX_PATH]
Definition: freeldr.c:39
Status
Definition: gdiplustypes.h:25
#define TAG_INI_FILE
Definition: inifile.h:24
BOOLEAN IniParseFile(PCHAR IniFileData, ULONG IniFileSize)
Definition: parse.c:31
static OUT PIO_STATUS_BLOCK OUT PVOID FileInformation
Definition: pipe.c:75
int Count
Definition: noreturn.cpp:7
@ 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().

◆ IniGetNextLine()

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

Definition at line 210 of file parse.c.

211{
212 ULONG Idx;
213
214 // Loop through grabbing chars until we hit the end of the
215 // file or we encounter a new line char
216 for (Idx=0; (CurrentOffset < IniFileSize); CurrentOffset++)
217 {
218 // If we haven't exceeded our buffer size yet
219 // then store another char
220 if (Idx < (BufferSize - 1))
221 {
222 Buffer[Idx++] = IniFileData[CurrentOffset];
223 }
224
225 // Check for new line char
226 if (IniFileData[CurrentOffset] == '\n')
227 {
228 CurrentOffset++;
229 break;
230 }
231 }
232
233 // Terminate the string
234 Buffer[Idx] = '\0';
235
236 // Get rid of newline & linefeed characters (if any)
237 while(Idx && (Buffer[--Idx] == '\n' || Buffer[Idx] == '\r'))
238 Buffer[Idx] = '\0';
239
240 // Send back new offset
241 return CurrentOffset;
242}
Definition: bufpool.h:45
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254

Referenced by IniParseFile().

◆ IniGetNextLineSize()

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

Definition at line 185 of file parse.c.

186{
187 ULONG LineCharCount = 0;
188
189 // Loop through counting chars until we hit the end of the
190 // file or we encounter a new line char
191 for (; (CurrentOffset < IniFileSize); CurrentOffset++)
192 {
193 // Increment the line character count
194 LineCharCount++;
195
196 // Check for new line char
197 if (IniFileData[CurrentOffset] == '\n')
198 {
199 break;
200 }
201 }
202
203 // Add one for the NULL-terminator
204 LineCharCount++;
205
206 // Send back line character count
207 return LineCharCount;
208}

Referenced by IniParseFile().

◆ IniGetNumSectionItems()

ULONG IniGetNumSectionItems ( ULONG_PTR  SectionId)

Definition at line 55 of file inifile.c.

56{
57 PINI_SECTION Section = (PINI_SECTION)SectionId;
58
59 TRACE("IniGetNumSectionItems() SectionId = 0x%x\n", SectionId);
60 TRACE("IniGetNumSectionItems() Item count = %d\n", Section->SectionItemCount);
61
62 return Section->SectionItemCount;
63}

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

◆ IniGetSectionNameSize()

ULONG IniGetSectionNameSize ( PCHAR  SectionNameLine,
ULONG  LineLength 
)

Definition at line 319 of file parse.c.

320{
321 ULONG Idx;
322 ULONG NameSize;
323
324 // Find the opening bracket (skipping whitespace)
325 for (Idx=0; Idx<LineLength; Idx++)
326 {
327 if ((SectionNameLine[Idx] == ' ') ||
328 (SectionNameLine[Idx] == '\t'))
329 {
330 continue;
331 }
332 else //if (SectionNameLine[Idx] == '[')
333 {
334 break;
335 }
336 }
337
338 // Skip past the opening bracket
339 Idx++;
340
341 // Count the characters up until the closing bracket or EOL
342 for (NameSize=0; Idx<LineLength; Idx++)
343 {
344 if ((SectionNameLine[Idx] == ']') ||
345 (SectionNameLine[Idx] == '\0'))
346 {
347 break;
348 }
349
350 // Increment the count
351 NameSize++;
352 }
353
354 // Add one for the NULL-terminator
355 NameSize++;
356
357 return NameSize;
358}

Referenced by IniParseFile().

◆ IniGetSectionSettingNameSize()

ULONG IniGetSectionSettingNameSize ( ULONG_PTR  SectionId,
ULONG  SettingIndex 
)

Definition at line 90 of file inifile.c.

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

Referenced by BuildArgvForOsLoader().

◆ IniGetSectionSettingValueSize()

ULONG IniGetSectionSettingValueSize ( ULONG_PTR  SectionId,
ULONG  SettingIndex 
)

Definition at line 103 of file inifile.c.

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

Referenced by BuildArgvForOsLoader(), and UiShowMessageBoxesInSection().

◆ IniGetSettingNameSize()

ULONG IniGetSettingNameSize ( PCHAR  SettingNameLine,
ULONG  LineLength 
)

Definition at line 416 of file parse.c.

417{
418 ULONG Idx;
419 ULONG NameSize;
420
421 // Skip whitespace
422 for (Idx=0; Idx<LineLength; Idx++)
423 {
424 if ((SettingNameLine[Idx] == ' ') ||
425 (SettingNameLine[Idx] == '\t'))
426 {
427 continue;
428 }
429 else
430 {
431 break;
432 }
433 }
434
435 // Count the characters up until the '=' equals sign or EOL
436 for (NameSize=0; Idx<LineLength; Idx++)
437 {
438 if ((SettingNameLine[Idx] == '=') ||
439 (SettingNameLine[Idx] == '\0'))
440 {
441 break;
442 }
443
444 // Increment the count
445 NameSize++;
446 }
447
448 // Add one for the NULL-terminator
449 NameSize++;
450
451 return NameSize;
452}

Referenced by IniParseFile().

◆ IniGetSettingValueSize()

ULONG IniGetSettingValueSize ( PCHAR  SettingValueLine,
ULONG  LineLength 
)

Definition at line 454 of file parse.c.

455{
456 ULONG Idx;
457 ULONG ValueSize;
458
459 // Skip whitespace
460 for (Idx=0; Idx<LineLength; Idx++)
461 {
462 if ((SettingValueLine[Idx] == ' ') ||
463 (SettingValueLine[Idx] == '\t'))
464 {
465 continue;
466 }
467 else
468 {
469 break;
470 }
471 }
472
473 // Skip the characters up until the '=' equals sign or EOL
474 for (; Idx<LineLength; Idx++)
475 {
476 if (SettingValueLine[Idx] == '=')
477 {
478 Idx++;
479 break;
480 }
481
482 // If we hit EOL then obviously the value size is zero
483 if (SettingValueLine[Idx] == '\0')
484 {
485 return 0;
486 }
487 }
488
489 // Count the characters up until the EOL
490 for (ValueSize=0; Idx<LineLength; Idx++)
491 {
492 if (SettingValueLine[Idx] == '\0')
493 {
494 break;
495 }
496
497 // Increment the count
498 ValueSize++;
499 }
500
501 // Add one for the NULL-terminator
502 ValueSize++;
503
504 return ValueSize;
505}

Referenced by IniParseFile().

◆ IniIsCommentLine()

BOOLEAN IniIsCommentLine ( PCHAR  LineOfText,
ULONG  TextLength 
)

Definition at line 267 of file parse.c.

268{
269 ULONG Idx;
270
271 // Check the first character (skipping whitespace)
272 // and make sure that it is an opening bracket
273 for (Idx=0; Idx<TextLength; Idx++)
274 {
275 if ((LineOfText[Idx] == ' ') ||
276 (LineOfText[Idx] == '\t'))
277 {
278 continue;
279 }
280 else if (LineOfText[Idx] == INI_FILE_COMMENT_CHAR)
281 {
282 return TRUE;
283 }
284 else
285 {
286 break;
287 }
288 }
289
290 return FALSE;
291}
#define INI_FILE_COMMENT_CHAR
Definition: inifile.h:22

Referenced by IniParseFile().

◆ IniIsLineEmpty()

BOOLEAN IniIsLineEmpty ( PCHAR  LineOfText,
ULONG  TextLength 
)

Definition at line 244 of file parse.c.

245{
246 ULONG Idx;
247
248 // Check for text (skipping whitespace)
249 for (Idx=0; Idx<TextLength; Idx++)
250 {
251 if ((LineOfText[Idx] == ' ') ||
252 (LineOfText[Idx] == '\t') ||
253 (LineOfText[Idx] == '\n') ||
254 (LineOfText[Idx] == '\r'))
255 {
256 continue;
257 }
258 else
259 {
260 return FALSE;
261 }
262 }
263
264 return TRUE;
265}

Referenced by IniParseFile().

◆ IniIsSectionName()

BOOLEAN IniIsSectionName ( PCHAR  LineOfText,
ULONG  TextLength 
)

Definition at line 293 of file parse.c.

294{
295 ULONG Idx;
296
297 // Check the first character (skipping whitespace)
298 // and make sure that it is an opening bracket
299 for (Idx=0; Idx<TextLength; Idx++)
300 {
301 if ((LineOfText[Idx] == ' ') ||
302 (LineOfText[Idx] == '\t'))
303 {
304 continue;
305 }
306 else if (LineOfText[Idx] == '[')
307 {
308 return TRUE;
309 }
310 else
311 {
312 break;
313 }
314 }
315
316 return FALSE;
317}

Referenced by IniParseFile().

◆ IniIsSetting()

BOOLEAN IniIsSetting ( PCHAR  LineOfText,
ULONG  TextLength 
)

Definition at line 400 of file parse.c.

401{
402 ULONG Idx;
403
404 // Basically just check for an '=' equals sign
405 for (Idx=0; Idx<TextLength; Idx++)
406 {
407 if (LineOfText[Idx] == '=')
408 {
409 return TRUE;
410 }
411 }
412
413 return FALSE;
414}

Referenced by IniParseFile().

◆ IniModifySettingValue()

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

Definition at line 296 of file inifile.c.

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

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

◆ IniOpenSection()

BOOLEAN IniOpenSection ( PCSTR  SectionName,
ULONG_PTR SectionId 
)

Definition at line 25 of file inifile.c.

26{
28 PINI_SECTION Section;
29
30 TRACE("IniOpenSection() SectionName = %s\n", SectionName);
31
32 // Loop through each section and find the one we want
35 Entry = Entry->Flink)
36 {
37 Section = CONTAINING_RECORD(Entry, INI_SECTION, ListEntry);
38
39 // Compare against the section name
40 if (_stricmp(SectionName, Section->SectionName) == 0)
41 {
42 // We found it
43 if (SectionId)
44 *SectionId = (ULONG_PTR)Section;
45 TRACE("IniOpenSection() Found it! SectionId = 0x%x\n", SectionId);
46 return TRUE;
47 }
48 }
49
50 TRACE("IniOpenSection() Section not found.\n");
51
52 return FALSE;
53}

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

◆ IniParseFile()

BOOLEAN IniParseFile ( PCHAR  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 {
54 return FALSE;
55 }
56
57 // Loop through each line and parse it
58 CurrentLineNumber = 0;
59 CurrentOffset = 0;
60 while (CurrentOffset < IniFileSize)
61 {
62 // First check the line size and increase our buffer if necessary
63 if (IniFileLineSize < IniGetNextLineSize(IniFileData, IniFileSize, CurrentOffset))
64 {
65 IniFileLineSize = IniGetNextLineSize(IniFileData, IniFileSize, CurrentOffset);
66 FrLdrTempFree(IniFileLine, TAG_INI_FILE);
67 IniFileLine = FrLdrTempAlloc(IniFileLineSize, TAG_INI_FILE);
68 if (!IniFileLine)
69 {
70 return FALSE;
71 }
72 }
73
74 // Get the line of data
75 CurrentOffset = IniGetNextLine(IniFileData, IniFileSize, IniFileLine, IniFileLineSize, CurrentOffset);
76 LineLength = (ULONG)strlen(IniFileLine);
77
78 // If it is a blank line or a comment then skip it
79 if (IniIsLineEmpty(IniFileLine, LineLength) || IniIsCommentLine(IniFileLine, LineLength))
80 {
81 CurrentLineNumber++;
82 continue;
83 }
84
85 // Check if it is a new section
86 if (IniIsSectionName(IniFileLine, LineLength))
87 {
88 // Allocate a new section structure
89 CurrentSection = FrLdrTempAlloc(sizeof(INI_SECTION), TAG_INI_SECTION);
90 if (!CurrentSection)
91 {
92 FrLdrTempFree(IniFileLine, TAG_INI_FILE);
93 return FALSE;
94 }
95
96 RtlZeroMemory(CurrentSection, sizeof(INI_SECTION));
97
98 // Allocate the section name buffer
99 CurrentSection->SectionName = FrLdrTempAlloc(IniGetSectionNameSize(IniFileLine, LineLength), TAG_INI_NAME);
100 if (!CurrentSection->SectionName)
101 {
102 FrLdrTempFree(CurrentSection, TAG_INI_FILE);
103 FrLdrTempFree(IniFileLine, TAG_INI_FILE);
104 return FALSE;
105 }
106
107 // Get the section name
108 IniExtractSectionName(CurrentSection->SectionName, IniFileLine, LineLength);
109 InitializeListHead(&CurrentSection->SectionItemList);
110
111 // Add it to the section list head
114
115 CurrentLineNumber++;
116 continue;
117 }
118
119 // Check if it is a setting
120 if (IniIsSetting(IniFileLine, LineLength))
121 {
122 // First check to make sure we're inside a [section]
123 if (CurrentSection == NULL)
124 {
125 ERR("Error: freeldr.ini:%lu: Setting '%s' found outside of a [section].\n", CurrentLineNumber, IniFileLine);
126
127 // Skip it
128 CurrentLineNumber++;
129 continue;
130 }
131
132 // Allocate a new item structure
134 if (!CurrentItem)
135 {
136 FrLdrTempFree(IniFileLine, TAG_INI_FILE);
137 return FALSE;
138 }
139
140 RtlZeroMemory(CurrentItem, sizeof(INI_SECTION_ITEM));
141
142 // Allocate the setting name buffer
143 CurrentItem->ItemName = FrLdrTempAlloc(IniGetSettingNameSize(IniFileLine, LineLength), TAG_INI_NAME);
144 if (!CurrentItem->ItemName)
145 {
147 FrLdrTempFree(IniFileLine, TAG_INI_FILE);
148 return FALSE;
149 }
150
151 // Allocate the setting value buffer
152 CurrentItem->ItemValue = FrLdrTempAlloc(IniGetSettingValueSize(IniFileLine, LineLength), TAG_INI_VALUE);
153 if (!CurrentItem->ItemValue)
154 {
155 FrLdrTempFree(CurrentItem->ItemName, TAG_INI_NAME);
157 FrLdrTempFree(IniFileLine, TAG_INI_FILE);
158 return FALSE;
159 }
160
161 // Get the section name
162 IniExtractSettingName(CurrentItem->ItemName, IniFileLine, LineLength);
163 IniExtractSettingValue(CurrentItem->ItemValue, IniFileLine, LineLength);
164
165 // Add it to the current section
167 CurrentSection->SectionItemCount++;
168 InsertTailList(&CurrentSection->SectionItemList, &CurrentItem->ListEntry);
169
170 CurrentLineNumber++;
171 continue;
172 }
173
174 CurrentLineNumber++;
175 }
176
177 FrLdrTempFree(IniFileLine, TAG_INI_FILE);
178
179 TRACE("Parsed %d sections and %d settings.\n", IniFileSectionCount, IniFileSettingCount);
180 TRACE("IniParseFile() done.\n");
181
182 return TRUE;
183}
ULONG IniGetSettingNameSize(PCHAR SettingNameLine, ULONG LineLength)
Definition: parse.c:416
VOID IniExtractSettingValue(PCHAR SettingValue, PCHAR SettingValueLine, ULONG LineLength)
Definition: parse.c:544
ULONG IniFileSectionCount
Definition: parse.c:27
BOOLEAN IniIsSetting(PCHAR LineOfText, ULONG TextLength)
Definition: parse.c:400
VOID IniExtractSettingName(PCHAR SettingName, PCHAR SettingNameLine, ULONG LineLength)
Definition: parse.c:507
ULONG IniGetSectionNameSize(PCHAR SectionNameLine, ULONG LineLength)
Definition: parse.c:319
BOOLEAN IniIsLineEmpty(PCHAR LineOfText, ULONG TextLength)
Definition: parse.c:244
ULONG IniGetNextLineSize(PCHAR IniFileData, ULONG IniFileSize, ULONG CurrentOffset)
Definition: parse.c:185
ULONG IniFileSettingCount
Definition: parse.c:28
LIST_ENTRY IniFileSectionListHead
Definition: parse.c:25
ULONG IniGetSettingValueSize(PCHAR SettingValueLine, ULONG LineLength)
Definition: parse.c:454
BOOLEAN IniIsSectionName(PCHAR LineOfText, ULONG TextLength)
Definition: parse.c:293
VOID IniExtractSectionName(PCHAR SectionName, PCHAR SectionNameLine, ULONG LineLength)
Definition: parse.c:360
ULONG IniGetNextLine(PCHAR IniFileData, ULONG IniFileSize, PCHAR Buffer, ULONG BufferSize, ULONG CurrentOffset)
Definition: parse.c:210
BOOLEAN IniIsCommentLine(PCHAR LineOfText, ULONG TextLength)
Definition: parse.c:267
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 149 of file inifile.c.

150{
151 PINI_SECTION Section = (PINI_SECTION)SectionId;
153 PINI_SECTION_ITEM SectionItem;
154
155 TRACE("IniReadSettingByName() SectionId = 0x%x\n", SectionId);
156
157 // Loop through each section item and find the one we want
158 for (Entry = Section->SectionItemList.Flink;
159 Entry != &Section->SectionItemList;
160 Entry = Entry->Flink)
161 {
162 SectionItem = CONTAINING_RECORD(Entry, INI_SECTION_ITEM, ListEntry);
163
164 // Check to see if this is the setting we want
165 if (_stricmp(SettingName, SectionItem->ItemName) == 0)
166 {
167 TRACE("IniReadSettingByName() Setting \'%s\' found.\n", SettingName);
168 TRACE("IniReadSettingByName() Setting value = %s\n", SectionItem->ItemValue);
169
170 strncpy(Buffer, SectionItem->ItemValue, BufferSize - 1);
171 Buffer[BufferSize - 1] = '\0';
172
173 return TRUE;
174 }
175 }
176
177 WARN("IniReadSettingByName() Setting \'%s\' not found.\n", SettingName);
178
179 return FALSE;
180}
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
#define WARN(fmt,...)
Definition: debug.h:112

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

◆ IniReadSettingByNumber()

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

Definition at line 116 of file inifile.c.

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

Definition at line 25 of file parse.c.

Referenced by IniAddSection(), IniCleanup(), IniOpenSection(), and IniParseFile().

◆ IniFileSettingCount

ULONG IniFileSettingCount
extern

Definition at line 28 of file parse.c.

Referenced by IniParseFile().