| 1 | /*
|
|---|
| 2 | * Create dynamic new structures of various types
|
|---|
| 3 | * and some utils in that trend.
|
|---|
| 4 | *
|
|---|
| 5 | * Copyright 1998 Bertho A. Stultiens
|
|---|
| 6 | *
|
|---|
| 7 | */
|
|---|
| 8 |
|
|---|
| 9 | #include "config.h"
|
|---|
| 10 |
|
|---|
| 11 | #include <stdio.h>
|
|---|
| 12 | #include <stdlib.h>
|
|---|
| 13 | #include <string.h>
|
|---|
| 14 | #include <assert.h>
|
|---|
| 15 | #include <string.h>
|
|---|
| 16 |
|
|---|
| 17 | #include "wrc.h"
|
|---|
| 18 | #include "newstruc.h"
|
|---|
| 19 | #include "utils.h"
|
|---|
| 20 | #include "parser.h"
|
|---|
| 21 |
|
|---|
| 22 | /* Generate new_* functions that have no parameters (NOTE: no ';') */
|
|---|
| 23 | __NEW_STRUCT_FUNC(dialog)
|
|---|
| 24 | __NEW_STRUCT_FUNC(dialogex)
|
|---|
| 25 | __NEW_STRUCT_FUNC(name_id)
|
|---|
| 26 | __NEW_STRUCT_FUNC(menu)
|
|---|
| 27 | __NEW_STRUCT_FUNC(menuex)
|
|---|
| 28 | __NEW_STRUCT_FUNC(menu_item)
|
|---|
| 29 | __NEW_STRUCT_FUNC(menuex_item)
|
|---|
| 30 | __NEW_STRUCT_FUNC(control)
|
|---|
| 31 | __NEW_STRUCT_FUNC(icon)
|
|---|
| 32 | __NEW_STRUCT_FUNC(cursor)
|
|---|
| 33 | __NEW_STRUCT_FUNC(versioninfo)
|
|---|
| 34 | __NEW_STRUCT_FUNC(ver_value)
|
|---|
| 35 | __NEW_STRUCT_FUNC(ver_block)
|
|---|
| 36 | __NEW_STRUCT_FUNC(stt_entry)
|
|---|
| 37 | __NEW_STRUCT_FUNC(accelerator)
|
|---|
| 38 | __NEW_STRUCT_FUNC(event)
|
|---|
| 39 | __NEW_STRUCT_FUNC(raw_data)
|
|---|
| 40 | __NEW_STRUCT_FUNC(lvc)
|
|---|
| 41 | __NEW_STRUCT_FUNC(res_count)
|
|---|
| 42 | __NEW_STRUCT_FUNC(string)
|
|---|
| 43 | __NEW_STRUCT_FUNC(toolbar_item)
|
|---|
| 44 |
|
|---|
| 45 | /* New instances for all types of structures */
|
|---|
| 46 | /* Very inefficient (in size), but very functional :-]
|
|---|
| 47 | * Especially for type-checking.
|
|---|
| 48 | */
|
|---|
| 49 | resource_t *new_resource(enum res_e t, void *res, int memopt, language_t *lan)
|
|---|
| 50 | {
|
|---|
| 51 | resource_t *r = (resource_t *)xmalloc(sizeof(resource_t));
|
|---|
| 52 | r->type = t;
|
|---|
| 53 | r->res.overlay = res;
|
|---|
| 54 | r->memopt = memopt;
|
|---|
| 55 | r->lan = lan;
|
|---|
| 56 | return r;
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | version_t *new_version(DWORD v)
|
|---|
| 60 | {
|
|---|
| 61 | version_t *vp = (version_t *)xmalloc(sizeof(version_t));
|
|---|
| 62 | *vp = v;
|
|---|
| 63 | return vp;
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | characts_t *new_characts(DWORD c)
|
|---|
| 67 | {
|
|---|
| 68 | characts_t *cp = (characts_t *)xmalloc(sizeof(characts_t));
|
|---|
| 69 | *cp = c;
|
|---|
| 70 | return cp;
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | language_t *new_language(int id, int sub)
|
|---|
| 74 | {
|
|---|
| 75 | language_t *lan = (language_t *)xmalloc(sizeof(language_t));
|
|---|
| 76 | lan->id = id;
|
|---|
| 77 | lan->sub = sub;
|
|---|
| 78 | return lan;
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | language_t *dup_language(language_t *l)
|
|---|
| 82 | {
|
|---|
| 83 | if(!l) return NULL;
|
|---|
| 84 | return new_language(l->id, l->sub);
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | version_t *dup_version(version_t *v)
|
|---|
| 88 | {
|
|---|
| 89 | if(!v) return NULL;
|
|---|
| 90 | return new_version(*v);
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | characts_t *dup_characts(characts_t *c)
|
|---|
| 94 | {
|
|---|
| 95 | if(!c) return NULL;
|
|---|
| 96 | return new_characts(*c);
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | rcdata_t *new_rcdata(raw_data_t *rd, int *memopt)
|
|---|
| 100 | {
|
|---|
| 101 | rcdata_t *rc = (rcdata_t *)xmalloc(sizeof(rcdata_t));
|
|---|
| 102 | rc->data = rd;
|
|---|
| 103 | if(memopt)
|
|---|
| 104 | {
|
|---|
| 105 | rc->memopt = *memopt;
|
|---|
| 106 | free(memopt);
|
|---|
| 107 | }
|
|---|
| 108 | else
|
|---|
| 109 | rc->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
|
|---|
| 110 | return rc;
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | font_id_t *new_font_id(int size, string_t *face, int weight, int italic)
|
|---|
| 114 | {
|
|---|
| 115 | font_id_t *fid = (font_id_t *)xmalloc(sizeof(font_id_t));
|
|---|
| 116 | fid->name = face;
|
|---|
| 117 | fid->size = size;
|
|---|
| 118 | fid->weight = weight;
|
|---|
| 119 | fid->italic = italic;
|
|---|
| 120 | return fid;
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | user_t *new_user(name_id_t *type, raw_data_t *rd, int *memopt)
|
|---|
| 124 | {
|
|---|
| 125 | user_t *usr = (user_t *)xmalloc(sizeof(user_t));
|
|---|
| 126 | usr->data = rd;
|
|---|
| 127 | if(memopt)
|
|---|
| 128 | {
|
|---|
| 129 | usr->memopt = *memopt;
|
|---|
| 130 | free(memopt);
|
|---|
| 131 | }
|
|---|
| 132 | else
|
|---|
| 133 | usr->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
|
|---|
| 134 | usr->type = type;
|
|---|
| 135 | return usr;
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | font_t *new_font(raw_data_t *rd, int *memopt)
|
|---|
| 139 | {
|
|---|
| 140 | font_t *fnt = (font_t *)xmalloc(sizeof(font_t));
|
|---|
| 141 | fnt->data = rd;
|
|---|
| 142 | if(memopt)
|
|---|
| 143 | {
|
|---|
| 144 | fnt->memopt = *memopt;
|
|---|
| 145 | free(memopt);
|
|---|
| 146 | }
|
|---|
| 147 | else
|
|---|
| 148 | fnt->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
|
|---|
| 149 | return fnt;
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 | icon_group_t *new_icon_group(raw_data_t *rd, int *memopt)
|
|---|
| 153 | {
|
|---|
| 154 | icon_group_t *icog = (icon_group_t *)xmalloc(sizeof(icon_group_t));
|
|---|
| 155 | if(memopt)
|
|---|
| 156 | {
|
|---|
| 157 | icog->memopt = *memopt;
|
|---|
| 158 | free(memopt);
|
|---|
| 159 | }
|
|---|
| 160 | else
|
|---|
| 161 | icog->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
|
|---|
| 162 | icog->lvc.language = dup_language(currentlanguage);
|
|---|
| 163 | split_icons(rd, icog, &(icog->nicon));
|
|---|
| 164 | free(rd->data);
|
|---|
| 165 | free(rd);
|
|---|
| 166 | return icog;
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 | cursor_group_t *new_cursor_group(raw_data_t *rd, int *memopt)
|
|---|
| 170 | {
|
|---|
| 171 | cursor_group_t *curg = (cursor_group_t *)xmalloc(sizeof(cursor_group_t));
|
|---|
| 172 | if(memopt)
|
|---|
| 173 | {
|
|---|
| 174 | curg->memopt = *memopt;
|
|---|
| 175 | free(memopt);
|
|---|
| 176 | }
|
|---|
| 177 | else
|
|---|
| 178 | curg->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
|
|---|
| 179 | curg->lvc.language = dup_language(currentlanguage);
|
|---|
| 180 | split_cursors(rd, curg, &(curg->ncursor));
|
|---|
| 181 | free(rd->data);
|
|---|
| 182 | free(rd);
|
|---|
| 183 | return curg;
|
|---|
| 184 | }
|
|---|
| 185 |
|
|---|
| 186 | bitmap_t *new_bitmap(raw_data_t *rd, int *memopt)
|
|---|
| 187 | {
|
|---|
| 188 | bitmap_t *bmp = (bitmap_t *)xmalloc(sizeof(bitmap_t));
|
|---|
| 189 | bmp->data = rd;
|
|---|
| 190 | if(memopt)
|
|---|
| 191 | {
|
|---|
| 192 | bmp->memopt = *memopt;
|
|---|
| 193 | free(memopt);
|
|---|
| 194 | }
|
|---|
| 195 | else
|
|---|
| 196 | bmp->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
|
|---|
| 197 | return bmp;
|
|---|
| 198 | }
|
|---|
| 199 |
|
|---|
| 200 | ver_words_t *new_ver_words(int i)
|
|---|
| 201 | {
|
|---|
| 202 | ver_words_t *w = (ver_words_t *)xmalloc(sizeof(ver_words_t));
|
|---|
| 203 | w->words = (WORD *)xmalloc(sizeof(WORD));
|
|---|
| 204 | w->words[0] = (WORD)i;
|
|---|
| 205 | w->nwords = 1;
|
|---|
| 206 | return w;
|
|---|
| 207 | }
|
|---|
| 208 |
|
|---|
| 209 | ver_words_t *add_ver_words(ver_words_t *w, int i)
|
|---|
| 210 | {
|
|---|
| 211 | w->words = (WORD *)xrealloc(w->words, (w->nwords+1) * sizeof(WORD));
|
|---|
| 212 | w->words[w->nwords] = (WORD)i;
|
|---|
| 213 | w->nwords++;
|
|---|
| 214 | return w;
|
|---|
| 215 | }
|
|---|
| 216 |
|
|---|
| 217 | messagetable_t *new_messagetable(raw_data_t *rd)
|
|---|
| 218 | {
|
|---|
| 219 | messagetable_t *msg = (messagetable_t *)xmalloc(sizeof(messagetable_t));
|
|---|
| 220 | msg->data = rd;
|
|---|
| 221 | return msg;
|
|---|
| 222 | }
|
|---|
| 223 |
|
|---|
| 224 | void copy_raw_data(raw_data_t *dst, raw_data_t *src, int offs, int len)
|
|---|
| 225 | {
|
|---|
| 226 | assert(offs <= src->size);
|
|---|
| 227 | assert(offs + len <= src->size);
|
|---|
| 228 | if(!dst->data)
|
|---|
| 229 | {
|
|---|
| 230 | dst->data = (char *)xmalloc(len);
|
|---|
| 231 | dst->size = 0;
|
|---|
| 232 | }
|
|---|
| 233 | else
|
|---|
| 234 | dst->data = (char *)xrealloc(dst->data, dst->size + len);
|
|---|
| 235 | /* dst->size holds the offset to copy to */
|
|---|
| 236 | memcpy(dst->data + dst->size, src->data + offs, len);
|
|---|
| 237 | dst->size += len;
|
|---|
| 238 | }
|
|---|
| 239 |
|
|---|
| 240 | int *new_int(int i)
|
|---|
| 241 | {
|
|---|
| 242 | int *ip = (int *)xmalloc(sizeof(int));
|
|---|
| 243 | *ip = i;
|
|---|
| 244 | return ip;
|
|---|
| 245 | }
|
|---|
| 246 |
|
|---|
| 247 | stringtable_t *new_stringtable(lvc_t *lvc)
|
|---|
| 248 | {
|
|---|
| 249 | stringtable_t *stt = (stringtable_t *)xmalloc(sizeof(stringtable_t));
|
|---|
| 250 |
|
|---|
| 251 | if(lvc)
|
|---|
| 252 | stt->lvc = *lvc;
|
|---|
| 253 |
|
|---|
| 254 | return stt;
|
|---|
| 255 | }
|
|---|
| 256 |
|
|---|
| 257 | toolbar_t *new_toolbar(int button_width, int button_height, toolbar_item_t *items, int nitems)
|
|---|
| 258 | {
|
|---|
| 259 | toolbar_t *tb = (toolbar_t *)xmalloc(sizeof(toolbar_t));
|
|---|
| 260 | tb->button_width = button_width;
|
|---|
| 261 | tb->button_height = button_height;
|
|---|
| 262 | tb->nitems = nitems;
|
|---|
| 263 | tb->items = items;
|
|---|
| 264 | return tb;
|
|---|
| 265 | }
|
|---|
| 266 |
|
|---|
| 267 | dlginit_t *new_dlginit(raw_data_t *rd, int *memopt)
|
|---|
| 268 | {
|
|---|
| 269 | dlginit_t *di = (dlginit_t *)xmalloc(sizeof(dlginit_t));
|
|---|
| 270 | di->data = rd;
|
|---|
| 271 | if(memopt)
|
|---|
| 272 | {
|
|---|
| 273 | di->memopt = *memopt;
|
|---|
| 274 | free(memopt);
|
|---|
| 275 | }
|
|---|
| 276 | else
|
|---|
| 277 | di->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
|
|---|
| 278 |
|
|---|
| 279 | return di;
|
|---|
| 280 | }
|
|---|
| 281 |
|
|---|
| 282 | style_pair_t *new_style_pair(int style, int exstyle)
|
|---|
| 283 | {
|
|---|
| 284 | style_pair_t *sp = (style_pair_t *)xmalloc(sizeof(style_pair_t));
|
|---|
| 285 | sp->style = style;
|
|---|
| 286 | sp->exstyle = exstyle;
|
|---|
| 287 | return sp;
|
|---|
| 288 | }
|
|---|