#ifndef TINI_HEADER
#define TINI_HEADER

struct tini;
typedef struct tini Tini;

typedef struct tini_setting {
	int id;
	char *setting;
	char *dflt;
	int flags;
	char *section;
	char *description;	
	char *helptext;
} TiniSetting;

/* flags */
enum {
	TINI_NONE  = 0x0,
	TINI_MULTI = 0x1
};

Tini *tini_init(TiniSetting *table);
void tini_free(Tini **ini);

int tini_load(Tini *ini, char *file, char *err, int bfsz);
int tini_save(Tini *ini, char *file, char *err, int bfsz);

//expects full setting line
int tini_set(Tini *ini, char *line);

//accepts either full setting line, or line without setting name
int tini_set_id(Tini *ini, int id, char *line);

void tini_clear(Tini *ini);
void tini_rmv(Tini *ini, int id);

char *tini_get(Tini *ini, int id); //returns NULL if no value exists
int tini_true(Tini *ini, int id); //TRUE if value istrue()
int tini_get_i(Tini *ini, int id); //atoi on setting, 0 if no value exists
char *tini_get_bf(Tini *ini, int id, char *bf, int bfsz); //returns bf, never NULL

struct titr;
typedef struct titr Titr;

//iterator, see example below
Titr *tini_first(Tini *ini, int id);
Titr *tini_valid(Titr *itr);
Titr *tini_next(Titr *itr);
void tini_end(Titr **itr);

//accessors for iterator, see example below
char *tini_cur(Titr *itr);
int tini_cur_true(Titr *itr);
int tini_cur_i(Titr *itr);
char *tini_cur_bf(Titr *itr, char *bf, int bfsz);

char *tini_cur_p(Titr *itr, int part);
int tini_cur_p_true(Titr *itr, int part);
int tini_cur_p_i(Titr *itr, int part);
char *tini_cur_p_bf(Titr *itr, int part, char *bf, int bfsz);

void tini_cur_rmv(Titr *itr);

int tini_quote_value(char *value, int bfsz); //modifies value in place

/* EXAMPLE...

enum {I_TEST,I_TEST2};

TiniSetting[] table = {
	{I_TEST,"test","hello world",0,"","",""},
	{I_TEST2,"test2",NULL,TINI_MULTI,"","",""},
	{0,NULL,NULL,0,NULL,NULL,NULL}
};

void main() {	
	char err[BFSZ];
	Tini *ini;
	Titr *itr;
	int id;

	ini = tini_init(table);
	if (!tini_load("filename.ini",err,BFSZ))
		return 1;

	printf("%s\n",tini_get(ini,I_TEST));

    for(itr = tini_first(ini,I_TEST2); itr; itr = tini_next(ini,itr)) {
		printf("%s,%s\n",tini_cur_p(ini,itr,0),tini_cur_p(ini,itr,1));
	}

    tini_free(&ini);

	return 0;
}
*/
#endif
