shithub: gpufs

ref: 8b6238bf263ac5d1f357c0f4a4d0e113b83f1570
dir: /names.c/

View raw version
#include <u.h>
#include <libc.h>
#include "names.h"

Name *names = nil;
String *strings = nil;

void
nameadd(uint id, char *name)
{
	Name *n;
	
	n = malloc(sizeof(Name));
	n->name = strdup(name);
	n->id = id;
	n->next = names;
	names = n;
}

void
stringadd(uint id, char *str)
{
	String *s;
	
	s = malloc(sizeof(String));
	s->str = strdup(str);
	s->id = id;
	s->next = strings;
	strings = s;
}

char*
namelookup(uint id)
{
	Name *n;
	
	for (n = names; n; n = n->next) {
		if (n->id == id)
			return n->name;
	}
	return nil;
}

char*
strlookup(uint id)
{
	String *s;
	
	for (s = strings; s; s = s->next) {
		if (s->id == id)
			return s->str;
	}
	return nil;
}