File: Mac_Resource.h

package info (click to toggle)
maelstrom 1.4.3-L3.0.6%2Bmain-9
  • links: PTS
  • area: main
  • in suites: bullseye, buster
  • size: 4,356 kB
  • sloc: cpp: 10,822; ansic: 2,779; sh: 2,680; makefile: 196
file content (107 lines) | stat: -rw-r--r-- 2,888 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
    MACLIB:  A companion library to SDL for working with Macintosh (tm) data
    Copyright (C) 1997  Sam Lantinga

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    Sam Lantinga
    5635-34 Springhouse Dr.
    Pleasanton, CA 94588 (USA)
    slouken@devolution.com
*/

#ifndef _Mac_Resource_h
#define _Mac_Resource_h

/* These are routines to parse a Macintosh Resource Fork file

	-Sam Lantinga			(slouken@devolution.com)

Note: Most of the info in this file came from "Inside Macintosh"
*/

#include <stdio.h>
#include <stdarg.h>

/* The actual resources in the resource fork */
typedef struct {
	Uint32 length;
	Uint8   *data;
} Mac_ResData;


class Mac_Resource {
public:
	Mac_Resource(const char *filename);
	~Mac_Resource();

	/* Create a NULL terminated list of resource types in this file */
	char  **Types(void);

	/* Return the number of resources of the given type */
	Uint16  NumResources(const char *res_type);

	/* Create a 0xFFFF terminated list of resource ids for a type */
	Uint16 *ResourceIDs(const char *res_type);

	/* Return a resource of a certain type and id.  These resources
	   are deleted automatically when Mac_Resource object is deleted.
	 */
	char   *ResourceName(const char *res_type, Uint16 id);
	Mac_ResData *Resource(const char *res_type, Uint16 id);
	Mac_ResData *Resource(const char *res_type, const char *name);

	/* This returns a more detailed error message, or NULL */
	char *Error(void) {
		return(errstr);
	}

protected:
	friend int Res_cmp(const void *A, const void *B);

	/* Offset of Resource data in resource fork */
	Uint32 res_offset;
	Uint16 num_types;		/* Number of types of resources */

	struct resource {
		char  *name;
		Uint16 id;
		Uint32 offset;
		Mac_ResData *data;
	};

	struct resource_list {
		char   type[5];			/* Four character type + nul */
		Uint16 count;
		struct resource *list;
	} *Resources;

	FILE   *filep;				/* The Resource Fork File */
	Uint32  base;				/* The offset of the rsrc */

	/* Useful for getting error feedback */
	void error(char *fmt, ...) {
		va_list ap;

		va_start(ap, fmt);
		vsnprintf(errbuf, BUFSIZ, fmt, ap);
		va_end(ap);
		errstr = errbuf;
	}
	char *errstr;
	char  errbuf[BUFSIZ];
};

#endif /* _Mac_Resource_h */