macostp.inc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 2003 by Olle Raab
  5. A selection of the MacOS API for FreePascal, written
  6. in the Turbo Pascal dialect.
  7. It is primarily for internal use in the rtl, please
  8. do not expect it to remain the same over time,
  9. it will be subject to changes.
  10. See the file COPYING.FPC, included in this distribution,
  11. for details about the copyright.
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. **********************************************************************}
  16. {Note: Types like Mac_XXX corresponds to the type XXX defined
  17. in MacOS Universal Headers. The prefix is to avoid name clashes
  18. with FPC types.}
  19. {************** from Types.p ***************}
  20. const
  21. noErr = 0;
  22. type
  23. SignedByte = shortint;
  24. SInt8 = SignedByte;
  25. SignedBytePtr = ^SignedByte;
  26. OSErr = Integer;
  27. OSType = Longint;
  28. Mac_Ptr = pointer;
  29. Mac_Handle = ^Mac_Ptr;
  30. Str31 = string[31];
  31. Str32 = string[32];
  32. Str63 = string[63];
  33. Str255 = string[255];
  34. StringPtr = ^Str255;
  35. ProcPtr = Mac_Ptr;
  36. UniversalProcPtr = ProcPtr;
  37. ScriptCode = INTEGER;
  38. LangCode = INTEGER;
  39. Point = record
  40. case INTEGER of
  41. 0: (
  42. v: INTEGER;
  43. h: INTEGER;
  44. );
  45. 1: (
  46. vh: array[0..1] of INTEGER;
  47. );
  48. end;
  49. PointPtr = ^Point;
  50. Rect = record
  51. case INTEGER of
  52. 0: (
  53. top: INTEGER;
  54. left: INTEGER;
  55. bottom: INTEGER;
  56. right: INTEGER;
  57. );
  58. 1: (
  59. topLeft: Point;
  60. botRight: Point;
  61. );
  62. end;
  63. RectPtr = ^Rect;
  64. procedure Debugger;
  65. external 'InterfaceLib';
  66. procedure DebugStr(s: Str255);
  67. external 'InterfaceLib';
  68. {************** from Memory.p ***************}
  69. type
  70. Size = LONGINT;
  71. function NewHandle (byteCount: Size): Mac_Handle;
  72. external 'InterfaceLib';
  73. function NewPtr(logicalSize: Size): Mac_Ptr ;
  74. external 'InterfaceLib';
  75. procedure DisposePtr (p: Mac_Ptr);
  76. external 'InterfaceLib';
  77. function GetPtrSize (p: Mac_Ptr): Size;
  78. external 'InterfaceLib';
  79. procedure SetPtrSize (p: Mac_Ptr; newSize: Size);
  80. external 'InterfaceLib';
  81. procedure DisposeHandle (h: Mac_Handle);
  82. external 'InterfaceLib';
  83. procedure SetHandleSize (h: Mac_Handle; newSize: Size);
  84. external 'InterfaceLib';
  85. function GetHandleSize (h: Mac_Handle): Size;
  86. external 'InterfaceLib';
  87. function Mac_FreeMem: Longint;
  88. external 'InterfaceLib' name 'FreeMem';
  89. {************** from OSUtils.p ***************}
  90. type
  91. QElemPtr = ^QElem;
  92. QElem = record
  93. qLink: QElemPtr;
  94. qType: INTEGER;
  95. qData: array[0..0] of INTEGER;
  96. end;
  97. {************** from Finder.p ***************}
  98. type
  99. FInfo = record
  100. fdType: OSType; {the type of the file}
  101. fdCreator: OSType; {file's creator}
  102. fdFlags: INTEGER; {flags ex. hasbundle,invisible,locked, etc.}
  103. fdLocation: Point; {file's location in folder}
  104. fdFldr: INTEGER; {folder containing file}
  105. end;
  106. FXInfo = record
  107. fdIconID: INTEGER; {Icon ID}
  108. fdUnused: array[0..2] of INTEGER; {unused but reserved 6 bytes}
  109. fdScript: SInt8; {Script flag and number}
  110. fdXFlags: SInt8; {More flag bits}
  111. fdComment: INTEGER; {Comment ID}
  112. fdPutAway: LONGINT; {Home Dir ID}
  113. end;
  114. DInfo = record
  115. frRect: Rect; {folder rect}
  116. frFlags: INTEGER; {Flags}
  117. frLocation: Point; {folder location}
  118. frView: INTEGER; {folder view}
  119. end;
  120. DXInfo = record
  121. frScroll: Point; {scroll position}
  122. frOpenChain: LONGINT; {DirID chain of open folders}
  123. frScript: SInt8; {Script flag and number}
  124. frXFlags: SInt8; {More flag bits}
  125. frComment: INTEGER; {comment}
  126. frPutAway: LONGINT; {DirID}
  127. end;
  128. {************** from Files.p ***************}
  129. const
  130. fsAtMark = 0;
  131. fsCurPerm = 0;
  132. fsRdPerm = 1;
  133. fInvisible = 16384;
  134. fsWrPerm = 2;
  135. fsRdWrPerm = 3;
  136. fsRdWrShPerm = 4;
  137. fsFromStart = 1;
  138. fsFromLEOF = 2;
  139. fsFromMark = 3;
  140. rdVerify = 64;
  141. ioMapBuffer = 4;
  142. ioModeReserved = 8;
  143. ioDirFlg = 4; { see IM IV-125 }
  144. ioDirMask = $10;
  145. fsRtParID = 1;
  146. fsRtDirID = 2;
  147. type
  148. IOCompletionUPP = UniversalProcPtr;
  149. CInfoPBRec = record
  150. qLink: QElemPtr;
  151. qType: INTEGER;
  152. ioTrap: INTEGER;
  153. ioCmdAddr: Mac_Ptr;
  154. ioCompletion: IOCompletionUPP;
  155. ioResult: OSErr;
  156. ioNamePtr: StringPtr;
  157. ioVRefNum: INTEGER;
  158. ioFRefNum: INTEGER;
  159. ioFVersNum: SInt8;
  160. filler1: SInt8;
  161. ioFDirIndex: INTEGER;
  162. ioFlAttrib: SInt8;
  163. ioACUser: SInt8;
  164. case INTEGER of
  165. 0: (
  166. ioFlFndrInfo: FInfo;
  167. ioDirID: LONGINT;
  168. ioFlStBlk: INTEGER;
  169. ioFlLgLen: LONGINT;
  170. ioFlPyLen: LONGINT;
  171. ioFlRStBlk: INTEGER;
  172. ioFlRLgLen: LONGINT;
  173. ioFlRPyLen: LONGINT;
  174. ioFlCrDat: LONGINT;
  175. ioFlMdDat: LONGINT;
  176. ioFlBkDat: LONGINT;
  177. ioFlXFndrInfo: FXInfo;
  178. ioFlParID: LONGINT;
  179. ioFlClpSiz: LONGINT;
  180. );
  181. 1: (
  182. ioDrUsrWds: DInfo;
  183. ioDrDirID: LONGINT;
  184. ioDrNmFls: INTEGER;
  185. filler3: array[1..9] of INTEGER;
  186. ioDrCrDat: LONGINT;
  187. ioDrMdDat: LONGINT;
  188. ioDrBkDat: LONGINT;
  189. ioDrFndrInfo: DXInfo;
  190. ioDrParID: LONGINT;
  191. );
  192. end;
  193. CInfoPBPtr = ^CInfoPBRec;
  194. FSSpec = record
  195. vRefNum: Integer;
  196. parID: Longint;
  197. name: Str63;
  198. end;
  199. FSSpecPtr = ^FSSpec;
  200. function MemError: OSErr;
  201. external 'InterfaceLib';
  202. function FSpOpenDF(spec: FSSpec; permission: SignedByte;
  203. var refNum: Integer): OSErr;
  204. external 'InterfaceLib';
  205. function FSpCreate(spec: FSSpec; creator, fileType: OSType;
  206. scriptTag: ScriptCode): OSErr;
  207. external 'InterfaceLib';
  208. function FSClose(refNum: Integer): OSErr;
  209. external 'InterfaceLib';
  210. function FSRead(refNum: Integer; var count: Longint; buffPtr: Mac_Ptr): OSErr;
  211. external 'InterfaceLib';
  212. function FSWrite(refNum: Integer; var count: Longint; buffPtr: Mac_Ptr): OSErr;
  213. external 'InterfaceLib';
  214. function GetFPos(refNum: Integer; var filePos: Longint): OSErr;
  215. external 'InterfaceLib';
  216. function SetFPos(refNum: Integer; posMode: Integer; posOff: Longint): OSErr;
  217. external 'InterfaceLib';
  218. function GetEOF(refNum: Integer; var logEOF: Longint): OSErr;
  219. external 'InterfaceLib';
  220. function SetEOF(refNum: Integer; logEOF: Longint): OSErr;
  221. external 'InterfaceLib';
  222. function FSMakeFSSpec (vRefNum: Integer; dirID: LongInt;
  223. fileName: Str255; VAR spec: FSSpec): OSErr;
  224. external 'InterfaceLib';
  225. function FSpDirCreate(spec: FSSpec; scriptTag: ScriptCode;
  226. var createdDirID: Longint): OSErr;
  227. external 'InterfaceLib';
  228. function FSpDelete(spec: FSSpec): OSErr;
  229. external 'InterfaceLib';
  230. function PBGetCatInfoSync (paramBlock: CInfoPBPtr): OSErr;
  231. external 'InterfaceLib';
  232. {************** from Aliases.p ***************}
  233. type
  234. AliasHandle = Mac_Handle;
  235. function NewAliasMinimalFromFullPath(fullPathLength: Integer;
  236. fullPath: Mac_Ptr; zoneName: Str32; serverName: Str31;
  237. var alias: AliasHandle):OSErr;
  238. external 'InterfaceLib';
  239. function ResolveAlias(fromFile: FSSpecPtr; alias: AliasHandle;
  240. var target: FSSpec; var wasChanged: Boolean):OSErr;
  241. external 'InterfaceLib';
  242. {************** from Processes.p ***************}
  243. type
  244. ProcessSerialNumber = record
  245. highLongOfPSN: LONGINT;
  246. lowLongOfPSN: LONGINT;
  247. end;
  248. ProcessSerialNumberPtr = ^ProcessSerialNumber;
  249. ProcessInfoRec = record
  250. processInfoLength: LONGINT;
  251. processName: StringPtr;
  252. processNumber: ProcessSerialNumber;
  253. processType: LONGINT;
  254. processSignature: OSType;
  255. processMode: LONGINT;
  256. processLocation: Mac_Ptr;
  257. processSize: LONGINT;
  258. processFreeMem: LONGINT;
  259. processLauncher: ProcessSerialNumber;
  260. processLaunchDate: LONGINT;
  261. processActiveTime: LONGINT;
  262. processAppSpec: FSSpecPtr;
  263. end;
  264. ProcessInfoRecPtr = ^ProcessInfoRec;
  265. const
  266. { Process identifier - Various reserved process serial numbers }
  267. kNoProcess = 0;
  268. kSystemProcess = 1;
  269. kCurrentProcess = 2;
  270. function GetProcessInformation ({CONST} var PSN: ProcessSerialNumber;
  271. var info: ProcessInfoRec): OSErr;
  272. external 'InterfaceLib';
  273. {************** from Script.p ***************}
  274. const
  275. smSystemScript = -1;
  276. {************** from MacErrors.p ***************}
  277. {Contains error codes for all File Manager calls, except
  278. for PBVolumeMount and for File ID Routines (from UI 3.4).
  279. And also memFullErr}
  280. const
  281. dirFulErr = -33; { Directory full }
  282. dskFulErr = -34; { disk full }
  283. nsvErr = -35; { no such volume }
  284. ioErr = -36; { I/O error (bummers) }
  285. bdNamErr = -37; { there may be no bad names in the final system! }
  286. fnOpnErr = -38; { File not open }
  287. eofErr = -39; { End of file }
  288. posErr = -40; { tried to position to before start of file (r/w) }
  289. mFulErr = -41; { memory full (open) or file won't fit (load) }
  290. tmfoErr = -42; { too many files open }
  291. fnfErr = -43; { File not found }
  292. wPrErr = -44; { diskette is write protected. }
  293. fLckdErr = -45; { file is locked }
  294. vLckdErr = -46; { volume is locked }
  295. fBsyErr = -47; { File is busy (delete) }
  296. dupFNErr = -48; { duplicate filename (rename) }
  297. opWrErr = -49; { file already open with with write permission }
  298. rfNumErr = -51; { refnum error }
  299. gfpErr = -52; { get file position error }
  300. volOffLinErr=-53; { volume not on line error (was Ejected) }
  301. permErr = -54; { permissions error (on file open) }
  302. volOnLinErr= -55; { drive volume already on-line at MountVol }
  303. nsDrvErr = -56; { no such drive (tried to mount a bad drive num) }
  304. noMacDskErr= -57; { not a mac diskette (sig bytes are wrong) }
  305. extFSErr = -58; { volume in question belongs to an external fs }
  306. fsRnErr = -59; { file system internal error:during rename the old entry was deleted but could not be restored. }
  307. badMDBErr = -60; { bad master directory block }
  308. wrPermErr = -61; { write permissions error }
  309. dirNFErr = -120; { Directory not found }
  310. tmwdoErr = -121; { No free WDCB available }
  311. badMovErr = -122; { Move into offspring error }
  312. wrgVolTypErr=-123; { Wrong volume type error [operation not supported for MFS] }
  313. volGoneErr = -124; { Server volume has been disconnected. }
  314. diffVolErr = -1303; { files on different volumes }
  315. catChangedErr= -1304; { the catalog has been modified }
  316. afpAccessDenied= -5000; { Insufficient access privileges for operation }
  317. afpDenyConflict= -5006; { Specified open/deny modes conflict with current open modes }
  318. afpNoMoreLocks= -5015; { Maximum lock limit reached }
  319. afpRangeNotLocked= -5020; { Tried to unlock range that was not locked by user }
  320. afpRangeOverlap= -5021; { Some or all of range already locked by same user }
  321. afpObjectTypeErr= -5025; { File/Directory specified where Directory/File expected }
  322. afpCatalogChanged= -5037;
  323. afpSameObjectErr= -5038;
  324. memFullErr = -108; { Not enough room in heap zone }
  325. {************** from others ***************}
  326. procedure ExitToShell;
  327. external 'InterfaceLib';
  328. procedure SysBeep(dur: Integer);
  329. external 'SysBeep';
  330. function TickCount: Longint;
  331. external 'InterfaceLib';
  332. function Munger (h: Mac_Handle; offset: LONGINT; ptr1: Mac_Ptr;
  333. len1: LONGINT; ptr2: Mac_Ptr; len2: LONGINT): LONGINT;
  334. external 'InterfaceLib';