/****************************************************************
   This file was created automatically by `FlexCat 2.3'
   from "amster.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 "amster_Cat.h"


/*
    Variables
*/
struct FC_String amster_Strings[116] = {
    { (STRPTR) "Cannot open %s V%d!\n", 0 },
    { (STRPTR) "Cannot create mui app!\n", 1 },
    { (STRPTR) "TCP/IP stack needed!", 2 },
    { (STRPTR) "Napster client", 3 },
    { (STRPTR) "Amster", 4 },
    { (STRPTR) "?\000About...", 5 },
    { (STRPTR) "About MUI...", 6 },
    { (STRPTR) "H\000Hide", 7 },
    { (STRPTR) "Q\000Quit", 8 },
    { (STRPTR) "Settings", 9 },
    { (STRPTR) "Configuration...", 10 },
    { (STRPTR) "MUI...", 11 },
    { (STRPTR) "About Amster", 12 },
    { (STRPTR) "\033c\033bAmster %s (%s)\033n\n\n"\
	"\033cCopyright © 1999-2000 by Gürer Özen.\n"\
	"\033cReleased under GNU Public License.\n"\
	"\n"\
	"Programming by Gürer Özen & Jacob Laursen.\n"\
	"Documentation by Jacob Laursen.\n", 13 },
    { (STRPTR) "_OK", 14 },
    { (STRPTR) "_Connect", 15 },
    { (STRPTR) "_Disconnect", 16 },
    { (STRPTR) "_Reconnect", 17 },
    { (STRPTR) "_Settings...", 18 },
    { (STRPTR) "Song", 19 },
    { (STRPTR) "Max.", 20 },
    { (STRPTR) "Search", 21 },
    { (STRPTR) "\033c\033b-- Advanced Search Options --", 22 },
    { (STRPTR) "Use", 23 },
    { (STRPTR) "Reset", 24 },
    { (STRPTR) "Line speed must be", 25 },
    { (STRPTR) "Bitrate must be", 26 },
    { (STRPTR) "Frequency must be", 27 },
    { (STRPTR) "Unknown", 28 },
    { (STRPTR) "14.4 Modem", 29 },
    { (STRPTR) "28.8 Modem", 30 },
    { (STRPTR) "33.6 Modem", 31 },
    { (STRPTR) "56K Modem", 32 },
    { (STRPTR) "ISDN 64K", 33 },
    { (STRPTR) "ISDN 128K", 34 },
    { (STRPTR) "Cable", 35 },
    { (STRPTR) "DSL", 36 },
    { (STRPTR) "T1", 37 },
    { (STRPTR) "T3+", 38 },
    { (STRPTR) "User", 39 },
    { (STRPTR) "List all MP3 files shared by a single user", 40 },
    { (STRPTR) "Browse", 41 },
    { (STRPTR) "Result:", 42 },
    { (STRPTR) "Not important", 43 },
    { (STRPTR) "At least", 44 },
    { (STRPTR) "Equal to", 45 },
    { (STRPTR) "At best", 46 },
    { (STRPTR) "\033cSong", 47 },
    { (STRPTR) "\033cSize", 48 },
    { (STRPTR) "\033cUser", 49 },
    { (STRPTR) "\033cLink", 50 },
    { (STRPTR) "Cl_ear", 51 },
    { (STRPTR) "Clear _all", 52 },
    { (STRPTR) "Do_wnload", 53 },
    { (STRPTR) "Searching...", 54 },
    { (STRPTR) "No files found.", 55 },
    { (STRPTR) "%d files found.", 56 },
    { (STRPTR) "Requesting list from user...", 57 },
    { (STRPTR) "Not connected to a server.", 58 },
    { (STRPTR) "Connecting...", 59 },
    { (STRPTR) "Connecting to %s...", 60 },
    { (STRPTR) "Connection to %s failed.", 61 },
    { (STRPTR) "Finding optimal server...", 62 },
    { (STRPTR) "Failed to find optimal server.", 63 },
    { (STRPTR) "%d songs in %d libraries (%d GB)", 64 },
    { (STRPTR) "Amster settings...", 65 },
    { (STRPTR) "Error", 66 },
    { (STRPTR) "You must be connected to change your e-mail address.", 67 },
    { (STRPTR) "User", 68 },
    { (STRPTR) "Options", 69 },
    { (STRPTR) "Advanced", 70 },
    { (STRPTR) "Username", 71 },
    { (STRPTR) "Password", 72 },
    { (STRPTR) "E-Mail", 73 },
    { (STRPTR) "U_pdate", 74 },
    { (STRPTR) "Connection", 75 },
    { (STRPTR) "Download path", 76 },
    { (STRPTR) "Select your download directory...", 77 },
    { (STRPTR) "Clear list before new searches", 78 },
    { (STRPTR) "Auto-connect on program startup", 79 },
    { (STRPTR) "Show full paths in result list", 80 },
    { (STRPTR) "Main server", 81 },
    { (STRPTR) "Amster gets MP3 server address from this server. You don't need to change it.", 82 },
    { (STRPTR) "MP3 server", 83 },
    { (STRPTR) "MP3 server address. If you want to get it from main server, leave this string empty.", 84 },
    { (STRPTR) "Version", 85 },
    { (STRPTR) "_Save", 86 },
    { (STRPTR) "_Use", 87 },
    { (STRPTR) "_Cancel", 88 },
    { (STRPTR) "Cannot save configuration!", 89 },
    { (STRPTR) "Amster information/debug...", 90 },
    { (STRPTR) "_Clear", 91 },
    { (STRPTR) "Connected.", 92 },
    { (STRPTR) "Login failed!", 93 },
    { (STRPTR) "Logged in.", 94 },
    { (STRPTR) "Server returned e-mail address '%s'.", 95 },
    { (STRPTR) "Server is busy. Try again later.", 96 },
    { (STRPTR) "Got '%s' from Napster.", 97 },
    { (STRPTR) "Port number needed (hostname:port)!", 98 },
    { (STRPTR) "Amster download...", 99 },
    { (STRPTR) "User aborted connection!", 100 },
    { (STRPTR) "Looking for host...", 101 },
    { (STRPTR) "_Abort", 102 },
    { (STRPTR) "\033uTitle\033n:\n"\
	"%s\n"\
	"\033uUser\033n: %s, \033uLink\033n: %s\n"\
	"\033uSize\033n: %ld bytes.\n"\
	"\033uBitrate\033n: %d kbps, \033uFrequency\033n: %d kHz\n", 103 },
    { (STRPTR) "Connecting...", 104 },
    { (STRPTR) "Connection lost.", 105 },
    { (STRPTR) "Requesting file...", 106 },
    { (STRPTR) "Downloading mp3...", 107 },
    { (STRPTR) "Cannot open file!", 108 },
    { (STRPTR) "Download finished", 109 },
    { (STRPTR) "Amster messenger...", 110 },
    { (STRPTR) "Network error.", 111 },
    { (STRPTR) "recv() error!", 112 },
    { (STRPTR) "Hostname lookup failed!", 113 },
    { (STRPTR) "Socket() error!", 114 },
    { (STRPTR) "Cannot connect!", 115 }
};

