2 * Copyright 1998 Bertho A. Stultiens (BS)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 *****************************************************************************
30 * Function : get_typename
31 * Syntax : char *get_typename(resource_t* r)
33 * r - Resource description
34 * Output : A pointer to a string representing the resource type
37 *****************************************************************************
39 char *get_typename(resource_t
* r
)
42 case res_acc
: return "ACCELERATOR";
43 case res_bmp
: return "BITMAP";
44 case res_cur
: return "CURSOR";
45 case res_curg
: return "GROUP_CURSOR";
46 case res_dlg
: return "DIALOG";
47 case res_dlgex
: return "DIALOGEX";
48 case res_fnt
: return "FONT";
49 case res_ico
: return "ICON";
50 case res_icog
: return "GROUP_ICON";
51 case res_men
: return "MENU";
52 case res_menex
: return "MENUEX";
53 case res_rdt
: return "RCDATA";
54 case res_stt
: return "STRINGTABLE";
55 case res_usr
: return "UserResource";
56 case res_msg
: return "MESSAGETABLE";
57 case res_ver
: return "VERSIONINFO";
58 case res_dlginit
: return "DLGINIT";
59 case res_toolbar
: return "TOOLBAR";
60 case res_anicur
: return "CURSOR (animated)";
61 case res_aniico
: return "ICON (animated)";
62 default: return "Unknown";
67 *****************************************************************************
68 * Function : strncpyWtoA
69 * Syntax : char *strncpyWtoA(char *cs, short *ws, int maxlen)
71 * cs - Pointer to buffer to receive result
72 * ws - Source wide-string
73 * maxlen - Max chars to copy
75 * Description : Copy a unicode string to ascii. Copying stops after the
76 * first occurring '\0' or when maxlen-1 chars are copied. The
77 * String is always nul terminated.
78 * Remarks : No codepage translation is done.
79 *****************************************************************************
81 char *strncpyWtoA(char *cs
, short *ws
, int maxlen
)
84 short *wsMax
= ws
+ maxlen
;
87 if(*ws
< -128 || *ws
> 127)
88 printf("***Warning: Unicode string contains non-printable chars***");
89 *cptr
++ = (char)*ws
++;
97 *****************************************************************************
98 * Function : print_string
99 * Syntax : void print_string(string_t *str)
104 *****************************************************************************
106 void print_string(string_t
*str
)
111 else if(str
->type
== str_char
)
112 printf("\"%s\"", str
->str
.cstr
);
115 strncpyWtoA(buffer
, str
->str
.wstr
, sizeof(buffer
));
116 printf("L\"%s\"", buffer
);
121 *****************************************************************************
122 * Function : get_nameid_str
123 * Syntax : char *get_nameid_str(name_id_t *n)
125 * n - nameid to convert to text
126 * Output : A pointer to the name.
128 * Remarks : Not reentrant because of static buffer
129 *****************************************************************************
131 char *get_nameid_str(name_id_t
*n
)
133 static char buffer
[256];
138 if(n
->type
== name_ord
)
140 sprintf(buffer
, "%d", n
->name
.i_name
);
143 else if(n
->type
== name_str
)
145 if(n
->name
.s_name
->type
== str_char
)
146 return n
->name
.s_name
->str
.cstr
;
149 strncpyWtoA(buffer
, n
->name
.s_name
->str
.wstr
, sizeof(buffer
));
154 return "Hoooo, report this: wrong type in nameid";
158 *****************************************************************************
159 * Function : dump_memopt
160 * Syntax : void dump_memopt(DWORD memopt)
162 * memopt - flag bits of the options set
166 *****************************************************************************
168 static void dump_memopt(DWORD memopt
)
170 printf("Memory/load options: ");
174 printf("LOADONCALL ");
184 printf("DISCARDABLE");
189 *****************************************************************************
190 * Function : dump_lvc
191 * Syntax : void dump_lvc(lvc_t *l)
193 * l - pointer to lvc structure
195 * Description : Dump language, version and characteristics
197 *****************************************************************************
199 static void dump_lvc(lvc_t
*l
)
202 printf("LANGUAGE %04x, %04x\n", l
->language
->id
, l
->language
->sub
);
204 printf("LANGUAGE <not set>\n");
207 printf("VERSION %08lx\n", *(l
->version
));
209 printf("VERSION <not set>\n");
212 printf("CHARACTERISTICS %08lx\n", *(l
->characts
));
214 printf("CHARACTERISTICS <not set>\n");
218 *****************************************************************************
219 * Function : dump_raw_data
220 * Syntax : void dump_raw_data(raw_data_t *d)
222 * d - Raw data descriptor
226 *****************************************************************************
228 static void dump_raw_data(raw_data_t
*d
)
239 printf("Rawdata size: %d\n", d
->size
);
243 for(n
= 0; n
< d
->size
; n
++)
250 for(i
= 0; i
< 16; i
++)
251 printf("%c", isprint(d
->data
[n
-16+i
] & 0xff) ? d
->data
[n
-16+i
] : '.');
252 printf("\n%08x: ", n
);
257 printf("%02x ", d
->data
[n
] & 0xff);
263 for(i
= 0; i
< j
; i
++)
264 printf("%c", isprint(d
->data
[n
-j
+i
] & 0xff) ? d
->data
[n
-j
+i
] : '.');
269 *****************************************************************************
270 * Function : dump_accelerator
271 * Syntax : void dump_accelerator(resource_t *acc)
273 * acc - Accelerator resource descriptor
277 *****************************************************************************
279 static void dump_accelerator(accelerator_t
*acc
)
281 event_t
*ev
= acc
->events
;
283 dump_memopt(acc
->memopt
);
284 dump_lvc(&(acc
->lvc
));
286 printf("Events: %s\n", ev
? "" : "<none>");
291 printf("\"%c\"", ev
->key
);
292 else if(iscntrl(ev
->key
))
293 printf("\"^%c\"", ev
->key
+'@');
295 printf("\\x%02x", ev
->key
& 0xff);
297 printf(" Id=%d flags=%04x\n", ev
->id
, ev
->flags
);
303 *****************************************************************************
304 * Function : dump_cursor
305 * Syntax : void dump_cursor(cursor_t *cur)
307 * cur - Cursor resource descriptor
311 *****************************************************************************
313 static void dump_cursor(cursor_t
*cur
)
315 printf("Id: %d\n", cur
->id
);
316 printf("Width: %d\n", cur
->width
);
317 printf("Height: %d\n", cur
->height
);
318 printf("X Hotspot: %d\n", cur
->xhot
);
319 printf("Y Hotspot: %d\n", cur
->yhot
);
320 dump_raw_data(cur
->data
);
324 *****************************************************************************
325 * Function : dump_cursor_group
326 * Syntax : void dump_cursor_group(cursor_group_t *cur)
328 * cur - Cursor group resource descriptor
332 *****************************************************************************
334 static void dump_cursor_group(cursor_group_t
*curg
)
336 dump_memopt(curg
->memopt
);
337 printf("There are %d cursors in this group\n", curg
->ncursor
);
341 *****************************************************************************
342 * Function : dump_icon
343 * Syntax : void dump_icon(icon_t *ico)
345 * ico - Icon resource descriptor
349 *****************************************************************************
351 static void dump_icon(icon_t
*ico
)
353 printf("Id: %d\n", ico
->id
);
354 printf("Width: %d\n", ico
->width
);
355 printf("Height: %d\n", ico
->height
);
356 printf("NColor: %d\n", ico
->nclr
);
357 printf("NPlanes: %d\n", ico
->planes
);
358 printf("NBits: %d\n", ico
->bits
);
359 dump_raw_data(ico
->data
);
363 *****************************************************************************
364 * Function : dump_icon_group
365 * Syntax : void dump_icon_group(icon_group_t *ico)
367 * ico - Icon group resource descriptor
371 *****************************************************************************
373 static void dump_icon_group(icon_group_t
*icog
)
375 dump_memopt(icog
->memopt
);
376 printf("There are %d icons in this group\n", icog
->nicon
);
380 *****************************************************************************
381 * Function : dump_ani_curico
382 * Syntax : void dump_ani_curico(ani_curico_t *ani)
384 * ani - Animated object resource descriptor
388 *****************************************************************************
390 static void dump_ani_curico(ani_curico_t
*ani
)
392 dump_memopt(ani
->memopt
);
393 dump_lvc(&ani
->data
->lvc
);
394 dump_raw_data(ani
->data
);
398 *****************************************************************************
399 * Function : dump_font
400 * Syntax : void dump_font(font_t *fnt)
402 * fnt - Font resource descriptor
406 *****************************************************************************
408 static void dump_font(font_t
*fnt
)
410 dump_memopt(fnt
->memopt
);
411 dump_lvc(&(fnt
->data
->lvc
));
412 dump_raw_data(fnt
->data
);
416 *****************************************************************************
417 * Function : dump_bitmap
418 * Syntax : void dump_bitmap(bitmap_t *bmp)
420 * bmp - Bitmap resource descriptor
424 *****************************************************************************
426 static void dump_bitmap(bitmap_t
*bmp
)
428 dump_memopt(bmp
->memopt
);
429 dump_lvc(&(bmp
->data
->lvc
));
430 dump_raw_data(bmp
->data
);
434 *****************************************************************************
435 * Function : dump_rcdata
436 * Syntax : void dump_rcdata(rcdata_t *rdt)
438 * rdt - RCData resource descriptor
442 *****************************************************************************
444 static void dump_rcdata(rcdata_t
*rdt
)
446 dump_memopt(rdt
->memopt
);
447 dump_lvc(&(rdt
->data
->lvc
));
448 dump_raw_data(rdt
->data
);
452 *****************************************************************************
453 * Function : dump_user
454 * Syntax : void dump_user(user_t *usr)
456 * usr - User resource descriptor
460 *****************************************************************************
462 static void dump_user(user_t
*usr
)
464 dump_memopt(usr
->memopt
);
465 dump_lvc(&(usr
->data
->lvc
));
466 printf("Class %s\n", get_nameid_str(usr
->type
));
467 dump_raw_data(usr
->data
);
471 *****************************************************************************
472 * Function : dump_messagetable
473 * Syntax : void dump_messagetable(messagetable_t *msg)
475 * msg - Messagetable resource descriptor
479 *****************************************************************************
481 static void dump_messagetable(messagetable_t
*msg
)
483 dump_memopt(msg
->memopt
);
484 dump_lvc(&(msg
->data
->lvc
));
485 dump_raw_data(msg
->data
);
489 *****************************************************************************
490 * Function : dump_stringtable
491 * Syntax : void dump_stringtable(stringtable_t *stt)
493 * stt - Stringtable resource descriptor
497 *****************************************************************************
499 static void dump_stringtable(stringtable_t
*stt
)
502 for(; stt
; stt
= stt
->next
)
505 dump_memopt(stt
->memopt
);
506 dump_lvc(&(stt
->lvc
));
507 for(i
= 0; i
< stt
->nentries
; i
++)
509 printf("Id=%-5d (%d) ", stt
->idbase
+i
, stt
->entries
[i
].id
);
510 if(stt
->entries
[i
].str
)
511 print_string(stt
->entries
[i
].str
);
521 *****************************************************************************
522 * Function : dump_control
523 * Syntax : void dump_control(control_t *ctrl)
525 * ctrl - Control resource descriptor
529 *****************************************************************************
531 static void dump_control(control_t
*ctrl
)
533 printf("Control {\n\tClass: %s\n", get_nameid_str(ctrl
->ctlclass
));
534 printf("\tText: "); get_nameid_str(ctrl
->title
); printf("\n");
535 printf("\tId: %d\n", ctrl
->id
);
536 printf("\tx, y, w, h: %d, %d, %d, %d\n", ctrl
->x
, ctrl
->y
, ctrl
->width
, ctrl
->height
);
539 assert(ctrl
->style
!= NULL
);
540 assert(ctrl
->style
->and_mask
== 0);
541 printf("\tStyle: %08lx\n", ctrl
->style
->or_mask
);
545 assert(ctrl
->exstyle
!= NULL
);
546 assert(ctrl
->exstyle
->and_mask
== 0);
547 printf("\tExStyle: %08lx\n", ctrl
->exstyle
->or_mask
);
550 printf("\tHelpid: %ld\n", ctrl
->helpid
);
554 dump_raw_data(ctrl
->extra
);
560 *****************************************************************************
561 * Function : dump_dialog
562 * Syntax : void dump_dialog(dialog_t *dlg)
564 * dlg - Dialog resource descriptor
568 *****************************************************************************
570 static void dump_dialog(dialog_t
*dlg
)
572 control_t
*c
= dlg
->controls
;
574 dump_memopt(dlg
->memopt
);
575 dump_lvc(&(dlg
->lvc
));
576 printf("x, y, w, h: %d, %d, %d, %d\n", dlg
->x
, dlg
->y
, dlg
->width
, dlg
->height
);
579 assert(dlg
->style
!= NULL
);
580 assert(dlg
->style
->and_mask
== 0);
581 printf("Style: %08lx\n", dlg
->style
->or_mask
);
586 assert(dlg
->exstyle
!= NULL
);
587 assert(dlg
->exstyle
->and_mask
== 0);
588 printf("ExStyle: %08lx\n", dlg
->exstyle
->or_mask
);
590 printf("Menu: %s\n", get_nameid_str(dlg
->menu
));
591 printf("Class: %s\n", get_nameid_str(dlg
->dlgclass
));
592 printf("Title: "); print_string(dlg
->title
); printf("\n");
598 printf("%d, ", dlg
->font
->size
);
599 print_string(dlg
->font
->name
);
610 *****************************************************************************
611 * Function : dump_dialogex
612 * Syntax : void dump_dialogex(dialogex_t *dlgex)
614 * dlgex - DialogEx resource descriptor
618 *****************************************************************************
620 static void dump_dialogex(dialogex_t
*dlgex
)
622 control_t
*c
= dlgex
->controls
;
624 dump_memopt(dlgex
->memopt
);
625 dump_lvc(&(dlgex
->lvc
));
626 printf("x, y, w, h: %d, %d, %d, %d\n", dlgex
->x
, dlgex
->y
, dlgex
->width
, dlgex
->height
);
629 assert(dlgex
->style
!= NULL
);
630 assert(dlgex
->style
->and_mask
== 0);
631 printf("Style: %08lx\n", dlgex
->style
->or_mask
);
633 if(dlgex
->gotexstyle
)
635 assert(dlgex
->exstyle
!= NULL
);
636 assert(dlgex
->exstyle
->and_mask
== 0);
637 printf("ExStyle: %08lx\n", dlgex
->exstyle
->or_mask
);
640 printf("Helpid: %ld\n", dlgex
->helpid
);
641 printf("Menu: %s\n", get_nameid_str(dlgex
->menu
));
642 printf("Class: %s\n", get_nameid_str(dlgex
->dlgclass
));
643 printf("Title: "); print_string(dlgex
->title
); printf("\n");
649 printf("%d, ", dlgex
->font
->size
);
650 print_string(dlgex
->font
->name
);
651 printf(", %d, %d\n", dlgex
->font
->weight
, dlgex
->font
->italic
);
661 *****************************************************************************
662 * Function : dump_menu_item
663 * Syntax : void dump_menu_item(menu_item_t *item)
668 *****************************************************************************
670 static void dump_menu_item(menu_item_t
*item
)
677 print_string(item
->name
);
679 dump_menu_item(item
->popup
);
686 print_string(item
->name
);
687 printf(", %d, %08lx", item
->id
, item
->state
);
698 *****************************************************************************
699 * Function : dump_menu
700 * Syntax : void dump_menu(menu_t *men)
702 * men - Menu resource descriptor
706 *****************************************************************************
708 static void dump_menu(menu_t
*men
)
710 dump_memopt(men
->memopt
);
711 dump_lvc(&(men
->lvc
));
712 dump_menu_item(men
->items
);
716 *****************************************************************************
717 * Function : dump_menuex_item
718 * Syntax : void dump_menuex_item(menuex_item_t *item)
723 *****************************************************************************
725 static void dump_menuex_item(menuex_item_t
*item
)
732 print_string(item
->name
);
734 printf(", Id=%d", item
->id
);
736 printf(", Type=%ld", item
->type
);
738 printf(", State=%08lx", item
->state
);
740 printf(", HelpId=%d", item
->helpid
);
742 dump_menuex_item(item
->popup
);
749 print_string(item
->name
);
751 printf(", Id=%d", item
->id
);
753 printf(", Type=%ld", item
->type
);
755 printf(", State=%08lx", item
->state
);
757 printf(", HelpId=%d", item
->helpid
);
768 *****************************************************************************
769 * Function : dump_menuex
770 * Syntax : void dump_menuex(dialogex_t *menex)
772 * menex - MenuEx resource descriptor
776 *****************************************************************************
778 static void dump_menuex(menuex_t
*menex
)
780 dump_memopt(menex
->memopt
);
781 dump_lvc(&(menex
->lvc
));
782 dump_menuex_item(menex
->items
);
786 *****************************************************************************
787 * Function : dump_ver_value
788 * Syntax : void dump_ver_value(ver_value_t *val)
793 *****************************************************************************
795 static void dump_ver_block(ver_block_t
*); /* Forward ref */
797 static void dump_ver_value(ver_value_t
*val
)
799 if(val
->type
== val_str
)
802 print_string(val
->key
);
804 print_string(val
->value
.str
);
807 else if(val
->type
== val_words
)
811 print_string(val
->key
);
812 for(i
= 0; i
< val
->value
.words
->nwords
; i
++)
813 printf(" %04x", val
->value
.words
->words
[i
]);
816 else if(val
->type
== val_block
)
818 dump_ver_block(val
->value
.block
);
823 *****************************************************************************
824 * Function : dump_ver_block
825 * Syntax : void dump_ver_block(ver_block_t *blk)
830 *****************************************************************************
832 static void dump_ver_block(ver_block_t
*blk
)
834 ver_value_t
*val
= blk
->values
;
836 print_string(blk
->name
);
847 *****************************************************************************
848 * Function : dump_versioninfo
849 * Syntax : void dump_versioninfo(versioninfo_t *ver)
851 * ver - Versioninfo resource descriptor
855 *****************************************************************************
857 static void dump_versioninfo(versioninfo_t
*ver
)
859 ver_block_t
*blk
= ver
->blocks
;
861 dump_lvc(&(ver
->lvc
));
864 printf("FILEVERSION %04x, %04x, %04x, %04x\n",
870 printf("PRODUCTVERSION %04x, %04x, %04x, %04x\n",
876 printf("FILEOS %08x\n", ver
->fileos
);
878 printf("FILEFLAGS %08x\n", ver
->fileflags
);
880 printf("FILEFLAGSMASK %08x\n", ver
->fileflagsmask
);
882 printf("FILETYPE %08x\n", ver
->filetype
);
884 printf("FILESUBTYPE %08x\n", ver
->filesubtype
);
893 *****************************************************************************
894 * Function : dump_toolbar_item
895 * Syntax : void dump_toolbar_item(toolbar_item_t *item)
900 *****************************************************************************
902 static void dump_toolbar_items(toolbar_item_t
*items
)
907 printf(" BUTTON %d", items
->id
);
909 printf(" SEPARATOR");
918 *****************************************************************************
919 * Function : dump_toolbar
920 * Syntax : void dump_toolbar(toolbar_t *toolbar)
922 * toolbar - Toolbar resource descriptor
926 *****************************************************************************
928 static void dump_toolbar(toolbar_t
*toolbar
)
930 dump_memopt(toolbar
->memopt
);
931 dump_lvc(&(toolbar
->lvc
));
932 dump_toolbar_items(toolbar
->items
);
936 *****************************************************************************
937 * Function : dump_dlginit
938 * Syntax : void dump_dlginit(dlginit_t *dit)
940 * dit - DlgInit resource descriptor
944 *****************************************************************************
946 static void dump_dlginit(dlginit_t
*dit
)
948 dump_memopt(dit
->memopt
);
949 dump_lvc(&(dit
->data
->lvc
));
950 dump_raw_data(dit
->data
);
954 *****************************************************************************
961 *****************************************************************************
964 *****************************************************************************
965 * Function : dump_resources
966 * Syntax : void dump_resources(resource_t *top)
968 * top - Top of the resource tree
971 * Description : Dump the parsed resource-tree to stdout
973 *****************************************************************************
975 void dump_resources(resource_t
*top
)
977 printf("Internal resource-tree dump:\n");
980 printf("Resource: %s\nId: %s\n",
982 get_nameid_str(top
->name
));
986 dump_accelerator(top
->res
.acc
);
989 dump_bitmap(top
->res
.bmp
);
992 dump_cursor(top
->res
.cur
);
995 dump_cursor_group(top
->res
.curg
);
998 dump_dialog(top
->res
.dlg
);
1001 dump_dialogex(top
->res
.dlgex
);
1004 dump_font(top
->res
.fnt
);
1007 dump_icon_group(top
->res
.icog
);
1010 dump_icon(top
->res
.ico
);
1013 dump_menu(top
->res
.men
);
1016 dump_menuex(top
->res
.menex
);
1019 dump_rcdata(top
->res
.rdt
);
1022 dump_stringtable(top
->res
.stt
);
1025 dump_user(top
->res
.usr
);
1028 dump_messagetable(top
->res
.msg
);
1031 dump_versioninfo(top
->res
.ver
);
1034 dump_dlginit(top
->res
.dlgi
);
1037 dump_toolbar(top
->res
.tbt
);
1041 dump_ani_curico(top
->res
.ani
);
1044 printf("Report this: Unknown resource type parsed %08x\n", top
->type
);