sysutils.pp 18 KB

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