Converted comments from c++ to c.
This commit is contained in:
+6
-6
@@ -31,8 +31,8 @@
|
|||||||
License.
|
License.
|
||||||
-------------------------------------------
|
-------------------------------------------
|
||||||
####COPYRIGHTEND####*/
|
####COPYRIGHTEND####*/
|
||||||
//#define TEST
|
/*#define TEST */
|
||||||
//#define TEST_KEY
|
/*#define TEST_KEY */
|
||||||
#include "key.h"
|
#include "key.h"
|
||||||
|
|
||||||
#ifdef TEST
|
#ifdef TEST
|
||||||
@@ -41,7 +41,7 @@
|
|||||||
|
|
||||||
#include "ctest.h"
|
#include "ctest.h"
|
||||||
|
|
||||||
// test the encode and decode macros
|
/* test the encode and decode macros */
|
||||||
void testKeys(Test * pTest)
|
void testKeys(Test * pTest)
|
||||||
{
|
{
|
||||||
int type, id;
|
int type, id;
|
||||||
@@ -61,7 +61,7 @@ void testKeys(Test * pTest)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// test the encode and decode macros
|
/* test the encode and decode macros */
|
||||||
void testKeySample(Test * pTest)
|
void testKeySample(Test * pTest)
|
||||||
{
|
{
|
||||||
int type, id;
|
int type, id;
|
||||||
@@ -99,8 +99,8 @@ int main(void)
|
|||||||
|
|
||||||
pTest = ct_create("key", NULL);
|
pTest = ct_create("key", NULL);
|
||||||
/* add the individual tests */
|
/* add the individual tests */
|
||||||
// rc = ct_addTestFunction(pTest, testKeys);
|
/* rc = ct_addTestFunction(pTest, testKeys); */
|
||||||
// assert(rc);
|
/* assert(rc); */
|
||||||
rc = ct_addTestFunction(pTest, testKeySample);
|
rc = ct_addTestFunction(pTest, testKeySample);
|
||||||
assert(rc);
|
assert(rc);
|
||||||
/* run all the tests */
|
/* run all the tests */
|
||||||
|
|||||||
+3
-3
@@ -36,11 +36,11 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
// This file has the macros that encode and decode the
|
/* This file has the macros that encode and decode the */
|
||||||
// keys for the keylist when used with BACnet Object Id's
|
/* keys for the keylist when used with BACnet Object Id's */
|
||||||
typedef uint32_t KEY;
|
typedef uint32_t KEY;
|
||||||
|
|
||||||
// assuming a 32 bit KEY
|
/* assuming a 32 bit KEY */
|
||||||
#define KEY_TYPE_OFFSET 22 /* bits - for BACnet */
|
#define KEY_TYPE_OFFSET 22 /* bits - for BACnet */
|
||||||
#define KEY_TYPE_MASK 0x000003FFL
|
#define KEY_TYPE_MASK 0x000003FFL
|
||||||
#define KEY_ID_MASK 0x003FFFFFL
|
#define KEY_ID_MASK 0x003FFFFFL
|
||||||
|
|||||||
+93
-93
@@ -30,18 +30,18 @@
|
|||||||
-------------------------------------------
|
-------------------------------------------
|
||||||
####COPYRIGHTEND####*/
|
####COPYRIGHTEND####*/
|
||||||
|
|
||||||
// Keyed Linked List Library
|
/* Keyed Linked List Library */
|
||||||
//
|
/* */
|
||||||
// This is an enhanced array of pointers to data.
|
/* This is an enhanced array of pointers to data. */
|
||||||
// The list is sorted, indexed, and keyed.
|
/* The list is sorted, indexed, and keyed. */
|
||||||
// The array is much faster than a linked list.
|
/* The array is much faster than a linked list. */
|
||||||
// It stores a pointer to data, which you must
|
/* It stores a pointer to data, which you must */
|
||||||
// malloc and free on your own, or just use
|
/* malloc and free on your own, or just use */
|
||||||
// static data
|
/* static data */
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "keylist.h" // check for valid prototypes
|
#include "keylist.h" /* check for valid prototypes */
|
||||||
|
|
||||||
#ifndef FALSE
|
#ifndef FALSE
|
||||||
#define FALSE 0
|
#define FALSE 0
|
||||||
@@ -51,51 +51,51 @@
|
|||||||
#define TRUE 1
|
#define TRUE 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////
|
/*/////////////////////////////////////////////////////////////////// */
|
||||||
// Generic node routines
|
/* Generic node routines */
|
||||||
/////////////////////////////////////////////////////////////////////
|
/*/////////////////////////////////////////////////////////////////// */
|
||||||
|
|
||||||
// grab memory for a node
|
/* grab memory for a node */
|
||||||
static struct Keylist_Node *NodeCreate(void)
|
static struct Keylist_Node *NodeCreate(void)
|
||||||
{
|
{
|
||||||
return calloc(1, sizeof(struct Keylist_Node));
|
return calloc(1, sizeof(struct Keylist_Node));
|
||||||
}
|
}
|
||||||
|
|
||||||
// grab memory for a list
|
/* grab memory for a list */
|
||||||
static struct Keylist *KeylistCreate(void)
|
static struct Keylist *KeylistCreate(void)
|
||||||
{
|
{
|
||||||
return calloc(1, sizeof(struct Keylist));
|
return calloc(1, sizeof(struct Keylist));
|
||||||
}
|
}
|
||||||
|
|
||||||
// check to see if the array is big enough for an addition
|
/* check to see if the array is big enough for an addition */
|
||||||
// or is too big when we are deleting and we can shrink
|
/* or is too big when we are deleting and we can shrink */
|
||||||
// returns TRUE if success, FALSE if failed
|
/* returns TRUE if success, FALSE if failed */
|
||||||
static int CheckArraySize(OS_Keylist list)
|
static int CheckArraySize(OS_Keylist list)
|
||||||
{
|
{
|
||||||
int new_size = 0; // set it up so that no size change is the default
|
int new_size = 0; /* set it up so that no size change is the default */
|
||||||
const int chunk = 8; // minimum number of nodes to allocate memory for
|
const int chunk = 8; /* minimum number of nodes to allocate memory for */
|
||||||
struct Keylist_Node **new_array; // new array of nodes, if needed
|
struct Keylist_Node **new_array; /* new array of nodes, if needed */
|
||||||
int i; // counter
|
int i; /* counter */
|
||||||
if (!list)
|
if (!list)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
// indicates the need for more memory allocation
|
/* indicates the need for more memory allocation */
|
||||||
if (list->count == list->size)
|
if (list->count == list->size)
|
||||||
new_size = list->size + chunk;
|
new_size = list->size + chunk;
|
||||||
|
|
||||||
// allow for shrinking memory
|
/* allow for shrinking memory */
|
||||||
else if ((list->size > chunk) && (list->count < (list->size - chunk)))
|
else if ((list->size > chunk) && (list->count < (list->size - chunk)))
|
||||||
new_size = list->size - chunk;
|
new_size = list->size - chunk;
|
||||||
if (new_size) {
|
if (new_size) {
|
||||||
|
|
||||||
// Allocate more room for node pointer array
|
/* Allocate more room for node pointer array */
|
||||||
new_array = calloc((size_t) new_size, sizeof(new_array));
|
new_array = calloc((size_t) new_size, sizeof(new_array));
|
||||||
|
|
||||||
// See if we got the memory we wanted
|
/* See if we got the memory we wanted */
|
||||||
if (!new_array)
|
if (!new_array)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
// copy the nodes from the old array to the new array
|
/* copy the nodes from the old array to the new array */
|
||||||
if (list->array) {
|
if (list->array) {
|
||||||
for (i = 0; i < list->count; i++) {
|
for (i = 0; i < list->count; i++) {
|
||||||
new_array[i] = list->array[i];
|
new_array[i] = list->array[i];
|
||||||
@@ -109,29 +109,29 @@ static int CheckArraySize(OS_Keylist list)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// find the index of the key that we are looking for
|
/* find the index of the key that we are looking for */
|
||||||
// since it is sorted, we can optimize the search
|
/* since it is sorted, we can optimize the search */
|
||||||
// returns TRUE if found, and FALSE not found
|
/* returns TRUE if found, and FALSE not found */
|
||||||
// returns the found key and the index where it was found in parameters
|
/* returns the found key and the index where it was found in parameters */
|
||||||
// If the key is not found, the nearest index from the bottom will be returned,
|
/* If the key is not found, the nearest index from the bottom will be returned, */
|
||||||
// allowing the ability to find where an key should go into the list.
|
/* allowing the ability to find where an key should go into the list. */
|
||||||
static int FindIndex(OS_Keylist list, KEY key, int *pIndex)
|
static int FindIndex(OS_Keylist list, KEY key, int *pIndex)
|
||||||
{
|
{
|
||||||
struct Keylist_Node *node; // holds the new node
|
struct Keylist_Node *node; /* holds the new node */
|
||||||
int left = 0; // the left branch of tree, beginning of list
|
int left = 0; /* the left branch of tree, beginning of list */
|
||||||
int right = 0; // the right branch on the tree, end of list
|
int right = 0; /* the right branch on the tree, end of list */
|
||||||
int index = 0; // our current search place in the array
|
int index = 0; /* our current search place in the array */
|
||||||
KEY current_key = 0; // place holder for current node key
|
KEY current_key = 0; /* place holder for current node key */
|
||||||
int status = FALSE; // return value
|
int status = FALSE; /* return value */
|
||||||
if (!list || !list->array || !list->count) {
|
if (!list || !list->array || !list->count) {
|
||||||
*pIndex = 0;
|
*pIndex = 0;
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
right = list->count - 1;
|
right = list->count - 1;
|
||||||
// assume that the list is sorted
|
/* assume that the list is sorted */
|
||||||
do {
|
do {
|
||||||
|
|
||||||
// A binary search
|
/* A binary search */
|
||||||
index = (left + right) / 2;
|
index = (left + right) / 2;
|
||||||
node = list->array[index];
|
node = list->array[index];
|
||||||
if (!node)
|
if (!node)
|
||||||
@@ -151,7 +151,7 @@ static int FindIndex(OS_Keylist list, KEY key, int *pIndex)
|
|||||||
|
|
||||||
else {
|
else {
|
||||||
|
|
||||||
// where the index should be
|
/* where the index should be */
|
||||||
if (key > current_key)
|
if (key > current_key)
|
||||||
*pIndex = index + 1;
|
*pIndex = index + 1;
|
||||||
|
|
||||||
@@ -162,29 +162,29 @@ static int FindIndex(OS_Keylist list, KEY key, int *pIndex)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////
|
/*/////////////////////////////////////////////////////////////////// */
|
||||||
// list data functions
|
/* list data functions */
|
||||||
/////////////////////////////////////////////////////////////////////
|
/*/////////////////////////////////////////////////////////////////// */
|
||||||
// inserts a node into its sorted position
|
/* inserts a node into its sorted position */
|
||||||
int Keylist_Data_Add(OS_Keylist list, KEY key, void *data)
|
int Keylist_Data_Add(OS_Keylist list, KEY key, void *data)
|
||||||
{
|
{
|
||||||
struct Keylist_Node *node; // holds the new node
|
struct Keylist_Node *node; /* holds the new node */
|
||||||
int index = -1; // return value
|
int index = -1; /* return value */
|
||||||
int i; // counts through the array
|
int i; /* counts through the array */
|
||||||
|
|
||||||
if (list && CheckArraySize(list)) {
|
if (list && CheckArraySize(list)) {
|
||||||
// figure out where to put the new node
|
/* figure out where to put the new node */
|
||||||
if (list->count) {
|
if (list->count) {
|
||||||
(void) FindIndex(list, key, &index);
|
(void) FindIndex(list, key, &index);
|
||||||
// Add to the beginning of the list
|
/* Add to the beginning of the list */
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
index = 0;
|
index = 0;
|
||||||
|
|
||||||
// Add to the end of the list
|
/* Add to the end of the list */
|
||||||
else if (index > list->count)
|
else if (index > list->count)
|
||||||
index = list->count;
|
index = list->count;
|
||||||
|
|
||||||
// Move all the items up to make room for the new one
|
/* Move all the items up to make room for the new one */
|
||||||
for (i = list->count; i > index; i--) {
|
for (i = list->count; i > index; i--) {
|
||||||
list->array[i] = list->array[i - 1];
|
list->array[i] = list->array[i - 1];
|
||||||
}
|
}
|
||||||
@@ -194,7 +194,7 @@ int Keylist_Data_Add(OS_Keylist list, KEY key, void *data)
|
|||||||
index = 0;
|
index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// create and add the node
|
/* create and add the node */
|
||||||
node = NodeCreate();
|
node = NodeCreate();
|
||||||
if (node) {
|
if (node) {
|
||||||
list->count++;
|
list->count++;
|
||||||
@@ -206,8 +206,8 @@ int Keylist_Data_Add(OS_Keylist list, KEY key, void *data)
|
|||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
// deletes a node specified by its index
|
/* deletes a node specified by its index */
|
||||||
// returns the data from the node
|
/* returns the data from the node */
|
||||||
void *Keylist_Data_Delete_By_Index(OS_Keylist list, int index)
|
void *Keylist_Data_Delete_By_Index(OS_Keylist list, int index)
|
||||||
{
|
{
|
||||||
struct Keylist_Node *node;
|
struct Keylist_Node *node;
|
||||||
@@ -219,19 +219,19 @@ void *Keylist_Data_Delete_By_Index(OS_Keylist list, int index)
|
|||||||
if (node)
|
if (node)
|
||||||
data = node->data;
|
data = node->data;
|
||||||
|
|
||||||
// move the nodes to account for the deleted one
|
/* move the nodes to account for the deleted one */
|
||||||
if (list->count == 1) {
|
if (list->count == 1) {
|
||||||
|
|
||||||
// There is no node shifting to do
|
/* There is no node shifting to do */
|
||||||
}
|
}
|
||||||
// We are the last one
|
/* We are the last one */
|
||||||
else if (index == (list->count - 1)) {
|
else if (index == (list->count - 1)) {
|
||||||
|
|
||||||
// There is no node shifting to do
|
/* There is no node shifting to do */
|
||||||
}
|
}
|
||||||
// Move all the nodes down one
|
/* Move all the nodes down one */
|
||||||
else {
|
else {
|
||||||
int i; // counter
|
int i; /* counter */
|
||||||
int count = list->count - 1;
|
int count = list->count - 1;
|
||||||
for (i = index; i < count; i++) {
|
for (i = index; i < count; i++) {
|
||||||
list->array[i] = list->array[i + 1];
|
list->array[i] = list->array[i + 1];
|
||||||
@@ -241,19 +241,19 @@ void *Keylist_Data_Delete_By_Index(OS_Keylist list, int index)
|
|||||||
if (node)
|
if (node)
|
||||||
free(node);
|
free(node);
|
||||||
|
|
||||||
// potentially reduce the size of the array
|
/* potentially reduce the size of the array */
|
||||||
(void) CheckArraySize(list);
|
(void) CheckArraySize(list);
|
||||||
}
|
}
|
||||||
return (data);
|
return (data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// deletes a node specified by its key
|
/* deletes a node specified by its key */
|
||||||
// returns the data from the node
|
/* returns the data from the node */
|
||||||
void *Keylist_Data_Delete(OS_Keylist list, KEY key)
|
void *Keylist_Data_Delete(OS_Keylist list, KEY key)
|
||||||
{
|
{
|
||||||
void *data = NULL; // return value
|
void *data = NULL; /* return value */
|
||||||
int index; // where the node is in the array
|
int index; /* where the node is in the array */
|
||||||
|
|
||||||
if (list) {
|
if (list) {
|
||||||
if (FindIndex(list, key, &index))
|
if (FindIndex(list, key, &index))
|
||||||
@@ -263,11 +263,11 @@ void *Keylist_Data_Delete(OS_Keylist list, KEY key)
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns the data from last node, and removes it from the list
|
/* returns the data from last node, and removes it from the list */
|
||||||
void *Keylist_Data_Pop(OS_Keylist list)
|
void *Keylist_Data_Pop(OS_Keylist list)
|
||||||
{
|
{
|
||||||
void *data = NULL; // return value
|
void *data = NULL; /* return value */
|
||||||
int index; // position in the array
|
int index; /* position in the array */
|
||||||
|
|
||||||
if (list && list->count) {
|
if (list && list->count) {
|
||||||
index = list->count - 1;
|
index = list->count - 1;
|
||||||
@@ -277,11 +277,11 @@ void *Keylist_Data_Pop(OS_Keylist list)
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns the data from the node specified by key
|
/* returns the data from the node specified by key */
|
||||||
void *Keylist_Data(OS_Keylist list, KEY key)
|
void *Keylist_Data(OS_Keylist list, KEY key)
|
||||||
{
|
{
|
||||||
struct Keylist_Node *node = NULL;
|
struct Keylist_Node *node = NULL;
|
||||||
int index = 0; // used to look up the index of node
|
int index = 0; /* used to look up the index of node */
|
||||||
|
|
||||||
if (list && list->array && list->count) {
|
if (list && list->array && list->count) {
|
||||||
if (FindIndex(list, key, &index))
|
if (FindIndex(list, key, &index))
|
||||||
@@ -291,7 +291,7 @@ void *Keylist_Data(OS_Keylist list, KEY key)
|
|||||||
return node ? node->data : NULL;
|
return node ? node->data : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns the data specified by key
|
/* returns the data specified by key */
|
||||||
void *Keylist_Data_Index(OS_Keylist list, int index)
|
void *Keylist_Data_Index(OS_Keylist list, int index)
|
||||||
{
|
{
|
||||||
struct Keylist_Node *node = NULL;
|
struct Keylist_Node *node = NULL;
|
||||||
@@ -303,10 +303,10 @@ void *Keylist_Data_Index(OS_Keylist list, int index)
|
|||||||
return node ? node->data : NULL;
|
return node ? node->data : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// return the key at the given index
|
/* return the key at the given index */
|
||||||
KEY Keylist_Key(OS_Keylist list, int index)
|
KEY Keylist_Key(OS_Keylist list, int index)
|
||||||
{
|
{
|
||||||
KEY key = 0; // return value
|
KEY key = 0; /* return value */
|
||||||
struct Keylist_Node *node;
|
struct Keylist_Node *node;
|
||||||
|
|
||||||
if (list && list->array && list->count &&
|
if (list && list->array && list->count &&
|
||||||
@@ -319,7 +319,7 @@ KEY Keylist_Key(OS_Keylist list, int index)
|
|||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns the next empty key from the list
|
/* returns the next empty key from the list */
|
||||||
KEY Keylist_Next_Empty_Key(OS_Keylist list, KEY key)
|
KEY Keylist_Next_Empty_Key(OS_Keylist list, KEY key)
|
||||||
{
|
{
|
||||||
int index;
|
int index;
|
||||||
@@ -335,17 +335,17 @@ KEY Keylist_Next_Empty_Key(OS_Keylist list, KEY key)
|
|||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
// return the number of nodes in this list
|
/* return the number of nodes in this list */
|
||||||
int Keylist_Count(OS_Keylist list)
|
int Keylist_Count(OS_Keylist list)
|
||||||
{
|
{
|
||||||
return list->count;
|
return list->count;
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////
|
/*/////////////////////////////////////////////////////////////////// */
|
||||||
// Public List functions
|
/* Public List functions */
|
||||||
/////////////////////////////////////////////////////////////////////
|
/*/////////////////////////////////////////////////////////////////// */
|
||||||
|
|
||||||
// returns head of the list or NULL on failure.
|
/* returns head of the list or NULL on failure. */
|
||||||
OS_Keylist Keylist_Create(void)
|
OS_Keylist Keylist_Create(void)
|
||||||
{
|
{
|
||||||
struct Keylist *list;
|
struct Keylist *list;
|
||||||
@@ -357,11 +357,11 @@ OS_Keylist Keylist_Create(void)
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete specified list
|
/* delete specified list */
|
||||||
void Keylist_Delete(OS_Keylist list) // list number to be deleted
|
void Keylist_Delete(OS_Keylist list) /* list number to be deleted */
|
||||||
{
|
{
|
||||||
if (list) {
|
if (list) {
|
||||||
// clean out the list
|
/* clean out the list */
|
||||||
while (list->count) {
|
while (list->count) {
|
||||||
(void) Keylist_Data_Delete_By_Index(list, 0);
|
(void) Keylist_Data_Delete_By_Index(list, 0);
|
||||||
}
|
}
|
||||||
@@ -379,7 +379,7 @@ void Keylist_Delete(OS_Keylist list) // list number to be deleted
|
|||||||
|
|
||||||
#include "ctest.h"
|
#include "ctest.h"
|
||||||
|
|
||||||
// test the encode and decode macros
|
/* test the encode and decode macros */
|
||||||
void testKeySample(Test * pTest)
|
void testKeySample(Test * pTest)
|
||||||
{
|
{
|
||||||
int type, id;
|
int type, id;
|
||||||
@@ -411,7 +411,7 @@ void testKeySample(Test * pTest)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// test the FIFO
|
/* test the FIFO */
|
||||||
void testKeyListFIFO(Test * pTest)
|
void testKeyListFIFO(Test * pTest)
|
||||||
{
|
{
|
||||||
OS_Keylist list;
|
OS_Keylist list;
|
||||||
@@ -454,7 +454,7 @@ void testKeyListFIFO(Test * pTest)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// test the FILO
|
/* test the FILO */
|
||||||
void testKeyListFILO(Test * pTest)
|
void testKeyListFILO(Test * pTest)
|
||||||
{
|
{
|
||||||
OS_Keylist list;
|
OS_Keylist list;
|
||||||
@@ -535,7 +535,7 @@ void testKeyListDataKey(Test * pTest)
|
|||||||
|
|
||||||
ct_test(pTest, Keylist_Count(list) == 3);
|
ct_test(pTest, Keylist_Count(list) == 3);
|
||||||
|
|
||||||
// look at the data
|
/* look at the data */
|
||||||
key = 2;
|
key = 2;
|
||||||
data = Keylist_Data(list, key);
|
data = Keylist_Data(list, key);
|
||||||
ct_test(pTest, data != NULL);
|
ct_test(pTest, data != NULL);
|
||||||
@@ -551,7 +551,7 @@ void testKeyListDataKey(Test * pTest)
|
|||||||
ct_test(pTest, data != NULL);
|
ct_test(pTest, data != NULL);
|
||||||
ct_test(pTest, strcmp(data, data3) == 0);
|
ct_test(pTest, strcmp(data, data3) == 0);
|
||||||
|
|
||||||
// work the data
|
/* work the data */
|
||||||
key = 2;
|
key = 2;
|
||||||
data = Keylist_Data_Delete(list, key);
|
data = Keylist_Data_Delete(list, key);
|
||||||
ct_test(pTest, data != NULL);
|
ct_test(pTest, data != NULL);
|
||||||
@@ -570,7 +570,7 @@ void testKeyListDataKey(Test * pTest)
|
|||||||
ct_test(pTest, data != NULL);
|
ct_test(pTest, data != NULL);
|
||||||
ct_test(pTest, strcmp(data, data3) == 0);
|
ct_test(pTest, strcmp(data, data3) == 0);
|
||||||
|
|
||||||
// cleanup
|
/* cleanup */
|
||||||
do {
|
do {
|
||||||
data = Keylist_Data_Pop(list);
|
data = Keylist_Data_Pop(list);
|
||||||
}
|
}
|
||||||
@@ -605,7 +605,7 @@ void testKeyListDataIndex(Test * pTest)
|
|||||||
|
|
||||||
ct_test(pTest, Keylist_Count(list) == 3);
|
ct_test(pTest, Keylist_Count(list) == 3);
|
||||||
|
|
||||||
// look at the data
|
/* look at the data */
|
||||||
data = Keylist_Data_Index(list, 0);
|
data = Keylist_Data_Index(list, 0);
|
||||||
ct_test(pTest, data != NULL);
|
ct_test(pTest, data != NULL);
|
||||||
ct_test(pTest, strcmp(data, data3) == 0);
|
ct_test(pTest, strcmp(data, data3) == 0);
|
||||||
@@ -618,7 +618,7 @@ void testKeyListDataIndex(Test * pTest)
|
|||||||
ct_test(pTest, data != NULL);
|
ct_test(pTest, data != NULL);
|
||||||
ct_test(pTest, strcmp(data, data1) == 0);
|
ct_test(pTest, strcmp(data, data1) == 0);
|
||||||
|
|
||||||
// work the data
|
/* work the data */
|
||||||
data = Keylist_Data_Delete_By_Index(list, 1);
|
data = Keylist_Data_Delete_By_Index(list, 1);
|
||||||
ct_test(pTest, data != NULL);
|
ct_test(pTest, data != NULL);
|
||||||
ct_test(pTest, strcmp(data, data2) == 0);
|
ct_test(pTest, strcmp(data, data2) == 0);
|
||||||
@@ -640,7 +640,7 @@ void testKeyListDataIndex(Test * pTest)
|
|||||||
data = Keylist_Data_Delete_By_Index(list, 1);
|
data = Keylist_Data_Delete_By_Index(list, 1);
|
||||||
ct_test(pTest, data == NULL);
|
ct_test(pTest, data == NULL);
|
||||||
|
|
||||||
// cleanup
|
/* cleanup */
|
||||||
do {
|
do {
|
||||||
data = Keylist_Data_Pop(list);
|
data = Keylist_Data_Pop(list);
|
||||||
}
|
}
|
||||||
@@ -651,7 +651,7 @@ void testKeyListDataIndex(Test * pTest)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// test access of a lot of entries
|
/* test access of a lot of entries */
|
||||||
void testKeyListLarge(Test * pTest)
|
void testKeyListLarge(Test * pTest)
|
||||||
{
|
{
|
||||||
int data1 = 42;
|
int data1 = 42;
|
||||||
|
|||||||
+24
-24
@@ -36,58 +36,58 @@
|
|||||||
|
|
||||||
#include "key.h"
|
#include "key.h"
|
||||||
|
|
||||||
// This is a key sorted linked list data library that
|
/* This is a key sorted linked list data library that */
|
||||||
// uses a key or index to access the data.
|
/* uses a key or index to access the data. */
|
||||||
// If the keys are duplicated, they can be added into the list like FIFO
|
/* If the keys are duplicated, they can be added into the list like FIFO */
|
||||||
|
|
||||||
// list data and datatype
|
/* list data and datatype */
|
||||||
struct Keylist_Node {
|
struct Keylist_Node {
|
||||||
KEY key; // unique number that is sorted in the list
|
KEY key; /* unique number that is sorted in the list */
|
||||||
void *data; // pointer to some data that is stored
|
void *data; /* pointer to some data that is stored */
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct Keylist {
|
typedef struct Keylist {
|
||||||
struct Keylist_Node **array; // array of nodes
|
struct Keylist_Node **array; /* array of nodes */
|
||||||
int count; // number of nodes in this list - more effecient than loop
|
int count; /* number of nodes in this list - more effecient than loop */
|
||||||
int size; // number of available nodes on this list - can grow or shrink
|
int size; /* number of available nodes on this list - can grow or shrink */
|
||||||
} KEYLIST_TYPE;
|
} KEYLIST_TYPE;
|
||||||
typedef KEYLIST_TYPE *OS_Keylist;
|
typedef KEYLIST_TYPE *OS_Keylist;
|
||||||
|
|
||||||
// returns head of the list or NULL on failure.
|
/* returns head of the list or NULL on failure. */
|
||||||
OS_Keylist Keylist_Create(void);
|
OS_Keylist Keylist_Create(void);
|
||||||
|
|
||||||
// delete specified list
|
/* delete specified list */
|
||||||
// note: you should pop all the nodes off the list first.
|
/* note: you should pop all the nodes off the list first. */
|
||||||
void Keylist_Delete(OS_Keylist list);
|
void Keylist_Delete(OS_Keylist list);
|
||||||
|
|
||||||
// inserts a node into its sorted position
|
/* inserts a node into its sorted position */
|
||||||
// returns the index where it was added
|
/* returns the index where it was added */
|
||||||
int Keylist_Data_Add(OS_Keylist list, KEY key, void *data);
|
int Keylist_Data_Add(OS_Keylist list, KEY key, void *data);
|
||||||
|
|
||||||
// deletes a node specified by its key
|
/* deletes a node specified by its key */
|
||||||
// returns the data from the node
|
/* returns the data from the node */
|
||||||
void *Keylist_Data_Delete(OS_Keylist list, KEY key);
|
void *Keylist_Data_Delete(OS_Keylist list, KEY key);
|
||||||
|
|
||||||
// deletes a node specified by its index
|
/* deletes a node specified by its index */
|
||||||
// returns the data from the node
|
/* returns the data from the node */
|
||||||
void *Keylist_Data_Delete_By_Index(OS_Keylist list, int index);
|
void *Keylist_Data_Delete_By_Index(OS_Keylist list, int index);
|
||||||
|
|
||||||
// returns the data from last node, and removes it from the list
|
/* returns the data from last node, and removes it from the list */
|
||||||
void *Keylist_Data_Pop(OS_Keylist list);
|
void *Keylist_Data_Pop(OS_Keylist list);
|
||||||
|
|
||||||
// returns the data from the node specified by key
|
/* returns the data from the node specified by key */
|
||||||
void *Keylist_Data(OS_Keylist list, KEY key);
|
void *Keylist_Data(OS_Keylist list, KEY key);
|
||||||
|
|
||||||
// returns the data specified by key
|
/* returns the data specified by key */
|
||||||
void *Keylist_Data_Index(OS_Keylist list, int index);
|
void *Keylist_Data_Index(OS_Keylist list, int index);
|
||||||
|
|
||||||
// return the key at the given index
|
/* return the key at the given index */
|
||||||
KEY Keylist_Key(OS_Keylist list, int index);
|
KEY Keylist_Key(OS_Keylist list, int index);
|
||||||
|
|
||||||
// returns the next empty key from the list
|
/* returns the next empty key from the list */
|
||||||
KEY Keylist_Next_Empty_Key(OS_Keylist list, KEY key);
|
KEY Keylist_Next_Empty_Key(OS_Keylist list, KEY key);
|
||||||
|
|
||||||
// returns the number of items in the list
|
/* returns the number of items in the list */
|
||||||
int Keylist_Count(OS_Keylist list);
|
int Keylist_Count(OS_Keylist list);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ static void *dlmstp_milliseconds_task(void *pArg)
|
|||||||
|
|
||||||
void dlmstp_reinit(void)
|
void dlmstp_reinit(void)
|
||||||
{
|
{
|
||||||
//RS485_Reinit();
|
/*RS485_Reinit(); */
|
||||||
dlmstp_set_mac_address(DEFAULT_MAC_ADDRESS);
|
dlmstp_set_mac_address(DEFAULT_MAC_ADDRESS);
|
||||||
dlmstp_set_max_info_frames(DEFAULT_MAX_INFO_FRAMES);
|
dlmstp_set_max_info_frames(DEFAULT_MAX_INFO_FRAMES);
|
||||||
dlmstp_set_max_master(DEFAULT_MAX_MASTER);
|
dlmstp_set_max_master(DEFAULT_MAX_MASTER);
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ void dlmstp_millisecond_timer(void)
|
|||||||
|
|
||||||
void dlmstp_reinit(void)
|
void dlmstp_reinit(void)
|
||||||
{
|
{
|
||||||
//RS485_Reinit();
|
/*RS485_Reinit(); */
|
||||||
dlmstp_set_mac_address(DEFAULT_MAC_ADDRESS);
|
dlmstp_set_mac_address(DEFAULT_MAC_ADDRESS);
|
||||||
dlmstp_set_max_info_frames(DEFAULT_MAX_INFO_FRAMES);
|
dlmstp_set_max_info_frames(DEFAULT_MAX_INFO_FRAMES);
|
||||||
dlmstp_set_max_master(DEFAULT_MAX_MASTER);
|
dlmstp_set_max_master(DEFAULT_MAX_MASTER);
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ void RS485_Set_Interface(char *ifname)
|
|||||||
|
|
||||||
static void RS485_Print_Error(void)
|
static void RS485_Print_Error(void)
|
||||||
{
|
{
|
||||||
char * szExtended = ""; // error string translated from error code
|
char * szExtended = ""; /* error string translated from error code */
|
||||||
DWORD dwExtSize;
|
DWORD dwExtSize;
|
||||||
DWORD dwErr;
|
DWORD dwErr;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user