/*  INIFILE.H	12-Apr-99 11:34:56 by Kevin D. Quitt

    Read and parse initialization files

16-May-00  7:22, [KDQ]\isiarm\users\dev\psosarm_pwe\apps\scanvue\inifile.h, Edit by KDQ
    Modifications for NetARM scanvue
*/

#ifndef	INIFILE__H
#define	INIFILE__H

#define	TEMPLINESIZE    (1024)		/* Size of utility line buffer	    */
#define	MAXSECTS	(100)		/* Sections in an INI file	    */
#define	WORKSPACESIZE	(65000)		/* Text storage for an INI file	    */


typedef struct
  {
    char   *Token;			/* Token string			    */
    char   *Value;			/* Value string			    */
  } TVPAIR;				/* Token/Value pair		    */

/*  The pointer to TVPairs here is the base of this section's TVPairs.
    The first section need not have a name.
*/
typedef struct
  {
    char       *Name;			/* Pointer to Section Name string   */
    TVPAIR     *TVPair;			/* The section's tokens & values    */
    int		TVCount;		/* How many TVPairs		    */
  } SECTION;				/* Ini file Section		    */


/*  To prevent malloc fractioning, a fixed buffer (Workspace) is statically
    allocated at startup and will contain the TVPairs and the strings.
    TVPairs are 'allocated' from the bottom of Workspace, strings are
    allocated from the top.  If the pointers are going to cross, we're done
    loading the ini file.
*/
typedef struct
  {
    int		SectionCount;		/* Active Section entries	    */
    SECTION	Section[ MAXSECTS ];

    int		TVCount;		/* Active TVPairs		    */
    TVPAIR     *TVPair;			/* Beginning of TVPair storage	    */

    TVPAIR     *NextTVPair;		/* Bottom of string storage
					    = &TVPair[ TVCount ]	    */
    char       *StringTop;		/* Top of string storage
					    = &Workspace[ WORKSPACESIZE ]   */
    char	Workspace[ WORKSPACESIZE ];
  } INIFILE;


extern	char iniFileName[];

/*  LoadIniFile	    Read the specified file and build IniFile structure.
    getTVPair	    Returns the index into the TVPair array of the first
		    pair with a matching token *after* the 'next' index.
    getINISecton    Returns a pointer to the named section.
    getINIValue	    Returns the value from specfied Section and Token,
		    with the search restricted by the list of IDs
*/
extern short	LoadIniFile( INIFILE *IFP, char *iniFile, size_t iniSize );
extern SECTION *getINISection( INIFILE *IFP, char *name );
extern char    *getINIValue( INIFILE *IFP, char *sectionName, char *token );

#endif
