/****************************************************************
   This file was created automatically by `FlexCat 2.5'
   from "Scout.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 "Scout_cat.h"


/*
    Variables
*/
struct FC_String Scout_Strings[158] = {
    { (STRPTR) "Can't open input.device!\n", 0 },
    { (STRPTR) "Can't open timer.device!\n", 1 },
    { (STRPTR) "No HOST specified!\n", 2 },
    { (STRPTR) "Please start a TCP/IP stack first (i.e. AmiTCP/Genesis or Miami(Dx))!\n", 3 },
    { (STRPTR) "Can't create application!\n", 4 },
    { (STRPTR) "Can't send script %s to port \"%s\"!\n", 5 },
    { (STRPTR) "***Break\n", 6 },
    { (STRPTR) "Can't initialize TCP/IP stack!\n", 100 },
    { (STRPTR) "Password:", 101 },
    { (STRPTR) "Can't get password!\n", 102 },
    { (STRPTR) "Can't connect to server!\n", 103 },
    { (STRPTR) "Can't create socket!\n", 104 },
    { (STRPTR) "Can't find host \"%s\"!\n", 105 },
    { (STRPTR) "Unknown option", 106 },
    { (STRPTR) "Wrong password!\n", 107 },
    { (STRPTR) "You don't have root privileges!\n", 108 },
    { (STRPTR) "Unknown user!\n", 109 },
    { (STRPTR) "No \"BEGIN\" received!\n", 110 },
    { (STRPTR) "Error occured!", 111 },
    { (STRPTR) "Continue", 112 },
    { (STRPTR) "_Continue", 200 },
    { (STRPTR) "\033c\n "\
	"%s\n "\
	"%s\n "\
	"\n "\
	"%s\n "\
	"All Rights Reserved\n "\
	"\n "\
	"This program is \033bFreeware\033n.\n "\
	"EMail: %s\n "\
	"\n "\
	"ARexx port name: %s\n", 201 },
    { (STRPTR) "_Update", 300 },
    { (STRPTR) "Pr_int", 301 },
    { (STRPTR) "_Remove", 302 },
    { (STRPTR) "_Priority", 303 },
    { (STRPTR) "_More", 304 },
    { (STRPTR) "_Close", 305 },
    { (STRPTR) "E_xit", 306 },
    { (STRPTR) "_Functions", 307 },
    { (STRPTR) "Yes|No", 308 },
    { (STRPTR) "Once|All|Cancel", 309 },
    { (STRPTR) "_Ok", 310 },
    { (STRPTR) "_Cancel", 311 },
    { (STRPTR) "<none>", 312 },
    { (STRPTR) "Do you really want to remove directory\n "\
	"\"%s\" from assign \"%s\"?", 400 },
    { (STRPTR) "Do you really want to assign \"%s\"?", 401 },
    { (STRPTR) "Do you really want to remove class\n "\
	"\"%s\"?", 500 },
    { (STRPTR) "Can't remove INTERNAL commands!", 600 },
    { (STRPTR) "Can't remove SYSTEM commands!", 601 },
    { (STRPTR) "Can't remove DISABLED commands!", 602 },
    { (STRPTR) "Do you really want to remove command\n "\
	"\"%s\"?", 603 },
    { (STRPTR) "_Appear", 700 },
    { (STRPTR) "_Disappear", 701 },
    { (STRPTR) "_Enable", 702 },
    { (STRPTR) "Di_sable", 703 },
    { (STRPTR) "_Kill", 704 },
    { (STRPTR) "List_Chg", 705 },
    { (STRPTR) "Uni_que", 706 },
    { (STRPTR) "Do you really want to remove commodity\n "\
	"\"%s\"?", 707 },
    { (STRPTR) "Do you really want to remove device\n "\
	"\"%s\"?", 800 },
    { (STRPTR) "Supported commands:", 801 },
    { (STRPTR) "[identify.library required]", 900 },
    { (STRPTR) "Do you really want to close font\n "\
	"\"%s\"?", 1000 },
    { (STRPTR) "Do you really want to remove font\n "\
	"\"%s\"?", 1001 },
    { (STRPTR) "Sorry, the count of accessors is already zero!", 1002 },
    { (STRPTR) "Sorry, the count of accessors is not zero!", 1003 },
    { (STRPTR) "<no .fd file>", 1100 },
    { (STRPTR) "<no jmp>", 1101 },
    { (STRPTR) "<no entry in .fd file>", 1102 },
    { (STRPTR) "Do you really want to remove inputhandler\n "\
	"\"%s\"?", 1200 },
    { (STRPTR) "Sorry, I can't remove an interrupt handler!", 1300 },
    { (STRPTR) "Do you really want to remove interrupt server\n "\
	"\"%s\"?", 1301 },
    { (STRPTR) "Do you really want to remove library\n "\
	"\"%s\"?", 1400 },
    { (STRPTR) "Do you really want to close library\n "\
	"\"%s\"?", 1401 },
    { (STRPTR) "Sorry, the open count is already zero!", 1402 },
    { (STRPTR) "Pattern:", 1500 },
    { (STRPTR) "%lD shown, %lD hidden", 1501 },
    { (STRPTR) "%lD shown, %lD hidden. Done.", 1502 },
    { (STRPTR) "Do you really want to remove lock\n "\
	"\"%s\"?", 1503 },
    { (STRPTR) "Yes|All|No|Abort", 1504 },
    { (STRPTR) "Do you really want to remove lowmemory handler\n "\
	"\"%s\"?", 1600 },
    { (STRPTR) "dummy", 1700 },
    { (STRPTR) "read only", 1800 },
    { (STRPTR) "validating", 1801 },
    { (STRPTR) "read/write", 1802 },
    { (STRPTR) "no disk", 1803 },
    { (STRPTR) "unreadable", 1804 },
    { (STRPTR) "Do you really want to remove port\n "\
	"\"%s\"?", 1900 },
    { (STRPTR) "Change priority", 2000 },
    { (STRPTR) "Min:", 2001 },
    { (STRPTR) "Max:", 2002 },
    { (STRPTR) "Old:", 2003 },
    { (STRPTR) "New:", 2004 },
    { (STRPTR) "\033c Please select a new priority for \n "\
	"\"%s\"", 2005 },
    { (STRPTR) "dummy", 2100 },
    { (STRPTR) "Do you really want to remove resource\n "\
	"\"%s\"?", 2200 },
    { (STRPTR) "MCOMPAT_MIXED: can share display with other MIXED", 2300 },
    { (STRPTR) "MCOMPAT_SELF: can share only within monitor", 2301 },
    { (STRPTR) "MCOMPAT_NOBODY: only one viewport", 2302 },
    { (STRPTR) "_Obtain", 2400 },
    { (STRPTR) "Re_lease", 2401 },
    { (STRPTR) "Do you really want to obtain semaphore\n "\
	"\"%s\"?", 2402 },
    { (STRPTR) "Do you really want to release semaphore\n "\
	"\"%s\"?", 2403 },
    { (STRPTR) "Sorry, the semaphore's nest count is already zero!", 2404 },
    { (STRPTR) "Do you really want to remove semaphore\n "\
	"\"%s\"?", 2405 },
    { (STRPTR) "Send signal", 2500 },
    { (STRPTR) "Signal:", 2501 },
    { (STRPTR) "SigWait:", 2502 },
    { (STRPTR) "\033c Please select the signal for \n "\
	"\"%s\"", 2503 },
    { (STRPTR) "dummy", 2600 },
    { (STRPTR) "_Freeze", 2700 },
    { (STRPTR) "_Activate", 2701 },
    { (STRPTR) "_Signal", 2702 },
    { (STRPTR) "_Break", 2703 },
    { (STRPTR) " Secs:", 2704 },
    { (STRPTR) "off", 2705 },
    { (STRPTR) "full", 2706 },
    { (STRPTR) "in %", 2707 },
    { (STRPTR) "Do you really want to remove %s\n "\
	"\"%s\"?", 2708 },
    { (STRPTR) "Also remove ports, window, etc allocated by task\n "\
	"\"%s\"?", 2709 },
    { (STRPTR) "Sorry, I can't find that task!", 2710 },
    { (STRPTR) "Can't install patch semaphore!", 2711 },
    { (STRPTR) "Found old patch semaphore (V%ld.%ld)!\n "\
	"I will replace this one by a new one (V%ld.%ld)!", 2712 },
    { (STRPTR) "<no task>", 2713 },
    { (STRPTR) "frozen", 2714 },
    { (STRPTR) "added", 2715 },
    { (STRPTR) "running", 2716 },
    { (STRPTR) "ready", 2717 },
    { (STRPTR) "waiting", 2718 },
    { (STRPTR) "except", 2719 },
    { (STRPTR) "removed", 2720 },
    { (STRPTR) "invalid", 2721 },
    { (STRPTR) "< ??? >", 2722 },
    { (STRPTR) "task", 2723 },
    { (STRPTR) "interrupt", 2724 },
    { (STRPTR) "device", 2725 },
    { (STRPTR) "msgport", 2726 },
    { (STRPTR) "message", 2727 },
    { (STRPTR) "freemsg", 2728 },
    { (STRPTR) "replymsg", 2729 },
    { (STRPTR) "resource", 2730 },
    { (STRPTR) "library", 2731 },
    { (STRPTR) "memory", 2732 },
    { (STRPTR) "softint", 2733 },
    { (STRPTR) "font", 2734 },
    { (STRPTR) "process", 2735 },
    { (STRPTR) "semaphore", 2736 },
    { (STRPTR) "signalsem", 2737 },
    { (STRPTR) "bootnode", 2738 },
    { (STRPTR) "kickmem", 2739 },
    { (STRPTR) "graphics", 2740 },
    { (STRPTR) "deathmessage", 2741 },
    { (STRPTR) "user", 2742 },
    { (STRPTR) "extended", 2743 },
    { (STRPTR) "unknown", 2744 },
    { (STRPTR) "< ??? >", 2745 },
    { (STRPTR) "dummy", 2800 },
    { (STRPTR) "dummy", 2900 },
    { (STRPTR) "To _Front", 3000 },
    { (STRPTR) "Do you really want to close screen\n "\
	"\"%s\"?", 3001 },
    { (STRPTR) "Do you really want to close window\n "\
	"\"%s\"?", 3002 },
    { (STRPTR) "SaferPatches is not installed", 3100 },
    { (STRPTR) "Disabling patches, even a complete patch list of\n "\
	"related patches is a potentially dangerous operation.\n "\
	"Are you sure you want to continue?", 3101 },
    { (STRPTR) "disabled", 3102 },
    { (STRPTR) "removed", 3103 },
    { (STRPTR) "active", 3104 },
    { (STRPTR) "Can't open %s version %ld!", 3200 }
};

