amath/src/system/language_amiga.cpp

186 lines
5.5 KiB
C++
Raw Normal View History

2017-02-27 22:31:21 +00:00
/*-
2021-01-11 19:37:42 +00:00
* Copyright (c) 2014-2021 Carsten Sonne Larsen <cs@innolan.net>
2015-04-01 12:43:50 +00:00
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
2017-02-27 22:31:21 +00:00
* Project homepage:
2017-07-14 09:30:24 +00:00
* https://amath.innolan.net
2021-01-11 19:37:42 +00:00
*
2015-04-01 12:43:50 +00:00
*/
2017-02-27 22:23:06 +00:00
#include "amath.h"
#include "amathc.h"
2017-03-11 22:37:45 +00:00
#include "program.h"
#include "language_amiga.h"
2017-04-12 22:50:51 +00:00
#include "loc/help.h"
#include "loc/text.h"
#include "loc/ident.h"
#include "loc/kword.h"
2015-04-01 12:43:50 +00:00
2017-04-15 18:36:40 +00:00
#if defined(AMIGA)
2015-04-08 09:05:41 +00:00
#include <clib/locale_protos.h>
2015-04-01 12:43:50 +00:00
2021-01-11 19:59:15 +00:00
#define CATALOG_HELP "amath-help.catalog"
#define CATALOG_IDEN "amath-ident.catalog"
#define CATALOG_TEXT "amath-text.catalog"
#define CATALOG_KEYW "amath-keyword.catalog"
#define CATALOG_DEF OC_BuiltInLanguage, "english"
2015-04-13 21:48:08 +00:00
AmigaLanguage::AmigaLanguage() :
Language::Language()
2015-04-01 12:43:50 +00:00
{
2017-03-24 19:09:05 +00:00
locale = OpenLocale(nullptr);
2015-04-13 21:44:17 +00:00
helpcatalog = OpenCatalog(locale, CATALOG_HELP, CATALOG_DEF, TAG_DONE);
identcatalog = OpenCatalog(locale, CATALOG_IDEN, CATALOG_DEF, TAG_DONE);
textcatalog = OpenCatalog(locale, CATALOG_TEXT, CATALOG_DEF, TAG_DONE);
keywordcatalog = OpenCatalog(locale, CATALOG_KEYW, CATALOG_DEF, TAG_DONE);
2017-03-24 19:09:05 +00:00
if (keywordcatalog != nullptr) {
2015-04-13 21:44:17 +00:00
keywordsloc = new keyworddef[keywordcount];
for (unsigned int j = 0; j < keywordcount; j++) {
keywordsloc[j].id = j;
2017-03-24 19:09:05 +00:00
keywordsloc[j].name = GetCatalogStr(keywordcatalog, j, nullptr);
2015-04-13 21:44:17 +00:00
keywordsloc[j].symbol = keywords[j].symbol;
}
2015-04-10 13:41:29 +00:00
}
2015-04-01 12:43:50 +00:00
}
AmigaLanguage::~AmigaLanguage()
{
2017-03-24 19:09:05 +00:00
if (helpcatalog != nullptr) {
2015-04-13 21:44:17 +00:00
CloseCatalog(helpcatalog);
}
2017-03-24 19:09:05 +00:00
if (identcatalog != nullptr) {
2015-04-13 21:44:17 +00:00
CloseCatalog(identcatalog);
}
2017-03-24 19:09:05 +00:00
if (textcatalog != nullptr) {
2015-04-13 21:44:17 +00:00
CloseCatalog(textcatalog);
}
2017-03-24 19:09:05 +00:00
if (keywordcatalog != nullptr) {
2015-04-13 21:44:17 +00:00
CloseCatalog(keywordcatalog);
}
2017-03-24 19:09:05 +00:00
if (locale != nullptr) {
2015-04-13 21:44:17 +00:00
CloseLocale(locale);
}
2015-04-10 13:41:29 +00:00
}
2015-04-13 22:03:33 +00:00
char* AmigaLanguage::Translate(textdef *def)
2015-04-10 13:41:29 +00:00
{
2015-04-13 21:48:08 +00:00
return (char*)GetCatalogStr(textcatalog, def->id, (char*)def->text);
2015-04-01 12:43:50 +00:00
}
2015-04-13 22:03:33 +00:00
char* AmigaLanguage::Translate(helptextdef *def)
2015-04-01 12:43:50 +00:00
{
2015-04-13 21:48:08 +00:00
return (char*)GetCatalogStr(helpcatalog, def->id, (char*)def->text);
2015-04-01 12:43:50 +00:00
}
2015-04-13 22:03:33 +00:00
char* AmigaLanguage::Translate(identhelpdef *def)
2015-04-01 12:43:50 +00:00
{
2015-04-13 21:48:08 +00:00
return (char*)GetCatalogStr(identcatalog, def->id, (char*)def->text);
2015-04-01 12:43:50 +00:00
}
char AmigaLanguage::GetFractionPoint()
{
#if defined(STRICT_LOCAL)
2015-04-01 12:43:50 +00:00
return locale->loc_DecimalPoint[0];
#else
// To ensure compatibility, set fraction point to full stop / period
return '.';
#endif
2015-04-01 12:43:50 +00:00
}
bool AmigaLanguage::CharIsAlNum(long unsigned int character)
{
return IsAlNum(locale, character);
}
bool AmigaLanguage::CharIsAlpha(long unsigned int character)
{
return IsAlpha(locale, character);
}
bool AmigaLanguage::CharIsDigit(long unsigned int character)
{
return IsDigit(locale, character);
}
bool AmigaLanguage::CharIsPunct(long unsigned int character)
{
return IsPunct(locale, character);
}
bool AmigaLanguage::CharIsSpace(long unsigned int character)
{
return IsSpace(locale, character);
}
bool AmigaLanguage::CharIsCntrl(long unsigned int character)
{
return IsCntrl(locale, character);
}
bool AmigaLanguage::StrIsEqualLoc(const char* s1, const char* s2)
{
2015-04-01 14:58:18 +00:00
return (StrnCmp(locale, (char*)s1, (char*)s2, -1, SC_COLLATE1) == 0);
2015-04-01 12:43:50 +00:00
}
2017-01-24 19:48:02 +00:00
bool AmigaLanguage::Validate(char c)
{
return CharIsAlNum(c) ||
CharIsPunct(c) ||
CharIsSpace(c) ||
CharIsQuote(c) ||
CharIsOperator(c);
}
2015-04-01 12:43:50 +00:00
/* for numeric values */
//STRPTR loc_DecimalPoint; /* character before the decimals */
//STRPTR loc_GroupSeparator; /* separates groups of digits */
//STRPTR loc_FracGroupSeparator; /* separates groups of digits */
//UBYTE *loc_Grouping; /* size of each group */
//UBYTE *loc_FracGrouping; /* size of each group */
/* elements of the byte arrays pointed to by:
* Locale.loc_Grouping
* Locale.loc_FracGrouping
* are interpreted as follows:
*
* 255 indicates that no further grouping is to be performed
* 0 indicates that the previous element is to be repeatedly used
* for the remainder of the digits
* <other> the number of digits that comprises the current group
*/
//LIBRARIES_LOCALE_H
/* constants for GetLocaleStr() */
//#define SOFTHYPHEN 43 /* soft hyphenation */
//#define HARDHYPHEN 44 /* hard hyphenation */
//#define OPENQUOTE 45 /* start of quoted block */
//#define CLOSEQUOTE 46 /* end of quoted block */
#endif