mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
va.[ch]:
new va function: nva which returns a strduped buffer expr.c options.c: use nva instead of strdup (va (... struct.c type.c: make type encoding work properly for structs
This commit is contained in:
parent
b98e52fb53
commit
e774943f24
7 changed files with 57 additions and 34 deletions
|
@ -32,7 +32,9 @@
|
|||
|
||||
#include "QF/gcc_attr.h"
|
||||
|
||||
char *va(const char *format, ...) __attribute__((format(printf,1,2)));
|
||||
// does a varargs printf into a temp buffer
|
||||
char *va(const char *format, ...) __attribute__((format(printf,1,2)));
|
||||
// does a varargs printf into a malloced buffer
|
||||
char *nva(const char *format, ...) __attribute__((format(printf,1,2)));
|
||||
|
||||
#endif // __va_h
|
||||
|
|
|
@ -30,17 +30,18 @@ static const char rcsid[] =
|
|||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
#ifdef HAVE_STRING_H
|
||||
# include <string.h>
|
||||
#endif
|
||||
#ifdef HAVE_STRINGS_H
|
||||
# include <strings.h>
|
||||
#endif
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "QF/dstring.h"
|
||||
#include "QF/qtypes.h"
|
||||
#include "QF/sys.h"
|
||||
#include "QF/va.h"
|
||||
|
||||
#include "compat.h"
|
||||
|
||||
|
||||
/*
|
||||
va
|
||||
|
@ -63,3 +64,19 @@ va (const char *fmt, ...)
|
|||
|
||||
return string->str;
|
||||
}
|
||||
|
||||
char *
|
||||
nva (const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
static dstring_t *string;
|
||||
|
||||
if (!string)
|
||||
string = dstring_new ();
|
||||
|
||||
va_start (args, fmt);
|
||||
dvsprintf (string, fmt, args);
|
||||
va_end (args);
|
||||
|
||||
return strdup (string->str);
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
|
||||
typedef struct type_s {
|
||||
etype_t type;
|
||||
const char *name;
|
||||
struct type_s *next;
|
||||
// function/pointer/struct types are more complex
|
||||
struct type_s *aux_type; // return type or field type
|
||||
|
|
|
@ -366,7 +366,7 @@ new_label_name (void)
|
|||
const char *fname = current_func->def->name;
|
||||
char *lname;
|
||||
|
||||
lname = strdup (va ("$%s_%d", fname, lnum));
|
||||
lname = nva ("$%s_%d", fname, lnum);
|
||||
SYS_CHECKMEM (lname);
|
||||
return lname;
|
||||
}
|
||||
|
|
|
@ -255,7 +255,7 @@ DecodeArgs (int argc, char **argv)
|
|||
char *temp = strtok (opts, ",");
|
||||
|
||||
while (temp) {
|
||||
add_cpp_def (strdup (va ("%s%s", "-D", temp)));
|
||||
add_cpp_def (nva ("%s%s", "-D", temp));
|
||||
temp = strtok (NULL, ",");
|
||||
}
|
||||
free (opts);
|
||||
|
@ -266,7 +266,7 @@ DecodeArgs (int argc, char **argv)
|
|||
char *temp = strtok (opts, ",");
|
||||
|
||||
while (temp) {
|
||||
add_cpp_def (strdup (va ("%s%s", "-I", temp)));
|
||||
add_cpp_def (nva ("%s%s", "-I", temp));
|
||||
temp = strtok (NULL, ",");
|
||||
}
|
||||
free (opts);
|
||||
|
@ -277,7 +277,7 @@ DecodeArgs (int argc, char **argv)
|
|||
char *temp = strtok (opts, ",");
|
||||
|
||||
while (temp) {
|
||||
add_cpp_def (strdup (va ("%s%s", "-U", temp)));
|
||||
add_cpp_def (nva ("%s%s", "-U", temp));
|
||||
temp = strtok (NULL, ",");
|
||||
}
|
||||
free (opts);
|
||||
|
|
|
@ -136,8 +136,10 @@ new_struct (const char *name)
|
|||
strct->type->type = ev_struct;
|
||||
strct->type->struct_tail = &strct->type->struct_head;
|
||||
strct->type->struct_fields = Hash_NewTable (61, struct_field_get_key, 0, 0);
|
||||
if (name)
|
||||
if (name) {
|
||||
strct->type->name = strdup (name);
|
||||
Hash_Add (structs, strct);
|
||||
}
|
||||
return strct->type;
|
||||
}
|
||||
|
||||
|
|
|
@ -61,34 +61,35 @@ typedef struct typedef_s {
|
|||
} typedef_t;
|
||||
|
||||
// simple types. function types are dynamically allocated
|
||||
type_t type_void = { ev_void };
|
||||
type_t type_string = { ev_string };
|
||||
type_t type_float = { ev_float };
|
||||
type_t type_vector = { ev_vector };
|
||||
type_t type_entity = { ev_entity };
|
||||
type_t type_field = { ev_field };
|
||||
type_t type_void = { ev_void, "void" };
|
||||
type_t type_string = { ev_string, "string" };
|
||||
type_t type_float = { ev_float, "float" };
|
||||
type_t type_vector = { ev_vector, "vector" };
|
||||
type_t type_entity = { ev_entity, "entity" };
|
||||
type_t type_field = { ev_field, "field" };
|
||||
|
||||
// type_function is a void() function used for state defs
|
||||
type_t type_function = { ev_func, NULL, &type_void };
|
||||
type_t type_pointer = { ev_pointer, NULL, &type_void };
|
||||
type_t type_quaternion = { ev_quaternion };
|
||||
type_t type_integer = { ev_integer };
|
||||
type_t type_uinteger = { ev_uinteger };
|
||||
type_t type_short = { ev_short };
|
||||
type_t type_struct = { ev_struct };
|
||||
type_t type_function = { ev_func, "function", NULL, &type_void };
|
||||
type_t type_pointer = { ev_pointer, "pointer", NULL, &type_void };
|
||||
type_t type_quaternion = { ev_quaternion, "quaternion" };
|
||||
type_t type_integer = { ev_integer, "integer" };
|
||||
type_t type_uinteger = { ev_uinteger, "uiniteger" };
|
||||
type_t type_short = { ev_short, "short" };
|
||||
type_t type_struct = { ev_struct, "struct" };
|
||||
// these will be built up further
|
||||
type_t type_id = { ev_pointer };
|
||||
type_t type_Class = { ev_pointer };
|
||||
type_t type_Protocol = { ev_pointer };
|
||||
type_t type_SEL = { ev_pointer };
|
||||
type_t type_IMP = { ev_func, NULL, &type_id, -3, { &type_id, &type_SEL }};
|
||||
type_t type_obj_exec_class = { ev_func, NULL, &type_void, 1, { 0 }};
|
||||
type_t type_Method = { ev_pointer };
|
||||
type_t type_id = { ev_pointer, "id" };
|
||||
type_t type_Class = { ev_pointer, "Class" };
|
||||
type_t type_Protocol = { ev_pointer, "Protocol" };
|
||||
type_t type_SEL = { ev_pointer, "SEL" };
|
||||
type_t type_IMP = { ev_func, "IMP", NULL, &type_id, -3, { &type_id,
|
||||
&type_SEL }};
|
||||
type_t type_obj_exec_class = { ev_func, "function", NULL, &type_void, 1, { 0 }};
|
||||
type_t type_Method = { ev_pointer, "Method" };
|
||||
type_t *type_category;
|
||||
type_t *type_ivar;
|
||||
type_t *type_module;
|
||||
|
||||
type_t type_floatfield = { ev_field, NULL, &type_float };
|
||||
type_t type_floatfield = { ev_field, ".float", NULL, &type_float };
|
||||
|
||||
static type_t *free_types;
|
||||
|
||||
|
@ -331,7 +332,7 @@ _encode_type (dstring_t *encoding, type_t *type, int level)
|
|||
case ev_object:
|
||||
case ev_class:
|
||||
dstring_appendstr (encoding, "{");
|
||||
//XXX dstring_appendstr (encoding, name);
|
||||
dstring_appendstr (encoding, type->name);
|
||||
if (level < 2) {
|
||||
dstring_appendstr (encoding, "=");
|
||||
for (field = type->struct_head; field; field = field->next)
|
||||
|
@ -345,7 +346,7 @@ _encode_type (dstring_t *encoding, type_t *type, int level)
|
|||
case ev_array:
|
||||
dstring_appendstr (encoding, "[");
|
||||
dstring_appendstr (encoding, va ("%d ", type->num_parms));
|
||||
//XXX dstring_appendstr (encoding, name);
|
||||
_encode_type (encoding, type->aux_type, level + 1);
|
||||
dstring_appendstr (encoding, "]");
|
||||
break;
|
||||
case ev_type_count:
|
||||
|
|
Loading…
Reference in a new issue