STATIC struct Catalog *ScoutCatalog = NULL;
#ifdef LOCALIZE_V20
STATIC STRPTR ScoutStrings = NULL;
STATIC ULONG ScoutStringsSize;
#endif


VOID CloseScoutCatalog(VOID)

{
    if (ScoutCatalog) {
    CloseCatalog(ScoutCatalog);
    }
#ifdef LOCALIZE_V20
    if (ScoutStrings) {
    FreeMem(ScoutStrings, ScoutStringsSize);
    }
#endif
}


VOID OpenScoutCatalog(VOID)
{
    if (LocaleBase) {
    if ((ScoutCatalog = OpenCatalog(NULL, (STRPTR) "Scout.catalog",
                     OC_BuiltInLanguage, "english",
                     OC_Version, 1,
                     TAG_DONE))) {
        struct FC_String *fc;
        int i;

        for (i = 0, fc = Scout_Strings;  i < 158;  i++, fc++) {
         fc->msg = GetCatalogStr(ScoutCatalog, fc->id, (STRPTR) fc->msg);
        }
    }
    }
}

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



#ifdef LOCALIZE_V20
VOID InitScoutCatalog(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, "Scout.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;

                ScoutStringsSize = 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);

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

                if (!bytesRemaining  &&
                (ScoutStrings = AllocMem(ScoutStringsSize, MEMF_ANY))) {
                STRPTR sptr;

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

                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 = Scout_Strings;  i < 158;  i++, fc++) {
                    if (fc->id == id) {
                        fc->msg = sptr;
                    }
                    }

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