Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/tools/wrc/genres.c
4389 views
1
/*
2
* Generate .res format from a resource-tree
3
*
4
* Copyright 1998 Bertho A. Stultiens
5
*
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Lesser General Public
8
* License as published by the Free Software Foundation; either
9
* version 2.1 of the License, or (at your option) any later version.
10
*
11
* This library is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* Lesser General Public License for more details.
15
*
16
* You should have received a copy of the GNU Lesser General Public
17
* 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
* 05-May-2000 BS - Added code to support endian conversions. The
22
* extra functions also aid unaligned access, but
23
* this is not yet implemented.
24
* 25-May-1998 BS - Added simple unicode -> char conversion for resource
25
* names in .s and .h files.
26
*/
27
28
#include "config.h"
29
30
#include <stdio.h>
31
#include <stdlib.h>
32
#include <string.h>
33
#include <stdarg.h>
34
#include <assert.h>
35
#include <ctype.h>
36
37
#include "../tools.h"
38
#include "wrc.h"
39
#include "utils.h"
40
#include "windef.h"
41
#include "winbase.h"
42
#include "wingdi.h"
43
#include "winuser.h"
44
45
unsigned char *output_buffer = NULL;
46
size_t output_buffer_pos = 0;
47
size_t output_buffer_size = 0;
48
49
static void set_word(int ofs, unsigned int w)
50
{
51
output_buffer[ofs+0] = w;
52
output_buffer[ofs+1] = w >> 8;
53
}
54
55
static void set_dword(int ofs, unsigned int d)
56
{
57
output_buffer[ofs+0] = d;
58
output_buffer[ofs+1] = d >> 8;
59
output_buffer[ofs+2] = d >> 16;
60
output_buffer[ofs+3] = d >> 24;
61
}
62
63
static unsigned int get_dword(int ofs)
64
{
65
return (output_buffer[ofs+3] << 24)
66
| (output_buffer[ofs+2] << 16)
67
| (output_buffer[ofs+1] << 8)
68
| 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
76
/*
77
*****************************************************************************
78
* Function : string_to_upper
79
* Syntax : void string_to_upper(string_t *str)
80
*****************************************************************************
81
*/
82
static void string_to_upper(string_t *str)
83
{
84
int i;
85
86
switch (str->type)
87
{
88
case str_char:
89
for (i = 0; i < str->size; i++)
90
if (str->str.cstr[i] >= 'a' && str->str.cstr[i] <= 'z') str->str.cstr[i] -= 32;
91
break;
92
case str_unicode:
93
for (i = 0; i < str->size; i++)
94
if (str->str.wstr[i] >= 'a' && str->str.wstr[i] <= 'z') str->str.wstr[i] -= 32;
95
break;
96
}
97
}
98
99
static int parse_accel_string( const string_t *key, int flags )
100
{
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
if((flags & WRC_AF_VIRTKEY) &&
108
!((key->str.cstr[0] >= 'A' && key->str.cstr[0] <= 'Z') ||
109
(key->str.cstr[0] >= '0' && key->str.cstr[0] <= '9')))
110
{
111
print_location( &key->loc );
112
error("VIRTKEY code is not equal to ascii value\n");
113
}
114
115
if(key->str.cstr[0] == '^' && (flags & WRC_AF_CONTROL) != 0)
116
{
117
print_location( &key->loc );
118
error("Cannot use both '^' and CONTROL modifier\n");
119
}
120
else if(key->str.cstr[0] == '^')
121
{
122
if (key->str.cstr[1] >= 'a' && key->str.cstr[1] <= 'z')
123
keycode = key->str.cstr[1] - 'a' + 1;
124
else if (key->str.cstr[1] >= 'A' && key->str.cstr[1] <= 'Z')
125
keycode = key->str.cstr[1] - 'A' + 1;
126
else
127
{
128
print_location( &key->loc );
129
error("Control-code out of range\n");
130
}
131
}
132
else
133
keycode = key->str.cstr[0];
134
break;
135
136
case str_unicode:
137
if (key->str.wstr[0] == '#') return 0; /* ignore message contexts */
138
if((flags & WRC_AF_VIRTKEY) &&
139
!((key->str.wstr[0] >= 'A' && key->str.wstr[0] <= 'Z') ||
140
(key->str.wstr[0] >= '0' && key->str.wstr[0] <= '9')))
141
{
142
print_location( &key->loc );
143
error("VIRTKEY code is not equal to ascii value\n");
144
}
145
if(key->str.wstr[0] == '^' && (flags & WRC_AF_CONTROL) != 0)
146
{
147
print_location( &key->loc );
148
error("Cannot use both '^' and CONTROL modifier\n");
149
}
150
else if(key->str.wstr[0] == '^')
151
{
152
if (key->str.wstr[1] >= 'a' && key->str.wstr[1] <= 'z')
153
keycode = key->str.wstr[1] - 'a' + 1;
154
else if (key->str.wstr[1] >= 'A' && key->str.wstr[1] <= 'Z')
155
keycode = key->str.wstr[1] - 'A' + 1;
156
else
157
{
158
print_location( &key->loc );
159
error("Control-code out of range\n");
160
}
161
}
162
else
163
keycode = key->str.wstr[0];
164
break;
165
}
166
return keycode;
167
}
168
169
/*
170
*****************************************************************************
171
* Function : put_string
172
* Input :
173
* str - String to put
174
* isterm - The string is '\0' terminated (disregard the string's
175
* size member)
176
*****************************************************************************
177
*/
178
static void put_string(const string_t *str, int isterm, language_t lang)
179
{
180
int cnt;
181
182
if (win32)
183
{
184
185
if (str->type == str_char)
186
{
187
int codepage = get_language_codepage( lang );
188
string_t *newstr = convert_string_unicode( str, codepage );
189
190
if (check_valid_utf8( str, codepage ))
191
{
192
print_location( &str->loc );
193
warning( "string \"%s\" seems to be UTF-8 but codepage %u is in use, maybe use --utf8?\n",
194
str->str.cstr, codepage );
195
}
196
str = newstr;
197
}
198
if (!isterm) put_word(str->size);
199
for(cnt = 0; cnt < str->size; cnt++)
200
{
201
WCHAR c = str->str.wstr[cnt];
202
if (isterm && !c) break;
203
put_word(c);
204
}
205
if (isterm) put_word(0);
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
}
219
}
220
221
/*
222
*****************************************************************************
223
* Function : put_name_id
224
*****************************************************************************
225
*/
226
static void put_name_id(name_id_t *nid, int upcase, language_t lang)
227
{
228
switch (nid->type)
229
{
230
case name_ord:
231
if(win32)
232
put_word(0xffff);
233
else
234
put_byte(0xff);
235
put_word(nid->name.i_name);
236
break;
237
case name_str:
238
if(upcase)
239
string_to_upper(nid->name.s_name);
240
put_string(nid->name.s_name, TRUE, lang);
241
break;
242
}
243
}
244
245
/*
246
*****************************************************************************
247
* Function : put_lvc
248
*****************************************************************************
249
*/
250
static void put_lvc(lvc_t *lvc)
251
{
252
if(lvc)
253
{
254
put_word(lvc->language);
255
put_dword(lvc->version);
256
put_dword(lvc->characts);
257
}
258
else
259
{
260
put_word(0); /* Neutral */
261
put_dword(0);
262
put_dword(0);
263
}
264
}
265
266
/*
267
*****************************************************************************
268
* Function : put_res_header
269
* Input :
270
* type - Resource identifier
271
* name - Resource's name
272
* memopt - Resource's memory options to write
273
* lvc - Language, version and characteristics (win32 only)
274
* Output : An index to the resource size field. The resource size field
275
* contains the header size upon exit.
276
*****************************************************************************
277
*/
278
static int put_res_header(int type, name_id_t *name, unsigned int memopt, lvc_t *lvc)
279
{
280
int tag = output_buffer_pos;
281
if(win32)
282
{
283
put_dword(0); /* We will overwrite these later */
284
put_dword(0);
285
put_word(0xffff); /* ResType */
286
put_word(type);
287
put_name_id(name, TRUE, lvc->language); /* ResName */
288
align_output(4);
289
put_dword(0); /* DataVersion */
290
put_word(memopt); /* Memory options */
291
put_lvc(lvc); /* Language, version and characts */
292
set_dword(tag + 0, output_buffer_pos - tag);
293
set_dword(tag + 4, output_buffer_pos - tag); /* Set HeaderSize */
294
}
295
else /* win16 */
296
{
297
put_byte(0xff); /* ResType */
298
put_word(type);
299
put_name_id(name, TRUE, 0); /* ResName */
300
put_word(memopt); /* Memory options */
301
tag = output_buffer_pos;
302
put_dword(4); /* ResSize overwritten later*/
303
}
304
return tag;
305
}
306
307
/*
308
*****************************************************************************
309
* Function : accelerator2res
310
* Input :
311
* name - Name/ordinal of the resource
312
* acc - The accelerator descriptor
313
*****************************************************************************
314
*/
315
static void accelerator2res(name_id_t *name, accelerator_t *acc)
316
{
317
int restag;
318
event_t *ev;
319
320
restag = put_res_header(WRC_RT_ACCELERATOR, name, acc->memopt, &acc->lvc);
321
if(win32)
322
{
323
for (ev = acc->events; ev; ev = ev->next)
324
{
325
int key = ev->key;
326
if (ev->str) key = parse_accel_string( ev->str, ev->flags );
327
put_word(ev->flags | (ev->next ? 0 : 0x80));
328
put_word(key);
329
put_word(ev->id);
330
align_output(4);
331
}
332
}
333
else /* win16 */
334
{
335
for (ev = acc->events; ev; ev = ev->next)
336
{
337
int key = ev->key;
338
if (ev->str) key = parse_accel_string( ev->str, ev->flags );
339
put_byte(ev->flags | (ev->next ? 0 : 0x80));
340
put_word(key);
341
put_word(ev->id);
342
}
343
}
344
set_res_size(restag);
345
}
346
347
/*
348
*****************************************************************************
349
* Function : dialog2res
350
* Input :
351
* name - Name/ordinal of the resource
352
* dlg - The dialog descriptor
353
*****************************************************************************
354
*/
355
static void dialog2res(name_id_t *name, dialog_t *dlg)
356
{
357
int restag;
358
control_t *ctrl;
359
int nctrl;
360
361
restag = put_res_header(WRC_RT_DIALOG, name, dlg->memopt, &dlg->lvc);
362
for (ctrl = dlg->controls, nctrl = 0; ctrl; ctrl = ctrl->next) nctrl++;
363
if(win32)
364
{
365
if (dlg->is_ex)
366
{
367
/* FIXME: MS doc says that the first word must contain 0xffff
368
* and the second 0x0001 to signal a DLGTEMPLATEEX. Borland's
369
* compiler reverses the two words.
370
* I don't know which one to choose, but I write it as Mr. B
371
* writes it.
372
*/
373
put_word(1); /* Signature */
374
put_word(0xffff); /* DlgVer */
375
put_dword(dlg->gothelpid ? dlg->helpid : 0);
376
put_dword(dlg->gotexstyle ? dlg->exstyle->or_mask : 0);
377
put_dword(dlg->gotstyle ? dlg->style->or_mask : WS_POPUPWINDOW);
378
}
379
else
380
{
381
put_dword(dlg->style->or_mask);
382
put_dword(dlg->gotexstyle ? dlg->exstyle->or_mask : 0);
383
}
384
put_word(nctrl);
385
put_word(dlg->x);
386
put_word(dlg->y);
387
put_word(dlg->width);
388
put_word(dlg->height);
389
if(dlg->menu)
390
put_name_id(dlg->menu, FALSE, dlg->lvc.language);
391
else
392
put_word(0);
393
if(dlg->dlgclass)
394
put_name_id(dlg->dlgclass, FALSE, dlg->lvc.language);
395
else
396
put_word(0);
397
if(dlg->title)
398
put_string(dlg->title, TRUE, dlg->lvc.language);
399
else
400
put_word(0);
401
if(dlg->font)
402
{
403
put_word(dlg->font->size);
404
if (dlg->is_ex)
405
{
406
put_word(dlg->font->weight);
407
/* FIXME: ? TRUE should be sufficient to say that it's
408
* italic, but Borland's compiler says it's 0x0101.
409
* I just copy it here, and hope for the best.
410
*/
411
put_word(dlg->font->italic ? 0x0101 : 0);
412
}
413
put_string(dlg->font->name, TRUE, dlg->lvc.language);
414
}
415
else if (dlg->style->or_mask & DS_SETFONT) put_word( 0x7fff );
416
417
align_output(4);
418
for (ctrl = dlg->controls; ctrl; ctrl = ctrl->next)
419
{
420
if (dlg->is_ex)
421
{
422
put_dword(ctrl->gothelpid ? ctrl->helpid : 0);
423
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
else
428
{
429
/* FIXME: what is default control style? */
430
put_dword(ctrl->gotstyle ? ctrl->style->or_mask: WS_CHILD);
431
put_dword(ctrl->gotexstyle ? ctrl->exstyle->or_mask : 0);
432
}
433
put_word(ctrl->x);
434
put_word(ctrl->y);
435
put_word(ctrl->width);
436
put_word(ctrl->height);
437
if (dlg->is_ex)
438
put_dword(ctrl->id);
439
else
440
put_word(ctrl->id);
441
put_name_id(ctrl->ctlclass, FALSE, dlg->lvc.language);
442
if(ctrl->title)
443
put_name_id(ctrl->title, FALSE, dlg->lvc.language);
444
else
445
put_word(0);
446
if(ctrl->extra)
447
{
448
put_word(ctrl->extra->size);
449
put_data(ctrl->extra->data, ctrl->extra->size);
450
}
451
else
452
put_word(0);
453
454
if(ctrl->next)
455
align_output(4);
456
}
457
}
458
else /* win16 */
459
{
460
restag = put_res_header(WRC_RT_DIALOG, name, dlg->memopt, NULL);
461
462
put_dword(dlg->gotstyle ? dlg->style->or_mask : WS_POPUPWINDOW);
463
put_byte(nctrl);
464
put_word(dlg->x);
465
put_word(dlg->y);
466
put_word(dlg->width);
467
put_word(dlg->height);
468
if(dlg->menu)
469
put_name_id(dlg->menu, TRUE, 0);
470
else
471
put_byte(0);
472
if(dlg->dlgclass)
473
put_name_id(dlg->dlgclass, TRUE, 0);
474
else
475
put_byte(0);
476
if(dlg->title)
477
put_string(dlg->title, TRUE, 0);
478
else
479
put_byte(0);
480
if(dlg->font)
481
{
482
put_word(dlg->font->size);
483
put_string(dlg->font->name, TRUE, 0);
484
}
485
486
for (ctrl = dlg->controls; ctrl; ctrl = ctrl->next)
487
{
488
put_word(ctrl->x);
489
put_word(ctrl->y);
490
put_word(ctrl->width);
491
put_word(ctrl->height);
492
put_word(ctrl->id);
493
put_dword(ctrl->gotstyle ? ctrl->style->or_mask: WS_CHILD);
494
if(ctrl->ctlclass->type == name_ord
495
&& ctrl->ctlclass->name.i_name >= 0x80
496
&& 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, 0);
500
else
501
error("Unknown control-class %04x\n", ctrl->ctlclass->name.i_name);
502
if(ctrl->title)
503
put_name_id(ctrl->title, FALSE, 0);
504
else
505
put_byte(0);
506
507
/* FIXME: What is this extra byte doing here? */
508
put_byte(0);
509
}
510
}
511
set_res_size(restag);
512
}
513
514
/*
515
*****************************************************************************
516
* Function : menuitem2res
517
* Remarks : Self recursive
518
*****************************************************************************
519
*/
520
static void menuitem2res(menu_item_t *menitem, language_t lang)
521
{
522
menu_item_t *itm = menitem;
523
524
while(itm)
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
else
532
{
533
if (win32) put_word(0);
534
else put_byte(0);
535
}
536
if(itm->popup)
537
menuitem2res(itm->popup, lang);
538
itm = itm->next;
539
}
540
}
541
542
/*
543
*****************************************************************************
544
* Function : menuexitem2res
545
* Remarks : Self recursive
546
*****************************************************************************
547
*/
548
static void menuexitem2res(menu_item_t *menitem, language_t lang)
549
{
550
menu_item_t *itm = menitem;
551
assert(win32 != 0);
552
while(itm)
553
{
554
put_dword(itm->gottype ? itm->type : 0);
555
put_dword(itm->gotstate ? itm->state : 0);
556
put_dword(itm->gotid ? itm->id : 0);
557
put_word((itm->popup ? 0x01 : 0) | (!itm->next ? MF_END : 0));
558
if(itm->name)
559
put_string(itm->name, TRUE, lang);
560
else
561
put_word(0);
562
align_output(4);
563
if(itm->popup)
564
{
565
put_dword(itm->gothelpid ? itm->helpid : 0);
566
menuexitem2res(itm->popup, lang);
567
}
568
itm = itm->next;
569
}
570
571
}
572
573
/*
574
*****************************************************************************
575
* Function : menu2res
576
* Input :
577
* name - Name/ordinal of the resource
578
* menex - The menuex descriptor
579
*****************************************************************************
580
*/
581
static void menu2res(name_id_t *name, menu_t *men)
582
{
583
int restag;
584
assert(name != NULL);
585
assert(men != NULL);
586
587
restag = put_res_header(WRC_RT_MENU, name, men->memopt, &men->lvc);
588
if(win32)
589
{
590
if (men->is_ex)
591
{
592
put_word(1); /* Menuheader: Version */
593
put_word(4); /* Offset */
594
put_dword(0); /* HelpId */
595
align_output(4);
596
menuexitem2res(men->items, men->lvc.language);
597
}
598
else
599
{
600
put_dword(0); /* Menuheader: Version and HeaderSize */
601
menuitem2res(men->items, men->lvc.language);
602
}
603
}
604
else /* win16 */
605
{
606
put_dword(0); /* Menuheader: Version and HeaderSize */
607
menuitem2res(men->items, 0);
608
}
609
set_res_size(restag);
610
}
611
612
/*
613
*****************************************************************************
614
* Function : cursorgroup2res
615
* Input :
616
* name - Name/ordinal of the resource
617
* curg - The cursor descriptor
618
*****************************************************************************
619
*/
620
static void cursorgroup2res(name_id_t *name, cursor_group_t *curg)
621
{
622
int restag;
623
cursor_t *cur;
624
625
restag = put_res_header(WRC_RT_GROUP_CURSOR, name, curg->memopt, &curg->lvc);
626
627
put_word(0); /* Reserved */
628
/* FIXME: The ResType in the NEWHEADER structure should
629
* contain 14 according to the MS win32 doc. This is
630
* not the case with the BRC compiler and I really doubt
631
* the latter. Putting one here is compliant to win16 spec,
632
* but who knows the true value?
633
*/
634
put_word(2); /* ResType */
635
put_word(curg->ncursor);
636
#if 0
637
for(cur = curg->cursorlist; cur; cur = cur->next)
638
#else
639
cur = curg->cursorlist;
640
while(cur->next)
641
cur = cur->next;
642
for(; cur; cur = cur->prev)
643
#endif
644
{
645
put_word(cur->width);
646
/* FIXME: The height of a cursor is half the size of
647
* the bitmap's height. BRC puts the height from the
648
* BITMAPINFOHEADER here instead of the cursorfile's
649
* height. MS doesn't seem to care...
650
*/
651
put_word(cur->height);
652
/* FIXME: The next two are reversed in BRC and I don't
653
* know why. Probably a bug. But, we can safely ignore
654
* it because win16 does not support color cursors.
655
* A warning should have been generated by the parser.
656
*/
657
put_word(cur->planes);
658
put_word(cur->bits);
659
/* FIXME: The +4 is the hotspot in the cursor resource.
660
* However, I could not find this in the documentation.
661
* The hotspot bytes must either be included or MS
662
* doesn't care.
663
*/
664
put_dword(cur->data->size +4);
665
put_word(cur->id);
666
}
667
668
set_res_size(restag);
669
}
670
671
/*
672
*****************************************************************************
673
* Function : cursor2res
674
* Input :
675
* cur - The cursor descriptor
676
*****************************************************************************
677
*/
678
static void cursor2res(cursor_t *cur)
679
{
680
int restag;
681
name_id_t name;
682
683
name.type = name_ord;
684
name.name.i_name = cur->id;
685
restag = put_res_header(WRC_RT_CURSOR, &name, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, &cur->lvc);
686
put_word(cur->xhot);
687
put_word(cur->yhot);
688
put_data(cur->data->data, cur->data->size);
689
690
set_res_size(restag);
691
}
692
693
/*
694
*****************************************************************************
695
* Function : icongroup2res
696
* Input :
697
* name - Name/ordinal of the resource
698
* icog - The icon group descriptor
699
*****************************************************************************
700
*/
701
static void icongroup2res(name_id_t *name, icon_group_t *icog)
702
{
703
int restag;
704
icon_t *ico;
705
706
restag = put_res_header(WRC_RT_GROUP_ICON, name, icog->memopt, &icog->lvc);
707
708
put_word(0); /* Reserved */
709
/* FIXME: The ResType in the NEWHEADER structure should
710
* contain 14 according to the MS win32 doc. This is
711
* not the case with the BRC compiler and I really doubt
712
* the latter. Putting one here is compliant to win16 spec,
713
* but who knows the true value?
714
*/
715
put_word(1); /* ResType */
716
put_word(icog->nicon);
717
for(ico = icog->iconlist; ico; ico = ico->next)
718
{
719
put_byte(ico->width);
720
put_byte(ico->height);
721
put_byte(ico->nclr);
722
put_byte(0); /* Reserved */
723
put_word(ico->planes);
724
put_word(ico->bits);
725
put_dword(ico->data->size);
726
put_word(ico->id);
727
}
728
729
set_res_size(restag);
730
}
731
732
/*
733
*****************************************************************************
734
* Function : icon2res
735
* Input :
736
* ico - The icon descriptor
737
*****************************************************************************
738
*/
739
static void icon2res(icon_t *ico)
740
{
741
int restag;
742
name_id_t name;
743
744
name.type = name_ord;
745
name.name.i_name = ico->id;
746
restag = put_res_header(WRC_RT_ICON, &name, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, &ico->lvc);
747
put_data(ico->data->data, ico->data->size);
748
set_res_size(restag);
749
}
750
751
/*
752
*****************************************************************************
753
* Function : anicurico2res
754
* Input :
755
* name - Name/ordinal of the resource
756
* ani - The animated object descriptor
757
* Remarks : There are rumors that win311 could handle animated stuff.
758
* That is why they are generated for both win16 and win32
759
* compile.
760
*****************************************************************************
761
*/
762
static void anicur2res(name_id_t *name, ani_curico_t *ani)
763
{
764
int restag = put_res_header(WRC_RT_ANICURSOR, name, ani->memopt, NULL);
765
766
put_data(ani->data->data, ani->data->size);
767
set_res_size(restag);
768
}
769
770
static void aniico2res(name_id_t *name, ani_curico_t *ani)
771
{
772
int restag = put_res_header(WRC_RT_ANIICON, name, ani->memopt, NULL);
773
774
put_data(ani->data->data, ani->data->size);
775
set_res_size(restag);
776
}
777
778
/*
779
*****************************************************************************
780
* Function : bitmap2res
781
* Input :
782
* name - Name/ordinal of the resource
783
* bmp - The bitmap descriptor
784
*****************************************************************************
785
*/
786
static void bitmap2res(name_id_t *name, bitmap_t *bmp)
787
{
788
int restag = put_res_header(WRC_RT_BITMAP, name, bmp->memopt, &bmp->data->lvc);
789
790
if(bmp->data->data[0] == 'B'
791
&& bmp->data->data[1] == 'M'
792
&& ((BITMAPFILEHEADER *)bmp->data->data)->bfSize == bmp->data->size
793
&& bmp->data->size >= sizeof(BITMAPFILEHEADER))
794
{
795
/* The File header is still attached, don't write it */
796
put_data((BITMAPFILEHEADER *)bmp->data->data + 1, bmp->data->size - sizeof(BITMAPFILEHEADER));
797
}
798
else
799
{
800
put_data(bmp->data->data, bmp->data->size);
801
}
802
set_res_size(restag);
803
}
804
805
/*
806
*****************************************************************************
807
* Function : font2res
808
* Input :
809
* name - Name/ordinal of the resource
810
* fnt - The font descriptor
811
* Remarks : The data has been prepared just after parsing.
812
*****************************************************************************
813
*/
814
static void font2res(name_id_t *name, font_t *fnt)
815
{
816
int restag = put_res_header(WRC_RT_FONT, name, fnt->memopt, &fnt->data->lvc);
817
818
put_data(fnt->data->data, fnt->data->size);
819
set_res_size(restag);
820
}
821
822
/*
823
*****************************************************************************
824
* Function : fontdir2res
825
* Input :
826
* name - Name/ordinal of the resource
827
* fntdir - The fontdir descriptor
828
* Remarks : The data has been prepared just after parsing.
829
*****************************************************************************
830
*/
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
put_data(fnd->data->data, fnd->data->size);
836
set_res_size(restag);
837
}
838
839
/*
840
*****************************************************************************
841
* Function : html2res
842
* Input :
843
* name - Name/ordinal of the resource
844
* rdt - The html descriptor
845
*****************************************************************************
846
*/
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
put_data(html->data->data, html->data->size);
852
set_res_size(restag);
853
}
854
855
/*
856
*****************************************************************************
857
* Function : rcdata2res
858
* Input :
859
* name - Name/ordinal of the resource
860
* rdt - The rcdata descriptor
861
*****************************************************************************
862
*/
863
static void rcdata2res(name_id_t *name, rcdata_t *rdt)
864
{
865
int restag = put_res_header(WRC_RT_RCDATA, name, rdt->memopt, &rdt->data->lvc);
866
867
put_data(rdt->data->data, rdt->data->size);
868
set_res_size(restag);
869
}
870
871
/*
872
*****************************************************************************
873
* Function : messagetable2res
874
* Input :
875
* name - Name/ordinal of the resource
876
* msg - The messagetable descriptor
877
*****************************************************************************
878
*/
879
static void messagetable2res(name_id_t *name, messagetable_t *msg)
880
{
881
int restag = put_res_header(WRC_RT_MESSAGETABLE, name, msg->memopt, &msg->data->lvc);
882
883
put_data(msg->data->data, msg->data->size);
884
set_res_size(restag);
885
}
886
887
/*
888
*****************************************************************************
889
* Function : stringtable2res
890
* Input :
891
* stt - The stringtable descriptor
892
*****************************************************************************
893
*/
894
static void stringtable2res(stringtable_t *stt)
895
{
896
name_id_t name;
897
int i;
898
int restag;
899
900
for(; stt; stt = stt->next)
901
{
902
if(!stt->nentries)
903
{
904
warning("Empty internal stringtable\n");
905
continue;
906
}
907
name.type = name_ord;
908
name.name.i_name = (stt->idbase >> 4) + 1;
909
restag = put_res_header(WRC_RT_STRING, &name, stt->memopt, &stt->lvc);
910
for(i = 0; i < stt->nentries; i++)
911
{
912
if(stt->entries[i].str && stt->entries[i].str->size)
913
{
914
put_string(stt->entries[i].str, FALSE, stt->lvc.language);
915
}
916
else
917
{
918
if (win32)
919
put_word(0);
920
else
921
put_byte(0);
922
}
923
}
924
set_res_size(restag);
925
}
926
}
927
928
/*
929
*****************************************************************************
930
* Function : user2res
931
* Input :
932
* name - Name/ordinal of the resource
933
* usr - The userresource descriptor
934
*****************************************************************************
935
*/
936
static void user2res(name_id_t *name, user_t *usr)
937
{
938
int tag = output_buffer_pos;
939
940
if(win32)
941
{
942
put_dword(0); /* We will overwrite these later */
943
put_dword(0);
944
put_name_id(usr->type, TRUE, usr->data->lvc.language);
945
put_name_id(name, TRUE, usr->data->lvc.language); /* ResName */
946
align_output(4);
947
put_dword(0); /* DataVersion */
948
put_word(usr->memopt); /* Memory options */
949
put_lvc(&usr->data->lvc); /* Language, version and characts */
950
set_dword(tag + 0, output_buffer_pos - tag);
951
set_dword(tag + 4, output_buffer_pos - tag); /* Set HeaderSize */
952
}
953
else /* win16 */
954
{
955
put_name_id(usr->type, TRUE, 0);
956
put_name_id(name, TRUE, 0); /* ResName */
957
put_word(usr->memopt); /* Memory options */
958
tag = output_buffer_pos;
959
put_dword(4); /* ResSize overwritten later*/
960
}
961
962
put_data(usr->data->data, usr->data->size);
963
set_res_size(tag);
964
}
965
966
/*
967
*****************************************************************************
968
* Function : versionblock2res
969
* Input :
970
* blk - The version block to be written
971
* Remarks : Self recursive
972
*****************************************************************************
973
*/
974
static void versionblock2res(ver_block_t *blk, int level, language_t lang)
975
{
976
ver_value_t *val;
977
int blksizetag;
978
int valblksizetag;
979
int valvalsizetag;
980
int tag;
981
int i;
982
983
blksizetag = output_buffer_pos;
984
put_word(0); /* Will be overwritten later */
985
put_word(0);
986
if(win32)
987
put_word(0); /* level ? */
988
put_string(blk->name, TRUE, 0);
989
align_output(4);
990
for(val = blk->values; val; val = val->next)
991
{
992
switch(val->type)
993
{
994
case val_str:
995
valblksizetag = output_buffer_pos;
996
put_word(0); /* Will be overwritten later */
997
valvalsizetag = output_buffer_pos;
998
put_word(0); /* Will be overwritten later */
999
if(win32)
1000
{
1001
put_word(level);
1002
}
1003
put_string(val->key, TRUE, 0);
1004
align_output(4);
1005
tag = output_buffer_pos;
1006
put_string(val->value.str, TRUE, lang);
1007
if(win32)
1008
set_word(valvalsizetag, (output_buffer_pos - tag) >> 1);
1009
else
1010
set_word(valvalsizetag, output_buffer_pos - tag);
1011
set_word(valblksizetag, output_buffer_pos - valblksizetag);
1012
align_output(4);
1013
break;
1014
case val_words:
1015
valblksizetag = output_buffer_pos;
1016
put_word(0); /* Will be overwritten later */
1017
valvalsizetag = output_buffer_pos;
1018
put_word(0); /* Will be overwritten later */
1019
if(win32)
1020
{
1021
put_word(level);
1022
}
1023
put_string(val->key, TRUE, 0);
1024
align_output(4);
1025
tag = output_buffer_pos;
1026
for(i = 0; i < val->value.words->nwords; i++)
1027
{
1028
put_word(val->value.words->words[i]);
1029
}
1030
set_word(valvalsizetag, output_buffer_pos - tag);
1031
set_word(valblksizetag, output_buffer_pos - valblksizetag);
1032
align_output(4);
1033
break;
1034
case val_block:
1035
versionblock2res(val->value.block, level+1, lang);
1036
break;
1037
}
1038
}
1039
1040
/* Set blocksize */
1041
set_word(blksizetag, output_buffer_pos - blksizetag);
1042
}
1043
1044
/*
1045
*****************************************************************************
1046
* Function : versioninfo2res
1047
* Input :
1048
* name - Name/ordinal of the resource
1049
* ver - The versioninfo descriptor
1050
*****************************************************************************
1051
*/
1052
static void versioninfo2res(name_id_t *name, versioninfo_t *ver)
1053
{
1054
static const char info[] = "VS_VERSION_INFO";
1055
unsigned int i;
1056
int restag, rootblocksizetag, valsizetag, tag;
1057
ver_block_t *blk;
1058
1059
restag = put_res_header(WRC_RT_VERSION, name, ver->memopt, &ver->lvc);
1060
rootblocksizetag = output_buffer_pos;
1061
put_word(0); /* BlockSize filled in later */
1062
valsizetag = output_buffer_pos;
1063
put_word(0); /* ValueSize filled in later*/
1064
if(win32)
1065
{
1066
put_word(0); /* Tree-level ? */
1067
for (i = 0; i < sizeof(info); i++) put_word(info[i]);
1068
align_output(4);
1069
}
1070
else
1071
{
1072
for (i = 0; i < sizeof(info); i++) put_byte(info[i]);
1073
}
1074
tag = output_buffer_pos;
1075
put_dword(VS_FFI_SIGNATURE);
1076
put_dword(VS_FFI_STRUCVERSION);
1077
put_dword((ver->filever_maj1 << 16) + (ver->filever_maj2 & 0xffff));
1078
put_dword((ver->filever_min1 << 16) + (ver->filever_min2 & 0xffff));
1079
put_dword((ver->prodver_maj1 << 16) + (ver->prodver_maj2 & 0xffff));
1080
put_dword((ver->prodver_min1 << 16) + (ver->prodver_min2 & 0xffff));
1081
put_dword(ver->fileflagsmask);
1082
put_dword(ver->fileflags);
1083
put_dword(ver->fileos);
1084
put_dword(ver->filetype);
1085
put_dword(ver->filesubtype);
1086
put_dword(0); /* FileDateMS */
1087
put_dword(0); /* FileDateLS */
1088
/* Set ValueSize */
1089
set_word(valsizetag, output_buffer_pos - tag);
1090
/* Descend into the blocks */
1091
for(blk = ver->blocks; blk; blk = blk->next)
1092
versionblock2res(blk, 0, win32 ? ver->lvc.language : 0);
1093
/* Set root block's size */
1094
set_word(rootblocksizetag, output_buffer_pos - rootblocksizetag);
1095
set_res_size(restag);
1096
}
1097
1098
/*
1099
*****************************************************************************
1100
* Function : toolbar2res
1101
* Input :
1102
* name - Name/ordinal of the resource
1103
* toolbar - The toolbar descriptor
1104
*****************************************************************************
1105
*/
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
restag = put_res_header(WRC_RT_TOOLBAR, name, toolbar->memopt, &toolbar->lvc);
1114
put_word(1); /* Menuheader: Version */
1115
put_word(toolbar->button_width); /* (in pixels?) */
1116
put_word(toolbar->button_height); /* (in pixels?) */
1117
put_word(toolbar->nitems);
1118
align_output(4);
1119
for (itm = toolbar->items; itm; itm = itm->next) put_word(itm->id);
1120
set_res_size(restag);
1121
}
1122
1123
/*
1124
*****************************************************************************
1125
* Function : dlginit2res
1126
* Input :
1127
* name - Name/ordinal of the resource
1128
* rdt - The dlginit descriptor
1129
*****************************************************************************
1130
*/
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
put_data(dit->data->data, dit->data->size);
1136
set_res_size(restag);
1137
}
1138
1139
/*
1140
*****************************************************************************
1141
* Function : write_resfile
1142
* Syntax : void write_resfile(char *outname, resource_t *top)
1143
* Input :
1144
* outname - Filename to write to
1145
* top - The resource-tree to convert
1146
*****************************************************************************
1147
*/
1148
void write_resfile(char *outname, resource_t *top)
1149
{
1150
init_output_buffer();
1151
1152
if(win32)
1153
{
1154
/* Put an empty resource first to signal win32 format */
1155
put_dword(0); /* ResSize */
1156
put_dword(0x00000020); /* HeaderSize */
1157
put_word(0xffff); /* ResType */
1158
put_word(0);
1159
put_word(0xffff); /* ResName */
1160
put_word(0);
1161
put_dword(0); /* DataVersion */
1162
put_word(0); /* Memory options */
1163
put_word(0); /* Language */
1164
put_dword(0); /* Version */
1165
put_dword(0); /* Characteristics */
1166
}
1167
1168
for ( ; top; top = top->next)
1169
{
1170
switch(top->type)
1171
{
1172
case res_acc: accelerator2res(top->name, top->res.acc); break;
1173
case res_bmp: bitmap2res(top->name, top->res.bmp); break;
1174
case res_cur: cursor2res(top->res.cur); break;
1175
case res_curg: cursorgroup2res(top->name, top->res.curg); break;
1176
case res_dlg: dialog2res(top->name, top->res.dlg); break;
1177
case res_fnt: font2res(top->name, top->res.fnt); break;
1178
case res_fntdir: fontdir2res(top->name, top->res.fnd); break;
1179
case res_ico: icon2res(top->res.ico); break;
1180
case res_icog: icongroup2res(top->name, top->res.icog); break;
1181
case res_men: menu2res(top->name, top->res.men); break;
1182
case res_html: html2res(top->name, top->res.html); break;
1183
case res_rdt: rcdata2res(top->name, top->res.rdt); break;
1184
case res_stt: stringtable2res(top->res.stt); break;
1185
case res_usr: user2res(top->name, top->res.usr); break;
1186
case res_msg: messagetable2res(top->name, top->res.msg); break;
1187
case res_ver: versioninfo2res(top->name, top->res.ver); break;
1188
case res_toolbar: toolbar2res(top->name, top->res.tbt); break;
1189
case res_dlginit: dlginit2res(top->name, top->res.dlgi); break;
1190
case res_anicur: anicur2res(top->name, top->res.ani); break;
1191
case res_aniico: aniico2res(top->name, top->res.ani); break;
1192
default: assert(0);
1193
}
1194
if (win32) align_output( 4 );
1195
}
1196
1197
flush_output_buffer( outname );
1198
}
1199
1200