system.pp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 2002 by Olle Raab
  5. FreePascal system unit for MacOS.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. unit System;
  13. interface
  14. { include system-independent routine headers }
  15. {$I systemh.inc}
  16. {Platform specific information}
  17. type
  18. {$ifdef CPU64}
  19. THandle = Int64;
  20. {$else CPU64}
  21. THandle = Longint;
  22. {$endif CPU64}
  23. const
  24. LineEnding = #13;
  25. LFNSupport = true;
  26. DirectorySeparator = ':';
  27. DriveSeparator = ':';
  28. PathSeparator = ','; // Is used in MPW
  29. FileNameCaseSensitive = false;
  30. { include heap support headers }
  31. {$I heaph.inc}
  32. const
  33. { Default filehandles }
  34. UnusedHandle : Longint = -1;
  35. StdInputHandle : Longint = 0;
  36. StdOutputHandle : Longint = 1;
  37. StdErrorHandle : Longint = 2;
  38. sLineBreak = LineEnding;
  39. DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsCR;
  40. var
  41. argc : longint;
  42. argv : ppchar;
  43. envp : ppchar;
  44. implementation
  45. {$define MACOS_USE_STDCLIB}
  46. { include system independent routines }
  47. {$I system.inc}
  48. {*********************** MacOS API *************}
  49. {TODO: Perhaps the System unit should check the MacOS version to
  50. ensure it is a supported version. }
  51. {Below is some MacOS API routines needed for internal use.
  52. Note, because the System unit is the most low level, it should not
  53. depend on any other units, and in particcular not the MacOS unit.
  54. Note: Types like Mac_XXX corresponds to the type XXX defined
  55. in MacOS Universal Headers. The prefix is to avoid name clashes
  56. with FPC types.}
  57. type
  58. SignedByte = shortint;
  59. SignedBytePtr = ^SignedByte;
  60. OSErr = Integer;
  61. OSType = Longint;
  62. Mac_Ptr = pointer;
  63. Mac_Handle = ^Mac_Ptr;
  64. Str31 = string[31];
  65. Str32 = string[32];
  66. Str63 = string[63];
  67. Str255 = string[255];
  68. FSSpec = record
  69. vRefNum: Integer;
  70. parID: Longint;
  71. name: Str63;
  72. end;
  73. FSSpecPtr = ^FSSpec;
  74. AliasHandle = Mac_Handle;
  75. ScriptCode = Integer;
  76. const
  77. noErr = 0;
  78. fnfErr = -43; //File not found error
  79. fsFromStart = 1;
  80. fsFromLEOF = 2;
  81. function Sbrk(logicalSize: Longint): Mac_Ptr ;
  82. external 'InterfaceLib' name 'NewPtr';
  83. procedure DisposeHandle(hdl: Mac_Handle);
  84. external 'InterfaceLib';
  85. function Mac_FreeMem: Longint;
  86. external 'InterfaceLib' name 'FreeMem';
  87. procedure Debugger;
  88. external 'InterfaceLib';
  89. procedure DebugStr(s: Str255);
  90. external 'InterfaceLib';
  91. procedure ExitToShell;
  92. external 'InterfaceLib';
  93. procedure SysBeep(dur: Integer);
  94. external 'SysBeep';
  95. function TickCount: Longint;
  96. external 'InterfaceLib';
  97. {$ifndef MACOS_USE_STDCLIB}
  98. function FSpOpenDF(spec: FSSpec; permission: SignedByte;
  99. var refNum: Integer): OSErr;
  100. external 'InterfaceLib';
  101. function FSpCreate(spec: FSSpec; creator, fileType: OSType;
  102. scriptTag: ScriptCode): OSErr;
  103. external 'InterfaceLib';
  104. function FSClose(refNum: Integer): OSErr;
  105. external 'InterfaceLib';
  106. function FSRead(refNum: Integer; var count: Longint; buffPtr: Mac_Ptr): OSErr;
  107. external 'InterfaceLib';
  108. function FSWrite(refNum: Integer; var count: Longint; buffPtr: Mac_Ptr): OSErr;
  109. external 'InterfaceLib';
  110. function GetFPos(refNum: Integer; var filePos: Longint): OSErr;
  111. external 'InterfaceLib';
  112. function SetFPos(refNum: Integer; posMode: Integer; posOff: Longint): OSErr;
  113. external 'InterfaceLib';
  114. function GetEOF(refNum: Integer; var logEOF: Longint): OSErr;
  115. external 'InterfaceLib';
  116. function SetEOF(refNum: Integer; logEOF: Longint): OSErr;
  117. external 'InterfaceLib';
  118. function NewAliasMinimalFromFullPath(fullPathLength: Integer;
  119. fullPath: Mac_Ptr; zoneName: Str32; serverName: Str31;
  120. var alias: AliasHandle):OSErr;
  121. external 'InterfaceLib';
  122. function ResolveAlias(fromFile: FSSpecPtr; alias: AliasHandle;
  123. var target: FSSpec; var wasChanged: Boolean):OSErr;
  124. external 'InterfaceLib';
  125. {$else}
  126. {**************** API to StdCLib in MacOS *************}
  127. {The reason StdCLib is used is that it can easily be connected
  128. to either SIOW or, in case of MPWTOOL, to MPW }
  129. {The prefix C_ or c_ is used where names conflicts with pascal
  130. keywords and names. Suffix Ptr is added for pointer to a type.}
  131. type
  132. size_t = Longint;
  133. off_t = Longint;
  134. C_int = Longint;
  135. C_short = Integer;
  136. C_long = Longint;
  137. C_unsigned_int = Cardinal;
  138. var
  139. errno: C_int; external name 'errno';
  140. MacOSErr: C_short; external name 'MacOSErr';
  141. const
  142. _IOFBF = $00;
  143. _IOLBF = $40;
  144. _IONBF = $04;
  145. O_RDONLY = $00; // Open for reading only.
  146. O_WRONLY = $01; // Open for writing only.
  147. O_RDWR = $02; // Open for reading & writing.
  148. O_APPEND = $08; // Write to the end of the file.
  149. O_RSRC = $10; // Open the resource fork.
  150. O_ALIAS = $20; // Open alias file.
  151. O_CREAT = $100; // Open or create a file.
  152. O_TRUNC = $200; // Open and truncate to zero length.
  153. O_EXCL = $400; // Create file only; fail if exists.
  154. O_BINARY = $800; // Open as a binary stream.
  155. O_NRESOLVE = $4000; // Don't resolve any aliases.
  156. SEEK_SET = 0;
  157. SEEK_CUR = 1;
  158. SEEK_END = 2;
  159. FIOINTERACTIVE = $00006602; // If device is interactive
  160. FIOBUFSIZE = $00006603; // Return optimal buffer size
  161. FIOFNAME = $00006604; // Return filename
  162. FIOREFNUM = $00006605; // Return fs refnum
  163. FIOSETEOF = $00006606; // Set file length
  164. TIOFLUSH = $00007408; // discard unread input. arg is ignored
  165. function C_open(path: PChar; oflag: C_int): C_int;
  166. external 'StdCLib' name 'open';
  167. function C_close(filedes: C_int): C_int;
  168. external 'StdCLib' name 'close';
  169. function C_write(filedes: C_int; buf: pointer; nbyte: size_t): size_t;
  170. external 'StdCLib' name 'write';
  171. {??? fread returns only when n items has been read. Does not specifically
  172. return after newlines, so cannot be used for reading input from the console.}
  173. function C_read(filedes: C_int; buf: pointer; nbyte: size_t): size_t;
  174. external 'StdCLib' name 'read';
  175. function lseek(filedes: C_int; offset: off_t; whence: C_int): off_t;
  176. external 'StdCLib' name 'lseek';
  177. function ioctl(filedes: C_int; cmd: C_unsigned_int; arg: pointer): C_int;
  178. external 'StdCLib' name 'ioctl';
  179. function remove(filename: PChar): C_int;
  180. external 'StdCLib';
  181. function c_rename(old, c_new: PChar): C_int;
  182. external 'StdCLib' name 'rename';
  183. procedure c_exit(status: C_int);
  184. external 'StdCLib' name 'exit';
  185. var
  186. {Is set to nonzero for MPWTool, zero otherwise.}
  187. StandAlone: C_int; external name 'StandAlone';
  188. CONST
  189. Sys_EPERM = 1; { No permission match }
  190. Sys_ENOENT = 2; { No such file or directory }
  191. Sys_ENORSRC = 3; { Resource not found *}
  192. Sys_EINTR = 4; { System service interrupted *}
  193. Sys_EIO = 5; { I/O error }
  194. Sys_ENXIO = 6; { No such device or address }
  195. Sys_E2BIG = 7; { Insufficient space for return argument * }
  196. Sys_ENOEXEC = 8; { File not executable * }
  197. Sys_EBADF = 9; { Bad file number }
  198. Sys_ECHILD = 10; { No child processes }
  199. Sys_EAGAIN = 11; { Resource temporarily unavailable * }
  200. Sys_ENOMEM = 12; { Not enough space * }
  201. Sys_EACCES = 13; { Permission denied }
  202. Sys_EFAULT = 14; { Illegal filename * }
  203. Sys_ENOTBLK = 15; { Block device required }
  204. Sys_EBUSY = 16; { Device or resource busy }
  205. Sys_EEXIST = 17; { File exists }
  206. Sys_EXDEV = 18; { Cross-device link }
  207. Sys_ENODEV = 19; { No such device }
  208. Sys_ENOTDIR = 20; { Not a directory }
  209. Sys_EISDIR = 21; { Is a directory }
  210. Sys_EINVAL = 22; { Invalid parameter * }
  211. Sys_ENFILE = 23; { File table overflow }
  212. Sys_EMFILE = 24; { Too many open files }
  213. Sys_ENOTTY = 25; { Not a typewriter }
  214. Sys_ETXTBSY = 26; { Text file busy }
  215. Sys_EFBIG = 27; { File too large }
  216. Sys_ENOSPC = 28; { No space left on device }
  217. Sys_ESPIPE = 29; { Illegal seek }
  218. Sys_EROFS = 30; { Read-only file system }
  219. Sys_EMLINK = 31; { Too many links }
  220. Sys_EPIPE = 32; { Broken pipe }
  221. Sys_EDOM = 33; { Math argument out of domain of func }
  222. Sys_ERANGE = 34; { Math result not representable }
  223. { Note * is slightly different, compared to rtl/sunos/errno.inc}
  224. {$endif}
  225. {******************************************************}
  226. Procedure Errno2InOutRes;
  227. {
  228. Convert ErrNo error to the correct Inoutres value
  229. }
  230. Begin
  231. if errno = 0 then { Else it will go through all the cases }
  232. exit;
  233. //If errno<0 then Errno:=-errno;
  234. case Errno of
  235. Sys_ENFILE,
  236. Sys_EMFILE : Inoutres:=4;
  237. Sys_ENOENT : Inoutres:=2;
  238. Sys_EBADF : Inoutres:=6;
  239. Sys_ENOMEM,
  240. Sys_EFAULT : Inoutres:=217;
  241. Sys_EINVAL : Inoutres:=218;
  242. Sys_EPIPE,
  243. Sys_EINTR,
  244. Sys_EIO,
  245. Sys_EAGAIN,
  246. Sys_ENOSPC : Inoutres:=101;
  247. Sys_ENOTDIR : Inoutres:=3;
  248. Sys_EROFS,
  249. Sys_EEXIST,
  250. Sys_EISDIR,
  251. Sys_EACCES : Inoutres:=5;
  252. Sys_ETXTBSY : Inoutres:=162;
  253. else
  254. InOutRes := Integer(errno);
  255. end;
  256. errno:=0;
  257. end;
  258. {*****************************************************************************
  259. ParamStr/Randomize
  260. *****************************************************************************}
  261. { number of args }
  262. function paramcount : longint;
  263. begin
  264. {paramcount := argc - 1;}
  265. paramcount:=0;
  266. end;
  267. { argument number l }
  268. function paramstr(l : longint) : string;
  269. begin
  270. {if (l>=0) and (l+1<=argc) then
  271. paramstr:=strpas(argv[l])
  272. else}
  273. paramstr:='';
  274. end;
  275. { set randseed to a new pseudo random value }
  276. procedure randomize;
  277. begin
  278. randseed:= Cardinal(TickCount);
  279. end;
  280. {*****************************************************************************
  281. Heap Management
  282. *****************************************************************************}
  283. var
  284. { Pointer to a block allocated with the MacOS Memory Manager, which
  285. is used as the initial FPC heap. }
  286. theHeap: Mac_Ptr;
  287. intern_heapsize : longint;external name 'HEAPSIZE';
  288. { first address of heap }
  289. function getheapstart:pointer;
  290. begin
  291. getheapstart:= theHeap;
  292. end;
  293. { current length of heap }
  294. function getheapsize:longint;
  295. begin
  296. getheapsize:= intern_heapsize ;
  297. end;
  298. { include standard heap management }
  299. {$I heap.inc}
  300. {*****************************************************************************
  301. Low Level File Routines
  302. ****************************************************************************}
  303. function do_isdevice(handle:longint):boolean;
  304. begin
  305. do_isdevice:=false;
  306. end;
  307. { close a file from the handle value }
  308. procedure do_close(h : longint);
  309. begin
  310. {$ifdef MACOS_USE_STDCLIB}
  311. C_close(h);
  312. Errno2InOutRes;
  313. {$else}
  314. InOutRes:=1;
  315. if FSClose(h) = noErr then
  316. InOutRes:=0;
  317. {$endif}
  318. end;
  319. procedure do_erase(p : pchar);
  320. begin
  321. {$ifdef MACOS_USE_STDCLIB}
  322. remove(p);
  323. Errno2InoutRes;
  324. {$else}
  325. InOutRes:=1;
  326. {$endif}
  327. end;
  328. procedure do_rename(p1,p2 : pchar);
  329. begin
  330. {$ifdef MACOS_USE_STDCLIB}
  331. c_rename(p1,p2);
  332. Errno2InoutRes;
  333. {$else}
  334. InOutRes:=1;
  335. {$endif}
  336. end;
  337. function do_write(h,addr,len : longint) : longint;
  338. begin
  339. {$ifdef MACOS_USE_STDCLIB}
  340. do_write:= C_write(h, pointer(addr), len);
  341. Errno2InoutRes;
  342. {$else}
  343. InOutRes:=1;
  344. if FSWrite(h, len, Mac_Ptr(addr)) = noErr then
  345. InOutRes:=0;
  346. do_write:= len;
  347. {$endif}
  348. end;
  349. function do_read(h,addr,len : longint) : longint;
  350. var
  351. i: Longint;
  352. begin
  353. {$ifdef MACOS_USE_STDCLIB}
  354. len:= C_read(h, pointer(addr), len);
  355. Errno2InoutRes;
  356. // TEMP BUGFIX Exchange CR to LF.
  357. for i:= 0 to len-1 do
  358. if SignedBytePtr(ord(addr) + i)^ = 13 then
  359. SignedBytePtr(ord(addr) + i)^ := 10;
  360. do_read:= len;
  361. {$else}
  362. InOutRes:=1;
  363. if FSread(h, len, Mac_Ptr(addr)) = noErr then
  364. InOutRes:=0;
  365. do_read:= len;
  366. {$endif}
  367. end;
  368. function do_filepos(handle : longint) : longint;
  369. var
  370. pos: Longint;
  371. begin
  372. {$ifdef MACOS_USE_STDCLIB}
  373. {This returns the filepos without moving it.}
  374. do_filepos := lseek(handle, 0, SEEK_CUR);
  375. Errno2InoutRes;
  376. {$else}
  377. InOutRes:=1;
  378. if GetFPos(handle, pos) = noErr then
  379. InOutRes:=0;
  380. do_filepos:= pos;
  381. {$endif}
  382. end;
  383. procedure do_seek(handle,pos : longint);
  384. begin
  385. {$ifdef MACOS_USE_STDCLIB}
  386. lseek(handle, pos, SEEK_SET);
  387. Errno2InoutRes;
  388. {$else}
  389. InOutRes:=1;
  390. if SetFPos(handle, fsFromStart, pos) = noErr then
  391. InOutRes:=0;
  392. {$endif}
  393. end;
  394. function do_seekend(handle:longint):longint;
  395. begin
  396. {$ifdef MACOS_USE_STDCLIB}
  397. lseek(handle, 0, SEEK_END);
  398. Errno2InoutRes;
  399. {$else}
  400. InOutRes:=1;
  401. if SetFPos(handle, fsFromLEOF, 0) = noErr then
  402. InOutRes:=0;
  403. {$endif}
  404. end;
  405. function do_filesize(handle : longint) : longint;
  406. var
  407. aktfilepos: Longint;
  408. begin
  409. {$ifdef MACOS_USE_STDCLIB}
  410. aktfilepos:= lseek(handle, 0, SEEK_CUR);
  411. if errno = 0 then
  412. begin
  413. do_filesize := lseek(handle, 0, SEEK_END);
  414. Errno2InOutRes; {Report the error from this operation.}
  415. lseek(handle, aktfilepos, SEEK_SET); {Always try to move back,
  416. even in presence of error.}
  417. end
  418. else
  419. Errno2InOutRes;
  420. {$else}
  421. InOutRes:=1;
  422. if GetEOF(handle, pos) = noErr then
  423. InOutRes:=0;
  424. do_filesize:= pos;
  425. {$endif}
  426. end;
  427. { truncate at a given position }
  428. procedure do_truncate (handle,pos:longint);
  429. begin
  430. {$ifdef MACOS_USE_STDCLIB}
  431. ioctl(handle, FIOSETEOF, pointer(pos));
  432. Errno2InoutRes;
  433. {$else}
  434. InOutRes:=1;
  435. do_seek(handle,pos); //TODO: Is this needed (Does the user anticipate the filemarker is at the end?)
  436. if SetEOF(handle, pos) = noErr then
  437. InOutRes:=0;
  438. {$endif}
  439. end;
  440. {$ifndef MACOS_USE_STDCLIB}
  441. function FSpLocationFromFullPath(fullPathLength: Integer;
  442. fullPath: Mac_Ptr; var spec: FSSpec ):OSErr;
  443. var
  444. alias: AliasHandle;
  445. res: OSErr;
  446. wasChanged: Boolean;
  447. nullString: Str32;
  448. begin
  449. nullString:= '';
  450. res:= NewAliasMinimalFromFullPath(fullPathLength,
  451. fullPath, nullString, nullString, alias);
  452. if res = noErr then
  453. begin
  454. res:= ResolveAlias(nil, alias, spec, wasChanged);
  455. DisposeHandle(Mac_Handle(alias));
  456. end;
  457. FSpLocationFromFullPath:= res;
  458. end;
  459. {$endif}
  460. procedure do_open(var f;p:pchar;flags:longint);
  461. {
  462. filerec and textrec have both handle and mode as the first items so
  463. they could use the same routine for opening/creating.
  464. when (flags and $100) the file will be append
  465. when (flags and $1000) the file will be truncate/rewritten
  466. when (flags and $10000) there is no check for close (needed for textfiles)
  467. }
  468. var
  469. spec: FSSpec;
  470. creator, fileType: OSType;
  471. scriptTag: ScriptCode;
  472. refNum: Integer;
  473. res: OSErr;
  474. fh: Longint;
  475. oflags : longint;
  476. Const
  477. fsCurPerm = 0;
  478. smSystemScript = -1;
  479. begin
  480. // AllowSlash(p);
  481. { close first if opened }
  482. if ((flags and $10000)=0) then
  483. begin
  484. case filerec(f).mode of
  485. fminput,fmoutput,fminout : Do_Close(filerec(f).handle);
  486. fmclosed : ;
  487. else
  488. begin
  489. {not assigned}
  490. inoutres:=102;
  491. exit;
  492. end;
  493. end;
  494. end;
  495. { reset file handle }
  496. filerec(f).handle:=UnusedHandle;
  497. {$ifdef MACOS_USE_STDCLIB}
  498. { We do the conversion of filemodes here, concentrated on 1 place }
  499. case (flags and 3) of
  500. 0 : begin
  501. oflags :=O_RDONLY;
  502. filerec(f).mode:=fminput;
  503. end;
  504. 1 : begin
  505. oflags :=O_WRONLY;
  506. filerec(f).mode:=fmoutput;
  507. end;
  508. 2 : begin
  509. oflags :=O_RDWR;
  510. filerec(f).mode:=fminout;
  511. end;
  512. end;
  513. if (flags and $1000)=$1000 then
  514. oflags:=oflags or (O_CREAT or O_TRUNC)
  515. else if (flags and $100)=$100 then
  516. oflags:=oflags or (O_APPEND);
  517. { empty name is special }
  518. if p[0]=#0 then
  519. begin
  520. case FileRec(f).mode of
  521. fminput :
  522. FileRec(f).Handle:=StdInputHandle;
  523. fminout, { this is set by rewrite }
  524. fmoutput :
  525. FileRec(f).Handle:=StdOutputHandle;
  526. fmappend :
  527. begin
  528. FileRec(f).Handle:=StdOutputHandle;
  529. FileRec(f).mode:=fmoutput; {fool fmappend}
  530. end;
  531. end;
  532. exit;
  533. end;
  534. fh:= C_open(p, oflags);
  535. //TODO Perhaps handle readonly filesystems, as in sysunix.inc
  536. Errno2InOutRes;
  537. if fh <> -1 then
  538. filerec(f).handle:= fh
  539. else
  540. filerec(f).handle:= UnusedHandle;
  541. {$else}
  542. InOutRes:=1;
  543. //creator:= $522A6368; {'MPS ' -- MPW}
  544. //creator:= $74747874; {'ttxt'}
  545. creator:= $522A6368; {'R*ch' -- BBEdit}
  546. fileType:= $54455854; {'TEXT'}
  547. { reset file handle }
  548. filerec(f).handle:=UnusedHandle;
  549. res:= FSpLocationFromFullPath(StrLen(p), p, spec);
  550. if (res = noErr) or (res = fnfErr) then
  551. begin
  552. if FSpCreate(spec, creator, fileType, smSystemScript) = noErr then
  553. ;
  554. if FSpOpenDF(spec, fsCurPerm, refNum) = noErr then
  555. begin
  556. filerec(f).handle:= refNum;
  557. InOutRes:=0;
  558. end;
  559. end;
  560. if (filerec(f).handle=UnusedHandle) then
  561. begin
  562. //errno:=GetLastError;
  563. //Errno2InoutRes;
  564. end;
  565. {$endif}
  566. end;
  567. {*****************************************************************************
  568. UnTyped File Handling
  569. *****************************************************************************}
  570. {$i file.inc}
  571. {*****************************************************************************
  572. Typed File Handling
  573. *****************************************************************************}
  574. {$i typefile.inc}
  575. {*****************************************************************************
  576. Text File Handling
  577. *****************************************************************************}
  578. { should we consider #26 as the end of a file ? }
  579. {?? $DEFINE EOF_CTRLZ}
  580. {$i text.inc}
  581. {*****************************************************************************
  582. Directory Handling
  583. *****************************************************************************}
  584. procedure mkdir(const s:string);[IOCheck];
  585. begin
  586. InOutRes:=1;
  587. end;
  588. procedure rmdir(const s:string);[IOCheck];
  589. begin
  590. InOutRes:=1;
  591. end;
  592. procedure chdir(const s:string);[IOCheck];
  593. begin
  594. InOutRes:=1;
  595. end;
  596. procedure GetDir (DriveNr: byte; var Dir: ShortString);
  597. begin
  598. InOutRes := 1;
  599. end;
  600. {*****************************************************************************
  601. SystemUnit Initialization
  602. *****************************************************************************}
  603. procedure setup_arguments;
  604. begin
  605. end;
  606. procedure setup_environment;
  607. begin
  608. end;
  609. {*****************************************************************************
  610. System Dependent Exit code
  611. *****************************************************************************}
  612. Procedure system_exit;
  613. begin
  614. {$ifndef MACOS_USE_STDCLIB}
  615. if StandAlone <> 0 then
  616. ExitToShell;
  617. {$else}
  618. c_exit(exitcode); //exitcode is only utilized by an MPW tool
  619. {$endif}
  620. end;
  621. procedure SysInitStdIO;
  622. begin
  623. { Setup stdin, stdout and stderr }
  624. {$ifdef MACOS_USE_STDCLIB}
  625. OpenStdIO(Input,fmInput,StdInputHandle);
  626. OpenStdIO(Output,fmOutput,StdOutputHandle);
  627. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  628. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  629. {$endif }
  630. end;
  631. begin
  632. if false then //To save it from the dead code stripper
  633. begin
  634. //Included only to make them available for debugging in asm.
  635. Debugger;
  636. DebugStr('');
  637. end;
  638. { To be set if this is a GUI or console application }
  639. IsConsole := TRUE;
  640. { To be set if this is a library and not a program }
  641. IsLibrary := FALSE;
  642. StackLength := InitialStkLen;
  643. StackBottom := SPtr - StackLength;
  644. { Setup heap }
  645. if Mac_FreeMem - intern_heapsize < 30000 then
  646. Halt(3);
  647. theHeap:= Sbrk(intern_heapsize);
  648. if theHeap = nil then
  649. Halt(3); //According to MPW
  650. InitHeap;
  651. SysInitStdIO;
  652. { Setup environment and arguments }
  653. Setup_Environment;
  654. setup_arguments;
  655. { Reset IO Error }
  656. InOutRes:=0;
  657. errno:=0;
  658. {$ifdef HASVARIANT}
  659. initvariantmanager;
  660. {$endif HASVARIANT}
  661. end.
  662. {
  663. $Log$
  664. Revision 1.8 2003-10-16 15:43:13 peter
  665. * THandle is platform dependent
  666. Revision 1.7 2003/09/27 11:52:35 peter
  667. * sbrk returns pointer
  668. Revision 1.6 2003/09/12 12:45:15 olle
  669. + filehandling complete
  670. + heaphandling complete
  671. + support for random
  672. * filehandling now uses filedecriptors in StdCLib
  673. * other minor changes
  674. - removed DEFINE MAC_SYS_RUNNABLE
  675. Revision 1.5 2003/01/13 17:18:55 olle
  676. + added support for rudimentary file handling
  677. Revision 1.4 2002/11/28 10:58:02 olle
  678. + added support for rudimentary heap
  679. Revision 1.3 2002/10/23 15:29:09 olle
  680. + added switch MAC_SYS_RUNABLE
  681. + added include of system.h etc
  682. + added standard globals
  683. + added dummy hook procedures
  684. Revision 1.2 2002/10/10 19:44:05 florian
  685. * changes from Olle to compile/link a simple program
  686. Revision 1.1 2002/10/02 21:34:31 florian
  687. * first dummy implementation
  688. }