system.pp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 2004 by Karoly Balogh for Genesi Sarl
  5. System unit for MorphOS/PowerPC
  6. Uses parts of the Amiga/68k port by Carl Eric Codere
  7. and Nils Sjoholm
  8. See the file COPYING.FPC, included in this distribution,
  9. for details about the copyright.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. **********************************************************************}
  14. unit {$ifdef VER1_0}SysMorph{$else}System{$endif};
  15. interface
  16. {$define FPC_IS_SYSTEM}
  17. {$I systemh.inc}
  18. type
  19. THandle = DWord;
  20. {$I heaph.inc}
  21. const
  22. LineEnding = #10;
  23. LFNSupport = True;
  24. DirectorySeparator = '/';
  25. DriveSeparator = ':';
  26. PathSeparator = ';';
  27. const
  28. UnusedHandle : LongInt = -1;
  29. StdInputHandle : LongInt = 0;
  30. StdOutputHandle : LongInt = 0;
  31. StdErrorHandle : LongInt = 0;
  32. FileNameCaseSensitive : Boolean = False;
  33. sLineBreak : string[1] = LineEnding;
  34. DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsLF;
  35. BreakOn : Boolean = True;
  36. var
  37. MOS_ExecBase : Pointer; external name '_ExecBase';
  38. MOS_DOSBase : Pointer;
  39. MOS_heapPool : Pointer; { pointer for the OS pool for growing the heap }
  40. { MorphOS functions }
  41. function exec_OpenLibrary(libname: PChar location 'a1';
  42. libver: LongInt location 'd0'): Pointer; SysCall MOS_ExecBase 552;
  43. procedure exec_CloseLibrary(libhandle: Pointer location 'a1'); SysCall MOS_ExecBase 414;
  44. function exec_CreatePool(memflags: LongInt location 'd0';
  45. puddleSize: LongInt location 'd1';
  46. threshSize: LongInt location 'd2'): Pointer; SysCall MOS_ExecBase 696;
  47. procedure exec_DeletePool(poolHeader: Pointer location 'a0'); SysCall MOS_ExecBase 702;
  48. function exec_AllocPooled(poolHeader: Pointer location 'a0';
  49. memSize: LongInt location 'd0'): Pointer; SysCall MOS_ExecBase 708;
  50. function exec_SetSignal(newSignals: LongInt location 'd0';
  51. signalMask: LongInt location 'd1'): LongInt; SysCall MOS_ExecBase 306;
  52. function dos_Output: LongInt; SysCall MOS_DOSBase 60;
  53. function dos_Input: LongInt; SysCall MOS_DOSBase 54;
  54. function dos_IoErr: LongInt; SysCall MOS_DOSBase 132;
  55. function dos_Open(fname: PChar location 'd1';
  56. accessMode: LongInt location 'd2'): LongInt; SysCall MOS_DOSBase 30;
  57. function dos_Close(fileh: LongInt location 'd1'): Boolean; SysCall MOS_DOSBase 36;
  58. function dos_Seek(fileh: LongInt location 'd1';
  59. position: LongInt location 'd2';
  60. posmode: LongInt location 'd3'): LongInt; SysCall MOS_DOSBase 66;
  61. function dos_SetFileSize(fileh: LongInt location 'd1';
  62. position: LongInt location 'd2';
  63. posmode: LongInt location 'd3'): LongInt; SysCall MOS_DOSBase 456;
  64. function dos_Read(fileh: LongInt location 'd1';
  65. buffer: Pointer location 'd2';
  66. length: LongInt location 'd3'): LongInt; SysCall MOS_DOSBase 40;
  67. function dos_Write(fileh: LongInt location 'd1';
  68. buffer: Pointer location 'd2';
  69. length: LongInt location 'd3'): LongInt; SysCall MOS_DOSBase 48;
  70. function dos_WriteChars(buf: PChar location 'd1';
  71. buflen: LongInt location 'd2'): LongInt; SysCall MOS_DOSBase 942;
  72. function dos_Rename(oldName: PChar location 'd1';
  73. newName: PChar location 'd2'): Boolean; SysCall MOS_DOSBase 78;
  74. function dos_DeleteFile(fname: PChar location 'd1'): Boolean; SysCall MOS_DOSBase 72;
  75. function dos_GetCurrentDirName(buf: PChar location 'd1';
  76. len: LongInt location 'd2'): Boolean; SysCall MOS_DOSBase 564;
  77. function dos_Lock(lname: PChar location 'd1';
  78. accessMode: LongInt location 'd2'): LongInt; SysCall MOS_DOSBase 84;
  79. implementation
  80. {$I system.inc}
  81. { OS dependant parts }
  82. { Errors from dos_IoErr(), etc. }
  83. const
  84. ERROR_NO_FREE_STORE = 103;
  85. ERROR_TASK_TABLE_FULL = 105;
  86. ERROR_BAD_TEMPLATE = 114;
  87. ERROR_BAD_NUMBER = 115;
  88. ERROR_REQUIRED_ARG_MISSING = 116;
  89. ERROR_KEY_NEEDS_ARG = 117;
  90. ERROR_TOO_MANY_ARGS = 118;
  91. ERROR_UNMATCHED_QUOTES = 119;
  92. ERROR_LINE_TOO_LONG = 120;
  93. ERROR_FILE_NOT_OBJECT = 121;
  94. ERROR_INVALID_RESIDENT_LIBRARY = 122;
  95. ERROR_NO_DEFAULT_DIR = 201;
  96. ERROR_OBJECT_IN_USE = 202;
  97. ERROR_OBJECT_EXISTS = 203;
  98. ERROR_DIR_NOT_FOUND = 204;
  99. ERROR_OBJECT_NOT_FOUND = 205;
  100. ERROR_BAD_STREAM_NAME = 206;
  101. ERROR_OBJECT_TOO_LARGE = 207;
  102. ERROR_ACTION_NOT_KNOWN = 209;
  103. ERROR_INVALID_COMPONENT_NAME = 210;
  104. ERROR_INVALID_LOCK = 211;
  105. ERROR_OBJECT_WRONG_TYPE = 212;
  106. ERROR_DISK_NOT_VALIDATED = 213;
  107. ERROR_DISK_WRITE_PROTECTED = 214;
  108. ERROR_RENAME_ACROSS_DEVICES = 215;
  109. ERROR_DIRECTORY_NOT_EMPTY = 216;
  110. ERROR_TOO_MANY_LEVELS = 217;
  111. ERROR_DEVICE_NOT_MOUNTED = 218;
  112. ERROR_SEEK_ERROR = 219;
  113. ERROR_COMMENT_TOO_BIG = 220;
  114. ERROR_DISK_FULL = 221;
  115. ERROR_DELETE_PROTECTED = 222;
  116. ERROR_WRITE_PROTECTED = 223;
  117. ERROR_READ_PROTECTED = 224;
  118. ERROR_NOT_A_DOS_DISK = 225;
  119. ERROR_NO_DISK = 226;
  120. ERROR_NO_MORE_ENTRIES = 232;
  121. { added for AOS 1.4 }
  122. ERROR_IS_SOFT_LINK = 233;
  123. ERROR_OBJECT_LINKED = 234;
  124. ERROR_BAD_HUNK = 235;
  125. ERROR_NOT_IMPLEMENTED = 236;
  126. ERROR_RECORD_NOT_LOCKED = 240;
  127. ERROR_LOCK_COLLISION = 241;
  128. ERROR_LOCK_TIMEOUT = 242;
  129. ERROR_UNLOCK_ERROR = 243;
  130. { DOS file offset modes }
  131. const
  132. OFFSET_BEGINNING = -1;
  133. OFFSET_CURRENT = 0;
  134. OFFSET_END = 1;
  135. { Memory flags }
  136. const
  137. MEMF_ANY = 0;
  138. MEMF_PUBLIC = 1 Shl 0;
  139. MEMF_CHIP = 1 Shl 1;
  140. MEMF_FAST = 1 Shl 2;
  141. MEMF_LOCAL = 1 Shl 8;
  142. MEMF_24BITDMA = 1 Shl 9;
  143. MEMF_KICK = 1 Shl 10;
  144. MEMF_CLEAR = 1 Shl 16;
  145. MEMF_LARGEST = 1 Shl 17;
  146. MEMF_REVERSE = 1 Shl 18;
  147. MEMF_TOTAL = 1 Shl 19;
  148. MEMF_NO_EXPUNGE = 1 Shl 31;
  149. const
  150. CTRL_C = 20; { Error code on CTRL-C press }
  151. SIGBREAKF_CTRL_C = $1000; { CTRL-C signal flags }
  152. {*****************************************************************************
  153. Misc. System Dependent Functions
  154. *****************************************************************************}
  155. procedure haltproc(e:longint);cdecl;external name '_haltproc';
  156. procedure System_exit;
  157. begin
  158. if MOS_DOSBase<>NIL then exec_CloseLibrary(MOS_DOSBase);
  159. if MOS_heapPool<>NIL then exec_DeletePool(MOS_heapPool);
  160. haltproc(ExitCode);
  161. end;
  162. { Converts a MorphOS dos.library error code to a TP compatible error code }
  163. { Based on 1.0.x Amiga RTL }
  164. procedure dosError2InOut(errno: LongInt);
  165. begin
  166. case errno of
  167. ERROR_BAD_NUMBER,
  168. ERROR_ACTION_NOT_KNOWN,
  169. ERROR_NOT_IMPLEMENTED : InOutRes := 1;
  170. ERROR_OBJECT_NOT_FOUND : InOutRes := 2;
  171. ERROR_DIR_NOT_FOUND : InOutRes := 3;
  172. ERROR_DISK_WRITE_PROTECTED : InOutRes := 150;
  173. ERROR_OBJECT_WRONG_TYPE : InOutRes := 151;
  174. ERROR_OBJECT_EXISTS,
  175. ERROR_DELETE_PROTECTED,
  176. ERROR_WRITE_PROTECTED,
  177. ERROR_READ_PROTECTED,
  178. ERROR_OBJECT_IN_USE,
  179. ERROR_DIRECTORY_NOT_EMPTY : InOutRes := 5;
  180. ERROR_NO_MORE_ENTRIES : InOutRes := 18;
  181. ERROR_RENAME_ACROSS_DEVICES : InOutRes := 17;
  182. ERROR_DISK_FULL : InOutRes := 101;
  183. ERROR_INVALID_RESIDENT_LIBRARY : InoutRes := 153;
  184. ERROR_BAD_HUNK : InOutRes := 153;
  185. ERROR_NOT_A_DOS_DISK : InOutRes := 157;
  186. ERROR_NO_DISK,
  187. ERROR_DISK_NOT_VALIDATED,
  188. ERROR_DEVICE_NOT_MOUNTED : InOutRes := 152;
  189. ERROR_SEEK_ERROR : InOutRes := 156;
  190. ERROR_LOCK_COLLISION,
  191. ERROR_LOCK_TIMEOUT,
  192. ERROR_UNLOCK_ERROR,
  193. ERROR_INVALID_LOCK,
  194. ERROR_INVALID_COMPONENT_NAME,
  195. ERROR_BAD_STREAM_NAME,
  196. ERROR_FILE_NOT_OBJECT : InOutRes := 6;
  197. else
  198. InOutres := errno;
  199. end;
  200. end;
  201. { Used for CTRL_C checking in I/O calls }
  202. procedure checkCTRLC;
  203. begin
  204. if BreakOn then begin
  205. if (exec_SetSignal(0,0) And SIGBREAKF_CTRL_C)<>0 then begin
  206. { Clear CTRL-C signal }
  207. exec_SetSignal(0,SIGBREAKF_CTRL_C);
  208. Halt(CTRL_C);
  209. end;
  210. end;
  211. end;
  212. {*****************************************************************************
  213. ParamStr/Randomize
  214. *****************************************************************************}
  215. { number of args }
  216. function paramcount : longint;
  217. begin
  218. {paramcount := argc - 1;}
  219. paramcount:=0;
  220. end;
  221. { argument number l }
  222. function paramstr(l : longint) : string;
  223. begin
  224. {if (l>=0) and (l+1<=argc) then
  225. paramstr:=strpas(argv[l])
  226. else}
  227. paramstr:='';
  228. end;
  229. { set randseed to a new pseudo random value }
  230. procedure randomize;
  231. begin
  232. {regs.realeax:=$2c00;
  233. sysrealintr($21,regs);
  234. hl:=regs.realedx and $ffff;
  235. randseed:=hl*$10000+ (regs.realecx and $ffff);}
  236. randseed:=0;
  237. end;
  238. {*****************************************************************************
  239. Heap Management
  240. *****************************************************************************}
  241. var
  242. int_heap : LongInt; external name 'HEAP';
  243. int_heapsize : LongInt; external name 'HEAPSIZE';
  244. { first address of heap }
  245. function getheapstart:pointer;
  246. begin
  247. getheapstart:=@int_heap;
  248. end;
  249. { current length of heap }
  250. function getheapsize:longint;
  251. begin
  252. getheapsize:=int_heapsize;
  253. end;
  254. { function to allocate size bytes more for the program }
  255. { must return the first address of new data space or nil if fail }
  256. function Sbrk(size : longint):pointer;
  257. begin
  258. Sbrk:=exec_AllocPooled(MOS_heapPool,size);
  259. end;
  260. {$I heap.inc}
  261. {*****************************************************************************
  262. Directory Handling
  263. *****************************************************************************}
  264. procedure mkdir(const s : string);[IOCheck];
  265. begin
  266. checkCTRLC;
  267. InOutRes:=1;
  268. end;
  269. procedure rmdir(const s : string);[IOCheck];
  270. var
  271. buffer : array[0..255] of char;
  272. j : Integer;
  273. temp : string;
  274. begin
  275. checkCTRLC;
  276. if (s='.') then InOutRes:=16;
  277. If (s='') or (InOutRes<>0) then exit;
  278. temp:=s;
  279. for j:=1 to length(temp) do
  280. if temp[j] = '\' then temp[j] := '/';
  281. move(temp[1],buffer,length(temp));
  282. buffer[length(temp)]:=#0;
  283. if not dos_DeleteFile(buffer) then
  284. dosError2InOut(dos_IoErr);
  285. end;
  286. procedure chdir(const s : string);[IOCheck];
  287. begin
  288. checkCTRLC;
  289. InOutRes:=1;
  290. end;
  291. procedure GetDir (DriveNr: byte; var Dir: ShortString);
  292. var tmpbuf: array[0..255] of char;
  293. begin
  294. checkCTRLC;
  295. Dir:='';
  296. if not dos_GetCurrentDirName(tmpbuf,256) then
  297. dosError2InOut(dos_IoErr)
  298. else
  299. Dir:=strpas(tmpbuf);
  300. end;
  301. {****************************************************************************
  302. Low level File Routines
  303. All these functions can set InOutRes on errors
  304. ****************************************************************************}
  305. { close a file from the handle value }
  306. procedure do_close(handle : longint);
  307. begin
  308. { Do _NOT_ check CTRL_C on Close, because it will conflict
  309. with System_Exit! }
  310. if not dos_Close(handle) then
  311. dosError2InOut(dos_IoErr);
  312. end;
  313. procedure do_erase(p : pchar);
  314. begin
  315. checkCTRLC;
  316. if not dos_DeleteFile(p) then
  317. dosError2InOut(dos_IoErr);
  318. end;
  319. procedure do_rename(p1,p2 : pchar);
  320. begin
  321. checkCTRLC;
  322. if not dos_Rename(p1,p2) then
  323. dosError2InOut(dos_IoErr);
  324. end;
  325. function do_write(h:longint; addr: pointer; len: longint) : longint;
  326. var dosResult: LongInt;
  327. begin
  328. checkCTRLC;
  329. do_write:=0;
  330. if len<=0 then exit;
  331. dosResult:=dos_Write(h,addr,len);
  332. if dosResult<0 then begin
  333. dosError2InOut(dos_IoErr);
  334. end else begin
  335. do_write:=dosResult;
  336. end;
  337. end;
  338. function do_read(h:longint; addr: pointer; len: longint) : longint;
  339. var dosResult: LongInt;
  340. begin
  341. checkCTRLC;
  342. do_read:=0;
  343. if len<=0 then exit;
  344. dosResult:=dos_Write(h,addr,len);
  345. if dosResult<0 then begin
  346. dosError2InOut(dos_IoErr);
  347. end else begin
  348. do_read:=dosResult;
  349. end
  350. end;
  351. function do_filepos(handle : longint) : longint;
  352. var dosResult: LongInt;
  353. begin
  354. checkCTRLC;
  355. do_filepos:=0;
  356. { Seeking zero from OFFSET_CURRENT to find out where we are }
  357. dosResult:=dos_Seek(handle,0,OFFSET_CURRENT);
  358. if dosResult<0 then begin
  359. dosError2InOut(dos_IoErr);
  360. end else begin
  361. do_filepos:=dosResult;
  362. end;
  363. end;
  364. procedure do_seek(handle,pos : longint);
  365. begin
  366. checkCTRLC;
  367. { Seeking from OFFSET_BEGINNING }
  368. if dos_Seek(handle,pos,OFFSET_BEGINNING)<0 then
  369. dosError2InOut(dos_IoErr);
  370. end;
  371. function do_seekend(handle:longint):longint;
  372. var dosResult: LongInt;
  373. begin
  374. checkCTRLC;
  375. do_seekend:=0;
  376. { Seeking to OFFSET_END }
  377. dosResult:=dos_Seek(handle,0,OFFSET_END);
  378. if dosResult<0 then begin
  379. dosError2InOut(dos_IoErr);
  380. end else begin
  381. do_seekend:=dosResult;
  382. end
  383. end;
  384. function do_filesize(handle : longint) : longint;
  385. var currfilepos: longint;
  386. begin
  387. checkCTRLC;
  388. currfilepos:=do_filepos(handle);
  389. { We have to do this twice, because seek returns the OLD position }
  390. do_filesize:=do_seekend(handle);
  391. do_filesize:=do_seekend(handle);
  392. do_seek(handle,currfilepos)
  393. end;
  394. { truncate at a given position }
  395. procedure do_truncate (handle,pos:longint);
  396. begin
  397. checkCTRLC;
  398. { Seeking from OFFSET_BEGINNING }
  399. if dos_SetFileSize(handle,pos,OFFSET_BEGINNING)<0 then
  400. dosError2InOut(dos_IoErr);
  401. end;
  402. procedure do_open(var f;p:pchar;flags:longint);
  403. {
  404. filerec and textrec have both handle and mode as the first items so
  405. they could use the same routine for opening/creating.
  406. when (flags and $10) the file will be append
  407. when (flags and $100) the file will be truncate/rewritten
  408. when (flags and $1000) there is no check for close (needed for textfiles)
  409. }
  410. var
  411. i,j : LongInt;
  412. openflags: LongInt;
  413. path : String;
  414. buffer : array[0..255] of Char;
  415. index : Integer;
  416. s : String;
  417. begin
  418. path:=strpas(p);
  419. for index:=1 to length(path) do
  420. if path[index]='\' then path[index]:='/';
  421. { remove any dot characters and replace by their current }
  422. { directory equivalent. }
  423. { look for parent directory }
  424. if pos('../',path) = 1 then
  425. begin
  426. delete(path,1,3);
  427. getdir(0,s);
  428. j:=length(s);
  429. while (s[j] <> '/') AND (s[j] <> ':') AND (j > 0 ) do
  430. dec(j);
  431. if j > 0 then
  432. s:=copy(s,1,j);
  433. path:=s+path;
  434. end
  435. else
  436. { look for current directory }
  437. if pos('./',path) = 1 then
  438. begin
  439. delete(path,1,2);
  440. getdir(0,s);
  441. if (s[length(s)] <> '/') and (s[length(s)] <> ':') then
  442. s:=s+'/';
  443. path:=s+path;
  444. end;
  445. move(path[1],buffer,length(path));
  446. buffer[length(path)]:=#0;
  447. { close first if opened }
  448. if ((flags and $10000)=0) then
  449. begin
  450. case filerec(f).mode of
  451. fminput,fmoutput,fminout : Do_Close(filerec(f).handle);
  452. fmclosed : ;
  453. else begin
  454. inoutres:=102; {not assigned}
  455. exit;
  456. end;
  457. end;
  458. end;
  459. { reset file handle }
  460. filerec(f).handle:=UnusedHandle;
  461. { convert filemode to filerec modes }
  462. { READ/WRITE on existing file }
  463. { RESET/APPEND }
  464. openflags := 1005;
  465. case (flags and 3) of
  466. 0 : filerec(f).mode:=fminput;
  467. 1 : filerec(f).mode:=fmoutput;
  468. 2 : filerec(f).mode:=fminout;
  469. end;
  470. { rewrite (create a new file) }
  471. if (flags and $1000)<>0 then openflags := 1006;
  472. { empty name is special }
  473. if p[0]=#0 then
  474. begin
  475. case filerec(f).mode of
  476. fminput :
  477. filerec(f).handle:=StdInputHandle;
  478. fmappend,
  479. fmoutput : begin
  480. filerec(f).handle:=StdOutputHandle;
  481. filerec(f).mode:=fmoutput; {fool fmappend}
  482. end;
  483. end;
  484. exit;
  485. end;
  486. i:=dos_Open(buffer,openflags);
  487. if i=0 then
  488. begin
  489. dosError2InOut(dos_IoErr);
  490. end else begin
  491. {AddToList(FileList,i);}
  492. filerec(f).handle:=i;
  493. end;
  494. { append mode }
  495. if ((Flags and $100)<>0) and (FileRec(F).Handle<>UnusedHandle) then
  496. begin
  497. do_seekend(filerec(f).handle);
  498. filerec(f).mode:=fmoutput; {fool fmappend}
  499. end;
  500. end;
  501. function do_isdevice(handle:longint):boolean;
  502. begin
  503. if (handle=StdOutputHandle) or (handle=StdInputHandle) or
  504. (handle=StdErrorHandle) then
  505. do_isdevice:=True
  506. else
  507. do_isdevice:=False;
  508. end;
  509. {*****************************************************************************
  510. UnTyped File Handling
  511. *****************************************************************************}
  512. {$i file.inc}
  513. {*****************************************************************************
  514. Typed File Handling
  515. *****************************************************************************}
  516. {$i typefile.inc}
  517. {*****************************************************************************
  518. Text File Handling
  519. *****************************************************************************}
  520. {$I text.inc}
  521. { MorphOS specific startup }
  522. procedure SysInitMorphOS;
  523. begin
  524. MOS_DOSBase:=exec_OpenLibrary('dos.library',50);
  525. if MOS_DOSBase=NIL then Halt(1);
  526. { Creating the memory pool for growing heap }
  527. MOS_heapPool:=exec_CreatePool(MEMF_FAST,growheapsize2,growheapsize1);
  528. if MOS_heapPool=NIL then Halt(1);
  529. StdInputHandle:=dos_Input;
  530. StdOutputHandle:=dos_Output;
  531. end;
  532. procedure SysInitStdIO;
  533. begin
  534. OpenStdIO(Input,fmInput,StdInputHandle);
  535. OpenStdIO(Output,fmOutput,StdOutputHandle);
  536. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  537. { * MorphOS doesn't have a separate stderr, just like AmigaOS (???) * }
  538. StdErrorHandle:=StdOutputHandle;
  539. // OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  540. end;
  541. {procedure SysInitExecPath;
  542. var
  543. hs : string[16];
  544. link : string;
  545. i : longint;
  546. begin
  547. str(Fpgetpid,hs);
  548. hs:='/proc/'+hs+'/exe'#0;
  549. i:=Fpreadlink(@hs[1],@link[1],high(link));
  550. { it must also be an absolute filename, linux 2.0 points to a memory
  551. location so this will skip that }
  552. if (i>0) and (link[1]='/') then
  553. begin
  554. link[0]:=chr(i);
  555. ExecPathStr:=link;
  556. end;
  557. end;
  558. }
  559. Begin
  560. IsConsole := TRUE;
  561. IsLibrary := FALSE;
  562. StackLength := InitialStkLen;
  563. StackBottom := Sptr - StackLength;
  564. { OS specific startup }
  565. SysInitMorphOS;
  566. { Set up signals handlers }
  567. // InstallSignals;
  568. { Setup heap }
  569. InitHeap;
  570. // SysInitExceptions;
  571. { Arguments }
  572. // SetupCmdLine;
  573. // SysInitExecPath;
  574. { Setup stdin, stdout and stderr }
  575. SysInitStdIO;
  576. { Reset IO Error }
  577. InOutRes:=0;
  578. (* This should be changed to a real value during *)
  579. (* thread driver initialization if appropriate. *)
  580. ThreadID := 1;
  581. {$ifdef HASVARIANT}
  582. initvariantmanager;
  583. {$endif HASVARIANT}
  584. End.
  585. {
  586. $Log$
  587. Revision 1.4 2004-05-02 02:06:57 karoly
  588. + most of file I/O calls implemented
  589. Revision 1.3 2004/05/01 15:09:47 karoly
  590. * first working system unit (very limited yet)
  591. Revision 1.1 2004/02/13 07:19:53 karoly
  592. * quick hack from Linux system unit
  593. }