started working on ini parser

This commit is contained in:
2025-08-20 01:27:25 +03:00
parent 5635cd1d69
commit eff681ca33
47 changed files with 1465 additions and 112 deletions

35
tests/ini/build.cpp Normal file
View File

@@ -0,0 +1,35 @@
#include "c.h"
#include "target.h"
#include "helper.h"
DECLARE_BUILD_STAGE(ini_test)
{
CProject_t p = {
.files = {
"../../tier0/lib.cpp",
"../../tier0/mem.cpp",
"../../tier0/platform.cpp",
"../../tier1/interface.cpp",
"../../tier1/utlbuffer.cpp",
"../../tier1/utlstring.cpp",
"../../tier1/utlvector.cpp",
"../../tier1/utlmap.cpp",
"../../tier1/commandline.cpp",
"../../tier2/fileformats/ini.cpp",
"../../tier2/filesystem.cpp",
"../../tier2/filesystem_libc.cpp",
"main.cpp",
},
.includeDirectories =
{
"../../public"
},
};
p.m_szName = "initest";
LinkProject_t l = ccompiler->Compile(&p);
CUtlString szPath = linker->Link(&l);
filesystem2->CopyFile("./", szPath);
return 0;
}

BIN
tests/ini/initest Normal file

Binary file not shown.

49
tests/ini/main.cpp Normal file
View File

@@ -0,0 +1,49 @@
#include "tier0/lib.h"
#include "tier0/mem.h"
#include "tier1/utlbuffer.h"
#include "tier1/commandline.h"
#include "tier2/fileformats/ini.h"
#include "tier2/ifilesystem.h"
int main( int argc, char **argv )
{
const char *szFileName;
IFileHandle *pHandle = NULL;
size_t nSize = 0;
CUtlBuffer<char> szData;
CommandLine()->CreateCommandLine(argc, argv);
filesystem->Init();
// Get file
szFileName = CommandLine()->ParamValue("-f");
if (!szFileName)
return 0;
// Load it
pHandle = filesystem->Open(szFileName, FILEMODE_READ);
if (!pHandle)
return 0;
// Get size
pHandle->Seek(SEEKMODE_RELATIVE_END, 0);
nSize = pHandle->Tell();
pHandle->Seek(SEEKMODE_RELATIVE_START, 0);
// Read it
szData = CUtlBuffer<char>(nSize+1);
pHandle->Read(szData, nSize);
pHandle->Close();
szData[nSize] = 0;
IINIFile *pIniFile = INIManager()->ReadString(szData);
if (!pIniFile)
return 0;
IINISection *pTestValues = pIniFile->GetSection("Test_Values");
if (!pTestValues)
return 0;
V_printf("%s\n",pTestValues->GetStringValue("abc3d"));
};

12
tests/ini/test1.ini Normal file
View File

@@ -0,0 +1,12 @@
[Test_Values]
a = "Hello world!\n"
b = true
c = false
c = 3.1415926
d = 123456
e = -2.71828
f = -890
g = .34
abc3d = "Hello world from the funny engine, you can use \" to add quotes"

1
tests/ini/test2.ini Normal file
View File

@@ -0,0 +1 @@
[

1
tests/ini/test3.ini Normal file
View File

@@ -0,0 +1 @@
[Hello

1
tests/ini/test4.ini Normal file
View File

@@ -0,0 +1 @@
[Test Hello]

2
tests/ini/test5.ini Normal file
View File

@@ -0,0 +1,2 @@
["Hello world"]
Test

2
tests/ini/test6.ini Normal file
View File

@@ -0,0 +1,2 @@
[Test]
a b

2
tests/ini/test7.ini Normal file
View File

@@ -0,0 +1,2 @@
[Test]
a =

5
tests/ini/test8.ini Normal file
View File

@@ -0,0 +1,5 @@
[Test]
a = b
c = d
d = test