genres.c 33.9 KB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
1 2 3 4 5
/*
 * Generate .res format from a resource-tree
 *
 * Copyright 1998 Bertho A. Stultiens
 *
6 7 8 9 10 11 12 13 14 15 16 17
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 20
 *
 * History:
21 22 23
 * 05-May-2000 BS	- Added code to support endian conversions. The
 * 			  extra functions also aid unaligned access, but
 * 			  this is not yet implemented.
Alexandre Julliard's avatar
Alexandre Julliard committed
24
 * 25-May-1998 BS	- Added simple unicode -> char conversion for resource
25
 *			  names in .s and .h files.
Alexandre Julliard's avatar
Alexandre Julliard committed
26 27
 */

28 29
#include "config.h"

Alexandre Julliard's avatar
Alexandre Julliard committed
30 31 32
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
33
#include <stdarg.h>
Alexandre Julliard's avatar
Alexandre Julliard committed
34 35 36
#include <assert.h>
#include <ctype.h>

37
#include "../tools.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
38 39
#include "wrc.h"
#include "utils.h"
40
#include "windef.h"
41
#include "winbase.h"
42
#include "wingdi.h"
43
#include "winuser.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
44

45 46 47
unsigned char *output_buffer = NULL;
size_t output_buffer_pos = 0;
size_t output_buffer_size = 0;
48

49
static void set_word(int ofs, unsigned int w)
50
{
51 52
    output_buffer[ofs+0] = w;
    output_buffer[ofs+1] = w >> 8;
53 54
}

55 56 57 58 59 60 61 62 63
static void set_dword(int ofs, unsigned int d)
{
    output_buffer[ofs+0] = d;
    output_buffer[ofs+1] = d >> 8;
    output_buffer[ofs+2] = d >> 16;
    output_buffer[ofs+3] = d >> 24;
}

static unsigned int get_dword(int ofs)
64
{
65 66 67 68
    return (output_buffer[ofs+3] << 24)
         | (output_buffer[ofs+2] << 16)
         | (output_buffer[ofs+1] <<  8)
         |  output_buffer[ofs+0];
69 70
}

71
static void set_res_size(int tag)
72
{
73
    set_dword( tag, output_buffer_pos - tag - get_dword(tag) );
74 75
}

