winex11.drv: Map coordinates before calling send_mouse_input.
[wine/zf.git] / tools / wrc / genres.c
blob0950b3e9c3c24f863563c754da89144831c6f25c
1 /*
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
20 * History:
21 * 05-May-2000 BS - Added code to support endian conversions. The
22 * extra functions also aid unaligned access, but
23 * this is not yet implemented.
24 * 25-May-1998 BS - Added simple unicode -> char conversion for resource
25 * names in .s and .h files.
28 #include "config.h"
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <stdarg.h>
34 #include <assert.h>
35 #include <ctype.h>
37 #include "wrc.h"
38 #include "genres.h"
39 #include "utils.h"
40 #include "windef.h"
41 #include "winbase.h"
42 #include "wingdi.h"
43 #include "winuser.h"
45 res_t *new_res(void)
47 res_t *r;
48 r = xmalloc(sizeof(res_t));
49 r->allocsize = RES_BLOCKSIZE;
50 r->size = 0;
51 r->dataidx = 0;
52 r->data = xmalloc(RES_BLOCKSIZE);
53 return r;
56 res_t *grow_res(res_t *r, unsigned int add)
58 r->allocsize += add;
59 r->data = xrealloc(r->data, r->allocsize);
60 return r;
64 *****************************************************************************
65 * Function : put_byte
66 * put_word
67 * put_dword
68 * Syntax : void put_byte(res_t *res, unsigned c)
69 * void put_word(res_t *res, unsigned w)
70 * void put_dword(res_t *res, unsigned d)
71 * Input :
72 * res - Binary resource to put the data in
73 * c, w, d - Data to put
74 * Output : nop
75 * Description : Put primitives that put an item in the binary resource.
76 * The data array grows automatically.
77 * Remarks :
78 *****************************************************************************
80 void put_byte(res_t *res, unsigned c)
82 if(res->allocsize - res->size < sizeof(char))
83 grow_res(res, RES_BLOCKSIZE);
84 res->data[res->size] = (char)c;
85 res->size += sizeof(char);
88 void put_word(res_t *res, unsigned w)
90 if(res->allocsize - res->size < sizeof(WORD))
91 grow_res(res, RES_BLOCKSIZE);
92 switch(byteorder)
94 #ifdef WORDS_BIGENDIAN
95 default:
96 #endif
97 case WRC_BO_BIG:
98 res->data[res->size+0] = HIBYTE(w);
99 res->data[res->size+1] = LOBYTE(w);
100 break;
102 #ifndef WORDS_BIGENDIAN
103 default:
104 #endif
105 case WRC_BO_LITTLE:
106 res->data[res->size+1] = HIBYTE(w);
107 res->data[res->size+0] = LOBYTE(w);
108 break;
110 res->size += sizeof(WORD);
113 void put_dword(res_t *res, unsigned d)
115 if(res->allocsize - res->size < sizeof(DWORD))
116 grow_res(res, RES_BLOCKSIZE);
117 switch(byteorder)
119 #ifdef WORDS_BIGENDIAN
120 default:
121 #endif
122 case WRC_BO_BIG:
123 res->data[res->size+0] = HIBYTE(HIWORD(d));
124 res->data[res->size+1] = LOBYTE(HIWORD(d));
125 res->data[res->size+2] = HIBYTE(LOWORD(d));
126 res->data[res->size+3] = LOBYTE(LOWORD(d));
127 break;
129 #ifndef WORDS_BIGENDIAN
130 default:
131 #endif
132 case WRC_BO_LITTLE:
133 res->data[res->size+3] = HIBYTE(HIWORD(d));
134 res->data[res->size+2] = LOBYTE(HIWORD(d));
135 res->data[res->size+1] = HIBYTE(LOWORD(d));
136 res->data[res->size+0] = LOBYTE(LOWORD(d));
137 break;
139 res->size += sizeof(DWORD);
142 static void put_pad(res_t *res)
144 while(res->size & 0x3)
145 put_byte(res, 0);
149 *****************************************************************************
150 * Function : set_word
151 * set_dword
152 * Syntax : void set_word(res_t *res, int ofs, unsigned w)
153 * void set_dword(res_t *res, int ofs, unsigned d)
154 * Input :
155 * res - Binary resource to put the data in
156 * ofs - Byte offset in data-array
157 * w, d - Data to put
158 * Output : nop
159 * Description : Set the value of a binary resource data array to a
160 * specific value.
161 * Remarks :
162 *****************************************************************************
164 static void set_word(res_t *res, int ofs, unsigned w)
166 switch(byteorder)
168 #ifdef WORDS_BIGENDIAN
169 default:
170 #endif
171 case WRC_BO_BIG:
172 res->data[ofs+0] = HIBYTE(w);
173 res->data[ofs+1] = LOBYTE(w);
174 break;
176 #ifndef WORDS_BIGENDIAN
177 default:
178 #endif
179 case WRC_BO_LITTLE:
180 res->data[ofs+1] = HIBYTE(w);
181 res->data[ofs+0] = LOBYTE(w);
182 break;
186 static void set_dword(res_t *res, int ofs, unsigned d)
188 switch(byteorder)
190 #ifdef WORDS_BIGENDIAN
191 default:
192 #endif
193 case WRC_BO_BIG:
194 res->data[ofs+0] = HIBYTE(HIWORD(d));
195 res->data[ofs+1] = LOBYTE(HIWORD(d));
196 res->data[ofs+2] = HIBYTE(LOWORD(d));
197 res->data[ofs+3] = LOBYTE(LOWORD(d));
198 break;
200 #ifndef WORDS_BIGENDIAN
201 default:
202 #endif
203 case WRC_BO_LITTLE:
204 res->data[ofs+3] = HIBYTE(HIWORD(d));
205 res->data[ofs+2] = LOBYTE(HIWORD(d));
206 res->data[ofs+1] = HIBYTE(LOWORD(d));
207 res->data[ofs+0] = LOBYTE(LOWORD(d));
208 break;
213 *****************************************************************************
214 * Function : get_dword
215 * Input :
216 * res - Binary resource to put the data in
217 * ofs - Byte offset in data-array
218 * Output : The data in native endian
219 * Description : Get the value of a binary resource data array in native
220 * endian.
221 * Remarks :
222 *****************************************************************************
224 static DWORD get_dword(res_t *res, int ofs)
226 switch(byteorder)
228 #ifdef WORDS_BIGENDIAN
229 default:
230 #endif
231 case WRC_BO_BIG:
232 return (res->data[ofs+0] << 24)
233 | (res->data[ofs+1] << 16)
234 | (res->data[ofs+2] << 8)
235 | res->data[ofs+3];
237 #ifndef WORDS_BIGENDIAN
238 default:
239 #endif
240 case WRC_BO_LITTLE:
241 return (res->data[ofs+3] << 24)
242 | (res->data[ofs+2] << 16)
243 | (res->data[ofs+1] << 8)
244 | res->data[ofs+0];
248 static res_t *end_res(res_t *res, int ofs)
250 set_dword( res, ofs, res->size - get_dword( res, ofs ));
251 if (win32) put_pad( res );
252 return res;
256 *****************************************************************************
257 * Function : string_to_upper
258 * Syntax : void string_to_upper(string_t *str)
259 * Input :
260 * Output :
261 * Description :
262 * Remarks : FIXME: codepages...
263 *****************************************************************************
265 static void string_to_upper(string_t *str)
267 int i;
269 if(str->type == str_char)
271 for (i = 0; i < str->size; i++)
272 if (str->str.cstr[i] >= 'a' && str->str.cstr[i] <= 'z') str->str.cstr[i] -= 32;
274 else if(str->type == str_unicode)
276 for (i = 0; i < str->size; i++)
277 if (str->str.wstr[i] >= 'a' && str->str.wstr[i] <= 'z') str->str.wstr[i] -= 32;
279 else
281 internal_error(__FILE__, __LINE__, "Invalid string type %d\n", str->type);
285 static int parse_accel_string( const string_t *key, int flags )
287 int keycode;
289 if(key->type == str_char)
291 if (key->str.cstr[0] == '#') return 0; /* ignore message contexts */
292 if((flags & WRC_AF_VIRTKEY) &&
293 !((key->str.cstr[0] >= 'A' && key->str.cstr[0] <= 'Z') ||
294 (key->str.cstr[0] >= '0' && key->str.cstr[0] <= '9')))
296 print_location( &key->loc );
297 error("VIRTKEY code is not equal to ascii value\n");
300 if(key->str.cstr[0] == '^' && (flags & WRC_AF_CONTROL) != 0)
302 print_location( &key->loc );
303 error("Cannot use both '^' and CONTROL modifier\n");
305 else if(key->str.cstr[0] == '^')
307 if (key->str.cstr[1] >= 'a' && key->str.cstr[1] <= 'z')
308 keycode = key->str.cstr[1] - 'a' + 1;
309 else if (key->str.cstr[1] >= 'A' && key->str.cstr[1] <= 'Z')
310 keycode = key->str.cstr[1] - 'A' + 1;
311 else
313 print_location( &key->loc );
314 error("Control-code out of range\n");
317 else
318 keycode = key->str.cstr[0];
320 else
322 if (key->str.wstr[0] == '#') return 0; /* ignore message contexts */
323 if((flags & WRC_AF_VIRTKEY) &&
324 !((key->str.wstr[0] >= 'A' && key->str.wstr[0] <= 'Z') ||
325 (key->str.wstr[0] >= '0' && key->str.wstr[0] <= '9')))
327 print_location( &key->loc );
328 error("VIRTKEY code is not equal to ascii value\n");
330 if(key->str.wstr[0] == '^' && (flags & WRC_AF_CONTROL) != 0)
332 print_location( &key->loc );
333 error("Cannot use both '^' and CONTROL modifier\n");
335 else if(key->str.wstr[0] == '^')
337 if (key->str.wstr[1] >= 'a' && key->str.wstr[1] <= 'z')
338 keycode = key->str.wstr[1] - 'a' + 1;
339 else if (key->str.wstr[1] >= 'A' && key->str.wstr[1] <= 'Z')
340 keycode = key->str.wstr[1] - 'A' + 1;
341 else
343 print_location( &key->loc );
344 error("Control-code out of range\n");
347 else
348 keycode = key->str.wstr[0];
350 return keycode;
354 *****************************************************************************
355 * Function : put_string
356 * Input :
357 * res - Binary resource to put the data in
358 * str - String to put
359 * isterm - The string is '\0' terminated (disregard the string's
360 * size member)
361 *****************************************************************************
363 static void put_string(res_t *res, const string_t *str, int isterm, const language_t *lang)
365 int cnt, codepage;
367 if (win32)
369 string_t *newstr;
371 if (lang) codepage = get_language_codepage( lang->id, lang->sub );
372 else codepage = get_language_codepage( 0, 0 );
373 assert( codepage != -1 );
375 newstr = convert_string_unicode( str, codepage );
376 if (str->type == str_char && check_valid_utf8( str, codepage ))
378 print_location( &str->loc );
379 warning( "string \"%s\" seems to be UTF-8 but codepage %u is in use, maybe use --utf8?\n",
380 str->str.cstr, codepage );
382 if (!isterm) put_word(res, newstr->size);
383 for(cnt = 0; cnt < newstr->size; cnt++)
385 WCHAR c = newstr->str.wstr[cnt];
386 if (isterm && !c) break;
387 put_word(res, c);
389 if (isterm) put_word(res, 0);
390 free_string(newstr);
392 else
394 if (str->type == str_unicode)
395 internal_error(__FILE__, __LINE__, "Unicode string %s in 16-bit\n",
396 convert_string_utf8( str, 0 ));
397 if (!isterm) put_byte(res, str->size);
398 for(cnt = 0; cnt < str->size; cnt++)
400 char c = str->str.cstr[cnt];
401 if (isterm && !c) break;
402 put_byte(res, c);
404 if (isterm) put_byte(res, 0);
409 *****************************************************************************
410 * Function : put_name_id
411 * Syntax : void put_name_id(res_t *res, name_id_t *nid, int upcase, const language_t *lang)
412 * Input :
413 * Output :
414 * Description :
415 * Remarks :
416 *****************************************************************************
418 static void put_name_id(res_t *res, name_id_t *nid, int upcase, const language_t *lang)
420 if(nid->type == name_ord)
422 if(win32)
423 put_word(res, 0xffff);
424 else
425 put_byte(res, 0xff);
426 put_word(res, (WORD)nid->name.i_name);
428 else if(nid->type == name_str)
430 if(upcase)
431 string_to_upper(nid->name.s_name);
432 put_string(res, nid->name.s_name, TRUE, lang);
434 else
436 internal_error(__FILE__, __LINE__, "Invalid name_id type %d\n", nid->type);
441 *****************************************************************************
442 * Function : put_lvc
443 * Syntax : void put_lvc(res_t *res, lvc_t *lvc)
444 * Input :
445 * Output :
446 * Description :
447 * Remarks :
448 *****************************************************************************
450 static void put_lvc(res_t *res, lvc_t *lvc)
452 if(lvc && lvc->language)
453 put_word(res, MAKELANGID(lvc->language->id, lvc->language->sub));
454 else
455 put_word(res, 0); /* Neutral */
456 if(lvc && lvc->version)
457 put_dword(res, *(lvc->version));
458 else
459 put_dword(res, 0);
460 if(lvc && lvc->characts)
461 put_dword(res, *(lvc->characts));
462 else
463 put_dword(res, 0);
467 *****************************************************************************
468 * Function : put_raw_data
469 * Syntax : void put_raw_data(res_t *res, raw_data_t *raw, int offset)
470 * Input :
471 * Output :
472 * Description :
473 * Remarks :
474 *****************************************************************************
476 static void put_raw_data(res_t *res, raw_data_t *raw, int offset)
478 unsigned int wsize = raw->size - offset;
479 if(res->allocsize - res->size < wsize)
480 grow_res(res, wsize);
481 memcpy(&(res->data[res->size]), raw->data + offset, wsize);
482 res->size += wsize;
486 *****************************************************************************
487 * Function : put_res_header
488 * Syntax : input_res_header(res_t *res, int type, name_id_t *ntype,
489 * name_id_t *name, DWORD memopt, lvc_t *lvc)
491 * Input :
492 * res - Binary resource descriptor to write to
493 * type - Resource identifier (if ntype == NULL)
494 * ntype - Name id of type
495 * name - Resource's name
496 * memopt - Resource's memory options to write
497 * lvc - Language, version and characteristics (win32 only)
498 * Output : An index to the resource size field. The resource size field
499 * contains the header size upon exit.
500 * Description :
501 * Remarks :
502 *****************************************************************************
504 static int put_res_header(res_t *res, int type, name_id_t *ntype, name_id_t *name,
505 DWORD memopt, lvc_t *lvc)
507 if(win32)
509 put_dword(res, 0); /* We will overwrite these later */
510 put_dword(res, 0);
511 if(!ntype)
513 put_word(res, 0xffff); /* ResType */
514 put_word(res, type);
516 else
517 put_name_id(res, ntype, TRUE, lvc->language);
518 put_name_id(res, name, TRUE, lvc->language); /* ResName */
519 put_pad(res);
520 put_dword(res, 0); /* DataVersion */
521 put_word(res, memopt); /* Memory options */
522 put_lvc(res, lvc); /* Language, version and characts */
523 set_dword(res, 0*sizeof(DWORD), res->size); /* Set preliminary resource */
524 set_dword(res, 1*sizeof(DWORD), res->size); /* Set HeaderSize */
525 res->dataidx = res->size;
526 return 0;
528 else /* win16 */
530 int tag;
531 if(!ntype)
533 put_byte(res, 0xff); /* ResType */
534 put_word(res, type);
536 else
537 put_name_id(res, ntype, TRUE, NULL);
538 put_name_id(res, name, TRUE, NULL); /* ResName */
539 put_word(res, memopt); /* Memory options */
540 tag = res->size;
541 put_dword(res, 0); /* ResSize overwritten later*/
542 set_dword(res, tag, res->size);
543 res->dataidx = res->size;
544 return tag;
549 *****************************************************************************
550 * Function : accelerator2res
551 * Syntax : res_t *accelerator2res(name_id_t *name, accelerator_t *acc)
552 * Input :
553 * name - Name/ordinal of the resource
554 * acc - The accelerator descriptor
555 * Output : New .res format structure
556 * Description :
557 * Remarks :
558 *****************************************************************************
560 static res_t *accelerator2res(name_id_t *name, accelerator_t *acc)
562 int restag;
563 res_t *res;
564 event_t *ev;
565 assert(name != NULL);
566 assert(acc != NULL);
568 ev = acc->events;
569 res = new_res();
570 if(win32)
572 restag = put_res_header(res, WRC_RT_ACCELERATOR, NULL, name, acc->memopt, &(acc->lvc));
573 while(ev)
575 int key = ev->key;
576 if (ev->str) key = parse_accel_string( ev->str, ev->flags );
577 put_word(res, ev->flags | (ev->next ? 0 : 0x80));
578 put_word(res, key);
579 put_word(res, ev->id);
580 put_word(res, 0); /* Padding */
581 ev = ev->next;
583 put_pad(res);
585 else /* win16 */
587 restag = put_res_header(res, WRC_RT_ACCELERATOR, NULL, name, acc->memopt, NULL);
588 while(ev)
590 int key = ev->key;
591 if (ev->str) key = parse_accel_string( ev->str, ev->flags );
592 put_byte(res, ev->flags | (ev->next ? 0 : 0x80));
593 put_word(res, key);
594 put_word(res, ev->id);
595 ev = ev->next;
598 return end_res(res, restag);
602 *****************************************************************************
603 * Function : dialog2res
604 * Syntax : res_t *dialog2res(name_id_t *name, dialog_t *dlg)
605 * Input :
606 * name - Name/ordinal of the resource
607 * dlg - The dialog descriptor
608 * Output : New .res format structure
609 * Description :
610 * Remarks :
611 *****************************************************************************
613 static res_t *dialog2res(name_id_t *name, dialog_t *dlg)
615 int restag;
616 res_t *res;
617 control_t *ctrl;
618 int tag_nctrl;
619 int nctrl = 0;
620 assert(name != NULL);
621 assert(dlg != NULL);
623 ctrl = dlg->controls;
624 res = new_res();
625 if(win32)
627 restag = put_res_header(res, WRC_RT_DIALOG, NULL, name, dlg->memopt, &(dlg->lvc));
629 if (dlg->is_ex)
631 /* FIXME: MS doc says that the first word must contain 0xffff
632 * and the second 0x0001 to signal a DLGTEMPLATEEX. Borland's
633 * compiler reverses the two words.
634 * I don't know which one to choose, but I write it as Mr. B
635 * writes it.
637 put_word(res, 1); /* Signature */
638 put_word(res, 0xffff); /* DlgVer */
639 put_dword(res, dlg->gothelpid ? dlg->helpid : 0);
640 put_dword(res, dlg->gotexstyle ? dlg->exstyle->or_mask : 0);
641 put_dword(res, dlg->gotstyle ? dlg->style->or_mask : WS_POPUPWINDOW);
643 else
645 put_dword(res, dlg->style->or_mask);
646 put_dword(res, dlg->gotexstyle ? dlg->exstyle->or_mask : 0);
648 tag_nctrl = res->size;
649 put_word(res, 0); /* Number of controls */
650 put_word(res, dlg->x);
651 put_word(res, dlg->y);
652 put_word(res, dlg->width);
653 put_word(res, dlg->height);
654 if(dlg->menu)
655 put_name_id(res, dlg->menu, FALSE, dlg->lvc.language);
656 else
657 put_word(res, 0);
658 if(dlg->dlgclass)
659 put_name_id(res, dlg->dlgclass, FALSE, dlg->lvc.language);
660 else
661 put_word(res, 0);
662 if(dlg->title)
663 put_string(res, dlg->title, TRUE, dlg->lvc.language);
664 else
665 put_word(res, 0);
666 if(dlg->font)
668 put_word(res, dlg->font->size);
669 if (dlg->is_ex)
671 put_word(res, dlg->font->weight);
672 /* FIXME: ? TRUE should be sufficient to say that it's
673 * italic, but Borland's compiler says it's 0x0101.
674 * I just copy it here, and hope for the best.
676 put_word(res, dlg->font->italic ? 0x0101 : 0);
678 put_string(res, dlg->font->name, TRUE, dlg->lvc.language);
680 else if (dlg->style->or_mask & DS_SETFONT) put_word( res, 0x7fff );
682 put_pad(res);
683 while(ctrl)
685 if (dlg->is_ex)
687 put_dword(res, ctrl->gothelpid ? ctrl->helpid : 0);
688 put_dword(res, ctrl->gotexstyle ? ctrl->exstyle->or_mask : 0);
689 /* FIXME: what is default control style? */
690 put_dword(res, ctrl->gotstyle ? ctrl->style->or_mask : WS_CHILD | WS_VISIBLE);
692 else
694 /* FIXME: what is default control style? */
695 put_dword(res, ctrl->gotstyle ? ctrl->style->or_mask: WS_CHILD);
696 put_dword(res, ctrl->gotexstyle ? ctrl->exstyle->or_mask : 0);
698 put_word(res, ctrl->x);
699 put_word(res, ctrl->y);
700 put_word(res, ctrl->width);
701 put_word(res, ctrl->height);
702 if (dlg->is_ex)
703 put_dword(res, ctrl->id);
704 else
705 put_word(res, ctrl->id);
706 if(ctrl->ctlclass)
707 put_name_id(res, ctrl->ctlclass, FALSE, dlg->lvc.language);
708 else
709 internal_error(__FILE__, __LINE__, "Control has no control-class\n");
710 if(ctrl->title)
711 put_name_id(res, ctrl->title, FALSE, dlg->lvc.language);
712 else
713 put_word(res, 0);
714 if(ctrl->extra)
716 put_word(res, ctrl->extra->size);
717 put_raw_data(res, ctrl->extra, 0);
719 else
720 put_word(res, 0);
722 if(ctrl->next)
723 put_pad(res);
724 nctrl++;
725 ctrl = ctrl->next;
727 /* Set number of controls */
728 set_word(res, tag_nctrl, (WORD)nctrl);
730 else /* win16 */
732 restag = put_res_header(res, WRC_RT_DIALOG, NULL, name, dlg->memopt, NULL);
734 put_dword(res, dlg->gotstyle ? dlg->style->or_mask : WS_POPUPWINDOW);
735 tag_nctrl = res->size;
736 put_byte(res, 0); /* Number of controls */
737 put_word(res, dlg->x);
738 put_word(res, dlg->y);
739 put_word(res, dlg->width);
740 put_word(res, dlg->height);
741 if(dlg->menu)
742 put_name_id(res, dlg->menu, TRUE, NULL);
743 else
744 put_byte(res, 0);
745 if(dlg->dlgclass)
746 put_name_id(res, dlg->dlgclass, TRUE, NULL);
747 else
748 put_byte(res, 0);
749 if(dlg->title)
750 put_string(res, dlg->title, TRUE, NULL);
751 else
752 put_byte(res, 0);
753 if(dlg->font)
755 put_word(res, dlg->font->size);
756 put_string(res, dlg->font->name, TRUE, NULL);
759 while(ctrl)
761 put_word(res, ctrl->x);
762 put_word(res, ctrl->y);
763 put_word(res, ctrl->width);
764 put_word(res, ctrl->height);
765 put_word(res, ctrl->id);
766 put_dword(res, ctrl->gotstyle ? ctrl->style->or_mask: WS_CHILD);
767 if(ctrl->ctlclass)
769 if(ctrl->ctlclass->type == name_ord
770 && ctrl->ctlclass->name.i_name >= 0x80
771 && ctrl->ctlclass->name.i_name <= 0x85)
772 put_byte(res, ctrl->ctlclass->name.i_name);
773 else if(ctrl->ctlclass->type == name_str)
774 put_name_id(res, ctrl->ctlclass, FALSE, NULL);
775 else
776 error("Unknown control-class %04x\n", ctrl->ctlclass->name.i_name);
778 else
779 internal_error(__FILE__, __LINE__, "Control has no control-class\n");
780 if(ctrl->title)
781 put_name_id(res, ctrl->title, FALSE, NULL);
782 else
783 put_byte(res, 0);
785 /* FIXME: What is this extra byte doing here? */
786 put_byte(res, 0);
788 nctrl++;
789 ctrl = ctrl->next;
791 /* Set number of controls */
792 ((char *)res->data)[tag_nctrl] = (char)nctrl;
794 return end_res(res, restag);
798 *****************************************************************************
799 * Function : menuitem2res
800 * Syntax : void menuitem2res(res_t *res, menu_item_t *item)
801 * Input :
802 * Output :
803 * Description :
804 * Remarks : Self recursive
805 *****************************************************************************
807 static void menuitem2res(res_t *res, menu_item_t *menitem, const language_t *lang)
809 menu_item_t *itm = menitem;
811 while(itm)
813 put_word(res, itm->state | (itm->popup ? MF_POPUP : 0) | (!itm->next ? MF_END : 0));
814 if(!itm->popup)
815 put_word(res, itm->id);
816 if(itm->name)
817 put_string(res, itm->name, TRUE, lang);
818 else
820 if (win32) put_word(res, 0);
821 else put_byte(res, 0);
823 if(itm->popup)
824 menuitem2res(res, itm->popup, lang);
825 itm = itm->next;
830 *****************************************************************************
831 * Function : menuexitem2res
832 * Syntax : void menuexitem2res(res_t *res, menuex_item_t *item)
833 * Input :
834 * Output : nop
835 * Description :
836 * Remarks : Self recursive
837 *****************************************************************************
839 static void menuexitem2res(res_t *res, menu_item_t *menitem, const language_t *lang)
841 menu_item_t *itm = menitem;
842 assert(win32 != 0);
843 while(itm)
845 put_dword(res, itm->gottype ? itm->type : 0);
846 put_dword(res, itm->gotstate ? itm->state : 0);
847 put_dword(res, itm->gotid ? itm->id : 0);
848 put_word(res, (itm->popup ? 0x01 : 0) | (!itm->next ? MF_END : 0));
849 if(itm->name)
850 put_string(res, itm->name, TRUE, lang);
851 else
852 put_word(res, 0);
853 put_pad(res);
854 if(itm->popup)
856 put_dword(res, itm->gothelpid ? itm->helpid : 0);
857 menuexitem2res(res, itm->popup, lang);
859 itm = itm->next;
865 *****************************************************************************
866 * Function : menu2res
867 * Syntax : res_t *menu2res(name_id_t *name, menu_t *men)
868 * Input :
869 * name - Name/ordinal of the resource
870 * menex - The menuex descriptor
871 * Output : New .res format structure
872 * Description :
873 * Remarks :
874 *****************************************************************************
876 static res_t *menu2res(name_id_t *name, menu_t *men)
878 int restag;
879 res_t *res;
880 assert(name != NULL);
881 assert(men != NULL);
883 res = new_res();
884 restag = put_res_header(res, WRC_RT_MENU, NULL, name, men->memopt, &men->lvc);
885 if(win32)
887 if (men->is_ex)
889 put_word(res, 1); /* Menuheader: Version */
890 put_word(res, 4); /* Offset */
891 put_dword(res, 0); /* HelpId */
892 put_pad(res);
893 menuexitem2res(res, men->items, men->lvc.language);
895 else
897 put_dword(res, 0); /* Menuheader: Version and HeaderSize */
898 menuitem2res(res, men->items, men->lvc.language);
901 else /* win16 */
903 put_dword(res, 0); /* Menuheader: Version and HeaderSize */
904 menuitem2res(res, men->items, NULL);
906 return end_res(res, restag);
910 *****************************************************************************
911 * Function : cursorgroup2res
912 * Syntax : res_t *cursorgroup2res(name_id_t *name, cursor_group_t *curg)
913 * Input :
914 * name - Name/ordinal of the resource
915 * curg - The cursor descriptor
916 * Output : New .res format structure
917 * Description :
918 * Remarks :
919 *****************************************************************************
921 static res_t *cursorgroup2res(name_id_t *name, cursor_group_t *curg)
923 int restag;
924 res_t *res;
925 cursor_t *cur;
926 assert(name != NULL);
927 assert(curg != NULL);
929 res = new_res();
930 restag = put_res_header(res, WRC_RT_GROUP_CURSOR, NULL, name, curg->memopt, &(curg->lvc));
932 put_word(res, 0); /* Reserved */
933 /* FIXME: The ResType in the NEWHEADER structure should
934 * contain 14 according to the MS win32 doc. This is
935 * not the case with the BRC compiler and I really doubt
936 * the latter. Putting one here is compliant to win16 spec,
937 * but who knows the true value?
939 put_word(res, 2); /* ResType */
940 put_word(res, curg->ncursor);
941 #if 0
942 for(cur = curg->cursorlist; cur; cur = cur->next)
943 #else
944 cur = curg->cursorlist;
945 while(cur->next)
946 cur = cur->next;
947 for(; cur; cur = cur->prev)
948 #endif
950 put_word(res, cur->width);
951 /* FIXME: The height of a cursor is half the size of
952 * the bitmap's height. BRC puts the height from the
953 * BITMAPINFOHEADER here instead of the cursorfile's
954 * height. MS doesn't seem to care...
956 put_word(res, cur->height);
957 /* FIXME: The next two are reversed in BRC and I don't
958 * know why. Probably a bug. But, we can safely ignore
959 * it because win16 does not support color cursors.
960 * A warning should have been generated by the parser.
962 put_word(res, cur->planes);
963 put_word(res, cur->bits);
964 /* FIXME: The +4 is the hotspot in the cursor resource.
965 * However, I could not find this in the documentation.
966 * The hotspot bytes must either be included or MS
967 * doesn't care.
969 put_dword(res, cur->data->size +4);
970 put_word(res, cur->id);
973 return end_res(res, restag);
977 *****************************************************************************
978 * Function : cursor2res
979 * Syntax : res_t *cursor2res(cursor_t *cur)
980 * Input :
981 * cur - The cursor descriptor
982 * Output : New .res format structure
983 * Description :
984 * Remarks :
985 *****************************************************************************
987 static res_t *cursor2res(cursor_t *cur)
989 int restag;
990 res_t *res;
991 name_id_t name;
993 assert(cur != NULL);
995 res = new_res();
996 name.type = name_ord;
997 name.name.i_name = cur->id;
998 restag = put_res_header(res, WRC_RT_CURSOR, NULL, &name, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, &(cur->lvc));
999 put_word(res, cur->xhot);
1000 put_word(res, cur->yhot);
1001 put_raw_data(res, cur->data, 0);
1003 return end_res(res, restag);
1007 *****************************************************************************
1008 * Function : icongroup2res
1009 * Syntax : res_t *icongroup2res(name_id_t *name, icon_group_t *icog)
1010 * Input :
1011 * name - Name/ordinal of the resource
1012 * icog - The icon group descriptor
1013 * Output : New .res format structure
1014 * Description :
1015 * Remarks :
1016 *****************************************************************************
1018 static res_t *icongroup2res(name_id_t *name, icon_group_t *icog)
1020 int restag;
1021 res_t *res;
1022 icon_t *ico;
1023 assert(name != NULL);
1024 assert(icog != NULL);
1026 res = new_res();
1027 restag = put_res_header(res, WRC_RT_GROUP_ICON, NULL, name, icog->memopt, &(icog->lvc));
1029 put_word(res, 0); /* Reserved */
1030 /* FIXME: The ResType in the NEWHEADER structure should
1031 * contain 14 according to the MS win32 doc. This is
1032 * not the case with the BRC compiler and I really doubt
1033 * the latter. Putting one here is compliant to win16 spec,
1034 * but who knows the true value?
1036 put_word(res, 1); /* ResType */
1037 put_word(res, icog->nicon);
1038 for(ico = icog->iconlist; ico; ico = ico->next)
1040 put_byte(res, ico->width);
1041 put_byte(res, ico->height);
1042 put_byte(res, ico->nclr);
1043 put_byte(res, 0); /* Reserved */
1044 put_word(res, ico->planes);
1045 put_word(res, ico->bits);
1046 put_dword(res, ico->data->size);
1047 put_word(res, ico->id);
1050 return end_res(res, restag);
1054 *****************************************************************************
1055 * Function : icon2res
1056 * Syntax : res_t *icon2res(icon_t *ico)
1057 * Input :
1058 * ico - The icon descriptor
1059 * Output : New .res format structure
1060 * Description :
1061 * Remarks :
1062 *****************************************************************************
1064 static res_t *icon2res(icon_t *ico)
1066 int restag;
1067 res_t *res;
1068 name_id_t name;
1070 assert(ico != NULL);
1072 res = new_res();
1073 name.type = name_ord;
1074 name.name.i_name = ico->id;
1075 restag = put_res_header(res, WRC_RT_ICON, NULL, &name, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, &(ico->lvc));
1076 put_raw_data(res, ico->data, 0);
1078 return end_res(res, restag);
1082 *****************************************************************************
1083 * Function : anicurico2res
1084 * Syntax : res_t *anicurico2res(name_id_t *name, ani_curico_t *ani)
1085 * Input :
1086 * name - Name/ordinal of the resource
1087 * ani - The animated object descriptor
1088 * Output : New .res format structure
1089 * Description :
1090 * Remarks : The endian of the object's structures have been converted
1091 * by the loader.
1092 * There are rumors that win311 could handle animated stuff.
1093 * That is why they are generated for both win16 and win32
1094 * compile.
1095 *****************************************************************************
1097 static res_t *anicurico2res(name_id_t *name, ani_curico_t *ani, enum res_e type)
1099 int restag;
1100 res_t *res;
1101 assert(name != NULL);
1102 assert(ani != NULL);
1104 res = new_res();
1105 restag = put_res_header(res, type == res_anicur ? WRC_RT_ANICURSOR : WRC_RT_ANIICON,
1106 NULL, name, ani->memopt, NULL);
1107 put_raw_data(res, ani->data, 0);
1108 return end_res(res, restag);
1112 *****************************************************************************
1113 * Function : bitmap2res
1114 * Syntax : res_t *bitmap2res(name_id_t *name, bitmap_t *bmp)
1115 * Input :
1116 * name - Name/ordinal of the resource
1117 * bmp - The bitmap descriptor
1118 * Output : New .res format structure
1119 * Description :
1120 * Remarks : The endian of the bitmap structures have been converted
1121 * by the loader.
1122 *****************************************************************************
1124 static res_t *bitmap2res(name_id_t *name, bitmap_t *bmp)
1126 int restag;
1127 res_t *res;
1128 assert(name != NULL);
1129 assert(bmp != NULL);
1131 res = new_res();
1132 restag = put_res_header(res, WRC_RT_BITMAP, NULL, name, bmp->memopt, &(bmp->data->lvc));
1133 if(bmp->data->data[0] == 'B'
1134 && bmp->data->data[1] == 'M'
1135 && ((BITMAPFILEHEADER *)bmp->data->data)->bfSize == bmp->data->size
1136 && bmp->data->size >= sizeof(BITMAPFILEHEADER))
1138 /* The File header is still attached, don't write it */
1139 put_raw_data(res, bmp->data, sizeof(BITMAPFILEHEADER));
1141 else
1143 put_raw_data(res, bmp->data, 0);
1145 return end_res(res, restag);
1149 *****************************************************************************
1150 * Function : font2res
1151 * Syntax : res_t *font2res(name_id_t *name, font_t *fnt)
1152 * Input :
1153 * name - Name/ordinal of the resource
1154 * fnt - The font descriptor
1155 * Output : New .res format structure
1156 * Description :
1157 * Remarks : The data has been prepared just after parsing.
1158 *****************************************************************************
1160 static res_t *font2res(name_id_t *name, font_t *fnt)
1162 int restag;
1163 res_t *res;
1164 assert(name != NULL);
1165 assert(fnt != NULL);
1167 res = new_res();
1168 restag = put_res_header(res, WRC_RT_FONT, NULL, name, fnt->memopt, &(fnt->data->lvc));
1169 put_raw_data(res, fnt->data, 0);
1170 return end_res(res, restag);
1174 *****************************************************************************
1175 * Function : fontdir2res
1176 * Syntax : res_t *fontdir2res(name_id_t *name, fontdir_t *fnd)
1177 * Input :
1178 * name - Name/ordinal of the resource
1179 * fntdir - The fontdir descriptor
1180 * Output : New .res format structure
1181 * Description :
1182 * Remarks : The data has been prepared just after parsing.
1183 *****************************************************************************
1185 static res_t *fontdir2res(name_id_t *name, fontdir_t *fnd)
1187 int restag;
1188 res_t *res;
1189 assert(name != NULL);
1190 assert(fnd != NULL);
1192 res = new_res();
1193 restag = put_res_header(res, WRC_RT_FONTDIR, NULL, name, fnd->memopt, &(fnd->data->lvc));
1194 put_raw_data(res, fnd->data, 0);
1195 return end_res(res, restag);
1199 *****************************************************************************
1200 * Function : html2res
1201 * Syntax : res_t *html2res(name_id_t *name, html_t *html)
1202 * Input :
1203 * name - Name/ordinal of the resource
1204 * rdt - The html descriptor
1205 * Output : New .res format structure
1206 * Description :
1207 * Remarks :
1208 *****************************************************************************
1210 static res_t *html2res(name_id_t *name, html_t *html)
1212 int restag;
1213 res_t *res;
1214 assert(name != NULL);
1215 assert(html != NULL);
1217 res = new_res();
1218 restag = put_res_header(res, WRC_RT_HTML, NULL, name, html->memopt, &(html->data->lvc));
1219 put_raw_data(res, html->data, 0);
1220 return end_res(res, restag);
1224 *****************************************************************************
1225 * Function : rcdata2res
1226 * Syntax : res_t *rcdata2res(name_id_t *name, rcdata_t *rdt)
1227 * Input :
1228 * name - Name/ordinal of the resource
1229 * rdt - The rcdata descriptor
1230 * Output : New .res format structure
1231 * Description :
1232 * Remarks :
1233 *****************************************************************************
1235 static res_t *rcdata2res(name_id_t *name, rcdata_t *rdt)
1237 int restag;
1238 res_t *res;
1239 assert(name != NULL);
1240 assert(rdt != NULL);
1242 res = new_res();
1243 restag = put_res_header(res, WRC_RT_RCDATA, NULL, name, rdt->memopt, &(rdt->data->lvc));
1244 put_raw_data(res, rdt->data, 0);
1245 return end_res(res, restag);
1249 *****************************************************************************
1250 * Function : messagetable2res
1251 * Syntax : res_t *messagetable2res(name_id_t *name, messagetable_t *msg)
1252 * Input :
1253 * name - Name/ordinal of the resource
1254 * msg - The messagetable descriptor
1255 * Output : New .res format structure
1256 * Description :
1257 * Remarks : The data has been converted to the appropriate endian
1258 * after it was parsed.
1259 *****************************************************************************
1261 static res_t *messagetable2res(name_id_t *name, messagetable_t *msg)
1263 int restag;
1264 res_t *res;
1265 assert(name != NULL);
1266 assert(msg != NULL);
1268 res = new_res();
1269 restag = put_res_header(res, WRC_RT_MESSAGETABLE, NULL, name, msg->memopt, &(msg->data->lvc));
1270 put_raw_data(res, msg->data, 0);
1271 return end_res(res, restag);
1275 *****************************************************************************
1276 * Function : stringtable2res
1277 * Syntax : res_t *stringtable2res(stringtable_t *stt)
1278 * Input :
1279 * stt - The stringtable descriptor
1280 * Output : New .res format structure
1281 * Description :
1282 * Remarks :
1283 *****************************************************************************
1285 static res_t *stringtable2res(stringtable_t *stt)
1287 res_t *res;
1288 name_id_t name;
1289 int i;
1290 int restag;
1291 DWORD lastsize = 0;
1293 assert(stt != NULL);
1294 res = new_res();
1296 for(; stt; stt = stt->next)
1298 if(!stt->nentries)
1300 warning("Empty internal stringtable\n");
1301 continue;
1303 name.type = name_ord;
1304 name.name.i_name = (stt->idbase >> 4) + 1;
1305 restag = put_res_header(res, WRC_RT_STRING, NULL, &name, stt->memopt, win32 ? &(stt->lvc) : NULL);
1306 for(i = 0; i < stt->nentries; i++)
1308 if(stt->entries[i].str && stt->entries[i].str->size)
1310 put_string(res, stt->entries[i].str, FALSE, stt->lvc.language);
1312 else
1314 if (win32)
1315 put_word(res, 0);
1316 else
1317 put_byte(res, 0);
1320 end_res(res, restag - lastsize);
1321 lastsize = res->size;
1323 return res;
1327 *****************************************************************************
1328 * Function : user2res
1329 * Syntax : res_t *user2res(name_id_t *name, user_t *usr)
1330 * Input :
1331 * name - Name/ordinal of the resource
1332 * usr - The userresource descriptor
1333 * Output : New .res format structure
1334 * Description :
1335 * Remarks :
1336 *****************************************************************************
1338 static res_t *user2res(name_id_t *name, user_t *usr)
1340 int restag;
1341 res_t *res;
1342 assert(name != NULL);
1343 assert(usr != NULL);
1345 res = new_res();
1346 restag = put_res_header(res, 0, usr->type, name, usr->memopt, &(usr->data->lvc));
1347 put_raw_data(res, usr->data, 0);
1348 return end_res(res, restag);
1352 *****************************************************************************
1353 * Function : versionblock2res
1354 * Syntax : void versionblock2res(res_t *res, ver_block_t *blk)
1355 * Input :
1356 * res - Binary resource to write to
1357 * blk - The version block to be written
1358 * Output :
1359 * Description :
1360 * Remarks : Self recursive
1361 *****************************************************************************
1363 static void versionblock2res(res_t *res, ver_block_t *blk, int level, const language_t *lang)
1365 ver_value_t *val;
1366 int blksizetag;
1367 int valblksizetag;
1368 int valvalsizetag;
1369 int tag;
1370 int i;
1372 blksizetag = res->size;
1373 put_word(res, 0); /* Will be overwritten later */
1374 put_word(res, 0);
1375 if(win32)
1376 put_word(res, 0); /* level ? */
1377 put_string(res, blk->name, TRUE, NULL);
1378 put_pad(res);
1379 for(val = blk->values; val; val = val->next)
1381 if(val->type == val_str)
1383 valblksizetag = res->size;
1384 put_word(res, 0); /* Will be overwritten later */
1385 valvalsizetag = res->size;
1386 put_word(res, 0); /* Will be overwritten later */
1387 if(win32)
1389 put_word(res, level);
1391 put_string(res, val->key, TRUE, NULL);
1392 put_pad(res);
1393 tag = res->size;
1394 put_string(res, val->value.str, TRUE, lang);
1395 if(win32)
1396 set_word(res, valvalsizetag, (WORD)((res->size - tag) >> 1));
1397 else
1398 set_word(res, valvalsizetag, (WORD)(res->size - tag));
1399 set_word(res, valblksizetag, (WORD)(res->size - valblksizetag));
1400 put_pad(res);
1402 else if(val->type == val_words)
1404 valblksizetag = res->size;
1405 put_word(res, 0); /* Will be overwritten later */
1406 valvalsizetag = res->size;
1407 put_word(res, 0); /* Will be overwritten later */
1408 if(win32)
1410 put_word(res, level);
1412 put_string(res, val->key, TRUE, NULL);
1413 put_pad(res);
1414 tag = res->size;
1415 for(i = 0; i < val->value.words->nwords; i++)
1417 put_word(res, val->value.words->words[i]);
1419 set_word(res, valvalsizetag, (WORD)(res->size - tag));
1420 set_word(res, valblksizetag, (WORD)(res->size - valblksizetag));
1421 put_pad(res);
1423 else if(val->type == val_block)
1425 versionblock2res(res, val->value.block, level+1, lang);
1427 else
1429 internal_error(__FILE__, __LINE__, "Invalid value indicator %d in VERSIONINFO\n", val->type);
1433 /* Set blocksize */
1434 set_word(res, blksizetag, (WORD)(res->size - blksizetag));
1438 *****************************************************************************
1439 * Function : versioninfo2res
1440 * Syntax : res_t *versioninfo2res(name_id_t *name, versioninfo_t *ver)
1441 * Input :
1442 * name - Name/ordinal of the resource
1443 * ver - The versioninfo descriptor
1444 * Output : New .res format structure
1445 * Description :
1446 * Remarks :
1447 *****************************************************************************
1449 static res_t *versioninfo2res(name_id_t *name, versioninfo_t *ver)
1451 static const char info[] = "VS_VERSION_INFO";
1452 unsigned int i;
1453 int restag, rootblocksizetag, valsizetag, tag;
1454 res_t *res;
1455 ver_block_t *blk;
1457 assert(name != NULL);
1458 assert(ver != NULL);
1460 res = new_res();
1461 restag = put_res_header(res, WRC_RT_VERSION, NULL, name, ver->memopt, &(ver->lvc));
1462 rootblocksizetag = res->size;
1463 put_word(res, 0); /* BlockSize filled in later */
1464 valsizetag = res->size;
1465 put_word(res, 0); /* ValueSize filled in later*/
1466 if(win32)
1468 put_word(res, 0); /* Tree-level ? */
1469 for (i = 0; i < sizeof(info); i++) put_word(res, info[i]);
1470 put_pad(res);
1472 else
1474 for (i = 0; i < sizeof(info); i++) put_byte(res, info[i]);
1476 tag = res->size;
1477 put_dword(res, VS_FFI_SIGNATURE);
1478 put_dword(res, VS_FFI_STRUCVERSION);
1479 put_dword(res, (ver->filever_maj1 << 16) + (ver->filever_maj2 & 0xffff));
1480 put_dword(res, (ver->filever_min1 << 16) + (ver->filever_min2 & 0xffff));
1481 put_dword(res, (ver->prodver_maj1 << 16) + (ver->prodver_maj2 & 0xffff));
1482 put_dword(res, (ver->prodver_min1 << 16) + (ver->prodver_min2 & 0xffff));
1483 put_dword(res, ver->fileflagsmask);
1484 put_dword(res, ver->fileflags);
1485 put_dword(res, ver->fileos);
1486 put_dword(res, ver->filetype);
1487 put_dword(res, ver->filesubtype);
1488 put_dword(res, 0); /* FileDateMS */
1489 put_dword(res, 0); /* FileDateLS */
1490 /* Set ValueSize */
1491 set_word(res, valsizetag, (WORD)(res->size - tag));
1492 /* Descend into the blocks */
1493 for(blk = ver->blocks; blk; blk = blk->next)
1494 versionblock2res(res, blk, 0, win32 ? ver->lvc.language : NULL);
1495 /* Set root block's size */
1496 set_word(res, rootblocksizetag, (WORD)(res->size - rootblocksizetag));
1497 return end_res(res, restag);
1501 *****************************************************************************
1502 * Function : toolbaritem2res
1503 * Syntax : void toolbaritem2res(res_t *res, toolbar_item_t *tbitem)
1504 * Input :
1505 * Output : nop
1506 * Description :
1507 * Remarks : Self recursive
1508 *****************************************************************************
1510 static void toolbaritem2res(res_t *res, toolbar_item_t *tbitem)
1512 toolbar_item_t *itm = tbitem;
1513 assert(win32 != 0);
1514 while(itm)
1516 put_word(res, itm->id);
1517 itm = itm->next;
1523 *****************************************************************************
1524 * Function : toolbar2res
1525 * Syntax : res_t *toolbar2res(name_id_t *name, toolbar_t *toolbar)
1526 * Input :
1527 * name - Name/ordinal of the resource
1528 * toolbar - The toolbar descriptor
1529 * Output : New .res format structure
1530 * Description :
1531 * Remarks :
1532 *****************************************************************************
1534 static res_t *toolbar2res(name_id_t *name, toolbar_t *toolbar)
1536 int restag;
1537 res_t *res;
1538 assert(name != NULL);
1539 assert(toolbar != NULL);
1541 if (!win32) return NULL;
1543 res = new_res();
1544 restag = put_res_header(res, WRC_RT_TOOLBAR, NULL, name, toolbar->memopt, &(toolbar->lvc));
1546 put_word(res, 1); /* Menuheader: Version */
1547 put_word(res, toolbar->button_width); /* (in pixels?) */
1548 put_word(res, toolbar->button_height); /* (in pixels?) */
1549 put_word(res, toolbar->nitems);
1550 put_pad(res);
1551 toolbaritem2res(res, toolbar->items);
1552 return end_res(res, restag);
1556 *****************************************************************************
1557 * Function : dlginit2res
1558 * Syntax : res_t *dlginit2res(name_id_t *name, dlginit_t *dit)
1559 * Input :
1560 * name - Name/ordinal of the resource
1561 * rdt - The dlginit descriptor
1562 * Output : New .res format structure
1563 * Description :
1564 * Remarks :
1565 *****************************************************************************
1567 static res_t *dlginit2res(name_id_t *name, dlginit_t *dit)
1569 int restag;
1570 res_t *res;
1571 assert(name != NULL);
1572 assert(dit != NULL);
1574 res = new_res();
1575 restag = put_res_header(res, WRC_RT_DLGINIT, NULL, name, dit->memopt, &(dit->data->lvc));
1576 put_raw_data(res, dit->data, 0);
1577 return end_res(res, restag);
1581 *****************************************************************************
1582 * Function : prep_nid_for_label
1583 * Syntax : char *prep_nid_for_label(const name_id_t *nid)
1584 * Input :
1585 * Output :
1586 * Description : Converts a resource name into the first 32 (or less)
1587 * characters of the name with conversions.
1588 * Remarks :
1589 *****************************************************************************
1591 #define MAXNAMELEN 32
1592 char *prep_nid_for_label(const name_id_t *nid)
1594 static char buf[MAXNAMELEN+1];
1596 assert(nid != NULL);
1598 if(nid->type == name_str && nid->name.s_name->type == str_unicode)
1600 WCHAR *sptr;
1601 int i;
1602 sptr = nid->name.s_name->str.wstr;
1603 buf[0] = '\0';
1604 for(i = 0; *sptr && i < MAXNAMELEN; i++)
1606 if((unsigned)*sptr < 0x80 && isprint(*sptr & 0xff))
1607 buf[i] = *sptr++;
1608 else
1609 warning("Resourcename (str_unicode) contain unprintable characters or invalid translation, ignored\n");
1611 buf[i] = '\0';
1613 else if(nid->type == name_str && nid->name.s_name->type == str_char)
1615 char *cptr;
1616 int i;
1617 cptr = nid->name.s_name->str.cstr;
1618 buf[0] = '\0';
1619 for(i = 0; *cptr && i < MAXNAMELEN; i++)
1621 if((unsigned)*cptr < 0x80 && isprint(*cptr & 0xff))
1622 buf[i] = *cptr++;
1623 else
1624 warning("Resourcename (str_char) contain unprintable characters, ignored\n");
1626 buf[i] = '\0';
1628 else if(nid->type == name_ord)
1630 sprintf(buf, "%u", nid->name.i_name);
1632 else
1634 internal_error(__FILE__, __LINE__, "Resource name_id with invalid type %d\n", nid->type);
1636 return buf;
1638 #undef MAXNAMELEN
1641 *****************************************************************************
1642 * Function : make_c_name
1643 * Syntax : char *make_c_name(const char *base, const name_id_t *nid, const language_t *lan)
1644 * Input :
1645 * Output :
1646 * Description : Converts a resource name into a valid c-identifier in the
1647 * form "_base_nid".
1648 * Remarks :
1649 *****************************************************************************
1651 char *make_c_name(const char *base, const name_id_t *nid, const language_t *lan)
1653 char *buf = prep_nid_for_label(nid);
1654 return strmake( "_%s_%s_%d", base, buf, lan ? MAKELANGID(lan->id, lan->sub) : 0);
1658 *****************************************************************************
1659 * Function : get_c_typename
1660 * Syntax : const char *get_c_typename(enum res_e type)
1661 * Input :
1662 * Output :
1663 * Description : Convert resource enum to char string to be used in c-name
1664 * creation.
1665 * Remarks :
1666 *****************************************************************************
1668 const char *get_c_typename(enum res_e type)
1670 switch(type)
1672 case res_acc: return "Acc";
1673 case res_anicur:return "AniCur";
1674 case res_aniico:return "AniIco";
1675 case res_bmp: return "Bmp";
1676 case res_cur: return "Cur";
1677 case res_curg: return "CurGrp";
1678 case res_dlg: return "Dlg";
1679 case res_fnt: return "Fnt";
1680 case res_fntdir:return "FntDir";
1681 case res_ico: return "Ico";
1682 case res_icog: return "IcoGrp";
1683 case res_men: return "Men";
1684 case res_rdt: return "RCDat";
1685 case res_stt: return "StrTab";
1686 case res_usr: return "Usr";
1687 case res_msg: return "MsgTab";
1688 case res_ver: return "VerInf";
1689 case res_toolbar: return "TlBr";
1690 case res_dlginit: return "DlgInit";
1691 default: return "Oops";
1696 *****************************************************************************
1697 * Function : resources2res
1698 * Syntax : void resources2res(resource_t *top)
1699 * Input :
1700 * top - The resource-tree to convert
1701 * Output :
1702 * Description : Convert logical resource descriptors into binary data
1703 * Remarks :
1704 *****************************************************************************
1706 void resources2res(resource_t *top)
1708 while(top)
1710 switch(top->type)
1712 case res_acc:
1713 if(!top->binres)
1714 top->binres = accelerator2res(top->name, top->res.acc);
1715 break;
1716 case res_bmp:
1717 if(!top->binres)
1718 top->binres = bitmap2res(top->name, top->res.bmp);
1719 break;
1720 case res_cur:
1721 if(!top->binres)
1722 top->binres = cursor2res(top->res.cur);
1723 break;
1724 case res_curg:
1725 if(!top->binres)
1726 top->binres = cursorgroup2res(top->name, top->res.curg);
1727 break;
1728 case res_dlg:
1729 if(!top->binres)
1730 top->binres = dialog2res(top->name, top->res.dlg);
1731 break;
1732 case res_fnt:
1733 if(!top->binres)
1734 top->binres = font2res(top->name, top->res.fnt);
1735 break;
1736 case res_fntdir:
1737 if(!top->binres)
1738 top->binres = fontdir2res(top->name, top->res.fnd);
1739 break;
1740 case res_ico:
1741 if(!top->binres)
1742 top->binres = icon2res(top->res.ico);
1743 break;
1744 case res_icog:
1745 if(!top->binres)
1746 top->binres = icongroup2res(top->name, top->res.icog);
1747 break;
1748 case res_men:
1749 if(!top->binres)
1750 top->binres = menu2res(top->name, top->res.men);
1751 break;
1752 case res_html:
1753 if(!top->binres)
1754 top->binres = html2res(top->name, top->res.html);
1755 break;
1756 case res_rdt:
1757 if(!top->binres)
1758 top->binres = rcdata2res(top->name, top->res.rdt);
1759 break;
1760 case res_stt:
1761 if(!top->binres)
1762 top->binres = stringtable2res(top->res.stt);
1763 break;
1764 case res_usr:
1765 if(!top->binres)
1766 top->binres = user2res(top->name, top->res.usr);
1767 break;
1768 case res_msg:
1769 if(!top->binres)
1770 top->binres = messagetable2res(top->name, top->res.msg);
1771 break;
1772 case res_ver:
1773 if(!top->binres)
1774 top->binres = versioninfo2res(top->name, top->res.ver);
1775 break;
1776 case res_toolbar:
1777 if(!top->binres)
1778 top->binres = toolbar2res(top->name, top->res.tbt);
1779 break;
1780 case res_dlginit:
1781 if(!top->binres)
1782 top->binres = dlginit2res(top->name, top->res.dlgi);
1783 break;
1784 case res_anicur:
1785 case res_aniico:
1786 if(!top->binres)
1787 top->binres = anicurico2res(top->name, top->res.ani, top->type);
1788 break;
1789 default:
1790 internal_error(__FILE__, __LINE__, "Unknown resource type encountered %d in binary res generation\n", top->type);
1792 top->c_name = make_c_name(get_c_typename(top->type), top->name, top->lan);
1793 top = top->next;