#include <stdio.h>
#include <stdlib.h>

#include <clib/exec_protos.h>

#include "/libraries/ini.h"
#include "/clib/ini_protos.h"
#include "/pragmas/ini_pragmas.h"

struct IniBase *IniBase;

int main( void )
{
    /* open the ini.library */
    if( ( IniBase = (struct IniBase *)OpenLibrary( "ini.library", 0 ) ) != NULL )
    {
        INIPARSER parser; 
        INILINEINFO *info;
        INIERROR rc;

        /* parse in a new inifile */
        if( ( rc = ini_New( "test.ini", &parser ) ) == INIERROR_NONE )
        {
            /* now you can examine the parser. this *very* rudimentary example
               only shows all section/variable strings; you'll probably do more
               serious things with this structure */

            for( info = (INILINEINFO *)parser.table.lh_Head;
                 info->node.ln_Succ;
                 info = (INILINEINFO *)info->node.ln_Succ )
            {
                switch( info->flags )
                {
                case INIFLAG_VARIABLE:
                    printf( "VARIABLE=\"%s\", CONTENTS=\"%s\"\n", 
                        info->variable, info->contents );
                    break;
                case INIFLAG_HEADER:
                    printf( "HEADER=\"%s\"\n", info->contents );
                    break;
                case INIFLAG_COMMENT: /* SHOULD BE IGNORED */
                    printf( "COMMENT=\"%s\"\n", info->allocated );
                    break;
                default:
                    printf( "UNKNOWN ENTRY AT 0x%08lx, PLEASE REPORT\n", info );
                }
            }
            ini_Delete( &parser );
        }
        else printf( "INIERROR:%s\n", ini_ErrorString( rc ) );
        
        /* close library */
        CloseLibrary( (struct Library *)IniBase );
    }
    return 0;
}
