1 #include "csf.h"
2 #include "csfimpl.h"
3
4 #include <string.h> /* strlen */
5
6 /* get the size of the history attribute
7 * returns
8 * the size of history buffer INCLUDING the terminating `\0`,
9 * or 0 if not available or in case of error
10 */
11 size_t MgetHistorySize(MAP *m) /* the map to get it from */
12 {
13 return (size_t)CsfAttributeSize(m, ATTR_ID_HISTORY);
14 }
15
16 /* get the size of the description attribute
MopenPerm(const MAP * m)17 * returns
18 * the size of description buffer INCLUDING the terminating `\0`,
19 * or 0 if not available or in case of error
20 */
21 size_t MgetDescriptionSize(MAP *m) /* the map to get it from */
22 {
23 return (size_t)CsfAttributeSize(m, ATTR_ID_DESCRIPTION);
24 }
25
26 /* get the number of colour palette entries
27 * MgetNrColourPaletteEntries returns the number of rgb tupels
28 * of the colour palette. Each tuple is a sequence of 3 UINT2
29 * words describing red, green and blue.
30 * returns
31 * the number of rgb tuples,
32 * or 0 if not available or in case of error
33 */
34 size_t MgetNrColourPaletteEntries(MAP *m) /* the map to get it from */
35 {
36 size_t s = (size_t)CsfAttributeSize(m, ATTR_ID_COLOUR_PAL);
37 POSTCOND( (s % (3*sizeof(UINT2))) == 0);
38 return s / (3*sizeof(UINT2));
Mopen(const char * fileName,enum MOPEN_PERM mode)39 }
40
41 /* get the number of grey palette entries
42 * MgetNrGreyPaletteEntries returns the number of grey tupels
43 * of the grey palette. Each tuple is one UINT2
44 * words describing the intensity: low, 0 is black, high is white.
45 * returns
46 * the number of grey tuples,
47 * or 0 if not available or in case of error
48 */
49 size_t MgetNrGreyPaletteEntries(MAP *m) /* the map to get it from */
50 {
51 size_t s = (size_t)CsfAttributeSize(m, ATTR_ID_GREY_PAL);
52 POSTCOND( (s % (sizeof(UINT2))) == 0);
53 return s / (sizeof(UINT2));
54 }
55
56 /* get the description attribute
57 * returns
58 * 0 if not available or in case of error,
59 * nonzero otherwise
60 */
61 int MgetDescription(MAP *m, /* the map to get it from */
62 char *des) /* the resulting description string */
63 {
64 size_t size;
65 return CsfGetAttribute(m, ATTR_ID_DESCRIPTION, sizeof(char), &size, des);
66 }
67
68 /* get the history attribute
69 * returns
70 * 0 if not available or in case of error,
71 * nonzero otherwise
72 */
73 int MgetHistory(MAP *m, /* the map to get it from */
74 char *history) /* the resulting history string */
75 {
76 size_t size;
77 return CsfGetAttribute(m, ATTR_ID_HISTORY, sizeof(char), &size, history);
78 }
79
80 /* get the colour palette
81 * MgetColourPalette fills the pal argument with a number of rgb tupels
82 * of the colour palette. Each tuple is a sequence of 3 UINT2
83 * words describing red, green and blue. Thus if the map has 8
84 * colour palette entries it puts 24 UINT2 values in pal.
85 * returns
86 * 0 if not available or in case of error,
87 * nonzero otherwise
88 */
89 int MgetColourPalette(MAP *m, /* the map to get it from */
90 UINT2 *pal) /* the resulting palette */
91 {
92 size_t size;
93 return CsfGetAttribute(m, ATTR_ID_COLOUR_PAL, sizeof(UINT2), &size, pal);
94 }
95
96 /* get the grey palette
97 * MgetGreyPalette fills the pal argument with a number of grey tupels
98 * of the grey palette. Each tuple is one UINT2
99 * words describing the intensity: low, 0 is black, high is white.
100 * returns
101 * 0 if not available or in case of error,
102 * nonzero otherwise
103 */
104 int MgetGreyPalette(MAP *m, /* the map to get it from */
105 UINT2 *pal) /* the resulting palette */
106 {
107 size_t size;
108 return CsfGetAttribute(m, ATTR_ID_GREY_PAL, sizeof(UINT2), &size, pal);
109 }
110
111 /* put the description attribute
112 * MputDescription writes the description string to a map.
113 * An existing description is overwritten.
114 * returns
115 * 0 if not available or in case of error,
116 * nonzero otherwise
117 */
118 int MputDescription(MAP *m, /* the map to get it from */
119 char *des) /* the new description string.
120 * Is a C-string, `\0`-terminated
121 */
122 {
123 return CsfUpdateAttribute(m, ATTR_ID_DESCRIPTION, sizeof(char),
124 strlen(des)+1, des);
125 }
126
127 /* put the history attribute
128 * MputHistory writes the history string to a map.
129 * An existing history is overwritten.
130 * returns
131 * 0 if not available or in case of error,
132 * nonzero otherwise
133 */
134 int MputHistory(MAP *m, /* the map to get it from */
135 char *history) /* the new history string
136 * Is a C-string, `\0`-terminated
137 */
138 {
139 return CsfUpdateAttribute(m, ATTR_ID_HISTORY, sizeof(char),
140 strlen(history)+1, history);
141 }
142
143 /* put the colour palette
144 * MputColourPalette writes the pal argument that is filled
145 * with a number of rgb tupels
146 * of the colour palette to the map. Each tuple is a sequence of 3 UINT2
147 * words describing red, green and blue. Thus if the map has 8
148 * colour palette entries it puts 24 UINT2 values in map palette.
149 * An existing colour palette is overwritten.
150 * returns
151 * 0 if not available or in case of error,
152 * nonzero otherwise
153 */
154 int MputColourPalette(MAP *m, /* the map to get it from */
155 UINT2 *pal, /* the new palette */
156 size_t nrTupels) /* the number of 3 UINT2 words tuples of pal */
157 {
158 return CsfUpdateAttribute(m, ATTR_ID_COLOUR_PAL, sizeof(UINT2),
159 nrTupels*3, pal);
160 }
161
162 /* put the grey palette
163 * MputColourPalette writes the pal argument that is filled
164 * with a number of grey tupels
165 * of the grey palette. Each tuple is one UINT2
166 * words describing the intensity: low, 0 is black, high is white.
167 * An existing grey palette is overwritten.
168 * returns
169 * 0 if not available or in case of error,
170 * nonzero otherwise
171 */
172 int MputGreyPalette(MAP *m, /* the map to get it from */
173 UINT2 *pal, /* the new grey palette */
174 size_t nrTupels) /* the number of UINT2 words tuples of pal */
175 {
176 return CsfUpdateAttribute(m, ATTR_ID_GREY_PAL, sizeof(UINT2),
177 nrTupels, pal);
178 }
179