sysutils.pp 18 KB

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