Mac OS 9
Resources.h
Go to the documentation of this file.
1 
19 #ifndef __RESOURCES__
20 #define __RESOURCES__
21 
22 #ifndef __MACTYPES__
23 #include <MacTypes.h>
24 #endif
25 
26 #ifndef __MIXEDMODE__
27 #include <MixedMode.h>
28 #endif
29 
30 #ifndef __FILES__
31 #include <Files.h>
32 #endif
33 
34 #if PRAGMA_ONCE
35 #pragma once
36 #endif
37 
38 #ifdef __cplusplus
39 extern "C"
40 {
41 #endif
42 
43 #if PRAGMA_IMPORT
44 #pragma import on
45 #endif
46 
47 #if PRAGMA_STRUCT_ALIGN
48 #pragma options align = mac68k
49 #elif PRAGMA_STRUCT_PACKPUSH
50 #pragma pack(push, 2)
51 #elif PRAGMA_STRUCT_PACK
52 #pragma pack(2)
53 #endif
54 
55  enum
56  {
57  resSysHeap = 64, /*System or application heap?*/
58  resPurgeable = 32, /*Purgeable resource?*/
59  resLocked = 16, /*Load it in locked?*/
60  resProtected = 8, /*Protected?*/
61  resPreload = 4, /*Load in on OpenResFile?*/
62  resChanged = 2, /*Resource changed?*/
63  mapReadOnly = 128, /*Resource file read-only*/
64  mapCompact = 64, /*Compact resource file*/
65  mapChanged = 32 /*Write map out at update*/
66  };
67 
68  enum
69  {
70  resSysRefBit = 7, /*reference to system/local reference*/
71  resSysHeapBit = 6, /*In system/in application heap*/
72  resPurgeableBit = 5, /*Purgeable/not purgeable*/
73  resLockedBit = 4, /*Locked/not locked*/
74  resProtectedBit = 3, /*Protected/not protected*/
75  resPreloadBit = 2, /*Read in at OpenResource?*/
76  resChangedBit = 1, /*Existing resource changed since last update*/
77  mapReadOnlyBit = 7, /*is this file read-only?*/
78  mapCompactBit = 6, /*Is a compact necessary?*/
79  mapChangedBit = 5 /*Is it necessary to write map?*/
80  };
81 
82  enum
83  {
84  kResFileNotOpened =
85  -1, /*ref num return as error when opening a resource file*/
86  kSystemResFile = 0 /*this is the default ref num to the system file*/
87  };
88 
89  typedef CALLBACK_API_REGISTER68K(void, ResErrProcPtr, (OSErr thErr));
90  typedef REGISTER_UPP_TYPE(ResErrProcPtr) ResErrUPP;
99  ResErrUPP
100  NewResErrUPP(ResErrProcPtr userRoutine);
101 #if !OPAQUE_UPP_TYPES
102  enum
103  {
104  uppResErrProcInfo = 0x00001002
105  }; /* register no_return_value Func(2_bytes:D0) */
106 #ifdef __cplusplus
107  inline ResErrUPP NewResErrUPP(ResErrProcPtr userRoutine)
108  {
109  return (ResErrUPP)NewRoutineDescriptor(
110  (ProcPtr)(userRoutine), uppResErrProcInfo, GetCurrentArchitecture());
111  }
112 #else
113 #define NewResErrUPP(userRoutine) \
114  (ResErrUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppResErrProcInfo, \
115  GetCurrentArchitecture())
116 #endif
117 #endif
118 
127  void
128  DisposeResErrUPP(ResErrUPP userUPP);
129 #if !OPAQUE_UPP_TYPES
130 #ifdef __cplusplus
131  inline void DisposeResErrUPP(ResErrUPP userUPP)
132  {
133  DisposeRoutineDescriptor((UniversalProcPtr)userUPP);
134  }
135 #else
136 #define DisposeResErrUPP(userUPP) DisposeRoutineDescriptor(userUPP)
137 #endif
138 #endif
139 
148 #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
149 #pragma parameter InvokeResErrUPP(__D0, __A0)
150 #endif
151  void
152  InvokeResErrUPP(OSErr thErr, ResErrUPP userUPP);
153 #if !OPAQUE_UPP_TYPES && \
154  (!TARGET_OS_MAC || !TARGET_CPU_68K || TARGET_RT_MAC_CFM)
155 #ifdef __cplusplus
156  inline void InvokeResErrUPP(OSErr thErr, ResErrUPP userUPP)
157  {
158  CALL_ONE_PARAMETER_UPP(userUPP, uppResErrProcInfo, thErr);
159  }
160 #else
161 #define InvokeResErrUPP(thErr, userUPP) \
162  CALL_ONE_PARAMETER_UPP((userUPP), uppResErrProcInfo, (thErr))
163 #endif
164 #endif
165 
166 #if CALL_NOT_IN_CARBON || OLDROUTINENAMES
167 /* support for pre-Carbon UPP routines: New...Proc and Call...Proc */
168 #define NewResErrProc(userRoutine) NewResErrUPP(userRoutine)
169 #define CallResErrProc(userRoutine, thErr) InvokeResErrUPP(thErr, userRoutine)
170 #endif /* CALL_NOT_IN_CARBON */
171 
172  /* QuickTime 3.0*/
173  typedef CALLBACK_API(OSErr,
174  ResourceEndianFilterPtr)(Handle theResource,
175  Boolean currentlyNativeEndian);
176 #if CALL_NOT_IN_CARBON
185  short
187 
196  void
198 
199 #endif /* CALL_NOT_IN_CARBON */
200 
209  void
210  CloseResFile(short refNum);
211 
246  OSErr
247  ResError(void);
248 
270  short
271  CurResFile(void);
272 
286  short
287  HomeResFile(Handle theResource);
288 
289 #if CALL_NOT_IN_CARBON
298  void
299  CreateResFile(ConstStr255Param fileName);
300 
309  short
310  OpenResFile(ConstStr255Param fileName);
311 
312 #endif /* CALL_NOT_IN_CARBON */
313 
355  void
356  UseResFile(short refNum);
357 
381  short rTotal, j;
382  ResType rt;
383  char *rtp;
384  rTotal = CountTypes();
385  for (j = 1; j <= rTotal; j++)
386  {
387  GetIndType(&rt, j);
388  rtp = &rt;
389  printf("Type '%c%c%c%c' has %d resources\n",
390  rtp[0], rtp[1], rtp[2], rtp[3], CountResources(rt));
391  }
392  </ pre>
393  * \copyright THINK Reference © 1991 - 1992 Symantec Corporation
394  * \non_carbon_cfm in InterfaceLib 7.1 and
395  later
396  * \carbon_lib in CarbonLib 1.0 and
397  later
398  * \mac_os_x in version 10.0 and
399  later
400  * /
401  short
402  CountTypes(void);
403 
423  short
424  Count1Types(void);
425 
456  void
457  GetIndType(ResType *theType, short index);
458 
467  void
468  Get1IndType(ResType *theType, short index);
469 
490  void
492 
520  /* before calling SetResLoad */
521  rCount = CountResources('DRVR');
522  SetResLoad(FALSE); /* do not need resource, just info */
523  for (j = 1; j <= rCount; j++)
524  {
525  rHandle = GetIndResource('DRVR', j);
526  GetResInfo(rHandle, &rID, &rType, rName);
527  printf(" 'DRVR' Rsrc ID: %6d, Name: %s\n", rID, PtoCstr(rName) + 1);
528  }
529  SetResLoad(TRUE); /* better do this! */
530  </ pre>
531  * \copyright THINK Reference © 1991 - 1992 Symantec Corporation
532  * \non_carbon_cfm in InterfaceLib 7.1 and
533  later
534  * \carbon_lib in CarbonLib 1.0 and
535  later
536  * \mac_os_x in version 10.0 and
537  later
538  * /
539  short
540  CountResources(ResType theType);
541 
564  short
565  Count1Resources(ResType theType);
566 
575  Handle
576  GetIndResource(ResType theType, short index);
577 
586  Handle
587  Get1IndResource(ResType theType, short index);
588 
597  Handle
598  GetResource(ResType theType, short theID);
599 
608  Handle
609  Get1Resource(ResType theType, short theID);
610 
619  Handle
620  GetNamedResource(ResType theType, ConstStr255Param name);
621 
630  Handle
631  Get1NamedResource(ResType theType, ConstStr255Param name);
632 
641 #if TARGET_OS_MAC
642 #define MacLoadResource LoadResource
643 #endif
644  void
645  MacLoadResource(Handle theResource);
646 
655  void
656  ReleaseResource(Handle theResource);
657 
689  void
690  DetachResource(Handle theResource);
691 
723  short
724  UniqueID(ResType theType);
725 
746  short
747  Unique1ID(ResType theType);
748 
757  short
758  GetResAttrs(Handle theResource);
759 
768  void
769  GetResInfo(Handle theResource, short *theID, ResType *theType, Str255 name);
770 
779  void
780  SetResInfo(Handle theResource, short theID, ConstStr255Param name);
781 
805  void
806  AddResource(Handle theData, ResType theType, short theID, ConstStr255Param name);
807 
816  long
817  GetResourceSizeOnDisk(Handle theResource);
818 
827  long
828  GetMaxResourceSize(Handle theResource);
829 
830 #if CALL_NOT_IN_CARBON
831 
853  long
854  RsrcMapEntry(Handle theResource);
855 
856 #endif /* CALL_NOT_IN_CARBON */
857 
912  void
913  SetResAttrs(Handle theResource, short attrs);
914 
923  void
924  ChangedResource(Handle theResource);
925 
934  void
935  RemoveResource(Handle theResource);
936 
969  void
970  UpdateResFile(short refNum);
971 
983  /*... modify the handle data... */
984  ChangedResource(rHandle); /* tag as changed */
985  if (ResError() == noErr)
986  { /* always check this! */
987  WriteResource(rHandle); /* record changes to disk */
988  }
989  HPurge(rHandle); /* allow purge */
990  Make sure you check ResError after calling ChangedResource(or
991  AddResource) and
992  before calling WriteResource.</ pre>
993  * \copyright THINK Reference © 1991 -
994  1992 Symantec Corporation
995  * \non_carbon_cfm in InterfaceLib 7.1 and
996  later
997  * \carbon_lib in CarbonLib 1.0 and
998  later
999  * \mac_os_x in version 10.0 and
1000  later
1001  * /
1002  void WriteResource(Handle theResource);
1003 
1030  void
1032 
1085  short
1086  GetResFileAttrs(short refNum);
1087 
1134  void
1135  SetResFileAttrs(short refNum, short attrs);
1136 
1145  short
1146  OpenRFPerm(ConstStr255Param fileName, short vRefNum, SInt8 permission);
1147 
1148 #if CALL_NOT_IN_CARBON
1157  Handle
1158  RGetResource(ResType theType, short theID);
1159 
1160 #endif /* CALL_NOT_IN_CARBON */
1161 
1170  short
1171  HOpenResFile(short vRefNum, long dirID, ConstStr255Param fileName,
1172  SInt8 permission);
1173 
1182  void
1183  HCreateResFile(short vRefNum, long dirID, ConstStr255Param fileName);
1184 
1207  short
1208  FSpOpenResFile(const FSSpec *spec, SignedByte permission);
1209 
1218  void
1219  FSpCreateResFile(const FSSpec *spec, OSType creator, OSType fileType,
1220  ScriptCode scriptTag);
1221 
1230  void
1231  ReadPartialResource(Handle theResource, long offset, void *buffer, long count);
1232 
1241  void
1242  WritePartialResource(Handle theResource, long offset, const void *buffer,
1243  long count);
1244 
1253  void
1254  SetResourceSize(Handle theResource, long newSize);
1255 
1264  Handle
1265  GetNextFOND(Handle fondHandle);
1266 
1267 /* QuickTime 3.0*/
1268 #if CALL_NOT_IN_CARBON
1277  OSErr
1279  ResourceEndianFilterPtr theFilterProc);
1280 
1281  /* Use TempInsertROMMap to force the ROM resource map to be
1282  inserted into the chain in front of the system. Note that
1283  this call is only temporary - the modified resource chain
1284  is only used for the next call to the resource manager.
1285  See IM IV 19 for more information.
1286  */
1295  void
1297 
1306 #endif /* CALL_NOT_IN_CARBON */
1307 
1308  typedef SInt16 RsrcChainLocation;
1309  enum
1310  {
1311  kRsrcChainBelowSystemMap = 0, /* Below the system's resource map*/
1312  kRsrcChainBelowApplicationMap = 1, /* Below the application's resource map*/
1313  kRsrcChainAboveApplicationMap = 2, /* Above the application's resource map*/
1314  kRsrcChainAboveAllMaps = 4 /* Above all resource maps*/
1315  };
1316 
1331  OSErr
1333 
1346  OSErr
1347  DetachResourceFile(SInt16 refNum);
1348 
1365  Boolean
1366  FSpResourceFileAlreadyOpen(const FSSpec *resourceFile, Boolean *inChain,
1367  SInt16 *refNum);
1368 
1387  OSErr
1388  FSpOpenOrphanResFile(const FSSpec *spec, SignedByte permission, SInt16 *refNum);
1389 
1403  OSErr
1404  GetTopResourceFile(SInt16 *refNum);
1405 
1422  OSErr
1423  GetNextResourceFile(SInt16 curRefNum, SInt16 *nextRefNum);
1424 
1425 #if CALL_NOT_IN_CARBON
1434  Handle
1435  getnamedresource(ResType theType, const char *name);
1436 
1445  Handle
1446  get1namedresource(ResType theType, const char *name);
1447 
1456  short
1457  openrfperm(const char *fileName, short vRefNum, char permission);
1458 
1467  short
1468  openresfile(const char *fileName);
1469 
1478  void
1479  createresfile(const char *fileName);
1480 
1489  void
1490  getresinfo(Handle theResource, short *theID, ResType *theType, char *name);
1491 
1500  void
1501  setresinfo(Handle theResource, short theID, const char *name);
1502 
1511  void
1512  addresource(Handle theResource, ResType theType, short theID, const char *name);
1513 
1514 #endif /* CALL_NOT_IN_CARBON */
1515 
1516 #if OLDROUTINENAMES
1517 #define SizeResource(theResource) GetResourceSizeOnDisk(theResource)
1518 #define MaxSizeRsrc(theResource) GetMaxResourceSize(theResource)
1519 #define RmveResource(theResource) RemoveResource(theResource)
1520 #endif /* OLDROUTINENAMES */
1521 
1530  short
1531  FSOpenResFile(const FSRef *ref, SInt8 permission);
1532 
1541  void
1542  FSCreateResFile(const FSRef *parentRef, UniCharCount nameLength,
1543  const UniChar *name, FSCatalogInfoBitmap whichInfo,
1544  const FSCatalogInfo *catalogInfo, FSRef *newRef,
1545  FSSpec *newSpec);
1546 
1555  Boolean
1556  FSResourceFileAlreadyOpen(const FSRef *resourceFileRef, Boolean *inChain,
1557  SInt16 *refNum);
1558 
1606  OSErr
1607  FSCreateResourceFile(const FSRef *parentRef, UniCharCount nameLength,
1608  const UniChar *name, FSCatalogInfoBitmap whichInfo,
1609  const FSCatalogInfo *catalogInfo, /* can be NULL */
1610  UniCharCount forkNameLength,
1611  const UniChar *forkName, /* can be NULL */
1612  FSRef *newRef, /* can be NULL */
1613  FSSpec *newSpec); /* can be NULL */
1614 
1648  OSErr
1649  FSOpenResourceFile(const FSRef *ref, UniCharCount forkNameLength,
1650  const UniChar *forkName, /* can be NULL */
1651  SInt8 permissions, SInt16 *refNum);
1652 
1656  typedef short ResFileRefNum;
1657  typedef short ResID;
1658  typedef short ResAttributes;
1659  typedef short ResFileAttributes;
1660 
1661 #if PRAGMA_STRUCT_ALIGN
1662 #pragma options align = reset
1663 #elif PRAGMA_STRUCT_PACKPUSH
1664 #pragma pack(pop)
1665 #elif PRAGMA_STRUCT_PACK
1666 #pragma pack()
1667 #endif
1668 
1669 #ifdef PRAGMA_IMPORT_OFF
1670 #pragma import off
1671 #elif PRAGMA_IMPORT
1672 #pragma import reset
1673 #endif
1674 
1675 #ifdef __cplusplus
1676 }
1677 #endif
1678 
1679 #endif /* __RESOURCES__ */
1680 * / FileAttributes;
1681 
1682 #if PRAGMA_STRUCT_ALIGN
1683 #pragma options align = reset
1684 #elif PRAGMA_STRUCT_PACKPUSH
1685 #pragma pack(pop)
1686 #elif PRAGMA_STRUCT_PACK
1687 #pragma pack()
1688 #endif
1689 
1690 #ifdef PRAGMA_IMPORT_OFF
1691 #pragma import off
1692 #elif PRAGMA_IMPORT
1693 #pragma import reset
1694 #endif
1695 
1696 #ifdef __cplusplus
1697 }
1698 #endif
1699 
1700 #endif /* __RESOURCES__ */
1701 * /*/*/ * /*/*/ * /*/*/ * /*/*/ * /*/*/ * /*/*/ * /*/*/ * /
#define check(assertion)
Definition: Debugging.h:819
File Manager (MFS, HFS, and HFS+) Interfaces.
printf("First vcb is at = %lx\n", qhp->qHead)
Obtain pointer to the volume control block queue header.
HPurge(myHandle)
Make a relocatable block purgeable.
Basic Macintosh data types.
unsigned char Boolean
Definition: MacTypes.h:318
Mixed Mode Manager Interfaces.
void DisposeRoutineDescriptor(UniversalProcPtr theUPP)
UniversalProcPtr NewRoutineDescriptor(ProcPtr theProc, ProcInfoType theProcInfo, ISAType theISA)
short openrfperm(const char *fileName, short vRefNum, char permission)
Handle Get1IndResource(ResType theType, short index)
void ReadPartialResource(Handle theResource, long offset, void *buffer, long count)
Boolean FSpResourceFileAlreadyOpen(const FSSpec *resourceFile, Boolean *inChain, SInt16 *refNum)
void SetResourceSize(Handle theResource, long newSize)
OSErr FSpOpenOrphanResFile(const FSSpec *spec, SignedByte permission, SInt16 *refNum)
short FSpOpenResFile(const FSSpec *spec, SignedByte permission)
Open resource file specified by an FSSpec.
short openresfile(const char *fileName)
void WritePartialResource(Handle theResource, long offset, const void *buffer, long count)
void GetIndType(ResType *theType, short index)
Get the ResType of a resource, given its index.
Handle GetResource(ResType theType, short theID)
short GetResFileAttrs(short refNum)
Obtain resource file attributes.
void createresfile(const char *fileName)
void ChangedResource(Handle theResource)
void SetResLoad(Boolean load)
Set state of automatic resource loading.
Handle GetNextFOND(Handle fondHandle)
void GetResInfo(Handle theResource, short *theID, ResType *theType, Str255 name)
Given a handle, obtain resource ID, type, and name.
OSErr InsertResourceFile(SInt16 refNum, RsrcChainLocation where)
void CloseResFile(short refNum)
Handle RGetResource(ResType theType, short theID)
short InitResources(void)
void getresinfo(Handle theResource, short *theID, ResType *theType, char *name)
void FSCreateResFile(const FSRef *parentRef, UniCharCount nameLength, const UniChar *name, FSCatalogInfoBitmap whichInfo, const FSCatalogInfo *catalogInfo, FSRef *newRef, FSSpec *newSpec)
void RemoveResource(Handle theResource)
Handle Get1Resource(ResType theType, short theID)
void AddResource(Handle theData, ResType theType, short theID, ConstStr255Param name)
Make arbitrary data in memory into a resource.
short CurResFile(void)
Get reference number of current resource file.
short HomeResFile(Handle theResource)
Given a resource handle, return a file reference number.
void SetResAttrs(Handle theResource, short attrs)
Set resource attributes (purgeable, locked, etc.)
short Count1Resources(ResType theType)
Get "1-deep" count of resources of selected type.
void setresinfo(Handle theResource, short theID, const char *name)
void MacLoadResource(Handle theResource)
long GetResourceSizeOnDisk(Handle theResource)
void FSpCreateResFile(const FSSpec *spec, OSType creator, OSType fileType, ScriptCode scriptTag)
SInt16 RsrcChainLocation
Definition: Resources.h:1308
void UpdateResFile(short refNum)
Write changed resource map and data to disk.
short Unique1ID(ResType theType)
1-deep, get unique resource ID
OSErr RegisterResourceEndianFilter(ResType theType, ResourceEndianFilterPtr theFilterProc)
void HCreateResFile(short vRefNum, long dirID, ConstStr255Param fileName)
void SetResPurge(Boolean install)
Write data of one resource to disk.
void CreateResFile(ConstStr255Param fileName)
OSErr FSCreateResourceFile(const FSRef *parentRef, UniCharCount nameLength, const UniChar *name, FSCatalogInfoBitmap whichInfo, const FSCatalogInfo *catalogInfo, UniCharCount forkNameLength, const UniChar *forkName, FSRef *newRef, FSSpec *newSpec)
short OpenResFile(ConstStr255Param fileName)
OSErr ResError(void)
Find if an error occurred in a resource operation.
Handle getnamedresource(ResType theType, const char *name)
Handle get1namedresource(ResType theType, const char *name)
OSErr GetNextResourceFile(SInt16 curRefNum, SInt16 *nextRefNum)
short ResFileRefNum
Definition: Resources.h:1656
short FSOpenResFile(const FSRef *ref, SInt8 permission)
void RsrcZoneInit(void)
OSErr GetTopResourceFile(SInt16 *refNum)
void TempInsertROMMap(Boolean tempResLoad)
long RsrcMapEntry(Handle theResource)
Obtain offset in resource map for a handle's entry.
short UniqueID(ResType theType)
Get unique resource ID (before adding a resource)
void DetachResource(Handle theResource)
Prevent resource from being discarded when file is closed.
void UseResFile(short refNum)
Make specified resource file the "current file".
short rTotal
Get total number of resource types in open files.
Definition: Resources.h:381
OSErr DetachResourceFile(SInt16 refNum)
Handle Get1NamedResource(ResType theType, ConstStr255Param name)
void addresource(Handle theResource, ResType theType, short theID, const char *name)
short HOpenResFile(short vRefNum, long dirID, ConstStr255Param fileName, SInt8 permission)
Handle GetIndResource(ResType theType, short index)
void Get1IndType(ResType *theType, short index)
void SetResFileAttrs(short refNum, short attrs)
Set resource file attributes.
void ReleaseResource(Handle theResource)
ResErrUPP NewResErrUPP(ResErrProcPtr userRoutine)
short Count1Types(void)
Get total number of resource types in current file.
short GetResAttrs(Handle theResource)
rCount
Find how many of a selected resource type exist.
Definition: Resources.h:521
void SetResInfo(Handle theResource, short theID, ConstStr255Param name)
void InvokeResErrUPP(OSErr thErr, ResErrUPP userUPP)
short OpenRFPerm(ConstStr255Param fileName, short vRefNum, SInt8 permission)
Boolean FSResourceFileAlreadyOpen(const FSRef *resourceFileRef, Boolean *inChain, SInt16 *refNum)
long GetMaxResourceSize(Handle theResource)
OSErr FSOpenResourceFile(const FSRef *ref, UniCharCount forkNameLength, const UniChar *forkName, SInt8 permissions, SInt16 *refNum)
void DisposeResErrUPP(ResErrUPP userUPP)
Handle GetNamedResource(ResType theType, ConstStr255Param name)
typedef CALLBACK_API_REGISTER68K(void, SIInterruptProcPtr,(SPBPtr inParamPtr, Ptr dataBuffer, short peakAmplitude, long sampleSize))
typedef REGISTER_UPP_TYPE(HighHookProcPtr) HighHookUPP
Definition: Files.h:6621
Definition: Files.h:6527
Definition: MacTypes.h:520