2000-10-23 23:33:06 +02:00
|
|
|
/*
|
|
|
|
* Builtin dlls resource support
|
|
|
|
*
|
|
|
|
* Copyright 2000 Alexandre Julliard
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2000-10-23 23:33:06 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2002-04-25 23:40:56 +02:00
|
|
|
#include "wine/port.h"
|
2000-10-23 23:33:06 +02:00
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2000-10-23 23:33:06 +02:00
|
|
|
#include <stdio.h>
|
2002-08-17 20:28:43 +02:00
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
|
|
# include <sys/types.h>
|
|
|
|
#endif
|
2000-10-23 23:33:06 +02:00
|
|
|
#include <fcntl.h>
|
2002-08-17 20:28:43 +02:00
|
|
|
#ifdef HAVE_SYS_STAT_H
|
|
|
|
# include <sys/stat.h>
|
|
|
|
#endif
|
2000-10-23 23:33:06 +02:00
|
|
|
#ifdef HAVE_SYS_MMAN_H
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#endif
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2000-10-23 23:33:06 +02:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "build.h"
|
|
|
|
|
|
|
|
/* Unicode string or integer id */
|
|
|
|
struct string_id
|
|
|
|
{
|
|
|
|
WCHAR *str; /* ptr to Unicode string */
|
|
|
|
WORD id; /* integer id if str is NULL */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* descriptor for a resource */
|
|
|
|
struct resource
|
|
|
|
{
|
|
|
|
struct string_id type;
|
|
|
|
struct string_id name;
|
|
|
|
const void *data;
|
|
|
|
unsigned int data_size;
|
|
|
|
WORD lang;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* name level of the resource tree */
|
|
|
|
struct res_name
|
|
|
|
{
|
|
|
|
const struct string_id *name; /* name */
|
|
|
|
const struct resource *res; /* resource */
|
|
|
|
int nb_languages; /* number of languages */
|
2004-09-07 22:45:03 +02:00
|
|
|
unsigned int name_offset; /* offset of name in resource dir */
|
2000-10-23 23:33:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* type level of the resource tree */
|
|
|
|
struct res_type
|
|
|
|
{
|
|
|
|
const struct string_id *type; /* type name */
|
|
|
|
struct res_name *names; /* names array */
|
|
|
|
unsigned int nb_names; /* total number of names */
|
|
|
|
unsigned int nb_id_names; /* number of names that have a numeric id */
|
2004-09-07 22:45:03 +02:00
|
|
|
unsigned int name_offset; /* offset of type name in resource dir */
|
2000-10-23 23:33:06 +02:00
|
|
|
};
|
|
|
|
|
2004-02-11 07:41:01 +01:00
|
|
|
/* top level of the resource tree */
|
|
|
|
struct res_tree
|
|
|
|
{
|
|
|
|
struct res_type *types; /* types array */
|
|
|
|
unsigned int nb_types; /* total number of types */
|
|
|
|
};
|
2000-10-23 23:33:06 +02:00
|
|
|
|
2005-08-10 15:04:23 +02:00
|
|
|
static int byte_swapped; /* whether the current resource file is byte-swapped */
|
2000-10-25 22:33:58 +02:00
|
|
|
static const unsigned char *file_pos; /* current position in resource file */
|
|
|
|
static const unsigned char *file_end; /* end of resource file */
|
2000-10-23 23:33:06 +02:00
|
|
|
static const char *file_name; /* current resource file name */
|
|
|
|
|
2004-09-07 22:45:03 +02:00
|
|
|
/* size of a resource directory with n entries */
|
|
|
|
#define RESDIR_SIZE(n) ((4 + 2 * (n)) * sizeof(int))
|
|
|
|
|
2000-10-23 23:33:06 +02:00
|
|
|
|
2004-02-11 07:41:01 +01:00
|
|
|
inline static struct resource *add_resource( DLLSPEC *spec )
|
2000-10-23 23:33:06 +02:00
|
|
|
{
|
2004-02-11 07:41:01 +01:00
|
|
|
spec->resources = xrealloc( spec->resources, (spec->nb_resources + 1) * sizeof(spec->resources[0]) );
|
|
|
|
return &spec->resources[spec->nb_resources++];
|
2000-10-23 23:33:06 +02:00
|
|
|
}
|
|
|
|
|
2003-04-22 01:27:21 +02:00
|
|
|
static inline unsigned int strlenW( const WCHAR *str )
|
|
|
|
{
|
|
|
|
const WCHAR *s = str;
|
|
|
|
while (*s) s++;
|
|
|
|
return s - str;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int strcmpW( const WCHAR *str1, const WCHAR *str2 )
|
|
|
|
{
|
|
|
|
while (*str1 && (*str1 == *str2)) { str1++; str2++; }
|
|
|
|
return *str1 - *str2;
|
|
|
|
}
|
|
|
|
|
2000-10-23 23:33:06 +02:00
|
|
|
static struct res_name *add_name( struct res_type *type, const struct resource *res )
|
|
|
|
{
|
|
|
|
struct res_name *name;
|
|
|
|
type->names = xrealloc( type->names, (type->nb_names + 1) * sizeof(*type->names) );
|
|
|
|
name = &type->names[type->nb_names++];
|
|
|
|
name->name = &res->name;
|
|
|
|
name->res = res;
|
|
|
|
name->nb_languages = 1;
|
|
|
|
if (!name->name->str) type->nb_id_names++;
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2004-02-11 07:41:01 +01:00
|
|
|
static struct res_type *add_type( struct res_tree *tree, const struct resource *res )
|
2000-10-23 23:33:06 +02:00
|
|
|
{
|
|
|
|
struct res_type *type;
|
2004-02-11 07:41:01 +01:00
|
|
|
tree->types = xrealloc( tree->types, (tree->nb_types + 1) * sizeof(*tree->types) );
|
|
|
|
type = &tree->types[tree->nb_types++];
|
2000-10-23 23:33:06 +02:00
|
|
|
type->type = &res->type;
|
|
|
|
type->names = NULL;
|
|
|
|
type->nb_names = 0;
|
|
|
|
type->nb_id_names = 0;
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get the next word from the current resource file */
|
|
|
|
static WORD get_word(void)
|
|
|
|
{
|
2004-05-18 23:27:44 +02:00
|
|
|
WORD ret = *(const WORD *)file_pos;
|
2005-08-10 15:04:23 +02:00
|
|
|
if (byte_swapped) ret = (ret << 8) | (ret >> 8);
|
2000-10-23 23:33:06 +02:00
|
|
|
file_pos += sizeof(WORD);
|
|
|
|
if (file_pos > file_end) fatal_error( "%s is a truncated file\n", file_name );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get the next dword from the current resource file */
|
|
|
|
static DWORD get_dword(void)
|
|
|
|
{
|
2004-05-18 23:27:44 +02:00
|
|
|
DWORD ret = *(const DWORD *)file_pos;
|
2005-08-10 15:04:23 +02:00
|
|
|
if (byte_swapped)
|
|
|
|
ret = ((ret << 24) | ((ret << 8) & 0x00ff0000) | ((ret >> 8) & 0x0000ff00) | (ret >> 24));
|
2000-10-23 23:33:06 +02:00
|
|
|
file_pos += sizeof(DWORD);
|
|
|
|
if (file_pos > file_end) fatal_error( "%s is a truncated file\n", file_name );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get a string from the current resource file */
|
|
|
|
static void get_string( struct string_id *str )
|
|
|
|
{
|
2004-05-18 23:27:44 +02:00
|
|
|
if (*(const WCHAR *)file_pos == 0xffff)
|
2000-10-23 23:33:06 +02:00
|
|
|
{
|
|
|
|
get_word(); /* skip the 0xffff */
|
|
|
|
str->str = NULL;
|
|
|
|
str->id = get_word();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-05-18 23:27:44 +02:00
|
|
|
WCHAR *p = xmalloc( (strlenW((const WCHAR*)file_pos) + 1) * sizeof(WCHAR) );
|
2000-10-25 22:33:58 +02:00
|
|
|
str->str = p;
|
|
|
|
str->id = 0;
|
2000-10-23 23:33:06 +02:00
|
|
|
while ((*p++ = get_word()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check the file header */
|
|
|
|
/* all values must be zero except header size */
|
2002-12-07 00:26:29 +01:00
|
|
|
static int check_header(void)
|
2000-10-23 23:33:06 +02:00
|
|
|
{
|
2005-08-10 15:04:23 +02:00
|
|
|
DWORD size;
|
|
|
|
|
2002-12-07 00:26:29 +01:00
|
|
|
if (get_dword()) return 0; /* data size */
|
2005-08-10 15:04:23 +02:00
|
|
|
size = get_dword(); /* header size */
|
|
|
|
if (size == 0x20000000) byte_swapped = 1;
|
|
|
|
else if (size != 0x20) return 0;
|
2002-12-07 00:26:29 +01:00
|
|
|
if (get_word() != 0xffff || get_word()) return 0; /* type, must be id 0 */
|
|
|
|
if (get_word() != 0xffff || get_word()) return 0; /* name, must be id 0 */
|
|
|
|
if (get_dword()) return 0; /* data version */
|
|
|
|
if (get_word()) return 0; /* mem options */
|
|
|
|
if (get_word()) return 0; /* language */
|
|
|
|
if (get_dword()) return 0; /* version */
|
|
|
|
if (get_dword()) return 0; /* characteristics */
|
|
|
|
return 1;
|
2000-10-23 23:33:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* load the next resource from the current file */
|
2004-02-11 07:41:01 +01:00
|
|
|
static void load_next_resource( DLLSPEC *spec )
|
2000-10-23 23:33:06 +02:00
|
|
|
{
|
|
|
|
DWORD hdr_size;
|
2004-02-11 07:41:01 +01:00
|
|
|
struct resource *res = add_resource( spec );
|
2000-10-23 23:33:06 +02:00
|
|
|
|
|
|
|
res->data_size = (get_dword() + 3) & ~3;
|
|
|
|
hdr_size = get_dword();
|
|
|
|
if (hdr_size & 3) fatal_error( "%s header size not aligned\n", file_name );
|
|
|
|
|
|
|
|
res->data = file_pos - 2*sizeof(DWORD) + hdr_size;
|
|
|
|
get_string( &res->type );
|
|
|
|
get_string( &res->name );
|
|
|
|
if ((int)file_pos & 2) get_word(); /* align to dword boundary */
|
|
|
|
get_dword(); /* skip data version */
|
|
|
|
get_word(); /* skip mem options */
|
|
|
|
res->lang = get_word();
|
|
|
|
get_dword(); /* skip version */
|
|
|
|
get_dword(); /* skip characteristics */
|
|
|
|
|
2005-07-10 19:45:53 +02:00
|
|
|
file_pos = (const unsigned char *)res->data + res->data_size;
|
2000-10-23 23:33:06 +02:00
|
|
|
if (file_pos > file_end) fatal_error( "%s is a truncated file\n", file_name );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* load a Win32 .res file */
|
2004-02-11 07:41:01 +01:00
|
|
|
int load_res32_file( const char *name, DLLSPEC *spec )
|
2000-10-23 23:33:06 +02:00
|
|
|
{
|
2002-12-07 00:26:29 +01:00
|
|
|
int fd, ret;
|
2000-10-23 23:33:06 +02:00
|
|
|
void *base;
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
if ((fd = open( name, O_RDONLY )) == -1) fatal_perror( "Cannot open %s", name );
|
|
|
|
if ((fstat( fd, &st ) == -1)) fatal_perror( "Cannot stat %s", name );
|
2003-09-19 02:19:16 +02:00
|
|
|
if (!st.st_size) fatal_error( "%s is an empty file\n", name );
|
2000-11-26 00:54:12 +01:00
|
|
|
#ifdef HAVE_MMAP
|
2000-10-23 23:33:06 +02:00
|
|
|
if ((base = mmap( NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0 )) == (void*)-1)
|
2000-11-26 00:54:12 +01:00
|
|
|
#endif /* HAVE_MMAP */
|
2000-10-23 23:33:06 +02:00
|
|
|
{
|
|
|
|
base = xmalloc( st.st_size );
|
|
|
|
if (read( fd, base, st.st_size ) != st.st_size)
|
|
|
|
fatal_error( "Cannot read %s\n", name );
|
|
|
|
}
|
|
|
|
|
2005-08-10 15:04:23 +02:00
|
|
|
byte_swapped = 0;
|
2000-10-23 23:33:06 +02:00
|
|
|
file_name = name;
|
2000-10-25 22:33:58 +02:00
|
|
|
file_pos = base;
|
|
|
|
file_end = file_pos + st.st_size;
|
2002-12-07 00:26:29 +01:00
|
|
|
if ((ret = check_header()))
|
|
|
|
{
|
2004-02-11 07:41:01 +01:00
|
|
|
while (file_pos < file_end) load_next_resource( spec );
|
2002-12-07 00:26:29 +01:00
|
|
|
}
|
|
|
|
close( fd );
|
|
|
|
return ret;
|
2000-10-23 23:33:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* compare two unicode strings/ids */
|
|
|
|
static int cmp_string( const struct string_id *str1, const struct string_id *str2 )
|
|
|
|
{
|
|
|
|
if (!str1->str)
|
|
|
|
{
|
|
|
|
if (!str2->str) return str1->id - str2->id;
|
|
|
|
return 1; /* an id compares larger than a string */
|
|
|
|
}
|
|
|
|
if (!str2->str) return -1;
|
2003-04-22 01:27:21 +02:00
|
|
|
return strcmpW( str1->str, str2->str );
|
2000-10-23 23:33:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* compare two resources for sorting the resource directory */
|
|
|
|
/* resources are stored first by type, then by name, then by language */
|
|
|
|
static int cmp_res( const void *ptr1, const void *ptr2 )
|
|
|
|
{
|
|
|
|
const struct resource *res1 = ptr1;
|
|
|
|
const struct resource *res2 = ptr2;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if ((ret = cmp_string( &res1->type, &res2->type ))) return ret;
|
|
|
|
if ((ret = cmp_string( &res1->name, &res2->name ))) return ret;
|
|
|
|
return res1->lang - res2->lang;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* build the 3-level (type,name,language) resource tree */
|
2004-02-11 07:41:01 +01:00
|
|
|
static struct res_tree *build_resource_tree( DLLSPEC *spec )
|
2000-10-23 23:33:06 +02:00
|
|
|
{
|
2005-03-18 15:04:07 +01:00
|
|
|
unsigned int i;
|
2004-02-11 07:41:01 +01:00
|
|
|
struct res_tree *tree;
|
2000-10-23 23:33:06 +02:00
|
|
|
struct res_type *type = NULL;
|
|
|
|
struct res_name *name = NULL;
|
|
|
|
|
2004-02-11 07:41:01 +01:00
|
|
|
qsort( spec->resources, spec->nb_resources, sizeof(*spec->resources), cmp_res );
|
2000-10-23 23:33:06 +02:00
|
|
|
|
2004-02-11 07:41:01 +01:00
|
|
|
tree = xmalloc( sizeof(*tree) );
|
|
|
|
tree->types = NULL;
|
|
|
|
tree->nb_types = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < spec->nb_resources; i++)
|
2000-10-23 23:33:06 +02:00
|
|
|
{
|
2004-02-11 07:41:01 +01:00
|
|
|
if (!i || cmp_string( &spec->resources[i].type, &spec->resources[i-1].type )) /* new type */
|
2000-10-23 23:33:06 +02:00
|
|
|
{
|
2004-02-11 07:41:01 +01:00
|
|
|
type = add_type( tree, &spec->resources[i] );
|
|
|
|
name = add_name( type, &spec->resources[i] );
|
2000-10-23 23:33:06 +02:00
|
|
|
}
|
2004-02-11 07:41:01 +01:00
|
|
|
else if (cmp_string( &spec->resources[i].name, &spec->resources[i-1].name )) /* new name */
|
2000-10-23 23:33:06 +02:00
|
|
|
{
|
2004-02-11 07:41:01 +01:00
|
|
|
name = add_name( type, &spec->resources[i] );
|
2000-10-23 23:33:06 +02:00
|
|
|
}
|
|
|
|
else name->nb_languages++;
|
|
|
|
}
|
2004-02-11 07:41:01 +01:00
|
|
|
return tree;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* free the resource tree */
|
|
|
|
static void free_resource_tree( struct res_tree *tree )
|
|
|
|
{
|
2005-03-18 15:04:07 +01:00
|
|
|
unsigned int i;
|
2004-02-11 07:41:01 +01:00
|
|
|
|
|
|
|
for (i = 0; i < tree->nb_types; i++) free( tree->types[i].names );
|
|
|
|
free( tree->types );
|
|
|
|
free( tree );
|
2000-10-23 23:33:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* output a Unicode string */
|
|
|
|
static void output_string( FILE *outfile, const WCHAR *name )
|
|
|
|
{
|
|
|
|
int i, len = strlenW(name);
|
|
|
|
fprintf( outfile, "0x%04x", len );
|
|
|
|
for (i = 0; i < len; i++) fprintf( outfile, ", 0x%04x", name[i] );
|
|
|
|
fprintf( outfile, " /* " );
|
|
|
|
for (i = 0; i < len; i++) fprintf( outfile, "%c", isprint((char)name[i]) ? (char)name[i] : '?' );
|
|
|
|
fprintf( outfile, " */" );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* output the resource definitions */
|
2004-02-11 07:41:01 +01:00
|
|
|
void output_resources( FILE *outfile, DLLSPEC *spec )
|
2000-10-23 23:33:06 +02:00
|
|
|
{
|
2005-03-18 15:04:07 +01:00
|
|
|
int j, k, nb_id_types;
|
|
|
|
unsigned int i, n, offset, data_offset;
|
2004-02-11 07:41:01 +01:00
|
|
|
struct res_tree *tree;
|
2004-09-07 22:45:03 +02:00
|
|
|
struct res_type *type;
|
|
|
|
struct res_name *name;
|
2000-10-23 23:33:06 +02:00
|
|
|
const struct resource *res;
|
|
|
|
|
2004-02-11 07:41:01 +01:00
|
|
|
if (!spec->nb_resources) return;
|
2000-10-23 23:33:06 +02:00
|
|
|
|
2004-02-11 07:41:01 +01:00
|
|
|
tree = build_resource_tree( spec );
|
2000-10-23 23:33:06 +02:00
|
|
|
|
|
|
|
/* directory structures */
|
|
|
|
|
|
|
|
fprintf( outfile, "struct res_dir {\n" );
|
|
|
|
fprintf( outfile, " unsigned int Characteristics;\n" );
|
|
|
|
fprintf( outfile, " unsigned int TimeDateStamp;\n" );
|
|
|
|
fprintf( outfile, " unsigned short MajorVersion, MinorVersion;\n" );
|
|
|
|
fprintf( outfile, " unsigned short NumerOfNamedEntries, NumberOfIdEntries;\n};\n\n" );
|
|
|
|
fprintf( outfile, "struct res_dir_entry {\n" );
|
|
|
|
fprintf( outfile, " unsigned int Name;\n" );
|
|
|
|
fprintf( outfile, " unsigned int OffsetToData;\n};\n\n" );
|
|
|
|
fprintf( outfile, "struct res_data_entry {\n" );
|
|
|
|
fprintf( outfile, " const unsigned int *OffsetToData;\n" );
|
|
|
|
fprintf( outfile, " unsigned int Size;\n" );
|
|
|
|
fprintf( outfile, " unsigned int CodePage;\n" );
|
|
|
|
fprintf( outfile, " unsigned int ResourceHandle;\n};\n\n" );
|
|
|
|
|
|
|
|
/* resource directory definition */
|
|
|
|
|
2000-10-24 03:42:17 +02:00
|
|
|
fprintf( outfile, "static struct res_struct{\n" );
|
2000-10-23 23:33:06 +02:00
|
|
|
fprintf( outfile, " struct res_dir type_dir;\n" );
|
2004-02-11 07:41:01 +01:00
|
|
|
fprintf( outfile, " struct res_dir_entry type_entries[%d];\n", tree->nb_types );
|
2004-09-07 22:45:03 +02:00
|
|
|
offset = RESDIR_SIZE( tree->nb_types );
|
2000-10-23 23:33:06 +02:00
|
|
|
|
2004-02-11 07:41:01 +01:00
|
|
|
for (i = 0, type = tree->types; i < tree->nb_types; i++, type++)
|
2000-10-23 23:33:06 +02:00
|
|
|
{
|
2004-09-07 22:45:03 +02:00
|
|
|
offset += RESDIR_SIZE( type->nb_names );
|
2000-10-23 23:33:06 +02:00
|
|
|
fprintf( outfile, " struct res_dir name_%d_dir;\n", i );
|
|
|
|
fprintf( outfile, " struct res_dir_entry name_%d_entries[%d];\n", i, type->nb_names );
|
2000-11-11 01:38:37 +01:00
|
|
|
for (n = 0, name = type->names; n < type->nb_names; n++, name++)
|
2000-10-23 23:33:06 +02:00
|
|
|
{
|
2004-09-07 22:45:03 +02:00
|
|
|
offset += RESDIR_SIZE( name->nb_languages );
|
2000-11-11 01:38:37 +01:00
|
|
|
fprintf( outfile, " struct res_dir lang_%d_%d_dir;\n", i, n );
|
2000-10-23 23:33:06 +02:00
|
|
|
fprintf( outfile, " struct res_dir_entry lang_%d_%d_entries[%d];\n",
|
2000-11-11 01:38:37 +01:00
|
|
|
i, n, name->nb_languages );
|
2000-10-23 23:33:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-11 07:41:01 +01:00
|
|
|
fprintf( outfile, " struct res_data_entry data_entries[%d];\n", spec->nb_resources );
|
2004-09-07 22:45:03 +02:00
|
|
|
offset += spec->nb_resources * 4 * sizeof(int);
|
2000-10-23 23:33:06 +02:00
|
|
|
|
2004-02-11 07:41:01 +01:00
|
|
|
for (i = nb_id_types = 0, type = tree->types; i < tree->nb_types; i++, type++)
|
2000-10-23 23:33:06 +02:00
|
|
|
{
|
|
|
|
if (type->type->str)
|
2004-09-07 22:45:03 +02:00
|
|
|
{
|
|
|
|
type->name_offset = offset | 0x80000000;
|
|
|
|
offset += (strlenW(type->type->str)+1) * sizeof(unsigned short);
|
2000-10-23 23:33:06 +02:00
|
|
|
fprintf( outfile, " unsigned short type_%d_name[%d];\n",
|
|
|
|
i, strlenW(type->type->str)+1 );
|
2004-09-07 22:45:03 +02:00
|
|
|
}
|
2004-02-11 07:41:01 +01:00
|
|
|
else
|
2004-09-07 22:45:03 +02:00
|
|
|
{
|
|
|
|
type->name_offset = type->type->id;
|
2004-02-11 07:41:01 +01:00
|
|
|
nb_id_types++;
|
2004-09-07 22:45:03 +02:00
|
|
|
}
|
2004-02-11 07:41:01 +01:00
|
|
|
|
2000-11-11 01:38:37 +01:00
|
|
|
for (n = 0, name = type->names; n < type->nb_names; n++, name++)
|
2000-10-23 23:33:06 +02:00
|
|
|
{
|
|
|
|
if (name->name->str)
|
2004-09-07 22:45:03 +02:00
|
|
|
{
|
|
|
|
name->name_offset = offset | 0x80000000;
|
|
|
|
offset += (strlenW(name->name->str)+1) * sizeof(unsigned short);
|
2000-10-23 23:33:06 +02:00
|
|
|
fprintf( outfile, " unsigned short name_%d_%d_name[%d];\n",
|
2000-11-11 01:38:37 +01:00
|
|
|
i, n, strlenW(name->name->str)+1 );
|
2004-09-07 22:45:03 +02:00
|
|
|
}
|
|
|
|
else name->name_offset = name->name->id;
|
2000-10-23 23:33:06 +02:00
|
|
|
}
|
|
|
|
}
|
2005-06-05 20:36:24 +02:00
|
|
|
for (i = 0, res = spec->resources; i < spec->nb_resources; i++, res++)
|
|
|
|
fprintf( outfile, " unsigned int res_%d[%d];\n", i, res->data_size / 4 );
|
2000-10-23 23:33:06 +02:00
|
|
|
|
|
|
|
/* resource directory contents */
|
|
|
|
|
2005-06-05 20:36:24 +02:00
|
|
|
fprintf( outfile, "} __wine_spec_resources = {\n" );
|
2004-02-11 07:41:01 +01:00
|
|
|
fprintf( outfile, " { 0, 0, 0, 0, %d, %d },\n", tree->nb_types - nb_id_types, nb_id_types );
|
2000-10-23 23:33:06 +02:00
|
|
|
|
|
|
|
/* dump the type directory */
|
2004-09-07 22:45:03 +02:00
|
|
|
offset = RESDIR_SIZE( tree->nb_types );
|
2000-10-23 23:33:06 +02:00
|
|
|
fprintf( outfile, " {\n" );
|
2004-02-11 07:41:01 +01:00
|
|
|
for (i = 0, type = tree->types; i < tree->nb_types; i++, type++)
|
2000-10-23 23:33:06 +02:00
|
|
|
{
|
2004-09-07 22:45:03 +02:00
|
|
|
fprintf( outfile, " { 0x%08x, 0x%08x },\n", type->name_offset, offset | 0x80000000 );
|
|
|
|
offset += RESDIR_SIZE( type->nb_names );
|
|
|
|
for (n = 0, name = type->names; n < type->nb_names; n++, name++)
|
|
|
|
offset += RESDIR_SIZE( name->nb_languages );
|
2000-10-23 23:33:06 +02:00
|
|
|
}
|
|
|
|
fprintf( outfile, " },\n" );
|
|
|
|
|
2004-09-07 22:45:03 +02:00
|
|
|
data_offset = offset;
|
|
|
|
offset = RESDIR_SIZE( tree->nb_types );
|
|
|
|
|
2000-10-23 23:33:06 +02:00
|
|
|
/* dump the names and languages directories */
|
2004-02-11 07:41:01 +01:00
|
|
|
for (i = 0, type = tree->types; i < tree->nb_types; i++, type++)
|
2000-10-23 23:33:06 +02:00
|
|
|
{
|
|
|
|
fprintf( outfile, " { 0, 0, 0, 0, %d, %d }, /* name_%d_dir */\n {\n",
|
|
|
|
type->nb_names - type->nb_id_names, type->nb_id_names, i );
|
2004-09-07 22:45:03 +02:00
|
|
|
offset += RESDIR_SIZE( type->nb_names );
|
2000-11-11 01:38:37 +01:00
|
|
|
for (n = 0, name = type->names; n < type->nb_names; n++, name++)
|
2000-10-23 23:33:06 +02:00
|
|
|
{
|
2004-09-07 22:45:03 +02:00
|
|
|
fprintf( outfile, " { 0x%08x, 0x%08x },\n", name->name_offset, offset | 0x80000000 );
|
|
|
|
offset += RESDIR_SIZE( name->nb_languages );
|
2000-10-23 23:33:06 +02:00
|
|
|
}
|
|
|
|
fprintf( outfile, " },\n" );
|
|
|
|
|
2000-11-11 01:38:37 +01:00
|
|
|
for (n = 0, name = type->names; n < type->nb_names; n++, name++)
|
2000-10-23 23:33:06 +02:00
|
|
|
{
|
|
|
|
fprintf( outfile, " { 0, 0, 0, 0, 0, %d }, /* lang_%d_%d_dir */\n {\n",
|
2000-11-11 01:38:37 +01:00
|
|
|
name->nb_languages, i, n );
|
2000-10-23 23:33:06 +02:00
|
|
|
for (k = 0, res = name->res; k < name->nb_languages; k++, res++)
|
|
|
|
{
|
2004-09-07 22:45:03 +02:00
|
|
|
fprintf( outfile, " { 0x%04x, 0x%08x },\n",
|
|
|
|
res->lang, data_offset + (res - spec->resources) * 4 * sizeof(int) );
|
2000-10-23 23:33:06 +02:00
|
|
|
}
|
|
|
|
fprintf( outfile, " },\n" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* dump the resource data entries */
|
|
|
|
fprintf( outfile, " {\n" );
|
2004-02-11 07:41:01 +01:00
|
|
|
for (i = 0, res = spec->resources; i < spec->nb_resources; i++, res++)
|
2000-10-23 23:33:06 +02:00
|
|
|
{
|
2005-06-05 20:36:24 +02:00
|
|
|
fprintf( outfile, " { __wine_spec_resources.res_%d, sizeof(__wine_spec_resources.res_%d), 0, 0 }, /* %08x */\n", i, i,
|
2004-09-07 22:45:03 +02:00
|
|
|
data_offset + i * 4 * sizeof(int) );
|
2000-10-23 23:33:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* dump the name strings */
|
2004-02-11 07:41:01 +01:00
|
|
|
for (i = 0, type = tree->types; i < tree->nb_types; i++, type++)
|
2000-10-23 23:33:06 +02:00
|
|
|
{
|
|
|
|
if (type->type->str)
|
|
|
|
{
|
|
|
|
fprintf( outfile, " },\n { " );
|
|
|
|
output_string( outfile, type->type->str );
|
|
|
|
}
|
2000-11-11 01:38:37 +01:00
|
|
|
for (n = 0, name = type->names; n < type->nb_names; n++, name++)
|
2000-10-23 23:33:06 +02:00
|
|
|
{
|
|
|
|
if (name->name->str)
|
|
|
|
{
|
|
|
|
fprintf( outfile, " },\n { " );
|
|
|
|
output_string( outfile, name->name->str );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-06-05 20:36:24 +02:00
|
|
|
fprintf( outfile, " },\n" );
|
|
|
|
|
|
|
|
/* resource data */
|
|
|
|
|
|
|
|
for (i = 0, res = spec->resources; i < spec->nb_resources; i++, res++)
|
|
|
|
{
|
|
|
|
const unsigned int *p = res->data;
|
|
|
|
int size = res->data_size / 4;
|
|
|
|
/* dump data as ints to ensure correct alignment */
|
|
|
|
fprintf( outfile, " { /* res_%d */\n ", i );
|
|
|
|
for (j = 0; j < size - 1; j++, p++)
|
|
|
|
{
|
|
|
|
fprintf( outfile, "0x%08x,", *p );
|
|
|
|
if ((j % 8) == 7) fprintf( outfile, "\n " );
|
|
|
|
}
|
|
|
|
fprintf( outfile, "0x%08x\n },\n", *p );
|
|
|
|
}
|
|
|
|
fprintf( outfile, "};\n\n" );
|
|
|
|
|
2004-02-11 07:41:01 +01:00
|
|
|
free_resource_tree( tree );
|
2000-10-23 23:33:06 +02:00
|
|
|
}
|