system.pp 21 KB

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