Commit 17f4d979 authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

term_type_str implements the same function as existing enum2str function.

Use one version everywhere, and make sure that one version is complete.
This version also uses a switch with the actuall enum types, which is safer.
parent ab83cffc
......@@ -134,25 +134,31 @@ err:
return ret;
}
static char * controller_block_term_str(enum controller_block_term_type et)
static char * controller_block_term_type2str(enum controller_block_term_type et)
{
char *type;
switch (et) {
case CONTROLLER_BLOCK_TERM_VOID:
return "void";
case CONTROLLER_BLOCK_TERM_FLOAT:
type = "float";
break;
return "float";
case CONTROLLER_BLOCK_TERM_BOOL:
type = "bool";
break;
return "bool";
case CONTROLLER_BLOCK_TERM_UINT8:
return "uint8";
case CONTROLLER_BLOCK_TERM_UINT16:
return "uint16";
case CONTROLLER_BLOCK_TERM_UINT32:
type = "uint32";
break;
return "uint32";
case CONTROLLER_BLOCK_TERM_SINT8:
return "sint8";
case CONTROLLER_BLOCK_TERM_SINT16:
return "sint16";
case CONTROLLER_BLOCK_TERM_SINT32:
return "sint32";
default:
type = "unknown";
break;
};
return type;
return "unknown";
}
int controller_block_add(struct controller_block *newblock)
......@@ -183,7 +189,8 @@ int controller_block_add(struct controller_block *newblock)
for (i = 0; i < newblock->inputs; i++) {
char *type;
type = controller_block_term_str(newblock->input[i].type);
type = controller_block_term_type2str(
newblock->input[i].type);
log_send(LOG_T_DEBUG,
"\t\t%d\t%s (%s)", i, newblock->input[i].name,
type);
......@@ -195,7 +202,8 @@ int controller_block_add(struct controller_block *newblock)
for (i = 0; i < newblock->outputs; i++) {
char *type;
type = controller_block_term_str(newblock->output[i].type);
type = controller_block_term_type2str(
newblock->output[i].type);
log_send(LOG_T_DEBUG, "\t\t%d\t%s (%s)",
i, newblock->output[i].name, type);
}
......@@ -437,20 +445,6 @@ int controller_block_connect(char *outblock, char *outterm, char *inblock, char
}
}
// Keep this list in sync with the controller_block_term_type enum in
// controller_block.h !
static const char *term_type_str[] = {
"(unknown)",
"float",
"bool",
"uint8",
"uint16",
"uint32",
"sint8",
"sint16",
"sint32",
};
static void set_ghost_otherside(struct controller_block_interm *input,
struct controller_block *otherside, void *outptr)
{
......@@ -513,14 +507,14 @@ static int controller_block_resolve_link(struct controller_block_link *link)
"%s.%s (of type '%s') to input terminal %s.%s "
"(of type '%s')",
link->outblock, link->outterm,
term_type_str[outtype],
controller_block_term_type2str(outtype),
link->inblock, link->interm,
term_type_str[in->input[i].type]);
controller_block_term_type2str(in->input[i].type));
return -1;
}
// Found both. Let's link them..
link->type = controller_block_term_str(in->input[i].type);
link->type = controller_block_term_type2str(in->input[i].type);
log_send(LOG_T_DEBUG,
"Linking %s.%s to %s.%s%s",
......
Supports Markdown
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