lambda-calc-1/stringtree/prepend.c
2025-01-13 20:36:07 -06:00

156 lines
1.9 KiB
C

#include <assert.h>
#include <debug.h>
#include <memory/smalloc.h>
#include <string/new.h>
#include <string/inc.h>
#include <string/free.h>
#include "inc.h"
#include "struct.h"
#include "prepend.h"
void stringtree_prepend_cstr(
struct stringtree* this,
const wchar_t* cstr)
{
ENTER;
struct child* new = smalloc(sizeof(*new));
new->kind = ck_cstr;
new->cstr = cstr;
new->prev = NULL;
new->next = NULL;
if (this->head)
{
new->next = this->head;
this->head = new;
}
else
{
this->head = new;
this->tail = new;
}
EXIT;
}
void stringtree_prepend_formatstr(
struct stringtree* this,
const char* fmt, ...)
{
ENTER;
TODO;
#if 0
va_list va;
va_start(va, fmt);
struct string* string = new_string_from_vargs(fmt, va);
stringtree_prepend_string(this, string);
free_string(string);
va_end(va);
#endif
EXIT;
}
void stringtree_prepend_string(
struct stringtree* this,
struct string* string)
{
ENTER;
struct child* new = smalloc(sizeof(*new));
new->kind = ck_string;
new->string = inc_string(string);
new->prev = NULL;
new->next = NULL;
if (this->head)
{
new->next = this->head;
this->head = new;
}
else
{
this->head = new;
this->tail = new;
}
EXIT;
}
void stringtree_prepend_stringtree(
struct stringtree* this,
struct stringtree* stringtree)
{
ENTER;
struct child* new = smalloc(sizeof(*new));
new->kind = ck_stringtree;
new->stringtree = inc_stringtree(stringtree);
new->prev = NULL;
new->next = NULL;
if (this->head)
{
new->next = this->head;
this->head = new;
}
else
{
this->head = new;
this->tail = new;
}
EXIT;
}