INI file format:
; Comment
[Node name]
Key = Value
...
// Read the value of a specific item in the INI File
Char * getinitkey (char * pfilename, char * playback ction, char * pkey)
{
Static char retstr [1024];
Int nflag = 0;
Char tmpline [1024];
File * pfile;
Pfile = fopen (pfilename, "R ");
If (pfile = NULL)
{
Return NULL;
}
While (1)
{
// Whether the end of the file is
If (fgets (tmpline, 1024, pfile) = NULL)
{
Break;
}
// Ignore the comment line
If (tmpline [0] = ';')
{
Continue;
}
// Whether the node name is found
If (nflag = 0)
{
// Whether the column is a node name
If (tmpline [0] = '[')
{
Int ntitlelen = strlen (Limit ction );
// Check whether the node name length is the same as the name of the queried node, and whether the node name is the same
If (tmpline [ntitlelen + 1] = ']' & strncmp (ction, tmpline + 1, ntitlelen) = 0)
{
Nflag = 1;
}
}
}
Else
{
// Whether it is a key-value column
// Const char * ptemp = strchr (tmpline, '= ');
// If (ptemp! = NULL)
Int nkeylen = strlen (pkey );
If (tmpline [nkeylen] = ')
{
// Ptemp-tmpline = nkeylen &&
If (strncmp (pkey, tmpline, nkeylen) = 0)
{
Strcpy (retstr, tmpline + 1 + nkeylen );
// Remove the last line break
Retstr [strlen (retstr)-1] = 0;
Fclose (pfile );
Return retstr;
}
}
// New node name, jump out
Else if (tmpline [0] = '[')
{
Break;
}
}
}
Fclose (pfile );
Return NULL;
}