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.
44 #include "wine/unicode.h"
46 #define SetResSize(res, tag) set_dword((res), (tag), (res)->size - get_dword((res), (tag)))
51 r
= xmalloc(sizeof(res_t
));
52 r
->allocsize
= RES_BLOCKSIZE
;
55 r
->data
= xmalloc(RES_BLOCKSIZE
);
59 res_t
*grow_res(res_t
*r
, unsigned int add
)
62 r
->data
= xrealloc(r
->data
, r
->allocsize
);
67 *****************************************************************************
71 * Syntax : void put_byte(res_t *res, unsigned c)
72 * void put_word(res_t *res, unsigned w)
73 * void put_dword(res_t *res, unsigned d)
75 * res - Binary resource to put the data in
76 * c, w, d - Data to put
78 * Description : Put primitives that put an item in the binary resource.
79 * The data array grows automatically.
81 *****************************************************************************
83 void put_byte(res_t
*res
, unsigned c
)
85 if(res
->allocsize
- res
->size
< sizeof(char))
86 grow_res(res
, RES_BLOCKSIZE
);
87 res
->data
[res
->size
] = (char)c
;
88 res
->size
+= sizeof(char);
91 void put_word(res_t
*res
, unsigned w
)
93 if(res
->allocsize
- res
->size
< sizeof(WORD
))
94 grow_res(res
, RES_BLOCKSIZE
);
97 #ifdef WORDS_BIGENDIAN
101 res
->data
[res
->size
+0] = HIBYTE(w
);
102 res
->data
[res
->size
+1] = LOBYTE(w
);
105 #ifndef WORDS_BIGENDIAN
109 res
->data
[res
->size
+1] = HIBYTE(w
);
110 res
->data
[res
->size
+0] = LOBYTE(w
);
113 res
->size
+= sizeof(WORD
);
116 void put_dword(res_t
*res
, unsigned d
)
118 if(res
->allocsize
- res
->size
< sizeof(DWORD
))
119 grow_res(res
, RES_BLOCKSIZE
);
122 #ifdef WORDS_BIGENDIAN
126 res
->data
[res
->size
+0] = HIBYTE(HIWORD(d
));
127 res
->data
[res
->size
+1] = LOBYTE(HIWORD(d
));
128 res
->data
[res
->size
+2] = HIBYTE(LOWORD(d
));
129 res
->data
[res
->size
+3] = LOBYTE(LOWORD(d
));
132 #ifndef WORDS_BIGENDIAN
136 res
->data
[res
->size
+3] = HIBYTE(HIWORD(d
));
137 res
->data
[res
->size
+2] = LOBYTE(HIWORD(d
));
138 res
->data
[res
->size
+1] = HIBYTE(LOWORD(d
));
139 res
->data
[res
->size
+0] = LOBYTE(LOWORD(d
));
142 res
->size
+= sizeof(DWORD
);
145 static void put_pad(res_t
*res
)
147 while(res
->size
& 0x3)
152 *****************************************************************************
153 * Function : set_word
155 * Syntax : void set_word(res_t *res, int ofs, unsigned w)
156 * void set_dword(res_t *res, int ofs, unsigned d)
158 * res - Binary resource to put the data in
159 * ofs - Byte offset in data-array
162 * Description : Set the value of a binary resource data array to a
165 *****************************************************************************
167 static void set_word(res_t
*res
, int ofs
, unsigned w
)
171 #ifdef WORDS_BIGENDIAN
175 res
->data
[ofs
+0] = HIBYTE(w
);
176 res
->data
[ofs
+1] = LOBYTE(w
);
179 #ifndef WORDS_BIGENDIAN
183 res
->data
[ofs
+1] = HIBYTE(w
);
184 res
->data
[ofs
+0] = LOBYTE(w
);
189 static void set_dword(res_t
*res
, int ofs
, unsigned d
)
193 #ifdef WORDS_BIGENDIAN
197 res
->data
[ofs
+0] = HIBYTE(HIWORD(d
));
198 res
->data
[ofs
+1] = LOBYTE(HIWORD(d
));
199 res
->data
[ofs
+2] = HIBYTE(LOWORD(d
));
200 res
->data
[ofs
+3] = LOBYTE(LOWORD(d
));
203 #ifndef WORDS_BIGENDIAN
207 res
->data
[ofs
+3] = HIBYTE(HIWORD(d
));
208 res
->data
[ofs
+2] = LOBYTE(HIWORD(d
));
209 res
->data
[ofs
+1] = HIBYTE(LOWORD(d
));
210 res
->data
[ofs
+0] = LOBYTE(LOWORD(d
));
216 *****************************************************************************
217 * Function : get_dword
219 * res - Binary resource to put the data in
220 * ofs - Byte offset in data-array
221 * Output : The data in native endian
222 * Description : Get the value of a binary resource data array in native
225 *****************************************************************************
227 static DWORD
get_dword(res_t
*res
, int ofs
)
231 #ifdef WORDS_BIGENDIAN
235 return (res
->data
[ofs
+0] << 24)
236 | (res
->data
[ofs
+1] << 16)
237 | (res
->data
[ofs
+2] << 8)
240 #ifndef WORDS_BIGENDIAN
244 return (res
->data
[ofs
+3] << 24)
245 | (res
->data
[ofs
+2] << 16)
246 | (res
->data
[ofs
+1] << 8)
252 *****************************************************************************
253 * Function : string_to_upper
254 * Syntax : void string_to_upper(string_t *str)
258 * Remarks : FIXME: codepages...
259 *****************************************************************************
261 static void string_to_upper(string_t
*str
)
265 if(str
->type
== str_char
)
267 for (i
= 0; i
< str
->size
; i
++) str
->str
.cstr
[i
] = toupper((unsigned char)str
->str
.cstr
[i
]);
269 else if(str
->type
== str_unicode
)
271 for (i
= 0; i
< str
->size
; i
++) str
->str
.wstr
[i
] = toupperW(str
->str
.wstr
[i
]);
275 internal_error(__FILE__
, __LINE__
, "Invalid string type %d\n", str
->type
);
280 *****************************************************************************
281 * Function : put_string
282 * Syntax : void put_string(res_t *res, string_t *str, enum str_e type,
283 * int isterm, const language_t *lang)
285 * res - Binary resource to put the data in
286 * str - String to put
287 * type - Data has to be written in either str_char or str_unicode
288 * isterm - The string is '\0' terminated (disregard the string's
293 *****************************************************************************
295 static void put_string(res_t
*res
, const string_t
*str
, enum str_e type
, int isterm
,
296 const language_t
*lang
)
304 if (lang
) codepage
= get_language_codepage( lang
->id
, lang
->sub
);
305 else codepage
= get_language_codepage( 0, 0 );
307 assert( codepage
!= -1 );
309 newstr
= convert_string(str
, type
, codepage
);
310 if (type
== str_unicode
)
312 if (str
->type
== str_char
)
314 if (!check_unicode_conversion( str
, newstr
, codepage
))
315 error( "String %s does not convert identically to Unicode and back in codepage %d. "
316 "Try using a Unicode string instead\n", str
->str
.cstr
, codepage
);
317 if (check_valid_utf8( str
, codepage
))
318 warning( "string \"%s\" seems to be UTF-8 but codepage %u is in use.\n",
319 str
->str
.cstr
, codepage
);
321 if (!isterm
) put_word(res
, newstr
->size
);
322 for(cnt
= 0; cnt
< newstr
->size
; cnt
++)
324 WCHAR c
= newstr
->str
.wstr
[cnt
];
325 if (isterm
&& !c
) break;
328 if (isterm
) put_word(res
, 0);
332 if (!isterm
) put_byte(res
, newstr
->size
);
333 for(cnt
= 0; cnt
< newstr
->size
; cnt
++)
335 char c
= newstr
->str
.cstr
[cnt
];
336 if (isterm
&& !c
) break;
339 if (isterm
) put_byte(res
, 0);
345 *****************************************************************************
346 * Function : put_name_id
347 * Syntax : void put_name_id(res_t *res, name_id_t *nid, int upcase, const language_t *lang)
352 *****************************************************************************
354 static void put_name_id(res_t
*res
, name_id_t
*nid
, int upcase
, const language_t
*lang
)
356 if(nid
->type
== name_ord
)
359 put_word(res
, 0xffff);
362 put_word(res
, (WORD
)nid
->name
.i_name
);
364 else if(nid
->type
== name_str
)
367 string_to_upper(nid
->name
.s_name
);
368 put_string(res
, nid
->name
.s_name
, win32
? str_unicode
: str_char
, TRUE
, lang
);
372 internal_error(__FILE__
, __LINE__
, "Invalid name_id type %d\n", nid
->type
);
377 *****************************************************************************
379 * Syntax : void put_lvc(res_t *res, lvc_t *lvc)
384 *****************************************************************************
386 static void put_lvc(res_t
*res
, lvc_t
*lvc
)
388 if(lvc
&& lvc
->language
)
389 put_word(res
, MAKELANGID(lvc
->language
->id
, lvc
->language
->sub
));
391 put_word(res
, 0); /* Neutral */
392 if(lvc
&& lvc
->version
)
393 put_dword(res
, *(lvc
->version
));
396 if(lvc
&& lvc
->characts
)
397 put_dword(res
, *(lvc
->characts
));
403 *****************************************************************************
404 * Function : put_raw_data
405 * Syntax : void put_raw_data(res_t *res, raw_data_t *raw, int offset)
410 *****************************************************************************
412 static void put_raw_data(res_t
*res
, raw_data_t
*raw
, int offset
)
414 unsigned int wsize
= raw
->size
- offset
;
415 if(res
->allocsize
- res
->size
< wsize
)
416 grow_res(res
, wsize
);
417 memcpy(&(res
->data
[res
->size
]), raw
->data
+ offset
, wsize
);
422 *****************************************************************************
423 * Function : put_res_header
424 * Syntax : input_res_header(res_t *res, int type, name_id_t *ntype,
425 * name_id_t *name, DWORD memopt, lvc_t *lvc)
428 * res - Binary resource descriptor to write to
429 * type - Resource identifier (if ntype == NULL)
430 * ntype - Name id of type
431 * name - Resource's name
432 * memopt - Resource's memory options to write
433 * lvc - Language, version and characteristics (win32 only)
434 * Output : An index to the resource size field. The resource size field
435 * contains the header size upon exit.
438 *****************************************************************************
440 static int put_res_header(res_t
*res
, int type
, name_id_t
*ntype
, name_id_t
*name
,
441 DWORD memopt
, lvc_t
*lvc
)
445 put_dword(res
, 0); /* We will overwrite these later */
449 put_word(res
, 0xffff); /* ResType */
453 put_name_id(res
, ntype
, TRUE
, lvc
->language
);
454 put_name_id(res
, name
, TRUE
, lvc
->language
); /* ResName */
456 put_dword(res
, 0); /* DataVersion */
457 put_word(res
, memopt
); /* Memory options */
458 put_lvc(res
, lvc
); /* Language, version and characts */
459 set_dword(res
, 0*sizeof(DWORD
), res
->size
); /* Set preliminary resource */
460 set_dword(res
, 1*sizeof(DWORD
), res
->size
); /* Set HeaderSize */
461 res
->dataidx
= res
->size
;
469 put_byte(res
, 0xff); /* ResType */
473 put_name_id(res
, ntype
, TRUE
, NULL
);
474 put_name_id(res
, name
, TRUE
, NULL
); /* ResName */
475 put_word(res
, memopt
); /* Memory options */
477 put_dword(res
, 0); /* ResSize overwritten later*/
478 set_dword(res
, tag
, res
->size
);
479 res
->dataidx
= res
->size
;
485 *****************************************************************************
486 * Function : accelerator2res
487 * Syntax : res_t *accelerator2res(name_id_t *name, accelerator_t *acc)
489 * name - Name/ordinal of the resource
490 * acc - The accelerator descriptor
491 * Output : New .res format structure
494 *****************************************************************************
496 static res_t
*accelerator2res(name_id_t
*name
, accelerator_t
*acc
)
501 assert(name
!= NULL
);
508 restag
= put_res_header(res
, WRC_RT_ACCELERATOR
, NULL
, name
, acc
->memopt
, &(acc
->lvc
));
511 put_word(res
, ev
->flags
| (ev
->next
? 0 : 0x80));
512 put_word(res
, ev
->key
);
513 put_word(res
, ev
->id
);
514 put_word(res
, 0); /* Padding */
521 restag
= put_res_header(res
, WRC_RT_ACCELERATOR
, NULL
, name
, acc
->memopt
, NULL
);
524 put_byte(res
, ev
->flags
| (ev
->next
? 0 : 0x80));
525 put_word(res
, ev
->key
);
526 put_word(res
, ev
->id
);
530 /* Set ResourceSize */
531 SetResSize(res
, restag
);
536 *****************************************************************************
537 * Function : dialog2res
538 * Syntax : res_t *dialog2res(name_id_t *name, dialog_t *dlg)
540 * name - Name/ordinal of the resource
541 * dlg - The dialog descriptor
542 * Output : New .res format structure
545 *****************************************************************************
547 static res_t
*dialog2res(name_id_t
*name
, dialog_t
*dlg
)
554 assert(name
!= NULL
);
557 ctrl
= dlg
->controls
;
561 restag
= put_res_header(res
, WRC_RT_DIALOG
, NULL
, name
, dlg
->memopt
, &(dlg
->lvc
));
563 put_dword(res
, dlg
->style
->or_mask
);
564 put_dword(res
, dlg
->gotexstyle
? dlg
->exstyle
->or_mask
: 0);
565 tag_nctrl
= res
->size
;
566 put_word(res
, 0); /* Number of controls */
567 put_word(res
, dlg
->x
);
568 put_word(res
, dlg
->y
);
569 put_word(res
, dlg
->width
);
570 put_word(res
, dlg
->height
);
572 put_name_id(res
, dlg
->menu
, TRUE
, dlg
->lvc
.language
);
576 put_name_id(res
, dlg
->dlgclass
, TRUE
, dlg
->lvc
.language
);
580 put_string(res
, dlg
->title
, str_unicode
, TRUE
, dlg
->lvc
.language
);
585 put_word(res
, dlg
->font
->size
);
586 put_string(res
, dlg
->font
->name
, str_unicode
, TRUE
, dlg
->lvc
.language
);
592 /* FIXME: what is default control style? */
593 put_dword(res
, ctrl
->gotstyle
? ctrl
->style
->or_mask
: WS_CHILD
);
594 put_dword(res
, ctrl
->gotexstyle
? ctrl
->exstyle
->or_mask
: 0);
595 put_word(res
, ctrl
->x
);
596 put_word(res
, ctrl
->y
);
597 put_word(res
, ctrl
->width
);
598 put_word(res
, ctrl
->height
);
599 put_word(res
, ctrl
->id
);
601 put_name_id(res
, ctrl
->ctlclass
, TRUE
, dlg
->lvc
.language
);
603 internal_error(__FILE__
, __LINE__
, "Control has no control-class\n");
605 put_name_id(res
, ctrl
->title
, FALSE
, dlg
->lvc
.language
);
610 put_word(res
, ctrl
->extra
->size
+2);
612 put_raw_data(res
, ctrl
->extra
, 0);
622 /* Set number of controls */
623 set_word(res
, tag_nctrl
, (WORD
)nctrl
);
627 restag
= put_res_header(res
, WRC_RT_DIALOG
, NULL
, name
, dlg
->memopt
, NULL
);
629 put_dword(res
, dlg
->gotstyle
? dlg
->style
->or_mask
: WS_POPUPWINDOW
);
630 tag_nctrl
= res
->size
;
631 put_byte(res
, 0); /* Number of controls */
632 put_word(res
, dlg
->x
);
633 put_word(res
, dlg
->y
);
634 put_word(res
, dlg
->width
);
635 put_word(res
, dlg
->height
);
637 put_name_id(res
, dlg
->menu
, TRUE
, NULL
);
641 put_name_id(res
, dlg
->dlgclass
, TRUE
, NULL
);
645 put_string(res
, dlg
->title
, str_char
, TRUE
, NULL
);
650 put_word(res
, dlg
->font
->size
);
651 put_string(res
, dlg
->font
->name
, str_char
, TRUE
, NULL
);
656 put_word(res
, ctrl
->x
);
657 put_word(res
, ctrl
->y
);
658 put_word(res
, ctrl
->width
);
659 put_word(res
, ctrl
->height
);
660 put_word(res
, ctrl
->id
);
661 put_dword(res
, ctrl
->gotstyle
? ctrl
->style
->or_mask
: WS_CHILD
);
664 if(ctrl
->ctlclass
->type
== name_ord
665 && ctrl
->ctlclass
->name
.i_name
>= 0x80
666 && ctrl
->ctlclass
->name
.i_name
<= 0x85)
667 put_byte(res
, ctrl
->ctlclass
->name
.i_name
);
668 else if(ctrl
->ctlclass
->type
== name_str
)
669 put_name_id(res
, ctrl
->ctlclass
, FALSE
, NULL
);
671 error("Unknown control-class %04x\n", ctrl
->ctlclass
->name
.i_name
);
674 internal_error(__FILE__
, __LINE__
, "Control has no control-class\n");
676 put_name_id(res
, ctrl
->title
, FALSE
, NULL
);
680 /* FIXME: What is this extra byte doing here? */
686 /* Set number of controls */
687 ((char *)res
->data
)[tag_nctrl
] = (char)nctrl
;
689 /* Set ResourceSize */
690 SetResSize(res
, restag
);
695 *****************************************************************************
696 * Function : dialogex2res
697 * Syntax : res_t *dialogex2res(name_id_t *name, dialogex_t *dlgex)
699 * name - Name/ordinal of the resource
700 * dlgex - The dialogex descriptor
701 * Output : New .res format structure
704 *****************************************************************************
706 static res_t
*dialogex2res(name_id_t
*name
, dialogex_t
*dlgex
)
713 assert(name
!= NULL
);
714 assert(dlgex
!= NULL
);
716 ctrl
= dlgex
->controls
;
720 restag
= put_res_header(res
, WRC_RT_DIALOG
, NULL
, name
, dlgex
->memopt
, &(dlgex
->lvc
));
722 /* FIXME: MS doc says that the first word must contain 0xffff
723 * and the second 0x0001 to signal a DLGTEMPLATEEX. Borland's
724 * compiler reverses the two words.
725 * I don't know which one to choose, but I write it as Mr. B
728 put_word(res
, 1); /* Signature */
729 put_word(res
, 0xffff); /* DlgVer */
730 put_dword(res
, dlgex
->gothelpid
? dlgex
->helpid
: 0);
731 put_dword(res
, dlgex
->gotexstyle
? dlgex
->exstyle
->or_mask
: 0);
732 put_dword(res
, dlgex
->gotstyle
? dlgex
->style
->or_mask
: WS_POPUPWINDOW
);
733 tag_nctrl
= res
->size
;
734 put_word(res
, 0); /* Number of controls */
735 put_word(res
, dlgex
->x
);
736 put_word(res
, dlgex
->y
);
737 put_word(res
, dlgex
->width
);
738 put_word(res
, dlgex
->height
);
740 put_name_id(res
, dlgex
->menu
, TRUE
, dlgex
->lvc
.language
);
744 put_name_id(res
, dlgex
->dlgclass
, TRUE
, dlgex
->lvc
.language
);
748 put_string(res
, dlgex
->title
, str_unicode
, TRUE
, dlgex
->lvc
.language
);
753 put_word(res
, dlgex
->font
->size
);
754 put_word(res
, dlgex
->font
->weight
);
755 /* FIXME: ? TRUE should be sufficient to say that it's
756 * italic, but Borland's compiler says it's 0x0101.
757 * I just copy it here, and hope for the best.
759 put_word(res
, dlgex
->font
->italic
? 0x0101 : 0);
760 put_string(res
, dlgex
->font
->name
, str_unicode
, TRUE
, dlgex
->lvc
.language
);
766 put_dword(res
, ctrl
->gothelpid
? ctrl
->helpid
: 0);
767 put_dword(res
, ctrl
->gotexstyle
? ctrl
->exstyle
->or_mask
: 0);
768 /* FIXME: what is default control style? */
769 put_dword(res
, ctrl
->gotstyle
? ctrl
->style
->or_mask
: WS_CHILD
| WS_VISIBLE
);
770 put_word(res
, ctrl
->x
);
771 put_word(res
, ctrl
->y
);
772 put_word(res
, ctrl
->width
);
773 put_word(res
, ctrl
->height
);
774 put_dword(res
, ctrl
->id
);
776 put_name_id(res
, ctrl
->ctlclass
, TRUE
, dlgex
->lvc
.language
);
778 internal_error(__FILE__
, __LINE__
, "Control has no control-class\n");
780 put_name_id(res
, ctrl
->title
, FALSE
, dlgex
->lvc
.language
);
786 put_word(res
, ctrl
->extra
->size
);
787 put_raw_data(res
, ctrl
->extra
, 0);
796 /* Set number of controls */
797 set_word(res
, tag_nctrl
, (WORD
)nctrl
);
798 /* Set ResourceSize */
799 SetResSize(res
, restag
);
804 /* Do not generate anything in 16-bit mode */
813 *****************************************************************************
814 * Function : menuitem2res
815 * Syntax : void menuitem2res(res_t *res, menu_item_t *item)
819 * Remarks : Self recursive
820 *****************************************************************************
822 static void menuitem2res(res_t
*res
, menu_item_t
*menitem
, const language_t
*lang
)
824 menu_item_t
*itm
= menitem
;
829 put_word(res
, itm
->state
| (itm
->popup
? MF_POPUP
: 0) | (!itm
->next
? MF_END
: 0));
831 put_word(res
, itm
->id
);
833 put_string(res
, itm
->name
, str_unicode
, TRUE
, lang
);
837 menuitem2res(res
, itm
->popup
, lang
);
845 put_word(res
, itm
->state
| (itm
->popup
? MF_POPUP
: 0) | (!itm
->next
? MF_END
: 0));
847 put_word(res
, itm
->id
);
849 put_string(res
, itm
->name
, str_char
, TRUE
, lang
);
853 menuitem2res(res
, itm
->popup
, lang
);
861 *****************************************************************************
862 * Function : menu2res
863 * Syntax : res_t *menu2res(name_id_t *name, menu_t *men)
865 * name - Name/ordinal of the resource
866 * men - The menu descriptor
867 * Output : New .res format structure
870 *****************************************************************************
872 static res_t
*menu2res(name_id_t
*name
, menu_t
*men
)
876 assert(name
!= NULL
);
880 restag
= put_res_header(res
, WRC_RT_MENU
, NULL
, name
, men
->memopt
, win32
? &(men
->lvc
) : NULL
);
882 put_dword(res
, 0); /* Menuheader: Version and HeaderSize */
883 menuitem2res(res
, men
->items
, win32
? men
->lvc
.language
: NULL
);
884 /* Set ResourceSize */
885 SetResSize(res
, restag
);
892 *****************************************************************************
893 * Function : menuexitem2res
894 * Syntax : void menuexitem2res(res_t *res, menuex_item_t *item)
898 * Remarks : Self recursive
899 *****************************************************************************
901 static void menuexitem2res(res_t
*res
, menuex_item_t
*menitem
, const language_t
*lang
)
903 menuex_item_t
*itm
= menitem
;
907 put_dword(res
, itm
->gottype
? itm
->type
: 0);
908 put_dword(res
, itm
->gotstate
? itm
->state
: 0);
909 put_dword(res
, itm
->gotid
? itm
->id
: 0); /* FIXME: Docu. says word */
910 put_word(res
, (itm
->popup
? 0x01 : 0) | (!itm
->next
? MF_END
: 0));
912 put_string(res
, itm
->name
, str_unicode
, TRUE
, lang
);
918 put_dword(res
, itm
->gothelpid
? itm
->helpid
: 0);
919 menuexitem2res(res
, itm
->popup
, lang
);
927 *****************************************************************************
928 * Function : menuex2res
929 * Syntax : res_t *menuex2res(name_id_t *name, menuex_t *menex)
931 * name - Name/ordinal of the resource
932 * menex - The menuex descriptor
933 * Output : New .res format structure
936 *****************************************************************************
938 static res_t
*menuex2res(name_id_t
*name
, menuex_t
*menex
)
942 assert(name
!= NULL
);
943 assert(menex
!= NULL
);
948 restag
= put_res_header(res
, WRC_RT_MENU
, NULL
, name
, menex
->memopt
, &(menex
->lvc
));
950 put_word(res
, 1); /* Menuheader: Version */
951 put_word(res
, 4); /* Offset */
952 put_dword(res
, 0); /* HelpId */
954 menuexitem2res(res
, menex
->items
, menex
->lvc
.language
);
955 /* Set ResourceSize */
956 SetResSize(res
, restag
);
961 /* Do not generate anything in 16-bit mode */
970 *****************************************************************************
971 * Function : cursorgroup2res
972 * Syntax : res_t *cursorgroup2res(name_id_t *name, cursor_group_t *curg)
974 * name - Name/ordinal of the resource
975 * curg - The cursor descriptor
976 * Output : New .res format structure
979 *****************************************************************************
981 static res_t
*cursorgroup2res(name_id_t
*name
, cursor_group_t
*curg
)
986 assert(name
!= NULL
);
987 assert(curg
!= NULL
);
990 restag
= put_res_header(res
, WRC_RT_GROUP_CURSOR
, NULL
, name
, curg
->memopt
, &(curg
->lvc
));
993 put_word(res
, 0); /* Reserved */
994 /* FIXME: The ResType in the NEWHEADER structure should
995 * contain 14 according to the MS win32 doc. This is
996 * not the case with the BRC compiler and I really doubt
997 * the latter. Putting one here is compliant to win16 spec,
998 * but who knows the true value?
1000 put_word(res
, 2); /* ResType */
1001 put_word(res
, curg
->ncursor
);
1003 for(cur
= curg
->cursorlist
; cur
; cur
= cur
->next
)
1005 cur
= curg
->cursorlist
;
1008 for(; cur
; cur
= cur
->prev
)
1011 put_word(res
, cur
->width
);
1012 /* FIXME: The height of a cursor is half the size of
1013 * the bitmap's height. BRC puts the height from the
1014 * BITMAPINFOHEADER here instead of the cursorfile's
1015 * height. MS doesn't seem to care...
1017 put_word(res
, cur
->height
);
1018 /* FIXME: The next two are reversed in BRC and I don't
1019 * know why. Probably a bug. But, we can safely ignore
1020 * it because win16 does not support color cursors.
1021 * A warning should have been generated by the parser.
1023 put_word(res
, cur
->planes
);
1024 put_word(res
, cur
->bits
);
1025 /* FIXME: The +4 is the hotspot in the cursor resource.
1026 * However, I could not find this in the documentation.
1027 * The hotspot bytes must either be included or MS
1030 put_dword(res
, cur
->data
->size
+4);
1031 put_word(res
, cur
->id
);
1036 put_word(res
, 0); /* Reserved */
1037 put_word(res
, 2); /* ResType */
1038 put_word(res
, curg
->ncursor
);
1040 for(cur
= curg
->cursorlist
; cur
; cur
= cur
->next
)
1042 cur
= curg
->cursorlist
;
1045 for(; cur
; cur
= cur
->prev
)
1048 put_word(res
, cur
->width
);
1049 /* FIXME: The height of a cursor is half the size of
1050 * the bitmap's height. BRC puts the height from the
1051 * BITMAPINFOHEADER here instead of the cursorfile's
1052 * height. MS doesn't seem to care...
1054 put_word(res
, cur
->height
);
1055 /* FIXME: The next two are reversed in BRC and I don't
1056 * know why. Probably a bug. But, we can safely ignore
1057 * it because win16 does not support color cursors.
1058 * A warning should have been generated by the parser.
1060 put_word(res
, cur
->planes
);
1061 put_word(res
, cur
->bits
);
1062 /* FIXME: The +4 is the hotspot in the cursor resource.
1063 * However, I could not find this in the documentation.
1064 * The hotspot bytes must either be included or MS
1067 put_dword(res
, cur
->data
->size
+4);
1068 put_word(res
, cur
->id
);
1071 SetResSize(res
, restag
); /* Set ResourceSize */
1079 *****************************************************************************
1080 * Function : cursor2res
1081 * Syntax : res_t *cursor2res(cursor_t *cur)
1083 * cur - The cursor descriptor
1084 * Output : New .res format structure
1087 *****************************************************************************
1089 static res_t
*cursor2res(cursor_t
*cur
)
1095 assert(cur
!= NULL
);
1098 name
.type
= name_ord
;
1099 name
.name
.i_name
= cur
->id
;
1100 restag
= put_res_header(res
, WRC_RT_CURSOR
, NULL
, &name
, WRC_MO_MOVEABLE
| WRC_MO_DISCARDABLE
, &(cur
->lvc
));
1101 put_word(res
, cur
->xhot
);
1102 put_word(res
, cur
->yhot
);
1103 put_raw_data(res
, cur
->data
, 0);
1105 SetResSize(res
, restag
); /* Set ResourceSize */
1113 *****************************************************************************
1114 * Function : icongroup2res
1115 * Syntax : res_t *icongroup2res(name_id_t *name, icon_group_t *icog)
1117 * name - Name/ordinal of the resource
1118 * icog - The icon group descriptor
1119 * Output : New .res format structure
1122 *****************************************************************************
1124 static res_t
*icongroup2res(name_id_t
*name
, icon_group_t
*icog
)
1129 assert(name
!= NULL
);
1130 assert(icog
!= NULL
);
1133 restag
= put_res_header(res
, WRC_RT_GROUP_ICON
, NULL
, name
, icog
->memopt
, &(icog
->lvc
));
1136 put_word(res
, 0); /* Reserved */
1137 /* FIXME: The ResType in the NEWHEADER structure should
1138 * contain 14 according to the MS win32 doc. This is
1139 * not the case with the BRC compiler and I really doubt
1140 * the latter. Putting one here is compliant to win16 spec,
1141 * but who knows the true value?
1143 put_word(res
, 1); /* ResType */
1144 put_word(res
, icog
->nicon
);
1145 for(ico
= icog
->iconlist
; ico
; ico
= ico
->next
)
1147 put_byte(res
, ico
->width
);
1148 put_byte(res
, ico
->height
);
1149 put_byte(res
, ico
->nclr
);
1150 put_byte(res
, 0); /* Reserved */
1151 put_word(res
, ico
->planes
);
1152 put_word(res
, ico
->bits
);
1153 put_dword(res
, ico
->data
->size
);
1154 put_word(res
, ico
->id
);
1159 put_word(res
, 0); /* Reserved */
1160 put_word(res
, 1); /* ResType */
1161 put_word(res
, icog
->nicon
);
1162 for(ico
= icog
->iconlist
; ico
; ico
= ico
->next
)
1164 put_byte(res
, ico
->width
);
1165 put_byte(res
, ico
->height
);
1166 put_byte(res
, ico
->nclr
);
1167 put_byte(res
, 0); /* Reserved */
1168 put_word(res
, ico
->planes
);
1169 put_word(res
, ico
->bits
);
1170 put_dword(res
, ico
->data
->size
);
1171 put_word(res
, ico
->id
);
1174 SetResSize(res
, restag
); /* Set ResourceSize */
1182 *****************************************************************************
1183 * Function : icon2res
1184 * Syntax : res_t *icon2res(icon_t *ico)
1186 * ico - The icon descriptor
1187 * Output : New .res format structure
1190 *****************************************************************************
1192 static res_t
*icon2res(icon_t
*ico
)
1198 assert(ico
!= NULL
);
1201 name
.type
= name_ord
;
1202 name
.name
.i_name
= ico
->id
;
1203 restag
= put_res_header(res
, WRC_RT_ICON
, NULL
, &name
, WRC_MO_MOVEABLE
| WRC_MO_DISCARDABLE
, &(ico
->lvc
));
1204 put_raw_data(res
, ico
->data
, 0);
1206 SetResSize(res
, restag
); /* Set ResourceSize */
1214 *****************************************************************************
1215 * Function : anicurico2res
1216 * Syntax : res_t *anicurico2res(name_id_t *name, ani_curico_t *ani)
1218 * name - Name/ordinal of the resource
1219 * ani - The animated object descriptor
1220 * Output : New .res format structure
1222 * Remarks : The endian of the object's structures have been converted
1224 * There are rumors that win311 could handle animated stuff.
1225 * That is why they are generated for both win16 and win32
1227 *****************************************************************************
1229 static res_t
*anicurico2res(name_id_t
*name
, ani_curico_t
*ani
, enum res_e type
)
1233 assert(name
!= NULL
);
1234 assert(ani
!= NULL
);
1237 restag
= put_res_header(res
, type
== res_anicur
? WRC_RT_ANICURSOR
: WRC_RT_ANIICON
,
1238 NULL
, name
, ani
->memopt
, NULL
);
1239 put_raw_data(res
, ani
->data
, 0);
1240 /* Set ResourceSize */
1241 SetResSize(res
, restag
);
1248 *****************************************************************************
1249 * Function : bitmap2res
1250 * Syntax : res_t *bitmap2res(name_id_t *name, bitmap_t *bmp)
1252 * name - Name/ordinal of the resource
1253 * bmp - The bitmap descriptor
1254 * Output : New .res format structure
1256 * Remarks : The endian of the bitmap structures have been converted
1258 *****************************************************************************
1260 static res_t
*bitmap2res(name_id_t
*name
, bitmap_t
*bmp
)
1264 assert(name
!= NULL
);
1265 assert(bmp
!= NULL
);
1268 restag
= put_res_header(res
, WRC_RT_BITMAP
, NULL
, name
, bmp
->memopt
, &(bmp
->data
->lvc
));
1269 if(bmp
->data
->data
[0] == 'B'
1270 && bmp
->data
->data
[1] == 'M'
1271 && ((BITMAPFILEHEADER
*)bmp
->data
->data
)->bfSize
== bmp
->data
->size
1272 && bmp
->data
->size
>= sizeof(BITMAPFILEHEADER
))
1274 /* The File header is still attached, don't write it */
1275 put_raw_data(res
, bmp
->data
, sizeof(BITMAPFILEHEADER
));
1279 put_raw_data(res
, bmp
->data
, 0);
1281 /* Set ResourceSize */
1282 SetResSize(res
, restag
);
1289 *****************************************************************************
1290 * Function : font2res
1291 * Syntax : res_t *font2res(name_id_t *name, font_t *fnt)
1293 * name - Name/ordinal of the resource
1294 * fnt - The font descriptor
1295 * Output : New .res format structure
1297 * Remarks : The data has been prepared just after parsing.
1298 *****************************************************************************
1300 static res_t
*font2res(name_id_t
*name
, font_t
*fnt
)
1304 assert(name
!= NULL
);
1305 assert(fnt
!= NULL
);
1308 restag
= put_res_header(res
, WRC_RT_FONT
, NULL
, name
, fnt
->memopt
, &(fnt
->data
->lvc
));
1309 put_raw_data(res
, fnt
->data
, 0);
1310 /* Set ResourceSize */
1311 SetResSize(res
, restag
);
1318 *****************************************************************************
1319 * Function : fontdir2res
1320 * Syntax : res_t *fontdir2res(name_id_t *name, fontdir_t *fnd)
1322 * name - Name/ordinal of the resource
1323 * fntdir - The fontdir descriptor
1324 * Output : New .res format structure
1326 * Remarks : The data has been prepared just after parsing.
1327 *****************************************************************************
1329 static res_t
*fontdir2res(name_id_t
*name
, fontdir_t
*fnd
)
1333 assert(name
!= NULL
);
1334 assert(fnd
!= NULL
);
1337 restag
= put_res_header(res
, WRC_RT_FONTDIR
, NULL
, name
, fnd
->memopt
, &(fnd
->data
->lvc
));
1338 put_raw_data(res
, fnd
->data
, 0);
1339 /* Set ResourceSize */
1340 SetResSize(res
, restag
);
1347 *****************************************************************************
1348 * Function : html2res
1349 * Syntax : res_t *html2res(name_id_t *name, html_t *html)
1351 * name - Name/ordinal of the resource
1352 * rdt - The html descriptor
1353 * Output : New .res format structure
1356 *****************************************************************************
1358 static res_t
*html2res(name_id_t
*name
, html_t
*html
)
1362 assert(name
!= NULL
);
1363 assert(html
!= NULL
);
1366 restag
= put_res_header(res
, WRC_RT_HTML
, NULL
, name
, html
->memopt
, &(html
->data
->lvc
));
1367 put_raw_data(res
, html
->data
, 0);
1368 /* Set ResourceSize */
1369 SetResSize(res
, restag
);
1376 *****************************************************************************
1377 * Function : rcdata2res
1378 * Syntax : res_t *rcdata2res(name_id_t *name, rcdata_t *rdt)
1380 * name - Name/ordinal of the resource
1381 * rdt - The rcdata descriptor
1382 * Output : New .res format structure
1385 *****************************************************************************
1387 static res_t
*rcdata2res(name_id_t
*name
, rcdata_t
*rdt
)
1391 assert(name
!= NULL
);
1392 assert(rdt
!= NULL
);
1395 restag
= put_res_header(res
, WRC_RT_RCDATA
, NULL
, name
, rdt
->memopt
, &(rdt
->data
->lvc
));
1396 put_raw_data(res
, rdt
->data
, 0);
1397 /* Set ResourceSize */
1398 SetResSize(res
, restag
);
1405 *****************************************************************************
1406 * Function : messagetable2res
1407 * Syntax : res_t *messagetable2res(name_id_t *name, messagetable_t *msg)
1409 * name - Name/ordinal of the resource
1410 * msg - The messagetable descriptor
1411 * Output : New .res format structure
1413 * Remarks : The data has been converted to the appropriate endian
1414 * after it was parsed.
1415 *****************************************************************************
1417 static res_t
*messagetable2res(name_id_t
*name
, messagetable_t
*msg
)
1421 assert(name
!= NULL
);
1422 assert(msg
!= NULL
);
1425 restag
= put_res_header(res
, WRC_RT_MESSAGETABLE
, NULL
, name
, msg
->memopt
, &(msg
->data
->lvc
));
1426 put_raw_data(res
, msg
->data
, 0);
1427 /* Set ResourceSize */
1428 SetResSize(res
, restag
);
1435 *****************************************************************************
1436 * Function : stringtable2res
1437 * Syntax : res_t *stringtable2res(stringtable_t *stt)
1439 * stt - The stringtable descriptor
1440 * Output : New .res format structure
1443 *****************************************************************************
1445 static res_t
*stringtable2res(stringtable_t
*stt
)
1453 assert(stt
!= NULL
);
1456 for(; stt
; stt
= stt
->next
)
1460 warning("Empty internal stringtable\n");
1463 name
.type
= name_ord
;
1464 name
.name
.i_name
= (stt
->idbase
>> 4) + 1;
1465 restag
= put_res_header(res
, WRC_RT_STRING
, NULL
, &name
, stt
->memopt
, win32
? &(stt
->lvc
) : NULL
);
1466 for(i
= 0; i
< stt
->nentries
; i
++)
1468 if(stt
->entries
[i
].str
&& stt
->entries
[i
].str
->size
)
1470 put_string(res
, stt
->entries
[i
].str
, win32
? str_unicode
: str_char
,
1471 FALSE
, win32
? stt
->lvc
.language
: NULL
);
1481 /* Set ResourceSize */
1482 SetResSize(res
, restag
- lastsize
);
1485 lastsize
= res
->size
;
1491 *****************************************************************************
1492 * Function : user2res
1493 * Syntax : res_t *user2res(name_id_t *name, user_t *usr)
1495 * name - Name/ordinal of the resource
1496 * usr - The userresource descriptor
1497 * Output : New .res format structure
1500 *****************************************************************************
1502 static res_t
*user2res(name_id_t
*name
, user_t
*usr
)
1506 assert(name
!= NULL
);
1507 assert(usr
!= NULL
);
1510 restag
= put_res_header(res
, 0, usr
->type
, name
, usr
->memopt
, &(usr
->data
->lvc
));
1511 put_raw_data(res
, usr
->data
, 0);
1512 /* Set ResourceSize */
1513 SetResSize(res
, restag
);
1520 *****************************************************************************
1521 * Function : versionblock2res
1522 * Syntax : void versionblock2res(res_t *res, ver_block_t *blk)
1524 * res - Binary resource to write to
1525 * blk - The version block to be written
1528 * Remarks : Self recursive
1529 *****************************************************************************
1531 static void versionblock2res(res_t
*res
, ver_block_t
*blk
, int level
, const language_t
*lang
)
1540 blksizetag
= res
->size
;
1541 put_word(res
, 0); /* Will be overwritten later */
1544 put_word(res
, 0); /* level ? */
1545 put_string(res
, blk
->name
, win32
? str_unicode
: str_char
, TRUE
, lang
);
1547 for(val
= blk
->values
; val
; val
= val
->next
)
1549 if(val
->type
== val_str
)
1551 valblksizetag
= res
->size
;
1552 put_word(res
, 0); /* Will be overwritten later */
1553 valvalsizetag
= res
->size
;
1554 put_word(res
, 0); /* Will be overwritten later */
1557 put_word(res
, level
);
1559 put_string(res
, val
->key
, win32
? str_unicode
: str_char
, TRUE
, lang
);
1562 put_string(res
, val
->value
.str
, win32
? str_unicode
: str_char
, TRUE
, lang
);
1564 set_word(res
, valvalsizetag
, (WORD
)((res
->size
- tag
) >> 1));
1566 set_word(res
, valvalsizetag
, (WORD
)(res
->size
- tag
));
1567 set_word(res
, valblksizetag
, (WORD
)(res
->size
- valblksizetag
));
1570 else if(val
->type
== val_words
)
1572 valblksizetag
= res
->size
;
1573 put_word(res
, 0); /* Will be overwritten later */
1574 valvalsizetag
= res
->size
;
1575 put_word(res
, 0); /* Will be overwritten later */
1578 put_word(res
, level
);
1580 put_string(res
, val
->key
, win32
? str_unicode
: str_char
, TRUE
, lang
);
1583 for(i
= 0; i
< val
->value
.words
->nwords
; i
++)
1585 put_word(res
, val
->value
.words
->words
[i
]);
1587 set_word(res
, valvalsizetag
, (WORD
)(res
->size
- tag
));
1588 set_word(res
, valblksizetag
, (WORD
)(res
->size
- valblksizetag
));
1591 else if(val
->type
== val_block
)
1593 versionblock2res(res
, val
->value
.block
, level
+1, lang
);
1597 internal_error(__FILE__
, __LINE__
, "Invalid value indicator %d in VERSIONINFO\n", val
->type
);
1602 set_word(res
, blksizetag
, (WORD
)(res
->size
- blksizetag
));
1606 *****************************************************************************
1607 * Function : versioninfo2res
1608 * Syntax : res_t *versioninfo2res(name_id_t *name, versioninfo_t *ver)
1610 * name - Name/ordinal of the resource
1611 * ver - The versioninfo descriptor
1612 * Output : New .res format structure
1615 *****************************************************************************
1617 static res_t
*versioninfo2res(name_id_t
*name
, versioninfo_t
*ver
)
1620 int rootblocksizetag
;
1627 assert(name
!= NULL
);
1628 assert(ver
!= NULL
);
1630 vsvi
.type
= str_char
;
1631 vsvi
.str
.cstr
= xstrdup("VS_VERSION_INFO");
1632 vsvi
.size
= 15; /* Excl. termination */
1635 restag
= put_res_header(res
, WRC_RT_VERSION
, NULL
, name
, ver
->memopt
, &(ver
->lvc
));
1636 rootblocksizetag
= res
->size
;
1637 put_word(res
, 0); /* BlockSize filled in later */
1638 valsizetag
= res
->size
;
1639 put_word(res
, 0); /* ValueSize filled in later*/
1641 put_word(res
, 0); /* Tree-level ? */
1642 put_string(res
, &vsvi
, win32
? str_unicode
: str_char
,
1643 TRUE
, win32
? ver
->lvc
.language
: NULL
);
1647 put_dword(res
, VS_FFI_SIGNATURE
);
1648 put_dword(res
, VS_FFI_STRUCVERSION
);
1649 put_dword(res
, (ver
->filever_maj1
<< 16) + (ver
->filever_maj2
& 0xffff));
1650 put_dword(res
, (ver
->filever_min1
<< 16) + (ver
->filever_min2
& 0xffff));
1651 put_dword(res
, (ver
->prodver_maj1
<< 16) + (ver
->prodver_maj2
& 0xffff));
1652 put_dword(res
, (ver
->prodver_min1
<< 16) + (ver
->prodver_min2
& 0xffff));
1653 put_dword(res
, ver
->fileflagsmask
);
1654 put_dword(res
, ver
->fileflags
);
1655 put_dword(res
, ver
->fileos
);
1656 put_dword(res
, ver
->filetype
);
1657 put_dword(res
, ver
->filesubtype
);
1658 put_dword(res
, 0); /* FileDateMS */
1659 put_dword(res
, 0); /* FileDateLS */
1661 set_word(res
, valsizetag
, (WORD
)(res
->size
- tag
));
1662 /* Descend into the blocks */
1663 for(blk
= ver
->blocks
; blk
; blk
= blk
->next
)
1664 versionblock2res(res
, blk
, 0, win32
? ver
->lvc
.language
: NULL
);
1665 /* Set root block's size */
1666 set_word(res
, rootblocksizetag
, (WORD
)(res
->size
- rootblocksizetag
));
1668 SetResSize(res
, restag
);
1672 free(vsvi
.str
.cstr
);
1677 *****************************************************************************
1678 * Function : toolbaritem2res
1679 * Syntax : void toolbaritem2res(res_t *res, toolbar_item_t *tbitem)
1683 * Remarks : Self recursive
1684 *****************************************************************************
1686 static void toolbaritem2res(res_t
*res
, toolbar_item_t
*tbitem
)
1688 toolbar_item_t
*itm
= tbitem
;
1692 put_word(res
, itm
->id
);
1699 *****************************************************************************
1700 * Function : toolbar2res
1701 * Syntax : res_t *toolbar2res(name_id_t *name, toolbar_t *toolbar)
1703 * name - Name/ordinal of the resource
1704 * toolbar - The toolbar descriptor
1705 * Output : New .res format structure
1708 *****************************************************************************
1710 static res_t
*toolbar2res(name_id_t
*name
, toolbar_t
*toolbar
)
1714 assert(name
!= NULL
);
1715 assert(toolbar
!= NULL
);
1720 restag
= put_res_header(res
, WRC_RT_TOOLBAR
, NULL
, name
, toolbar
->memopt
, &(toolbar
->lvc
));
1722 put_word(res
, 1); /* Menuheader: Version */
1723 put_word(res
, toolbar
->button_width
); /* (in pixels?) */
1724 put_word(res
, toolbar
->button_height
); /* (in pixels?) */
1725 put_word(res
, toolbar
->nitems
);
1727 toolbaritem2res(res
, toolbar
->items
);
1728 /* Set ResourceSize */
1729 SetResSize(res
, restag
);
1734 /* Do not generate anything in 16-bit mode */
1743 *****************************************************************************
1744 * Function : dlginit2res
1745 * Syntax : res_t *dlginit2res(name_id_t *name, dlginit_t *dit)
1747 * name - Name/ordinal of the resource
1748 * rdt - The dlginit descriptor
1749 * Output : New .res format structure
1752 *****************************************************************************
1754 static res_t
*dlginit2res(name_id_t
*name
, dlginit_t
*dit
)
1758 assert(name
!= NULL
);
1759 assert(dit
!= NULL
);
1762 restag
= put_res_header(res
, WRC_RT_DLGINIT
, NULL
, name
, dit
->memopt
, &(dit
->data
->lvc
));
1763 put_raw_data(res
, dit
->data
, 0);
1764 /* Set ResourceSize */
1765 SetResSize(res
, restag
);
1772 *****************************************************************************
1773 * Function : prep_nid_for_label
1774 * Syntax : char *prep_nid_for_label(const name_id_t *nid)
1777 * Description : Converts a resource name into the first 32 (or less)
1778 * characters of the name with conversions.
1780 *****************************************************************************
1782 #define MAXNAMELEN 32
1783 char *prep_nid_for_label(const name_id_t
*nid
)
1785 static char buf
[MAXNAMELEN
+1];
1787 assert(nid
!= NULL
);
1789 if(nid
->type
== name_str
&& nid
->name
.s_name
->type
== str_unicode
)
1793 sptr
= nid
->name
.s_name
->str
.wstr
;
1795 for(i
= 0; *sptr
&& i
< MAXNAMELEN
; i
++)
1797 if((unsigned)*sptr
< 0x80 && isprint(*sptr
& 0xff))
1800 warning("Resourcename (str_unicode) contain unprintable characters or invalid translation, ignored\n");
1804 else if(nid
->type
== name_str
&& nid
->name
.s_name
->type
== str_char
)
1808 cptr
= nid
->name
.s_name
->str
.cstr
;
1810 for(i
= 0; *cptr
&& i
< MAXNAMELEN
; i
++)
1812 if((unsigned)*cptr
< 0x80 && isprint(*cptr
& 0xff))
1815 warning("Resourcename (str_char) contain unprintable characters, ignored\n");
1819 else if(nid
->type
== name_ord
)
1821 sprintf(buf
, "%u", nid
->name
.i_name
);
1825 internal_error(__FILE__
, __LINE__
, "Resource name_id with invalid type %d\n", nid
->type
);
1832 *****************************************************************************
1833 * Function : make_c_name
1834 * Syntax : char *make_c_name(const char *base, const name_id_t *nid, const language_t *lan)
1837 * Description : Converts a resource name into a valid c-identifier in the
1840 *****************************************************************************
1842 char *make_c_name(const char *base
, const name_id_t
*nid
, const language_t
*lan
)
1849 sprintf(lanbuf
, "%d", lan
? MAKELANGID(lan
->id
, lan
->sub
) : 0);
1850 buf
= prep_nid_for_label(nid
);
1851 nlen
= strlen(buf
) + strlen(lanbuf
);
1852 nlen
+= strlen(base
) + 4; /* three time '_' and '\0' */
1853 ret
= xmalloc(nlen
);
1859 strcat(ret
, lanbuf
);
1864 *****************************************************************************
1865 * Function : get_c_typename
1866 * Syntax : const char *get_c_typename(enum res_e type)
1869 * Description : Convert resource enum to char string to be used in c-name
1872 *****************************************************************************
1874 const char *get_c_typename(enum res_e type
)
1878 case res_acc
: return "Acc";
1879 case res_anicur
:return "AniCur";
1880 case res_aniico
:return "AniIco";
1881 case res_bmp
: return "Bmp";
1882 case res_cur
: return "Cur";
1883 case res_curg
: return "CurGrp";
1885 case res_dlgex
: return "Dlg";
1886 case res_fnt
: return "Fnt";
1887 case res_fntdir
:return "FntDir";
1888 case res_ico
: return "Ico";
1889 case res_icog
: return "IcoGrp";
1891 case res_menex
: return "Men";
1892 case res_rdt
: return "RCDat";
1893 case res_stt
: return "StrTab";
1894 case res_usr
: return "Usr";
1895 case res_msg
: return "MsgTab";
1896 case res_ver
: return "VerInf";
1897 case res_toolbar
: return "TlBr";
1898 case res_dlginit
: return "DlgInit";
1899 default: return "Oops";
1904 *****************************************************************************
1905 * Function : resources2res
1906 * Syntax : void resources2res(resource_t *top)
1908 * top - The resource-tree to convert
1910 * Description : Convert logical resource descriptors into binary data
1912 *****************************************************************************
1914 void resources2res(resource_t
*top
)
1922 top
->binres
= accelerator2res(top
->name
, top
->res
.acc
);
1926 top
->binres
= bitmap2res(top
->name
, top
->res
.bmp
);
1930 top
->binres
= cursor2res(top
->res
.cur
);
1934 top
->binres
= cursorgroup2res(top
->name
, top
->res
.curg
);
1938 top
->binres
= dialog2res(top
->name
, top
->res
.dlg
);
1942 top
->binres
= dialogex2res(top
->name
, top
->res
.dlgex
);
1946 top
->binres
= font2res(top
->name
, top
->res
.fnt
);
1950 top
->binres
= fontdir2res(top
->name
, top
->res
.fnd
);
1954 top
->binres
= icon2res(top
->res
.ico
);
1958 top
->binres
= icongroup2res(top
->name
, top
->res
.icog
);
1962 top
->binres
= menu2res(top
->name
, top
->res
.men
);
1966 top
->binres
= menuex2res(top
->name
, top
->res
.menex
);
1970 top
->binres
= html2res(top
->name
, top
->res
.html
);
1974 top
->binres
= rcdata2res(top
->name
, top
->res
.rdt
);
1978 top
->binres
= stringtable2res(top
->res
.stt
);
1982 top
->binres
= user2res(top
->name
, top
->res
.usr
);
1986 top
->binres
= messagetable2res(top
->name
, top
->res
.msg
);
1990 top
->binres
= versioninfo2res(top
->name
, top
->res
.ver
);
1994 top
->binres
= toolbar2res(top
->name
, top
->res
.tbt
);
1998 top
->binres
= dlginit2res(top
->name
, top
->res
.dlgi
);
2003 top
->binres
= anicurico2res(top
->name
, top
->res
.ani
, top
->type
);
2006 internal_error(__FILE__
, __LINE__
, "Unknown resource type encountered %d in binary res generation\n", top
->type
);
2008 top
->c_name
= make_c_name(get_c_typename(top
->type
), top
->name
, top
->lan
);