mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-05 07:01:53 +02:00
41 lines
692 B
C
41 lines
692 B
C
|
/*
|
||
|
* 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;
|
||
|
}
|