/****************************************************************
   This file was created automatically by `FlexCat 2.1'
   from "dreamcdguide.cd".

   Do NOT edit by hand!
****************************************************************/

/****************************************************************
    This file uses the auto initialization possibilities of
    Dice, gcc and SAS/C, respectively.

    Dice does this by using the keywords __autoinit and
    __autoexit, SAS uses names beginning with _STI or
    _STD, respectively. gcc uses the asm() instruction,
    to emulate C++ constructors and destructors.

    Using this file you don't have *all* possibilities of
    the locale.library. (No Locale or Language arguments are
    supported when opening the catalog. However, these are
    *very* rarely used, so this should be sufficient for most
    applications.
****************************************************************/


/*
    Include files and compiler specific stuff
*/
#include <exec/memory.h>
#include <libraries/locale.h>
#include <libraries/iffparse.h>

#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/locale.h>
#include <proto/utility.h>
#include <proto/iffparse.h>

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



#include "dreamcat.h"


/*
    Variables
*/
struct FC_String dreamcdguide_Strings[59] = {
    { (STRPTR) "\000Drawer", 1 },
    { (STRPTR) "\000Parent...", 2 },
    { (STRPTR) "\000Change Dir", 3 },
    { (STRPTR) "\000Project", 4 },
    { (STRPTR) "?\000About...", 5 },
    { (STRPTR) "M\000About MUI", 6 },
    { (STRPTR) "Q\000Quit", 7 },
    { (STRPTR) "\000Settings", 8 },
    { (STRPTR) "\000MUI...", 9 },
    { (STRPTR) "\000Tools", 10 },
    { (STRPTR) "\000LHA Output", 11 },
    { (STRPTR) "\000Log File", 12 },
    { (STRPTR) "\000Search", 13 },
    { (STRPTR) "MUI Front-End for Aminet CDs", 14 },
    { (STRPTR) "Emilie, I love you !", 15 },
    { (STRPTR) "Drawer:", 16 },
    { (STRPTR) "Enter here the name\nof the dir to display...", 17 },
    { (STRPTR) "Please choose a directory...", 18 },
    { (STRPTR) "Directories", 19 },
    { (STRPTR) "Choose a directory\nto display its contents...", 20 },
    { (STRPTR) "Archives", 21 },
    { (STRPTR) "Archives in the current Dir...", 22 },
    { (STRPTR) "Options:", 23 },
    { (STRPTR) "_Parent", 24 },
    { (STRPTR) "_Info", 25 },
    { (STRPTR) "_Extract", 26 },
    { (STRPTR) "_Quit", 27 },
    { (STRPTR) "Quit DreamCDGuide...", 28 },
    { (STRPTR) "Description of the \nSelected File...", 29 },
    { (STRPTR) "Unable to create the application.", 30 },
    { (STRPTR) "DreamCDGuide has detected \n the insertion of the CD:", 31 },
    { (STRPTR) "Continue ?", 32 },
    { (STRPTR) "Continue !", 33 },
    { (STRPTR) "Quit...", 34 },
    { (STRPTR) "Ok !", 35 },
    { (STRPTR) "Go to Parent dir...", 36 },
    { (STRPTR) "Extracts the selected file...", 37 },
    { (STRPTR) "Shows contents of the selected archive", 38 },
    { (STRPTR) "Where to extract", 39 },
    { (STRPTR) "Extract", 40 },
    { (STRPTR) "To", 41 },
    { (STRPTR) "Couldn't lock", 42 },
    { (STRPTR) "MUI FrontEnd for Aminet CDs", 43 },
    { (STRPTR) "File Selected:", 44 },
    { (STRPTR) "No File Selected !", 45 },
    { (STRPTR) "DreamCDGuide haven't detected", 46 },
    { (STRPTR) "The insertion of any CD...", 47 },
    { (STRPTR) "Do you wish to wait ?", 48 },
    { (STRPTR) "Wait", 49 },
    { (STRPTR) "DreamCDGuide cannot be started Twice !", 50 },
    { (STRPTR) "No !", 51 },
    { (STRPTR) "\033c** No File Selected !**", 52 },
    { (STRPTR) "\033c**Description not Available !**", 53 },
    { (STRPTR) "Oh, Sh*** !", 54 },
    { (STRPTR) "Operation Aborded !", 55 },
    { (STRPTR) "Ok...", 56 },
    { (STRPTR) "\033cDiskchange...\nPress Ok then Change CD\n\n(DreamCDGuide will autodetect the diskchange...)", 57 },
    { (STRPTR) "Operation Canceled !", 58 },
    { (STRPTR) "\033c\033bShortCuts:\n----------\033n\n\033l\0333F1\0330-Extracts the Selected File\n\0333F2-\0330Display contents of the current Archive\n\0333F10\0330-Diskchange (Autolock)", 59 }
};

STATIC struct Catalog *dreamcdguideCatalog = NULL;
#ifdef LOCALIZE_V20
STATIC STRPTR dreamcdguideStrings = NULL;
STATIC ULONG dreamcdguideStringsSize;
#endif


#if defined(_DCC)
STATIC __autoexit VOID _STDClosedreamcdguideCatalog(VOID)
#elif defined(__SASC)
VOID _STDClosedreamcdguideCatalog(VOID)
#elif defined(__GNUC__)
STATIC VOID _STDClosedreamcdguideCatalog(VOID)
#else
VOID ClosedreamcdguideCatalog(VOID)
#endif

