sysutils.pp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by Florian Klaempfl
  5. member of the Free Pascal development team
  6. Sysutils unit for OS/2
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. unit sysutils;
  14. interface
  15. {$MODE objfpc}
  16. { force ansistrings }
  17. {$H+}
  18. uses
  19. Dos, Strings;
  20. { Include platform independent interface part }
  21. {$i sysutilh.inc}
  22. implementation
  23. { Include platform independent implementation part }
  24. {$i sysutils.inc}
  25. {****************************************************************************
  26. System (imported) calls
  27. ****************************************************************************}
  28. (* "uses DosCalls" could not be used here due to type *)
  29. (* conflicts, so needed parts had to be redefined here). *)
  30. type
  31. TFileStatus = object
  32. end;
  33. PFileStatus = ^TFileStatus;
  34. TFileStatus0 = object (TFileStatus)
  35. DateCreation, {Date of file creation.}
  36. TimeCreation, {Time of file creation.}
  37. DateLastAccess, {Date of last access to file.}
  38. TimeLastAccess, {Time of last access to file.}
  39. DateLastWrite, {Date of last modification of file.}
  40. TimeLastWrite: word; {Time of last modification of file.}
  41. FileSize, {Size of file.}
  42. FileAlloc: cardinal; {Amount of space the file really
  43. occupies on disk.}
  44. end;
  45. PFileStatus0 = ^TFileStatus0;
  46. TFileStatus3 = object (TFileStatus)
  47. NextEntryOffset: cardinal; {Offset of next entry}
  48. DateCreation, {Date of file creation.}
  49. TimeCreation, {Time of file creation.}
  50. DateLastAccess, {Date of last access to file.}
  51. TimeLastAccess, {Time of last access to file.}
  52. DateLastWrite, {Date of last modification of file.}
  53. TimeLastWrite: word; {Time of last modification of file.}
  54. FileSize, {Size of file.}
  55. FileAlloc: cardinal; {Amount of space the file really
  56. occupies on disk.}
  57. AttrFile: cardinal; {Attributes of file.}
  58. end;
  59. PFileStatus3 = ^TFileStatus3;
  60. TFileFindBuf3 = object (TFileStatus3)
  61. Name: ShortString; {Also possible to use as ASCIIZ.
  62. The byte following the last string
  63. character is always zero.}
  64. end;
  65. PFileFindBuf3 = ^TFileFindBuf3;
  66. TFSInfo = record
  67. case word of
  68. 1:
  69. (File_Sys_ID,
  70. Sectors_Per_Cluster,
  71. Total_Clusters,
  72. Free_Clusters: cardinal;
  73. Bytes_Per_Sector: word);
  74. 2: {For date/time description,
  75. see file searching realted
  76. routines.}
  77. (Label_Date, {Date when volume label was created.}
  78. Label_Time: word; {Time when volume label was created.}
  79. VolumeLabel: ShortString); {Volume label. Can also be used
  80. as ASCIIZ, because the byte
  81. following the last character of
  82. the string is always zero.}
  83. end;
  84. PFSInfo = ^TFSInfo;
  85. TCountryCode=record
  86. Country, {Country to query info about (0=current).}
  87. CodePage: cardinal; {Code page to query info about (0=current).}
  88. end;
  89. PCountryCode=^TCountryCode;
  90. TTimeFmt = (Clock12, Clock24);
  91. TCountryInfo=record
  92. Country, CodePage: cardinal; {Country and codepage requested.}
  93. case byte of
  94. 0:
  95. (DateFormat: cardinal; {1=ddmmyy 2=yymmdd 3=mmddyy}
  96. CurrencyUnit: array [0..4] of char;
  97. ThousandSeparator: char; {Thousands separator.}
  98. Zero1: byte; {Always zero.}
  99. DecimalSeparator: char; {Decimals separator,}
  100. Zero2: byte;
  101. DateSeparator: char; {Date separator.}
  102. Zero3: byte;
  103. TimeSeparator: char; {Time separator.}
  104. Zero4: byte;
  105. CurrencyFormat, {Bit field:
  106. Bit 0: 0=indicator before value
  107. 1=indicator after value
  108. Bit 1: 1=insert space after
  109. indicator.
  110. Bit 2: 1=Ignore bit 0&1, replace
  111. decimal separator with
  112. indicator.}
  113. DecimalPlace: byte; {Number of decimal places used in
  114. currency indication.}
  115. TimeFormat: TTimeFmt; {12/24 hour.}
  116. Reserve1: array [0..1] of word;
  117. DataSeparator: char; {Data list separator}
  118. Zero5: byte;
  119. Reserve2: array [0..4] of word);
  120. 1:
  121. (fsDateFmt: cardinal; {1=ddmmyy 2=yymmdd 3=mmddyy}
  122. szCurrency: array [0..4] of char;
  123. {null terminated currency symbol}
  124. szThousandsSeparator: array [0..1] of char;
  125. {Thousands separator + #0}
  126. szDecimal: array [0..1] of char;
  127. {Decimals separator + #0}
  128. szDateSeparator: array [0..1] of char;
  129. {Date separator + #0}
  130. szTimeSeparator: array [0..1] of char;
  131. {Time separator + #0}
  132. fsCurrencyFmt, {Bit field:
  133. Bit 0: 0=indicator before value
  134. 1=indicator after value
  135. Bit 1: 1=insert space after
  136. indicator.
  137. Bit 2: 1=Ignore bit 0&1, replace
  138. decimal separator with
  139. indicator}
  140. cDecimalPlace: byte; {Number of decimal places used in
  141. currency indication}
  142. fsTimeFmt: byte; {0=12,1=24 hours}
  143. abReserved1: array [0..1] of word;
  144. szDataSeparator: array [0..1] of char;
  145. {Data list separator + #0}
  146. abReserved2: array [0..4] of word);
  147. end;
  148. PCountryInfo=^TCountryInfo;
  149. const
  150. ilStandard = 1;
  151. ilQueryEAsize = 2;
  152. ilQueryEAs = 3;
  153. ilQueryFullName = 5;
  154. {This is the correct way to call external assembler procedures.}
  155. procedure syscall;external name '___SYSCALL';
  156. function DosSetFileInfo (Handle: longint; InfoLevel: cardinal; AFileStatus: PFileStatus;
  157. FileStatusLen: cardinal): cardinal; cdecl; external 'DOSCALLS' index 218;
  158. function DosQueryFSInfo (DiskNum, InfoLevel: cardinal; var Buffer: TFSInfo;
  159. BufLen: cardinal): cardinal; cdecl; external 'DOSCALLS' index 278;
  160. function DosQueryFileInfo (Handle: longint; InfoLevel: cardinal;
  161. AFileStatus: PFileStatus; FileStatusLen: cardinal): cardinal; cdecl;
  162. external 'DOSCALLS' index 279;
  163. function DosScanEnv (Name: PChar; var Value: PChar): cardinal; cdecl;
  164. external 'DOSCALLS' index 227;
  165. function DosFindFirst (FileMask: PChar; var Handle: longint; Attrib: cardinal;
  166. AFileStatus: PFileStatus; FileStatusLen: cardinal;
  167. var Count: cardinal; InfoLevel: cardinal): cardinal; cdecl;
  168. external 'DOSCALLS' index 264;
  169. function DosFindNext (Handle: longint; AFileStatus: PFileStatus;
  170. FileStatusLen: cardinal; var Count: cardinal): cardinal; cdecl;
  171. external 'DOSCALLS' index 265;
  172. function DosFindClose (Handle: longint): cardinal; cdecl;
  173. external 'DOSCALLS' index 263;
  174. function DosQueryCtryInfo (Size: cardinal; var Country: TCountryCode;
  175. var Res: TCountryInfo; var ActualSize: cardinal): cardinal; cdecl;
  176. external 'NLS' index 5;
  177. function DosMapCase (Size: cardinal; var Country: TCountryCode;
  178. AString: PChar): cardinal; cdecl; external 'NLS' index 7;
  179. function DosDelete(FileName:PChar): Longint; cdecl;
  180. external 'DOSCALLS' index 259;
  181. function DosMove(OldFile, NewFile:PChar): Longint; cdecl;
  182. external 'DOSCALLS' index 271;
  183. function DosQueryPathInfo(FileName:PChar;InfoLevel:cardinal;
  184. AFileStatus:PFileStatus;FileStatusLen:cardinal): Longint; cdecl;
  185. external 'DOSCALLS' index 223;
  186. function DosSetPathInfo(FileName:PChar;InfoLevel:longint;
  187. AFileStatus:PFileStatus;FileStatusLen,
  188. Options:longint):longint; cdecl;
  189. external 'DOSCALLS' index 219;
  190. {****************************************************************************
  191. File Functions
  192. ****************************************************************************}
  193. const
  194. ofRead = $0000; {Open for reading}
  195. ofWrite = $0001; {Open for writing}
  196. ofReadWrite = $0002; {Open for reading/writing}
  197. doDenyRW = $0010; {DenyAll (no sharing)}
  198. faCreateNew = $00010000; {Create if file does not exist}
  199. faOpenReplace = $00040000; {Truncate if file exists}
  200. faCreate = $00050000; {Create if file does not exist, truncate otherwise}
  201. FindResvdMask = $00003737; {Allowed bits in attribute
  202. specification for DosFindFirst call.}
  203. {$ASMMODE INTEL}
  204. function FileOpen (const FileName: string; Mode: integer): longint; assembler;
  205. asm
  206. push ebx
  207. mov eax, Mode
  208. (* DenyAll if sharing not specified. *)
  209. test eax, 112
  210. jnz @FOpen1
  211. or eax, 16
  212. @FOpen1:
  213. mov ecx, eax
  214. mov eax, 7F2Bh
  215. mov edx, FileName
  216. call syscall
  217. pop ebx
  218. end {['eax', 'ebx', 'ecx', 'edx']};
  219. function FileCreate (const FileName: string): longint; assembler;
  220. asm
  221. push ebx
  222. mov eax, 7F2Bh
  223. mov ecx, ofReadWrite or faCreate or doDenyRW (* Sharing to DenyAll *)
  224. mov edx, FileName
  225. call syscall
  226. pop ebx
  227. end {['eax', 'ebx', 'ecx', 'edx']};
  228. function FileCreate (const FileName: string; Mode: longint): longint;
  229. begin
  230. FileCreate := FileCreate(FileName);
  231. end;
  232. function FileRead (Handle: longint; var Buffer; Count: longint): longint;
  233. assembler;
  234. asm
  235. push ebx
  236. mov eax, 3F00h
  237. mov ebx, Handle
  238. mov ecx, Count
  239. mov edx, Buffer
  240. call syscall
  241. jnc @FReadEnd
  242. mov eax, -1
  243. @FReadEnd:
  244. pop ebx
  245. end {['eax', 'ebx', 'ecx', 'edx']};
  246. function FileWrite (Handle: longint; const Buffer; Count: longint): longint;
  247. assembler;
  248. asm
  249. push ebx
  250. mov eax, 4000h
  251. mov ebx, Handle
  252. mov ecx, Count
  253. mov edx, Buffer
  254. call syscall
  255. jnc @FWriteEnd
  256. mov eax, -1
  257. @FWriteEnd:
  258. pop ebx
  259. end {['eax', 'ebx', 'ecx', 'edx']};
  260. function FileSeek (Handle, FOffset, Origin: longint): longint; assembler;
  261. asm
  262. push ebx
  263. mov eax, Origin
  264. mov ah, 42h
  265. mov ebx, Handle
  266. mov edx, FOffset
  267. call syscall
  268. jnc @FSeekEnd
  269. mov eax, -1
  270. @FSeekEnd:
  271. pop ebx
  272. end {['eax', 'ebx', 'edx']};
  273. function FileSeek (Handle: longint; FOffset, Origin: Int64): Int64;
  274. begin
  275. {$warning need to add 64bit call }
  276. Result:=FileSeek(Handle,Longint(Foffset),Longint(Origin));
  277. end;
  278. procedure FileClose (Handle: longint); assembler;
  279. asm
  280. push ebx
  281. mov eax, Handle
  282. cmp eax, 2
  283. jbe @FCloseEnd
  284. mov ebx, eax
  285. mov eax, 3E00h
  286. call syscall
  287. @FCloseEnd:
  288. pop ebx
  289. end {['eax', 'ebx']};
  290. function FileTruncate (Handle, Size: longint): boolean; assembler;
  291. asm
  292. push ebx
  293. mov eax, 7F25h
  294. mov ebx, Handle
  295. mov edx, Size
  296. call syscall
  297. jc @FTruncEnd
  298. mov eax, 4202h
  299. mov ebx, Handle
  300. mov edx, 0
  301. call syscall
  302. mov eax, 0
  303. jnc @FTruncEnd
  304. dec eax
  305. @FTruncEnd:
  306. pop ebx
  307. end {['eax', 'ebx', 'ecx', 'edx']};
  308. function FileAge (const FileName: string): longint;
  309. var Handle: longint;
  310. begin
  311. Handle := FileOpen (FileName, 0);
  312. if Handle <> -1 then
  313. begin
  314. Result := FileGetDate (Handle);
  315. FileClose (Handle);
  316. end
  317. else
  318. Result := -1;
  319. end;
  320. function FileExists (const FileName: string): boolean;
  321. var
  322. SR: TSearchRec;
  323. begin
  324. FileExists:=False;
  325. if FindFirst(FileName, faAnyFile, SR)=0 then FileExists:=True;
  326. FindClose(SR);
  327. end;
  328. type TRec = record
  329. T, D: word;
  330. end;
  331. PSearchRec = ^SearchRec;
  332. function FindFirst (const Path: string; Attr: longint; var Rslt: TSearchRec): longint;
  333. var SR: PSearchRec;
  334. FStat: PFileFindBuf3;
  335. Count: cardinal;
  336. Err: cardinal;
  337. begin
  338. New (FStat);
  339. Rslt.FindHandle := $FFFFFFFF;
  340. Count := 1;
  341. Err := DosFindFirst (PChar (Path), Rslt.FindHandle,
  342. Attr and FindResvdMask, FStat, SizeOf (FStat^), Count,
  343. ilStandard);
  344. if (Err = 0) and (Count = 0) then Err := 18;
  345. FindFirst := -Err;
  346. if Err = 0 then
  347. begin
  348. Rslt.Name := FStat^.Name;
  349. Rslt.Size := FStat^.FileSize;
  350. Rslt.Attr := FStat^.AttrFile;
  351. Rslt.ExcludeAttr := 0;
  352. TRec (Rslt.Time).T := FStat^.TimeLastWrite;
  353. TRec (Rslt.Time).D := FStat^.DateLastWrite;
  354. end;
  355. Dispose (FStat);
  356. end;
  357. function FindNext (var Rslt: TSearchRec): longint;
  358. var SR: PSearchRec;
  359. FStat: PFileFindBuf3;
  360. Count: cardinal;
  361. Err: cardinal;
  362. begin
  363. New (FStat);
  364. Count := 1;
  365. Err := DosFindNext (Rslt.FindHandle, FStat, SizeOf (FStat^),
  366. Count);
  367. if (Err = 0) and (Count = 0) then Err := 18;
  368. FindNext := -Err;
  369. if Err = 0 then
  370. begin
  371. Rslt.Name := FStat^.Name;
  372. Rslt.Size := FStat^.FileSize;
  373. Rslt.Attr := FStat^.AttrFile;
  374. Rslt.ExcludeAttr := 0;
  375. TRec (Rslt.Time).T := FStat^.TimeLastWrite;
  376. TRec (Rslt.Time).D := FStat^.DateLastWrite;
  377. end;
  378. Dispose (FStat);
  379. end;
  380. procedure FindClose (var F: TSearchrec);
  381. var SR: PSearchRec;
  382. begin
  383. DosFindClose (F.FindHandle);
  384. F.FindHandle := 0;
  385. end;
  386. function FileGetDate (Handle: longint): longint; assembler;
  387. asm
  388. push ebx
  389. mov ax, 5700h
  390. mov ebx, Handle
  391. call syscall
  392. mov eax, -1
  393. jc @FGetDateEnd
  394. mov ax, dx
  395. shld eax, ecx, 16
  396. @FGetDateEnd:
  397. pop ebx
  398. end {['eax', 'ebx', 'ecx', 'edx']};
  399. function FileSetDate (Handle, Age: longint): longint;
  400. var FStat: PFileStatus0;
  401. RC: cardinal;
  402. begin
  403. New (FStat);
  404. RC := DosQueryFileInfo (Handle, ilStandard, FStat,
  405. SizeOf (FStat^));
  406. if RC <> 0 then
  407. FileSetDate := -1
  408. else
  409. begin
  410. FStat^.DateLastAccess := Hi (Age);
  411. FStat^.DateLastWrite := Hi (Age);
  412. FStat^.TimeLastAccess := Lo (Age);
  413. FStat^.TimeLastWrite := Lo (Age);
  414. RC := DosSetFileInfo (Handle, ilStandard, FStat,
  415. SizeOf (FStat^));
  416. if RC <> 0 then
  417. FileSetDate := -1
  418. else
  419. FileSetDate := 0;
  420. end;
  421. Dispose (FStat);
  422. end;
  423. function FileGetAttr (const FileName: string): longint;
  424. var
  425. FS: PFileStatus3;
  426. S: PChar;
  427. begin
  428. New(FS);
  429. S:=StrAlloc(length(FileName)+1);
  430. StrPCopy(S, FileName);
  431. Result:=-DosQueryPathInfo(S, ilStandard, FS, SizeOf(FS^));
  432. StrDispose(S);
  433. If Result=0 Then Result:=FS^.attrFile;
  434. Dispose(FS);
  435. end;
  436. function FileSetAttr (const Filename: string; Attr: longint): longint;
  437. Var
  438. FS: PFileStatus3;
  439. S: PChar;
  440. Begin
  441. New(FS);
  442. FillChar(FS, SizeOf(FS^), 0);
  443. FS^.attrFile:=Attr;
  444. S:=StrAlloc(length(FileName)+1);
  445. StrPCopy(S, FileName);
  446. Result:=-DosSetPathInfo(S, ilStandard, FS, SizeOf(FS^), 0);
  447. StrDispose(S);
  448. Dispose(FS);
  449. end;
  450. function DeleteFile (const FileName: string): boolean;
  451. Var
  452. S: PChar;
  453. Begin
  454. S:=StrAlloc(length(FileName)+1);
  455. StrPCopy(S, FileName);
  456. Result:=(DosDelete(S)=0);
  457. StrDispose(S);
  458. End;
  459. function RenameFile (const OldName, NewName: string): boolean;
  460. Var
  461. S1, S2: PChar;
  462. Begin
  463. S1:=StrAlloc(length(OldName)+1);
  464. StrPCopy(S1, OldName);
  465. S2:=StrAlloc(length(NewName)+1);
  466. StrPCopy(S2, NewName);
  467. Result:=(DosMove(S1, S2)=0);
  468. StrDispose(S1);
  469. StrDispose(S2);
  470. End;
  471. {****************************************************************************
  472. Disk Functions
  473. ****************************************************************************}
  474. {$ASMMODE ATT}
  475. function DiskFree (Drive: byte): int64;
  476. var FI: TFSinfo;
  477. RC: cardinal;
  478. begin
  479. {In OS/2, we use the filesystem information.}
  480. RC := DosQueryFSInfo (Drive, 1, FI, SizeOf (FI));
  481. if RC = 0 then
  482. DiskFree := int64 (FI.Free_Clusters) *
  483. int64 (FI.Sectors_Per_Cluster) * int64 (FI.Bytes_Per_Sector)
  484. else
  485. DiskFree := -1;
  486. end;
  487. function DiskSize (Drive: byte): int64;
  488. var FI: TFSinfo;
  489. RC: cardinal;
  490. begin
  491. {In OS/2, we use the filesystem information.}
  492. RC := DosQueryFSinfo (Drive, 1, FI, SizeOf (FI));
  493. if RC = 0 then
  494. DiskSize := int64 (FI.Total_Clusters) *
  495. int64 (FI.Sectors_Per_Cluster) * int64 (FI.Bytes_Per_Sector)
  496. else
  497. DiskSize := -1;
  498. end;
  499. function GetCurrentDir: string;
  500. begin
  501. GetDir (0, Result);
  502. end;
  503. function SetCurrentDir (const NewDir: string): boolean;
  504. begin
  505. {$I-}
  506. ChDir (NewDir);
  507. Result := (IOResult = 0);
  508. {$I+}
  509. end;
  510. function CreateDir (const NewDir: string): boolean;
  511. begin
  512. {$I-}
  513. MkDir (NewDir);
  514. Result := (IOResult = 0);
  515. {$I+}
  516. end;
  517. function RemoveDir (const Dir: string): boolean;
  518. begin
  519. {$I-}
  520. RmDir (Dir);
  521. Result := (IOResult = 0);
  522. {$I+}
  523. end;
  524. {$ASMMODE INTEL}
  525. function DirectoryExists (const Directory: string): boolean; assembler;
  526. asm
  527. mov ax, 4300h
  528. mov edx, Directory
  529. call syscall
  530. mov eax, 0
  531. jc @FExistsEnd
  532. test cx, 10h
  533. jz @FExistsEnd
  534. inc eax
  535. @FExistsEnd:
  536. end {['eax', 'ecx', 'edx']};
  537. {****************************************************************************
  538. Time Functions
  539. ****************************************************************************}
  540. procedure GetLocalTime (var SystemTime: TSystemTime); assembler;
  541. asm
  542. (* Expects the default record alignment (word)!!! *)
  543. push edi
  544. mov ah, 2Ah
  545. call syscall
  546. mov edi, SystemTime
  547. mov ax, cx
  548. stosw
  549. xor eax, eax
  550. mov al, 10
  551. mul dl
  552. shl eax, 16
  553. mov al, dh
  554. stosd
  555. push edi
  556. mov ah, 2Ch
  557. call syscall
  558. pop edi
  559. xor eax, eax
  560. mov al, cl
  561. shl eax, 16
  562. mov al, ch
  563. stosd
  564. mov al, dl
  565. shl eax, 16
  566. mov al, dh
  567. stosd
  568. pop edi
  569. end {['eax', 'ecx', 'edx', 'edi']};
  570. {$asmmode default}
  571. {****************************************************************************
  572. Misc Functions
  573. ****************************************************************************}
  574. procedure Beep;
  575. begin
  576. end;
  577. {****************************************************************************
  578. Locale Functions
  579. ****************************************************************************}
  580. procedure InitAnsi;
  581. var I: byte;
  582. Country: TCountryCode;
  583. begin
  584. for I := 0 to 255 do
  585. UpperCaseTable [I] := Chr (I);
  586. Move (UpperCaseTable, LowerCaseTable, SizeOf (UpperCaseTable));
  587. FillChar (Country, SizeOf (Country), 0);
  588. DosMapCase (SizeOf (UpperCaseTable), Country, @UpperCaseTable);
  589. for I := 0 to 255 do
  590. if UpperCaseTable [I] <> Chr (I) then
  591. LowerCaseTable [Ord (UpperCaseTable [I])] := Chr (I);
  592. end;
  593. procedure InitInternational;
  594. var Country: TCountryCode;
  595. CtryInfo: TCountryInfo;
  596. Size: cardinal;
  597. RC: cardinal;
  598. begin
  599. Size := 0;
  600. FillChar (Country, SizeOf (Country), 0);
  601. FillChar (CtryInfo, SizeOf (CtryInfo), 0);
  602. RC := DosQueryCtryInfo (SizeOf (CtryInfo), Country, CtryInfo, Size);
  603. if RC = 0 then
  604. begin
  605. DateSeparator := CtryInfo.DateSeparator;
  606. case CtryInfo.DateFormat of
  607. 1: begin
  608. ShortDateFormat := 'd/m/y';
  609. LongDateFormat := 'dd" "mmmm" "yyyy';
  610. end;
  611. 2: begin
  612. ShortDateFormat := 'y/m/d';
  613. LongDateFormat := 'yyyy" "mmmm" "dd';
  614. end;
  615. 3: begin
  616. ShortDateFormat := 'm/d/y';
  617. LongDateFormat := 'mmmm" "dd" "yyyy';
  618. end;
  619. end;
  620. TimeSeparator := CtryInfo.TimeSeparator;
  621. DecimalSeparator := CtryInfo.DecimalSeparator;
  622. ThousandSeparator := CtryInfo.ThousandSeparator;
  623. CurrencyFormat := CtryInfo.CurrencyFormat;
  624. CurrencyString := PChar (CtryInfo.CurrencyUnit);
  625. end;
  626. InitAnsi;
  627. end;
  628. function SysErrorMessage(ErrorCode: Integer): String;
  629. begin
  630. Result:=Format(SUnknownErrorCode,[ErrorCode]);
  631. end;
  632. {****************************************************************************
  633. OS Utils
  634. ****************************************************************************}
  635. Function GetEnvironmentVariable(Const EnvVar : String) : String;
  636. begin
  637. GetEnvironmentVariable := StrPas (GetEnvPChar (EnvVar));
  638. end;
  639. {****************************************************************************
  640. Initialization code
  641. ****************************************************************************}
  642. Initialization
  643. InitExceptions; { Initialize exceptions. OS independent }
  644. InitInternational; { Initialize internationalization settings }
  645. Finalization
  646. DoneExceptions;
  647. end.
  648. {
  649. $Log$
  650. Revision 1.35 2003-10-27 11:43:40 yuri
  651. * New set of native functions
  652. Revision 1.34 2003/10/18 16:58:39 hajny
  653. * stdcall fixes again
  654. Revision 1.33 2003/10/13 21:17:31 hajny
  655. * longint to cardinal corrections
  656. Revision 1.32 2003/10/08 05:22:47 yuri
  657. * Some emx code removed
  658. Revision 1.31 2003/10/07 21:26:34 hajny
  659. * stdcall fixes and asm routines cleanup
  660. Revision 1.30 2003/10/03 21:46:41 peter
  661. * stdcall fixes
  662. Revision 1.29 2003/06/06 23:34:40 hajny
  663. * better fix for bug 2518
  664. Revision 1.28 2003/06/06 23:31:17 hajny
  665. * fix for bug 2518 applied to OS/2 as well
  666. Revision 1.27 2003/04/01 15:57:41 peter
  667. * made THandle platform dependent and unique type
  668. Revision 1.26 2003/03/31 02:18:39 yuri
  669. FileClose bug fixed (again ;))
  670. Revision 1.25 2003/03/29 19:14:16 yuri
  671. * Directoryexists function header changed back.
  672. Revision 1.24 2003/03/29 18:53:10 yuri
  673. * Fixed DirectoryExists function header
  674. Revision 1.23 2003/03/29 15:01:20 hajny
  675. + DirectoryExists added for main branch OS/2 too
  676. Revision 1.22 2003/03/01 21:19:14 hajny
  677. * FileClose bug fixed
  678. Revision 1.21 2003/01/04 16:25:08 hajny
  679. * modified to make use of the common GetEnv code
  680. Revision 1.20 2003/01/03 20:41:04 peter
  681. * FileCreate(string,mode) overload added
  682. Revision 1.19 2002/11/18 19:51:00 hajny
  683. * another bunch of type corrections
  684. Revision 1.18 2002/09/23 17:42:37 hajny
  685. * AnsiString to PChar typecast
  686. Revision 1.17 2002/09/07 16:01:25 peter
  687. * old logs removed and tabs fixed
  688. Revision 1.16 2002/07/11 16:00:05 hajny
  689. * FindFirst fix (invalid attribute bits masked out)
  690. Revision 1.15 2002/01/25 16:23:03 peter
  691. * merged filesearch() fix
  692. }