system.pp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838
  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 Sbrk(logicalSize: Longint): Mac_Ptr ;
  76. external 'InterfaceLib' name 'NewPtr';
  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. { include standard heap management }
  293. {$I heap.inc}
  294. {*****************************************************************************
  295. Low Level File Routines
  296. ****************************************************************************}
  297. function do_isdevice(handle:longint):boolean;
  298. begin
  299. do_isdevice:=false;
  300. end;
  301. { close a file from the handle value }
  302. procedure do_close(h : longint);
  303. begin
  304. {$ifdef MACOS_USE_STDCLIB}
  305. C_close(h);
  306. Errno2InOutRes;
  307. {$else}
  308. InOutRes:=1;
  309. if FSClose(h) = noErr then
  310. InOutRes:=0;
  311. {$endif}
  312. end;
  313. procedure do_erase(p : pchar);
  314. begin
  315. {$ifdef MACOS_USE_STDCLIB}
  316. remove(p);
  317. Errno2InoutRes;
  318. {$else}
  319. InOutRes:=1;
  320. {$endif}
  321. end;
  322. procedure do_rename(p1,p2 : pchar);
  323. begin
  324. {$ifdef MACOS_USE_STDCLIB}
  325. c_rename(p1,p2);
  326. Errno2InoutRes;
  327. {$else}
  328. InOutRes:=1;
  329. {$endif}
  330. end;
  331. function do_write(h,addr,len : longint) : longint;
  332. begin
  333. {$ifdef MACOS_USE_STDCLIB}
  334. do_write:= C_write(h, pointer(addr), len);
  335. Errno2InoutRes;
  336. {$else}
  337. InOutRes:=1;
  338. if FSWrite(h, len, Mac_Ptr(addr)) = noErr then
  339. InOutRes:=0;
  340. do_write:= len;
  341. {$endif}
  342. end;
  343. function do_read(h,addr,len : longint) : longint;
  344. var
  345. i: Longint;
  346. begin
  347. {$ifdef MACOS_USE_STDCLIB}
  348. len:= C_read(h, pointer(addr), len);
  349. Errno2InoutRes;
  350. // TEMP BUGFIX Exchange CR to LF.
  351. for i:= 0 to len-1 do
  352. if SignedBytePtr(ord(addr) + i)^ = 13 then
  353. SignedBytePtr(ord(addr) + i)^ := 10;
  354. do_read:= len;
  355. {$else}
  356. InOutRes:=1;
  357. if FSread(h, len, Mac_Ptr(addr)) = noErr then
  358. InOutRes:=0;
  359. do_read:= len;
  360. {$endif}
  361. end;
  362. function do_filepos(handle : longint) : longint;
  363. var
  364. pos: Longint;
  365. begin
  366. {$ifdef MACOS_USE_STDCLIB}
  367. {This returns the filepos without moving it.}
  368. do_filepos := lseek(handle, 0, SEEK_CUR);
  369. Errno2InoutRes;
  370. {$else}
  371. InOutRes:=1;
  372. if GetFPos(handle, pos) = noErr then
  373. InOutRes:=0;
  374. do_filepos:= pos;
  375. {$endif}
  376. end;
  377. procedure do_seek(handle,pos : longint);
  378. begin
  379. {$ifdef MACOS_USE_STDCLIB}
  380. lseek(handle, pos, SEEK_SET);
  381. Errno2InoutRes;
  382. {$else}
  383. InOutRes:=1;
  384. if SetFPos(handle, fsFromStart, pos) = noErr then
  385. InOutRes:=0;
  386. {$endif}
  387. end;
  388. function do_seekend(handle:longint):longint;
  389. begin
  390. {$ifdef MACOS_USE_STDCLIB}
  391. lseek(handle, 0, SEEK_END);
  392. Errno2InoutRes;
  393. {$else}
  394. InOutRes:=1;
  395. if SetFPos(handle, fsFromLEOF, 0) = noErr then
  396. InOutRes:=0;
  397. {$endif}
  398. end;
  399. function do_filesize(handle : longint) : longint;
  400. var
  401. aktfilepos: Longint;
  402. begin
  403. {$ifdef MACOS_USE_STDCLIB}
  404. aktfilepos:= lseek(handle, 0, SEEK_CUR);
  405. if errno = 0 then
  406. begin
  407. do_filesize := lseek(handle, 0, SEEK_END);
  408. Errno2InOutRes; {Report the error from this operation.}
  409. lseek(handle, aktfilepos, SEEK_SET); {Always try to move back,
  410. even in presence of error.}
  411. end
  412. else
  413. Errno2InOutRes;
  414. {$else}
  415. InOutRes:=1;
  416. if GetEOF(handle, pos) = noErr then
  417. InOutRes:=0;
  418. do_filesize:= pos;
  419. {$endif}
  420. end;
  421. { truncate at a given position }
  422. procedure do_truncate (handle,pos:longint);
  423. begin
  424. {$ifdef MACOS_USE_STDCLIB}
  425. ioctl(handle, FIOSETEOF, pointer(pos));
  426. Errno2InoutRes;
  427. {$else}
  428. InOutRes:=1;
  429. do_seek(handle,pos); //TODO: Is this needed (Does the user anticipate the filemarker is at the end?)
  430. if SetEOF(handle, pos) = noErr then
  431. InOutRes:=0;
  432. {$endif}
  433. end;
  434. {$ifndef MACOS_USE_STDCLIB}
  435. function FSpLocationFromFullPath(fullPathLength: Integer;
  436. fullPath: Mac_Ptr; var spec: FSSpec ):OSErr;
  437. var
  438. alias: AliasHandle;
  439. res: OSErr;
  440. wasChanged: Boolean;
  441. nullString: Str32;
  442. begin
  443. nullString:= '';
  444. res:= NewAliasMinimalFromFullPath(fullPathLength,
  445. fullPath, nullString, nullString, alias);
  446. if res = noErr then
  447. begin
  448. res:= ResolveAlias(nil, alias, spec, wasChanged);
  449. DisposeHandle(Mac_Handle(alias));
  450. end;
  451. FSpLocationFromFullPath:= res;
  452. end;
  453. {$endif}
  454. procedure do_open(var f;p:pchar;flags:longint);
  455. {
  456. filerec and textrec have both handle and mode as the first items so
  457. they could use the same routine for opening/creating.
  458. when (flags and $100) the file will be append
  459. when (flags and $1000) the file will be truncate/rewritten
  460. when (flags and $10000) there is no check for close (needed for textfiles)
  461. }
  462. var
  463. spec: FSSpec;
  464. creator, fileType: OSType;
  465. scriptTag: ScriptCode;
  466. refNum: Integer;
  467. res: OSErr;
  468. fh: Longint;
  469. oflags : longint;
  470. Const
  471. fsCurPerm = 0;
  472. smSystemScript = -1;
  473. begin
  474. // AllowSlash(p);
  475. { close first if opened }
  476. if ((flags and $10000)=0) then
  477. begin
  478. case filerec(f).mode of
  479. fminput,fmoutput,fminout : Do_Close(filerec(f).handle);
  480. fmclosed : ;
  481. else
  482. begin
  483. {not assigned}
  484. inoutres:=102;
  485. exit;
  486. end;
  487. end;
  488. end;
  489. { reset file handle }
  490. filerec(f).handle:=UnusedHandle;
  491. {$ifdef MACOS_USE_STDCLIB}
  492. { We do the conversion of filemodes here, concentrated on 1 place }
  493. case (flags and 3) of
  494. 0 : begin
  495. oflags :=O_RDONLY;
  496. filerec(f).mode:=fminput;
  497. end;
  498. 1 : begin
  499. oflags :=O_WRONLY;
  500. filerec(f).mode:=fmoutput;
  501. end;
  502. 2 : begin
  503. oflags :=O_RDWR;
  504. filerec(f).mode:=fminout;
  505. end;
  506. end;
  507. if (flags and $1000)=$1000 then
  508. oflags:=oflags or (O_CREAT or O_TRUNC)
  509. else if (flags and $100)=$100 then
  510. oflags:=oflags or (O_APPEND);
  511. { empty name is special }
  512. if p[0]=#0 then
  513. begin
  514. case FileRec(f).mode of
  515. fminput :
  516. FileRec(f).Handle:=StdInputHandle;
  517. fminout, { this is set by rewrite }
  518. fmoutput :
  519. FileRec(f).Handle:=StdOutputHandle;
  520. fmappend :
  521. begin
  522. FileRec(f).Handle:=StdOutputHandle;
  523. FileRec(f).mode:=fmoutput; {fool fmappend}
  524. end;
  525. end;
  526. exit;
  527. end;
  528. fh:= C_open(p, oflags);
  529. //TODO Perhaps handle readonly filesystems, as in sysunix.inc
  530. Errno2InOutRes;
  531. if fh <> -1 then
  532. filerec(f).handle:= fh
  533. else
  534. filerec(f).handle:= UnusedHandle;
  535. {$else}
  536. InOutRes:=1;
  537. //creator:= $522A6368; {'MPS ' -- MPW}
  538. //creator:= $74747874; {'ttxt'}
  539. creator:= $522A6368; {'R*ch' -- BBEdit}
  540. fileType:= $54455854; {'TEXT'}
  541. { reset file handle }
  542. filerec(f).handle:=UnusedHandle;
  543. res:= FSpLocationFromFullPath(StrLen(p), p, spec);
  544. if (res = noErr) or (res = fnfErr) then
  545. begin
  546. if FSpCreate(spec, creator, fileType, smSystemScript) = noErr then
  547. ;
  548. if FSpOpenDF(spec, fsCurPerm, refNum) = noErr then
  549. begin
  550. filerec(f).handle:= refNum;
  551. InOutRes:=0;
  552. end;
  553. end;
  554. if (filerec(f).handle=UnusedHandle) then
  555. begin
  556. //errno:=GetLastError;
  557. //Errno2InoutRes;
  558. end;
  559. {$endif}
  560. end;
  561. {*****************************************************************************
  562. UnTyped File Handling
  563. *****************************************************************************}
  564. {$i file.inc}
  565. {*****************************************************************************
  566. Typed File Handling
  567. *****************************************************************************}
  568. {$i typefile.inc}
  569. {*****************************************************************************
  570. Text File Handling
  571. *****************************************************************************}
  572. { should we consider #26 as the end of a file ? }
  573. {?? $DEFINE EOF_CTRLZ}
  574. {$i text.inc}
  575. {*****************************************************************************
  576. Directory Handling
  577. *****************************************************************************}
  578. procedure mkdir(const s:string);[IOCheck];
  579. begin
  580. InOutRes:=1;
  581. end;
  582. procedure rmdir(const s:string);[IOCheck];
  583. begin
  584. InOutRes:=1;
  585. end;
  586. procedure chdir(const s:string);[IOCheck];
  587. begin
  588. InOutRes:=1;
  589. end;
  590. procedure GetDir (DriveNr: byte; var Dir: ShortString);
  591. begin
  592. InOutRes := 1;
  593. end;
  594. {*****************************************************************************
  595. SystemUnit Initialization
  596. *****************************************************************************}
  597. procedure setup_arguments;
  598. begin
  599. end;
  600. procedure setup_environment;
  601. begin
  602. end;
  603. {*****************************************************************************
  604. System Dependent Exit code
  605. *****************************************************************************}
  606. Procedure system_exit;
  607. begin
  608. {$ifndef MACOS_USE_STDCLIB}
  609. if StandAlone <> 0 then
  610. ExitToShell;
  611. {$else}
  612. c_exit(exitcode); //exitcode is only utilized by an MPW tool
  613. {$endif}
  614. end;
  615. procedure SysInitStdIO;
  616. begin
  617. { Setup stdin, stdout and stderr }
  618. {$ifdef MACOS_USE_STDCLIB}
  619. OpenStdIO(Input,fmInput,StdInputHandle);
  620. OpenStdIO(Output,fmOutput,StdOutputHandle);
  621. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  622. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  623. {$endif }
  624. end;
  625. begin
  626. if false then //To save it from the dead code stripper
  627. begin
  628. //Included only to make them available for debugging in asm.
  629. Debugger;
  630. DebugStr('');
  631. end;
  632. { To be set if this is a GUI or console application }
  633. IsConsole := TRUE;
  634. { To be set if this is a library and not a program }
  635. IsLibrary := FALSE;
  636. StackLength := InitialStkLen;
  637. StackBottom := SPtr - StackLength;
  638. { Setup heap }
  639. if Mac_FreeMem - intern_heapsize < 30000 then
  640. Halt(3);
  641. theHeap:= Sbrk(intern_heapsize);
  642. if theHeap = nil then
  643. Halt(3); //According to MPW
  644. InitHeap;
  645. SysInitStdIO;
  646. { Setup environment and arguments }
  647. Setup_Environment;
  648. setup_arguments;
  649. { Reset IO Error }
  650. InOutRes:=0;
  651. errno:=0;
  652. {$ifdef HASVARIANT}
  653. initvariantmanager;
  654. {$endif HASVARIANT}
  655. end.
  656. {
  657. $Log$
  658. Revision 1.7 2003-09-27 11:52:35 peter
  659. * sbrk returns pointer
  660. Revision 1.6 2003/09/12 12:45:15 olle
  661. + filehandling complete
  662. + heaphandling complete
  663. + support for random
  664. * filehandling now uses filedecriptors in StdCLib
  665. * other minor changes
  666. - removed DEFINE MAC_SYS_RUNNABLE
  667. Revision 1.5 2003/01/13 17:18:55 olle
  668. + added support for rudimentary file handling
  669. Revision 1.4 2002/11/28 10:58:02 olle
  670. + added support for rudimentary heap
  671. Revision 1.3 2002/10/23 15:29:09 olle
  672. + added switch MAC_SYS_RUNABLE
  673. + added include of system.h etc
  674. + added standard globals
  675. + added dummy hook procedures
  676. Revision 1.2 2002/10/10 19:44:05 florian
  677. * changes from Olle to compile/link a simple program
  678. Revision 1.1 2002/10/02 21:34:31 florian
  679. * first dummy implementation
  680. }