amath  1.8.5
Simple command line calculator
language_amiga.cpp
Go to the documentation of this file.
1 /*-
2  * Copyright (c) 2014-2018 Carsten Sonne Larsen <cs@innolan.net>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  * Project homepage:
26  * https://amath.innolan.net
27  *
28  */
29 
30 #include "amath.h"
31 #include "amathc.h"
32 #include "program.h"
33 #include "language_amiga.h"
34 #include "loc/help.h"
35 #include "loc/text.h"
36 #include "loc/ident.h"
37 #include "loc/kword.h"
38 
39 #if defined(AMIGA)
40 #include <clib/locale_protos.h>
41 
42 AmigaLanguage::AmigaLanguage() :
43  Language::Language()
44 {
45  locale = OpenLocale(nullptr);
46  helpcatalog = OpenCatalog(locale, CATALOG_HELP, CATALOG_DEF, TAG_DONE);
47  identcatalog = OpenCatalog(locale, CATALOG_IDEN, CATALOG_DEF, TAG_DONE);
48  textcatalog = OpenCatalog(locale, CATALOG_TEXT, CATALOG_DEF, TAG_DONE);
49  keywordcatalog = OpenCatalog(locale, CATALOG_KEYW, CATALOG_DEF, TAG_DONE);
50 
51  if (keywordcatalog != nullptr) {
52  keywordsloc = new keyworddef[keywordcount];
53  for (unsigned int j = 0; j < keywordcount; j++) {
54  keywordsloc[j].id = j;
55  keywordsloc[j].name = GetCatalogStr(keywordcatalog, j, nullptr);
56  keywordsloc[j].symbol = keywords[j].symbol;
57  }
58  }
59 }
60 
61 AmigaLanguage::~AmigaLanguage()
62 {
63  if (helpcatalog != nullptr) {
64  CloseCatalog(helpcatalog);
65  }
66 
67  if (identcatalog != nullptr) {
68  CloseCatalog(identcatalog);
69  }
70 
71  if (textcatalog != nullptr) {
72  CloseCatalog(textcatalog);
73  }
74 
75  if (keywordcatalog != nullptr) {
76  CloseCatalog(keywordcatalog);
77  }
78 
79  if (locale != nullptr) {
80  CloseLocale(locale);
81  }
82 }
83 
84 char* AmigaLanguage::Translate(textdef *def)
85 {
86  return (char*)GetCatalogStr(textcatalog, def->id, (char*)def->text);
87 }
88 
89 char* AmigaLanguage::Translate(helptextdef *def)
90 {
91  return (char*)GetCatalogStr(helpcatalog, def->id, (char*)def->text);
92 }
93 
94 char* AmigaLanguage::Translate(identhelpdef *def)
95 {
96  return (char*)GetCatalogStr(identcatalog, def->id, (char*)def->text);
97 }
98 
99 char AmigaLanguage::GetFractionPoint()
100 {
101  return locale->loc_DecimalPoint[0];
102 }
103 
104 bool AmigaLanguage::CharIsAlNum(long unsigned int character)
105 {
106  return IsAlNum(locale, character);
107 }
108 
109 bool AmigaLanguage::CharIsAlpha(long unsigned int character)
110 {
111  return IsAlpha(locale, character);
112 }
113 
114 bool AmigaLanguage::CharIsDigit(long unsigned int character)
115 {
116  return IsDigit(locale, character);
117 }
118 
119 bool AmigaLanguage::CharIsPunct(long unsigned int character)
120 {
121  return IsPunct(locale, character);
122 }
123 
124 bool AmigaLanguage::CharIsSpace(long unsigned int character)
125 {
126  return IsSpace(locale, character);
127 }
128 
129 bool AmigaLanguage::CharIsCntrl(long unsigned int character)
130 {
131  return IsCntrl(locale, character);
132 }
133 
134 bool AmigaLanguage::StrIsEqualLoc(const char* s1, const char* s2)
135 {
136  return (StrnCmp(locale, (char*)s1, (char*)s2, -1, SC_COLLATE1) == 0);
137 }
138 
139 bool AmigaLanguage::Validate(char c)
140 {
141  return CharIsAlNum(c) ||
142  CharIsPunct(c) ||
143  CharIsSpace(c) ||
144  CharIsQuote(c) ||
145  CharIsOperator(c);
146 }
147 
148 /* for numeric values */
149 //STRPTR loc_DecimalPoint; /* character before the decimals */
150 //STRPTR loc_GroupSeparator; /* separates groups of digits */
151 //STRPTR loc_FracGroupSeparator; /* separates groups of digits */
152 //UBYTE *loc_Grouping; /* size of each group */
153 //UBYTE *loc_FracGrouping; /* size of each group */
154 
155 /* elements of the byte arrays pointed to by:
156  * Locale.loc_Grouping
157  * Locale.loc_FracGrouping
158  * are interpreted as follows:
159  *
160  * 255 indicates that no further grouping is to be performed
161  * 0 indicates that the previous element is to be repeatedly used
162  * for the remainder of the digits
163  * <other> the number of digits that comprises the current group
164  */
165 
166 
167 //LIBRARIES_LOCALE_H
168 /* constants for GetLocaleStr() */
169 //#define SOFTHYPHEN 43 /* soft hyphenation */
170 //#define HARDHYPHEN 44 /* hard hyphenation */
171 //#define OPENQUOTE 45 /* start of quoted block */
172 //#define CLOSEQUOTE 46 /* end of quoted block */
173 
174 #endif