sysutils.pp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  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 GetCurrentDir : String;
  421. begin
  422. GetDir (0,Result);
  423. end;
  424. Function SetCurrentDir (Const NewDir : String) : Boolean;
  425. begin
  426. ChDir(NewDir);
  427. result := (IOResult = 0);
  428. end;
  429. Function CreateDir (Const NewDir : String) : Boolean;
  430. begin
  431. MkDir(NewDir);
  432. result := (IOResult = 0);
  433. end;
  434. Function RemoveDir (Const Dir : String) : Boolean;
  435. begin
  436. RmDir(Dir);
  437. result := (IOResult = 0);
  438. end;
  439. function DirectoryExists(const Directory: RawByteString): Boolean;
  440. var
  441. tmpLock: LongInt;
  442. FIB : PFileInfoBlock;
  443. SystemFileName: RawByteString;
  444. begin
  445. result:=false;
  446. if (Directory='') or (InOutRes<>0) then exit;
  447. SystemFileName:=PathConv(ToSingleByteFileSystemEncodedFileName(Directory));
  448. tmpLock:=dosLock(PChar(SystemFileName),SHARED_LOCK);
  449. if tmpLock=0 then exit;
  450. FIB:=nil; new(FIB);
  451. if (Examine(tmpLock,FIB)=True) and (FIB^.fib_DirEntryType>0) then
  452. result:=True;
  453. if tmpLock<>0 then Unlock(tmpLock);
  454. if assigned(FIB) then dispose(FIB);
  455. end;
  456. {****************************************************************************
  457. Locale Functions
  458. ****************************************************************************}
  459. Procedure GetLocalTime(var SystemTime: TSystemTime);
  460. var
  461. dayOfWeek: word;
  462. begin
  463. dos.GetTime(SystemTime.Hour, SystemTime.Minute, SystemTime.Second,SystemTime.Millisecond);
  464. dos.GetDate(SystemTime.Year, SystemTime.Month, SystemTime.Day, DayOfWeek);
  465. end;
  466. Procedure InitAnsi;
  467. Var
  468. i : longint;
  469. begin
  470. { Fill table entries 0 to 127 }
  471. for i := 0 to 96 do
  472. UpperCaseTable[i] := chr(i);
  473. for i := 97 to 122 do
  474. UpperCaseTable[i] := chr(i - 32);
  475. for i := 123 to 191 do
  476. UpperCaseTable[i] := chr(i);
  477. Move (CPISO88591UCT,UpperCaseTable[192],SizeOf(CPISO88591UCT));
  478. for i := 0 to 64 do
  479. LowerCaseTable[i] := chr(i);
  480. for i := 65 to 90 do
  481. LowerCaseTable[i] := chr(i + 32);
  482. for i := 91 to 191 do
  483. LowerCaseTable[i] := chr(i);
  484. Move (CPISO88591LCT,UpperCaseTable[192],SizeOf(CPISO88591UCT));
  485. end;
  486. Procedure InitInternational;
  487. begin
  488. InitInternationalGeneric;
  489. InitAnsi;
  490. end;
  491. function SysErrorMessage(ErrorCode: Integer): String;
  492. begin
  493. { Result:=StrError(ErrorCode);}
  494. end;
  495. function GetLastOSError: Integer;
  496. begin
  497. result:=-1;
  498. end;
  499. {****************************************************************************
  500. OS utility functions
  501. ****************************************************************************}
  502. Function GetEnvironmentVariable(Const EnvVar : String) : String;
  503. begin
  504. Result:=Dos.Getenv(shortstring(EnvVar));
  505. end;
  506. Function GetEnvironmentVariableCount : Integer;
  507. begin
  508. // Result:=FPCCountEnvVar(EnvP);
  509. Result:=Dos.envCount;
  510. end;
  511. Function GetEnvironmentString(Index : Integer) : String;
  512. begin
  513. // Result:=FPCGetEnvStrFromP(Envp,Index);
  514. Result:=Dos.EnvStr(Index);
  515. end;
  516. function ExecuteProcess (const Path: AnsiString; const ComLine: AnsiString;Flags:TExecuteFlags=[]):
  517. integer;
  518. var
  519. tmpPath: AnsiString;
  520. convPath: AnsiString;
  521. CommandLine: AnsiString;
  522. tmpLock: longint;
  523. E: EOSError;
  524. begin
  525. DosError:= 0;
  526. convPath:=PathConv(Path);
  527. tmpPath:=convPath+' '+ComLine;
  528. { Here we must first check if the command we wish to execute }
  529. { actually exists, because this is NOT handled by the }
  530. { _SystemTagList call (program will abort!!) }
  531. { Try to open with shared lock }
  532. tmpLock:=Lock(PChar(convPath),SHARED_LOCK);
  533. if tmpLock<>0 then
  534. begin
  535. { File exists - therefore unlock it }
  536. Unlock(tmpLock);
  537. result:=SystemTagList(PChar(tmpPath),nil);
  538. { on return of -1 the shell could not be executed }
  539. { probably because there was not enough memory }
  540. if result = -1 then
  541. DosError:=8;
  542. end
  543. else
  544. DosError:=3;
  545. if DosError <> 0 then begin
  546. if ComLine = '' then
  547. CommandLine := Path
  548. else
  549. CommandLine := Path + ' ' + ComLine;
  550. E := EOSError.CreateFmt (SExecuteProcessFailed, [CommandLine, DosError]);
  551. E.ErrorCode := DosError;
  552. raise E;
  553. end;
  554. end;
  555. function ExecuteProcess (const Path: AnsiString;
  556. const ComLine: array of AnsiString;Flags:TExecuteFlags=[]): integer;
  557. var
  558. CommandLine: AnsiString;
  559. I: integer;
  560. begin
  561. Commandline := '';
  562. for I := 0 to High (ComLine) do
  563. if Pos (' ', ComLine [I]) <> 0 then
  564. CommandLine := CommandLine + ' ' + '"' + ComLine [I] + '"'
  565. else
  566. CommandLine := CommandLine + ' ' + Comline [I];
  567. ExecuteProcess := ExecuteProcess (Path, CommandLine);
  568. end;
  569. procedure Sleep (Milliseconds: cardinal);
  570. begin
  571. // Amiga/MorphOS dos.library Delay() has precision of 1/50 seconds
  572. Delay(Milliseconds div 20);
  573. end;
  574. {****************************************************************************
  575. Initialization code
  576. ****************************************************************************}
  577. Initialization
  578. InitExceptions;
  579. InitInternational; { Initialize internationalization settings }
  580. OnBeep:=Nil; { No SysBeep() on MorphOS, for now. Figure out if we want
  581. to use intuition.library/DisplayBeep() for this (KB) }
  582. Finalization
  583. DoneExceptions;
  584. end.