home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 5
/
FreshFish_July-August1994.bin
/
bbs
/
dev
/
flexcat-1.2.lha
/
FlexCat
/
C_c_V20.sd
< prev
next >
Wrap
Text File
|
1994-03-11
|
6KB
|
222 lines
##stringtype C
##shortstrings
/****************************************************************
This file was created automatically by `FlexCat V1.1'
Do NOT edit by hand!
****************************************************************/
#ifndef %b_CAT_H
#include "%b_CAT.h"
#endif /* !%b_CAT_H */
#include <string.h>
#include <exec/memory.h>
#include <libraries/iffparse.h>
#include <clib/iffparse_protos.h>
#include <clib/locale_protos.h>
#include <clib/dos_protos.h>
#include <clib/exec_protos.h>
#include <clib/utility_protos.h>
#ifdef AZTEC_C
#include <pragmas/locale_lib.h>
#include <pragmas/iffparse_lib.h>
#include <pragmas/dos_lib.h>
#include <pragmas/exec_lib.h>
#include <pragmas/utility_lib.h>
#endif /* AZTEC_C */
#if defined(__SASC) || defined(_DCC) || defined(__MAXON__)
#include <pragmas/locale_pragmas.h>
#include <pragmas/iffparse_pragmas.h>
#include <pragmas/dos_pragmas.h>
#include <pragmas/exec_pragmas.h>
#include <pragmas/utility_pragmas.h>
#endif /* __SASC || _DCC || __MAXON__ */
#ifdef __GNUC__
#include <inline/locale.h>
#include <inline/iffparse.h>
#include <inline/dos.h>
#include <inline/exec.h>
#include <inline/utility.h>
#endif /* __GNUC__ */
static LONG %b_Version = %v;
static const STRPTR %b_BuiltInLanguage = (STRPTR) %l;
struct FC_Type
{ LONG ID;
STRPTR Str;
};
static const struct FC_Type %b_Array [] =
{
%i, (STRPTR) %s%,
};
static struct Catalog *%b_Catalog = NULL;
static struct FC_Type *%b_OwnCatalog = NULL;
static LONG %b_OwnStrings;
static LONG %b_OwnBytes;
void Open%bCatalog(struct Locale *loc, STRPTR language)
{ LONG tag, tagarg;
extern struct Library *LocaleBase;
extern struct Library *IFFParseBase;
Close%bCatalog(); /* Not needed if the programmer pairs Open-()
and CloseCatalog() right, but does no harm. */
if (language == NULL)
{ tag = TAG_IGNORE;
}
else
{ tag = OC_Language;
tagarg = (LONG) language;
}
if (LocaleBase != NULL && %b_Catalog == NULL)
{ %b_Catalog = OpenCatalog(loc, (STRPTR) "%b.catalog",
OC_BuiltInLanguage, %b_BuiltInLanguage,
tag, tagarg,
OC_Version, %b_Version,
TAG_DONE);
}
if (LocaleBase == NULL && IFFParseBase != NULL && language != NULL &&
Stricmp(language, %b_BuiltInLanguage) != 0)
{ struct IFFHandle *iffhandle;
char path[128]; /* Enough to hold 4 path items (dos.library 3.0) */
if ((iffhandle = AllocIFF()) != NULL)
{ /* Trying to open the catalog */
strcpy(path, "Catalogs");
AddPart((STRPTR) path, language, sizeof(path));
AddPart((STRPTR) path, (STRPTR) "%b.catalog", sizeof(path));
if ((iffhandle->iff_Stream = Open((STRPTR) path, MODE_OLDFILE))
== NULL)
{ strcpy(path, "Locale:Catalogs");
AddPart((STRPTR) path, language, sizeof(path));
AddPart((STRPTR) path, (STRPTR) "%b.catalog", 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 != 0)
{ break;
}
if (sp = FindProp(iffhandle, MAKE_ID('C','T','L','G'),
MAKE_ID('S','T','R','S')))
{ LONG *ptr;
LONG BytesToScan, StrLength;
/* First scan: Check the number of strings */
/* Note that this assumes that the strings are padded */
/* to a longword boundary! */
%b_OwnBytes = 0;
%b_OwnStrings = 0;
BytesToScan = sp->sp_Size;
ptr = sp->sp_Data;
while (BytesToScan > 0)
{ ++%b_OwnStrings;
++ptr; /* Skip ID */
StrLength = *ptr+1; /* NUL-Byte! */
%b_OwnBytes += StrLength;
ptr += 1+(StrLength+3)/4; /* Skip Length and String*/
BytesToScan -= 8+((StrLength+3)/4)*4;
}
/* Marginal check: BytesToScan has to be 0! */
if (BytesToScan == 0)
{ char *cptr;
LONG i;
if (%b_OwnCatalog = (struct FC_Type *)
AllocMem(%b_OwnStrings*sizeof(struct FC_Type)+%b_OwnBytes,
MEMF_ANY))
{ /* Second scan: Copy the strings and their ID's */
cptr = (char *) &%b_OwnCatalog[%b_OwnStrings];
BytesToScan = sp->sp_Size;
ptr = sp->sp_Data;
i = 0;
while (BytesToScan > 0)
{ %b_OwnCatalog[i].ID = *(ptr++);
%b_OwnCatalog[i].Str = (STRPTR) cptr;
StrLength = *ptr+1; /* NUL-Byte! */
ptr++;
strncpy(cptr, (char *) ptr, StrLength);
/* Not more, not less bytes! */
cptr+=StrLength;
ptr += (StrLength+3)/4;
BytesToScan -= 8+((StrLength+3)/4)*4;
++i;
}
break;
}
}
}
}
}
CloseIFF(iffhandle);
}
Close(iffhandle->iff_Stream);
}
FreeIFF(iffhandle);
}
}
}
void Close%bCatalog(void)
{ if (LocaleBase != NULL)
{ CloseCatalog(%b_Catalog);
}
%b_Catalog = NULL;
if (%b_OwnCatalog != NULL)
{ FreeMem(%b_OwnCatalog,
%b_OwnStrings*sizeof(struct FC_Type)+%b_OwnBytes);
%b_OwnCatalog = NULL;
}
}
STRPTR Get%bString(LONG strnum)
{ STRPTR defaultstr = NULL;
LONG i;
for (i = 0; i < sizeof(%b_Array)/sizeof(struct FC_Type); i++)
{ if (%b_Array[i].ID == strnum)
{ defaultstr = %b_Array[i].Str;
break;
}
}
if (%b_Catalog == NULL)
{ if (%b_OwnCatalog != NULL)
{ for (i = 0; i < %b_OwnStrings; i++)
{ if (%b_OwnCatalog[i].ID == strnum)
{ return(%b_OwnCatalog[i].Str);
}
}
}
return(defaultstr);
}
return(GetCatalogStr(%b_Catalog, strnum, defaultstr));
}