sysutils.pp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  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. SystemFileName: RawByteString;
  255. begin
  256. validFile:=false;
  257. SystemFileName := PathConv(ToSingleByteFileSystemEncodedFileName(FileName));
  258. tmpLock := Lock(PChar(SystemFileName), SHARED_LOCK);
  259. if (tmpLock <> 0) then begin
  260. new(tmpFIB);
  261. if Examine(tmpLock,tmpFIB) then begin
  262. tmpDateTime:=AmigaFileDateToDateTime(tmpFIB^.fib_Date,validFile);
  263. end;
  264. Unlock(tmpLock);
  265. dispose(tmpFIB);
  266. end;
  267. if validFile then
  268. result:=DateTimeToFileDate(tmpDateTime)
  269. else
  270. result:=-1;
  271. end;
  272. function FileExists (const FileName : RawByteString) : Boolean;
  273. var
  274. tmpLock: LongInt;
  275. tmpFIB : PFileInfoBlock;
  276. SystemFileName: RawByteString;
  277. begin
  278. result:=false;
  279. SystemFileName := PathConv(ToSingleByteFileSystemEncodedFileName(FileName));
  280. tmpLock := Lock(PChar(SystemFileName), SHARED_LOCK);
  281. if (tmpLock <> 0) then begin
  282. new(tmpFIB);
  283. if Examine(tmpLock,tmpFIB) and (tmpFIB^.fib_DirEntryType <= 0) then
  284. result:=true;
  285. Unlock(tmpLock);
  286. dispose(tmpFIB);
  287. end;
  288. end;
  289. Function InternalFindFirst (Const Path : RawByteString; Attr : Longint; out Rslt : TAbstractSearchRec; var Name: RawByteString) : Longint;
  290. var
  291. tmpStr: RawByteString;
  292. Anchor: PAnchorPath;
  293. tmpDateTime: TDateTime;
  294. validDate: boolean;
  295. begin
  296. result:=-1; { We emulate Linux/Unix behaviour, and return -1 on errors. }
  297. { Initialize out Rslt, this is a *MUST*, because of caller side magic in objpas/sysutils/filutil.inc }
  298. fillchar(Rslt,sizeof(Rslt),0);
  299. tmpStr:=PathConv(ToSingleByteFileSystemEncodedFileName(Path));
  300. { $1e = faHidden or faSysFile or faVolumeID or faDirectory }
  301. Rslt.ExcludeAttr := (not Attr) and ($1e);
  302. Rslt.FindHandle := 0;
  303. new(Anchor);
  304. FillChar(Anchor^,sizeof(TAnchorPath),#0);
  305. if MatchFirst(pchar(tmpStr),Anchor)<>0 then exit;
  306. Rslt.FindHandle := longint(Anchor);
  307. with Anchor^.ap_Info do begin
  308. Name := fib_FileName;
  309. SetCodePage(Name,DefaultFileSystemCodePage,False);
  310. Rslt.Size := fib_Size;
  311. Rslt.Time := DateTimeToFileDate(AmigaFileDateToDateTime(fib_Date,validDate));
  312. if not validDate then exit;
  313. { "128" is Windows "NORMALFILE" attribute. Some buggy code depend on this... :( (KB) }
  314. Rslt.Attr := 128;
  315. if fib_DirEntryType > 0 then Rslt.Attr:=Rslt.Attr or faDirectory;
  316. if ((fib_Protection and FIBF_READ) <> 0) and
  317. ((fib_Protection and FIBF_WRITE) = 0) then Rslt.Attr:=Rslt.Attr or faReadOnly;
  318. result:=0; { Return zero if everything went OK }
  319. end;
  320. end;
  321. Function InternalFindNext (var Rslt : TAbstractSearchRec; var Name : RawByteString) : Longint;
  322. var
  323. Anchor: PAnchorPath;
  324. validDate: boolean;
  325. begin
  326. result:=-1;
  327. Anchor:=PAnchorPath(Rslt.FindHandle);
  328. if not assigned(Anchor) then exit;
  329. if MatchNext(Anchor) <> 0 then exit;
  330. with Anchor^.ap_Info do begin
  331. Name := fib_FileName;
  332. SetCodePage(Name,DefaultFileSystemCodePage,False);
  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 InternalFindClose(var Handle: THandle);
  345. var
  346. Anchor: PAnchorPath;
  347. begin
  348. Anchor:=PAnchorPath(Handle);
  349. if not assigned(Anchor) then exit;
  350. MatchEnd(Anchor);
  351. Dispose(Anchor);
  352. Handle:=THandle(nil);
  353. end;
  354. (****** end of non portable routines ******)
  355. Function FileGetAttr (Const FileName : RawByteString) : Longint;
  356. var
  357. F: file;
  358. attr: word;
  359. begin
  360. Assign(F,FileName);
  361. dos.GetFAttr(F,attr);
  362. if DosError <> 0 then
  363. FileGetAttr := -1
  364. else
  365. FileGetAttr := Attr;
  366. end;
  367. Function FileSetAttr (Const Filename : RawByteString; Attr: longint) : Longint;
  368. var
  369. F: file;
  370. begin
  371. Assign(F, FileName);
  372. Dos.SetFAttr(F, Attr and $ffff);
  373. FileSetAttr := DosError;
  374. end;
  375. {****************************************************************************
  376. Disk Functions
  377. ****************************************************************************}
  378. {
  379. The Diskfree and Disksize functions need a file on the specified drive, since this
  380. is required for the statfs system call.
  381. These filenames are set in drivestr[0..26], and have been preset to :
  382. 0 - '.' (default drive - hence current dir is ok.)
  383. 1 - '/fd0/.' (floppy drive 1 - should be adapted to local system )
  384. 2 - '/fd1/.' (floppy drive 2 - should be adapted to local system )
  385. 3 - '/' (C: equivalent of dos is the root partition)
  386. 4..26 (can be set by you're own applications)
  387. ! Use AddDisk() to Add new drives !
  388. They both return -1 when a failure occurs.
  389. }
  390. Const
  391. FixDriveStr : array[0..3] of pchar=(
  392. '.',
  393. '/fd0/.',
  394. '/fd1/.',
  395. '/.'
  396. );
  397. var
  398. Drives : byte;
  399. DriveStr : array[4..26] of pchar;
  400. Procedure AddDisk(const path:string);
  401. begin
  402. if not (DriveStr[Drives]=nil) then
  403. FreeMem(DriveStr[Drives],StrLen(DriveStr[Drives])+1);
  404. GetMem(DriveStr[Drives],length(Path)+1);
  405. StrPCopy(DriveStr[Drives],path);
  406. inc(Drives);
  407. if Drives>26 then
  408. Drives:=4;
  409. end;
  410. Function DiskFree(Drive: Byte): int64;
  411. Begin
  412. DiskFree := dos.diskFree(Drive);
  413. End;
  414. Function DiskSize(Drive: Byte): int64;
  415. Begin
  416. DiskSize := dos.DiskSize(Drive);
  417. End;
  418. function DirectoryExists(const Directory: RawByteString): Boolean;
  419. var
  420. tmpLock: LongInt;
  421. FIB : PFileInfoBlock;
  422. SystemDirName: RawByteString;
  423. begin
  424. result:=false;
  425. if (Directory='') or (InOutRes<>0) then exit;
  426. SystemDirName:=PathConv(ToSingleByteFileSystemEncodedFileName(Directory));
  427. tmpLock:=Lock(PChar(SystemDirName),SHARED_LOCK);
  428. if tmpLock=0 then exit;
  429. FIB:=nil; new(FIB);
  430. if (Examine(tmpLock,FIB)=True) and (FIB^.fib_DirEntryType>0) then
  431. result:=True;
  432. if tmpLock<>0 then Unlock(tmpLock);
  433. if assigned(FIB) then dispose(FIB);
  434. end;
  435. {****************************************************************************
  436. Locale Functions
  437. ****************************************************************************}
  438. Procedure GetLocalTime(var SystemTime: TSystemTime);
  439. var
  440. dayOfWeek: word;
  441. begin
  442. dos.GetTime(SystemTime.Hour, SystemTime.Minute, SystemTime.Second,SystemTime.Millisecond);
  443. dos.GetDate(SystemTime.Year, SystemTime.Month, SystemTime.Day, DayOfWeek);
  444. end;
  445. Procedure InitAnsi;
  446. Var
  447. i : longint;
  448. begin
  449. { Fill table entries 0 to 127 }
  450. for i := 0 to 96 do
  451. UpperCaseTable[i] := chr(i);
  452. for i := 97 to 122 do
  453. UpperCaseTable[i] := chr(i - 32);
  454. for i := 123 to 191 do
  455. UpperCaseTable[i] := chr(i);
  456. Move (CPISO88591UCT,UpperCaseTable[192],SizeOf(CPISO88591UCT));
  457. for i := 0 to 64 do
  458. LowerCaseTable[i] := chr(i);
  459. for i := 65 to 90 do
  460. LowerCaseTable[i] := chr(i + 32);
  461. for i := 91 to 191 do
  462. LowerCaseTable[i] := chr(i);
  463. Move (CPISO88591LCT,UpperCaseTable[192],SizeOf(CPISO88591UCT));
  464. end;
  465. Procedure InitInternational;
  466. begin
  467. InitInternationalGeneric;
  468. InitAnsi;
  469. end;
  470. function SysErrorMessage(ErrorCode: Integer): String;
  471. begin
  472. { Result:=StrError(ErrorCode);}
  473. end;
  474. function GetLastOSError: Integer;
  475. begin
  476. result:=-1;
  477. end;
  478. {****************************************************************************
  479. OS utility functions
  480. ****************************************************************************}
  481. Function GetEnvironmentVariable(Const EnvVar : String) : String;
  482. begin
  483. Result:=Dos.Getenv(shortstring(EnvVar));
  484. end;
  485. Function GetEnvironmentVariableCount : Integer;
  486. begin
  487. // Result:=FPCCountEnvVar(EnvP);
  488. Result:=Dos.envCount;
  489. end;
  490. Function GetEnvironmentString(Index : Integer) : {$ifdef FPC_RTL_UNICODE}UnicodeString{$else}AnsiString{$endif};
  491. begin
  492. // Result:=FPCGetEnvStrFromP(Envp,Index);
  493. Result:=Dos.EnvStr(Index);
  494. end;
  495. function ExecuteProcess (const Path: AnsiString; const ComLine: AnsiString;Flags:TExecuteFlags=[]):
  496. integer;
  497. var
  498. tmpPath: AnsiString;
  499. convPath: AnsiString;
  500. CommandLine: AnsiString;
  501. tmpLock: longint;
  502. E: EOSError;
  503. begin
  504. DosError:= 0;
  505. convPath:=PathConv(Path);
  506. tmpPath:=convPath+' '+ComLine;
  507. { Here we must first check if the command we wish to execute }
  508. { actually exists, because this is NOT handled by the }
  509. { _SystemTagList call (program will abort!!) }
  510. { Try to open with shared lock }
  511. tmpLock:=Lock(PChar(convPath),SHARED_LOCK);
  512. if tmpLock<>0 then
  513. begin
  514. { File exists - therefore unlock it }
  515. Unlock(tmpLock);
  516. result:=SystemTagList(PChar(tmpPath),nil);
  517. { on return of -1 the shell could not be executed }
  518. { probably because there was not enough memory }
  519. if result = -1 then
  520. DosError:=8;
  521. end
  522. else
  523. DosError:=3;
  524. if DosError <> 0 then begin
  525. if ComLine = '' then
  526. CommandLine := Path
  527. else
  528. CommandLine := Path + ' ' + ComLine;
  529. E := EOSError.CreateFmt (SExecuteProcessFailed, [CommandLine, DosError]);
  530. E.ErrorCode := DosError;
  531. raise E;
  532. end;
  533. end;
  534. function ExecuteProcess (const Path: AnsiString;
  535. const ComLine: array of AnsiString;Flags:TExecuteFlags=[]): integer;
  536. var
  537. CommandLine: AnsiString;
  538. I: integer;
  539. begin
  540. Commandline := '';
  541. for I := 0 to High (ComLine) do
  542. if Pos (' ', ComLine [I]) <> 0 then
  543. CommandLine := CommandLine + ' ' + '"' + ComLine [I] + '"'
  544. else
  545. CommandLine := CommandLine + ' ' + Comline [I];
  546. ExecuteProcess := ExecuteProcess (Path, CommandLine);
  547. end;
  548. procedure Sleep (Milliseconds: cardinal);
  549. begin
  550. // Amiga/MorphOS dos.library Delay() has precision of 1/50 seconds
  551. Delay(Milliseconds div 20);
  552. end;
  553. {****************************************************************************
  554. Initialization code
  555. ****************************************************************************}
  556. Initialization
  557. InitExceptions;
  558. InitInternational; { Initialize internationalization settings }
  559. OnBeep:=Nil; { No SysBeep() on MorphOS, for now. Figure out if we want
  560. to use intuition.library/DisplayBeep() for this (KB) }
  561. Finalization
  562. DoneExceptions;
  563. end.