summaryrefslogtreecommitdiff
path: root/src/base/idManager.c
diff options
context:
space:
mode:
authorConnor Thomson <blumatrikz@gmail.com>2026-09-08 18:27:39 -0700
committerConnor Thomson <blumatrikz@gmail.com>2026-09-08 18:27:39 -0700
commitf1ddc12b68b4e4c8087962de25260470e6df2bea (patch)
tree7d0440a6402a9b0ef75ded23fa64b68534255bba /src/base/idManager.c
parent6025860a61386bf767b29c3ec5fd0d31285f1056 (diff)
Add tuxanci2 files
Diffstat (limited to 'src/base/idManager.c')
-rw-r--r--src/base/idManager.c198
1 files changed, 0 insertions, 198 deletions
diff --git a/src/base/idManager.c b/src/base/idManager.c
deleted file mode 100644
index 87042bb..0000000
--- a/src/base/idManager.c
+++ /dev/null
@@ -1,198 +0,0 @@
-#include <stdlib.h>
-#include <stdio.h>
-#include <assert.h>
-
-#include "main.h"
-#include "list.h"
-#include "idManager.h"
-
-static list_t *listID;
-static int lastID;
-
-typedef struct id_item_struct {
- int id;
- int count;
-} id_item_t;
-
-static id_item_t *newIdItem(int id, int count)
-{
- id_item_t *new;
-
- new = malloc(sizeof(id_item_t));
- new->id = id;
- new->count = count;
-
- return new;
-}
-
-static void destroyIdItem(id_item_t *p)
-{
- assert(p != NULL);
-
- free(p);
-}
-
-void id_init_list()
-{
- debug("Initializing ID manager");
-
- listID = list_new();
- lastID = 0;
-
-}
-
-int id_is_register(int id)
-{
- int i;
-
- assert(listID != NULL);
-
- for (i = 0; i < listID->count; i++) {
- id_item_t *this;
-
- this = listID->list[i];
-
- if (this->id == id) {
- return i;
- }
- }
-
- return -1;
-}
-
-static int findNewID()
-{
- int ret;
-
- assert(listID != NULL);
-
- if (listID->count >= MAX_ID - 1) {
- fatal("There is no free ID left");
- }
-
- do {
- /*ret = (random() % (listID->count + 8 )) + 1;*/
- ret = random() % MAX_ID + 1;
- } while (id_is_register(ret) != -1);
-
- /*printf("new ID %d\n", ret);*/
-
- return ret;
-}
-
-int id_get_newcount(int count)
-{
- int id;
-
- id = findNewID();
-
- list_add(listID, newIdItem(id, count));
-
- return id;
-}
-
-int id_get_new()
-{
- return id_get_newcount(1);
-}
-
-void id_inc(int id)
-{
- id_item_t *this;
- int index;
-
- assert(listID != NULL);
-
- index = id_is_register(id);
-
- if (index == -1) {
- error("Trying to increment counter of never registered ID [%d]", id);
- assert(0);
- return; /* ha ha ha */
- }
-
- this = listID->list[index];
-
- this->count++;
-
- /*printf("inc ID %d %d\n", this->id, this->count);*/
- return;
-}
-
-void id_del(int id)
-{
- id_item_t *this;
- int index;
-
- assert(listID != NULL);
-
- index = id_is_register(id);
-
- if (index == -1) {
- error("Trying to delete never registered ID [%d]", id);
- assert(0);
- return; /* ha ha ha */
- }
-
- this = listID->list[index];
-
- this->count--;
- /*printf("dec ID %d %d\n", this->id, this->count);*/
-
- if (this->count <= 0) {
- list_del_item(listID, index, free);
- /*printf("listID->count = %d\n", listID->count);*/
- }
-
- return;
-}
-
-void id_replace(int old_id, int new_id)
-{
- int index_old_id;
- int index_new_id;
- id_item_t *this;
-
- if (old_id == new_id) {
- return;
- }
-
- index_old_id = id_is_register(old_id);
- assert(index_old_id != -1);
-
- index_new_id = id_is_register(new_id);
- assert(index_new_id == -1);
-
- this = listID->list[index_old_id];
- this->id = new_id;
-}
-
-void infoID(int id)
-{
- id_item_t *this;
- int index;
-
- assert(listID != NULL);
-
- index = id_is_register(id);
-
- if (index == -1) {
- debug("Getting information of nonexistent ID [%d]", id);
-
- return;
- }
-
- this = listID->list[index];
-
- debug("ID information [%d]: used %d times", this->id, this->count);
-
- return;
-}
-
-void id_quit_list()
-{
- debug("Shutting down ID manager");
-
- assert(listID != NULL);
- list_destroy_item(listID, destroyIdItem);
-}