const char *cbf_copy_strings (cbf_context *context, const char *string1, const char *string2, char type) { char *new_string; void *memblock; if (!string1) return cbf_copy_string(context,string2,type); if (!string2) return cbf_copy_string(context,string2,type); if (type) { if (cbf_alloc (&memblock, NULL, sizeof (char), strlen (string1) + strlen(string2) + 2) == 0) { new_string = (char *)memblock; *new_string = type; strcpy (new_string + 1, string1); strcpy (new_string + 1 + strlen(string1),string2); return new_string; } } if (cbf_alloc (&memblock, NULL, sizeof (char), strlen (string1) + strlen(string2) + 1) == 0) { new_string = (char *)memblock; strcpy (new_string, string1); strcpy (new_string + strlen(string1), string2); return new_string; } return NULL; }
const char *cbf_copy_string (cbf_context *context, const char *string, char type) { char *new_string; void *memblock; if (string) { if (type) { if (cbf_alloc (&memblock, NULL, sizeof (char), strlen (string) + 2) == 0) { new_string = (char *)memblock; *new_string = type; strcpy (new_string + 1, string); return new_string; } } else if (cbf_alloc (&memblock, NULL, \ sizeof (char), strlen (string) + 1) == 0) { new_string = (char *)memblock; strcpy (new_string, string); return new_string; } } /* Fail */ return NULL; }
int cbf_make_context (cbf_context **context) { /* Allocate the memory */ cbf_failnez (cbf_alloc ((void **) context, NULL, sizeof (cbf_context), 1)) /* Initialise */ (*context)->temporary = NULL; (*context)->connections = 1; /* Success */ return 0; }
int cbf_make_new_node (cbf_node **node, CBF_NODETYPE type, cbf_context *context, const char *name) { int errorcode; if (!node) return CBF_ARGUMENT; /* Create the new node */ cbf_failnez (cbf_alloc ((void **) node, NULL, sizeof (cbf_node), 1)) /* Initialise the node */ (*node)->type = type; (*node)->name = NULL; (*node)->link = NULL; (*node)->parent = NULL; (*node)->children = 0; (*node)->child_size = 0; (*node)->child = NULL; /* Add the context? */ if (type == CBF_LINK) (*node)->context = NULL; else { /* Does the context exist? */ if (context) (*node)->context = context; else (*node)->context = NULL; /* Add a context connection */ cbf_onfailnez (cbf_add_contextconnection (&(*node)->context), cbf_free ((void **) node, NULL)) /* Name the node */ errorcode = cbf_name_new_node (*node, name); if (errorcode) { errorcode |= cbf_free_context (&(*node)->context); return errorcode | cbf_free_node (*node); } } /* Success */ return 0; }