Moving node list into global scope.
This commit is contained in:
29
src/globals.h
Normal file
29
src/globals.h
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Ortega Froysa, Nicolás <deathsbreed@themusicinnoise.net>
|
||||
* Author: Ortega Froysa, Nicolás <deathsbreed@themusicinnoise.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this program. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "nodes.h"
|
||||
|
||||
// List of nodes
|
||||
extern struct node *node_list;
|
||||
// Maximum number of nodes
|
||||
extern unsigned int node_max;
|
||||
// Number of nodes in the list
|
||||
extern unsigned int node_count;
|
26
src/neocomm.c
Normal file
26
src/neocomm.c
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Ortega Froysa, Nicolás <deathsbreed@themusicinnoise.net>
|
||||
* Author: Ortega Froysa, Nicolás <deathsbreed@themusicinnoise.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this program. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "neocomm.h"
|
||||
|
||||
int NeoComm_init(unsigned int max_nodes) {
|
||||
if(!NeoComm_init_nodes(max_nodes))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
17
src/nodes.c
17
src/nodes.c
@ -19,17 +19,14 @@
|
||||
|
||||
#include "nodes.h"
|
||||
|
||||
#include "globals.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
// List of nodes
|
||||
static struct node *node_list;
|
||||
// Maximum number of nodes
|
||||
static unsigned int node_max;
|
||||
// Number of nodes in the list
|
||||
static unsigned int node_count;
|
||||
|
||||
int NeoComm_init_nodes(unsigned int max_nodes) {
|
||||
if(max_nodes == 0)
|
||||
return 1;
|
||||
node_list = calloc(max_nodes, sizeof(struct node));
|
||||
if(!node_list)
|
||||
return 0;
|
||||
@ -43,6 +40,12 @@ int NeoComm_init_nodes(unsigned int max_nodes) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
void NeoComm_deinit_nodes() {
|
||||
free(node_list);
|
||||
node_max = 0;
|
||||
node_count = 0;
|
||||
}
|
||||
|
||||
int NeoComm_resize_node_list(unsigned int new_max_nodes) {
|
||||
if(new_max_nodes <= node_max)
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user