Commit 264d8884 authored by Alexandre Julliard's avatar Alexandre Julliard

widl: Add strmake() helper.

parent 9240ffbb
......@@ -2038,11 +2038,8 @@ var_t *find_const(const char *name, int f)
char *gen_name(void)
{
static const char format[] = "__WIDL_%s_generated_name_%08lX";
static unsigned long n = 0;
static const char *file_id;
static size_t size;
char *name;
if (! file_id)
{
......@@ -2052,13 +2049,8 @@ char *gen_name(void)
for (; *dst; ++dst)
if (! isalnum((unsigned char) *dst))
*dst = '_';
size = sizeof format - 7 + strlen(file_id) + 8;
}
name = xmalloc(size);
sprintf(name, format, file_id, n++);
return name;
return strmake("__WIDL_%s_generated_name_%08lX", file_id, n++);
}
struct allowed_attr
......@@ -2727,14 +2719,6 @@ static void check_functions(const type_t *iface, int is_inside_library)
}
}
static char *concat_str(const char *prefix, const char *str)
{
char *ret = xmalloc(strlen(prefix) + strlen(str) + 1);
strcpy(ret, prefix);
strcat(ret, str);
return ret;
}
static int async_iface_attrs(attr_list_t *attrs, const attr_t *attr)
{
switch(attr->type)
......@@ -2774,7 +2758,7 @@ static void check_async_uuid(type_t *iface)
if (!inherit)
error_loc("async_uuid applied to an interface with incompatible parent\n");
async_iface = get_type(TYPE_INTERFACE, concat_str("Async", iface->name), iface->namespace, 0);
async_iface = get_type(TYPE_INTERFACE, strmake("Async%s", iface->name), iface->namespace, 0);
async_iface->attrs = map_attrs(iface->attrs, async_iface_attrs);
STATEMENTS_FOR_EACH_FUNC( stmt, type_iface_get_stmts(iface) )
......@@ -2791,13 +2775,13 @@ static void check_async_uuid(type_t *iface)
finish_args = append_var(finish_args, copy_var(arg, strdup(arg->name), arg_out_attrs));
}
begin_func = copy_var(func, concat_str("Begin_", func->name), NULL);
begin_func = copy_var(func, strmake("Begin_%s", func->name), NULL);
begin_func->declspec.type = type_new_function(begin_args);
begin_func->declspec.type->attrs = func->attrs;
begin_func->declspec.type->details.function->retval = func->declspec.type->details.function->retval;
stmts = append_statement(stmts, make_statement_declaration(begin_func));
finish_func = copy_var(func, concat_str("Finish_", func->name), NULL);
finish_func = copy_var(func, strmake("Finish_%s", func->name), NULL);
finish_func->declspec.type = type_new_function(finish_args);
finish_func->declspec.type->attrs = func->attrs;
finish_func->declspec.type->details.function->retval = func->declspec.type->details.function->retval;
......
......@@ -321,8 +321,7 @@ void output_typelib_regscript( const typelib_t *typelib )
if (expr)
{
sprintf(id_part, "\\%d", expr->cval);
resname = xmalloc( strlen(typelib_name) + 20 );
sprintf(resname, "%s\\%d", typelib_name, expr->cval);
resname = strmake("%s\\%d", typelib_name, expr->cval);
}
put_str( indent, "'%x' { %s = s '%%MODULE%%%s' }\n",
lcid_expr ? lcid_expr->cval : 0, pointer_size == 8 ? "win64" : "win32", id_part );
......
......@@ -226,6 +226,25 @@ void *xrealloc(void *p, size_t size)
return res;
}
char *strmake( const char* fmt, ... )
{
int n;
size_t size = 100;
va_list ap;
for (;;)
{
char *p = xmalloc( size );
va_start( ap, fmt );
n = vsnprintf( p, size, fmt, ap );
va_end( ap );
if (n == -1) size *= 2;
else if ((size_t)n >= size) size = n + 1;
else return p;
free( p );
}
}
char *xstrdup(const char *str)
{
char *s;
......
......@@ -44,6 +44,7 @@ void error_loc_info(const loc_info_t *, const char *s, ...) __attribute__((forma
void warning(const char *s, ...) __attribute__((format (printf, 1, 2)));
void warning_loc_info(const loc_info_t *, const char *s, ...) __attribute__((format (printf, 2, 3)));
void chat(const char *s, ...) __attribute__((format (printf, 1, 2)));
char *strmake(const char* fmt, ...) __attribute__((__format__ (__printf__, 1, 2 )));
char *dup_basename(const char *name, const char *ext);
size_t widl_getline(char **linep, size_t *lenp, FILE *fp);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment