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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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
= (res_t
*)xmalloc(sizeof(res_t
));
52 r
->allocsize
= RES_BLOCKSIZE
;
54 r
->data
= (char *)xmalloc(RES_BLOCKSIZE
);
58 res_t
*grow_res(res_t
*r
, unsigned int add
)
61 r
->data
= (char *)xrealloc(r
->data
, r
->allocsize
);
66 *****************************************************************************
70 * Syntax : void put_byte(res_t *res, unsigned c)
71 * void put_word(res_t *res, unsigned w)
72 * void put_dword(res_t *res, unsigned d)
74 * res - Binary resource to put the data in
75 * c, w, d - Data to put
77 * Description : Put primitives that put an item in the binary resource.
78 * The data array grows automatically.
80 *****************************************************************************
82 void put_byte(res_t
*res
, unsigned c
)
84 if(res
->allocsize
- res
->size
< sizeof(char))
85 grow_res(res
, RES_BLOCKSIZE
);
86 res
->data
[res
->size
] = (char)c
;
87 res
->size
+= sizeof(char);
90 void put_word(res_t
*res
, unsigned w
)
92 if(res
->allocsize
- res
->size
< sizeof(WORD
))
93 grow_res(res
, RES_BLOCKSIZE
);
96 #ifdef WORDS_BIGENDIAN
100 res
->data
[res
->size
+0] = HIBYTE(w
);
101 res
->data
[res
->size
+1] = LOBYTE(w
);
104 #ifndef WORDS_BIGENDIAN
108 res
->data
[res
->size
+1] = HIBYTE(w
);
109 res
->data
[res
->size
+0] = LOBYTE(w
);
112 res
->size
+= sizeof(WORD
);
115 void put_dword(res_t
*res
, unsigned d
)
117 if(res
->allocsize
- res
->size
< sizeof(DWORD
))
118 grow_res(res
, RES_BLOCKSIZE
);
121 #ifdef WORDS_BIGENDIAN
125 res
->data
[res
->size
+0] = HIBYTE(HIWORD(d
));
126 res
->data
[res
->size
+1] = LOBYTE(HIWORD(d
));
127 res
->data
[res
->size
+2] = HIBYTE(LOWORD(d
));
128 res
->data
[res
->size
+3] = LOBYTE(LOWORD(d
));
131 #ifndef WORDS_BIGENDIAN
135 res
->data
[res
->size
+3] = HIBYTE(HIWORD(d
));
136 res
->data
[res
->size
+2] = LOBYTE(HIWORD(d
));
137 res
->data
[res
->size
+1] = HIBYTE(LOWORD(d
));
138 res
->data
[res
->size
+0] = LOBYTE(LOWORD(d
));
141 res
->size
+= sizeof(DWORD
);
144 static void put_pad(res_t
*res
)
146 while(res
->size
& 0x3)
151 *****************************************************************************
152 * Function : set_word
154 * Syntax : void set_word(res_t *res, int ofs, unsigned w)
155 * void set_dword(res_t *res, int ofs, unsigned d)
157 * res - Binary resource to put the data in
158 * ofs - Byte offset in data-array
161 * Description : Set the value of a binary resource data array to a
164 *****************************************************************************
166 static void set_word(res_t
*res
, int ofs
, unsigned w
)
170 #ifdef WORDS_BIGENDIAN
174 res
->data
[ofs
+0] = HIBYTE(w
);
175 res
->data
[ofs
+1] = LOBYTE(w
);
178 #ifndef WORDS_BIGENDIAN
182 res
->data
[ofs
+1] = HIBYTE(w
);
183 res
->data
[ofs
+0] = LOBYTE(w
);
188 static void set_dword(res_t
*res
, int ofs
, unsigned d
)
192 #ifdef WORDS_BIGENDIAN
196 res
->data
[ofs
+0] = HIBYTE(HIWORD(d
));
197 res
->data
[ofs
+1] = LOBYTE(HIWORD(d
));
198 res
->data
[ofs
+2] = HIBYTE(LOWORD(d
));
199 res
->data
[ofs
+3] = LOBYTE(LOWORD(d
));
202 #ifndef WORDS_BIGENDIAN
206 res
->data
[ofs
+3] = HIBYTE(HIWORD(d
));
207 res
->data
[ofs
+2] = LOBYTE(HIWORD(d
));
208 res
->data
[ofs
+1] = HIBYTE(LOWORD(d
));
209 res
->data
[ofs
+0] = LOBYTE(LOWORD(d
));
215 *****************************************************************************
216 * Function : get_dword
218 * res - Binary resource to put the data in
219 * ofs - Byte offset in data-array
220 * Output : The data in native endian
221 * Description : Get the value of a binary resource data array in native
224 *****************************************************************************
226 static DWORD
get_dword(res_t
*res
, int ofs
)
230 #ifdef WORDS_BIGENDIAN
234 return (res
->data
[ofs
+0] << 24)
235 | (res
->data
[ofs
+1] << 16)
236 | (res
->data
[ofs
+2] << 8)
239 #ifndef WORDS_BIGENDIAN
243 return (res
->data
[ofs
+3] << 24)
244 | (res
->data
[ofs
+2] << 16)
245 | (res
->data
[ofs
+1] << 8)
251 *****************************************************************************
252 * Function : string_to_upper
253 * Syntax : void string_to_upper(string_t *str)
257 * Remarks : FIXME: codepages...
258 *****************************************************************************
260 static void string_to_upper(string_t
*str
)
264 if(str
->type
== str_char
)
266 for (i
= 0; i
< str
->size
; i
++) str
->str
.cstr
[i
] = toupper((unsigned char)str
->str
.cstr
[i
]);
268 else if(str
->type
== str_unicode
)
270 for (i
= 0; i
< str
->size
; i
++) str
->str
.wstr
[i
] = toupperW(str
->str
.wstr
[i
]);
274 internal_error(__FILE__
, __LINE__
, "Invalid string type %d", str
->type
);
279 *****************************************************************************
280 * Function : put_string
281 * Syntax : void put_string(res_t *res, string_t *str, enum str_e type,
282 * int isterm, const language_t *lang)
284 * res - Binary resource to put the data in
285 * str - String to put
286 * type - Data has to be written in either str_char or str_unicode
287 * isterm - The string is '\0' terminated (disregard the string's
292 *****************************************************************************
294 static void put_string(res_t
*res
, const string_t
*str
, enum str_e type
, int isterm
,
295 const language_t
*lang
)
303 if (lang
) codepage
= get_language_codepage( lang
->id
, lang
->sub
);
304 else codepage
= get_language_codepage( 0, 0 );
306 assert( codepage
!= -1 );
308 newstr
= convert_string(str
, type
, codepage
);
309 if (type
== str_unicode
)
311 if (str
->type
== str_char
)
313 if (!check_unicode_conversion( str
, newstr
, codepage
))
314 error( "String %s does not convert identically to Unicode and back in codepage %d. "
315 "Try using a Unicode string instead.", str
->str
.cstr
, codepage
);
317 if (!isterm
) put_word(res
, newstr
->size
);
318 for(cnt
= 0; cnt
< newstr
->size
; cnt
++)
320 WCHAR c
= newstr
->str
.wstr
[cnt
];
321 if (isterm
&& !c
) break;
324 if (isterm
) put_word(res
, 0);
328 if (!isterm
) put_byte(res
, newstr
->size
);
329 for(cnt
= 0; cnt
< newstr
->size
; cnt
++)
331 char c
= newstr
->str
.cstr
[cnt
];
332 if (isterm
&& !c
) break;
335 if (isterm
) put_byte(res
, 0);
341 *****************************************************************************
342 * Function : put_name_id
343 * Syntax : void put_name_id(res_t *res, name_id_t *nid, int upcase, const language_t *lang)
348 *****************************************************************************
350 static void put_name_id(res_t
*res
, name_id_t
*nid
, int upcase
, const language_t
*lang
)
352 if(nid
->type
== name_ord
)
355 put_word(res
, 0xffff);
358 put_word(res
, (WORD
)nid
->name
.i_name
);
360 else if(nid
->type
== name_str
)
363 string_to_upper(nid
->name
.s_name
);
364 put_string(res
, nid
->name
.s_name
, win32
? str_unicode
: str_char
, TRUE
, lang
);
368 internal_error(__FILE__
, __LINE__
, "Invalid name_id type %d", nid
->type
);
373 *****************************************************************************
375 * Syntax : void put_lvc(res_t *res, lvc_t *lvc)
380 *****************************************************************************
382 static void put_lvc(res_t
*res
, lvc_t
*lvc
)
384 if(lvc
&& lvc
->language
)
385 put_word(res
, MAKELANGID(lvc
->language
->id
, lvc
->language
->sub
));
387 put_word(res
, 0); /* Neutral */
388 if(lvc
&& lvc
->version
)
389 put_dword(res
, *(lvc
->version
));
392 if(lvc
&& lvc
->characts
)
393 put_dword(res
, *(lvc
->characts
));
399 *****************************************************************************
400 * Function : put_raw_data
401 * Syntax : void put_raw_data(res_t *res, raw_data_t *raw, int offset)
406 *****************************************************************************
408 static void put_raw_data(res_t
*res
, raw_data_t
*raw
, int offset
)
410 unsigned int wsize
= raw
->size
- offset
;
411 if(res
->allocsize
- res
->size
< wsize
)
412 grow_res(res
, wsize
);
413 memcpy(&(res
->data
[res
->size
]), raw
->data
+ offset
, wsize
);
418 *****************************************************************************
419 * Function : put_res_header
420 * Syntax : intput_res_header(res_t *res, int type, name_id_t *ntype,
421 * name_id_t *name, DWORD memopt, lvc_t *lvc)
424 * res - Binary resource descriptor to write to
425 * type - Resource identifier (if ntype == NULL)
426 * ntype - Name id of type
427 * name - Resource's name
428 * memopt - Resource's memory options to write
429 * lvc - Language, version and characteristics (win32 only)
430 * Output : An index to the resource size field. The resource size field
431 * contains the header size upon exit.
434 *****************************************************************************
436 static int put_res_header(res_t
*res
, int type
, name_id_t
*ntype
, name_id_t
*name
,
437 DWORD memopt
, lvc_t
*lvc
)
441 put_dword(res
, 0); /* We will overwrite these later */
445 put_word(res
, 0xffff); /* ResType */
449 put_name_id(res
, ntype
, TRUE
, lvc
->language
);
450 put_name_id(res
, name
, TRUE
, lvc
->language
); /* ResName */
452 put_dword(res
, 0); /* DataVersion */
453 put_word(res
, memopt
); /* Memory options */
454 put_lvc(res
, lvc
); /* Language, version and characts */
455 set_dword(res
, 0*sizeof(DWORD
), res
->size
); /* Set preliminary resource */
456 set_dword(res
, 1*sizeof(DWORD
), res
->size
); /* Set HeaderSize */
457 res
->dataidx
= res
->size
;
465 put_byte(res
, 0xff); /* ResType */
469 put_name_id(res
, ntype
, TRUE
, NULL
);
470 put_name_id(res
, name
, TRUE
, NULL
); /* ResName */
471 put_word(res
, memopt
); /* Memory options */
473 put_dword(res
, 0); /* ResSize overwritten later*/
474 set_dword(res
, tag
, res
->size
);
475 res
->dataidx
= res
->size
;
481 *****************************************************************************
482 * Function : accelerator2res
483 * Syntax : res_t *accelerator2res(name_id_t *name, accelerator_t *acc)
485 * name - Name/ordinal of the resource
486 * acc - The accelerator descriptor
487 * Output : New .res format structure
490 *****************************************************************************
492 static res_t
*accelerator2res(name_id_t
*name
, accelerator_t
*acc
)
497 assert(name
!= NULL
);
504 restag
= put_res_header(res
, WRC_RT_ACCELERATOR
, NULL
, name
, acc
->memopt
, &(acc
->lvc
));
507 put_word(res
, ev
->flags
| (ev
->next
? 0 : 0x80));
508 put_word(res
, ev
->key
);
509 put_word(res
, ev
->id
);
510 put_word(res
, 0); /* Padding */
517 restag
= put_res_header(res
, WRC_RT_ACCELERATOR
, NULL
, name
, acc
->memopt
, NULL
);
520 put_byte(res
, ev
->flags
| (ev
->next
? 0 : 0x80));
521 put_word(res
, ev
->key
);
522 put_word(res
, ev
->id
);
526 /* Set ResourceSize */
527 SetResSize(res
, restag
);
532 *****************************************************************************
533 * Function : dialog2res
534 * Syntax : res_t *dialog2res(name_id_t *name, dialog_t *dlg)
536 * name - Name/ordinal of the resource
537 * dlg - The dialog descriptor
538 * Output : New .res format structure
541 *****************************************************************************
543 static res_t
*dialog2res(name_id_t
*name
, dialog_t
*dlg
)
550 assert(name
!= NULL
);
553 ctrl
= dlg
->controls
;
557 restag
= put_res_header(res
, WRC_RT_DIALOG
, NULL
, name
, dlg
->memopt
, &(dlg
->lvc
));
559 put_dword(res
, dlg
->style
->or_mask
);
560 put_dword(res
, dlg
->gotexstyle
? dlg
->exstyle
->or_mask
: 0);
561 tag_nctrl
= res
->size
;
562 put_word(res
, 0); /* Number of controls */
563 put_word(res
, dlg
->x
);
564 put_word(res
, dlg
->y
);
565 put_word(res
, dlg
->width
);
566 put_word(res
, dlg
->height
);
568 put_name_id(res
, dlg
->menu
, TRUE
, dlg
->lvc
.language
);
572 put_name_id(res
, dlg
->dlgclass
, TRUE
, dlg
->lvc
.language
);
576 put_string(res
, dlg
->title
, str_unicode
, TRUE
, dlg
->lvc
.language
);
581 put_word(res
, dlg
->font
->size
);
582 put_string(res
, dlg
->font
->name
, str_unicode
, TRUE
, dlg
->lvc
.language
);
588 /* FIXME: what is default control style? */
589 put_dword(res
, ctrl
->gotstyle
? ctrl
->style
->or_mask
: WS_CHILD
);
590 put_dword(res
, ctrl
->gotexstyle
? ctrl
->exstyle
->or_mask
: 0);
591 put_word(res
, ctrl
->x
);
592 put_word(res
, ctrl
->y
);
593 put_word(res
, ctrl
->width
);
594 put_word(res
, ctrl
->height
);
595 put_word(res
, ctrl
->id
);
597 put_name_id(res
, ctrl
->ctlclass
, TRUE
, dlg
->lvc
.language
);
599 internal_error(__FILE__
, __LINE__
, "Control has no control-class");
601 put_name_id(res
, ctrl
->title
, FALSE
, dlg
->lvc
.language
);
606 put_word(res
, ctrl
->extra
->size
+2);
608 put_raw_data(res
, ctrl
->extra
, 0);
618 /* Set number of controls */
619 set_word(res
, tag_nctrl
, (WORD
)nctrl
);
623 restag
= put_res_header(res
, WRC_RT_DIALOG
, NULL
, name
, dlg
->memopt
, NULL
);
625 put_dword(res
, dlg
->gotstyle
? dlg
->style
->or_mask
: WS_POPUPWINDOW
);
626 tag_nctrl
= res
->size
;
627 put_byte(res
, 0); /* Number of controls */
628 put_word(res
, dlg
->x
);
629 put_word(res
, dlg
->y
);
630 put_word(res
, dlg
->width
);
631 put_word(res
, dlg
->height
);
633 put_name_id(res
, dlg
->menu
, TRUE
, NULL
);
637 put_name_id(res
, dlg
->dlgclass
, TRUE
, NULL
);
641 put_string(res
, dlg
->title
, str_char
, TRUE
, NULL
);
646 put_word(res
, dlg
->font
->size
);
647 put_string(res
, dlg
->font
->name
, str_char
, TRUE
, NULL
);
652 put_word(res
, ctrl
->x
);
653 put_word(res
, ctrl
->y
);
654 put_word(res
, ctrl
->width
);
655 put_word(res
, ctrl
->height
);
656 put_word(res
, ctrl
->id
);
657 put_dword(res
, ctrl
->gotstyle
? ctrl
->style
->or_mask
: WS_CHILD
);
660 if(ctrl
->ctlclass
->type
== name_ord
661 && ctrl
->ctlclass
->name
.i_name
>= 0x80
662 && ctrl
->ctlclass
->name
.i_name
<= 0x85)
663 put_byte(res
, ctrl
->ctlclass
->name
.i_name
);
664 else if(ctrl
->ctlclass
->type
== name_str
)
665 put_name_id(res
, ctrl
->ctlclass
, FALSE
, NULL
);
667 error("Unknown control-class %04x", ctrl
->ctlclass
->name
.i_name
);
670 internal_error(__FILE__
, __LINE__
, "Control has no control-class");
672 put_name_id(res
, ctrl
->title
, FALSE
, NULL
);
676 /* FIXME: What is this extra byte doing here? */
682 /* Set number of controls */
683 ((char *)res
->data
)[tag_nctrl
] = (char)nctrl
;
685 /* Set ResourceSize */
686 SetResSize(res
, restag
);
691 *****************************************************************************
692 * Function : dialogex2res
693 * Syntax : res_t *dialogex2res(name_id_t *name, dialogex_t *dlgex)
695 * name - Name/ordinal of the resource
696 * dlgex - The dialogex descriptor
697 * Output : New .res format structure
700 *****************************************************************************
702 static res_t
*dialogex2res(name_id_t
*name
, dialogex_t
*dlgex
)
709 assert(name
!= NULL
);
710 assert(dlgex
!= NULL
);
712 ctrl
= dlgex
->controls
;
716 restag
= put_res_header(res
, WRC_RT_DIALOG
, NULL
, name
, dlgex
->memopt
, &(dlgex
->lvc
));
718 /* FIXME: MS doc says thet the first word must contain 0xffff
719 * and the second 0x0001 to signal a DLGTEMPLATEEX. Borland's
720 * compiler reverses the two words.
721 * I don't know which one to choose, but I write it as Mr. B
724 put_word(res
, 1); /* Signature */
725 put_word(res
, 0xffff); /* DlgVer */
726 put_dword(res
, dlgex
->gothelpid
? dlgex
->helpid
: 0);
727 put_dword(res
, dlgex
->gotexstyle
? dlgex
->exstyle
->or_mask
: 0);
728 put_dword(res
, dlgex
->gotstyle
? dlgex
->style
->or_mask
: WS_POPUPWINDOW
);
729 tag_nctrl
= res
->size
;
730 put_word(res
, 0); /* Number of controls */
731 put_word(res
, dlgex
->x
);
732 put_word(res
, dlgex
->y
);
733 put_word(res
, dlgex
->width
);
734 put_word(res
, dlgex
->height
);
736 put_name_id(res
, dlgex
->menu
, TRUE
, dlgex
->lvc
.language
);
740 put_name_id(res
, dlgex
->dlgclass
, TRUE
, dlgex
->lvc
.language
);
744 put_string(res
, dlgex
->title
, str_unicode
, TRUE
, dlgex
->lvc
.language
);
749 put_word(res
, dlgex
->font
->size
);
750 put_word(res
, dlgex
->font
->weight
);
751 /* FIXME: ? TRUE should be sufficient to say that its
752 * italic, but Borland's compiler says its 0x0101.
753 * I just copy it here, and hope for the best.
755 put_word(res
, dlgex
->font
->italic
? 0x0101 : 0);
756 put_string(res
, dlgex
->font
->name
, str_unicode
, TRUE
, dlgex
->lvc
.language
);
762 put_dword(res
, ctrl
->gothelpid
? ctrl
->helpid
: 0);
763 put_dword(res
, ctrl
->gotexstyle
? ctrl
->exstyle
->or_mask
: 0);
764 /* FIXME: what is default control style? */
765 put_dword(res
, ctrl
->gotstyle
? ctrl
->style
->or_mask
: WS_CHILD
| WS_VISIBLE
);
766 put_word(res
, ctrl
->x
);
767 put_word(res
, ctrl
->y
);
768 put_word(res
, ctrl
->width
);
769 put_word(res
, ctrl
->height
);
770 put_dword(res
, ctrl
->id
);
772 put_name_id(res
, ctrl
->ctlclass
, TRUE
, dlgex
->lvc
.language
);
774 internal_error(__FILE__
, __LINE__
, "Control has no control-class");
776 put_name_id(res
, ctrl
->title
, FALSE
, dlgex
->lvc
.language
);
782 put_word(res
, ctrl
->extra
->size
);
783 put_raw_data(res
, ctrl
->extra
, 0);
792 /* Set number of controls */
793 set_word(res
, tag_nctrl
, (WORD
)nctrl
);
794 /* Set ResourceSize */
795 SetResSize(res
, restag
);
800 /* Do not generate anything in 16-bit mode */
809 *****************************************************************************
810 * Function : menuitem2res
811 * Syntax : void menuitem2res(res_t *res, menu_item_t *item)
815 * Remarks : Self recursive
816 *****************************************************************************
818 static void menuitem2res(res_t
*res
, menu_item_t
*menitem
, const language_t
*lang
)
820 menu_item_t
*itm
= menitem
;
825 put_word(res
, itm
->state
| (itm
->popup
? MF_POPUP
: 0) | (!itm
->next
? MF_END
: 0));
827 put_word(res
, itm
->id
);
829 put_string(res
, itm
->name
, str_unicode
, TRUE
, lang
);
833 menuitem2res(res
, itm
->popup
, lang
);
841 put_word(res
, itm
->state
| (itm
->popup
? MF_POPUP
: 0) | (!itm
->next
? MF_END
: 0));
843 put_word(res
, itm
->id
);
845 put_string(res
, itm
->name
, str_char
, TRUE
, lang
);
849 menuitem2res(res
, itm
->popup
, lang
);
857 *****************************************************************************
858 * Function : menu2res
859 * Syntax : res_t *menu2res(name_id_t *name, menu_t *men)
861 * name - Name/ordinal of the resource
862 * men - The menu descriptor
863 * Output : New .res format structure
866 *****************************************************************************
868 static res_t
*menu2res(name_id_t
*name
, menu_t
*men
)
872 assert(name
!= NULL
);
876 restag
= put_res_header(res
, WRC_RT_MENU
, NULL
, name
, men
->memopt
, win32
? &(men
->lvc
) : NULL
);
878 put_dword(res
, 0); /* Menuheader: Version and HeaderSize */
879 menuitem2res(res
, men
->items
, win32
? men
->lvc
.language
: NULL
);
880 /* Set ResourceSize */
881 SetResSize(res
, restag
);
888 *****************************************************************************
889 * Function : menuexitem2res
890 * Syntax : void menuexitem2res(res_t *res, menuex_item_t *item)
894 * Remarks : Self recursive
895 *****************************************************************************
897 static void menuexitem2res(res_t
*res
, menuex_item_t
*menitem
, const language_t
*lang
)
899 menuex_item_t
*itm
= menitem
;
903 put_dword(res
, itm
->gottype
? itm
->type
: 0);
904 put_dword(res
, itm
->gotstate
? itm
->state
: 0);
905 put_dword(res
, itm
->gotid
? itm
->id
: 0); /* FIXME: Docu. says word */
906 put_word(res
, (itm
->popup
? 0x01 : 0) | (!itm
->next
? MF_END
: 0));
908 put_string(res
, itm
->name
, str_unicode
, TRUE
, lang
);
914 put_dword(res
, itm
->gothelpid
? itm
->helpid
: 0);
915 menuexitem2res(res
, itm
->popup
, lang
);
923 *****************************************************************************
924 * Function : menuex2res
925 * Syntax : res_t *menuex2res(name_id_t *name, menuex_t *menex)
927 * name - Name/ordinal of the resource
928 * menex - The menuex descriptor
929 * Output : New .res format structure
932 *****************************************************************************
934 static res_t
*menuex2res(name_id_t
*name
, menuex_t
*menex
)
938 assert(name
!= NULL
);
939 assert(menex
!= NULL
);
944 restag
= put_res_header(res
, WRC_RT_MENU
, NULL
, name
, menex
->memopt
, &(menex
->lvc
));
946 put_word(res
, 1); /* Menuheader: Version */
947 put_word(res
, 4); /* Offset */
948 put_dword(res
, 0); /* HelpId */
950 menuexitem2res(res
, menex
->items
, menex
->lvc
.language
);
951 /* Set ResourceSize */
952 SetResSize(res
, restag
);
957 /* Do not generate anything in 16-bit mode */
966 *****************************************************************************
967 * Function : cursorgroup2res
968 * Syntax : res_t *cursorgroup2res(name_id_t *name, cursor_group_t *curg)
970 * name - Name/ordinal of the resource
971 * curg - The cursor descriptor
972 * Output : New .res format structure
975 *****************************************************************************
977 static res_t
*cursorgroup2res(name_id_t
*name
, cursor_group_t
*curg
)
982 assert(name
!= NULL
);
983 assert(curg
!= NULL
);
986 restag
= put_res_header(res
, WRC_RT_GROUP_CURSOR
, NULL
, name
, curg
->memopt
, &(curg
->lvc
));
989 put_word(res
, 0); /* Reserved */
990 /* FIXME: The ResType in the NEWHEADER structure should
991 * contain 14 according to the MS win32 doc. This is
992 * not the case with the BRC compiler and I really doubt
993 * the latter. Putting one here is compliant to win16 spec,
994 * but who knows the true value?
996 put_word(res
, 2); /* ResType */
997 put_word(res
, curg
->ncursor
);
999 for(cur
= curg
->cursorlist
; cur
; cur
= cur
->next
)
1001 cur
= curg
->cursorlist
;
1004 for(; cur
; cur
= cur
->prev
)
1007 put_word(res
, cur
->width
);
1008 /* FIXME: The height of a cursor is half the size of
1009 * the bitmap's height. BRC puts the height from the
1010 * BITMAPINFOHEADER here instead of the cursorfile's
1011 * height. MS doesn't seem to care...
1013 put_word(res
, cur
->height
);
1014 /* FIXME: The next two are reversed in BRC and I don't
1015 * know why. Probably a bug. But, we can safely ignore
1016 * it because win16 does not support color cursors.
1017 * A warning should have been generated by the parser.
1019 put_word(res
, cur
->planes
);
1020 put_word(res
, cur
->bits
);
1021 /* FIXME: The +4 is the hotspot in the cursor resource.
1022 * However, I cound not find this in the documentation.
1023 * The hotspot bytes must either be included or MS
1026 put_dword(res
, cur
->data
->size
+4);
1027 put_word(res
, cur
->id
);
1032 put_word(res
, 0); /* Reserved */
1033 put_word(res
, 2); /* ResType */
1034 put_word(res
, curg
->ncursor
);
1036 for(cur
= curg
->cursorlist
; cur
; cur
= cur
->next
)
1038 cur
= curg
->cursorlist
;
1041 for(; cur
; cur
= cur
->prev
)
1044 put_word(res
, cur
->width
);
1045 /* FIXME: The height of a cursor is half the size of
1046 * the bitmap's height. BRC puts the height from the
1047 * BITMAPINFOHEADER here instead of the cursorfile's
1048 * height. MS doesn't seem to care...
1050 put_word(res
, cur
->height
);
1051 /* FIXME: The next two are reversed in BRC and I don't
1052 * know why. Probably a bug. But, we can safely ignore
1053 * it because win16 does not support color cursors.
1054 * A warning should have been generated by the parser.
1056 put_word(res
, cur
->planes
);
1057 put_word(res
, cur
->bits
);
1058 /* FIXME: The +4 is the hotspot in the cursor resource.
1059 * However, I cound not find this in the documentation.
1060 * The hotspot bytes must either be included or MS
1063 put_dword(res
, cur
->data
->size
+4);
1064 put_word(res
, cur
->id
);
1067 SetResSize(res
, restag
); /* Set ResourceSize */
1075 *****************************************************************************
1076 * Function : cursor2res
1077 * Syntax : res_t *cursor2res(cursor_t *cur)
1079 * cur - The cursor descriptor
1080 * Output : New .res format structure
1083 *****************************************************************************
1085 static res_t
*cursor2res(cursor_t
*cur
)
1091 assert(cur
!= NULL
);
1094 name
.type
= name_ord
;
1095 name
.name
.i_name
= cur
->id
;
1096 restag
= put_res_header(res
, WRC_RT_CURSOR
, NULL
, &name
, WRC_MO_MOVEABLE
| WRC_MO_DISCARDABLE
, &(cur
->lvc
));
1097 put_word(res
, cur
->xhot
);
1098 put_word(res
, cur
->yhot
);
1099 put_raw_data(res
, cur
->data
, 0);
1101 SetResSize(res
, restag
); /* Set ResourceSize */
1109 *****************************************************************************
1110 * Function : icongroup2res
1111 * Syntax : res_t *icongroup2res(name_id_t *name, icon_group_t *icog)
1113 * name - Name/ordinal of the resource
1114 * icog - The icon group descriptor
1115 * Output : New .res format structure
1118 *****************************************************************************
1120 static res_t
*icongroup2res(name_id_t
*name
, icon_group_t
*icog
)
1125 assert(name
!= NULL
);
1126 assert(icog
!= NULL
);
1129 restag
= put_res_header(res
, WRC_RT_GROUP_ICON
, NULL
, name
, icog
->memopt
, &(icog
->lvc
));
1132 put_word(res
, 0); /* Reserved */
1133 /* FIXME: The ResType in the NEWHEADER structure should
1134 * contain 14 according to the MS win32 doc. This is
1135 * not the case with the BRC compiler and I really doubt
1136 * the latter. Putting one here is compliant to win16 spec,
1137 * but who knows the true value?
1139 put_word(res
, 1); /* ResType */
1140 put_word(res
, icog
->nicon
);
1141 for(ico
= icog
->iconlist
; ico
; ico
= ico
->next
)
1143 put_byte(res
, ico
->width
);
1144 put_byte(res
, ico
->height
);
1145 put_byte(res
, ico
->nclr
);
1146 put_byte(res
, 0); /* Reserved */
1147 put_word(res
, ico
->planes
);
1148 put_word(res
, ico
->bits
);
1149 put_dword(res
, ico
->data
->size
);
1150 put_word(res
, ico
->id
);
1155 put_word(res
, 0); /* Reserved */
1156 put_word(res
, 1); /* ResType */
1157 put_word(res
, icog
->nicon
);
1158 for(ico
= icog
->iconlist
; ico
; ico
= ico
->next
)
1160 put_byte(res
, ico
->width
);
1161 put_byte(res
, ico
->height
);
1162 put_byte(res
, ico
->nclr
);
1163 put_byte(res
, 0); /* Reserved */
1164 put_word(res
, ico
->planes
);
1165 put_word(res
, ico
->bits
);
1166 put_dword(res
, ico
->data
->size
);
1167 put_word(res
, ico
->id
);
1170 SetResSize(res
, restag
); /* Set ResourceSize */
1178 *****************************************************************************
1179 * Function : icon2res
1180 * Syntax : res_t *icon2res(icon_t *ico)
1182 * ico - The icon descriptor
1183 * Output : New .res format structure
1186 *****************************************************************************
1188 static res_t
*icon2res(icon_t
*ico
)
1194 assert(ico
!= NULL
);
1197 name
.type
= name_ord
;
1198 name
.name
.i_name
= ico
->id
;
1199 restag
= put_res_header(res
, WRC_RT_ICON
, NULL
, &name
, WRC_MO_MOVEABLE
| WRC_MO_DISCARDABLE
, &(ico
->lvc
));
1200 put_raw_data(res
, ico
->data
, 0);
1202 SetResSize(res
, restag
); /* Set ResourceSize */
1210 *****************************************************************************
1211 * Function : anicurico2res
1212 * Syntax : res_t *anicurico2res(name_id_t *name, ani_curico_t *ani)
1214 * name - Name/ordinal of the resource
1215 * ani - The animated object descriptor
1216 * Output : New .res format structure
1218 * Remarks : The endian of the object's structures have been converted
1220 * There are rumors that win311 could handle animated stuff.
1221 * That is why they are generated for both win16 and win32
1223 *****************************************************************************
1225 static res_t
*anicurico2res(name_id_t
*name
, ani_curico_t
*ani
, enum res_e type
)
1229 assert(name
!= NULL
);
1230 assert(ani
!= NULL
);
1233 restag
= put_res_header(res
, type
== res_anicur
? WRC_RT_ANICURSOR
: WRC_RT_ANIICON
,
1234 NULL
, name
, ani
->memopt
, NULL
);
1235 put_raw_data(res
, ani
->data
, 0);
1236 /* Set ResourceSize */
1237 SetResSize(res
, restag
);
1244 *****************************************************************************
1245 * Function : bitmap2res
1246 * Syntax : res_t *bitmap2res(name_id_t *name, bitmap_t *bmp)
1248 * name - Name/ordinal of the resource
1249 * bmp - The bitmap descriptor
1250 * Output : New .res format structure
1252 * Remarks : The endian of the bitmap structures have been converted
1254 *****************************************************************************
1256 static res_t
*bitmap2res(name_id_t
*name
, bitmap_t
*bmp
)
1260 assert(name
!= NULL
);
1261 assert(bmp
!= NULL
);
1264 restag
= put_res_header(res
, WRC_RT_BITMAP
, NULL
, name
, bmp
->memopt
, &(bmp
->data
->lvc
));
1265 if(bmp
->data
->data
[0] == 'B'
1266 && bmp
->data
->data
[1] == 'M'
1267 && ((BITMAPFILEHEADER
*)bmp
->data
->data
)->bfSize
== bmp
->data
->size
1268 && bmp
->data
->size
>= sizeof(BITMAPFILEHEADER
))
1270 /* The File header is still attached, don't write it */
1271 put_raw_data(res
, bmp
->data
, sizeof(BITMAPFILEHEADER
));
1275 put_raw_data(res
, bmp
->data
, 0);
1277 /* Set ResourceSize */
1278 SetResSize(res
, restag
);
1285 *****************************************************************************
1286 * Function : font2res
1287 * Syntax : res_t *font2res(name_id_t *name, font_t *fnt)
1289 * name - Name/ordinal of the resource
1290 * fnt - The font descriptor
1291 * Output : New .res format structure
1293 * Remarks : The data has been prepared just after parsing.
1294 *****************************************************************************
1296 static res_t
*font2res(name_id_t
*name
, font_t
*fnt
)
1300 assert(name
!= NULL
);
1301 assert(fnt
!= NULL
);
1304 restag
= put_res_header(res
, WRC_RT_FONT
, NULL
, name
, fnt
->memopt
, &(fnt
->data
->lvc
));
1305 put_raw_data(res
, fnt
->data
, 0);
1306 /* Set ResourceSize */
1307 SetResSize(res
, restag
);
1314 *****************************************************************************
1315 * Function : fontdir2res
1316 * Syntax : res_t *fontdir2res(name_id_t *name, fontdir_t *fnd)
1318 * name - Name/ordinal of the resource
1319 * fntdir - The fontdir descriptor
1320 * Output : New .res format structure
1322 * Remarks : The data has been prepared just after parsing.
1323 *****************************************************************************
1325 static res_t
*fontdir2res(name_id_t
*name
, fontdir_t
*fnd
)
1329 assert(name
!= NULL
);
1330 assert(fnd
!= NULL
);
1333 restag
= put_res_header(res
, WRC_RT_FONTDIR
, NULL
, name
, fnd
->memopt
, &(fnd
->data
->lvc
));
1334 put_raw_data(res
, fnd
->data
, 0);
1335 /* Set ResourceSize */
1336 SetResSize(res
, restag
);
1343 *****************************************************************************
1344 * Function : rcdata2res
1345 * Syntax : res_t *rcdata2res(name_id_t *name, rcdata_t *rdt)
1347 * name - Name/ordinal of the resource
1348 * rdt - The rcdata descriptor
1349 * Output : New .res format structure
1352 *****************************************************************************
1354 static res_t
*rcdata2res(name_id_t
*name
, rcdata_t
*rdt
)
1358 assert(name
!= NULL
);
1359 assert(rdt
!= NULL
);
1362 restag
= put_res_header(res
, WRC_RT_RCDATA
, NULL
, name
, rdt
->memopt
, &(rdt
->data
->lvc
));
1363 put_raw_data(res
, rdt
->data
, 0);
1364 /* Set ResourceSize */
1365 SetResSize(res
, restag
);
1372 *****************************************************************************
1373 * Function : messagetable2res
1374 * Syntax : res_t *messagetable2res(name_id_t *name, messagetable_t *msg)
1376 * name - Name/ordinal of the resource
1377 * msg - The messagetable descriptor
1378 * Output : New .res format structure
1380 * Remarks : The data has been converted to the appropriate endian
1381 * after is was parsed.
1382 *****************************************************************************
1384 static res_t
*messagetable2res(name_id_t
*name
, messagetable_t
*msg
)
1388 assert(name
!= NULL
);
1389 assert(msg
!= NULL
);
1392 restag
= put_res_header(res
, WRC_RT_MESSAGETABLE
, NULL
, name
, msg
->memopt
, &(msg
->data
->lvc
));
1393 put_raw_data(res
, msg
->data
, 0);
1394 /* Set ResourceSize */
1395 SetResSize(res
, restag
);
1402 *****************************************************************************
1403 * Function : stringtable2res
1404 * Syntax : res_t *stringtable2res(stringtable_t *stt)
1406 * stt - The stringtable descriptor
1407 * Output : New .res format structure
1410 *****************************************************************************
1412 static res_t
*stringtable2res(stringtable_t
*stt
)
1420 assert(stt
!= NULL
);
1423 for(; stt
; stt
= stt
->next
)
1427 warning("Empty internal stringtable");
1430 name
.type
= name_ord
;
1431 name
.name
.i_name
= (stt
->idbase
>> 4) + 1;
1432 restag
= put_res_header(res
, WRC_RT_STRING
, NULL
, &name
, stt
->memopt
, win32
? &(stt
->lvc
) : NULL
);
1433 for(i
= 0; i
< stt
->nentries
; i
++)
1435 if(stt
->entries
[i
].str
&& stt
->entries
[i
].str
->size
)
1437 put_string(res
, stt
->entries
[i
].str
, win32
? str_unicode
: str_char
,
1438 FALSE
, win32
? stt
->lvc
.language
: NULL
);
1448 /* Set ResourceSize */
1449 SetResSize(res
, restag
- lastsize
);
1452 lastsize
= res
->size
;
1458 *****************************************************************************
1459 * Function : user2res
1460 * Syntax : res_t *user2res(name_id_t *name, user_t *usr)
1462 * name - Name/ordinal of the resource
1463 * usr - The userresource descriptor
1464 * Output : New .res format structure
1467 *****************************************************************************
1469 static res_t
*user2res(name_id_t
*name
, user_t
*usr
)
1473 assert(name
!= NULL
);
1474 assert(usr
!= NULL
);
1477 restag
= put_res_header(res
, 0, usr
->type
, name
, usr
->memopt
, &(usr
->data
->lvc
));
1478 put_raw_data(res
, usr
->data
, 0);
1479 /* Set ResourceSize */
1480 SetResSize(res
, restag
);
1487 *****************************************************************************
1488 * Function : versionblock2res
1489 * Syntax : void versionblock2res(res_t *res, ver_block_t *blk)
1491 * res - Binary resource to write to
1492 * blk - The version block to be written
1495 * Remarks : Self recursive
1496 *****************************************************************************
1498 static void versionblock2res(res_t
*res
, ver_block_t
*blk
, int level
, const language_t
*lang
)
1507 blksizetag
= res
->size
;
1508 put_word(res
, 0); /* Will be overwritten later */
1511 put_word(res
, 0); /* level ? */
1512 put_string(res
, blk
->name
, win32
? str_unicode
: str_char
, TRUE
, lang
);
1514 for(val
= blk
->values
; val
; val
= val
->next
)
1516 if(val
->type
== val_str
)
1518 valblksizetag
= res
->size
;
1519 put_word(res
, 0); /* Will be overwritten later */
1520 valvalsizetag
= res
->size
;
1521 put_word(res
, 0); /* Will be overwritten later */
1524 put_word(res
, level
);
1526 put_string(res
, val
->key
, win32
? str_unicode
: str_char
, TRUE
, lang
);
1529 put_string(res
, val
->value
.str
, win32
? str_unicode
: str_char
, TRUE
, lang
);
1531 set_word(res
, valvalsizetag
, (WORD
)((res
->size
- tag
) >> 1));
1533 set_word(res
, valvalsizetag
, (WORD
)(res
->size
- tag
));
1534 set_word(res
, valblksizetag
, (WORD
)(res
->size
- valblksizetag
));
1537 else if(val
->type
== val_words
)
1539 valblksizetag
= res
->size
;
1540 put_word(res
, 0); /* Will be overwritten later */
1541 valvalsizetag
= res
->size
;
1542 put_word(res
, 0); /* Will be overwritten later */
1545 put_word(res
, level
);
1547 put_string(res
, val
->key
, win32
? str_unicode
: str_char
, TRUE
, lang
);
1550 for(i
= 0; i
< val
->value
.words
->nwords
; i
++)
1552 put_word(res
, val
->value
.words
->words
[i
]);
1554 set_word(res
, valvalsizetag
, (WORD
)(res
->size
- tag
));
1555 set_word(res
, valblksizetag
, (WORD
)(res
->size
- valblksizetag
));
1558 else if(val
->type
== val_block
)
1560 versionblock2res(res
, val
->value
.block
, level
+1, lang
);
1564 internal_error(__FILE__
, __LINE__
, "Invalid value indicator %d in VERSIONINFO", val
->type
);
1569 set_word(res
, blksizetag
, (WORD
)(res
->size
- blksizetag
));
1573 *****************************************************************************
1574 * Function : versioninfo2res
1575 * Syntax : res_t *versioninfo2res(name_id_t *name, versioninfo_t *ver)
1577 * name - Name/ordinal of the resource
1578 * ver - The versioninfo descriptor
1579 * Output : New .res format structure
1582 *****************************************************************************
1584 static res_t
*versioninfo2res(name_id_t
*name
, versioninfo_t
*ver
)
1587 int rootblocksizetag
;
1594 assert(name
!= NULL
);
1595 assert(ver
!= NULL
);
1597 vsvi
.type
= str_char
;
1598 vsvi
.str
.cstr
= xstrdup("VS_VERSION_INFO");
1599 vsvi
.size
= 15; /* Excl. termination */
1602 restag
= put_res_header(res
, WRC_RT_VERSION
, NULL
, name
, ver
->memopt
, &(ver
->lvc
));
1603 rootblocksizetag
= res
->size
;
1604 put_word(res
, 0); /* BlockSize filled in later */
1605 valsizetag
= res
->size
;
1606 put_word(res
, 0); /* ValueSize filled in later*/
1608 put_word(res
, 0); /* Tree-level ? */
1609 put_string(res
, &vsvi
, win32
? str_unicode
: str_char
,
1610 TRUE
, win32
? ver
->lvc
.language
: NULL
);
1614 put_dword(res
, VS_FFI_SIGNATURE
);
1615 put_dword(res
, VS_FFI_STRUCVERSION
);
1616 put_dword(res
, (ver
->filever_maj1
<< 16) + (ver
->filever_maj2
& 0xffff));
1617 put_dword(res
, (ver
->filever_min1
<< 16) + (ver
->filever_min2
& 0xffff));
1618 put_dword(res
, (ver
->prodver_maj1
<< 16) + (ver
->prodver_maj2
& 0xffff));
1619 put_dword(res
, (ver
->prodver_min1
<< 16) + (ver
->prodver_min2
& 0xffff));
1620 put_dword(res
, ver
->fileflagsmask
);
1621 put_dword(res
, ver
->fileflags
);
1622 put_dword(res
, ver
->fileos
);
1623 put_dword(res
, ver
->filetype
);
1624 put_dword(res
, ver
->filesubtype
);
1625 put_dword(res
, 0); /* FileDateMS */
1626 put_dword(res
, 0); /* FileDateLS */
1628 set_word(res
, valsizetag
, (WORD
)(res
->size
- tag
));
1629 /* Descend into the blocks */
1630 for(blk
= ver
->blocks
; blk
; blk
= blk
->next
)
1631 versionblock2res(res
, blk
, 0, win32
? ver
->lvc
.language
: NULL
);
1632 /* Set root block's size */
1633 set_word(res
, rootblocksizetag
, (WORD
)(res
->size
- rootblocksizetag
));
1635 SetResSize(res
, restag
);
1639 free(vsvi
.str
.cstr
);
1644 *****************************************************************************
1645 * Function : toolbaritem2res
1646 * Syntax : void toolbaritem2res(res_t *res, toolbar_item_t *tbitem)
1650 * Remarks : Self recursive
1651 *****************************************************************************
1653 static void toolbaritem2res(res_t
*res
, toolbar_item_t
*tbitem
)
1655 toolbar_item_t
*itm
= tbitem
;
1659 put_word(res
, itm
->id
);
1666 *****************************************************************************
1667 * Function : toolbar2res
1668 * Syntax : res_t *toolbar2res(name_id_t *name, toolbar_t *toolbar)
1670 * name - Name/ordinal of the resource
1671 * toolbar - The toolbar descriptor
1672 * Output : New .res format structure
1675 *****************************************************************************
1677 static res_t
*toolbar2res(name_id_t
*name
, toolbar_t
*toolbar
)
1681 assert(name
!= NULL
);
1682 assert(toolbar
!= NULL
);
1687 restag
= put_res_header(res
, WRC_RT_TOOLBAR
, NULL
, name
, toolbar
->memopt
, &(toolbar
->lvc
));
1689 put_word(res
, 1); /* Menuheader: Version */
1690 put_word(res
, toolbar
->button_width
); /* (in pixels?) */
1691 put_word(res
, toolbar
->button_height
); /* (in pixels?) */
1692 put_word(res
, toolbar
->nitems
);
1694 toolbaritem2res(res
, toolbar
->items
);
1695 /* Set ResourceSize */
1696 SetResSize(res
, restag
);
1701 /* Do not generate anything in 16-bit mode */
1710 *****************************************************************************
1711 * Function : dlginit2res
1712 * Syntax : res_t *dlginit2res(name_id_t *name, dlginit_t *dit)
1714 * name - Name/ordinal of the resource
1715 * rdt - The dlginit descriptor
1716 * Output : New .res format structure
1719 *****************************************************************************
1721 static res_t
*dlginit2res(name_id_t
*name
, dlginit_t
*dit
)
1725 assert(name
!= NULL
);
1726 assert(dit
!= NULL
);
1729 restag
= put_res_header(res
, WRC_RT_DLGINIT
, NULL
, name
, dit
->memopt
, &(dit
->data
->lvc
));
1730 put_raw_data(res
, dit
->data
, 0);
1731 /* Set ResourceSize */
1732 SetResSize(res
, restag
);
1739 *****************************************************************************
1740 * Function : prep_nid_for_label
1741 * Syntax : char *prep_nid_for_label(const name_id_t *nid)
1744 * Description : Converts a resource name into the first 32 (or less)
1745 * characters of the name with conversions.
1747 *****************************************************************************
1749 #define MAXNAMELEN 32
1750 char *prep_nid_for_label(const name_id_t
*nid
)
1752 static char buf
[MAXNAMELEN
+1];
1754 assert(nid
!= NULL
);
1756 if(nid
->type
== name_str
&& nid
->name
.s_name
->type
== str_unicode
)
1760 sptr
= nid
->name
.s_name
->str
.wstr
;
1762 for(i
= 0; *sptr
&& i
< MAXNAMELEN
; i
++)
1764 if((unsigned)*sptr
< 0x80 && isprint(*sptr
& 0xff))
1767 warning("Resourcename (str_unicode) contain unprintable characters or invalid translation, ignored");
1771 else if(nid
->type
== name_str
&& nid
->name
.s_name
->type
== str_char
)
1775 cptr
= nid
->name
.s_name
->str
.cstr
;
1777 for(i
= 0; *cptr
&& i
< MAXNAMELEN
; i
++)
1779 if((unsigned)*cptr
< 0x80 && isprint(*cptr
& 0xff))
1782 warning("Resourcename (str_char) contain unprintable characters, ignored");
1786 else if(nid
->type
== name_ord
)
1788 sprintf(buf
, "%u", nid
->name
.i_name
);
1792 internal_error(__FILE__
, __LINE__
, "Resource name_id with invalid type %d", nid
->type
);
1799 *****************************************************************************
1800 * Function : make_c_name
1801 * Syntax : char *make_c_name(const char *base, const name_id_t *nid, const language_t *lan)
1804 * Description : Converts a resource name into a valid c-identifier in the
1807 *****************************************************************************
1809 char *make_c_name(const char *base
, const name_id_t
*nid
, const language_t
*lan
)
1816 sprintf(lanbuf
, "%d", lan
? MAKELANGID(lan
->id
, lan
->sub
) : 0);
1817 buf
= prep_nid_for_label(nid
);
1818 nlen
= strlen(buf
) + strlen(lanbuf
);
1819 nlen
+= strlen(base
) + 4; /* three time '_' and '\0' */
1820 ret
= (char *)xmalloc(nlen
);
1826 strcat(ret
, lanbuf
);
1831 *****************************************************************************
1832 * Function : get_c_typename
1833 * Syntax : const char *get_c_typename(enum res_e type)
1836 * Description : Convert resource enum to char string to be used in c-name
1839 *****************************************************************************
1841 const char *get_c_typename(enum res_e type
)
1845 case res_acc
: return "Acc";
1846 case res_anicur
:return "AniCur";
1847 case res_aniico
:return "AniIco";
1848 case res_bmp
: return "Bmp";
1849 case res_cur
: return "Cur";
1850 case res_curg
: return "CurGrp";
1852 case res_dlgex
: return "Dlg";
1853 case res_fnt
: return "Fnt";
1854 case res_fntdir
:return "FntDir";
1855 case res_ico
: return "Ico";
1856 case res_icog
: return "IcoGrp";
1858 case res_menex
: return "Men";
1859 case res_rdt
: return "RCDat";
1860 case res_stt
: return "StrTab";
1861 case res_usr
: return "Usr";
1862 case res_msg
: return "MsgTab";
1863 case res_ver
: return "VerInf";
1864 case res_toolbar
: return "TlBr";
1865 case res_dlginit
: return "DlgInit";
1866 default: return "Oops";
1871 *****************************************************************************
1872 * Function : resources2res
1873 * Syntax : void resources2res(resource_t *top)
1875 * top - The resource-tree to convert
1877 * Description : Convert logical resource descriptors into binary data
1879 *****************************************************************************
1881 void resources2res(resource_t
*top
)
1889 top
->binres
= accelerator2res(top
->name
, top
->res
.acc
);
1893 top
->binres
= bitmap2res(top
->name
, top
->res
.bmp
);
1897 top
->binres
= cursor2res(top
->res
.cur
);
1901 top
->binres
= cursorgroup2res(top
->name
, top
->res
.curg
);
1905 top
->binres
= dialog2res(top
->name
, top
->res
.dlg
);
1909 top
->binres
= dialogex2res(top
->name
, top
->res
.dlgex
);
1913 top
->binres
= font2res(top
->name
, top
->res
.fnt
);
1917 top
->binres
= fontdir2res(top
->name
, top
->res
.fnd
);
1921 top
->binres
= icon2res(top
->res
.ico
);
1925 top
->binres
= icongroup2res(top
->name
, top
->res
.icog
);
1929 top
->binres
= menu2res(top
->name
, top
->res
.men
);
1933 top
->binres
= menuex2res(top
->name
, top
->res
.menex
);
1937 top
->binres
= rcdata2res(top
->name
, top
->res
.rdt
);
1941 top
->binres
= stringtable2res(top
->res
.stt
);
1945 top
->binres
= user2res(top
->name
, top
->res
.usr
);
1949 top
->binres
= messagetable2res(top
->name
, top
->res
.msg
);
1953 top
->binres
= versioninfo2res(top
->name
, top
->res
.ver
);
1957 top
->binres
= toolbar2res(top
->name
, top
->res
.tbt
);
1961 top
->binres
= dlginit2res(top
->name
, top
->res
.dlgi
);
1966 top
->binres
= anicurico2res(top
->name
, top
->res
.ani
, top
->type
);
1969 internal_error(__FILE__
, __LINE__
, "Unknown resource type encountered %d in binary res generation", top
->type
);
1971 top
->c_name
= make_c_name(get_c_typename(top
->type
), top
->name
, top
->lan
);