Newer
Older
/*
* data.c
*
* Copyright 2022 Jonathan Schöbel <jonathan@Ubermos-2019>
*
* 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., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/
#include <stdlib.h>
static inline void init_pages (struct SH_Data * data);
struct SH_Data *
SH_Data_new ()
{
struct SH_Data * data;
data = malloc (sizeof (struct SH_Data));
if (data == NULL) {
EXIT;
}
static inline void free_pages (struct SH_Data * data);
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
static inline void
init_pages (struct SH_Data * data)
{
data->page_n = 0;
data->pages = malloc (0);
data->page_next = PAGE_MIN;
return;
}
static inline void
free_pages (struct SH_Data * data)
{
unsigned int index;
for (index = 0; index < data->page_n; index++)
{
free (data->pages[index].name);
}
free (data->pages);
return;
}
page_t
SH_Data_register_page (struct SH_Data * data, const char * name)
{
data->pages = realloc (data->pages,
(data->page_n + 1) * sizeof (struct SH_Page));
data->pages[data->page_n].id = data->page_next;
data->pages[data->page_n].name = strdup (name);
/* abort on overflow */
if (data->page_n == UINT_MAX || data->page_next == PAGE_MAX)
{
EXIT;
}
data->page_n++;
return NEXT_PAGE(data->page_next);
}