2 * Generate .res format from a resource-tree
4 * Copyright 1998 Bertho A. Stultiens
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.
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.
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
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.
45 unsigned char *output_buffer
= NULL
;
46 size_t output_buffer_pos
= 0;
47 size_t output_buffer_size
= 0;
49 static void set_word(int ofs
, unsigned int w
)
51 output_buffer
[ofs
+0] = w
;
52 output_buffer
[ofs
+1] = w
>> 8;
55 static void set_dword(int ofs
, unsigned int d
)
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;
63 static unsigned int get_dword(int ofs
)
65 return (output_buffer
[ofs
+3] << 24)
66 | (output_buffer
[ofs
+2] << 16)
67 | (output_buffer
[ofs
+1] << 8)
68 | output_buffer
[ofs
+0];
71 static void set_res_size(int tag
)
73 set_dword( tag
, output_buffer_pos
- tag
- get_dword(tag
) );
77 *****************************************************************************
78 * Function : string_to_upper
79 * Syntax : void string_to_upper(string_t *str)
80 *****************************************************************************
82 static void string_to_upper(string_t
*str
)
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;
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;
99 static int parse_accel_string( const string_t
*key
, int flags
)
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')))
111 print_location( &key
->loc
);
112 error("VIRTKEY code is not equal to ascii value\n");
115 if(key
->str
.cstr
[0] == '^' && (flags
& WRC_AF_CONTROL
) != 0)
117 print_location( &key
->loc
);
118 error("Cannot use both '^' and CONTROL modifier\n");
120 else if(key
->str
.cstr
[0] == '^')
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;
128 print_location( &key
->loc
);
129 error("Control-code out of range\n");
133 keycode
= key
->str
.cstr
[0];
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')))
142 print_location( &key
->loc
);
143 error("VIRTKEY code is not equal to ascii value\n");
145 if(key
->str
.wstr
[0] == '^' && (flags
& WRC_AF_CONTROL
) != 0)
147 print_location( &key
->loc
);
148 error("Cannot use both '^' and CONTROL modifier\n");
150 else if(key
->str
.wstr
[0] == '^')
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;
158 print_location( &key
->loc
);
159 error("Control-code out of range\n");
163 keycode
= key
->str
.wstr
[0];
170 *****************************************************************************
171 * Function : put_string
173 * str - String to put
174 * isterm - The string is '\0' terminated (disregard the string's
176 *****************************************************************************
178 static void put_string(const string_t
*str
, int isterm
, language_t lang
)
185 if (str
->type
== str_char
)
187 int codepage
= get_language_codepage( lang
);
188 string_t
*newstr
= convert_string_unicode( str
, codepage
);
190 if (check_valid_utf8( str
, codepage
))
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
);
198 if (!isterm
) put_word(str
->size
);
199 for(cnt
= 0; cnt
< str
->size
; cnt
++)
201 WCHAR c
= str
->str
.wstr
[cnt
];
202 if (isterm
&& !c
) break;
205 if (isterm
) put_word(0);
209 assert( str
->type
== str_char
);
210 if (!isterm
) put_byte(str
->size
);
211 for(cnt
= 0; cnt
< str
->size
; cnt
++)
213 char c
= str
->str
.cstr
[cnt
];
214 if (isterm
&& !c
) break;
217 if (isterm
) put_byte(0);
222 *****************************************************************************
223 * Function : put_name_id
224 *****************************************************************************
226 static void put_name_id(name_id_t
*nid
, int upcase
, language_t lang
)
235 put_word(nid
->name
.i_name
);
239 string_to_upper(nid
->name
.s_name
);
240 put_string(nid
->name
.s_name
, TRUE
, lang
);
246 *****************************************************************************
248 *****************************************************************************
250 static void put_lvc(lvc_t
*lvc
)
254 put_word(lvc
->language
);
255 put_dword(lvc
->version
);
256 put_dword(lvc
->characts
);
260 put_word(0); /* Neutral */
267 *****************************************************************************
268 * Function : put_res_header
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 *****************************************************************************
278 static int put_res_header(int type
, name_id_t
*name
, unsigned int memopt
, lvc_t
*lvc
)
280 int tag
= output_buffer_pos
;
283 put_dword(0); /* We will overwrite these later */
285 put_word(0xffff); /* ResType */
287 put_name_id(name
, TRUE
, lvc
->language
); /* ResName */
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 */
297 put_byte(0xff); /* ResType */
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*/
308 *****************************************************************************
309 * Function : accelerator2res
311 * name - Name/ordinal of the resource
312 * acc - The accelerator descriptor
313 *****************************************************************************
315 static void accelerator2res(name_id_t
*name
, accelerator_t
*acc
)
320 restag
= put_res_header(WRC_RT_ACCELERATOR
, name
, acc
->memopt
, &acc
->lvc
);
323 for (ev
= acc
->events
; ev
; ev
= ev
->next
)
326 if (ev
->str
) key
= parse_accel_string( ev
->str
, ev
->flags
);
327 put_word(ev
->flags
| (ev
->next
? 0 : 0x80));
335 for (ev
= acc
->events
; ev
; ev
= ev
->next
)
338 if (ev
->str
) key
= parse_accel_string( ev
->str
, ev
->flags
);
339 put_byte(ev
->flags
| (ev
->next
? 0 : 0x80));
344 set_res_size(restag
);
348 *****************************************************************************
349 * Function : dialog2res
351 * name - Name/ordinal of the resource
352 * dlg - The dialog descriptor
353 *****************************************************************************
355 static void dialog2res(name_id_t
*name
, dialog_t
*dlg
)
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
++;
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
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
);
381 put_dword(dlg
->style
->or_mask
);
382 put_dword(dlg
->gotexstyle
? dlg
->exstyle
->or_mask
: 0);
387 put_word(dlg
->width
);
388 put_word(dlg
->height
);
390 put_name_id(dlg
->menu
, FALSE
, dlg
->lvc
.language
);
394 put_name_id(dlg
->dlgclass
, FALSE
, dlg
->lvc
.language
);
398 put_string(dlg
->title
, TRUE
, dlg
->lvc
.language
);
403 put_word(dlg
->font
->size
);
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.
411 put_word(dlg
->font
->italic
? 0x0101 : 0);
413 put_string(dlg
->font
->name
, TRUE
, dlg
->lvc
.language
);
415 else if (dlg
->style
->or_mask
& DS_SETFONT
) put_word( 0x7fff );
418 for (ctrl
= dlg
->controls
; ctrl
; ctrl
= ctrl
->next
)
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
);
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);
435 put_word(ctrl
->width
);
436 put_word(ctrl
->height
);
441 put_name_id(ctrl
->ctlclass
, FALSE
, dlg
->lvc
.language
);
443 put_name_id(ctrl
->title
, FALSE
, dlg
->lvc
.language
);
448 put_word(ctrl
->extra
->size
);
449 put_data(ctrl
->extra
->data
, ctrl
->extra
->size
);
460 restag
= put_res_header(WRC_RT_DIALOG
, name
, dlg
->memopt
, NULL
);
462 put_dword(dlg
->gotstyle
? dlg
->style
->or_mask
: WS_POPUPWINDOW
);
466 put_word(dlg
->width
);
467 put_word(dlg
->height
);
469 put_name_id(dlg
->menu
, TRUE
, 0);
473 put_name_id(dlg
->dlgclass
, TRUE
, 0);
477 put_string(dlg
->title
, TRUE
, 0);
482 put_word(dlg
->font
->size
);
483 put_string(dlg
->font
->name
, TRUE
, 0);
486 for (ctrl
= dlg
->controls
; ctrl
; ctrl
= ctrl
->next
)
490 put_word(ctrl
->width
);
491 put_word(ctrl
->height
);
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);
501 error("Unknown control-class %04x\n", ctrl
->ctlclass
->name
.i_name
);
503 put_name_id(ctrl
->title
, FALSE
, 0);
507 /* FIXME: What is this extra byte doing here? */
511 set_res_size(restag
);
515 *****************************************************************************
516 * Function : menuitem2res
517 * Remarks : Self recursive
518 *****************************************************************************
520 static void menuitem2res(menu_item_t
*menitem
, language_t lang
)
522 menu_item_t
*itm
= menitem
;
526 put_word(itm
->state
| (itm
->popup
? MF_POPUP
: 0) | (!itm
->next
? MF_END
: 0));
530 put_string(itm
->name
, TRUE
, lang
);
533 if (win32
) put_word(0);
537 menuitem2res(itm
->popup
, lang
);
543 *****************************************************************************
544 * Function : menuexitem2res
545 * Remarks : Self recursive
546 *****************************************************************************
548 static void menuexitem2res(menu_item_t
*menitem
, language_t lang
)
550 menu_item_t
*itm
= menitem
;
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));
559 put_string(itm
->name
, TRUE
, lang
);
565 put_dword(itm
->gothelpid
? itm
->helpid
: 0);
566 menuexitem2res(itm
->popup
, lang
);
574 *****************************************************************************
575 * Function : menu2res
577 * name - Name/ordinal of the resource
578 * menex - The menuex descriptor
579 *****************************************************************************
581 static void menu2res(name_id_t
*name
, menu_t
*men
)
584 assert(name
!= NULL
);
587 restag
= put_res_header(WRC_RT_MENU
, name
, men
->memopt
, &men
->lvc
);
592 put_word(1); /* Menuheader: Version */
593 put_word(4); /* Offset */
594 put_dword(0); /* HelpId */
596 menuexitem2res(men
->items
, men
->lvc
.language
);
600 put_dword(0); /* Menuheader: Version and HeaderSize */
601 menuitem2res(men
->items
, men
->lvc
.language
);
606 put_dword(0); /* Menuheader: Version and HeaderSize */
607 menuitem2res(men
->items
, 0);
609 set_res_size(restag
);
613 *****************************************************************************
614 * Function : cursorgroup2res
616 * name - Name/ordinal of the resource
617 * curg - The cursor descriptor
618 *****************************************************************************
620 static void cursorgroup2res(name_id_t
*name
, cursor_group_t
*curg
)
625 restag
= put_res_header(WRC_RT_GROUP_CURSOR
, name
, curg
->memopt
, &curg
->lvc
);
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?
634 put_word(2); /* ResType */
635 put_word(curg
->ncursor
);
637 for(cur
= curg
->cursorlist
; cur
; cur
= cur
->next
)
639 cur
= curg
->cursorlist
;
642 for(; cur
; cur
= cur
->prev
)
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...
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.
657 put_word(cur
->planes
);
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
664 put_dword(cur
->data
->size
+4);
668 set_res_size(restag
);
672 *****************************************************************************
673 * Function : cursor2res
675 * cur - The cursor descriptor
676 *****************************************************************************
678 static void cursor2res(cursor_t
*cur
)
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
);
688 put_data(cur
->data
->data
, cur
->data
->size
);
690 set_res_size(restag
);
694 *****************************************************************************
695 * Function : icongroup2res
697 * name - Name/ordinal of the resource
698 * icog - The icon group descriptor
699 *****************************************************************************
701 static void icongroup2res(name_id_t
*name
, icon_group_t
*icog
)
706 restag
= put_res_header(WRC_RT_GROUP_ICON
, name
, icog
->memopt
, &icog
->lvc
);
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?
715 put_word(1); /* ResType */
716 put_word(icog
->nicon
);
717 for(ico
= icog
->iconlist
; ico
; ico
= ico
->next
)
719 put_byte(ico
->width
);
720 put_byte(ico
->height
);
722 put_byte(0); /* Reserved */
723 put_word(ico
->planes
);
725 put_dword(ico
->data
->size
);
729 set_res_size(restag
);
733 *****************************************************************************
734 * Function : icon2res
736 * ico - The icon descriptor
737 *****************************************************************************
739 static void icon2res(icon_t
*ico
)
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
);
752 *****************************************************************************
753 * Function : anicurico2res
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
760 *****************************************************************************
762 static void anicur2res(name_id_t
*name
, ani_curico_t
*ani
)
764 int restag
= put_res_header(WRC_RT_ANICURSOR
, name
, ani
->memopt
, NULL
);
766 put_data(ani
->data
->data
, ani
->data
->size
);
767 set_res_size(restag
);
770 static void aniico2res(name_id_t
*name
, ani_curico_t
*ani
)
772 int restag
= put_res_header(WRC_RT_ANIICON
, name
, ani
->memopt
, NULL
);
774 put_data(ani
->data
->data
, ani
->data
->size
);
775 set_res_size(restag
);
779 *****************************************************************************
780 * Function : bitmap2res
782 * name - Name/ordinal of the resource
783 * bmp - The bitmap descriptor
784 *****************************************************************************
786 static void bitmap2res(name_id_t
*name
, bitmap_t
*bmp
)
788 int restag
= put_res_header(WRC_RT_BITMAP
, name
, bmp
->memopt
, &bmp
->data
->lvc
);
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
))
795 /* The File header is still attached, don't write it */
796 put_data((BITMAPFILEHEADER
*)bmp
->data
->data
+ 1, bmp
->data
->size
- sizeof(BITMAPFILEHEADER
));
800 put_data(bmp
->data
->data
, bmp
->data
->size
);
802 set_res_size(restag
);
806 *****************************************************************************
807 * Function : font2res
809 * name - Name/ordinal of the resource
810 * fnt - The font descriptor
811 * Remarks : The data has been prepared just after parsing.
812 *****************************************************************************
814 static void font2res(name_id_t
*name
, font_t
*fnt
)
816 int restag
= put_res_header(WRC_RT_FONT
, name
, fnt
->memopt
, &fnt
->data
->lvc
);
818 put_data(fnt
->data
->data
, fnt
->data
->size
);
819 set_res_size(restag
);
823 *****************************************************************************
824 * Function : fontdir2res
826 * name - Name/ordinal of the resource
827 * fntdir - The fontdir descriptor
828 * Remarks : The data has been prepared just after parsing.
829 *****************************************************************************
831 static void fontdir2res(name_id_t
*name
, fontdir_t
*fnd
)
833 int restag
= put_res_header(WRC_RT_FONTDIR
, name
, fnd
->memopt
, &fnd
->data
->lvc
);
835 put_data(fnd
->data
->data
, fnd
->data
->size
);
836 set_res_size(restag
);
840 *****************************************************************************
841 * Function : html2res
843 * name - Name/ordinal of the resource
844 * rdt - The html descriptor
845 *****************************************************************************
847 static void html2res(name_id_t
*name
, html_t
*html
)
849 int restag
= put_res_header(WRC_RT_HTML
, name
, html
->memopt
, &html
->data
->lvc
);
851 put_data(html
->data
->data
, html
->data
->size
);
852 set_res_size(restag
);
856 *****************************************************************************
857 * Function : rcdata2res
859 * name - Name/ordinal of the resource
860 * rdt - The rcdata descriptor
861 *****************************************************************************
863 static void rcdata2res(name_id_t
*name
, rcdata_t
*rdt
)
865 int restag
= put_res_header(WRC_RT_RCDATA
, name
, rdt
->memopt
, &rdt
->data
->lvc
);
867 put_data(rdt
->data
->data
, rdt
->data
->size
);
868 set_res_size(restag
);
872 *****************************************************************************
873 * Function : messagetable2res
875 * name - Name/ordinal of the resource
876 * msg - The messagetable descriptor
877 *****************************************************************************
879 static void messagetable2res(name_id_t
*name
, messagetable_t
*msg
)
881 int restag
= put_res_header(WRC_RT_MESSAGETABLE
, name
, msg
->memopt
, &msg
->data
->lvc
);
883 put_data(msg
->data
->data
, msg
->data
->size
);
884 set_res_size(restag
);
888 *****************************************************************************
889 * Function : stringtable2res
891 * stt - The stringtable descriptor
892 *****************************************************************************
894 static void stringtable2res(stringtable_t
*stt
)
900 for(; stt
; stt
= stt
->next
)
904 warning("Empty internal stringtable\n");
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
++)
912 if(stt
->entries
[i
].str
&& stt
->entries
[i
].str
->size
)
914 put_string(stt
->entries
[i
].str
, FALSE
, stt
->lvc
.language
);
924 set_res_size(restag
);
929 *****************************************************************************
930 * Function : user2res
932 * name - Name/ordinal of the resource
933 * usr - The userresource descriptor
934 *****************************************************************************
936 static void user2res(name_id_t
*name
, user_t
*usr
)
938 int tag
= output_buffer_pos
;
942 put_dword(0); /* We will overwrite these later */
944 put_name_id(usr
->type
, TRUE
, usr
->data
->lvc
.language
);
945 put_name_id(name
, TRUE
, usr
->data
->lvc
.language
); /* ResName */
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 */
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*/
962 put_data(usr
->data
->data
, usr
->data
->size
);
967 *****************************************************************************
968 * Function : versionblock2res
970 * blk - The version block to be written
971 * Remarks : Self recursive
972 *****************************************************************************
974 static void versionblock2res(ver_block_t
*blk
, int level
, language_t lang
)
983 blksizetag
= output_buffer_pos
;
984 put_word(0); /* Will be overwritten later */
987 put_word(0); /* level ? */
988 put_string(blk
->name
, TRUE
, 0);
990 for(val
= blk
->values
; val
; val
= val
->next
)
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 */
1003 put_string(val
->key
, TRUE
, 0);
1005 tag
= output_buffer_pos
;
1006 put_string(val
->value
.str
, TRUE
, lang
);
1008 set_word(valvalsizetag
, (output_buffer_pos
- tag
) >> 1);
1010 set_word(valvalsizetag
, output_buffer_pos
- tag
);
1011 set_word(valblksizetag
, output_buffer_pos
- valblksizetag
);
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 */
1023 put_string(val
->key
, TRUE
, 0);
1025 tag
= output_buffer_pos
;
1026 for(i
= 0; i
< val
->value
.words
->nwords
; i
++)
1028 put_word(val
->value
.words
->words
[i
]);
1030 set_word(valvalsizetag
, output_buffer_pos
- tag
);
1031 set_word(valblksizetag
, output_buffer_pos
- valblksizetag
);
1035 versionblock2res(val
->value
.block
, level
+1, lang
);
1041 set_word(blksizetag
, output_buffer_pos
- blksizetag
);
1045 *****************************************************************************
1046 * Function : versioninfo2res
1048 * name - Name/ordinal of the resource
1049 * ver - The versioninfo descriptor
1050 *****************************************************************************
1052 static void versioninfo2res(name_id_t
*name
, versioninfo_t
*ver
)
1054 static const char info
[] = "VS_VERSION_INFO";
1056 int restag
, rootblocksizetag
, valsizetag
, tag
;
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*/
1066 put_word(0); /* Tree-level ? */
1067 for (i
= 0; i
< sizeof(info
); i
++) put_word(info
[i
]);
1072 for (i
= 0; i
< sizeof(info
); i
++) put_byte(info
[i
]);
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 */
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
);
1099 *****************************************************************************
1100 * Function : toolbar2res
1102 * name - Name/ordinal of the resource
1103 * toolbar - The toolbar descriptor
1104 *****************************************************************************
1106 static void toolbar2res(name_id_t
*name
, toolbar_t
*toolbar
)
1108 toolbar_item_t
*itm
;
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
);
1119 for (itm
= toolbar
->items
; itm
; itm
= itm
->next
) put_word(itm
->id
);
1120 set_res_size(restag
);
1124 *****************************************************************************
1125 * Function : dlginit2res
1127 * name - Name/ordinal of the resource
1128 * rdt - The dlginit descriptor
1129 *****************************************************************************
1131 static void dlginit2res(name_id_t
*name
, dlginit_t
*dit
)
1133 int restag
= put_res_header(WRC_RT_DLGINIT
, name
, dit
->memopt
, &dit
->data
->lvc
);
1135 put_data(dit
->data
->data
, dit
->data
->size
);
1136 set_res_size(restag
);
1140 *****************************************************************************
1141 * Function : write_resfile
1142 * Syntax : void write_resfile(char *outname, resource_t *top)
1144 * outname - Filename to write to
1145 * top - The resource-tree to convert
1146 *****************************************************************************
1148 void write_resfile(char *outname
, resource_t
*top
)
1150 init_output_buffer();
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 */
1159 put_word(0xffff); /* ResName */
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 */
1168 for ( ; top
; top
= top
->next
)
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;
1194 if (win32
) align_output( 4 );
1197 flush_output_buffer( outname
);