Fixed allocation of 16x16 icons.
[wine.git] / tools / wrc / newstruc.c
blob2b1f2ddf1c64fd9661354c86f77200e63e91bad9
1 /*
2 * Create dynamic new structures of various types
3 * and some utils in that trend.
5 * Copyright 1998 Bertho A. Stultiens
7 */
9 #include "config.h"
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <assert.h>
16 #include "wrc.h"
17 #include "newstruc.h"
18 #include "utils.h"
19 #include "parser.h"
21 /* Generate new_* functions that have no parameters (NOTE: no ';') */
22 __NEW_STRUCT_FUNC(dialog)
23 __NEW_STRUCT_FUNC(dialogex)
24 __NEW_STRUCT_FUNC(name_id)
25 __NEW_STRUCT_FUNC(menu)
26 __NEW_STRUCT_FUNC(menuex)
27 __NEW_STRUCT_FUNC(menu_item)
28 __NEW_STRUCT_FUNC(menuex_item)
29 __NEW_STRUCT_FUNC(control)
30 __NEW_STRUCT_FUNC(icon)
31 __NEW_STRUCT_FUNC(cursor)
32 __NEW_STRUCT_FUNC(versioninfo)
33 __NEW_STRUCT_FUNC(ver_value)
34 __NEW_STRUCT_FUNC(ver_block)
35 __NEW_STRUCT_FUNC(stt_entry)
36 __NEW_STRUCT_FUNC(accelerator)
37 __NEW_STRUCT_FUNC(event)
38 __NEW_STRUCT_FUNC(raw_data)
39 __NEW_STRUCT_FUNC(lvc)
40 __NEW_STRUCT_FUNC(res_count)
41 __NEW_STRUCT_FUNC(string)
42 __NEW_STRUCT_FUNC(toolbar_item)
44 /* New instances for all types of structures */
45 /* Very inefficient (in size), but very functional :-]
46 * Especially for type-checking.
48 resource_t *new_resource(enum res_e t, void *res, int memopt, language_t *lan)
50 resource_t *r = (resource_t *)xmalloc(sizeof(resource_t));
51 r->type = t;
52 r->res.overlay = res;
53 r->memopt = memopt;
54 r->lan = lan;
55 return r;
58 version_t *new_version(DWORD v)
60 version_t *vp = (version_t *)xmalloc(sizeof(version_t));
61 *vp = v;
62 return vp;
65 characts_t *new_characts(DWORD c)
67 characts_t *cp = (characts_t *)xmalloc(sizeof(characts_t));
68 *cp = c;
69 return cp;
72 language_t *new_language(int id, int sub)
74 language_t *lan = (language_t *)xmalloc(sizeof(language_t));
75 lan->id = id;
76 lan->sub = sub;
77 return lan;
80 language_t *dup_language(language_t *l)
82 if(!l) return NULL;
83 return new_language(l->id, l->sub);
86 version_t *dup_version(version_t *v)
88 if(!v) return NULL;
89 return new_version(*v);
92 characts_t *dup_characts(characts_t *c)
94 if(!c) return NULL;
95 return new_characts(*c);
98 rcdata_t *new_rcdata(raw_data_t *rd, int *memopt)
100 rcdata_t *rc = (rcdata_t *)xmalloc(sizeof(rcdata_t));
101 rc->data = rd;
102 if(memopt)
104 rc->memopt = *memopt;
105 free(memopt);
107 else
108 rc->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
109 return rc;
112 font_id_t *new_font_id(int size, string_t *face, int weight, int italic)
114 font_id_t *fid = (font_id_t *)xmalloc(sizeof(font_id_t));
115 fid->name = face;
116 fid->size = size;
117 fid->weight = weight;
118 fid->italic = italic;
119 return fid;
122 user_t *new_user(name_id_t *type, raw_data_t *rd, int *memopt)
124 user_t *usr = (user_t *)xmalloc(sizeof(user_t));
125 usr->data = rd;
126 if(memopt)
128 usr->memopt = *memopt;
129 free(memopt);
131 else
132 usr->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
133 usr->type = type;
134 return usr;
137 font_t *new_font(raw_data_t *rd, int *memopt)
139 font_t *fnt = (font_t *)xmalloc(sizeof(font_t));
140 fnt->data = rd;
141 if(memopt)
143 fnt->memopt = *memopt;
144 free(memopt);
146 else
147 fnt->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
148 return fnt;
151 icon_group_t *new_icon_group(raw_data_t *rd, int *memopt)
153 icon_group_t *icog = (icon_group_t *)xmalloc(sizeof(icon_group_t));
154 if(memopt)
156 icog->memopt = *memopt;
157 free(memopt);
159 else
160 icog->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
161 icog->lvc.language = dup_language(currentlanguage);
162 split_icons(rd, icog, &(icog->nicon));
163 free(rd->data);
164 free(rd);
165 return icog;
168 cursor_group_t *new_cursor_group(raw_data_t *rd, int *memopt)
170 cursor_group_t *curg = (cursor_group_t *)xmalloc(sizeof(cursor_group_t));
171 if(memopt)
173 curg->memopt = *memopt;
174 free(memopt);
176 else
177 curg->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
178 curg->lvc.language = dup_language(currentlanguage);
179 split_cursors(rd, curg, &(curg->ncursor));
180 free(rd->data);
181 free(rd);
182 return curg;
185 bitmap_t *new_bitmap(raw_data_t *rd, int *memopt)
187 bitmap_t *bmp = (bitmap_t *)xmalloc(sizeof(bitmap_t));
188 bmp->data = rd;
189 if(memopt)
191 bmp->memopt = *memopt;
192 free(memopt);
194 else
195 bmp->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
196 return bmp;
199 ver_words_t *new_ver_words(int i)
201 ver_words_t *w = (ver_words_t *)xmalloc(sizeof(ver_words_t));
202 w->words = (WORD *)xmalloc(sizeof(WORD));
203 w->words[0] = (WORD)i;
204 w->nwords = 1;
205 return w;
208 ver_words_t *add_ver_words(ver_words_t *w, int i)
210 w->words = (WORD *)xrealloc(w->words, (w->nwords+1) * sizeof(WORD));
211 w->words[w->nwords] = (WORD)i;
212 w->nwords++;
213 return w;
216 messagetable_t *new_messagetable(raw_data_t *rd)
218 messagetable_t *msg = (messagetable_t *)xmalloc(sizeof(messagetable_t));
219 msg->data = rd;
220 return msg;
223 void copy_raw_data(raw_data_t *dst, raw_data_t *src, int offs, int len)
225 assert(offs <= src->size);
226 assert(offs + len <= src->size);
227 if(!dst->data)
229 dst->data = (char *)xmalloc(len);
230 dst->size = 0;
232 else
233 dst->data = (char *)xrealloc(dst->data, dst->size + len);
234 /* dst->size holds the offset to copy to */
235 memcpy(dst->data + dst->size, src->data + offs, len);
236 dst->size += len;
239 int *new_int(int i)
241 int *ip = (int *)xmalloc(sizeof(int));
242 *ip = i;
243 return ip;
246 stringtable_t *new_stringtable(lvc_t *lvc)
248 stringtable_t *stt = (stringtable_t *)xmalloc(sizeof(stringtable_t));
250 if(lvc)
251 stt->lvc = *lvc;
253 return stt;
256 toolbar_t *new_toolbar(int button_width, int button_height, toolbar_item_t *items, int nitems)
258 toolbar_t *tb = (toolbar_t *)xmalloc(sizeof(toolbar_t));
259 tb->button_width = button_width;
260 tb->button_height = button_height;
261 tb->nitems = nitems;
262 tb->items = items;
263 return tb;
266 dlginit_t *new_dlginit(raw_data_t *rd, int *memopt)
268 dlginit_t *di = (dlginit_t *)xmalloc(sizeof(dlginit_t));
269 di->data = rd;
270 if(memopt)
272 di->memopt = *memopt;
273 free(memopt);
275 else
276 di->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
278 return di;
281 style_pair_t *new_style_pair(style_t *style, style_t *exstyle)
283 style_pair_t *sp = (style_pair_t *)xmalloc(sizeof(style_pair_t));
284 sp->style = style;
285 sp->exstyle = exstyle;
286 return sp;
289 style_t *new_style(DWORD or_mask, DWORD and_mask)
291 style_t *st = (style_t *)xmalloc(sizeof(style_t));
292 st->or_mask = or_mask;
293 st->and_mask = and_mask;
294 return st;