1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-12-23 22:21:08 +02:00
eda-tools/b2/util.c

41 lines
692 B
C
Raw Normal View History

2012-03-18 18:24:12 +02:00
/*
* util.h - Utility functions
*
* Copyright 2012 by Werner Almesberger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
#include <string.h>
#include <glib.h>
#include "util.h"
static GTree *tree = NULL;
static gint comp(gconstpointer a, gconstpointer b)
{
return strcmp(a, b);
}
const char *unique(const char *s)
{
char *u;
if (!tree)
tree = g_tree_new(comp);
u = g_tree_lookup(tree, s);
if (!u) {
u = strdup(s);
g_tree_insert(tree, u, u);
}
return u;
}