system.pp 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 2002-2004 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 and OzTeX}
  29. FileNameCaseSensitive = false;
  30. maxExitCode = 65535;
  31. { include heap support headers }
  32. {$I heaph.inc}
  33. const
  34. { Default filehandles }
  35. UnusedHandle : Longint = -1;
  36. StdInputHandle : Longint = 0;
  37. StdOutputHandle : Longint = 1;
  38. StdErrorHandle : Longint = 2;
  39. sLineBreak = LineEnding;
  40. DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsCR;
  41. var
  42. argc : longint;
  43. argv : ppchar;
  44. envp : ppchar;
  45. {*********************************}
  46. {** MacOS specific functions **}
  47. {*********************************}
  48. {To be called at regular intervals, for lenghty tasks.
  49. Yield might give time for other tasks to run under the cooperative
  50. multitasked macos. For an MPW Tool, it also spinns the cursor.}
  51. procedure Yield;
  52. {To set mac file type and creator codes, to be used for files created
  53. by the FPC runtime library. They must be exactly 4 chars long.}
  54. procedure SetDefaultMacOSFiletype(ftype: ShortString);
  55. procedure SetDefaultMacOSCreator(creator: ShortString);
  56. {*********************************}
  57. {** Available features on macos **}
  58. {*********************************}
  59. var
  60. macosHasGestalt: Boolean;
  61. macosHasWaitNextEvent: Boolean;
  62. macosHasColorQD: Boolean;
  63. macosHasFPU: Boolean;
  64. macosSystemVersion: Integer;
  65. macosHasSysDebugger: Boolean = false;
  66. macosHasCFM: Boolean;
  67. macosHasAppleEvents: Boolean;
  68. macosHasAliasMgr: Boolean;
  69. macosHasFSSpec: Boolean;
  70. macosHasFindFolder: Boolean;
  71. macosHasScriptMgr: Boolean;
  72. macosNrOfScriptsInstalled: Integer;
  73. macosHasAppearance: Boolean;
  74. macosHasAppearance101: Boolean;
  75. macosHasAppearance11: Boolean;
  76. macosBootVolumeVRefNum: Integer;
  77. macosBootVolumeName: String[31];
  78. {
  79. MacOS paths
  80. ===========
  81. MacOS directory separator is a colon ":" which is the only character not
  82. allowed in filenames.
  83. A path containing no colon or which begins with a colon is a partial path.
  84. E g ":kalle:petter" ":kalle" "kalle"
  85. All other paths are full (absolute) paths. E g "HD:kalle:" "HD:"
  86. When generating paths, one is safe is one ensures that all partial paths
  87. begins with a colon, and all full paths ends with a colon.
  88. In full paths the first name (e g HD above) is the name of a mounted volume.
  89. These names are not unique, because, for instance, two diskettes with the
  90. same names could be inserted. This means that paths on MacOS is not
  91. waterproof. In case of equal names the first volume found will do.
  92. Two colons "::" are the relative path to the parent. Three is to the
  93. grandparent etc.
  94. }
  95. implementation
  96. {
  97. About the implementation
  98. ========================
  99. A MacOS application is assembled and linked by MPW (Macintosh
  100. Programmers Workshop), which nowadays is free to use. For info
  101. and download of MPW and MacOS api, see www.apple.com
  102. It can be linked to either a graphical user interface application,
  103. a standalone text only application (using SIOW) or
  104. to an MPW tool, this is entirely controlled by the linking step.
  105. It requires system 7 and CFM, which is always the case for PowerPC.
  106. If a m68k version would be implemented, it would save a lot
  107. of efforts if it also uses CFM. This System.pp should, with
  108. minor modifications, probably work with m68k.
  109. Initial working directory is the directory of the application,
  110. or for an MPWTool, the working directory as set by the
  111. Directory command in MPW.
  112. Note about working directory. There is a facility in MacOS which
  113. manages a working directory for an application, initially set to
  114. the applications directory, or for an MPWTool, the tool's directory.
  115. However, this requires the application to have a unique application
  116. signature (creator code), to distinguish its working directory
  117. from working directories of other applications. Due to the fact
  118. that casual applications are anonymous in this sense (without an
  119. application signature), this facility will not work. Also, this
  120. working directory facility is not present in Carbon. Hence we
  121. will manage a working directory by our self.
  122. Deviations
  123. ==========
  124. In current implementation, working directory is stored as
  125. directory id. This means there is a possibility the user moves the
  126. working directory or a parent to it, while the application uses it.
  127. Then the path to the wd suddenly changes. This is AFAIK not in
  128. accordance with other OS's. Although this is a minor caveat,
  129. it is mentioned here. To overcome this the wd could be stored
  130. as a path instead, but this imposes translations from fullpath
  131. to directory ID each time the filesystem is accessed.
  132. The initial working directory for an MPWTool, as considered by
  133. FPC, is different from the MacOS working directory facility,
  134. see above.
  135. Possible improvements:
  136. =====================
  137. Perhaps handle readonly filesystems, as in sysunix.inc
  138. }
  139. {This implementation uses StdCLib, which is included in the MPW.}
  140. {$define MACOS_USE_STDCLIB}
  141. {******** include system independent routines **********}
  142. {$I system.inc}
  143. {*********************** MacOS API *********************}
  144. {Below is some MacOS API routines included for internal use.
  145. Note, because the System unit is the most low level, it should not
  146. depend on any other units, and thus the macos api must be accessed
  147. as an include file and not a unit.}
  148. {$I macostp.inc}
  149. {If the Apples Universal Interfaces are used, the qd variable is required
  150. to be allocated somewhere, so we do it here for the convenience to the user.}
  151. var
  152. qd: QDGlobals; cvar;
  153. {$ifdef MACOS_USE_STDCLIB}
  154. {************** API to StdCLib in MacOS ***************}
  155. {The reason StdCLib is used is that it can easily be connected
  156. to either SIOW or, in case of MPWTOOL, to MPW }
  157. {The prefix C_ or c_ is used where names conflicts with pascal
  158. keywords and names. Suffix Ptr is added for pointer to a type.}
  159. type
  160. size_t = Longint;
  161. off_t = Longint;
  162. C_int = Longint;
  163. C_short = Integer;
  164. C_long = Longint;
  165. C_unsigned_int = Cardinal;
  166. var
  167. errno: C_int; external name 'errno';
  168. MacOSErr: C_short; external name 'MacOSErr';
  169. const
  170. _IOFBF = $00;
  171. _IOLBF = $40;
  172. _IONBF = $04;
  173. O_RDONLY = $00; // Open for reading only.
  174. O_WRONLY = $01; // Open for writing only.
  175. O_RDWR = $02; // Open for reading & writing.
  176. O_APPEND = $08; // Write to the end of the file.
  177. O_RSRC = $10; // Open the resource fork.
  178. O_ALIAS = $20; // Open alias file.
  179. O_CREAT = $100; // Open or create a file.
  180. O_TRUNC = $200; // Open and truncate to zero length.
  181. O_EXCL = $400; // Create file only; fail if exists.
  182. O_BINARY = $800; // Open as a binary stream.
  183. O_NRESOLVE = $4000; // Don't resolve any aliases.
  184. SEEK_SET = 0;
  185. SEEK_CUR = 1;
  186. SEEK_END = 2;
  187. FIOINTERACTIVE = $00006602; // If device is interactive
  188. FIOBUFSIZE = $00006603; // Return optimal buffer size
  189. FIOFNAME = $00006604; // Return filename
  190. FIOREFNUM = $00006605; // Return fs refnum
  191. FIOSETEOF = $00006606; // Set file length
  192. TIOFLUSH = $00007408; // discard unread input. arg is ignored
  193. function c_open(path: PChar; oflag: C_int): C_int; cdecl;
  194. external 'StdCLib' name 'open';
  195. function c_close(filedes: C_int): C_int; cdecl;
  196. external 'StdCLib' name 'close';
  197. function c_write(filedes: C_int; buf: pointer; nbyte: size_t): size_t; cdecl;
  198. external 'StdCLib' name 'write';
  199. function c_read(filedes: C_int; buf: pointer; nbyte: size_t): size_t; cdecl;
  200. external 'StdCLib' name 'read';
  201. function lseek(filedes: C_int; offset: off_t; whence: C_int): off_t; cdecl;
  202. external 'StdCLib' name 'lseek';
  203. function ioctl(filedes: C_int; cmd: C_unsigned_int; arg: pointer): C_int; cdecl;
  204. external 'StdCLib' name 'ioctl';
  205. function remove(filename: PChar): C_int; cdecl;
  206. external 'StdCLib';
  207. function c_rename(old, c_new: PChar): C_int; cdecl;
  208. external 'StdCLib' name 'rename';
  209. procedure c_exit(status: C_int); cdecl;
  210. external 'StdCLib' name 'exit';
  211. {cdecl is actually only needed for m68k}
  212. var
  213. {Is set to zero for MPWTool, nonzero otherwise.}
  214. StandAlone: C_int; external name 'StandAlone';
  215. CONST
  216. Sys_EPERM = 1; { No permission match }
  217. Sys_ENOENT = 2; { No such file or directory }
  218. Sys_ENORSRC = 3; { Resource not found *}
  219. Sys_EINTR = 4; { System service interrupted *}
  220. Sys_EIO = 5; { I/O error }
  221. Sys_ENXIO = 6; { No such device or address }
  222. Sys_E2BIG = 7; { Insufficient space for return argument * }
  223. Sys_ENOEXEC = 8; { File not executable * }
  224. Sys_EBADF = 9; { Bad file number }
  225. Sys_ECHILD = 10; { No child processes }
  226. Sys_EAGAIN = 11; { Resource temporarily unavailable * }
  227. Sys_ENOMEM = 12; { Not enough space * }
  228. Sys_EACCES = 13; { Permission denied }
  229. Sys_EFAULT = 14; { Illegal filename * }
  230. Sys_ENOTBLK = 15; { Block device required }
  231. Sys_EBUSY = 16; { Device or resource busy }
  232. Sys_EEXIST = 17; { File exists }
  233. Sys_EXDEV = 18; { Cross-device link }
  234. Sys_ENODEV = 19; { No such device }
  235. Sys_ENOTDIR = 20; { Not a directory }
  236. Sys_EISDIR = 21; { Is a directory }
  237. Sys_EINVAL = 22; { Invalid parameter * }
  238. Sys_ENFILE = 23; { File table overflow }
  239. Sys_EMFILE = 24; { Too many open files }
  240. Sys_ENOTTY = 25; { Not a typewriter }
  241. Sys_ETXTBSY = 26; { Text file busy. The new process was
  242. a pure procedure (shared text) file which was
  243. open for writing by another process, or file
  244. which was open for writing by another process,
  245. or while the pure procedure file was being
  246. executed an open(2) call requested write access
  247. requested write access.
  248. (Probably not applicable on macos)}
  249. Sys_EFBIG = 27; { File too large }
  250. Sys_ENOSPC = 28; { No space left on device }
  251. Sys_ESPIPE = 29; { Illegal seek }
  252. Sys_EROFS = 30; { Read-only file system }
  253. Sys_EMLINK = 31; { Too many links }
  254. Sys_EPIPE = 32; { Broken pipe }
  255. Sys_EDOM = 33; { Math argument out of domain of func }
  256. Sys_ERANGE = 34; { Math result not representable }
  257. { Note * is slightly different, compared to rtl/sunos/errno.inc}
  258. {$endif}
  259. {*********************** Macutils *********************}
  260. {And also include the same utilities as in the macutils.pp unit.}
  261. var
  262. {emulated working directory}
  263. workingDirectorySpec: FSSpec; cvar;
  264. {Also declared in macutils.pp as external. Declared here to be available
  265. to macutils.inc and below in this file.}
  266. {$I macutils.inc}
  267. {******************************************************}
  268. function GetAppFileLocation (var spec: FSSpec): Boolean;
  269. {Requires >= System 7}
  270. var
  271. PSN: ProcessSerialNumber;
  272. info: ProcessInfoRec;
  273. appFileRefNum: Integer;
  274. appName: Str255;
  275. dummy: Mac_Handle;
  276. begin
  277. begin
  278. PSN.highLongOfPSN := 0;
  279. PSN.lowLongOfPSN := kCurrentProcess;
  280. info.processInfoLength := SizeOf(info);
  281. info.processName := nil;
  282. info.processAppSpec := @spec;
  283. if GetProcessInformation(PSN, info) = noErr then
  284. begin
  285. spec.name := '';
  286. GetAppFileLocation := true;
  287. end
  288. else
  289. GetAppFileLocation := false;
  290. end
  291. end;
  292. Procedure Errno2InOutRes;
  293. {
  294. Convert ErrNo error to the correct InOutRes value.
  295. It seems that some of the errno is, in macos,
  296. used for other purposes than its original definition.
  297. }
  298. begin
  299. if errno = 0 then { Else it will go through all the cases }
  300. exit;
  301. case Errno of
  302. Sys_ENFILE,
  303. Sys_EMFILE : Inoutres:=4;
  304. Sys_ENOENT : Inoutres:=2;
  305. Sys_EBADF : Inoutres:=6;
  306. Sys_ENOMEM,
  307. Sys_EFAULT : Inoutres:=217; //TODO Exchange to something better
  308. Sys_EINVAL : Inoutres:=218; //TODO RTE 218 doesn't exist
  309. Sys_EAGAIN,
  310. Sys_ENOSPC : Inoutres:=101;
  311. Sys_ENOTDIR : Inoutres:=3;
  312. Sys_EPERM,
  313. Sys_EROFS,
  314. Sys_EEXIST,
  315. Sys_EISDIR,
  316. Sys_EINTR, //Happens when attempt to rename a file fails
  317. Sys_EBUSY, //Happens when attempt to remove a locked file
  318. Sys_EACCES,
  319. Sys_EMLINK : Inoutres:=5; //Happens when attempt to remove open file
  320. Sys_ENXIO : InOutRes:=152;
  321. Sys_ESPIPE : InOutRes:=156; //Illegal seek
  322. else
  323. InOutRes := Integer(errno);//TODO Exchange to something better
  324. end;
  325. errno:=0;
  326. end;
  327. Procedure OSErr2InOutRes(err: OSErr);
  328. begin
  329. InOutRes:= MacOSErr2RTEerr(err);
  330. end;
  331. function FSpLocationFromFullPath(fullPathLength: Integer;
  332. fullPath: Mac_Ptr; var spec: FSSpec ):OSErr;
  333. var
  334. alias: AliasHandle;
  335. res: OSErr;
  336. wasChanged: Boolean;
  337. nullString: Str32;
  338. begin
  339. nullString:= '';
  340. res:= NewAliasMinimalFromFullPath(fullPathLength,
  341. fullPath, nullString, nullString, alias);
  342. if res = noErr then
  343. begin
  344. res:= ResolveAlias(nil, alias, spec, wasChanged);
  345. DisposeHandle(Mac_Handle(alias));
  346. end;
  347. FSpLocationFromFullPath:= res;
  348. end;
  349. {*****************************************************************************
  350. MacOS specific functions
  351. *****************************************************************************}
  352. var
  353. defaultCreator: OSType = $4D505320; {'MPS ' MPW Shell}
  354. //defaultCreator: OSType = $74747874; {'ttxt' Simple Text}
  355. defaultFileType: OSType = $54455854; {'TEXT'}
  356. procedure Yield;
  357. begin
  358. if StandAlone = 0 then
  359. SpinCursor(1);
  360. end;
  361. procedure SetDefaultMacOSFiletype(ftype: ShortString);
  362. begin
  363. if Length(ftype) = 4 then
  364. defaultFileType:= PLongWord(@ftype[1])^;
  365. end;
  366. procedure SetDefaultMacOSCreator(creator: ShortString);
  367. begin
  368. if Length(creator) = 4 then
  369. defaultCreator:= PLongWord(@creator[1])^;
  370. end;
  371. {*****************************************************************************
  372. ParamStr/Randomize
  373. *****************************************************************************}
  374. { number of args }
  375. function paramcount : longint;
  376. begin
  377. paramcount := argc - 1;
  378. //paramcount:=0;
  379. end;
  380. { argument number l }
  381. function paramstr(l : longint) : string;
  382. begin
  383. if (l>=0) and (l+1<=argc) then
  384. paramstr:=strpas(argv[l])
  385. else
  386. paramstr:='';
  387. end;
  388. { set randseed to a new pseudo random value }
  389. procedure randomize;
  390. begin
  391. randseed:= Cardinal(TickCount);
  392. end;
  393. {*****************************************************************************
  394. Heap Management
  395. *****************************************************************************}
  396. var
  397. { Pointer to a block allocated with the MacOS Memory Manager, which
  398. is used as the initial FPC heap. }
  399. theHeap: Mac_Ptr;
  400. intern_heapsize : longint;external name 'HEAPSIZE';
  401. { first address of heap }
  402. function getheapstart:pointer;
  403. begin
  404. getheapstart:= theHeap;
  405. end;
  406. { current length of heap }
  407. function getheapsize:longint;
  408. begin
  409. getheapsize:= intern_heapsize ;
  410. end;
  411. {*****************************************************************************
  412. OS Memory allocation / deallocation
  413. ****************************************************************************}
  414. { function to allocate size bytes more for the program }
  415. { must return the first address of new data space or nil if failed }
  416. function SysOSAlloc(size: ptrint): pointer;
  417. begin
  418. result := NewPtr(size);
  419. end;
  420. {$define HAS_SYSOSFREE}
  421. procedure SysOSFree(p: pointer; size: ptrint);
  422. begin
  423. DisposePtr(p);
  424. end;
  425. { include standard heap management }
  426. {$I heap.inc}
  427. {*****************************************************************************
  428. Low Level File Routines
  429. ****************************************************************************}
  430. function do_isdevice(handle:longint):boolean;
  431. begin
  432. do_isdevice:=false;
  433. end;
  434. { close a file from the handle value }
  435. procedure do_close(h : longint);
  436. var
  437. err: OSErr;
  438. {No error handling, according to the other targets, which seems reasonable,
  439. because close might be used to clean up after an error.}
  440. begin
  441. {$ifdef MACOS_USE_STDCLIB}
  442. c_close(h);
  443. // Errno2InOutRes;
  444. {$else}
  445. err:= FSClose(h);
  446. // OSErr2InOutRes(err);
  447. {$endif}
  448. end;
  449. procedure do_erase(p : pchar);
  450. var
  451. spec: FSSpec;
  452. err: OSErr;
  453. res: Integer;
  454. begin
  455. res:= PathArgToFSSpec(p, spec);
  456. if (res = 0) then
  457. begin
  458. if not IsDirectory(spec) then
  459. begin
  460. err:= FSpDelete(spec);
  461. OSErr2InOutRes(err);
  462. end
  463. else
  464. InOutRes:= 2;
  465. end
  466. else
  467. InOutRes:=res;
  468. end;
  469. procedure do_rename(p1,p2 : pchar);
  470. var
  471. s1,s2: AnsiString;
  472. begin
  473. {$ifdef MACOS_USE_STDCLIB}
  474. InOutRes:= PathArgToFullPath(p1, s1);
  475. if InOutRes <> 0 then
  476. exit;
  477. InOutRes:= PathArgToFullPath(p2, s2);
  478. if InOutRes <> 0 then
  479. exit;
  480. c_rename(PChar(s1),PChar(s2));
  481. Errno2InoutRes;
  482. {$else}
  483. InOutRes:=1;
  484. {$endif}
  485. end;
  486. function do_write(h:longint;addr:pointer;len : longint) : longint;
  487. begin
  488. {$ifdef MACOS_USE_STDCLIB}
  489. do_write:= c_write(h, addr, len);
  490. Errno2InoutRes;
  491. {$else}
  492. InOutRes:=1;
  493. if FSWrite(h, len, Mac_Ptr(addr)) = noErr then
  494. InOutRes:=0;
  495. do_write:= len;
  496. {$endif}
  497. end;
  498. function do_read(h:longint;addr:pointer;len : longint) : longint;
  499. var
  500. i: Longint;
  501. begin
  502. {$ifdef MACOS_USE_STDCLIB}
  503. len:= c_read(h, addr, len);
  504. Errno2InoutRes;
  505. do_read:= len;
  506. {$else}
  507. InOutRes:=1;
  508. if FSread(h, len, Mac_Ptr(addr)) = noErr then
  509. InOutRes:=0;
  510. do_read:= len;
  511. {$endif}
  512. end;
  513. function do_filepos(handle : longint) : longint;
  514. var
  515. pos: Longint;
  516. begin
  517. {$ifdef MACOS_USE_STDCLIB}
  518. {This returns the filepos without moving it.}
  519. do_filepos := lseek(handle, 0, SEEK_CUR);
  520. Errno2InoutRes;
  521. {$else}
  522. InOutRes:=1;
  523. if GetFPos(handle, pos) = noErr then
  524. InOutRes:=0;
  525. do_filepos:= pos;
  526. {$endif}
  527. end;
  528. procedure do_seek(handle,pos : longint);
  529. begin
  530. {$ifdef MACOS_USE_STDCLIB}
  531. lseek(handle, pos, SEEK_SET);
  532. Errno2InoutRes;
  533. {$else}
  534. InOutRes:=1;
  535. if SetFPos(handle, fsFromStart, pos) = noErr then
  536. InOutRes:=0;
  537. {$endif}
  538. end;
  539. function do_seekend(handle:longint):longint;
  540. begin
  541. {$ifdef MACOS_USE_STDCLIB}
  542. do_seekend:= lseek(handle, 0, SEEK_END);
  543. Errno2InoutRes;
  544. {$else}
  545. InOutRes:=1;
  546. if SetFPos(handle, fsFromLEOF, 0) = noErr then
  547. InOutRes:=0;
  548. {TODO Resulting file position is to be returned.}
  549. {$endif}
  550. end;
  551. function do_filesize(handle : longint) : longint;
  552. var
  553. aktfilepos: Longint;
  554. begin
  555. {$ifdef MACOS_USE_STDCLIB}
  556. aktfilepos:= lseek(handle, 0, SEEK_CUR);
  557. if errno = 0 then
  558. begin
  559. do_filesize := lseek(handle, 0, SEEK_END);
  560. Errno2InOutRes; {Report the error from this operation.}
  561. lseek(handle, aktfilepos, SEEK_SET); {Always try to move back,
  562. even in presence of error.}
  563. end
  564. else
  565. Errno2InOutRes;
  566. {$else}
  567. InOutRes:=1;
  568. if GetEOF(handle, pos) = noErr then
  569. InOutRes:=0;
  570. do_filesize:= pos;
  571. {$endif}
  572. end;
  573. { truncate at a given position }
  574. procedure do_truncate (handle,pos:longint);
  575. begin
  576. {$ifdef MACOS_USE_STDCLIB}
  577. ioctl(handle, FIOSETEOF, pointer(pos));
  578. Errno2InoutRes;
  579. {$else}
  580. InOutRes:=1;
  581. do_seek(handle,pos); //TODO: Is this needed (Does the user anticipate the filemarker is at the end?)
  582. if SetEOF(handle, pos) = noErr then
  583. InOutRes:=0;
  584. {$endif}
  585. end;
  586. procedure do_open(var f;p:pchar;flags:longint);
  587. {
  588. filerec and textrec have both handle and mode as the first items so
  589. they could use the same routine for opening/creating.
  590. when (flags and $100) the file will be append
  591. when (flags and $1000) the file will be truncate/rewritten
  592. when (flags and $10000) there is no check for close (needed for textfiles)
  593. }
  594. var
  595. scriptTag: ScriptCode;
  596. refNum: Integer;
  597. err: OSErr;
  598. res: Integer;
  599. spec: FSSpec;
  600. fh: Longint;
  601. oflags : longint;
  602. fullPath: AnsiString;
  603. finderInfo: FInfo;
  604. begin
  605. // AllowSlash(p);
  606. { close first if opened }
  607. if ((flags and $10000)=0) then
  608. begin
  609. case filerec(f).mode of
  610. fminput,fmoutput,fminout : Do_Close(filerec(f).handle);
  611. fmclosed : ;
  612. else
  613. begin
  614. {not assigned}
  615. inoutres:=102;
  616. exit;
  617. end;
  618. end;
  619. end;
  620. { reset file handle }
  621. filerec(f).handle:=UnusedHandle;
  622. {$ifdef MACOS_USE_STDCLIB}
  623. { We do the conversion of filemodes here, concentrated on 1 place }
  624. case (flags and 3) of
  625. 0 : begin
  626. oflags :=O_RDONLY;
  627. filerec(f).mode:=fminput;
  628. end;
  629. 1 : begin
  630. oflags :=O_WRONLY;
  631. filerec(f).mode:=fmoutput;
  632. end;
  633. 2 : begin
  634. oflags :=O_RDWR;
  635. filerec(f).mode:=fminout;
  636. end;
  637. end;
  638. if (flags and $1000)=$1000 then
  639. oflags:=oflags or (O_CREAT or O_TRUNC)
  640. else if (flags and $100)=$100 then
  641. oflags:=oflags or (O_APPEND);
  642. { empty name is special }
  643. if p[0]=#0 then
  644. begin
  645. case FileRec(f).mode of
  646. fminput :
  647. FileRec(f).Handle:=StdInputHandle;
  648. fminout, { this is set by rewrite }
  649. fmoutput :
  650. FileRec(f).Handle:=StdOutputHandle;
  651. fmappend :
  652. begin
  653. FileRec(f).Handle:=StdOutputHandle;
  654. FileRec(f).mode:=fmoutput; {fool fmappend}
  655. end;
  656. end;
  657. exit;
  658. end
  659. else
  660. begin
  661. InOutRes:= PathArgToFSSpec(p, spec);
  662. if (InOutRes = 0) or (InOutRes = 2) then
  663. begin
  664. err:= FSpGetFullPath(spec, fullPath, false);
  665. InOutRes:= MacOSErr2RTEerr(err);
  666. end;
  667. if InOutRes <> 0 then
  668. exit;
  669. p:= PChar(fullPath);
  670. if FileRec(f).mode in [fmoutput, fminout, fmappend] then
  671. begin
  672. {Since opening of an existing file will not change filetype and creator,
  673. it is set here. Otherwise overwritten darwin files will not get filetype
  674. TEXT. This is not done when only opening file for reading.}
  675. FSpGetFInfo(spec, finderInfo);
  676. finderInfo.fdType:= defaultFileType;
  677. finderInfo.fdCreator:= defaultCreator;
  678. FSpSetFInfo(spec, finderInfo);
  679. end;
  680. end;
  681. fh:= c_open(p, oflags);
  682. if (fh = -1) and (errno = Sys_EROFS) and ((oflags and O_RDWR)<>0) then
  683. begin
  684. oflags:=oflags and not(O_RDWR);
  685. fh:= c_open(p, oflags);
  686. end;
  687. Errno2InOutRes;
  688. if fh <> -1 then
  689. filerec(f).handle:= fh
  690. else
  691. filerec(f).handle:= UnusedHandle;
  692. {$else}
  693. InOutRes:=1;
  694. { reset file handle }
  695. filerec(f).handle:=UnusedHandle;
  696. res:= FSpLocationFromFullPath(StrLen(p), p, spec);
  697. if (res = noErr) or (res = fnfErr) then
  698. begin
  699. if FSpCreate(spec, defaultCreator, defaultFileType, smSystemScript) = noErr then
  700. ;
  701. if FSpOpenDF(spec, fsCurPerm, refNum) = noErr then
  702. begin
  703. filerec(f).handle:= refNum;
  704. InOutRes:=0;
  705. end;
  706. end;
  707. if (filerec(f).handle=UnusedHandle) then
  708. begin
  709. //errno:=GetLastError;
  710. //Errno2InoutRes;
  711. end;
  712. {$endif}
  713. end;
  714. {*****************************************************************************
  715. UnTyped File Handling
  716. *****************************************************************************}
  717. {$i file.inc}
  718. {*****************************************************************************
  719. Typed File Handling
  720. *****************************************************************************}
  721. {$i typefile.inc}
  722. {*****************************************************************************
  723. Text File Handling
  724. *****************************************************************************}
  725. { #26 is not end of a file in MacOS ! }
  726. {$i text.inc}
  727. {*****************************************************************************
  728. Directory Handling
  729. *****************************************************************************}
  730. procedure mkdir(const s:string);[IOCheck];
  731. var
  732. spec: FSSpec;
  733. createdDirID: Longint;
  734. err: OSErr;
  735. res: Integer;
  736. begin
  737. If (s='') or (InOutRes <> 0) then
  738. exit;
  739. res:= PathArgToFSSpec(s, spec);
  740. if (res = 0) or (res = 2) then
  741. begin
  742. err:= FSpDirCreate(spec, smSystemScript, createdDirID);
  743. OSErr2InOutRes(err);
  744. end
  745. else
  746. InOutRes:=res;
  747. end;
  748. procedure rmdir(const s:string);[IOCheck];
  749. var
  750. spec: FSSpec;
  751. err: OSErr;
  752. res: Integer;
  753. begin
  754. If (s='') or (InOutRes <> 0) then
  755. exit;
  756. res:= PathArgToFSSpec(s, spec);
  757. if (res = 0) then
  758. begin
  759. if IsDirectory(spec) then
  760. begin
  761. err:= FSpDelete(spec);
  762. OSErr2InOutRes(err);
  763. end
  764. else
  765. InOutRes:= 20;
  766. end
  767. else
  768. InOutRes:=res;
  769. end;
  770. procedure chdir(const s:string);[IOCheck];
  771. var
  772. spec, newDirSpec: FSSpec;
  773. err: OSErr;
  774. res: Integer;
  775. begin
  776. if (s='') or (InOutRes <> 0) then
  777. exit;
  778. res:= PathArgToFSSpec(s, spec);
  779. if (res = 0) or (res = 2) then
  780. begin
  781. { The fictive file x is appended to the directory name to make
  782. FSMakeFSSpec return a FSSpec to a file in the directory.
  783. Then by clearing the name, the FSSpec then
  784. points to the directory. It doesn't matter whether x exists or not.}
  785. err:= FSMakeFSSpec (spec.vRefNum, spec.parID, ':'+spec.name+':x', newDirSpec);
  786. if (err = noErr) or (err = fnfErr) then
  787. begin
  788. workingDirectorySpec:= newDirSpec;
  789. workingDirectorySpec.name:='';
  790. InOutRes:= 0;
  791. end
  792. else
  793. begin
  794. {E g if the directory doesn't exist.}
  795. OSErr2InOutRes(err);
  796. end;
  797. end
  798. else
  799. InOutRes:=res;
  800. end;
  801. procedure getDir (DriveNr: byte; var Dir: ShortString);
  802. var
  803. fullPath: AnsiString;
  804. pathHandleSize: Longint;
  805. begin
  806. if FSpGetFullPath(workingDirectorySpec, fullPath, false) <> noErr then
  807. Halt(3); {exit code 3 according to MPW}
  808. if Length(fullPath) <= 255 then {because dir is ShortString}
  809. InOutRes := 0
  810. else
  811. InOutRes := 1; //TODO Exchange to something better
  812. dir:= fullPath;
  813. end;
  814. {*****************************************************************************
  815. SystemUnit Initialization
  816. *****************************************************************************}
  817. procedure pascalmain; external name 'PASCALMAIN';
  818. {Main entry point in C style, needed to capture program parameters.
  819. For this to work, the system unit must be before the main program
  820. in the linking order.}
  821. procedure main(argcparam: Longint; argvparam: ppchar; envpparam: ppchar); cdecl; [public];
  822. begin
  823. argc:= argcparam;
  824. argv:= argvparam;
  825. envp:= envpparam;
  826. pascalmain; {run the pascal main program}
  827. end;
  828. procedure setup_arguments;
  829. begin
  830. {Nothing needs to be done here.}
  831. end;
  832. procedure setup_environment;
  833. begin
  834. end;
  835. { FindSysFolder returns the (real) vRefNum, and the DirID of the current
  836. system folder. It uses the Folder Manager if present, otherwise it falls
  837. back to SysEnvirons. It returns zero on success, otherwise a standard
  838. system error. }
  839. function FindSysFolder(var foundVRefNum: Integer; var foundDirID: Longint): OSErr;
  840. var
  841. gesResponse: Longint;
  842. envRec: SysEnvRec;
  843. myWDPB: WDPBRec;
  844. volName: String[34];
  845. err: OSErr;
  846. begin
  847. foundVRefNum := 0;
  848. foundDirID := 0;
  849. if macosHasGestalt
  850. and (Gestalt (FourCharCodeToLongword(gestaltFindFolderAttr), gesResponse) = noErr)
  851. and BitIsSet (gesResponse, gestaltFindFolderPresent) then
  852. begin { Does Folder Manager exist? }
  853. err := FindFolder (kOnSystemDisk, FourCharCodeToLongword(kSystemFolderType),
  854. kDontCreateFolder, foundVRefNum, foundDirID);
  855. end
  856. else
  857. begin
  858. { Gestalt can't give us the answer, so we resort to SysEnvirons }
  859. err := SysEnvirons (curSysEnvVers, envRec);
  860. if (err = noErr) then
  861. begin
  862. myWDPB.ioVRefNum := envRec.sysVRefNum;
  863. volName := '';
  864. myWDPB.ioNamePtr := @volName;
  865. myWDPB.ioWDIndex := 0;
  866. myWDPB.ioWDProcID := 0;
  867. err := PBGetWDInfoSync (@myWDPB);
  868. if (err = noErr) then
  869. begin
  870. foundVRefNum := myWDPB.ioWDVRefNum;
  871. foundDirID := myWDPB.ioWDDirID;
  872. end;
  873. end;
  874. end;
  875. FindSysFolder:= err;
  876. end;
  877. procedure InvestigateSystem;
  878. {$IFDEF CPUM68K}
  879. const
  880. _GestaltDispatch = $A0AD;
  881. _WaitNextEvent = $A860;
  882. _ScriptUtil = $A8B5;
  883. qdOffscreenTrap = $AB1D;
  884. {$ENDIF}
  885. var
  886. err: Integer;
  887. response: Longint;
  888. {$IFDEF CPUM68K}
  889. environs: SysEnvRec;
  890. {$ENDIF}
  891. {Vi rŠknar med att man kšr pŒ minst system 6.0.5. DŒ finns bŒde Gestalt och GDevice med.}
  892. {Enligt Change Histrory Šr MacOS 6.0.5 mera konsistent mellan maskinmodellerna Šn fšregŒende system}
  893. begin
  894. {$IFDEF CPUM68K}
  895. macosHasGestalt := TrapAvailable(_GestaltDispatch);
  896. {$ELSE}
  897. macosHasGestalt := true; {There is always Gestalt on PowerPC}
  898. {$ENDIF}
  899. if not macosHasGestalt then (* If we don't have Gestalt, then we can't have any System 7 features *)
  900. begin
  901. {$IFDEF CPUM68K}
  902. { Detta kan endast gŠlla pŒ en 68K maskin.}
  903. macosHasScriptMgr := TrapAvailable(_ScriptUtil);
  904. macosNrOfScriptsInstalled := 1; (* assume only Roman script, to start with *)
  905. err := SysEnvirons(1, environs);
  906. if err = noErr then
  907. begin
  908. if environs.machineType < 0 then { gammalt ROM}
  909. macosHasWaitNextEvent := FALSE
  910. else
  911. macosHasWaitNextEvent := TrapAvailable(_WaitNextEvent);
  912. macosHasColorQD := environs.hasColorQD;
  913. macosHasFPU := environs.hasFPU;
  914. macosSystemVersion := environs.systemVersion;
  915. end
  916. else
  917. begin
  918. macosHasWaitNextEvent := FALSE;
  919. macosHasColorQD := FALSE;
  920. macosHasFPU := FALSE;
  921. macosSystemVersion := 0;
  922. end;
  923. macosHasSysDebugger := (LongintPtr(MacJmp)^ <> 0);
  924. macosHasCFM := false;
  925. macosHasAppleEvents := false;
  926. macosHasAliasMgr := false;
  927. macosHasFSSpec := false;
  928. macosHasFindFolder := false;
  929. macosHasAppearance := false;
  930. macosHasAppearance101 := false;
  931. macosHasAppearance11 := false;
  932. {$IFDEF THINK_PASCAL}
  933. if (macosHasScriptMgr) then
  934. macosNrOfScriptsInstalled := GetEnvirons(smEnabled);
  935. {$ELSE}
  936. if (macosHasScriptMgr) then
  937. macosNrOfScriptsInstalled := GetScriptManagerVariable(smEnabled); {Gamla rutinnamnet var GetEnvirons.}
  938. {$ENDIF}
  939. {$ENDIF}
  940. end
  941. else
  942. begin
  943. macosHasScriptMgr := Gestalt(FourCharCodeToLongword(gestaltScriptMgrVersion), response) = noErr; {Fšr att ta reda pŒ om script mgr finns.}
  944. macosNrOfScriptsInstalled := 1; (* assume only Roman script, to start with *)
  945. macosHasWaitNextEvent := true;
  946. if Gestalt(FourCharCodeToLongword(gestaltSystemVersion), response) = noErr then
  947. macosSystemVersion := response
  948. else
  949. macosSystemVersion := 0; {Borde inte kunna hŠnda.}
  950. if Gestalt(FourCharCodeToLongword(gestaltOSAttr), response) = noErr then
  951. macosHasSysDebugger := BitIsSet(response, gestaltSysDebuggerSupport)
  952. else
  953. macosHasSysDebugger := false;
  954. if Gestalt(FourCharCodeToLongword(gestaltQuickdrawVersion), response) = noErr then
  955. macosHasColorQD := (response >= $0100)
  956. else
  957. macosHasColorQD := false;
  958. if Gestalt(FourCharCodeToLongword(gestaltFPUType), response) = noErr then
  959. macosHasFPU := (response <> gestaltNoFPU)
  960. else
  961. macosHasFPU := false;
  962. if Gestalt(FourCharCodeToLongword(gestaltCFMAttr), response) = noErr then
  963. macosHasCFM := BitIsSet(response, gestaltCFMPresent)
  964. else
  965. macosHasCFM := false;
  966. macosHasAppleEvents := Gestalt(FourCharCodeToLongword(gestaltAppleEventsAttr), response) = noErr;
  967. macosHasAliasMgr := Gestalt(FourCharCodeToLongword(gestaltAliasMgrAttr), response) = noErr;
  968. if Gestalt(FourCharCodeToLongword(gestaltFSAttr), response) = noErr then
  969. macosHasFSSpec := BitIsSet(response, gestaltHasFSSpecCalls)
  970. else
  971. macosHasFSSpec := false;
  972. macosHasFindFolder := Gestalt(FourCharCodeToLongword(gestaltFindFolderAttr), response) = noErr;
  973. if macosHasScriptMgr then
  974. begin
  975. err := Gestalt(FourCharCodeToLongword(gestaltScriptCount), response);
  976. if (err = noErr) then
  977. macosNrOfScriptsInstalled := Integer(response);
  978. end;
  979. if (Gestalt(FourCharCodeToLongword(gestaltAppearanceAttr), response) = noErr) then
  980. begin
  981. macosHasAppearance := BitIsSet(response, gestaltAppearanceExists);
  982. if Gestalt(FourCharCodeToLongword(gestaltAppearanceVersion), response) = noErr then
  983. begin
  984. macosHasAppearance101 := (response >= $101);
  985. macosHasAppearance11 := (response >= $110);
  986. end
  987. end
  988. else
  989. begin
  990. macosHasAppearance := false;
  991. macosHasAppearance101 := false;
  992. macosHasAppearance11 := false;
  993. end;
  994. end;
  995. end;
  996. {*****************************************************************************
  997. System Dependent Exit code
  998. *****************************************************************************}
  999. Procedure system_exit;
  1000. var
  1001. s: ShortString;
  1002. begin
  1003. if StandAlone <> 0 then
  1004. if exitcode <> 0 then
  1005. begin
  1006. Str(exitcode,s);
  1007. if IsConsole then
  1008. Writeln( '### Program exited with exit code ' + s)
  1009. else if macosHasSysDebugger then
  1010. DebugStr('A possible error occured, exit code: ' + s + '. Type "g" and return to continue.')
  1011. else
  1012. {Be quiet}
  1013. end;
  1014. {$ifndef MACOS_USE_STDCLIB}
  1015. if StandAlone <> 0 then
  1016. ExitToShell;
  1017. {$else}
  1018. c_exit(exitcode); {exitcode is only utilized by an MPW tool}
  1019. {$endif}
  1020. end;
  1021. procedure SysInitStdIO;
  1022. begin
  1023. { Setup stdin, stdout and stderr }
  1024. {$ifdef MACOS_USE_STDCLIB}
  1025. OpenStdIO(Input,fmInput,StdInputHandle);
  1026. OpenStdIO(Output,fmOutput,StdOutputHandle);
  1027. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  1028. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  1029. {$endif }
  1030. end;
  1031. var
  1032. resHdl: Mac_Handle;
  1033. isFolder, hadAlias, leafIsAlias: Boolean;
  1034. dirStr: string[2];
  1035. err: OSErr;
  1036. dummySysFolderDirID: Longint;
  1037. begin
  1038. InvestigateSystem; {Must be first}
  1039. {Check requred features for system.pp to work.}
  1040. if not macosHasFSSpec then
  1041. Halt(3); //exit code 3 according to MPW
  1042. if FindSysFolder(macosBootVolumeVRefNum, dummySysFolderDirID) <> noErr then
  1043. Halt(3); //exit code 3 according to MPW
  1044. if GetVolumeName(macosBootVolumeVRefNum, macosBootVolumeName) <> noErr then
  1045. Halt(3); //exit code 3 according to MPW
  1046. { To be set if this is a GUI or console application }
  1047. if StandAlone = 0 then
  1048. IsConsole := true {Its an MPW tool}
  1049. else
  1050. begin
  1051. resHdl:= Get1Resource(FourCharCodeToLongword('siow'),0);
  1052. IsConsole := (resHdl <> nil); {A SIOW app is also a console}
  1053. ReleaseResource(resHdl);
  1054. end;
  1055. { To be set if this is a library and not a program }
  1056. IsLibrary := FALSE;
  1057. StackLength := InitialStkLen;
  1058. StackBottom := SPtr - StackLength;
  1059. { Setup working directory }
  1060. if StandAlone <> 0 then
  1061. begin
  1062. if not GetAppFileLocation(workingDirectorySpec) then
  1063. Halt(3); //exit code 3 according to MPW
  1064. end
  1065. else
  1066. begin
  1067. { The fictive file x is used to make
  1068. FSMakeFSSpec return a FSSpec to a file in the directory.
  1069. Then by clearing the name, the FSSpec then
  1070. points to the directory. It doesn't matter whether x exists or not.}
  1071. dirStr:= ':x';
  1072. err:= ResolveFolderAliases(0, 0, @dirStr, true,
  1073. workingDirectorySpec, isFolder, hadAlias, leafIsAlias);
  1074. workingDirectorySpec.name:='';
  1075. if (err <> noErr) and (err <> fnfErr) then
  1076. Halt(3); //exit code 3 according to MPW
  1077. end;
  1078. { Setup heap }
  1079. if StandAlone <> 0 then
  1080. MaxApplZone;
  1081. if Mac_FreeMem - intern_heapsize < 30000 then
  1082. Halt(3); //exit code 3 according to MPW
  1083. theHeap:= NewPtr(intern_heapsize);
  1084. if theHeap = nil then
  1085. Halt(3); //exit code 3 according to MPW
  1086. InitHeap;
  1087. SysInitExceptions;
  1088. SysInitStdIO;
  1089. { Setup environment and arguments }
  1090. Setup_Environment;
  1091. setup_arguments;
  1092. { Reset IO Error }
  1093. InOutRes:=0;
  1094. errno:=0;
  1095. (* This should be changed to a real value during *)
  1096. (* thread driver initialization if appropriate. *)
  1097. ThreadID := 1;
  1098. {$ifdef HASVARIANT}
  1099. initvariantmanager;
  1100. {$endif HASVARIANT}
  1101. if StandAlone = 0 then
  1102. begin
  1103. InitGraf(@qd.thePort);
  1104. SetFScaleDisable(true);
  1105. InitCursorCtl(nil);
  1106. end;
  1107. end.
  1108. {
  1109. $Log$
  1110. Revision 1.22 2004-09-30 19:58:42 olle
  1111. + Added SetDefaultMacOS[Filetype|Creator]
  1112. * Files written to by fpc rtl now always will get decent filetype/creator
  1113. * Adapted to use FSpGetFullPath
  1114. Revision 1.21 2004/09/12 19:51:02 olle
  1115. + InitGraf called for MPW tool, which make strange bug disappear.
  1116. * bugfix initial wd for MPW tool
  1117. + Added SysInitExceptions
  1118. Revision 1.20 2004/09/03 19:26:08 olle
  1119. + added maxExitCode to all System.pp
  1120. * constrained error code to be below maxExitCode in RunError et. al.
  1121. Revision 1.19 2004/08/20 10:18:15 olle
  1122. + added Yield routine
  1123. Revision 1.18 2004/07/14 23:34:07 olle
  1124. + added qd, the "QuickDraw globals"
  1125. Revision 1.17 2004/06/21 19:23:34 olle
  1126. + Variables describing misc OS features added
  1127. + Detection of GUI app
  1128. * Working directory for APPTYPE TOOL correct now
  1129. + Exit code <> 0 written to, console for console apps, to system debugger (if installed) for GUI apps.
  1130. * Misc fixes
  1131. Revision 1.16 2004/06/17 16:16:13 peter
  1132. * New heapmanager that releases memory back to the OS, donated
  1133. by Micha Nelissen
  1134. Revision 1.15 2004/05/11 18:05:41 olle
  1135. + added call to MaxApplZone to have the whole MacOS heap available
  1136. Revision 1.14 2004/04/29 11:27:36 olle
  1137. * do_read/do_write addr arg changed to pointer
  1138. * misc internal changes
  1139. Revision 1.13 2004/02/04 15:17:16 olle
  1140. * internal changes
  1141. Revision 1.12 2004/01/20 23:11:20 hajny
  1142. * ExecuteProcess fixes, ProcessID and ThreadID added
  1143. Revision 1.11 2004/01/04 21:06:43 jonas
  1144. * make the C-main public
  1145. Revision 1.10 2003/10/29 22:34:52 olle
  1146. + handles program parameters for MPW
  1147. + program start stub
  1148. * improved working directory handling
  1149. * minor changes
  1150. + some documentation
  1151. Revision 1.9 2003/10/17 23:44:30 olle
  1152. + working direcory emulated
  1153. + implemented directory handling procs
  1154. + all proc which take a path param, now resolve it relative wd
  1155. Revision 1.8 2003/10/16 15:43:13 peter
  1156. * THandle is platform dependent
  1157. Revision 1.7 2003/09/27 11:52:35 peter
  1158. * sbrk returns pointer
  1159. Revision 1.6 2003/09/12 12:45:15 olle
  1160. + filehandling complete
  1161. + heaphandling complete
  1162. + support for random
  1163. * filehandling now uses filedecriptors in StdCLib
  1164. * other minor changes
  1165. - removed DEFINE MAC_SYS_RUNNABLE
  1166. Revision 1.5 2003/01/13 17:18:55 olle
  1167. + added support for rudimentary file handling
  1168. Revision 1.4 2002/11/28 10:58:02 olle
  1169. + added support for rudimentary heap
  1170. Revision 1.3 2002/10/23 15:29:09 olle
  1171. + added switch MAC_SYS_RUNABLE
  1172. + added include of system.h etc
  1173. + added standard globals
  1174. + added dummy hook procedures
  1175. Revision 1.2 2002/10/10 19:44:05 florian
  1176. * changes from Olle to compile/link a simple program
  1177. Revision 1.1 2002/10/02 21:34:31 florian
  1178. * first dummy implementation
  1179. }