Check for INI_GetEntryName, it should exist in YSI 4 as well.
|
bool:INI_GetEntryName(source[], dest[], &i)
{
new
j;
while (source[j] && source[j] <= ' ') j++;
i = j;
while (source[i] > ' ' && source[i] != '=') i++;
if (i == j) return false;
i -= j;
memcpy(dest, source, j, i * 4, MAX_INI_ENTRY_NAME);
dest[i] = '\0';
return true;
}
EntryNameExists(const file_name[], const entry_name[])
{
new File: f = fopen(file_name, io_read);
if (!f) return 0;
new line[MAX_INI_ENTRY_NAME], stringIdent[MAX_INI_ENTRY_NAME], pos, comment;
while (fread(f, line))
{
StripNL(line);
if (!line[0]) continue;
comment = chrfind(';', line);
if (comment != -1) line[comment] = '\0';
if (INI_GetEntryName(line, stringIdent, pos) && !strcmp(entry_name, stringIdent)) return fclose(f), 1;
}
return fclose(f), 0;
}
if (!EntryNameExists("some_file.ini", "some_entry")) print("\"some_entry\" does not exist in the INI file.");
new File: file = fopen("file.ini", io_read); if (!file) return 1; new str[128], bool: found; while (fread(file, str)) { if (strcmp(str, "entry =", false, LENGTH OF THE ENTRY + 2 (7 here) )) continue; found = true; } fclose(file); // Use the found variable to see if it exists or not.