STATIC struct Catalog *amsterCatalog = NULL;
#ifdef LOCALIZE_V20
STATIC STRPTR amsterStrings = NULL;
STATIC ULONG amsterStringsSize;
#endif


#if defined(_DCC)
STATIC __autoexit VOID _STDCloseamsterCatalog(VOID)
#elif defined(__SASC)
VOID _STDCloseamsterCatalog(VOID)
#elif defined(__GNUC__)
STATIC VOID _STDCloseamsterCatalog(VOID)
#else
VOID CloseamsterCatalog(VOID)
#endif

{
    if (amsterCatalog) {
	CloseCatalog(amsterCatalog);
    }
#ifdef LOCALIZE_V20
    if (amsterStrings) {
	FreeMem(amsterStrings, amsterStringsSize);
    }
#endif
}


#if defined(_DCC)
STATIC __autoinit VOID _STIOpenamsterCatalog(VOID)
#elif defined(__SASC)
VOID _STIOpenamsterCatalog(VOID)
#elif defined(__GNUC__)
VOID _STIOpenamsterCatalog(VOID)
#else
VOID OpenamsterCatalog(VOID)
#endif

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

	    for (i = 0, fc = amster_Strings;  i < 116;  i++, fc++) {
		 fc->msg = GetCatalogStr(amsterCatalog, fc->id, (STRPTR) fc->msg);
	    }
	}
    }
}

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



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

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

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

			    if (!bytesRemaining  &&
				(amsterStrings = AllocMem(amsterStringsSize, MEMF_ANY))) {
				STRPTR sptr;

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

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

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