sysutils.pp 19 KB

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