{
    if (dreamcdguideCatalog) {
    CloseCatalog(dreamcdguideCatalog);
    }
#ifdef LOCALIZE_V20
    if (dreamcdguideStrings) {
    FreeMem(dreamcdguideStrings, dreamcdguideStringsSize);
    }
#endif
}


#if defined(_DCC)
STATIC __autoinit VOID _STIOpendreamcdguideCatalog(VOID)
#elif defined(__SASC)
VOID _STIOpendreamcdguideCatalog(VOID)
#elif defined(__GNUC__)
VOID _STIOpendreamcdguideCatalog(VOID)
#else
VOID OpendreamcdguideCatalog(VOID)
#endif

{
    if (LocaleBase) {
    if ((dreamcdguideCatalog = OpenCatalog(NULL, (STRPTR) "dreamcdguide.catalog",
                     OC_BuiltInLanguage, "english",
                     OC_Version, 0,
                     TAG_DONE))) {
        struct FC_String *fc;
        int i;

        for (i = 0, fc = dreamcdguide_Strings;  i < 59;  i++, fc++) {
         fc->msg = GetCatalogStr(dreamcdguideCatalog, fc->id, (STRPTR) fc->msg);
        }
    }
    }
}

#if defined(__GNUC__)
__asm ("  .text;  .stabs \"___CTOR_LIST__\",22,0,0,__STIOpendreamcdguideCatalog");
__asm ("  .text;  .stabs \"___DTOR_LIST__\",22,0,0,__STDClosedreamcdguideCatalog");
#endif



#ifdef LOCALIZE_V20
VOID InitdreamcdguideCatalog(STRPTR language)

{
    struct IFFHandle *iffHandle;

    /*
    **  Use iffparse.library only, if we need to.
    */
    if (LocaleBase  ||  !IFFParseBase  ||  !language  ||
    Stricmp(language, "english") == 0) {
    return;
    }

    if ((iffHandle = AllocIFF())) {
    char path[128]; /* Enough to hold 4 path items (dos.library 3.1)    */
    strcpy(path, "PROGDIR:Catalogs");
    AddPart((STRPTR) path, language, sizeof(path));
    AddPart((STRPTR) path, "dreamcdguide.catalog", sizeof(path));
    if (!(iffHandle->iff_Stream = Open((STRPTR) path, MODE_OLDFILE))) {
        strcpy(path, "LOCALE:Catalogs");
        AddPart((STRPTR) path, language, sizeof(path));
        AddPart((STRPTR) path, language, sizeof(path));
        iffHandle->iff_Stream = Open((STRPTR) path, MODE_OLDFILE);
    }

    if (iffHandle->iff_Stream) {
        InitIFFasDOS(iffHandle);
        if (!OpenIFF(iffHandle, IFFF_READ)) {
        if (!PropChunk(iffHandle, MAKE_ID('C','T','L','G'),
                   MAKE_ID('S','T','R','S'))) {
            struct StoredProperty *sp;
            int error;

            for (;;) {
            if ((error = ParseIFF(iffHandle, IFFPARSE_STEP))
                   ==  IFFERR_EOC) {
                continue;
            }
            if (error) {
                break;
            }

            if ((sp = FindProp(iffHandle, MAKE_ID('C','T','L','G'),
                       MAKE_ID('S','T','R','S')))) {
                /*
                **  Check catalog and calculate the needed
                **  number of bytes.
                **  A catalog string consists of
                **      ID (LONG)
                **      Size (LONG)
                **      Bytes (long word padded)
                */
                LONG bytesRemaining;
                LONG *ptr;

                dreamcdguideStringsSize = 0;
                bytesRemaining = sp->sp_Size;
                ptr = (LONG *) sp->sp_Data;

                while (bytesRemaining > 0) {
                LONG skipSize, stringSize;

                ptr++;                  /*  Skip ID     */
                stringSize = *ptr++;
                skipSize = ((stringSize+3) >> 2);

                dreamcdguideStringsSize += stringSize+1;  /*  NUL */
                bytesRemaining -= 8 + (skipSize << 2);
                ptr += skipSize;
                }

                if (!bytesRemaining  &&
                (dreamcdguideStrings = AllocMem(dreamcdguideStringsSize, MEMF_ANY))) {
                STRPTR sptr;

                bytesRemaining = sp->sp_Size;
                ptr = (LONG *) sp->sp_Data;
                sptr = dreamcdguideStrings;

                while (bytesRemaining) {
                    LONG skipSize, stringSize, id;
                    struct FC_String *fc;
                    int i;

                    id = *ptr++;
                    stringSize = *ptr++;
                    skipSize = ((stringSize+3) >> 2);

                    CopyMem(ptr, sptr, stringSize);
                    bytesRemaining -= 8 + (skipSize << 2);
                    ptr += skipSize;

                    for (i = 0, fc = dreamcdguide_Strings;  i < 59;  i++, fc++) {
                    if (fc->id == id) {
                        fc->msg = sptr;
                    }
                    }

                    sptr += stringSize;
                    *sptr++ = '\0';
                }
                }
                break;
            }
            }
        }
        CloseIFF(iffHandle);
        }
        Close(iffHandle->iff_Stream);
    }
    FreeIFF(iffHandle);
    }
}
#endif