Alexandre Julliard's avatar
Alexandre Julliard committed
76 77 78 79 80 81
/*
 *****************************************************************************
 * Function	: string_to_upper
 * Syntax	: void string_to_upper(string_t *str)
 *****************************************************************************
*/
82
static void string_to_upper(string_t *str)
Alexandre Julliard's avatar
Alexandre Julliard committed
83
{
84 85
    int i;

86
    switch (str->type)
87
    {
88
    case str_char:
89 90
        for (i = 0; i < str->size; i++)
            if (str->str.cstr[i] >= 'a' && str->str.cstr[i] <= 'z') str->str.cstr[i] -= 32;
91 92
        break;
    case str_unicode:
93 94
        for (i = 0; i < str->size; i++)
            if (str->str.wstr[i] >= 'a' && str->str.wstr[i] <= 'z') str->str.wstr[i] -= 32;
95
        break;
96
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
97 98
}

99 100
static int parse_accel_string( const string_t *key, int flags )
{
101
    int keycode = 0;
102

103
    switch (key->type)
104
    {
105
    case str_char:
106
        if (key->str.cstr[0] == '#') return 0;  /* ignore message contexts */
107 108 109 110 111
	if((flags & WRC_AF_VIRTKEY) &&
           !((key->str.cstr[0] >= 'A' && key->str.cstr[0] <= 'Z') ||
             (key->str.cstr[0] >= '0' && key->str.cstr[0] <= '9')))
        {
            print_location( &key->loc );
112
            error("VIRTKEY code is not equal to ascii value\n");
113 114 115 116 117
        }

	if(key->str.cstr[0] == '^' && (flags & WRC_AF_CONTROL) != 0)
	{
            print_location( &key->loc );
118
            error("Cannot use both '^' and CONTROL modifier\n");
119 120 121
	}
	else if(key->str.cstr[0] == '^')
	{
122 123 124 125 126
            if (key->str.cstr[1] >= 'a' && key->str.cstr[1] <= 'z')
                keycode = key->str.cstr[1] - 'a' + 1;
            else if (key->str.cstr[1] >= 'A' && key->str.cstr[1] <= 'Z')
                keycode = key->str.cstr[1] - 'A' + 1;
            else
127 128
            {
                print_location( &key->loc );
129
                error("Control-code out of range\n");
130 131 132 133
            }
	}
	else
            keycode = key->str.cstr[0];
134 135 136
        break;

    case str_unicode:
137
        if (key->str.wstr[0] == '#') return 0;  /* ignore message contexts */
138 139 140 141 142
	if((flags & WRC_AF_VIRTKEY) &&
           !((key->str.wstr[0] >= 'A' && key->str.wstr[0] <= 'Z') ||
             (key->str.wstr[0] >= '0' && key->str.wstr[0] <= '9')))
        {
            print_location( &key->loc );
143
            error("VIRTKEY code is not equal to ascii value\n");
144 145 146 147
        }
	if(key->str.wstr[0] == '^' && (flags & WRC_AF_CONTROL) != 0)
	{
            print_location( &key->loc );
148
            error("Cannot use both '^' and CONTROL modifier\n");
149 150 151
	}
	else if(key->str.wstr[0] == '^')
	{
152 153 154 155 156
            if (key->str.wstr[1] >= 'a' && key->str.wstr[1] <= 'z')
                keycode = key->str.wstr[1] - 'a' + 1;
            else if (key->str.wstr[1] >= 'A' && key->str.wstr[1] <= 'Z')
                keycode = key->str.wstr[1] - 'A' + 1;
            else
157 158
            {
                print_location( &key->loc );
159
                error("Control-code out of range\n");
160 161 162 163
            }
	}
	else
            keycode = key->str.wstr[0];
164
        break;
165 166 167 168
    }
    return keycode;
}

Alexandre Julliard's avatar
Alexandre Julliard committed
169 170 171 172 173 174 175 176 177
/*
 *****************************************************************************
 * Function	: put_string
 * Input	:
 *	str	- String to put
 *	isterm	- The string is '\0' terminated (disregard the string's
 *		  size member)
 *****************************************************************************
*/
178
static void put_string(const string_t *str, int isterm, const language_t *lang)
Alexandre Julliard's avatar
Alexandre Julliard committed
179
{
180 181
    int cnt, codepage;

182
    if (win32)
183
    {
184 185 186 187 188 189 190 191
        string_t *newstr;

        if (lang) codepage = get_language_codepage( lang->id, lang->sub );
        else codepage = get_language_codepage( 0, 0 );
        assert( codepage != -1 );

        newstr = convert_string_unicode( str, codepage );
        if (str->type == str_char && check_valid_utf8( str, codepage ))
192
        {
193 194 195
            print_location( &str->loc );
            warning( "string \"%s\" seems to be UTF-8 but codepage %u is in use, maybe use --utf8?\n",
                     str->str.cstr, codepage );
196
        }
197
        if (!isterm) put_word(newstr->size);
198 199 200 201
        for(cnt = 0; cnt < newstr->size; cnt++)
        {
            WCHAR c = newstr->str.wstr[cnt];
            if (isterm && !c) break;
202
            put_word(c);
203
        }
204
        if (isterm) put_word(0);
205
        free_string(newstr);
206
    }
207
    else
208
    {
209
        assert( str->type == str_char );
210
        if (!isterm) put_byte(str->size);
211
        for(cnt = 0; cnt < str->size; cnt++)
212
        {
213
            char c = str->str.cstr[cnt];
214
            if (isterm && !c) break;
215
            put_byte(c);
216
        }
217
        if (isterm) put_byte(0);
218
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
219 220 221 222 223 224 225
}

/*
 *****************************************************************************
 * Function	: put_name_id
 *****************************************************************************
*/
226
static void put_name_id(name_id_t *nid, int upcase, const language_t *lang)
Alexandre Julliard's avatar
Alexandre Julliard committed
227
{
228
	switch (nid->type)
Alexandre Julliard's avatar
Alexandre Julliard committed
229
	{
230
	case name_ord:
Alexandre Julliard's avatar
Alexandre Julliard committed
231
		if(win32)
232
			put_word(0xffff);
Alexandre Julliard's avatar
Alexandre Julliard committed
233
		else
234 235
			put_byte(0xff);
		put_word((WORD)nid->name.i_name);
236 237
		break;
	case name_str:
Alexandre Julliard's avatar
Alexandre Julliard committed
238 239
		if(upcase)
			string_to_upper(nid->name.s_name);
240
		put_string(nid->name.s_name, TRUE, lang);
241
		break;
Alexandre Julliard's avatar
Alexandre Julliard committed
242 243 244 245 246 247 248 249
	}
}

/*
 *****************************************************************************
 * Function	: put_lvc
 *****************************************************************************
*/
250
static void put_lvc(lvc_t *lvc)
Alexandre Julliard's avatar
Alexandre Julliard committed
251 252
{
	if(lvc && lvc->language)
253
		put_word(MAKELANGID(lvc->language->id, lvc->language->sub));
Alexandre Julliard's avatar
Alexandre Julliard committed
254
	else
255
		put_word(0);	/* Neutral */
Alexandre Julliard's avatar
Alexandre Julliard committed
256
	if(lvc && lvc->version)
257
		put_dword(*lvc->version);
Alexandre Julliard's avatar
Alexandre Julliard committed
258
	else
259
		put_dword(0);
Alexandre Julliard's avatar
Alexandre Julliard committed
260
	if(lvc && lvc->characts)
261
		put_dword(*lvc->characts);
Alexandre Julliard's avatar
Alexandre Julliard committed
262
	else
263
		put_dword(0);
Alexandre Julliard's avatar
Alexandre Julliard committed
264 265 266 267 268 269
}

/*
 *****************************************************************************
 * Function	: put_res_header
 * Input	:
270
 *	type	- Resource identifier
Alexandre Julliard's avatar
Alexandre Julliard committed
271 272 273 274 275 276 277
 *	name	- Resource's name
 *	memopt	- Resource's memory options to write
 *	lvc	- Language, version and characteristics (win32 only)
 * Output	: An index to the resource size field. The resource size field
 *		  contains the header size upon exit.
 *****************************************************************************
*/
278
static int put_res_header(int type, name_id_t *name, DWORD memopt, lvc_t *lvc)
Alexandre Julliard's avatar
Alexandre Julliard committed
279
{
280
	int tag = output_buffer_pos;
Alexandre Julliard's avatar
Alexandre Julliard committed
281 282
	if(win32)
	{
283 284 285 286 287 288 289 290 291 292 293
		put_dword(0);		/* We will overwrite these later */
		put_dword(0);
		put_word(0xffff);		/* ResType */
		put_word(type);
		put_name_id(name, TRUE, lvc->language); /* ResName */
		align_output(4);
		put_dword(0);		/* DataVersion */
		put_word(memopt);		/* Memory options */
		put_lvc(lvc);		/* Language, version and characts */
		set_dword(tag + 0, output_buffer_pos - tag);
		set_dword(tag + 4, output_buffer_pos - tag);	/* Set HeaderSize */
Alexandre Julliard's avatar
Alexandre Julliard committed
294 295 296
	}
	else /* win16 */
	{
297 298 299 300 301 302
		put_byte(0xff);		/* ResType */
		put_word(type);
		put_name_id(name, TRUE, NULL); /* ResName */
		put_word(memopt);		/* Memory options */
		tag = output_buffer_pos;
		put_dword(4);		/* ResSize overwritten later*/
Alexandre Julliard's avatar
Alexandre Julliard committed
303
	}
304
	return tag;
Alexandre Julliard's avatar
Alexandre Julliard committed
305 306 307 308 309 310 311 312 313 314
}

/*
 *****************************************************************************
 * Function	: accelerator2res
 * Input	:
 *	name	- Name/ordinal of the resource
 *	acc	- The accelerator descriptor
 *****************************************************************************
*/
315
static void accelerator2res(name_id_t *name, accelerator_t *acc)
Alexandre Julliard's avatar
Alexandre Julliard committed
316 317 318 319
{
	int restag;
	event_t *ev;

320
	restag = put_res_header(WRC_RT_ACCELERATOR, name, acc->memopt, &acc->lvc);
Alexandre Julliard's avatar
Alexandre Julliard committed
321 322
	if(win32)
	{
323
		for (ev = acc->events; ev; ev = ev->next)
Alexandre Julliard's avatar
Alexandre Julliard committed
324
		{
325 326
			int key = ev->key;
			if (ev->str) key = parse_accel_string( ev->str, ev->flags );
327 328 329 330
			put_word(ev->flags | (ev->next ? 0 : 0x80));
			put_word(key);
			put_word(ev->id);
                        align_output(4);
Alexandre Julliard's avatar
Alexandre Julliard committed
331 332 333 334
		}
	}
	else /* win16 */
	{
335
		for (ev = acc->events; ev; ev = ev->next)
Alexandre Julliard's avatar
Alexandre Julliard committed
336
		{
337 338
			int key = ev->key;
			if (ev->str) key = parse_accel_string( ev->str, ev->flags );
339 340 341
			put_byte(ev->flags | (ev->next ? 0 : 0x80));
			put_word(key);
			put_word(ev->id);
Alexandre Julliard's avatar
Alexandre Julliard committed
342 343
		}
	}
344
	set_res_size(restag);
Alexandre Julliard's avatar
Alexandre Julliard committed
345 346 347 348 349 350 351 352 353 354
}

/*
 *****************************************************************************
 * Function	: dialog2res
 * Input	:
 *	name	- Name/ordinal of the resource
 *	dlg	- The dialog descriptor
 *****************************************************************************
*/
355
static void dialog2res(name_id_t *name, dialog_t *dlg)
Alexandre Julliard's avatar
Alexandre Julliard committed
356 357 358
{
	int restag;
	control_t *ctrl;
359
	int nctrl;
Alexandre Julliard's avatar
Alexandre Julliard committed
360

361 362
        restag = put_res_header(WRC_RT_DIALOG, name, dlg->memopt, &dlg->lvc);
	for (ctrl = dlg->controls, nctrl = 0; ctrl; ctrl = ctrl->next) nctrl++;
Alexandre Julliard's avatar
Alexandre Julliard committed
363 364
	if(win32)
	{
365 366 367 368 369 370 371 372
		if (dlg->is_ex)
		{
			/* FIXME: MS doc says that the first word must contain 0xffff
			 * and the second 0x0001 to signal a DLGTEMPLATEEX. Borland's
			 * compiler reverses the two words.
			 * I don't know which one to choose, but I write it as Mr. B
			 * writes it.
			 */
373 374 375 376 377
			put_word(1);		/* Signature */
			put_word(0xffff);		/* DlgVer */
			put_dword(dlg->gothelpid ? dlg->helpid : 0);
			put_dword(dlg->gotexstyle ? dlg->exstyle->or_mask : 0);
			put_dword(dlg->gotstyle ? dlg->style->or_mask : WS_POPUPWINDOW);
378 379 380
		}
		else
		{
381 382
			put_dword(dlg->style->or_mask);
			put_dword(dlg->gotexstyle ? dlg->exstyle->or_mask : 0);
383
		}
384 385 386 387 388
		put_word(nctrl);
		put_word(dlg->x);
		put_word(dlg->y);
		put_word(dlg->width);
		put_word(dlg->height);
Alexandre Julliard's avatar
Alexandre Julliard committed
389
		if(dlg->menu)
390
			put_name_id(dlg->menu, FALSE, dlg->lvc.language);
Alexandre Julliard's avatar
Alexandre Julliard committed
391
		else
392
			put_word(0);
Alexandre Julliard's avatar
Alexandre Julliard committed
393
		if(dlg->dlgclass)
394
			put_name_id(dlg->dlgclass, FALSE, dlg->lvc.language);
Alexandre Julliard's avatar
Alexandre Julliard committed
395
		else
396
			put_word(0);
Alexandre Julliard's avatar
Alexandre Julliard committed
397
		if(dlg->title)
398
			put_string(dlg->title, TRUE, dlg->lvc.language);
Alexandre Julliard's avatar
Alexandre Julliard committed
399
		else
400
			put_word(0);
Alexandre Julliard's avatar
Alexandre Julliard committed
401 402
		if(dlg->font)
		{
403
			put_word(dlg->font->size);
404 405
			if (dlg->is_ex)
			{
406
				put_word(dlg->font->weight);
407 408 409 410
				/* FIXME: ? TRUE should be sufficient to say that it's
				 * italic, but Borland's compiler says it's 0x0101.
				 * I just copy it here, and hope for the best.
				 */
411
				put_word(dlg->font->italic ? 0x0101 : 0);
412
			}
413
			put_string(dlg->font->name, TRUE, dlg->lvc.language);
Alexandre Julliard's avatar
Alexandre Julliard committed
414
		}
415
                else if (dlg->style->or_mask & DS_SETFONT) put_word( 0x7fff );
Alexandre Julliard's avatar
Alexandre Julliard committed
416

417 418
		align_output(4);
		for (ctrl = dlg->controls; ctrl; ctrl = ctrl->next)
Alexandre Julliard's avatar
Alexandre Julliard committed
419
		{
420 421
			if (dlg->is_ex)
			{
422 423
				put_dword(ctrl->gothelpid ? ctrl->helpid : 0);
				put_dword(ctrl->gotexstyle ? ctrl->exstyle->or_mask : 0);
424
				/* FIXME: what is default control style? */
425
				put_dword(ctrl->gotstyle ? ctrl->style->or_mask : WS_CHILD | WS_VISIBLE);
426 427 428 429
			}
			else
			{
				/* FIXME: what is default control style? */
430 431
				put_dword(ctrl->gotstyle ? ctrl->style->or_mask: WS_CHILD);
				put_dword(ctrl->gotexstyle ? ctrl->exstyle->or_mask : 0);
432
			}
433 434 435 436
			put_word(ctrl->x);
			put_word(ctrl->y);
			put_word(ctrl->width);
			put_word(ctrl->height);
437
			if (dlg->is_ex)
438
				put_dword(ctrl->id);
439
			else
440 441
				put_word(ctrl->id);
			put_name_id(ctrl->ctlclass, FALSE, dlg->lvc.language);
Alexandre Julliard's avatar
Alexandre Julliard committed
442
			if(ctrl->title)
443
				put_name_id(ctrl->title, FALSE, dlg->lvc.language);
Alexandre Julliard's avatar
Alexandre Julliard committed
444
			else
445
				put_word(0);
Alexandre Julliard's avatar
Alexandre Julliard committed
446 447
			if(ctrl->extra)
			{
448 449
				put_word(ctrl->extra->size);
				put_data(ctrl->extra->data, ctrl->extra->size);
Alexandre Julliard's avatar
Alexandre Julliard committed
450 451
			}
			else
452
				put_word(0);
Alexandre Julliard's avatar
Alexandre Julliard committed
453 454

			if(ctrl->next)
455
				align_output(4);
Alexandre Julliard's avatar
Alexandre Julliard committed
456 457 458 459
		}
	}
	else /* win16 */
	{
460 461 462 463 464 465 466 467
		restag = put_res_header(WRC_RT_DIALOG, name, dlg->memopt, NULL);

		put_dword(dlg->gotstyle ? dlg->style->or_mask : WS_POPUPWINDOW);
		put_byte(nctrl);
		put_word(dlg->x);
		put_word(dlg->y);
		put_word(dlg->width);
		put_word(dlg->height);
Alexandre Julliard's avatar
Alexandre Julliard committed
468
		if(dlg->menu)
469
			put_name_id(dlg->menu, TRUE, NULL);
Alexandre Julliard's avatar
Alexandre Julliard committed
470
		else
471
			put_byte(0);
Alexandre Julliard's avatar
Alexandre Julliard committed
472
		if(dlg->dlgclass)
473
			put_name_id(dlg->dlgclass, TRUE, NULL);
Alexandre Julliard's avatar
Alexandre Julliard committed
474
		else
475
			put_byte(0);
Alexandre Julliard's avatar
Alexandre Julliard committed
476
		if(dlg->title)
477
			put_string(dlg->title, TRUE, NULL);
Alexandre Julliard's avatar
Alexandre Julliard committed
478
		else
479
			put_byte(0);
Alexandre Julliard's avatar
Alexandre Julliard committed
480 481
		if(dlg->font)
		{
482 483
			put_word(dlg->font->size);
			put_string(dlg->font->name, TRUE, NULL);
Alexandre Julliard's avatar
Alexandre Julliard committed
484 485
		}

486
		for (ctrl = dlg->controls; ctrl; ctrl = ctrl->next)
Alexandre Julliard's avatar
Alexandre Julliard committed
487
		{
488 489 490 491 492 493
			put_word(ctrl->x);
			put_word(ctrl->y);
			put_word(ctrl->width);
			put_word(ctrl->height);
			put_word(ctrl->id);
			put_dword(ctrl->gotstyle ? ctrl->style->or_mask: WS_CHILD);
494 495 496
			if(ctrl->ctlclass->type == name_ord
			&& ctrl->ctlclass->name.i_name >= 0x80
			&& ctrl->ctlclass->name.i_name <= 0x85)
497
				put_byte(ctrl->ctlclass->name.i_name);
498
			else if(ctrl->ctlclass->type == name_str)
499
				put_name_id(ctrl->ctlclass, FALSE, NULL);
Alexandre Julliard's avatar
Alexandre Julliard committed
500
			else
501
				error("Unknown control-class %04x\n", ctrl->ctlclass->name.i_name);
Alexandre Julliard's avatar
Alexandre Julliard committed
502
			if(ctrl->title)
503
				put_name_id(ctrl->title, FALSE, NULL);
Alexandre Julliard's avatar
Alexandre Julliard committed
504
			else
505
				put_byte(0);
Alexandre Julliard's avatar
Alexandre Julliard committed
506 507

			/* FIXME: What is this extra byte doing here? */
508
			put_byte(0);
Alexandre Julliard's avatar
Alexandre Julliard committed
509 510
		}
	}
511
	set_res_size(restag);
Alexandre Julliard's avatar
Alexandre Julliard committed
512 513 514 515 516 517 518 519
}

/*
 *****************************************************************************
 * Function	: menuitem2res
 * Remarks	: Self recursive
 *****************************************************************************
*/
520
static void menuitem2res(menu_item_t *menitem, const language_t *lang)
Alexandre Julliard's avatar
Alexandre Julliard committed
521 522
{
	menu_item_t *itm = menitem;
523 524

	while(itm)
Alexandre Julliard's avatar
Alexandre Julliard committed
525
	{
526
		put_word(itm->state | (itm->popup ? MF_POPUP : 0) | (!itm->next ? MF_END : 0));
527
		if(!itm->popup)
528
			put_word(itm->id);
529
		if(itm->name)
530
			put_string(itm->name, TRUE, lang);
531 532
		else
                {
533 534
			if (win32) put_word(0);
			else put_byte(0);
Alexandre Julliard's avatar
Alexandre Julliard committed
535
		}
536
		if(itm->popup)
537
			menuitem2res(itm->popup, lang);
538
		itm = itm->next;
Alexandre Julliard's avatar
Alexandre Julliard committed
539 540 541 542 543 544 545 546 547
	}
}

/*
 *****************************************************************************
 * Function	: menuexitem2res
 * Remarks	: Self recursive
 *****************************************************************************
*/
548
static void menuexitem2res(menu_item_t *menitem, const language_t *lang)
Alexandre Julliard's avatar
Alexandre Julliard committed
549
{
550
	menu_item_t *itm = menitem;
Alexandre Julliard's avatar
Alexandre Julliard committed
551 552 553
	assert(win32 != 0);
	while(itm)
	{
554 555 556 557
		put_dword(itm->gottype ? itm->type : 0);
		put_dword(itm->gotstate ? itm->state : 0);
		put_dword(itm->gotid ? itm->id : 0);
		put_word((itm->popup ? 0x01 : 0) | (!itm->next ? MF_END : 0));
Alexandre Julliard's avatar
Alexandre Julliard committed
558
		if(itm->name)
559
			put_string(itm->name, TRUE, lang);
Alexandre Julliard's avatar
Alexandre Julliard committed
560
		else
561 562
			put_word(0);
		align_output(4);
Alexandre Julliard's avatar
Alexandre Julliard committed
563 564
		if(itm->popup)
		{
565 566
			put_dword(itm->gothelpid ? itm->helpid : 0);
			menuexitem2res(itm->popup, lang);
Alexandre Julliard's avatar
Alexandre Julliard committed
567 568 569 570 571 572 573 574
		}
		itm = itm->next;
	}

}

/*
 *****************************************************************************
575
 * Function	: menu2res
Alexandre Julliard's avatar
Alexandre Julliard committed
576 577 578 579 580
 * Input	:
 *	name	- Name/ordinal of the resource
 *	menex	- The menuex descriptor
 *****************************************************************************
*/
581
static void menu2res(name_id_t *name, menu_t *men)
Alexandre Julliard's avatar
Alexandre Julliard committed
582 583 584
{
	int restag;
	assert(name != NULL);
585
	assert(men != NULL);
Alexandre Julliard's avatar
Alexandre Julliard committed
586

587
	restag = put_res_header(WRC_RT_MENU, name, men->memopt, &men->lvc);
Alexandre Julliard's avatar
Alexandre Julliard committed
588 589
	if(win32)
	{
590 591
		if (men->is_ex)
		{
592 593 594 595 596
			put_word(1);		/* Menuheader: Version */
			put_word(4);		/* Offset */
			put_dword(0);		/* HelpId */
			align_output(4);
			menuexitem2res(men->items, men->lvc.language);
597 598 599
		}
		else
		{
600 601
			put_dword(0);		/* Menuheader: Version and HeaderSize */
			menuitem2res(men->items, men->lvc.language);
602
		}
Alexandre Julliard's avatar
Alexandre Julliard committed
603 604 605
	}
	else /* win16 */
	{
606 607
		put_dword(0);		/* Menuheader: Version and HeaderSize */
		menuitem2res(men->items, NULL);
Alexandre Julliard's avatar
Alexandre Julliard committed
608
	}
609
	set_res_size(restag);
Alexandre Julliard's avatar
Alexandre Julliard committed
610 611 612 613 614 615 616 617 618 619
}

/*
 *****************************************************************************
 * Function	: cursorgroup2res
 * Input	:
 *	name	- Name/ordinal of the resource
 *	curg	- The cursor descriptor
 *****************************************************************************
*/
620
static void cursorgroup2res(name_id_t *name, cursor_group_t *curg)
Alexandre Julliard's avatar
Alexandre Julliard committed
621
{
622 623
    int restag;
    cursor_t *cur;
Alexandre Julliard's avatar
Alexandre Julliard committed
624

625
    restag = put_res_header(WRC_RT_GROUP_CURSOR, name, curg->memopt, &curg->lvc);
626

627
    put_word(0);	/* Reserved */
628 629 630 631 632 633
    /* FIXME: The ResType in the NEWHEADER structure should
     * contain 14 according to the MS win32 doc. This is
     * not the case with the BRC compiler and I really doubt
     * the latter. Putting one here is compliant to win16 spec,
     * but who knows the true value?
     */
634 635
    put_word(2);	/* ResType */
    put_word(curg->ncursor);
Alexandre Julliard's avatar
Alexandre Julliard committed
636
#if 0
637
    for(cur = curg->cursorlist; cur; cur = cur->next)
Alexandre Julliard's avatar
Alexandre Julliard committed
638
#else
639 640 641 642
    cur = curg->cursorlist;
    while(cur->next)
        cur = cur->next;
    for(; cur; cur = cur->prev)
Alexandre Julliard's avatar
Alexandre Julliard committed
643
#endif
644
    {
645
        put_word(cur->width);
646 647 648 649 650
        /* FIXME: The height of a cursor is half the size of
         * the bitmap's height. BRC puts the height from the
         * BITMAPINFOHEADER here instead of the cursorfile's
         * height. MS doesn't seem to care...
         */
651
        put_word(cur->height);
652 653 654 655 656
        /* FIXME: The next two are reversed in BRC and I don't
         * know why. Probably a bug. But, we can safely ignore
         * it because win16 does not support color cursors.
         * A warning should have been generated by the parser.
         */
657 658
        put_word(cur->planes);
        put_word(cur->bits);
659 660 661 662 663
        /* FIXME: The +4 is the hotspot in the cursor resource.
         * However, I could not find this in the documentation.
         * The hotspot bytes must either be included or MS
         * doesn't care.
         */
664 665
        put_dword(cur->data->size +4);
        put_word(cur->id);
666 667
    }

668
    set_res_size(restag);
Alexandre Julliard's avatar
Alexandre Julliard committed
669 670 671 672 673 674 675 676 677
}

/*
 *****************************************************************************
 * Function	: cursor2res
 * Input	:
 *	cur	- The cursor descriptor
 *****************************************************************************
*/
678
static void cursor2res(cursor_t *cur)
Alexandre Julliard's avatar
Alexandre Julliard committed
679 680 681 682 683 684
{
	int restag;
	name_id_t name;

	name.type = name_ord;
	name.name.i_name = cur->id;
685 686 687 688
	restag = put_res_header(WRC_RT_CURSOR, &name, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, &cur->lvc);
	put_word(cur->xhot);
	put_word(cur->yhot);
	put_data(cur->data->data, cur->data->size);
Alexandre Julliard's avatar
Alexandre Julliard committed
689

690
	set_res_size(restag);
Alexandre Julliard's avatar
Alexandre Julliard committed
691 692 693 694 695 696 697 698 699 700
}

/*
 *****************************************************************************
 * Function	: icongroup2res
 * Input	:
 *	name	- Name/ordinal of the resource
 *	icog	- The icon group descriptor
 *****************************************************************************
*/
701
static void icongroup2res(name_id_t *name, icon_group_t *icog)
Alexandre Julliard's avatar
Alexandre Julliard committed
702
{
703 704
    int restag;
    icon_t *ico;
Alexandre Julliard's avatar
Alexandre Julliard committed
705

706
    restag = put_res_header(WRC_RT_GROUP_ICON, name, icog->memopt, &icog->lvc);
707

708
    put_word(0);	/* Reserved */
709 710 711 712 713 714
    /* FIXME: The ResType in the NEWHEADER structure should
     * contain 14 according to the MS win32 doc. This is
     * not the case with the BRC compiler and I really doubt
     * the latter. Putting one here is compliant to win16 spec,
     * but who knows the true value?
     */
715 716
    put_word(1);	/* ResType */
    put_word(icog->nicon);
717 718
    for(ico = icog->iconlist; ico; ico = ico->next)
    {
719 720 721 722 723 724 725 726
        put_byte(ico->width);
        put_byte(ico->height);
        put_byte(ico->nclr);
        put_byte(0);	/* Reserved */
        put_word(ico->planes);
        put_word(ico->bits);
        put_dword(ico->data->size);
        put_word(ico->id);
727 728
    }

729
    set_res_size(restag);
Alexandre Julliard's avatar
Alexandre Julliard committed
730 731 732 733 734 735 736 737 738
}

/*
 *****************************************************************************
 * Function	: icon2res
 * Input	:
 *	ico	- The icon descriptor
 *****************************************************************************
*/
739
static void icon2res(icon_t *ico)
Alexandre Julliard's avatar
Alexandre Julliard committed
740 741 742 743 744 745
{
	int restag;
	name_id_t name;

	name.type = name_ord;
	name.name.i_name = ico->id;
746 747 748
	restag = put_res_header(WRC_RT_ICON, &name, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, &ico->lvc);
	put_data(ico->data->data, ico->data->size);
	set_res_size(restag);
Alexandre Julliard's avatar
Alexandre Julliard committed
749 750
}

751 752 753 754 755 756
/*
 *****************************************************************************
 * Function	: anicurico2res
 * Input	:
 *	name	- Name/ordinal of the resource
 *	ani	- The animated object descriptor
757
 * Remarks	: There are rumors that win311 could handle animated stuff.
758 759 760 761
 * 		  That is why they are generated for both win16 and win32
 * 		  compile.
 *****************************************************************************
*/
762
static void anicur2res(name_id_t *name, ani_curico_t *ani)
763
{
764 765 766 767 768
	int restag = put_res_header(WRC_RT_ANICURSOR, name, ani->memopt, NULL);

	put_data(ani->data->data, ani->data->size);
	set_res_size(restag);
}
769

770 771 772 773 774 775
static void aniico2res(name_id_t *name, ani_curico_t *ani)
{
	int restag = put_res_header(WRC_RT_ANIICON, name, ani->memopt, NULL);

	put_data(ani->data->data, ani->data->size);
	set_res_size(restag);
776 777
}

Alexandre Julliard's avatar
Alexandre Julliard committed
778 779 780 781 782 783 784 785
/*
 *****************************************************************************
 * Function	: bitmap2res
 * Input	:
 *	name	- Name/ordinal of the resource
 *	bmp	- The bitmap descriptor
 *****************************************************************************
*/
786
static void bitmap2res(name_id_t *name, bitmap_t *bmp)
Alexandre Julliard's avatar
Alexandre Julliard committed
787
{
788
	int restag = put_res_header(WRC_RT_BITMAP, name, bmp->memopt, &bmp->data->lvc);
Alexandre Julliard's avatar
Alexandre Julliard committed
789 790 791 792 793 794 795

	if(bmp->data->data[0] == 'B'
	&& bmp->data->data[1] == 'M'
	&& ((BITMAPFILEHEADER *)bmp->data->data)->bfSize == bmp->data->size
	&& bmp->data->size >= sizeof(BITMAPFILEHEADER))
	{
		/* The File header is still attached, don't write it */
796
		put_data((BITMAPFILEHEADER *)bmp->data->data + 1, bmp->data->size - sizeof(BITMAPFILEHEADER));
Alexandre Julliard's avatar
Alexandre Julliard committed
797 798 799
	}
	else
	{
800
		put_data(bmp->data->data, bmp->data->size);
Alexandre Julliard's avatar
Alexandre Julliard committed
801
	}
802
	set_res_size(restag);
Alexandre Julliard's avatar
Alexandre Julliard committed
803 804 805 806 807 808 809 810
}

/*
 *****************************************************************************
 * Function	: font2res
 * Input	:
 *	name	- Name/ordinal of the resource
 *	fnt	- The font descriptor
811
 * Remarks	: The data has been prepared just after parsing.
Alexandre Julliard's avatar
Alexandre Julliard committed
812 813
 *****************************************************************************
*/
814
static void font2res(name_id_t *name, font_t *fnt)
Alexandre Julliard's avatar
Alexandre Julliard committed
815
{
816
	int restag = put_res_header(WRC_RT_FONT, name, fnt->memopt, &fnt->data->lvc);
817

818 819
	put_data(fnt->data->data, fnt->data->size);
	set_res_size(restag);
820 821 822 823 824 825 826 827 828 829 830
}

/*
 *****************************************************************************
 * Function	: fontdir2res
 * Input	:
 *	name	- Name/ordinal of the resource
 *	fntdir	- The fontdir descriptor
 * Remarks	: The data has been prepared just after parsing.
 *****************************************************************************
*/
831
static void fontdir2res(name_id_t *name, fontdir_t *fnd)
832
{
833
	int restag = put_res_header(WRC_RT_FONTDIR, name, fnd->memopt, &fnd->data->lvc);
834

835 836
	put_data(fnd->data->data, fnd->data->size);
	set_res_size(restag);
Alexandre Julliard's avatar
Alexandre Julliard committed
837 838
}

839 840 841 842 843 844 845 846
/*
 *****************************************************************************
 * Function	: html2res
 * Input	:
 *	name	- Name/ordinal of the resource
 *	rdt	- The html descriptor
 *****************************************************************************
*/
847
static void html2res(name_id_t *name, html_t *html)
848
{
849
	int restag = put_res_header(WRC_RT_HTML, name, html->memopt, &html->data->lvc);
850

851 852
	put_data(html->data->data, html->data->size);
	set_res_size(restag);
853 854
}

Alexandre Julliard's avatar
Alexandre Julliard committed
855 856 857 858 859 860 861 862
/*
 *****************************************************************************
 * Function	: rcdata2res
 * Input	:
 *	name	- Name/ordinal of the resource
 *	rdt	- The rcdata descriptor
 *****************************************************************************
*/
863
static void rcdata2res(name_id_t *name, rcdata_t *rdt)
Alexandre Julliard's avatar
Alexandre Julliard committed
864
{
865
	int restag = put_res_header(WRC_RT_RCDATA, name, rdt->memopt, &rdt->data->lvc);
Alexandre Julliard's avatar
Alexandre Julliard committed
866

867 868
	put_data(rdt->data->data, rdt->data->size);
	set_res_size(restag);
Alexandre Julliard's avatar
Alexandre Julliard committed
869 870 871 872 873 874 875 876 877 878
}

/*
 *****************************************************************************
 * Function	: messagetable2res
 * Input	:
 *	name	- Name/ordinal of the resource
 *	msg	- The messagetable descriptor
 *****************************************************************************
*/
879
static void messagetable2res(name_id_t *name, messagetable_t *msg)
Alexandre Julliard's avatar
Alexandre Julliard committed
880
{
881
	int restag = put_res_header(WRC_RT_MESSAGETABLE, name, msg->memopt, &msg->data->lvc);
882

883 884
	put_data(msg->data->data, msg->data->size);
	set_res_size(restag);
Alexandre Julliard's avatar
Alexandre Julliard committed
885 886 887 888 889 890 891 892 893
}

/*
 *****************************************************************************
 * Function	: stringtable2res
 * Input	:
 *	stt	- The stringtable descriptor
 *****************************************************************************
*/
894
static void stringtable2res(stringtable_t *stt)
Alexandre Julliard's avatar
Alexandre Julliard committed
895 896 897 898 899 900 901 902 903
{
	name_id_t name;
	int i;
	int restag;

	for(; stt; stt = stt->next)
	{
		if(!stt->nentries)
		{
904
			warning("Empty internal stringtable\n");
Alexandre Julliard's avatar
Alexandre Julliard committed
905 906 907 908
			continue;
		}
		name.type = name_ord;
		name.name.i_name = (stt->idbase >> 4) + 1;
909
		restag = put_res_header(WRC_RT_STRING, &name, stt->memopt, &stt->lvc);
Alexandre Julliard's avatar
Alexandre Julliard committed
910 911
		for(i = 0; i < stt->nentries; i++)
		{
912
			if(stt->entries[i].str && stt->entries[i].str->size)
Alexandre Julliard's avatar
Alexandre Julliard committed
913
			{
914
				put_string(stt->entries[i].str, FALSE, stt->lvc.language);
Alexandre Julliard's avatar
Alexandre Julliard committed
915 916 917
			}
			else
			{
918
				if (win32)
919
					put_word(0);
Alexandre Julliard's avatar
Alexandre Julliard committed
920
				else
921
					put_byte(0);
Alexandre Julliard's avatar
Alexandre Julliard committed
922 923
			}
		}
924
                set_res_size(restag);
Alexandre Julliard's avatar
Alexandre Julliard committed
925 926 927 928 929 930 931 932 933 934 935
	}
}

/*
 *****************************************************************************
 * Function	: user2res
 * Input	:
 *	name	- Name/ordinal of the resource
 *	usr	- The userresource descriptor
 *****************************************************************************
*/
936
static void user2res(name_id_t *name, user_t *usr)
Alexandre Julliard's avatar
Alexandre Julliard committed
937
{
938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960
	int tag = output_buffer_pos;

	if(win32)
	{
		put_dword(0);		/* We will overwrite these later */
		put_dword(0);
		put_name_id(usr->type, TRUE, usr->data->lvc.language);
		put_name_id(name, TRUE, usr->data->lvc.language); /* ResName */
		align_output(4);
		put_dword(0);		/* DataVersion */
		put_word(usr->memopt);		/* Memory options */
		put_lvc(&usr->data->lvc);	/* Language, version and characts */
		set_dword(tag + 0, output_buffer_pos - tag);
		set_dword(tag + 4, output_buffer_pos - tag);	/* Set HeaderSize */
	}
	else /* win16 */
	{
		put_name_id(usr->type, TRUE, NULL);
		put_name_id(name, TRUE, NULL); /* ResName */
		put_word(usr->memopt);		/* Memory options */
		tag = output_buffer_pos;
		put_dword(4);		/* ResSize overwritten later*/
	}
Alexandre Julliard's avatar
Alexandre Julliard committed
961

962 963
	put_data(usr->data->data, usr->data->size);
	set_res_size(tag);
Alexandre Julliard's avatar
Alexandre Julliard committed
964 965 966 967 968 969 970 971 972 973
}

/*
 *****************************************************************************
 * Function	: versionblock2res
 * Input	:
 *	blk	- The version block to be written
 * Remarks	: Self recursive
 *****************************************************************************
*/
974
static void versionblock2res(ver_block_t *blk, int level, const language_t *lang)
Alexandre Julliard's avatar
Alexandre Julliard committed
975 976 977 978 979 980 981 982
{
	ver_value_t *val;
	int blksizetag;
	int valblksizetag;
	int valvalsizetag;
	int tag;
	int i;

983 984 985
	blksizetag = output_buffer_pos;
	put_word(0);	/* Will be overwritten later */
	put_word(0);
Alexandre Julliard's avatar
Alexandre Julliard committed
986
	if(win32)
987 988 989
		put_word(0);	/* level ? */
	put_string(blk->name, TRUE, NULL);
	align_output(4);
Alexandre Julliard's avatar
Alexandre Julliard committed
990 991
	for(val = blk->values; val; val = val->next)
	{
992
		switch(val->type)
Alexandre Julliard's avatar
Alexandre Julliard committed
993
		{
994
		case val_str:
995 996 997 998
			valblksizetag = output_buffer_pos;
			put_word(0);	/* Will be overwritten later */
			valvalsizetag = output_buffer_pos;
			put_word(0);	/* Will be overwritten later */
Alexandre Julliard's avatar
Alexandre Julliard committed
999 1000
			if(win32)
			{
1001
				put_word(level);
Alexandre Julliard's avatar
Alexandre Julliard committed
1002
			}
1003 1004 1005 1006
			put_string(val->key, TRUE, NULL);
			align_output(4);
			tag = output_buffer_pos;
			put_string(val->value.str, TRUE, lang);
Alexandre Julliard's avatar
Alexandre Julliard committed
1007
			if(win32)
1008
				set_word(valvalsizetag, (output_buffer_pos - tag) >> 1);
Alexandre Julliard's avatar
Alexandre Julliard committed
1009
			else
1010 1011 1012
				set_word(valvalsizetag, output_buffer_pos - tag);
			set_word(valblksizetag, output_buffer_pos - valblksizetag);
			align_output(4);
1013 1014
                        break;
		case val_words:
1015 1016 1017 1018
			valblksizetag = output_buffer_pos;
			put_word(0);	/* Will be overwritten later */
			valvalsizetag = output_buffer_pos;
			put_word(0);	/* Will be overwritten later */
Alexandre Julliard's avatar
Alexandre Julliard committed
1019 1020
			if(win32)
			{
1021
				put_word(level);
Alexandre Julliard's avatar
Alexandre Julliard committed
1022
			}
1023 1024 1025
			put_string(val->key, TRUE, NULL);
			align_output(4);
			tag = output_buffer_pos;
Alexandre Julliard's avatar
Alexandre Julliard committed
1026 1027
			for(i = 0; i < val->value.words->nwords; i++)
			{
1028
				put_word(val->value.words->words[i]);
Alexandre Julliard's avatar
Alexandre Julliard committed
1029
			}
1030 1031 1032
			set_word(valvalsizetag, output_buffer_pos - tag);
			set_word(valblksizetag, output_buffer_pos - valblksizetag);
			align_output(4);
1033 1034
                        break;
		case val_block:
1035
			versionblock2res(val->value.block, level+1, lang);
1036
                        break;
Alexandre Julliard's avatar
Alexandre Julliard committed
1037 1038 1039 1040
		}
	}

	/* Set blocksize */
1041
	set_word(blksizetag, output_buffer_pos - blksizetag);
Alexandre Julliard's avatar
Alexandre Julliard committed
1042 1043 1044 1045 1046 1047 1048 1049 1050 1051
}

/*
 *****************************************************************************
 * Function	: versioninfo2res
 * Input	:
 *	name	- Name/ordinal of the resource
 *	ver	- The versioninfo descriptor
 *****************************************************************************
*/
1052
static void versioninfo2res(name_id_t *name, versioninfo_t *ver)
Alexandre Julliard's avatar
Alexandre Julliard committed
1053
{
1054 1055 1056
	static const char info[] = "VS_VERSION_INFO";
	unsigned int i;
	int restag, rootblocksizetag, valsizetag, tag;
Alexandre Julliard's avatar
Alexandre Julliard committed
1057 1058
	ver_block_t *blk;

1059 1060 1061 1062 1063
	restag = put_res_header(WRC_RT_VERSION, name, ver->memopt, &ver->lvc);
	rootblocksizetag = output_buffer_pos;
	put_word(0);	/* BlockSize filled in later */
	valsizetag = output_buffer_pos;
	put_word(0);	/* ValueSize filled in later*/
Alexandre Julliard's avatar
Alexandre Julliard committed
1064
	if(win32)
1065
	{
1066 1067 1068
		put_word(0);	/* Tree-level ? */
		for (i = 0; i < sizeof(info); i++) put_word(info[i]);
		align_output(4);
1069 1070 1071
	}
	else
	{
1072
		for (i = 0; i < sizeof(info); i++) put_byte(info[i]);
1073
	}
1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087
	tag = output_buffer_pos;
	put_dword(VS_FFI_SIGNATURE);
	put_dword(VS_FFI_STRUCVERSION);
	put_dword((ver->filever_maj1 << 16) + (ver->filever_maj2 & 0xffff));
	put_dword((ver->filever_min1 << 16) + (ver->filever_min2 & 0xffff));
	put_dword((ver->prodver_maj1 << 16) + (ver->prodver_maj2 & 0xffff));
	put_dword((ver->prodver_min1 << 16) + (ver->prodver_min2 & 0xffff));
	put_dword(ver->fileflagsmask);
	put_dword(ver->fileflags);
	put_dword(ver->fileos);
	put_dword(ver->filetype);
	put_dword(ver->filesubtype);
	put_dword(0);		/* FileDateMS */
	put_dword(0);		/* FileDateLS */
Alexandre Julliard's avatar
Alexandre Julliard committed
1088
	/* Set ValueSize */
1089
	set_word(valsizetag, output_buffer_pos - tag);
Alexandre Julliard's avatar
Alexandre Julliard committed
1090 1091
	/* Descend into the blocks */
	for(blk = ver->blocks; blk; blk = blk->next)
1092
		versionblock2res(blk, 0, win32 ? ver->lvc.language : NULL);
Alexandre Julliard's avatar
Alexandre Julliard committed
1093
	/* Set root block's size */
1094 1095
	set_word(rootblocksizetag, output_buffer_pos - rootblocksizetag);
	set_res_size(restag);
1096 1097 1098 1099 1100 1101 1102 1103 1104 1105
}

/*
 *****************************************************************************
 * Function	: toolbar2res
 * Input	:
 *	name	- Name/ordinal of the resource
 *	toolbar	- The toolbar descriptor
 *****************************************************************************
*/
1106
static void toolbar2res(name_id_t *name, toolbar_t *toolbar)
1107
{
1108
	toolbar_item_t *itm;
1109
	int restag;
1110

1111
	if (!win32) return;
1112

1113 1114 1115 1116 1117 1118 1119 1120
	restag = put_res_header(WRC_RT_TOOLBAR, name, toolbar->memopt, &toolbar->lvc);
	put_word(1);		/* Menuheader: Version */
	put_word(toolbar->button_width); /* (in pixels?) */
	put_word(toolbar->button_height); /* (in pixels?) */
	put_word(toolbar->nitems);
	align_output(4);
	for (itm = toolbar->items; itm; itm = itm->next) put_word(itm->id);
	set_res_size(restag);
1121 1122
}

1123 1124 1125 1126 1127 1128 1129 1130
/*
 *****************************************************************************
 * Function	: dlginit2res
 * Input	:
 *	name	- Name/ordinal of the resource
 *	rdt	- The dlginit descriptor
 *****************************************************************************
*/
1131
static void dlginit2res(name_id_t *name, dlginit_t *dit)
1132
{
1133
	int restag = put_res_header(WRC_RT_DLGINIT, name, dit->memopt, &dit->data->lvc);
1134

1135 1136
	put_data(dit->data->data, dit->data->size);
	set_res_size(restag);
Alexandre Julliard's avatar
Alexandre Julliard committed
1137
}
1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149

/*
 *****************************************************************************
 * Function	: write_resfile
 * Syntax	: void write_resfile(char *outname, resource_t *top)
 * Input	:
 *	outname	- Filename to write to
 *	top	- The resource-tree to convert
 *****************************************************************************
*/
void write_resfile(char *outname, resource_t *top)
{
1150 1151
        init_output_buffer();

1152 1153 1154
	if(win32)
	{
		/* Put an empty resource first to signal win32 format */
1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165
		put_dword(0);		/* ResSize */
		put_dword(0x00000020);	/* HeaderSize */
		put_word(0xffff);		/* ResType */
		put_word(0);
		put_word(0xffff);		/* ResName */
		put_word(0);
		put_dword(0);		/* DataVersion */
		put_word(0);		/* Memory options */
		put_word(0);		/* Language */
		put_dword(0);		/* Version */
		put_dword(0);		/* Characteristics */
1166 1167
	}

1168
	for ( ; top; top = top->next)
1169
	{
1170
		switch(top->type)
1171
		{
1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192
		case res_acc:     accelerator2res(top->name, top->res.acc); break;
		case res_bmp:     bitmap2res(top->name, top->res.bmp); break;
		case res_cur:     cursor2res(top->res.cur); break;
		case res_curg:    cursorgroup2res(top->name, top->res.curg); break;
		case res_dlg:     dialog2res(top->name, top->res.dlg); break;
		case res_fnt:     font2res(top->name, top->res.fnt); break;
		case res_fntdir:  fontdir2res(top->name, top->res.fnd); break;
		case res_ico:     icon2res(top->res.ico); break;
		case res_icog:    icongroup2res(top->name, top->res.icog); break;
		case res_men:     menu2res(top->name, top->res.men); break;
		case res_html:    html2res(top->name, top->res.html); break;
		case res_rdt:     rcdata2res(top->name, top->res.rdt); break;
		case res_stt:     stringtable2res(top->res.stt); break;
		case res_usr:     user2res(top->name, top->res.usr); break;
		case res_msg:     messagetable2res(top->name, top->res.msg); break;
		case res_ver:     versioninfo2res(top->name, top->res.ver); break;
		case res_toolbar: toolbar2res(top->name, top->res.tbt); break;
		case res_dlginit: dlginit2res(top->name, top->res.dlgi); break;
		case res_anicur:  anicur2res(top->name, top->res.ani); break;
		case res_aniico:  aniico2res(top->name, top->res.ani); break;
		default: assert(0);
1193
		}
1194 1195 1196
		if (win32) align_output( 4 );
	}

1197
	flush_output_buffer( outname );
1198
}