/************************************************
***   Simple example program for INI library  ***
***          © 2001 by Basty/Seasons          ***
***   This program demonstrates the powerful  ***
***     save functions of the INI library     ***
***               C/C++ version               ***
***  StormC 3.0 DSK was used for development  ***
************************************************/

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

#include <exec/types.h>
#include <exec/libraries.h>
#include <libraries/ini_lib.h>
#include <proto/exec.h>
#include <proto/ini.h>

#include "INI_Example.h"

struct iniLibBase *INIBase;
struct iniFile *DefINIFile;

WORD NewColorTable[16] =
{
  0xFFF, 0x000, 0x777, 0xCCC,
  0x444, 0x555, 0x666, 0x888,
  0x111, 0x222, 0xAAA, 0x333,
  0x999, 0xDDD, 0xBBB, 0xEEE
};

void main()
{
  /* Set FAIL error mark */

  int rc = 20;
  ULONG len;

  /* Load v33.00 of ini.library */

  if (!( INIBase = (struct iniLibBase *) OpenLibrary("ini.library",33L)))
    exit ( rc );

  /* Open :Example.INI INI file/create it */

  if (!(DefINIFile = iniOpenDefault( DefaultINI, ":Example.INI", sizeof(DefaultINI))))
    goto CloseINI;


  /* Now we want to change the ViewMode in [Screen1]
     and write the value 0 in the form 0x0000 */

  iniWriteLong ( DefINIFile, "Screen1", "ViewMode", 0x0L, 0L, INI_FORMAT_HEX_0X, 4L, '0' );

  /* Now we change the width of the screen to 320
     so we have a lores screen. We want standard
     decimal output without zero preceding. */

  iniWriteLong ( DefINIFile, "Screen1", "Width", 320L, 0L, INI_FORMAT_DEC, 0L, 0L );

  iniWriteLong ( DefINIFile, "Window1", "Width", 320L, 0L, INI_FORMAT_DEC, 0L, 0L );
  iniWriteLong ( DefINIFile, "Window2", "Width", 320L, 0L, INI_FORMAT_DEC, 0L, 0L );
  iniWriteLong ( DefINIFile, "Window3", "Width", 320L, 0L, INI_FORMAT_DEC, 0L, 0L );
  iniWriteLong ( DefINIFile, "Window4", "Width", 320L, 0L, INI_FORMAT_DEC, 0L, 0L );

  iniWriteLong ( DefINIFile, "Window1", "MaxWidth", 320L, 0L, INI_FORMAT_DEC, 0L, 0L );
  iniWriteLong ( DefINIFile, "Window2", "MaxWidth", 320L, 0L, INI_FORMAT_DEC, 0L, 0L );
  iniWriteLong ( DefINIFile, "Window3", "MaxWidth", 320L, 0L, INI_FORMAT_DEC, 0L, 0L );
  iniWriteLong ( DefINIFile, "Window4", "MaxWidth", 320L, 0L, INI_FORMAT_DEC, 0L, 0L );

  /* This time we want to change the screen title */

  iniWriteStr ( DefINIFile, "Screen1", "Title", "Example INI Test Screen Lo-Res © 2001 by Basty/Seasons", 0L );

  /* Now we want a new color table */

  iniWriteWordA ( DefINIFile, "Screen1", "ColorTable", NewColorTable, (sizeof (NewColorTable) / sizeof (WORD)), 0L, INI_FORMAT_HEX_0X, 3L, '0' );

  /* After we have changed all entries, we need
     to store the changed data to disk */

  len = iniSaveFile ( DefINIFile, ":Example.INI", MODE_NEWFILE );

CloseINI:

/* We want to close the INI file */

  iniClose ( DefINIFile );

  /* Close INI Library */

  CloseLibrary ( (struct Library *) INIBase );

  rc = 0;

  /* Exit to DOS */

  exit ( rc );
}
