2002-01-30 06:21:20 +00:00
|
|
|
/*
|
|
|
|
pr_resource.c
|
|
|
|
|
|
|
|
progs resource management
|
|
|
|
|
|
|
|
Copyright (C) 2001 Bill Currie <bill@taniwha.org>
|
|
|
|
|
|
|
|
Author: Bill Currie <bill@taniwha.org>
|
|
|
|
Date: 2002/1/29
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "QF/hash.h"
|
|
|
|
#include "QF/progs.h"
|
|
|
|
#include "QF/sys.h"
|
|
|
|
|
|
|
|
struct pr_resource_s {
|
|
|
|
const char *name;
|
|
|
|
pr_resource_t *next;
|
|
|
|
void *data;
|
|
|
|
void (*clear)(progs_t *pr, void *data);
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *
|
2012-07-18 13:34:37 +00:00
|
|
|
resource_get_key (const void *r, void *unused)
|
2002-01-30 06:21:20 +00:00
|
|
|
{
|
|
|
|
return ((pr_resource_t *)r)->name;
|
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2002-01-30 06:21:20 +00:00
|
|
|
PR_Resources_Init (progs_t *pr)
|
|
|
|
{
|
2020-03-25 06:43:16 +00:00
|
|
|
pr->resource_hash = Hash_NewTable (1021, resource_get_key, 0, 0,
|
2022-05-12 08:54:23 +00:00
|
|
|
pr->hashctx);
|
2002-01-30 06:21:20 +00:00
|
|
|
pr->resources = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PR_Resources_Clear (progs_t *pr)
|
|
|
|
{
|
|
|
|
pr_resource_t *res = pr->resources;
|
|
|
|
while (res) {
|
|
|
|
res->clear (pr, res->data);
|
|
|
|
res = res->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2002-01-30 06:21:20 +00:00
|
|
|
PR_Resources_Register (progs_t *pr, const char *name, void *data,
|
|
|
|
void (*clear)(progs_t *, void *))
|
|
|
|
{
|
|
|
|
pr_resource_t *res = malloc (sizeof (pr_resource_t));
|
|
|
|
if (!res)
|
|
|
|
Sys_Error ("PR_Resources_Register: out of memory");
|
|
|
|
res->name = name;
|
|
|
|
res->data = data;
|
|
|
|
res->clear = clear;
|
|
|
|
res->next = pr->resources;
|
2002-04-09 16:06:05 +00:00
|
|
|
pr->resources = res;
|
2002-01-30 06:21:20 +00:00
|
|
|
Hash_Add (pr->resource_hash, res);
|
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void *
|
2002-01-30 06:21:20 +00:00
|
|
|
PR_Resources_Find (progs_t *pr, const char *name)
|
|
|
|
{
|
|
|
|
pr_resource_t *res = Hash_Find (pr->resource_hash, name);
|
|
|
|
if (!res)
|
|
|
|
return 0;
|
|
|
|
return res->data;
|
|
|
|
}
|