/* This file is part of `mogul'
 * Copyright (c) 1995 David Deaven
 *
 * In the following, "you" and "You" refer to any entity other than 
 * the Microsoft corporation and its subsidiaries.  All rights are
 * reserved by the author in connection with Microsoft and its
 * subsidiaries.  The Microsoft Network is explicity denied the right
 * to copy, reproduce, or transmit this software.
 *
 *   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.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * $Author: deaven $
 * $Id: stringpool.c,v 2.0 1996/07/09 20:59:55 deaven Exp $
 */

#include <math.h>
#include <stdlib.h>
#include "dmd/memory.h"
#include "mogul.h"

struct StringPoolRec {
	unsigned int n;
	char **pool;
};

StringPool NewStringPool(void)
{
	StringPool sp = NewPointer(sp);
	sp->n = 0;
	sp->pool = NULL;
	return sp;
}

void DeleteStringPool(StringPool sp)
{
	if (sp) {
	  int i;
	  for(i=0; i<sp->n; i++) myfree(sp->pool[i]);
	  myfree(sp->pool);
	  myfree(sp);
	}
}

char *AddToStringPool(StringPool sp, char *s)
{
	int i;
	for(i=0; i<sp->n; i++)
	  if(!strcmp(sp->pool[i], s)) return sp->pool[i];

	sp->pool = ResizePointerArray(sp->pool, sp->n + 1);
	sp->pool[sp->n] = mystrdup(s);
	return sp->pool[(sp->n)++];
}

