#ifndef LIBRARIES_INI_H
#define LIBRARIES_INI_H

#ifndef EXEC_NODES_H
#include "exec/nodes.h"
#endif /* EXEC_NODES_H */

#ifndef EXEC_LISTS_H
#include "exec/lists.h"
#endif /* EXEC_LISTS_H */

#ifndef EXEC_LIBRARIES_H
#include "exec/libraries.h"
#endif /* EXEC_LIBRARIES_H */

#define INIERROR_NONE			0
#define INIERROR_NOT_ENOUGH_MEMORY	1
#define INIERROR_CANNOT_OPEN_FILE	2
#define INIERROR_CANNOT_EXAMINE_FILE	3
#define INIERROR_CANNOT_READ_FILE	4
#define INIERROR_CANNOT_WRITE_FILE	5
#define INIERROR_INVALID_PARSER		6
#define INIERROR_HEADER_NOT_FOUND	7
#define INIERROR_VARIABLE_NOT_FOUND	8
#define INIERROR_INVALID_ARGS		9
#define INIERROR_TEMPLATE_FAILED	10
#define INIERROR_INVALID_INI_FILE	11
#define INIERROR_INITFAILED		12
#define INIERROR_NO_TEMPLATE_INPUT	13
#define INIERROR_INVALID_PASSWORD	14

#define INIFLAG_UNKNOWN			0
#define INIFLAG_VARIABLE		1
#define INIFLAG_HEADER			2
#define INIFLAG_COMMENT			4

typedef struct IniLineInfo
	{
		struct Node node;		/* for internal linkage */
		UBYTE	flags;			/* one of the above flags */
		UBYTE	reserved;		/* INTERNAL USE, currently ZERO	*/
		STRPTR	variable;		/* ptr to variable or NULL (if not variable) */
		STRPTR	contents;		/* ptr to contents or NULL (if no contents) */
		STRPTR	allocated;		/* ptr to allocated memory */
		LONG	size;			/* size of allocated memory */
	} INILINEINFO;

typedef struct IniParser
	{
		struct List table;		/* INILINEINFO anchor */
		LONG flags;
		UBYTE	Private[12];
	} INIPARSER;

/* the lowest 4 bits tell you about the "real" location of your
   inifile (which may be anywhere, since the ini.library does
   the path dispatching for you) */

#define INIPARSER_UNKNOWN	0	/* uses fixed path (or current directory) */
#define INIPARSER_S		(1<<0)	/* uses S: */
#define INIPARSER_INI		(1<<1)	/* uses INI: */
#define INIPARSER_ENV		(1<<2)	/* uses ENV: */
#define INIPARSER_USER		(1<<3)	/* uses USER: */

/* if this bit is set, the extensions to the ini-standard are DISABLED
   (which you shouldn't normally insist on) */
#define INIPARSERB_NOEXTENSIONS	31
#define INIPARSERF_NOEXTENSIONS	(1<<31)

/* Note well : LN_NAME does NOT point to a valid name but to 
   a "struct Task" (or rather "struct Process") if the config is
   local (this is how the ini.library knows which local node to use)
   if the config is global, LN_NAME will probably always be NULL */

typedef struct IniLibConfig
	{
		struct Node node;
		LONG Flags;		
		STRPTR UserAssign;
/* this structure may well grow in the future; use ini_NewConfig()/
   ini_DeleteConfig() if you want to create one yourself */
	} INICONFIG;

/* Flagbits same as above for parser */
#define INICONFIGB_NOINIMASK 8
#define INICONFIGF_NOINIMASK (1<<8)

#define INI_Dummy 		(TAG_USER+100)
#define ICFG_ENABLE_S		(INI_Dummy+1)
#define ICFG_ENABLE_INI		(INI_Dummy+2)
#define ICFG_ENABLE_ENV		(INI_Dummy+3)
#define ICFG_ENABLE_USER	(INI_Dummy+4)
#define ICFG_INIMASK		(INI_Dummy+5)
#define ICFG_ASSIGN		(INI_Dummy+6)

typedef struct IniBase
	{
		struct Library Base;
		ULONG	SegList;
		APTR	SysBase;
		APTR	DosBase;
		INICONFIG *GlobalConfig;
		struct List LocalConfig;
		LONG Flags;
	} INIBASE;

typedef long INIERROR;

#endif /* LIBRARIES_INI_H */
