locale.pas 13 KB

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