2 * This file provides functions for easier accessing of _the_ table
17 /* This is a two-dimensional dynamic array of Container-pointers. I’ve always wanted
18 * to be a three-star programmer :) */
19 Container ***table = NULL;
21 struct table_dimensions_t table_dims = {0, 0};
32 static void new_container(Container **container) {
34 new = *container = calloc(sizeof(Container), 1);
35 CIRCLEQ_INIT(&(new->clients));
41 * Add one row to the table
44 void expand_table_rows() {
49 for (c = 0; c < table_dims.x; c++) {
50 table[c] = realloc(table[c], sizeof(Container*) * table_dims.y);
51 new_container(&(table[c][table_dims.y-1]));
56 * Add one column to the table
59 void expand_table_cols() {
63 table = realloc(table, sizeof(Container**) * table_dims.x);
64 table[table_dims.x-1] = calloc(sizeof(Container*) * table_dims.y, 1);
65 for (c = 0; c < table_dims.y; c++)
66 new_container(&(table[table_dims.x-1][c]));
70 * Performs simple bounds checking for the given column/row
73 bool cell_exists(int col, int row) {
74 return (col >= 0 && col < table_dims.x) &&
75 (row >= 0 && row < table_dims.y);