2
0

sysutils.pp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2004-2006 by Karoly Balogh
  4. Sysutils unit for MorphOS
  5. Based on Amiga version by Carl Eric Codere, and other
  6. parts of the RTL
  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. {$MODESWITCH OUT}
  17. { force ansistrings }
  18. {$H+}
  19. {$DEFINE OS_FILESETDATEBYNAME}
  20. {$DEFINE HAS_SLEEP}
  21. {$DEFINE HAS_OSERROR}
  22. { Include platform independent interface part }
  23. {$i sysutilh.inc}
  24. { Platform dependent calls }
  25. Procedure AddDisk(const path:string);
  26. implementation
  27. uses dos,sysconst;
  28. {$DEFINE FPC_FEXPAND_VOLUMES} (* Full paths begin with drive specification *)
  29. {$DEFINE FPC_FEXPAND_DRIVESEP_IS_ROOT}
  30. {$DEFINE FPC_FEXPAND_NO_DEFAULT_PATHS}
  31. { used OS file system APIs use ansistring }
  32. {$define SYSUTILS_HAS_ANSISTR_FILEUTIL_IMPL}
  33. { Include platform independent implementation part }
  34. {$i sysutils.inc}
  35. { * Include MorphOS specific includes * }
  36. {$include execd.inc}
  37. {$include execf.inc}
  38. {$include timerd.inc}
  39. {$include doslibd.inc}
  40. {$include doslibf.inc}
  41. {$include utilf.inc}
  42. { * Followings are implemented in the system unit! * }
  43. function PathConv(path: shortstring): shortstring; external name 'PATHCONV';
  44. function PathConv(path: RawByteString): shortstring; external name 'PATHCONVRBS';
  45. procedure AddToList(var l: Pointer; h: LongInt); external name 'ADDTOLIST';
  46. function RemoveFromList(var l: Pointer; h: LongInt): boolean; external name 'REMOVEFROMLIST';
  47. function CheckInList(var l: Pointer; h: LongInt): pointer; external name 'CHECKINLIST';
  48. var
  49. MOS_fileList: Pointer; external name 'MOS_FILELIST';
  50. function dosLock(const name: String;
  51. accessmode: Longint) : LongInt;
  52. var
  53. buffer: array[0..255] of Char;
  54. begin
  55. move(name[1],buffer,length(name));
  56. buffer[length(name)]:=#0;
  57. dosLock:=Lock(buffer,accessmode);
  58. end;
  59. function AmigaFileDateToDateTime(aDate: TDateStamp; out success: boolean): TDateTime;
  60. var
  61. tmpSecs: DWord;
  62. tmpDate: TDateTime;
  63. tmpTime: TDateTime;
  64. clockData: TClockData;
  65. begin
  66. with aDate do
  67. tmpSecs:=(ds_Days * (24 * 60 * 60)) + (ds_Minute * 60) + (ds_Tick div TICKS_PER_SECOND);
  68. Amiga2Date(tmpSecs,@clockData);
  69. {$HINT TODO: implement msec values, if possible}
  70. with clockData do begin
  71. success:=TryEncodeDate(year,month,mday,tmpDate) and
  72. TryEncodeTime(hour,min,sec,0,tmpTime);
  73. end;
  74. result:=ComposeDateTime(tmpDate,tmpTime);
  75. end;
  76. function DateTimeToAmigaDateStamp(dateTime: TDateTime): TDateStamp;
  77. var
  78. tmpSecs: DWord;
  79. clockData: TClockData;
  80. tmpMSec: Word;
  81. begin
  82. {$HINT TODO: implement msec values, if possible}
  83. with clockData do begin
  84. DecodeDate(dateTime,year,month,mday);
  85. DecodeTime(dateTime,hour,min,sec,tmpMSec);
  86. end;
  87. tmpSecs:=Date2Amiga(@clockData);
  88. with result do begin
  89. ds_Days:= tmpSecs div (24 * 60 * 60);
  90. ds_Minute:= (tmpSecs div 60) mod ds_Days;
  91. ds_Tick:= (((tmpSecs mod 60) mod ds_Minute) mod ds_Days) * TICKS_PER_SECOND;
  92. end;
  93. end;
  94. {****************************************************************************
  95. File Functions
  96. ****************************************************************************}
  97. {$I-}{ Required for correct usage of these routines }
  98. (****** non portable routines ******)
  99. function FileOpen(const FileName: rawbytestring; Mode: Integer): LongInt;
  100. var
  101. SystemFileName: RawByteString;
  102. dosResult: LongInt;
  103. begin
  104. SystemFileName:=PathConv(ToSingleByteFileSystemEncodedFileName(FileName));
  105. {$WARNING FIX ME! To do: FileOpen Access Modes}
  106. dosResult:=Open(PChar(SystemFileName),MODE_OLDFILE);
  107. if dosResult=0 then
  108. dosResult:=-1
  109. else
  110. AddToList(MOS_fileList,dosResult);
  111. FileOpen:=dosResult;
  112. end;
  113. function FileGetDate(Handle: LongInt) : LongInt;
  114. var
  115. tmpFIB : PFileInfoBlock;
  116. tmpDateTime: TDateTime;
  117. validFile: boolean;
  118. begin
  119. validFile:=false;
  120. if (Handle <> 0) then begin
  121. new(tmpFIB);
  122. if ExamineFH(Handle,tmpFIB) then begin
  123. tmpDateTime:=AmigaFileDateToDateTime(tmpFIB^.fib_Date,validFile);
  124. end;
  125. dispose(tmpFIB);
  126. end;
  127. if validFile then
  128. result:=DateTimeToFileDate(tmpDateTime)
  129. else
  130. result:=-1;
  131. end;
  132. function FileSetDate(Handle, Age: LongInt) : LongInt;
  133. var
  134. tmpDateStamp: TDateStamp;
  135. tmpName: array[0..255] of char;
  136. begin
  137. result:=0;
  138. if (Handle <> 0) then begin
  139. if (NameFromFH(Handle, @tmpName, 256) = dosTrue) then begin
  140. tmpDateStamp:=DateTimeToAmigaDateStamp(FileDateToDateTime(Age));
  141. if not SetFileDate(@tmpName,@tmpDateStamp) then begin
  142. IoErr(); // dump the error code for now (TODO)
  143. result:=-1;
  144. end;
  145. end;
  146. end;
  147. end;
  148. function FileSetDate(const FileName: RawByteString; Age: LongInt) : LongInt;
  149. var
  150. tmpDateStamp: TDateStamp;
  151. SystemFileName: RawByteString;
  152. begin
  153. result:=0;
  154. SystemFileName:=PathConv(ToSingleByteFileSystemEncodedFileName(FileName));
  155. tmpDateStamp:=DateTimeToAmigaDateStamp(FileDateToDateTime(Age));
  156. if not SetFileDate(PChar(SystemFileName),@tmpDateStamp) then begin
  157. IoErr(); // dump the error code for now (TODO)
  158. result:=-1;
  159. end;
  160. end;
  161. function FileCreate(const FileName: RawByteString) : LongInt;
  162. var
  163. SystemFileName: RawByteString;
  164. dosResult: LongInt;
  165. begin
  166. dosResult:=-1;
  167. { Open file in MODDE_READWRITE, then truncate it by hand rather than
  168. opening it in MODE_NEWFILE, because that returns an exclusive lock
  169. so some operations might fail with it (KB) }
  170. SystemFileName:=PathConv(ToSingleByteFileSystemEncodedFileName(FileName));
  171. dosResult:=Open(PChar(SystemFileName),MODE_READWRITE);
  172. if dosResult = 0 then exit;
  173. if SetFileSize(dosResult, 0, OFFSET_BEGINNING) = 0 then
  174. AddToList(MOS_fileList,dosResult)
  175. else begin
  176. dosClose(dosResult);
  177. dosResult:=-1;
  178. end;
  179. FileCreate:=dosResult;
  180. end;
  181. function FileCreate(const FileName: RawByteString; Rights: integer): LongInt;
  182. begin
  183. {$WARNING FIX ME! To do: FileCreate Access Modes}
  184. FileCreate:=FileCreate(FileName);
  185. end;
  186. function FileCreate(const FileName: RawByteString; ShareMode: integer; Rights : integer): LongInt;
  187. begin
  188. {$WARNING FIX ME! To do: FileCreate Access Modes}
  189. FileCreate:=FileCreate(FileName);
  190. end;
  191. function FileRead(Handle: LongInt; out Buffer; Count: LongInt): LongInt;
  192. begin
  193. FileRead:=-1;
  194. if (Count<=0) or (Handle<=0) then exit;
  195. FileRead:=dosRead(Handle,@Buffer,Count);
  196. end;
  197. function FileWrite(Handle: LongInt; const Buffer; Count: LongInt): LongInt;
  198. begin
  199. FileWrite:=-1;
  200. if (Count<=0) or (Handle<=0) then exit;
  201. FileWrite:=dosWrite(Handle,@Buffer,Count);
  202. end;
  203. function FileSeek(Handle, FOffset, Origin: LongInt) : LongInt;
  204. var
  205. seekMode: LongInt;
  206. begin
  207. FileSeek:=-1;
  208. if (Handle<=0) then exit;
  209. case Origin of
  210. fsFromBeginning: seekMode:=OFFSET_BEGINNING;
  211. fsFromCurrent : seekMode:=OFFSET_CURRENT;
  212. fsFromEnd : seekMode:=OFFSET_END;
  213. end;
  214. FileSeek:=dosSeek(Handle, FOffset, seekMode);
  215. end;
  216. function FileSeek(Handle: LongInt; FOffset: Int64; Origin: Longint): Int64;
  217. begin
  218. {$WARNING Need to add 64bit call }
  219. FileSeek:=FileSeek(Handle,LongInt(FOffset),LongInt(Origin));
  220. end;
  221. procedure FileClose(Handle: LongInt);
  222. begin
  223. if (Handle<=0) then exit;
  224. dosClose(Handle);
  225. RemoveFromList(MOS_fileList,Handle);
  226. end;
  227. function FileTruncate(Handle: THandle; Size: Int64): Boolean;
  228. var
  229. dosResult: LongInt;
  230. begin
  231. FileTruncate:=False;
  232. if Size > high (longint) then exit;
  233. {$WARNING Possible support for 64-bit FS to be checked!}
  234. if (Handle<=0) then exit;
  235. dosResult:=SetFileSize(Handle, Size, OFFSET_BEGINNING);
  236. if (dosResult<0) then exit;
  237. FileTruncate:=True;
  238. end;
  239. function DeleteFile(const FileName: RawByteString) : Boolean;
  240. var
  241. SystemFileName: RawByteString;
  242. begin
  243. SystemFileName:=PathConv(ToSingleByteFileSystemEncodedFileName(FileName));
  244. DeleteFile:=dosDeleteFile(PChar(SystemFileName));
  245. end;
  246. function RenameFile(const OldName, NewName: RawByteString): Boolean;
  247. var
  248. OldSystemFileName, NewSystemFileName: RawByteString;
  249. begin
  250. OldSystemFileName:=PathConv(ToSingleByteFileSystemEncodedFileName(OldName));
  251. NewSystemFileName:=PathConv(ToSingleByteFileSystemEncodedFileName(NewName));
  252. RenameFile:=dosRename(PChar(OldSystemFileName), PChar(NewSystemFileName));
  253. end;
  254. (****** end of non portable routines ******)
  255. function FileAge (const FileName : String): Longint;
  256. var
  257. tmpName: String;
  258. tmpLock: Longint;
  259. tmpFIB : PFileInfoBlock;
  260. tmpDateTime: TDateTime;
  261. validFile: boolean;
  262. begin
  263. validFile:=false;
  264. tmpName := PathConv(FileName);
  265. tmpLock := dosLock(tmpName, SHARED_LOCK);
  266. if (tmpLock <> 0) then begin
  267. new(tmpFIB);
  268. if Examine(tmpLock,tmpFIB) then begin
  269. tmpDateTime:=AmigaFileDateToDateTime(tmpFIB^.fib_Date,validFile);
  270. end;
  271. Unlock(tmpLock);
  272. dispose(tmpFIB);
  273. end;
  274. if validFile then
  275. result:=DateTimeToFileDate(tmpDateTime)
  276. else
  277. result:=-1;
  278. end;
  279. function FileExists (const FileName : RawByteString) : Boolean;
  280. var
  281. tmpLock: LongInt;
  282. tmpFIB : PFileInfoBlock;
  283. SystemFileName: RawByteString;
  284. begin
  285. result:=false;
  286. SystemFileName:=PathConv(ToSingleByteFileSystemEncodedFileName(FileName));
  287. tmpLock := dosLock(PChar(SystemFileName), SHARED_LOCK);
  288. if (tmpLock <> 0) then begin
  289. new(tmpFIB);
  290. if Examine(tmpLock,tmpFIB) and (tmpFIB^.fib_DirEntryType <= 0) then
  291. result:=true;
  292. Unlock(tmpLock);
  293. dispose(tmpFIB);
  294. end;
  295. end;
  296. function FindFirst(const Path: String; Attr : Longint; out Rslt: TSearchRec): Longint;
  297. var
  298. tmpStr: array[0..255] of Char;
  299. Anchor: PAnchorPath;
  300. tmpDateTime: TDateTime;
  301. validDate: boolean;
  302. begin
  303. result:=-1; { We emulate Linux/Unix behaviour, and return -1 on errors. }
  304. tmpStr:=PathConv(path)+#0;
  305. { $1e = faHidden or faSysFile or faVolumeID or faDirectory }
  306. Rslt.ExcludeAttr := (not Attr) and ($1e);
  307. Rslt.FindHandle := 0;
  308. new(Anchor);
  309. FillChar(Anchor^,sizeof(TAnchorPath),#0);
  310. if MatchFirst(@tmpStr,Anchor)<>0 then exit;
  311. Rslt.FindHandle := longint(Anchor);
  312. with Anchor^.ap_Info do begin
  313. Rslt.Name := StrPas(fib_FileName);
  314. Rslt.Size := fib_Size;
  315. Rslt.Time := DateTimeToFileDate(AmigaFileDateToDateTime(fib_Date,validDate));
  316. if not validDate then exit;
  317. { "128" is Windows "NORMALFILE" attribute. Some buggy code depend on this... :( (KB) }
  318. Rslt.Attr := 128;
  319. if fib_DirEntryType > 0 then Rslt.Attr:=Rslt.Attr or faDirectory;
  320. if ((fib_Protection and FIBF_READ) <> 0) and
  321. ((fib_Protection and FIBF_WRITE) = 0) then Rslt.Attr:=Rslt.Attr or faReadOnly;
  322. result:=0; { Return zero if everything went OK }
  323. end;
  324. end;
  325. function FindNext (var Rslt : TSearchRec): Longint;
  326. var
  327. Anchor: PAnchorPath;
  328. validDate: boolean;
  329. begin
  330. result:=-1;
  331. Anchor:=PAnchorPath(Rslt.FindHandle);
  332. if not assigned(Anchor) then exit;
  333. if MatchNext(Anchor) <> 0 then exit;
  334. with Anchor^.ap_Info do begin
  335. Rslt.Name := StrPas(fib_FileName);
  336. Rslt.Size := fib_Size;
  337. Rslt.Time := DateTimeToFileDate(AmigaFileDateToDateTime(fib_Date,validDate));
  338. if not validDate then exit;
  339. { "128" is Windows "NORMALFILE" attribute. Some buggy code depend on this... :( (KB) }
  340. Rslt.Attr := 128;
  341. if fib_DirEntryType > 0 then Rslt.Attr:=Rslt.Attr or faDirectory;
  342. if ((fib_Protection and FIBF_READ) <> 0) and
  343. ((fib_Protection and FIBF_WRITE) = 0) then Rslt.Attr:=Rslt.Attr or faReadOnly;
  344. result:=0; { Return zero if everything went OK }
  345. end;
  346. end;
  347. procedure FindClose(var f: TSearchRec);
  348. var
  349. Anchor: PAnchorPath;
  350. begin
  351. Anchor:=PAnchorPath(f.FindHandle);
  352. if not assigned(Anchor) then exit;
  353. MatchEnd(Anchor);
  354. Dispose(Anchor);
  355. end;
  356. (****** end of non portable routines ******)
  357. Function FileGetAttr (Const FileName : RawByteString) : Longint;
  358. var
  359. F: file;
  360. attr: word;
  361. begin
  362. Assign(F,FileName);
  363. dos.GetFAttr(F,attr);
  364. if DosError <> 0 then
  365. FileGetAttr := -1
  366. else
  367. FileGetAttr := Attr;
  368. end;
  369. Function FileSetAttr (Const Filename : RawByteString; Attr: longint) : Longint;
  370. var
  371. F: file;
  372. begin
  373. Assign(F, FileName);
  374. Dos.SetFAttr(F, Attr and $ffff);
  375. FileSetAttr := DosError;
  376. end;
  377. {****************************************************************************
  378. Disk Functions
  379. ****************************************************************************}
  380. {
  381. The Diskfree and Disksize functions need a file on the specified drive, since this
  382. is required for the statfs system call.
  383. These filenames are set in drivestr[0..26], and have been preset to :
  384. 0 - '.' (default drive - hence current dir is ok.)
  385. 1 - '/fd0/.' (floppy drive 1 - should be adapted to local system )
  386. 2 - '/fd1/.' (floppy drive 2 - should be adapted to local system )
  387. 3 - '/' (C: equivalent of dos is the root partition)
  388. 4..26 (can be set by you're own applications)
  389. ! Use AddDisk() to Add new drives !
  390. They both return -1 when a failure occurs.
  391. }
  392. Const
  393. FixDriveStr : array[0..3] of pchar=(
  394. '.',
  395. '/fd0/.',
  396. '/fd1/.',
  397. '/.'
  398. );
  399. var
  400. Drives : byte;
  401. DriveStr : array[4..26] of pchar;
  402. Procedure AddDisk(const path:string);
  403. begin
  404. if not (DriveStr[Drives]=nil) then
  405. FreeMem(DriveStr[Drives],StrLen(DriveStr[Drives])+1);
  406. GetMem(DriveStr[Drives],length(Path)+1);
  407. StrPCopy(DriveStr[Drives],path);
  408. inc(Drives);
  409. if Drives>26 then
  410. Drives:=4;
  411. end;
  412. Function DiskFree(Drive: Byte): int64;
  413. Begin
  414. DiskFree := dos.diskFree(Drive);
  415. End;
  416. Function DiskSize(Drive: Byte): int64;
  417. Begin
  418. DiskSize := dos.DiskSize(Drive);
  419. End;
  420. function DirectoryExists(const Directory: RawByteString): Boolean;
  421. var
  422. tmpLock: LongInt;
  423. FIB : PFileInfoBlock;
  424. SystemFileName: RawByteString;
  425. begin
  426. result:=false;
  427. if (Directory='') or (InOutRes<>0) then exit;
  428. SystemFileName:=PathConv(ToSingleByteFileSystemEncodedFileName(Directory));
  429. tmpLock:=dosLock(PChar(SystemFileName),SHARED_LOCK);
  430. if tmpLock=0 then exit;
  431. FIB:=nil; new(FIB);
  432. if (Examine(tmpLock,FIB)=True) and (FIB^.fib_DirEntryType>0) then
  433. result:=True;
  434. if tmpLock<>0 then Unlock(tmpLock);
  435. if assigned(FIB) then dispose(FIB);
  436. end;
  437. {****************************************************************************
  438. Locale Functions
  439. ****************************************************************************}
  440. Procedure GetLocalTime(var SystemTime: TSystemTime);
  441. var
  442. dayOfWeek: word;
  443. begin
  444. dos.GetTime(SystemTime.Hour, SystemTime.Minute, SystemTime.Second,SystemTime.Millisecond);
  445. dos.GetDate(SystemTime.Year, SystemTime.Month, SystemTime.Day, DayOfWeek);
  446. end;
  447. Procedure InitAnsi;
  448. Var
  449. i : longint;
  450. begin
  451. { Fill table entries 0 to 127 }
  452. for i := 0 to 96 do
  453. UpperCaseTable[i] := chr(i);
  454. for i := 97 to 122 do
  455. UpperCaseTable[i] := chr(i - 32);
  456. for i := 123 to 191 do
  457. UpperCaseTable[i] := chr(i);
  458. Move (CPISO88591UCT,UpperCaseTable[192],SizeOf(CPISO88591UCT));
  459. for i := 0 to 64 do
  460. LowerCaseTable[i] := chr(i);
  461. for i := 65 to 90 do
  462. LowerCaseTable[i] := chr(i + 32);
  463. for i := 91 to 191 do
  464. LowerCaseTable[i] := chr(i);
  465. Move (CPISO88591LCT,UpperCaseTable[192],SizeOf(CPISO88591UCT));
  466. end;
  467. Procedure InitInternational;
  468. begin
  469. InitInternationalGeneric;
  470. InitAnsi;
  471. end;
  472. function SysErrorMessage(ErrorCode: Integer): String;
  473. begin
  474. { Result:=StrError(ErrorCode);}
  475. end;
  476. function GetLastOSError: Integer;
  477. begin
  478. result:=-1;
  479. end;
  480. {****************************************************************************
  481. OS utility functions
  482. ****************************************************************************}
  483. Function GetEnvironmentVariable(Const EnvVar : String) : String;
  484. begin
  485. Result:=Dos.Getenv(shortstring(EnvVar));
  486. end;
  487. Function GetEnvironmentVariableCount : Integer;
  488. begin
  489. // Result:=FPCCountEnvVar(EnvP);
  490. Result:=Dos.envCount;
  491. end;
  492. Function GetEnvironmentString(Index : Integer) : String;
  493. begin
  494. // Result:=FPCGetEnvStrFromP(Envp,Index);
  495. Result:=Dos.EnvStr(Index);
  496. end;
  497. function ExecuteProcess (const Path: AnsiString; const ComLine: AnsiString;Flags:TExecuteFlags=[]):
  498. integer;
  499. var
  500. tmpPath: AnsiString;
  501. convPath: AnsiString;
  502. CommandLine: AnsiString;
  503. tmpLock: longint;
  504. E: EOSError;
  505. begin
  506. DosError:= 0;
  507. convPath:=PathConv(Path);
  508. tmpPath:=convPath+' '+ComLine;
  509. { Here we must first check if the command we wish to execute }
  510. { actually exists, because this is NOT handled by the }
  511. { _SystemTagList call (program will abort!!) }
  512. { Try to open with shared lock }
  513. tmpLock:=Lock(PChar(convPath),SHARED_LOCK);
  514. if tmpLock<>0 then
  515. begin
  516. { File exists - therefore unlock it }
  517. Unlock(tmpLock);
  518. result:=SystemTagList(PChar(tmpPath),nil);
  519. { on return of -1 the shell could not be executed }
  520. { probably because there was not enough memory }
  521. if result = -1 then
  522. DosError:=8;
  523. end
  524. else
  525. DosError:=3;
  526. if DosError <> 0 then begin
  527. if ComLine = '' then
  528. CommandLine := Path
  529. else
  530. CommandLine := Path + ' ' + ComLine;
  531. E := EOSError.CreateFmt (SExecuteProcessFailed, [CommandLine, DosError]);
  532. E.ErrorCode := DosError;
  533. raise E;
  534. end;
  535. end;
  536. function ExecuteProcess (const Path: AnsiString;
  537. const ComLine: array of AnsiString;Flags:TExecuteFlags=[]): integer;
  538. var
  539. CommandLine: AnsiString;
  540. I: integer;
  541. begin
  542. Commandline := '';
  543. for I := 0 to High (ComLine) do
  544. if Pos (' ', ComLine [I]) <> 0 then
  545. CommandLine := CommandLine + ' ' + '"' + ComLine [I] + '"'
  546. else
  547. CommandLine := CommandLine + ' ' + Comline [I];
  548. ExecuteProcess := ExecuteProcess (Path, CommandLine);
  549. end;
  550. procedure Sleep (Milliseconds: cardinal);
  551. begin
  552. // Amiga/MorphOS dos.library Delay() has precision of 1/50 seconds
  553. Delay(Milliseconds div 20);
  554. end;
  555. {****************************************************************************
  556. Initialization code
  557. ****************************************************************************}
  558. Initialization
  559. InitExceptions;
  560. InitInternational; { Initialize internationalization settings }
  561. OnBeep:=Nil; { No SysBeep() on MorphOS, for now. Figure out if we want
  562. to use intuition.library/DisplayBeep() for this (KB) }
  563. Finalization
  564. DoneExceptions;
  565. end.