-
Notifications
You must be signed in to change notification settings - Fork 3
darnit_stringtable.h
Various functions for using stringtables. Stringtables are in a special format. Stringtables are used to quickly look up loadable string data using string keys.
- DARNIT_STRINGTABLE *d_stringtable_open(const char *fname);
- int d_stringtable_section_load(DARNIT_STRINGTABLE *stringtable, const char *section);
- const DARNIT_STRINGTABLE_SECTIONS d_stringtable_section_list* (DARNIT_STRINGTABLE *stringtable);
- const char *d_stringtable_entry(DARNIT_STRINGTABLE *stringtable, const char *entry);
- int d_stringtable_section_unload(DARNIT_STRINGTABLE *stringtable, const char *section);
- DARNIT_STRINGTABLE *d_stringtable_close(DARNIT_STRINGTABLE *stringtable);
A list of sections in the stringtable.
typedef struct DARNIT_STRINGTABLE_SECTIONS {
const char **name;
unsigned int names;
} DARNIT_STRINGTABLE_SECTIONS;DARNIT_STRINGTABLE *d_stringtable_open(const char *fname); Opens a stringtable file, but does not load any sections.
Arguments
- fname - The filename of the stringtable to open
Return value
Returns NULL on failure, anything else is a valid DARNIT_STRINGTABLE.
int d_stringtable_section_load(DARNIT_STRINGTABLE *stringtable, const char *section);
Loads a stringtable and makes its entries available.
Arguments
- stringtable - The stringtable to load a section in
- section - The name of the section to load
Return value
Returns -1 on failure, 0 on success.
const DARNIT_STRINGTABLE_SECTIONS *d_stringtable_section_list(DARNIT_STRINGTABLE *stringtable);
Returns a list of the sections in the loaded stringtable. This list is allocated on stringtable load and must not be free'd manually, it is automatically free'd when the stringtable is unloaded.
Arguments
- stringtable - The stringtable to list entries in
Return value
Returns NULL if stringtable is NULL, otherwise, a valid stringtable list is returned.
const char *d_stringtable_entry(DARNIT_STRINGTABLE *stringtable, const char *entry);
Returns the string connected to the string key entry. This pointer is allocated statically in the stirngtable and must not be free'd, it is free'd automatically when its section is unloaded.
Arguments
- stringtable - The stringtable to get an entry from
- entry - The name of the entry to return
Return value
If a string connected to entry wasn't found, entry is returned. If entry is NULL, "(NULL)" is returned. If neither is true, the string connected to entry is returned.
int d_stringtable_section_unload(DARNIT_STRINGTABLE *stringtable, const char *section);
Unloads a stringtable section and free's up all entries in it.
Arguments
- stringtable - The stringtable to unload a section in
- section - The name of the section to unload
Return value
Returns -1 if the section can't be found in the stringtable, 0 if it was found and then unloaded.
DARNIT_STRINGTABLE *d_stringtable_close(DARNIT_STRINGTABLE *stringtable);
Unloads a stringtable and all the section that's loaded in it.
Arguments
- stringtable - The stringtable to unload
Return value
Returns NULL for compact pointer clearing.