2 * Write .res, .s and .h file(s) from a resource-tree
4 * Copyright 1998 Bertho A. Stultiens
21 char s_file_head_str
[] =
23 "# This file is generated with wrc version " WRC_FULLVERSION
". Do not edit!\n"
31 char s_file_tail_str
[] =
35 char s_file_autoreg_str
[] =
39 #ifdef NEED_UNDERSCORE_PREFIX
40 "\tcall\t_LIBRES_RegisterResources\n"
42 "\tcall\tLIBRES_RegisterResources\n"
46 "\t.section .ctors,\"aw\"\n"
47 "\t.long\t.LAuto_Register\n\n"
50 char h_file_head_str
[] =
52 " * This file is generated with wrc version " WRC_FULLVERSION
". Do not edit!\n"
57 "#ifndef __%08x_H\n" /* This becomes the data of compile */
58 "#define __%08x_H\n\n"
59 "#ifndef __WRC_RSC_H\n"
60 "#include <wrc_rsc.h>\n"
64 char h_file_tail_str
[] =
69 char _NEResTab
[] = "_NEResTab";
70 char _PEResTab
[] = "_PEResTab";
71 char _ResTable
[] = "_ResTable";
73 res_count_t
*rcarray
= NULL
;
76 int n_name_entries
= 0;
81 *****************************************************************************
82 * Function : write_resfile
83 * Syntax : void write_resfile(char *outname, resource_t *top)
85 * outname - Filename to write to
86 * top - The resource-tree to convert
90 *****************************************************************************
92 void write_resfile(char *outname
, resource_t
*top
)
96 char zeros
[3] = {0, 0, 0};
98 fo
= fopen(outname
, "wb");
101 error("Could not open %s\n", outname
);
106 /* Put an empty resource first to signal win32 format */
107 res_t
*res
= new_res();
108 put_dword(res
, 0); /* ResSize */
109 put_dword(res
, 0x00000020); /* HeaderSize */
110 put_word(res
, 0xffff); /* ResType */
112 put_word(res
, 0xffff); /* ResName */
114 put_dword(res
, 0); /* DataVersion */
115 put_word(res
, 0); /* Memory options */
116 put_word(res
, 0); /* Language */
117 put_dword(res
, 0); /* Version */
118 put_dword(res
, 0); /* Charateristics */
119 ret
= fwrite(res
->data
, 1, res
->size
, fo
);
123 error("Error writing %s", outname
);
128 for(; top
; top
= top
->next
)
133 ret
= fwrite(top
->binres
->data
, 1, top
->binres
->size
, fo
);
134 if(ret
!= top
->binres
->size
)
137 error("Error writing %s", outname
);
139 if(win32
&& (top
->binres
->size
& 0x03))
142 ret
= fwrite(zeros
, 1, 4 - (top
->binres
->size
& 0x03), fo
);
143 if(ret
!= 4 - (top
->binres
->size
& 0x03))
146 error("Error writing %s", outname
);
154 *****************************************************************************
155 * Function : write_s_res
156 * Syntax : void write_s_res(FILE *fp, res_t *res)
161 *****************************************************************************
163 #define BYTESPERLINE 8
164 void write_s_res(FILE *fp
, res_t
*res
)
166 int idx
= res
->dataidx
;
168 int rest
= (end
- idx
) % BYTESPERLINE
;
169 int lines
= (end
- idx
) / BYTESPERLINE
;
172 for(i
= 0 ; i
< lines
; i
++)
174 fprintf(fp
, "\t.byte\t");
175 for(j
= 0; j
< BYTESPERLINE
; j
++, idx
++)
177 fprintf(fp
, "0x%02x%s", res
->data
[idx
] & 0xff,
178 j
== BYTESPERLINE
-1 ? "" : ", ");
184 fprintf(fp
, "\t.byte\t");
185 for(j
= 0; j
< rest
; j
++, idx
++)
187 fprintf(fp
, "0x%02x%s", res
->data
[idx
] & 0xff,
188 j
== rest
-1 ? "" : ", ");
195 *****************************************************************************
196 * Function : write_name_str
197 * Syntax : void write_name_str(FILE *fp, name_id_t *nid)
201 * Remarks : One level self recursive for string type conversion
202 *****************************************************************************
204 void write_name_str(FILE *fp
, name_id_t
*nid
)
207 assert(nid
->type
== name_str
);
209 if(!win32
&& nid
->name
.s_name
->type
== str_char
)
211 res
.size
= strlen(nid
->name
.s_name
->str
.cstr
);
213 error("Can't write strings larger than 254 bytes");
215 internal_error(__FILE__
, __LINE__
, "Attempt to write empty string");
217 res
.data
= (char *)xmalloc(res
.size
+ 1);
218 res
.data
[0] = (char)res
.size
;
219 res
.size
++; /* We need to write the lenth byte as well */
220 strcpy(res
.data
+1, nid
->name
.s_name
->str
.cstr
);
221 write_s_res(fp
, &res
);
224 else if(!win32
&& nid
->name
.s_name
->type
== str_unicode
)
229 lnid
.type
= name_str
;
230 lnid
.name
.s_name
= &str
;
232 str
.str
.cstr
= dupwstr2cstr(nid
->name
.s_name
->str
.wstr
);
233 write_name_str(fp
, &lnid
);
236 else if(win32
&& nid
->name
.s_name
->type
== str_char
)
241 lnid
.type
= name_str
;
242 lnid
.name
.s_name
= &str
;
243 str
.type
= str_unicode
;
244 str
.str
.wstr
= dupcstr2wstr(nid
->name
.s_name
->str
.cstr
);
245 write_name_str(fp
, &lnid
);
248 else if(win32
&& nid
->name
.s_name
->type
== str_unicode
)
250 res
.size
= wstrlen(nid
->name
.s_name
->str
.wstr
);
252 error("Can't write strings larger than 65534 bytes");
254 internal_error(__FILE__
, __LINE__
, "Attempt to write empty string");
256 res
.data
= (char *)xmalloc((res
.size
+ 1) * 2);
257 ((short *)res
.data
)[0] = (short)res
.size
;
258 wstrcpy((short *)(res
.data
+2), nid
->name
.s_name
->str
.wstr
);
259 res
.size
*= 2; /* Function writes bytes, not shorts... */
260 res
.size
+= 2; /* We need to write the length word as well */
261 write_s_res(fp
, &res
);
266 internal_error(__FILE__
, __LINE__
, "Hmm, requested to write a string of unknown type %d",
267 nid
->name
.s_name
->type
);
272 *****************************************************************************
273 * Function : compare_name_id
274 * Syntax : int compare_name_id(name_id_t *n1, name_id_t *n2)
279 *****************************************************************************
281 int compare_name_id(name_id_t
*n1
, name_id_t
*n2
)
283 if(n1
->type
== name_ord
&& n2
->type
== name_ord
)
285 return n1
->name
.i_name
- n2
->name
.i_name
;
287 else if(n1
->type
== name_str
&& n2
->type
== name_str
)
289 if(n1
->name
.s_name
->type
== str_char
290 && n2
->name
.s_name
->type
== str_char
)
292 return stricmp(n1
->name
.s_name
->str
.cstr
, n2
->name
.s_name
->str
.cstr
);
294 else if(n1
->name
.s_name
->type
== str_unicode
295 && n2
->name
.s_name
->type
== str_unicode
)
297 return wstricmp(n1
->name
.s_name
->str
.wstr
, n2
->name
.s_name
->str
.wstr
);
301 internal_error(__FILE__
, __LINE__
, "Can't yet compare strings of mixed type");
304 else if(n1
->type
== name_ord
&& n2
->type
== name_str
)
306 else if(n1
->type
== name_str
&& n2
->type
== name_ord
)
309 internal_error(__FILE__
, __LINE__
, "Comparing name-ids with unknown types (%d, %d)",
312 return 0; /* Keep the compiler happy */
316 *****************************************************************************
317 * Function : find_counter
318 * Syntax : res_count_t *find_counter(name_id_t *type)
323 *****************************************************************************
325 res_count_t
*find_counter(name_id_t
*type
)
328 for(i
= 0; i
< rccount
; i
++)
330 if(!compare_name_id(type
, &(rcarray
[i
].type
)))
337 *****************************************************************************
338 * Function : count_resources
339 * Syntax : res_count_t *count_resources(resource_t *top)
343 * Remarks : The whole lot is converted into arrays because they are
344 * easy sortable. Makes the lot almost unreadable, but it
345 * works (I hope). Basically you have to keep in mind that
346 * the lot is a three-dimensional structure for win32 and a
347 * two-dimensional structure for win16.
348 *****************************************************************************
350 #define RCT(v) (*((resource_t **)(v)))
351 /* qsort sorting function */
352 int sort_name_id(const void *e1
, const void *e2
)
354 return compare_name_id(RCT(e1
)->name
, RCT(e2
)->name
);
357 int sort_language(const void *e1
, const void *e2
)
359 assert((RCT(e1
)->lan
) != NULL
);
360 assert((RCT(e2
)->lan
) != NULL
);
362 return MAKELANGID(RCT(e1
)->lan
->id
, RCT(e1
)->lan
->sub
)
363 - MAKELANGID(RCT(e2
)->lan
->id
, RCT(e2
)->lan
->sub
);
366 #define RCT(v) ((res_count_t *)(v))
367 int sort_type(const void *e1
, const void *e2
)
369 return compare_name_id(&(RCT(e1
)->type
), &(RCT(e2
)->type
));
373 void count_resources(resource_t
*top
)
380 for(rsc
= top
; rsc
; rsc
= rsc
->next
)
387 nid
.name
.i_name
= WRC_RT_DIALOG
;
391 nid
.name
.i_name
= WRC_RT_MENU
;
395 nid
= *(rsc
->res
.usr
->type
);
398 nid
.name
.i_name
= rsc
->type
;
402 if((rcp
= find_counter(&nid
)) == NULL
)
404 /* Count the number of uniq ids and names */
406 if(nid
.type
== name_ord
)
413 rcarray
= (res_count_t
*)xmalloc(sizeof(res_count_t
));
415 rcarray
[0].count
= 1;
416 rcarray
[0].type
= nid
;
417 rcarray
[0].rscarray
= (resource_t
**)xmalloc(sizeof(resource_t
*));
418 rcarray
[0].rscarray
[0] = rsc
;
423 rcarray
= (res_count_t
*)xrealloc(rcarray
, rccount
* sizeof(res_count_t
));
424 rcarray
[rccount
-1].count
= 1;
425 rcarray
[rccount
-1].type
= nid
;
426 rcarray
[rccount
-1].rscarray
= (resource_t
**)xmalloc(sizeof(resource_t
*));
427 rcarray
[rccount
-1].rscarray
[0] = rsc
;
433 rcp
->rscarray
= (resource_t
**)xrealloc(rcp
->rscarray
, rcp
->count
* sizeof(resource_t
*));
434 rcp
->rscarray
[rcp
->count
-1] = rsc
;
440 /* We're done, win16 requires no special sorting */
444 /* We now have a unsorted list of types with an array of res_count_t
445 * in rcarray[0..rccount-1]. And we have names of one type in the
446 * rcarray[x].rsc[0..rcarray[x].count-1] arrays.
447 * The list needs to be sorted for win32's top level tree structure.
452 qsort(rcarray
, rccount
, sizeof(rcarray
[0]), sort_type
);
454 /* Now sort the name-id arrays */
455 for(i
= 0; i
< rccount
; i
++)
457 if(rcarray
[i
].count
> 1)
458 qsort(rcarray
[i
].rscarray
, rcarray
[i
].count
, sizeof(rcarray
[0].rscarray
[0]), sort_name_id
);
461 /* Now split the name-id arrays into name/language
462 * subs. Don't look at the awfull expressions...
463 * We do this by taking the array elements out of rscarray and putting
464 * together a new array in rsc32array.
466 for(i
= 0; i
< rccount
; i
++)
470 assert(rcarray
[i
].count
>= 1);
472 /* rcap points to the current type we are dealing with */
473 rcap
= &(rcarray
[i
]);
475 /* Insert the first name-id */
476 rcap
->rsc32array
= (res32_count_t
*)xmalloc(sizeof(res32_count_t
));
478 rcap
->rsc32array
[0].rsc
= (resource_t
**)xmalloc(sizeof(resource_t
*));
479 rcap
->rsc32array
[0].count
= 1;
480 rcap
->rsc32array
[0].rsc
[0] = rcap
->rscarray
[0];
481 if(rcap
->rscarray
[0]->name
->type
== name_ord
)
483 rcap
->n_id_entries
= 1;
484 rcap
->n_name_entries
= 0;
488 rcap
->n_id_entries
= 0;
489 rcap
->n_name_entries
= 1;
492 /* Now loop over the resting resources of the current type
493 * to find duplicate names (which should have different
496 for(j
= 1; j
< rcap
->count
; j
++)
498 res32_count_t
*r32cp
;
500 /* r32cp points to the current res32_count structure
501 * that holds the resource name we are processing.
503 r32cp
= &(rcap
->rsc32array
[rcap
->count32
-1]);
505 if(!compare_name_id(r32cp
->rsc
[0]->name
, rcarray
[i
].rscarray
[j
]->name
))
507 /* Names are the same, add to list */
509 r32cp
->rsc
= (resource_t
**)xrealloc(r32cp
->rsc
, r32cp
->count
* sizeof(resource_t
*));
510 r32cp
->rsc
[r32cp
->count
-1] = rcap
->rscarray
[j
];
512 if(rcap
->rscarray
[j
]->name
->type
== name_ord
)
514 rcap
->n_id_entries
= 1;
515 rcap
->n_name_entries
= 0;
519 rcap
->n_id_entries
= 0;
520 rcap
->n_name_entries
= 1;
525 /* New name-id, sort the old one by
526 * language and create new list
529 qsort(r32cp
->rsc
, r32cp
->count
, sizeof(r32cp
->rsc
[0]), sort_language
);
531 rcap
->rsc32array
= (res32_count_t
*)xrealloc(rcap
->rsc32array
, rcap
->count32
* sizeof(res32_count_t
));
532 rcap
->rsc32array
[rcap
->count32
-1].rsc
= (resource_t
**)xmalloc(sizeof(resource_t
*));
533 rcap
->rsc32array
[rcap
->count32
-1].count
= 1;
534 rcap
->rsc32array
[rcap
->count32
-1].rsc
[0] = rcap
->rscarray
[j
];
536 if(rcap
->rscarray
[j
]->name
->type
== name_ord
)
537 rcap
->n_id_entries
++;
539 rcap
->n_name_entries
++;
542 /* Also sort the languages of the last name group */
543 if(rcap
->rsc32array
[rcap
->count32
-1].count
> 1)
544 qsort(rcap
->rsc32array
[rcap
->count32
-1].rsc
,
545 rcap
->rsc32array
[rcap
->count32
-1].count
,
546 sizeof(rcap
->rsc32array
[rcap
->count32
-1].rsc
[0]),
552 *****************************************************************************
553 * Function : write_pe_segment
554 * Syntax : void write_pe_segment(FILE *fp, resource_t *top)
559 *****************************************************************************
561 void write_pe_segment(FILE *fp
, resource_t
*top
)
565 fprintf(fp
, "\t.align\t4\n");
566 fprintf(fp
, "%s%s:\n", prefix
, _PEResTab
);
567 fprintf(fp
, "\t.globl\t%s%s\n", prefix
, _PEResTab
);
569 fprintf(fp
, "\t.long\t0\n");
570 /* Time/Date stamp */
571 fprintf(fp
, "\t.long\t0x%08lx\n", now
);
573 fprintf(fp
, "\t.long\t0\n"); /* FIXME: must version be filled out? */
574 /* # of id entries, # of name entries */
575 fprintf(fp
, "\t.short\t%d, %d\n", n_name_entries
, n_id_entries
);
577 /* Write the type level of the tree */
578 for(i
= 0; i
< rccount
; i
++)
586 if(rcp
->type
.type
== name_ord
)
587 fprintf(fp
, "\t.long\t%d\n", rcp
->type
.name
.i_name
);
590 char *name
= prep_nid_for_label(&(rcp
->type
));
591 fprintf(fp
, "\t.long\t(%s_%s_typename - %s%s) | 0x80000000\n",
598 label
= prep_nid_for_label(&(rcp
->type
));
599 fprintf(fp
, "\t.long\t(.L%s - %s%s) | 0x80000000\n",
605 /* Write the name level of the tree */
607 for(i
= 0; i
< rccount
; i
++)
616 typelabel
= xstrdup(prep_nid_for_label(&(rcp
->type
)));
617 fprintf(fp
, ".L%s:\n", typelabel
);
619 fprintf(fp
, "\t.long\t0\n"); /* Flags */
620 fprintf(fp
, "\t.long\t0x%08lx\n", now
); /* TimeDate */
621 fprintf(fp
, "\t.long\t0\n"); /* FIXME: must version be filled out? */
622 fprintf(fp
, "\t.short\t%d, %d\n", rcp
->n_name_entries
, rcp
->n_id_entries
);
623 for(j
= 0; j
< rcp
->count32
; j
++)
625 resource_t
*rsc
= rcp
->rsc32array
[j
].rsc
[0];
627 if(rsc
->name
->type
== name_ord
)
628 fprintf(fp
, "\t.long\t%d\n", rsc
->name
->name
.i_name
);
631 fprintf(fp
, "\t.long\t(%s%s_name - %s%s) | 0x80000000\n",
637 /* Maybe FIXME: Unescape the tree (ommit 0x80000000) and
638 * put the offset to the resource data entry.
639 * ?? Is unescaping worth while ??
642 namelabel
= prep_nid_for_label(rsc
->name
);
643 fprintf(fp
, "\t.long\t(.L%s_%s - %s%s) | 0x80000000\n",
652 /* Write the language level of the tree */
654 for(i
= 0; i
< rccount
; i
++)
662 typelabel
= xstrdup(prep_nid_for_label(&(rcp
->type
)));
664 for(j
= 0; j
< rcp
->count32
; j
++)
666 res32_count_t
*r32cp
= &(rcp
->rsc32array
[j
]);
669 namelabel
= xstrdup(prep_nid_for_label(r32cp
->rsc
[0]->name
));
670 fprintf(fp
, ".L%s_%s:\n", typelabel
, namelabel
);
672 fprintf(fp
, "\t.long\t0\n"); /* Flags */
673 fprintf(fp
, "\t.long\t0x%08lx\n", now
); /* TimeDate */
674 fprintf(fp
, "\t.long\t0\n"); /* FIXME: must version be filled out? */
675 fprintf(fp
, "\t.short\t0, %d\n", r32cp
->count
);
677 for(k
= 0; k
< r32cp
->count
; k
++)
679 resource_t
*rsc
= r32cp
->rsc
[k
];
680 assert(rsc
->lan
!= NULL
);
682 fprintf(fp
, "\t.long\t0x%08x\n", rsc
->lan
? MAKELANGID(rsc
->lan
->id
, rsc
->lan
->sub
) : 0);
684 fprintf(fp
, "\t.long\t.L%s_%s_%d - %s%s\n",
687 rsc
->lan
? MAKELANGID(rsc
->lan
->id
, rsc
->lan
->sub
) : 0,
696 /* Write the resource table itself */
698 for(i
= 0; i
< rccount
; i
++)
706 typelabel
= xstrdup(prep_nid_for_label(&(rcp
->type
)));
708 for(j
= 0; j
< rcp
->count32
; j
++)
710 res32_count_t
*r32cp
= &(rcp
->rsc32array
[j
]);
713 namelabel
= xstrdup(prep_nid_for_label(r32cp
->rsc
[0]->name
));
715 for(k
= 0; k
< r32cp
->count
; k
++)
717 resource_t
*rsc
= r32cp
->rsc
[k
];
719 assert(rsc
->lan
!= NULL
);
721 fprintf(fp
, ".L%s_%s_%d:\n",
724 rsc
->lan
? MAKELANGID(rsc
->lan
->id
, rsc
->lan
->sub
) : 0);
727 fprintf(fp
, "\t.long\t%s%s_data - %s%s\n",
733 fprintf(fp
, "\t.long\t%d\n",
734 rsc
->binres
->size
- rsc
->binres
->dataidx
);
736 fprintf(fp
, "\t.long\t%ld\n", codepage
);
738 fprintf(fp
, "\t.long\t0\n");
748 *****************************************************************************
749 * Function : write_ne_segment
750 * Syntax : void write_ne_segment(FILE *fp, resource_t *top)
755 *****************************************************************************
757 void write_ne_segment(FILE *fp
, resource_t
*top
)
761 fprintf(fp
, "\t.align\t4\n");
762 fprintf(fp
, "%s%s:\n", prefix
, _NEResTab
);
763 fprintf(fp
, "\t.globl\t%s%s\n", prefix
, _NEResTab
);
766 fprintf(fp
, "\t.short\t%d\n", alignment_pwr
);
769 for(i
= 0; i
< rccount
; i
++)
771 res_count_t
*rcp
= &rcarray
[i
];
774 if(rcp
->type
.type
== name_ord
)
775 fprintf(fp
, "\t.short\t0x%04x\n", rcp
->type
.name
.i_name
| 0x8000);
777 fprintf(fp
, "\t.short\t%s_%s_typename - %s%s\n",
779 rcp
->type
.name
.s_name
->str
.cstr
,
783 fprintf(fp
, "\t.short\t%d\n", rcp
->count
);
785 fprintf(fp
, "\t.long\t0\n");
787 for(j
= 0; j
< rcp
->count
; j
++)
789 /* FIXME: dividing by `alignment` doesn't seem to
790 * work with as (GAS). Shifting results in the
791 * correct behaviour. Maybe an as bug or just my
792 * lack of knowing as expression-syntax.
797 * The offset is relative to the beginning of the NE resource segment
798 * and _NOT_ to the file-beginning. This is because we do not have a
799 * file based resource, but a simulated NE segment. The offset _is_
800 * scaled by the AlignShift field.
801 * All other things are as the MS doc describes (alignment etc.)
803 fprintf(fp
, "\t.short\t(%s%s_data - %s%s) >> %d\n",
805 rcp
->rscarray
[j
]->c_name
,
810 fprintf(fp
, "\t.short\t%d\n",
811 rcp
->rscarray
[j
]->binres
->size
- rcp
->rscarray
[j
]->binres
->dataidx
);
813 fprintf(fp
, "\t.short\t0x%04x\n", (WORD
)rcp
->rscarray
[j
]->memopt
);
815 if(rcp
->rscarray
[j
]->name
->type
== name_ord
)
816 fprintf(fp
, "\t.short\t0x%04x\n", rcp
->rscarray
[j
]->name
->name
.i_name
| 0x8000);
818 fprintf(fp
, "\t.short\t%s%s_name - %s%s\n",
820 rcp
->rscarray
[j
]->c_name
,
823 /* Handle and Usage */
824 fprintf(fp
, "\t.short\t0, 0\n");
828 fprintf(fp
, "\t.short\t0\n");
832 *****************************************************************************
833 * Function : write_rsc_names
834 * Syntax : void write_rsc_names(FILE *fp, resource_t *top)
839 *****************************************************************************
841 void write_rsc_names(FILE *fp
, resource_t
*top
)
847 /* Write the names */
849 for(i
= 0; i
< rccount
; i
++)
855 if(rcp
->type
.type
== name_str
)
857 char *name
= prep_nid_for_label(&(rcp
->type
));
858 fprintf(fp
, "%s_%s_typename:\n",
861 write_name_str(fp
, &(rcp
->type
));
864 for(j
= 0; j
< rcp
->count32
; j
++)
866 resource_t
*rsc
= rcp
->rsc32array
[j
].rsc
[0];
868 if(rsc
->name
->type
== name_str
)
870 fprintf(fp
, "%s%s_name:\n",
873 write_name_str(fp
, rsc
->name
);
881 for(i
= 0; i
< rccount
; i
++)
883 res_count_t
*rcp
= &rcarray
[i
];
885 for(j
= 0; j
< rcp
->count
; j
++)
887 if(rcp
->type
.type
== name_str
)
889 fprintf(fp
, "%s_%s_typename:\n",
891 rcp
->type
.name
.s_name
->str
.cstr
);
892 write_name_str(fp
, &(rcp
->type
));
894 if(rcp
->rscarray
[j
]->name
->type
== name_str
)
896 fprintf(fp
, "%s%s_name:\n",
898 rcp
->rscarray
[j
]->c_name
);
899 write_name_str(fp
, rcp
->rscarray
[j
]->name
);
905 /* This is to end the NE resource table */
907 fprintf(fp
, "\t.byte\t0\n");
914 *****************************************************************************
915 * Function : write_s_file
916 * Syntax : void write_s_file(char *outname, resource_t *top)
918 * outname - Filename to write to
919 * top - The resource-tree to convert
923 *****************************************************************************
925 void write_s_file(char *outname
, resource_t
*top
)
930 fo
= fopen(outname
, "wt");
933 error("Could not open %s\n", outname
);
937 fprintf(fo
, s_file_head_str
, input_name
? input_name
: "stdin",
938 cmdline
, ctime(&now
));
940 /* Get an idea how many we have and restructure the tables */
941 count_resources(top
);
943 /* First write the segment tables */
947 write_pe_segment(fo
, top
);
949 write_ne_segment(fo
, top
);
953 write_rsc_names(fo
, top
);
957 /* Write the resource data */
958 fprintf(fo
, "#\n# Resource binary data\n#\n");
959 for(rsc
= top
; rsc
; rsc
= rsc
->next
)
964 fprintf(fo
, "\t.align\t%d\n", win32
? 4 : alignment
);
965 fprintf(fo
, "%s%s_data:\n", prefix
, rsc
->c_name
);
967 fprintf(fo
, "\t.globl\t%s%s_data\n", prefix
, rsc
->c_name
);
969 write_s_res(fo
, rsc
->binres
);
977 /* Write the indirection structures */
978 fprintf(fo
, "\n#\n# Resource indirection structures\n#\n");
979 fprintf(fo
, "\t.align\t4\n");
980 for(rsc
= top
; rsc
; rsc
= rsc
->next
)
983 char *type_name
= NULL
;
994 type
= WRC_RT_DIALOG
;
997 assert(rsc
->res
.usr
->type
!= NULL
);
998 type_name
= prep_nid_for_label(rsc
->res
.usr
->type
);
1006 * This follows a structure like:
1007 * struct wrc_resource {
1011 * RSCNAME *typename;
1015 * The 'RSCNAME' is a pascal-style string where the
1016 * first byte/word denotes the size and the rest the string
1019 fprintf(fo
, "%s%s:\n", prefix
, rsc
->c_name
);
1021 fprintf(fo
, "\t.globl\t%s%s\n", prefix
, rsc
->c_name
);
1022 fprintf(fo
, "\t.long\t%d, %s%s%s, %d, %s%s%s%s, %s%s_data, %d\n",
1023 rsc
->name
->type
== name_ord
? rsc
->name
->name
.i_name
: 0,
1024 rsc
->name
->type
== name_ord
? "0" : prefix
,
1025 rsc
->name
->type
== name_ord
? "" : rsc
->c_name
,
1026 rsc
->name
->type
== name_ord
? "" : "_name",
1028 type
? "0" : prefix
,
1030 type
? "" : type_name
,
1031 type
? "" : "_typename",
1034 rsc
->binres
->size
- rsc
->binres
->dataidx
);
1039 /* Write the indirection table */
1040 fprintf(fo
, "#\n# Resource indirection table\n#\n");
1041 fprintf(fo
, "\t.align\t4\n");
1042 fprintf(fo
, "%s%s:\n", prefix
, _ResTable
);
1043 fprintf(fo
, "\t.globl\t%s%s\n", prefix
, _ResTable
);
1044 for(rsc
= top
; rsc
; rsc
= rsc
->next
)
1046 fprintf(fo
, "\t.long\t%s%s\n", prefix
, rsc
->c_name
);
1048 fprintf(fo
, "\t.long\t0\n");
1053 fprintf(fo
, s_file_autoreg_str
, prefix
, _ResTable
);
1055 fprintf(fo
, s_file_tail_str
);
1060 *****************************************************************************
1061 * Function : write_h_file
1062 * Syntax : void write_h_file(char *outname, resource_t *top)
1064 * outname - Filename to write to
1065 * top - The resource-tree to convert
1069 *****************************************************************************
1071 void write_h_file(char *outname
, resource_t
*top
)
1077 #ifdef NEED_UNDERSCORE_PREFIX
1078 h_prefix
= prefix
+ 1;
1083 fo
= fopen(outname
, "wt");
1086 error("Could not open %s\n", outname
);
1090 fprintf(fo
, h_file_head_str
, input_name
? input_name
: "stdin",
1091 cmdline
, ctime(&now
), now
, now
);
1093 /* First write the segment tables reference */
1096 fprintf(fo
, "extern %schar %s%s[];\n\n",
1097 constant
? "const " : "",
1099 win32
? _PEResTab
: _NEResTab
);
1102 /* Write the resource data */
1103 for(rsc
= top
; global
&& rsc
; rsc
= rsc
->next
)
1108 fprintf(fo
, "extern %schar %s%s_data[];\n",
1109 constant
? "const " : "",
1119 /* Write the indirection structures */
1120 for(rsc
= top
; global
&& rsc
; rsc
= rsc
->next
)
1122 fprintf(fo
, "extern %swrc_resource%d_t %s%s;\n",
1123 constant
? "const " : "",
1132 /* Write the indirection table */
1133 fprintf(fo
, "extern %swrc_resource%d_t %s%s[];\n\n",
1134 constant
? "const " : "",
1140 fprintf(fo
, h_file_tail_str
);