Skip to content

darnit_stringtable.h

Steven Arnow edited this page Jun 1, 2013 · 2 revisions

DARNIT_STRINGTABLE

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_SECTIONS

A list of sections in the stringtable.

typedef struct DARNIT_STRINGTABLE_SECTIONS {
	const char		**name;
	unsigned int		names;
} DARNIT_STRINGTABLE_SECTIONS;

d_stringtable_open

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.

d_stringtable_section_load

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.

d_stringtable_section_list

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.

d_stringtable_entry

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.

d_stringtable_section_unload

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.

d_stringtable_close

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.

Clone this wiki locally