1 { 2 This file is part of the Free Pascal run time library. 3 Copyright (c) 2017 by Free Pascal development team 4 5 locale.library functions 6 7 See the file COPYING.FPC, included in this distribution, 8 for details about the copyright. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 13 14 **********************************************************************} 15 16 {$PACKRECORDS 2} 17 18 unit locale; 19 20 interface 21 uses 22 exec, amigados, utility; 23 24 const 25 // constants for GetLocaleStr() 26 LANG_CODE = 0; // ISO-639-2/T 3-letter lowercase language code (e.g. "eng"). Added in V50 27 28 DAY_1 = 1; // Sunday 29 DAY_2 = 2; // Monday 30 DAY_3 = 3; // Tuesday 31 DAY_4 = 4; // Wednesday 32 DAY_5 = 5; // Thursday 33 DAY_6 = 6; // Friday 34 DAY_7 = 7; // Saturday 35 36 ABDAY_1 = 8; // Sun 37 ABDAY_2 = 9; // Mon 38 ABDAY_3 = 10; // Tue 39 ABDAY_4 = 11; // Wed 40 ABDAY_5 = 12; // Thu 41 ABDAY_6 = 13; // Fri 42 ABDAY_7 = 14; // Sat 43 44 MON_1 = 15; // January 45 MON_2 = 16; // February 46 MON_3 = 17; // March 47 MON_4 = 18; // April 48 MON_5 = 19; // May 49 MON_6 = 20; // June 50 MON_7 = 21; // July 51 MON_8 = 22; // August 52 MON_9 = 23; // September 53 MON_10 = 24; // October 54 MON_11 = 25; // November 55 MON_12 = 26; // December 56 57 ABMON_1 = 27; // Jan 58 ABMON_2 = 28; // Feb 59 ABMON_3 = 29; // Mar 60 ABMON_4 = 30; // Apr 61 ABMON_5 = 31; // May 62 ABMON_6 = 32; // Jun 63 ABMON_7 = 33; // Jul 64 ABMON_8 = 34; // Aug 65 ABMON_9 = 35; // Sep 66 ABMON_10 = 36; // Oct 67 ABMON_11 = 37; // Nov 68 ABMON_12 = 38; // Dec 69 70 YESSTR = 39; // affirmative response for yes/no queries 71 NOSTR = 40; // negative response for yes/no queries 72 73 AM_STR = 41; // AM 74 PM_STR = 42; // PM 75 76 SOFTHYPHEN = 43; // soft hyphenation 77 HARDHYPHEN = 44; // hard hyphenation 78 79 OPENQUOTE = 45; // start of quoted block 80 CLOSEQUOTE = 46; // end of quoted block 81 82 YESTERDAYSTR = 47; // Yesterday 83 TODAYSTR = 48; // Today 84 TOMORROWSTR = 49; // Tomorrow 85 FUTURESTR = 50; // Future 86 87 LANG_NAME = 51; // native name of this language in this language and charset. Added in V50. 88 89 // Added in V50: Alternate forms of weekday names to be used 90 // in date strings, some languages need those. Fallback are 91 // the normal weekday names for standalone usage. 92 ALTDAY_1 = 52; // Sunday 93 ALTDAY_2 = 53; // Monday 94 ALTDAY_3 = 54; // Tuesday 95 ALTDAY_4 = 55; // Wednesday 96 ALTDAY_5 = 56; // Thursday 97 ALTDAY_6 = 57; // Friday 98 ALTDAY_7 = 58; // Saturday 99 100 // Added in V50: Alternate forms of month names to be used 101 // in date strings, some languages need those. Fallback are 102 // the normal month names for standalone usage. 103 ALTMON_1 = 59; // January 104 ALTMON_2 = 60; // February 105 ALTMON_3 = 61; // March 106 ALTMON_4 = 62; // April 107 ALTMON_5 = 63; // May 108 ALTMON_6 = 64; // June 109 ALTMON_7 = 65; // July 110 ALTMON_8 = 66; // August 111 ALTMON_9 = 67; // September 112 ALTMON_10 = 68; // October 113 ALTMON_11 = 69; // November 114 ALTMON_12 = 70; // December 115 116 MAXSTRMSG = 71; { current number of defined strings } 117 118 119 //*************************************************************************** 120 121 type 122 // OpenLibrary("locale.library",0) returns a pointer to this structure 123 PLocaleBase = ^TLocaleBase; 124 TLocaleBase = record 125 lb_LibNode: TLibrary; 126 lb_SysPatches: Boolean; // True if locale installed its patches 127 end; 128 129 {***************************************************************************} 130 131 type 132 // This structure must only be allocated by locale.library and is READ-ONLY! 133 PLocale = ^TLocale; 134 TLocale = record 135 loc_LocaleName: STRPTR; // locale's name 136 loc_LanguageName: STRPTR; // language of this locale 137 loc_PrefLanguages: array[0..9] of STRPTR; // preferred languages 138 loc_Flags: LongWord; // always 0 for now 139 140 loc_CodeSet: LongWord; // IANA charset number. V50+ default charset 141 loc_CountryCode: LongWord; // user's country code 142 loc_TelephoneCode: LongWord; // country's telephone code 143 loc_GMTOffset: LongWord; // minutes from GMT 144 loc_MeasuringSystem: Byte; // what measuring system? 145 loc_CalendarType: Byte; // what calendar type? 146 loc_Reserved0: array[0..1] of Byte; 147 148 loc_DateTimeFormat: STRPTR; // regular date & time format 149 loc_DateFormat: STRPTR; // date format by itself 150 loc_TimeFormat: STRPTR; // time format by itself 151 152 loc_ShortDateTimeFormat: STRPTR; // short date & time format 153 loc_ShortDateFormat: STRPTR; // short date format by itself 154 loc_ShortTimeFormat: STRPTR; // short time format by itself 155 156 // for numeric values 157 loc_DecimalPoint: STRPTR; // character before the decimals 158 loc_GroupSeparator: STRPTR; // separates groups of digits 159 loc_FracGroupSeparator: STRPTR; // separates groups of digits 160 loc_Grouping: PByte; // size of each group 161 loc_FracGrouping: PByte; // size of each group 162 163 // for monetary values 164 loc_MonDecimalPoint: STRPTR; 165 loc_MonGroupSeparator: STRPTR; 166 loc_MonFracGroupSeparator: STRPTR; 167 loc_MonGrouping: PByte; 168 loc_MonFracGrouping: PByte; 169 loc_MonFracDigits: Byte; // digits after the decimal point 170 loc_MonIntFracDigits : Byte; // for international representation 171 loc_Reserved1: array[0..1] of Byte; 172 173 // for currency symbols 174 loc_MonCS: STRPTR; // currency symbol 175 loc_MonSmallCS: STRPTR; // symbol for small amounts 176 loc_MonIntCS: STRPTR; // internationl (ISO 4217) code 177 178 { for positive monetary values } 179 loc_MonPositiveSign: STRPTR; // indicate positive money value 180 loc_MonPositiveSpaceSep: Byte; // determine if separated by space 181 loc_MonPositiveSignPos: Byte; // position of positive sign 182 loc_MonPositiveCSPos: Byte; // position of currency symbol 183 loc_Reserved2: Byte; 184 185 //{ for negative monetary values } 186 loc_MonNegativeSign: STRPTR; // indicate negative money value 187 loc_MonNegativeSpaceSep: STRPTR; // determine if separated by space 188 loc_MonNegativeSignPos: STRPTR; // position of negative sign 189 loc_MonNegativeCSPos: STRPTR; // position of currency symbol 190 loc_Reserved3: Byte; 191 end; 192 193 const 194 // constants for Locale.loc_MeasuringSystem 195 MS_ISO = 0; // international metric system 196 MS_AMERICAN = 1; // american system 197 MS_IMPERIAL = 2; // imperial system 198 MS_BRITISH = 3; // british system 199 200 // constants for Locale.loc_CalendarType 201 CT_7SUN = 0; // 7 days a week, Sunday is the first day 202 CT_7MON = 1; // 7 days a week, Monday is the first day 203 CT_7TUE = 2; // 7 days a week, Tuesday is the first day 204 CT_7WED = 3; // 7 days a week, Wednesday is the first day 205 CT_7THU = 4; // 7 days a week, Thursday is the first day 206 CT_7FRI = 5; // 7 days a week, Friday is the first day 207 CT_7SAT = 6; // 7 days a week, Saturday is the first day 208 209 // constants for Locale.loc_MonPositiveSpaceSep and Locale.loc_MonNegativeSpaceSep 210 SS_NOSPACE = 0; // cur. symbol is NOT separated from value with a space 211 SS_SPACE = 1; // cur. symbol IS separated from value with a space 212 213 // constants for Locale.loc_MonPositiveSignPos and Locale.loc_MonNegativeSignPos } 214 SP_PARENS = 0; // () surround the quantity and currency_symbol 215 SP_PREC_ALL = 1; // sign string comes before amount and symbol 216 SP_SUCC_ALL = 2; // sign string comes after amount and symbol 217 SP_PREC_CURR = 3; // sign string comes right before currency symbol 218 SP_SUCC_CURR = 4; // sign string comes right after currency symbol 219 220 // constants for Locale.loc_MonPositiveCSPos and Locale.loc_MonNegativeCSPos 221 CSP_PRECEDES = 0; // currency symbol comes before value 222 CSP_SUCCEEDS = 1; // currency symbol comes after value 223 224 { elements of the byte arrays pointed to by: 225 Locale.loc_Grouping 226 Locale.loc_FracGrouping 227 Locale.loc_MonGrouping 228 Locale.loc_MonFracGrouping 229 are interpreted as follows: 230 231 255 indicates that no further grouping is to be performed 232 0 indicates that the previous element is to be repeatedly used 233 for the remainder of the digits 234 <other> the number of digits that comprises the current group} 235 236 237 //*************************************************************************** 238 239 240 // Tags for OpenCatalog() 241 OC_TagBase = TAG_USER + $90000; 242 OC_BuiltInLanguage = OC_TagBase + 1; // language of built-in strings 243 OC_BuiltInCodeSet = OC_TagBase + 2; // code set of built-in strings 244 OC_Version = OC_TagBase + 3; // catalog version number required 245 OC_Language = OC_TagBase + 4; // preferred language of catalog 246 OC_WantedCodeSet = OC_TagBase + 5; // code set of font to be used (V50) 247 OC_BuiltInVersion = OC_TagBase + 6; // version of builtin strings (V52.3) 248 OC_PreferExternal = OC_TagBase + 7; // replace builtin language? (V53.4) 249 250 251 //*************************************************************************** 252 253 254 // Comparison types for StrnCmp() 255 SC_ASCII = 0; 256 SC_COLLATE1 = 1; 257 SC_COLLATE2 = 2; 258 259 260 //*************************************************************************** 261 262 type 263 // This structure must only be allocated by locale.library and is READ-ONLY! 264 PCatalog = ^TCatalog; 265 TCatalog = record 266 cat_Link: TNode; // for internal linkage 267 cat_Pad: Word; // to longword align 268 cat_Language: STRPTR; // language of the catalog 269 cat_CodeSet: LongWord; // currently always 0 270 cat_Version: Word; // version of the catalog 271 cat_Revision: Word; // revision of the catalog 272 end; 273 274 var 275 LocaleBase: PLocaleBase = nil; 276 ILocale: PInterface = nil; 277 278 const 279 LOCALENAME: PChar = 'locale.library'; 280 281 function LocaleObtain(): LongWord; syscall ILocale 60; 282 function LocaleRelease(): LongWord; syscall ILocale 64; 283 procedure LocaleExpunge(); syscall ILocale 68; 284 function LocaleClone(): PInterface; syscall ILocale 72; 285 // 76 Private 1 286 procedure CloseCatalog(Catalog: PCatalog); syscall ILocale 80; 287 procedure CloseLocale(Locale: PLocale); syscall ILocale 84; 288 function ConvToLower(Locale: PLocale; Character: LongWord): LongWord; syscall ILocale 88; 289 function ConvToUpper(Locale: PLocale; Character: LongWord): LongWord; syscall ILocale 92; 290 procedure FormatDate(Locale: PLocale; FmtTemplate: STRPTR; Date: PDateStamp; PutCharFunc: PHook); syscall ILocale 96; 291 function FormatString(Locale: PLocale; FmtTemplate: STRPTR; DataStream: APTR; PutCharFunc: PHook): POINTER; syscall ILocale 100; 292 function GetCatalogStr(Catalog: PCatalog; StringNum: LongInt; DefaultString: STRPTR): PChar; syscall ILocale 104; 293 function GetLocaleStr(Locale: PLocale; StringNum: LongWord): PChar; syscall ILocale 108; 294 function IsAlNum(Locale: PLocale; Character: LongWord): LongBool; syscall ILocale 112; 295 function IsAlpha(Locale: PLocale; Character: LongWord): LongBool; syscall ILocale 116; 296 function IsCntrl(Locale: PLocale; Character: LongWord): LongBool; syscall ILocale 120; 297 function IsDigit(Locale: PLocale; Character: LongWord): LongBool; syscall ILocale 124; 298 function IsGraph(Locale: PLocale; Character: LongWord): LongBool; syscall ILocale 128; 299 function IsLower(Locale: PLocale; Character: LongWord): LongBool; syscall ILocale 132; 300 function IsPrint(Locale: PLocale; Character: LongWord): LongBool; syscall ILocale 136; 301 function IsPunct(Locale: PLocale; Character: LongWord): LongBool; syscall ILocale 140; 302 function IsSpace(Locale: PLocale; Character: LongWord): LongBool; syscall ILocale 144; 303 function IsUpper(Locale: PLocale; Character: LongWord): LongBool; syscall ILocale 148; 304 function IsXDigit(Locale: PLocale; Character: LongWord): LongBool; syscall ILocale 152; 305 function OpenCatalogA(Locale: PLocale; Name: PChar; Tags: PTagItem): PCatalog; syscall ILocale 156; 306 // 160 OpenCatalog 307 function OpenLocale(Name: STRPTR): PLocale; syscall ILocale 164; 308 function ParseDate(Locale: PLocale; Date: PDateStamp; FmtTemplate: STRPTR; GetCharFunc: PHook): LongBool; syscall ILocale 168; 309 // 172 Private2 310 function StrConvert(Locale: PLocale; String1: STRPTR; Buffer: APTR; BufferSize: LongWord; Typ: LongWord): LongWord; syscall ILocale 176; 311 function StrnCmp(Locale: PLocale; String1: STRPTR; String2: STRPTR; Length: LongInt; Typ: LongWord): LongInt; syscall ILocale 180; 312 function Locale_DateToStr(DateTime: PDateTime): LongInt; syscall ILocale 184; 313 function Locale_StrToDate(DateTime: PDateTime): LongInt; syscall ILocale 188; 314 function IsBlank(Locale: PLocale; Character: LongWord): LongInt; syscall ILocale 192; 315 function FormatString32(Locale: Plocale; FmtTemplate: STRPTR; DataStream: APTR; PutCharFunc: PHook): APTR; syscall ILocale 196; 316 317 function OpenCatalog(Locale: PLocale; Name: STRPTR; const Args: array of PtrUInt): PCatalog; inline; 318 319 implementation 320 321 function OpenCatalog(Locale: PLocale; Name: STRPTR; const Args: array of PtrUInt): PCatalog; 322 begin 323 OpenCatalog := OpenCatalogA(Locale, Name, @Args); 324 end; 325 326 const 327 LIBVERSION: LongWord = 0; 328 329 initialization 330 LocaleBase := PLocaleBase(OpenLibrary(LOCALENAME, LIBVERSION)); 331 if Assigned(LocaleBase) then 332 ILocale := GetInterface(PLibrary(LocaleBase), 'main', 1, nil); 333 finalization 334 if Assigned(ILocale) then 335 DropInterface(ILocale); 336 if Assigned(LocaleBase) then 337 CloseLibrary(PLibrary(LocaleBase)); 338 end. 339 340 341 342