/*
Auto:       cc <file>
Auto:       ln +q -m <file> -lc
*/

/* $Revision Header built by KCommodity by
   Kai Iske *** (do not edit) ************
**
** © Copyright by MAXON GMBH, Kickstart
**
** File             : GPrefs.c
** Created on       : Wednesday, 22-Jan-92 15:43
** Created by       : Kai Iske
** Current revision : V1.00
**
**
** Purpose
** -------
**     Merkt, falls eine Veränderung an den
**     Preferences-Files PALETTE/POINTER
**     in ENV: vorgenommen wurden und zeigt
**     dieses an.
**
** Revision V1.00
** --------------
**     --- Initial release ---
**
*********************************************/
#define REVISION "1.00"
#define REVDATE  "22-Jan-92"

#include    <clib/exec_protos.h>
#include    <clib/dos_protos.h>
#include    <clib/alib_protos.h>
#include    <clib/intuition_protos.h>
#include    <pragmas/exec_lib.h>
#include    <pragmas/dos_lib.h>
#include    <pragmas/intuition_lib.h>
#include    <stdlib.h>

#include    <exec/execbase.h>
#include    <dos/notify.h>
#include    <dos/dos.h>
#include    <intuition/intuition.h>


extern struct ExecBase *SysBase;
extern struct DOSBase *DOSBase;
struct IntuitionBase *IntuitionBase;

/**********************************************/
/*      Strukturen für die Notifications      */
/**********************************************/
struct NotifyRequest MyRequest[] =
{
    {
        /* Name des Files, daß überwacht
           werden soll */
        (UBYTE *)"ENV:SYS/PALETTE.ILBM",
        NULL,
        NULL,
        /* Es soll eine Nachricht gesendet
           werden, fall Veraenderungen vor-
           genommen wurden */
        NRF_SEND_MESSAGE,
    },
    {
        (UBYTE *)"ENV:SYS/POINTER.ILBM",
        NULL,
        NULL,
        NRF_SEND_MESSAGE,
    }
};


/**********************************************/
/*          Hier kommt das Ganze              */
/**********************************************/
void main(void)
{
    struct NotifyMessage *NotifyMsg;
    struct MsgPort *NotifyPort = NULL;
    struct EasyStruct EasyReq;
    LONG NotifySig, ThisSig;

    /* Kein Start unter OS1.x möglich */
    if(SysBase->LibNode.lib_Version <= 36)
          exit(10);

    /* Läuft GPrefs schon ? */
    if((NotifyPort = FindPort((UBYTE *)
                               "GPrefs")))
    {
         /* Dem "Anderen" sagen, daß jetzt
            Schluß ist */
         Signal(NotifyPort->mp_SigTask,
               SIGBREAKF_CTRL_C);

         puts("GPrefs V"REVISION" beendet");
         puts(REVDATE" von Kai Iske");
         puts("(C) 1992 MAXON, Kickstart\n");
         exit(0);
    }


    /* Library öffnen */
    if(!(IntuitionBase = (struct IntuitionBase *)
        OpenLibrary((UBYTE *)"intuition.library",
        0L)))
    {
        puts("Konnte Intuition-Library nicht
             öffnen.");
        exit(10);
    }

    /* Notify-Port, an den die Messages gehen
       einrichten */
    if(!(NotifyPort = CreatePort((UBYTE *)
                   "GPrefs", 0L)))
        goto CleanUp;

    /* Signal Maske berechnen */
    NotifySig = (1L << NotifyPort->mp_SigBit);

    /* Portadresse in die Strukturen
       eintragen */
    MyRequest[0].nr_stuff.nr_Msg.nr_Port =
            NotifyPort;
    MyRequest[1].nr_stuff.nr_Msg.nr_Port =
            NotifyPort;

    /* Requests starten */
    StartNotify(&MyRequest[0]);
    StartNotify(&MyRequest[1]);

    do
    {
        /* Warten auf ein Signal */
        ThisSig = Wait(NotifySig |
                    SIGBREAKF_CTRL_C);

        if(ThisSig & NotifySig)
        {
            /* Message besorgen */
            while((NotifyMsg =
                (struct NotifyMessage *)
                GetMsg(NotifyPort)))
            {

            /* Anzeigen, welches File geändert
               wurde */
            EasyReq.es_StructSize =
                sizeof(struct EasyStruct);
            EasyReq.es_Flags = 0;
            EasyReq.es_Title = (UBYTE *)
                "GPrefs Information";
            EasyReq.es_TextFormat = (UBYTE *)
                "Das file %s wurde verändert.";
            EasyReq.es_GadgetFormat = (UBYTE *)
                "Dachte ich mir schon";
            EasyRequest(NULL, &EasyReq, NULL,
                NotifyMsg->nm_NReq->nr_FullName);

                /* Message beantworten */
                ReplyMsg((struct Message *)
                     NotifyMsg);
            }
        }
    } while(!(ThisSig & SIGBREAKF_CTRL_C));


CleanUp:
    EndNotify(&MyRequest[0]);
    EndNotify(&MyRequest[1]);
    if(NotifyPort)
        DeletePort(NotifyPort);
    CloseLibrary((struct Library *)
        IntuitionBase);
    exit(0);
}
