2 * Generate .res format from a resource-tree
4 * Copyright 1998 Bertho A. Stultiens
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 * 05-May-2000 BS - Added code to support endian conversions. The
22 * extra functions also aid unaligned access, but
23 * this is not yet implemented.
24 * 25-May-1998 BS - Added simple unicode -> char conversion for resource
25 * names in .s and .h files.
45 #define SetResSize(res, tag) set_dword((res), (tag), (res)->size - get_dword((res), (tag)))
50 r
= xmalloc(sizeof(res_t
));
51 r
->allocsize
= RES_BLOCKSIZE
;
54 r
->data
= xmalloc(RES_BLOCKSIZE
);
58 res_t
*grow_res(res_t
*r
, unsigned int add
)
61 r
->data
= 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\n", str
->type
);
278 static int parse_accel_string( const string_t
*key
, int flags
)
282 if(key
->type
== str_char
)
284 if (key
->str
.cstr
[0] == '#') return 0; /* ignore message contexts */
285 if((flags
& WRC_AF_VIRTKEY
) &&
286 !((key
->str
.cstr
[0] >= 'A' && key
->str
.cstr
[0] <= 'Z') ||
287 (key
->str
.cstr
[0] >= '0' && key
->str
.cstr
[0] <= '9')))
289 print_location( &key
->loc
);
290 error("VIRTKEY code is not equal to ascii value\n");
293 if(key
->str
.cstr
[0] == '^' && (flags
& WRC_AF_CONTROL
) != 0)
295 print_location( &key
->loc
);
296 error("Cannot use both '^' and CONTROL modifier\n");
298 else if(key
->str
.cstr
[0] == '^')
300 keycode
= toupper((unsigned char)key
->str
.cstr
[1]) - '@';
303 print_location( &key
->loc
);
304 error("Control-code out of range\n");
308 keycode
= key
->str
.cstr
[0];
312 if (key
->str
.wstr
[0] == '#') return 0; /* ignore message contexts */
313 if((flags
& WRC_AF_VIRTKEY
) &&
314 !((key
->str
.wstr
[0] >= 'A' && key
->str
.wstr
[0] <= 'Z') ||
315 (key
->str
.wstr
[0] >= '0' && key
->str
.wstr
[0] <= '9')))
317 print_location( &key
->loc
);
318 error("VIRTKEY code is not equal to ascii value\n");
320 if(key
->str
.wstr
[0] == '^' && (flags
& WRC_AF_CONTROL
) != 0)
322 print_location( &key
->loc
);
323 error("Cannot use both '^' and CONTROL modifier\n");
325 else if(key
->str
.wstr
[0] == '^')
327 keycode
= toupperW(key
->str
.wstr
[1]) - '@';
330 print_location( &key
->loc
);
331 error("Control-code out of range\n");
335 keycode
= key
->str
.wstr
[0];
341 *****************************************************************************
342 * Function : put_string
343 * Syntax : void put_string(res_t *res, string_t *str, enum str_e type,
344 * int isterm, const language_t *lang)
346 * res - Binary resource to put the data in
347 * str - String to put
348 * type - Data has to be written in either str_char or str_unicode
349 * isterm - The string is '\0' terminated (disregard the string's
354 *****************************************************************************
356 static void put_string(res_t
*res
, const string_t
*str
, enum str_e type
, int isterm
,
357 const language_t
*lang
)
365 if (lang
) codepage
= get_language_codepage( lang
->id
, lang
->sub
);
366 else codepage
= get_language_codepage( 0, 0 );
368 assert( codepage
!= -1 );
370 newstr
= convert_string(str
, type
, codepage
);
371 if (type
== str_unicode
)
373 if (str
->type
== str_char
)
375 if (!check_unicode_conversion( str
, newstr
, codepage
))
377 print_location( &str
->loc
);
378 error( "String %s does not convert identically to Unicode and back in codepage %d. "
379 "Try using a Unicode string instead\n", str
->str
.cstr
, codepage
);
381 if (check_valid_utf8( str
, codepage
))
383 print_location( &str
->loc
);
384 warning( "string \"%s\" seems to be UTF-8 but codepage %u is in use.\n",
385 str
->str
.cstr
, codepage
);
388 if (!isterm
) put_word(res
, newstr
->size
);
389 for(cnt
= 0; cnt
< newstr
->size
; cnt
++)
391 WCHAR c
= newstr
->str
.wstr
[cnt
];
392 if (isterm
&& !c
) break;
395 if (isterm
) put_word(res
, 0);
399 if (!isterm
) put_byte(res
, newstr
->size
);
400 for(cnt
= 0; cnt
< newstr
->size
; cnt
++)
402 char c
= newstr
->str
.cstr
[cnt
];
403 if (isterm
&& !c
) break;
406 if (isterm
) put_byte(res
, 0);
412 *****************************************************************************
413 * Function : put_name_id
414 * Syntax : void put_name_id(res_t *res, name_id_t *nid, int upcase, const language_t *lang)
419 *****************************************************************************
421 static void put_name_id(res_t
*res
, name_id_t
*nid
, int upcase
, const language_t
*lang
)
423 if(nid
->type
== name_ord
)
426 put_word(res
, 0xffff);
429 put_word(res
, (WORD
)nid
->name
.i_name
);
431 else if(nid
->type
== name_str
)
434 string_to_upper(nid
->name
.s_name
);
435 put_string(res
, nid
->name
.s_name
, win32
? str_unicode
: str_char
, TRUE
, lang
);
439 internal_error(__FILE__
, __LINE__
, "Invalid name_id type %d\n", nid
->type
);
444 *****************************************************************************
446 * Syntax : void put_lvc(res_t *res, lvc_t *lvc)
451 *****************************************************************************
453 static void put_lvc(res_t
*res
, lvc_t
*lvc
)
455 if(lvc
&& lvc
->language
)
456 put_word(res
, MAKELANGID(lvc
->language
->id
, lvc
->language
->sub
));
458 put_word(res
, 0); /* Neutral */
459 if(lvc
&& lvc
->version
)
460 put_dword(res
, *(lvc
->version
));
463 if(lvc
&& lvc
->characts
)
464 put_dword(res
, *(lvc
->characts
));
470 *****************************************************************************
471 * Function : put_raw_data
472 * Syntax : void put_raw_data(res_t *res, raw_data_t *raw, int offset)
477 *****************************************************************************
479 static void put_raw_data(res_t
*res
, raw_data_t
*raw
, int offset
)
481 unsigned int wsize
= raw
->size
- offset
;
482 if(res
->allocsize
- res
->size
< wsize
)
483 grow_res(res
, wsize
);
484 memcpy(&(res
->data
[res
->size
]), raw
->data
+ offset
, wsize
);
489 *****************************************************************************
490 * Function : put_res_header
491 * Syntax : input_res_header(res_t *res, int type, name_id_t *ntype,
492 * name_id_t *name, DWORD memopt, lvc_t *lvc)
495 * res - Binary resource descriptor to write to
496 * type - Resource identifier (if ntype == NULL)
497 * ntype - Name id of type
498 * name - Resource's name
499 * memopt - Resource's memory options to write
500 * lvc - Language, version and characteristics (win32 only)
501 * Output : An index to the resource size field. The resource size field
502 * contains the header size upon exit.
505 *****************************************************************************
507 static int put_res_header(res_t
*res
, int type
, name_id_t
*ntype
, name_id_t
*name
,
508 DWORD memopt
, lvc_t
*lvc
)
512 put_dword(res
, 0); /* We will overwrite these later */
516 put_word(res
, 0xffff); /* ResType */
520 put_name_id(res
, ntype
, TRUE
, lvc
->language
);
521 put_name_id(res
, name
, TRUE
, lvc
->language
); /* ResName */
523 put_dword(res
, 0); /* DataVersion */
524 put_word(res
, memopt
); /* Memory options */
525 put_lvc(res
, lvc
); /* Language, version and characts */
526 set_dword(res
, 0*sizeof(DWORD
), res
->size
); /* Set preliminary resource */
527 set_dword(res
, 1*sizeof(DWORD
), res
->size
); /* Set HeaderSize */
528 res
->dataidx
= res
->size
;
536 put_byte(res
, 0xff); /* ResType */
540 put_name_id(res
, ntype
, TRUE
, NULL
);
541 put_name_id(res
, name
, TRUE
, NULL
); /* ResName */
542 put_word(res
, memopt
); /* Memory options */
544 put_dword(res
, 0); /* ResSize overwritten later*/
545 set_dword(res
, tag
, res
->size
);
546 res
->dataidx
= res
->size
;
552 *****************************************************************************
553 * Function : accelerator2res
554 * Syntax : res_t *accelerator2res(name_id_t *name, accelerator_t *acc)
556 * name - Name/ordinal of the resource
557 * acc - The accelerator descriptor
558 * Output : New .res format structure
561 *****************************************************************************
563 static res_t
*accelerator2res(name_id_t
*name
, accelerator_t
*acc
)
568 assert(name
!= NULL
);
575 restag
= put_res_header(res
, WRC_RT_ACCELERATOR
, NULL
, name
, acc
->memopt
, &(acc
->lvc
));
579 if (ev
->str
) key
= parse_accel_string( ev
->str
, ev
->flags
);
580 put_word(res
, ev
->flags
| (ev
->next
? 0 : 0x80));
582 put_word(res
, ev
->id
);
583 put_word(res
, 0); /* Padding */
590 restag
= put_res_header(res
, WRC_RT_ACCELERATOR
, NULL
, name
, acc
->memopt
, NULL
);
594 if (ev
->str
) key
= parse_accel_string( ev
->str
, ev
->flags
);
595 put_byte(res
, ev
->flags
| (ev
->next
? 0 : 0x80));
597 put_word(res
, ev
->id
);
601 /* Set ResourceSize */
602 SetResSize(res
, restag
);
607 *****************************************************************************
608 * Function : dialog2res
609 * Syntax : res_t *dialog2res(name_id_t *name, dialog_t *dlg)
611 * name - Name/ordinal of the resource
612 * dlg - The dialog descriptor
613 * Output : New .res format structure
616 *****************************************************************************
618 static res_t
*dialog2res(name_id_t
*name
, dialog_t
*dlg
)
625 assert(name
!= NULL
);
628 ctrl
= dlg
->controls
;
632 restag
= put_res_header(res
, WRC_RT_DIALOG
, NULL
, name
, dlg
->memopt
, &(dlg
->lvc
));
636 /* FIXME: MS doc says that the first word must contain 0xffff
637 * and the second 0x0001 to signal a DLGTEMPLATEEX. Borland's
638 * compiler reverses the two words.
639 * I don't know which one to choose, but I write it as Mr. B
642 put_word(res
, 1); /* Signature */
643 put_word(res
, 0xffff); /* DlgVer */
644 put_dword(res
, dlg
->gothelpid
? dlg
->helpid
: 0);
645 put_dword(res
, dlg
->gotexstyle
? dlg
->exstyle
->or_mask
: 0);
646 put_dword(res
, dlg
->gotstyle
? dlg
->style
->or_mask
: WS_POPUPWINDOW
);
650 put_dword(res
, dlg
->style
->or_mask
);
651 put_dword(res
, dlg
->gotexstyle
? dlg
->exstyle
->or_mask
: 0);
653 tag_nctrl
= res
->size
;
654 put_word(res
, 0); /* Number of controls */
655 put_word(res
, dlg
->x
);
656 put_word(res
, dlg
->y
);
657 put_word(res
, dlg
->width
);
658 put_word(res
, dlg
->height
);
660 put_name_id(res
, dlg
->menu
, TRUE
, dlg
->lvc
.language
);
664 put_name_id(res
, dlg
->dlgclass
, TRUE
, dlg
->lvc
.language
);
668 put_string(res
, dlg
->title
, str_unicode
, TRUE
, dlg
->lvc
.language
);
673 put_word(res
, dlg
->font
->size
);
676 put_word(res
, dlg
->font
->weight
);
677 /* FIXME: ? TRUE should be sufficient to say that it's
678 * italic, but Borland's compiler says it's 0x0101.
679 * I just copy it here, and hope for the best.
681 put_word(res
, dlg
->font
->italic
? 0x0101 : 0);
683 put_string(res
, dlg
->font
->name
, str_unicode
, TRUE
, dlg
->lvc
.language
);
691 put_dword(res
, ctrl
->gothelpid
? ctrl
->helpid
: 0);
692 put_dword(res
, ctrl
->gotexstyle
? ctrl
->exstyle
->or_mask
: 0);
693 /* FIXME: what is default control style? */
694 put_dword(res
, ctrl
->gotstyle
? ctrl
->style
->or_mask
: WS_CHILD
| WS_VISIBLE
);
698 /* FIXME: what is default control style? */
699 put_dword(res
, ctrl
->gotstyle
? ctrl
->style
->or_mask
: WS_CHILD
);
700 put_dword(res
, ctrl
->gotexstyle
? ctrl
->exstyle
->or_mask
: 0);
702 put_word(res
, ctrl
->x
);
703 put_word(res
, ctrl
->y
);
704 put_word(res
, ctrl
->width
);
705 put_word(res
, ctrl
->height
);
707 put_dword(res
, ctrl
->id
);
709 put_word(res
, ctrl
->id
);
711 put_name_id(res
, ctrl
->ctlclass
, TRUE
, dlg
->lvc
.language
);
713 internal_error(__FILE__
, __LINE__
, "Control has no control-class\n");
715 put_name_id(res
, ctrl
->title
, FALSE
, dlg
->lvc
.language
);
720 put_word(res
, ctrl
->extra
->size
+2);
722 put_raw_data(res
, ctrl
->extra
, 0);
732 /* Set number of controls */
733 set_word(res
, tag_nctrl
, (WORD
)nctrl
);
737 restag
= put_res_header(res
, WRC_RT_DIALOG
, NULL
, name
, dlg
->memopt
, NULL
);
739 put_dword(res
, dlg
->gotstyle
? dlg
->style
->or_mask
: WS_POPUPWINDOW
);
740 tag_nctrl
= res
->size
;
741 put_byte(res
, 0); /* Number of controls */
742 put_word(res
, dlg
->x
);
743 put_word(res
, dlg
->y
);
744 put_word(res
, dlg
->width
);
745 put_word(res
, dlg
->height
);
747 put_name_id(res
, dlg
->menu
, TRUE
, NULL
);
751 put_name_id(res
, dlg
->dlgclass
, TRUE
, NULL
);
755 put_string(res
, dlg
->title
, str_char
, TRUE
, NULL
);
760 put_word(res
, dlg
->font
->size
);
761 put_string(res
, dlg
->font
->name
, str_char
, TRUE
, NULL
);
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_word(res
, ctrl
->id
);
771 put_dword(res
, ctrl
->gotstyle
? ctrl
->style
->or_mask
: WS_CHILD
);
774 if(ctrl
->ctlclass
->type
== name_ord
775 && ctrl
->ctlclass
->name
.i_name
>= 0x80
776 && ctrl
->ctlclass
->name
.i_name
<= 0x85)
777 put_byte(res
, ctrl
->ctlclass
->name
.i_name
);
778 else if(ctrl
->ctlclass
->type
== name_str
)
779 put_name_id(res
, ctrl
->ctlclass
, FALSE
, NULL
);
781 error("Unknown control-class %04x\n", ctrl
->ctlclass
->name
.i_name
);
784 internal_error(__FILE__
, __LINE__
, "Control has no control-class\n");
786 put_name_id(res
, ctrl
->title
, FALSE
, NULL
);
790 /* FIXME: What is this extra byte doing here? */
796 /* Set number of controls */
797 ((char *)res
->data
)[tag_nctrl
] = (char)nctrl
;
799 /* Set ResourceSize */
800 SetResSize(res
, restag
);
805 *****************************************************************************
806 * Function : menuitem2res
807 * Syntax : void menuitem2res(res_t *res, menu_item_t *item)
811 * Remarks : Self recursive
812 *****************************************************************************
814 static void menuitem2res(res_t
*res
, menu_item_t
*menitem
, const language_t
*lang
)
816 menu_item_t
*itm
= menitem
;
821 put_word(res
, itm
->state
| (itm
->popup
? MF_POPUP
: 0) | (!itm
->next
? MF_END
: 0));
823 put_word(res
, itm
->id
);
825 put_string(res
, itm
->name
, str_unicode
, TRUE
, lang
);
829 menuitem2res(res
, itm
->popup
, lang
);
837 put_word(res
, itm
->state
| (itm
->popup
? MF_POPUP
: 0) | (!itm
->next
? MF_END
: 0));
839 put_word(res
, itm
->id
);
841 put_string(res
, itm
->name
, str_char
, TRUE
, lang
);
845 menuitem2res(res
, itm
->popup
, lang
);
853 *****************************************************************************
854 * Function : menuexitem2res
855 * Syntax : void menuexitem2res(res_t *res, menuex_item_t *item)
859 * Remarks : Self recursive
860 *****************************************************************************
862 static void menuexitem2res(res_t
*res
, menu_item_t
*menitem
, const language_t
*lang
)
864 menu_item_t
*itm
= menitem
;
868 put_dword(res
, itm
->gottype
? itm
->type
: 0);
869 put_dword(res
, itm
->gotstate
? itm
->state
: 0);
870 put_dword(res
, itm
->gotid
? itm
->id
: 0); /* FIXME: Docu. says word */
871 put_word(res
, (itm
->popup
? 0x01 : 0) | (!itm
->next
? MF_END
: 0));
873 put_string(res
, itm
->name
, str_unicode
, TRUE
, lang
);
879 put_dword(res
, itm
->gothelpid
? itm
->helpid
: 0);
880 menuexitem2res(res
, itm
->popup
, lang
);
888 *****************************************************************************
889 * Function : menu2res
890 * Syntax : res_t *menu2res(name_id_t *name, menu_t *men)
892 * name - Name/ordinal of the resource
893 * menex - The menuex descriptor
894 * Output : New .res format structure
897 *****************************************************************************
899 static res_t
*menu2res(name_id_t
*name
, menu_t
*men
)
903 assert(name
!= NULL
);
909 restag
= put_res_header(res
, WRC_RT_MENU
, NULL
, name
, men
->memopt
, &(men
->lvc
));
913 put_word(res
, 1); /* Menuheader: Version */
914 put_word(res
, 4); /* Offset */
915 put_dword(res
, 0); /* HelpId */
917 menuexitem2res(res
, men
->items
, men
->lvc
.language
);
921 put_dword(res
, 0); /* Menuheader: Version and HeaderSize */
922 menuitem2res(res
, men
->items
, men
->lvc
.language
);
924 /* Set ResourceSize */
925 SetResSize(res
, restag
);
930 restag
= put_res_header(res
, WRC_RT_MENU
, NULL
, name
, men
->memopt
, NULL
);
932 put_dword(res
, 0); /* Menuheader: Version and HeaderSize */
933 menuitem2res(res
, men
->items
, NULL
);
934 /* Set ResourceSize */
935 SetResSize(res
, restag
);
941 *****************************************************************************
942 * Function : cursorgroup2res
943 * Syntax : res_t *cursorgroup2res(name_id_t *name, cursor_group_t *curg)
945 * name - Name/ordinal of the resource
946 * curg - The cursor descriptor
947 * Output : New .res format structure
950 *****************************************************************************
952 static res_t
*cursorgroup2res(name_id_t
*name
, cursor_group_t
*curg
)
957 assert(name
!= NULL
);
958 assert(curg
!= NULL
);
961 restag
= put_res_header(res
, WRC_RT_GROUP_CURSOR
, NULL
, name
, curg
->memopt
, &(curg
->lvc
));
964 put_word(res
, 0); /* Reserved */
965 /* FIXME: The ResType in the NEWHEADER structure should
966 * contain 14 according to the MS win32 doc. This is
967 * not the case with the BRC compiler and I really doubt
968 * the latter. Putting one here is compliant to win16 spec,
969 * but who knows the true value?
971 put_word(res
, 2); /* ResType */
972 put_word(res
, curg
->ncursor
);
974 for(cur
= curg
->cursorlist
; cur
; cur
= cur
->next
)
976 cur
= curg
->cursorlist
;
979 for(; cur
; cur
= cur
->prev
)
982 put_word(res
, cur
->width
);
983 /* FIXME: The height of a cursor is half the size of
984 * the bitmap's height. BRC puts the height from the
985 * BITMAPINFOHEADER here instead of the cursorfile's
986 * height. MS doesn't seem to care...
988 put_word(res
, cur
->height
);
989 /* FIXME: The next two are reversed in BRC and I don't
990 * know why. Probably a bug. But, we can safely ignore
991 * it because win16 does not support color cursors.
992 * A warning should have been generated by the parser.
994 put_word(res
, cur
->planes
);
995 put_word(res
, cur
->bits
);
996 /* FIXME: The +4 is the hotspot in the cursor resource.
997 * However, I could not find this in the documentation.
998 * The hotspot bytes must either be included or MS
1001 put_dword(res
, cur
->data
->size
+4);
1002 put_word(res
, cur
->id
);
1007 put_word(res
, 0); /* Reserved */
1008 put_word(res
, 2); /* ResType */
1009 put_word(res
, curg
->ncursor
);
1011 for(cur
= curg
->cursorlist
; cur
; cur
= cur
->next
)
1013 cur
= curg
->cursorlist
;
1016 for(; cur
; cur
= cur
->prev
)
1019 put_word(res
, cur
->width
);
1020 /* FIXME: The height of a cursor is half the size of
1021 * the bitmap's height. BRC puts the height from the
1022 * BITMAPINFOHEADER here instead of the cursorfile's
1023 * height. MS doesn't seem to care...
1025 put_word(res
, cur
->height
);
1026 /* FIXME: The next two are reversed in BRC and I don't
1027 * know why. Probably a bug. But, we can safely ignore
1028 * it because win16 does not support color cursors.
1029 * A warning should have been generated by the parser.
1031 put_word(res
, cur
->planes
);
1032 put_word(res
, cur
->bits
);
1033 /* FIXME: The +4 is the hotspot in the cursor resource.
1034 * However, I could not find this in the documentation.
1035 * The hotspot bytes must either be included or MS
1038 put_dword(res
, cur
->data
->size
+4);
1039 put_word(res
, cur
->id
);
1042 SetResSize(res
, restag
); /* Set ResourceSize */
1050 *****************************************************************************
1051 * Function : cursor2res
1052 * Syntax : res_t *cursor2res(cursor_t *cur)
1054 * cur - The cursor descriptor
1055 * Output : New .res format structure
1058 *****************************************************************************
1060 static res_t
*cursor2res(cursor_t
*cur
)
1066 assert(cur
!= NULL
);
1069 name
.type
= name_ord
;
1070 name
.name
.i_name
= cur
->id
;
1071 restag
= put_res_header(res
, WRC_RT_CURSOR
, NULL
, &name
, WRC_MO_MOVEABLE
| WRC_MO_DISCARDABLE
, &(cur
->lvc
));
1072 put_word(res
, cur
->xhot
);
1073 put_word(res
, cur
->yhot
);
1074 put_raw_data(res
, cur
->data
, 0);
1076 SetResSize(res
, restag
); /* Set ResourceSize */
1084 *****************************************************************************
1085 * Function : icongroup2res
1086 * Syntax : res_t *icongroup2res(name_id_t *name, icon_group_t *icog)
1088 * name - Name/ordinal of the resource
1089 * icog - The icon group descriptor
1090 * Output : New .res format structure
1093 *****************************************************************************
1095 static res_t
*icongroup2res(name_id_t
*name
, icon_group_t
*icog
)
1100 assert(name
!= NULL
);
1101 assert(icog
!= NULL
);
1104 restag
= put_res_header(res
, WRC_RT_GROUP_ICON
, NULL
, name
, icog
->memopt
, &(icog
->lvc
));
1107 put_word(res
, 0); /* Reserved */
1108 /* FIXME: The ResType in the NEWHEADER structure should
1109 * contain 14 according to the MS win32 doc. This is
1110 * not the case with the BRC compiler and I really doubt
1111 * the latter. Putting one here is compliant to win16 spec,
1112 * but who knows the true value?
1114 put_word(res
, 1); /* ResType */
1115 put_word(res
, icog
->nicon
);
1116 for(ico
= icog
->iconlist
; ico
; ico
= ico
->next
)
1118 put_byte(res
, ico
->width
);
1119 put_byte(res
, ico
->height
);
1120 put_byte(res
, ico
->nclr
);
1121 put_byte(res
, 0); /* Reserved */
1122 put_word(res
, ico
->planes
);
1123 put_word(res
, ico
->bits
);
1124 put_dword(res
, ico
->data
->size
);
1125 put_word(res
, ico
->id
);
1130 put_word(res
, 0); /* Reserved */
1131 put_word(res
, 1); /* ResType */
1132 put_word(res
, icog
->nicon
);
1133 for(ico
= icog
->iconlist
; ico
; ico
= ico
->next
)
1135 put_byte(res
, ico
->width
);
1136 put_byte(res
, ico
->height
);
1137 put_byte(res
, ico
->nclr
);
1138 put_byte(res
, 0); /* Reserved */
1139 put_word(res
, ico
->planes
);
1140 put_word(res
, ico
->bits
);
1141 put_dword(res
, ico
->data
->size
);
1142 put_word(res
, ico
->id
);
1145 SetResSize(res
, restag
); /* Set ResourceSize */
1153 *****************************************************************************
1154 * Function : icon2res
1155 * Syntax : res_t *icon2res(icon_t *ico)
1157 * ico - The icon descriptor
1158 * Output : New .res format structure
1161 *****************************************************************************
1163 static res_t
*icon2res(icon_t
*ico
)
1169 assert(ico
!= NULL
);
1172 name
.type
= name_ord
;
1173 name
.name
.i_name
= ico
->id
;
1174 restag
= put_res_header(res
, WRC_RT_ICON
, NULL
, &name
, WRC_MO_MOVEABLE
| WRC_MO_DISCARDABLE
, &(ico
->lvc
));
1175 put_raw_data(res
, ico
->data
, 0);
1177 SetResSize(res
, restag
); /* Set ResourceSize */
1185 *****************************************************************************
1186 * Function : anicurico2res
1187 * Syntax : res_t *anicurico2res(name_id_t *name, ani_curico_t *ani)
1189 * name - Name/ordinal of the resource
1190 * ani - The animated object descriptor
1191 * Output : New .res format structure
1193 * Remarks : The endian of the object's structures have been converted
1195 * There are rumors that win311 could handle animated stuff.
1196 * That is why they are generated for both win16 and win32
1198 *****************************************************************************
1200 static res_t
*anicurico2res(name_id_t
*name
, ani_curico_t
*ani
, enum res_e type
)
1204 assert(name
!= NULL
);
1205 assert(ani
!= NULL
);
1208 restag
= put_res_header(res
, type
== res_anicur
? WRC_RT_ANICURSOR
: WRC_RT_ANIICON
,
1209 NULL
, name
, ani
->memopt
, NULL
);
1210 put_raw_data(res
, ani
->data
, 0);
1211 /* Set ResourceSize */
1212 SetResSize(res
, restag
);
1219 *****************************************************************************
1220 * Function : bitmap2res
1221 * Syntax : res_t *bitmap2res(name_id_t *name, bitmap_t *bmp)
1223 * name - Name/ordinal of the resource
1224 * bmp - The bitmap descriptor
1225 * Output : New .res format structure
1227 * Remarks : The endian of the bitmap structures have been converted
1229 *****************************************************************************
1231 static res_t
*bitmap2res(name_id_t
*name
, bitmap_t
*bmp
)
1235 assert(name
!= NULL
);
1236 assert(bmp
!= NULL
);
1239 restag
= put_res_header(res
, WRC_RT_BITMAP
, NULL
, name
, bmp
->memopt
, &(bmp
->data
->lvc
));
1240 if(bmp
->data
->data
[0] == 'B'
1241 && bmp
->data
->data
[1] == 'M'
1242 && ((BITMAPFILEHEADER
*)bmp
->data
->data
)->bfSize
== bmp
->data
->size
1243 && bmp
->data
->size
>= sizeof(BITMAPFILEHEADER
))
1245 /* The File header is still attached, don't write it */
1246 put_raw_data(res
, bmp
->data
, sizeof(BITMAPFILEHEADER
));
1250 put_raw_data(res
, bmp
->data
, 0);
1252 /* Set ResourceSize */
1253 SetResSize(res
, restag
);
1260 *****************************************************************************
1261 * Function : font2res
1262 * Syntax : res_t *font2res(name_id_t *name, font_t *fnt)
1264 * name - Name/ordinal of the resource
1265 * fnt - The font descriptor
1266 * Output : New .res format structure
1268 * Remarks : The data has been prepared just after parsing.
1269 *****************************************************************************
1271 static res_t
*font2res(name_id_t
*name
, font_t
*fnt
)
1275 assert(name
!= NULL
);
1276 assert(fnt
!= NULL
);
1279 restag
= put_res_header(res
, WRC_RT_FONT
, NULL
, name
, fnt
->memopt
, &(fnt
->data
->lvc
));
1280 put_raw_data(res
, fnt
->data
, 0);
1281 /* Set ResourceSize */
1282 SetResSize(res
, restag
);
1289 *****************************************************************************
1290 * Function : fontdir2res
1291 * Syntax : res_t *fontdir2res(name_id_t *name, fontdir_t *fnd)
1293 * name - Name/ordinal of the resource
1294 * fntdir - The fontdir descriptor
1295 * Output : New .res format structure
1297 * Remarks : The data has been prepared just after parsing.
1298 *****************************************************************************
1300 static res_t
*fontdir2res(name_id_t
*name
, fontdir_t
*fnd
)
1304 assert(name
!= NULL
);
1305 assert(fnd
!= NULL
);
1308 restag
= put_res_header(res
, WRC_RT_FONTDIR
, NULL
, name
, fnd
->memopt
, &(fnd
->data
->lvc
));
1309 put_raw_data(res
, fnd
->data
, 0);
1310 /* Set ResourceSize */
1311 SetResSize(res
, restag
);
1318 *****************************************************************************
1319 * Function : html2res
1320 * Syntax : res_t *html2res(name_id_t *name, html_t *html)
1322 * name - Name/ordinal of the resource
1323 * rdt - The html descriptor
1324 * Output : New .res format structure
1327 *****************************************************************************
1329 static res_t
*html2res(name_id_t
*name
, html_t
*html
)
1333 assert(name
!= NULL
);
1334 assert(html
!= NULL
);
1337 restag
= put_res_header(res
, WRC_RT_HTML
, NULL
, name
, html
->memopt
, &(html
->data
->lvc
));
1338 put_raw_data(res
, html
->data
, 0);
1339 /* Set ResourceSize */
1340 SetResSize(res
, restag
);
1347 *****************************************************************************
1348 * Function : rcdata2res
1349 * Syntax : res_t *rcdata2res(name_id_t *name, rcdata_t *rdt)
1351 * name - Name/ordinal of the resource
1352 * rdt - The rcdata descriptor
1353 * Output : New .res format structure
1356 *****************************************************************************
1358 static res_t
*rcdata2res(name_id_t
*name
, rcdata_t
*rdt
)
1362 assert(name
!= NULL
);
1363 assert(rdt
!= NULL
);
1366 restag
= put_res_header(res
, WRC_RT_RCDATA
, NULL
, name
, rdt
->memopt
, &(rdt
->data
->lvc
));
1367 put_raw_data(res
, rdt
->data
, 0);
1368 /* Set ResourceSize */
1369 SetResSize(res
, restag
);
1376 *****************************************************************************
1377 * Function : messagetable2res
1378 * Syntax : res_t *messagetable2res(name_id_t *name, messagetable_t *msg)
1380 * name - Name/ordinal of the resource
1381 * msg - The messagetable descriptor
1382 * Output : New .res format structure
1384 * Remarks : The data has been converted to the appropriate endian
1385 * after it was parsed.
1386 *****************************************************************************
1388 static res_t
*messagetable2res(name_id_t
*name
, messagetable_t
*msg
)
1392 assert(name
!= NULL
);
1393 assert(msg
!= NULL
);
1396 restag
= put_res_header(res
, WRC_RT_MESSAGETABLE
, NULL
, name
, msg
->memopt
, &(msg
->data
->lvc
));
1397 put_raw_data(res
, msg
->data
, 0);
1398 /* Set ResourceSize */
1399 SetResSize(res
, restag
);
1406 *****************************************************************************
1407 * Function : stringtable2res
1408 * Syntax : res_t *stringtable2res(stringtable_t *stt)
1410 * stt - The stringtable descriptor
1411 * Output : New .res format structure
1414 *****************************************************************************
1416 static res_t
*stringtable2res(stringtable_t
*stt
)
1424 assert(stt
!= NULL
);
1427 for(; stt
; stt
= stt
->next
)
1431 warning("Empty internal stringtable\n");
1434 name
.type
= name_ord
;
1435 name
.name
.i_name
= (stt
->idbase
>> 4) + 1;
1436 restag
= put_res_header(res
, WRC_RT_STRING
, NULL
, &name
, stt
->memopt
, win32
? &(stt
->lvc
) : NULL
);
1437 for(i
= 0; i
< stt
->nentries
; i
++)
1439 if(stt
->entries
[i
].str
&& stt
->entries
[i
].str
->size
)
1441 put_string(res
, stt
->entries
[i
].str
, win32
? str_unicode
: str_char
,
1442 FALSE
, win32
? stt
->lvc
.language
: NULL
);
1452 /* Set ResourceSize */
1453 SetResSize(res
, restag
- lastsize
);
1456 lastsize
= res
->size
;
1462 *****************************************************************************
1463 * Function : user2res
1464 * Syntax : res_t *user2res(name_id_t *name, user_t *usr)
1466 * name - Name/ordinal of the resource
1467 * usr - The userresource descriptor
1468 * Output : New .res format structure
1471 *****************************************************************************
1473 static res_t
*user2res(name_id_t
*name
, user_t
*usr
)
1477 assert(name
!= NULL
);
1478 assert(usr
!= NULL
);
1481 restag
= put_res_header(res
, 0, usr
->type
, name
, usr
->memopt
, &(usr
->data
->lvc
));
1482 put_raw_data(res
, usr
->data
, 0);
1483 /* Set ResourceSize */
1484 SetResSize(res
, restag
);
1491 *****************************************************************************
1492 * Function : versionblock2res
1493 * Syntax : void versionblock2res(res_t *res, ver_block_t *blk)
1495 * res - Binary resource to write to
1496 * blk - The version block to be written
1499 * Remarks : Self recursive
1500 *****************************************************************************
1502 static void versionblock2res(res_t
*res
, ver_block_t
*blk
, int level
, const language_t
*lang
)
1511 blksizetag
= res
->size
;
1512 put_word(res
, 0); /* Will be overwritten later */
1515 put_word(res
, 0); /* level ? */
1516 put_string(res
, blk
->name
, win32
? str_unicode
: str_char
, TRUE
, lang
);
1518 for(val
= blk
->values
; val
; val
= val
->next
)
1520 if(val
->type
== val_str
)
1522 valblksizetag
= res
->size
;
1523 put_word(res
, 0); /* Will be overwritten later */
1524 valvalsizetag
= res
->size
;
1525 put_word(res
, 0); /* Will be overwritten later */
1528 put_word(res
, level
);
1530 put_string(res
, val
->key
, win32
? str_unicode
: str_char
, TRUE
, lang
);
1533 put_string(res
, val
->value
.str
, win32
? str_unicode
: str_char
, TRUE
, lang
);
1535 set_word(res
, valvalsizetag
, (WORD
)((res
->size
- tag
) >> 1));
1537 set_word(res
, valvalsizetag
, (WORD
)(res
->size
- tag
));
1538 set_word(res
, valblksizetag
, (WORD
)(res
->size
- valblksizetag
));
1541 else if(val
->type
== val_words
)
1543 valblksizetag
= res
->size
;
1544 put_word(res
, 0); /* Will be overwritten later */
1545 valvalsizetag
= res
->size
;
1546 put_word(res
, 0); /* Will be overwritten later */
1549 put_word(res
, level
);
1551 put_string(res
, val
->key
, win32
? str_unicode
: str_char
, TRUE
, lang
);
1554 for(i
= 0; i
< val
->value
.words
->nwords
; i
++)
1556 put_word(res
, val
->value
.words
->words
[i
]);
1558 set_word(res
, valvalsizetag
, (WORD
)(res
->size
- tag
));
1559 set_word(res
, valblksizetag
, (WORD
)(res
->size
- valblksizetag
));
1562 else if(val
->type
== val_block
)
1564 versionblock2res(res
, val
->value
.block
, level
+1, lang
);
1568 internal_error(__FILE__
, __LINE__
, "Invalid value indicator %d in VERSIONINFO\n", val
->type
);
1573 set_word(res
, blksizetag
, (WORD
)(res
->size
- blksizetag
));
1577 *****************************************************************************
1578 * Function : versioninfo2res
1579 * Syntax : res_t *versioninfo2res(name_id_t *name, versioninfo_t *ver)
1581 * name - Name/ordinal of the resource
1582 * ver - The versioninfo descriptor
1583 * Output : New .res format structure
1586 *****************************************************************************
1588 static res_t
*versioninfo2res(name_id_t
*name
, versioninfo_t
*ver
)
1591 int rootblocksizetag
;
1598 assert(name
!= NULL
);
1599 assert(ver
!= NULL
);
1601 vsvi
.type
= str_char
;
1602 vsvi
.str
.cstr
= xstrdup("VS_VERSION_INFO");
1603 vsvi
.size
= 15; /* Excl. termination */
1606 restag
= put_res_header(res
, WRC_RT_VERSION
, NULL
, name
, ver
->memopt
, &(ver
->lvc
));
1607 rootblocksizetag
= res
->size
;
1608 put_word(res
, 0); /* BlockSize filled in later */
1609 valsizetag
= res
->size
;
1610 put_word(res
, 0); /* ValueSize filled in later*/
1612 put_word(res
, 0); /* Tree-level ? */
1613 put_string(res
, &vsvi
, win32
? str_unicode
: str_char
,
1614 TRUE
, win32
? ver
->lvc
.language
: NULL
);
1618 put_dword(res
, VS_FFI_SIGNATURE
);
1619 put_dword(res
, VS_FFI_STRUCVERSION
);
1620 put_dword(res
, (ver
->filever_maj1
<< 16) + (ver
->filever_maj2
& 0xffff));
1621 put_dword(res
, (ver
->filever_min1
<< 16) + (ver
->filever_min2
& 0xffff));
1622 put_dword(res
, (ver
->prodver_maj1
<< 16) + (ver
->prodver_maj2
& 0xffff));
1623 put_dword(res
, (ver
->prodver_min1
<< 16) + (ver
->prodver_min2
& 0xffff));
1624 put_dword(res
, ver
->fileflagsmask
);
1625 put_dword(res
, ver
->fileflags
);
1626 put_dword(res
, ver
->fileos
);
1627 put_dword(res
, ver
->filetype
);
1628 put_dword(res
, ver
->filesubtype
);
1629 put_dword(res
, 0); /* FileDateMS */
1630 put_dword(res
, 0); /* FileDateLS */
1632 set_word(res
, valsizetag
, (WORD
)(res
->size
- tag
));
1633 /* Descend into the blocks */
1634 for(blk
= ver
->blocks
; blk
; blk
= blk
->next
)
1635 versionblock2res(res
, blk
, 0, win32
? ver
->lvc
.language
: NULL
);
1636 /* Set root block's size */
1637 set_word(res
, rootblocksizetag
, (WORD
)(res
->size
- rootblocksizetag
));
1639 SetResSize(res
, restag
);
1643 free(vsvi
.str
.cstr
);
1648 *****************************************************************************
1649 * Function : toolbaritem2res
1650 * Syntax : void toolbaritem2res(res_t *res, toolbar_item_t *tbitem)
1654 * Remarks : Self recursive
1655 *****************************************************************************
1657 static void toolbaritem2res(res_t
*res
, toolbar_item_t
*tbitem
)
1659 toolbar_item_t
*itm
= tbitem
;
1663 put_word(res
, itm
->id
);
1670 *****************************************************************************
1671 * Function : toolbar2res
1672 * Syntax : res_t *toolbar2res(name_id_t *name, toolbar_t *toolbar)
1674 * name - Name/ordinal of the resource
1675 * toolbar - The toolbar descriptor
1676 * Output : New .res format structure
1679 *****************************************************************************
1681 static res_t
*toolbar2res(name_id_t
*name
, toolbar_t
*toolbar
)
1685 assert(name
!= NULL
);
1686 assert(toolbar
!= NULL
);
1691 restag
= put_res_header(res
, WRC_RT_TOOLBAR
, NULL
, name
, toolbar
->memopt
, &(toolbar
->lvc
));
1693 put_word(res
, 1); /* Menuheader: Version */
1694 put_word(res
, toolbar
->button_width
); /* (in pixels?) */
1695 put_word(res
, toolbar
->button_height
); /* (in pixels?) */
1696 put_word(res
, toolbar
->nitems
);
1698 toolbaritem2res(res
, toolbar
->items
);
1699 /* Set ResourceSize */
1700 SetResSize(res
, restag
);
1705 /* Do not generate anything in 16-bit mode */
1714 *****************************************************************************
1715 * Function : dlginit2res
1716 * Syntax : res_t *dlginit2res(name_id_t *name, dlginit_t *dit)
1718 * name - Name/ordinal of the resource
1719 * rdt - The dlginit descriptor
1720 * Output : New .res format structure
1723 *****************************************************************************
1725 static res_t
*dlginit2res(name_id_t
*name
, dlginit_t
*dit
)
1729 assert(name
!= NULL
);
1730 assert(dit
!= NULL
);
1733 restag
= put_res_header(res
, WRC_RT_DLGINIT
, NULL
, name
, dit
->memopt
, &(dit
->data
->lvc
));
1734 put_raw_data(res
, dit
->data
, 0);
1735 /* Set ResourceSize */
1736 SetResSize(res
, restag
);
1743 *****************************************************************************
1744 * Function : prep_nid_for_label
1745 * Syntax : char *prep_nid_for_label(const name_id_t *nid)
1748 * Description : Converts a resource name into the first 32 (or less)
1749 * characters of the name with conversions.
1751 *****************************************************************************
1753 #define MAXNAMELEN 32
1754 char *prep_nid_for_label(const name_id_t
*nid
)
1756 static char buf
[MAXNAMELEN
+1];
1758 assert(nid
!= NULL
);
1760 if(nid
->type
== name_str
&& nid
->name
.s_name
->type
== str_unicode
)
1764 sptr
= nid
->name
.s_name
->str
.wstr
;
1766 for(i
= 0; *sptr
&& i
< MAXNAMELEN
; i
++)
1768 if((unsigned)*sptr
< 0x80 && isprint(*sptr
& 0xff))
1771 warning("Resourcename (str_unicode) contain unprintable characters or invalid translation, ignored\n");
1775 else if(nid
->type
== name_str
&& nid
->name
.s_name
->type
== str_char
)
1779 cptr
= nid
->name
.s_name
->str
.cstr
;
1781 for(i
= 0; *cptr
&& i
< MAXNAMELEN
; i
++)
1783 if((unsigned)*cptr
< 0x80 && isprint(*cptr
& 0xff))
1786 warning("Resourcename (str_char) contain unprintable characters, ignored\n");
1790 else if(nid
->type
== name_ord
)
1792 sprintf(buf
, "%u", nid
->name
.i_name
);
1796 internal_error(__FILE__
, __LINE__
, "Resource name_id with invalid type %d\n", nid
->type
);
1803 *****************************************************************************
1804 * Function : make_c_name
1805 * Syntax : char *make_c_name(const char *base, const name_id_t *nid, const language_t *lan)
1808 * Description : Converts a resource name into a valid c-identifier in the
1811 *****************************************************************************
1813 char *make_c_name(const char *base
, const name_id_t
*nid
, const language_t
*lan
)
1815 char *buf
= prep_nid_for_label(nid
);
1816 return strmake( "_%s_%s_%d", base
, buf
, lan
? MAKELANGID(lan
->id
, lan
->sub
) : 0);
1820 *****************************************************************************
1821 * Function : get_c_typename
1822 * Syntax : const char *get_c_typename(enum res_e type)
1825 * Description : Convert resource enum to char string to be used in c-name
1828 *****************************************************************************
1830 const char *get_c_typename(enum res_e type
)
1834 case res_acc
: return "Acc";
1835 case res_anicur
:return "AniCur";
1836 case res_aniico
:return "AniIco";
1837 case res_bmp
: return "Bmp";
1838 case res_cur
: return "Cur";
1839 case res_curg
: return "CurGrp";
1840 case res_dlg
: return "Dlg";
1841 case res_fnt
: return "Fnt";
1842 case res_fntdir
:return "FntDir";
1843 case res_ico
: return "Ico";
1844 case res_icog
: return "IcoGrp";
1845 case res_men
: return "Men";
1846 case res_rdt
: return "RCDat";
1847 case res_stt
: return "StrTab";
1848 case res_usr
: return "Usr";
1849 case res_msg
: return "MsgTab";
1850 case res_ver
: return "VerInf";
1851 case res_toolbar
: return "TlBr";
1852 case res_dlginit
: return "DlgInit";
1853 default: return "Oops";
1858 *****************************************************************************
1859 * Function : resources2res
1860 * Syntax : void resources2res(resource_t *top)
1862 * top - The resource-tree to convert
1864 * Description : Convert logical resource descriptors into binary data
1866 *****************************************************************************
1868 void resources2res(resource_t
*top
)
1876 top
->binres
= accelerator2res(top
->name
, top
->res
.acc
);
1880 top
->binres
= bitmap2res(top
->name
, top
->res
.bmp
);
1884 top
->binres
= cursor2res(top
->res
.cur
);
1888 top
->binres
= cursorgroup2res(top
->name
, top
->res
.curg
);
1892 top
->binres
= dialog2res(top
->name
, top
->res
.dlg
);
1896 top
->binres
= font2res(top
->name
, top
->res
.fnt
);
1900 top
->binres
= fontdir2res(top
->name
, top
->res
.fnd
);
1904 top
->binres
= icon2res(top
->res
.ico
);
1908 top
->binres
= icongroup2res(top
->name
, top
->res
.icog
);
1912 top
->binres
= menu2res(top
->name
, top
->res
.men
);
1916 top
->binres
= html2res(top
->name
, top
->res
.html
);
1920 top
->binres
= rcdata2res(top
->name
, top
->res
.rdt
);
1924 top
->binres
= stringtable2res(top
->res
.stt
);
1928 top
->binres
= user2res(top
->name
, top
->res
.usr
);
1932 top
->binres
= messagetable2res(top
->name
, top
->res
.msg
);
1936 top
->binres
= versioninfo2res(top
->name
, top
->res
.ver
);
1940 top
->binres
= toolbar2res(top
->name
, top
->res
.tbt
);
1944 top
->binres
= dlginit2res(top
->name
, top
->res
.dlgi
);
1949 top
->binres
= anicurico2res(top
->name
, top
->res
.ani
, top
->type
);
1952 internal_error(__FILE__
, __LINE__
, "Unknown resource type encountered %d in binary res generation\n", top
->type
);
1954 top
->c_name
= make_c_name(get_c_typename(top
->type
), top
->name
, top
->lan
);