Fixing indent
Spaces not tabs
This commit is contained in:
@@ -4,8 +4,8 @@
|
|||||||
Version: 2.2
|
Version: 2.2
|
||||||
Module: util/list.h
|
Module: util/list.h
|
||||||
Description: Generic list
|
Description: Generic list
|
||||||
https://gist.github.com/pseudomuto/6334796#file-list-c
|
https://gist.github.com/pseudomuto/6334796#file-list-c
|
||||||
Accessed: April 9, 2019
|
Accessed: April 9, 2019
|
||||||
Authors: David Muto, Modified by Michael E. Tryby
|
Authors: David Muto, Modified by Michael E. Tryby
|
||||||
Copyright: see AUTHORS
|
Copyright: see AUTHORS
|
||||||
License: see LICENSE
|
License: see LICENSE
|
||||||
@@ -29,8 +29,8 @@
|
|||||||
|
|
||||||
list_t *create_list(size_t elementSize, freeFunction freeFn)
|
list_t *create_list(size_t elementSize, freeFunction freeFn)
|
||||||
{
|
{
|
||||||
list_t *list;
|
list_t *list;
|
||||||
list = (list_t *)calloc(1, sizeof(list_t));
|
list = (list_t *)calloc(1, sizeof(list_t));
|
||||||
|
|
||||||
assert(elementSize > 0);
|
assert(elementSize > 0);
|
||||||
list->logicalLength = 0;
|
list->logicalLength = 0;
|
||||||
@@ -54,8 +54,7 @@ void delete_list(list_t *list)
|
|||||||
free(current->data);
|
free(current->data);
|
||||||
free(current);
|
free(current);
|
||||||
}
|
}
|
||||||
|
free(list);
|
||||||
free(list);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void prepend_list(list_t *list, void *element)
|
void prepend_list(list_t *list, void *element)
|
||||||
@@ -106,45 +105,45 @@ void for_each_list(list_t *list, listIterator iterator)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void *head_list(list_t *list, bool removeFromList)
|
void *head_list(list_t *list, bool removeFromList)
|
||||||
//
|
//
|
||||||
// Warning: Caller is responsible for freeing the node->data returned.
|
// Warning: Caller is responsible for freeing the node->data returned.
|
||||||
//
|
//
|
||||||
{
|
{
|
||||||
assert(list->head != NULL);
|
assert(list->head != NULL);
|
||||||
|
|
||||||
listNode *node = list->head;
|
listNode *node = list->head;
|
||||||
// Allocating and copying pointer to node data
|
// Allocating and copying pointer to node data
|
||||||
void *element = (void *)malloc(list->elementSize);
|
void *element = (void *)malloc(list->elementSize);
|
||||||
memcpy(element, node->data, list->elementSize);
|
memcpy(element, node->data, list->elementSize);
|
||||||
|
|
||||||
if(removeFromList) {
|
if(removeFromList) {
|
||||||
// Disconnecting head node
|
// Disconnecting head node
|
||||||
list->head = node->next;
|
list->head = node->next;
|
||||||
list->logicalLength--;
|
list->logicalLength--;
|
||||||
|
|
||||||
// Freeing pointer to node->data and node
|
// Freeing pointer to node->data and node
|
||||||
free(node->data);
|
free(node->data);
|
||||||
free(node);
|
free(node);
|
||||||
}
|
}
|
||||||
// Now element points to data formerly pointed to by node. Caller
|
// Now element points to data formerly pointed to by node. Caller
|
||||||
// is responsible for freeing both pointer to data and data.
|
// is responsible for freeing both pointer to data and data.
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *tail_list(list_t *list)
|
void *tail_list(list_t *list)
|
||||||
//
|
//
|
||||||
// Warning: Caller is responsible for freeing the node->data returned.
|
// Warning: Caller is responsible for freeing the node->data returned.
|
||||||
//
|
//
|
||||||
{
|
{
|
||||||
assert(list->tail != NULL);
|
assert(list->tail != NULL);
|
||||||
|
|
||||||
listNode *node = list->tail;
|
listNode *node = list->tail;
|
||||||
// Allocating and copying pointer to node data
|
// Allocating and copying pointer to node data
|
||||||
void *element = (void *)malloc(list->elementSize);
|
void *element = (void *)malloc(list->elementSize);
|
||||||
memcpy(element, node->data, list->elementSize);
|
memcpy(element, node->data, list->elementSize);
|
||||||
|
|
||||||
// Pointer to element data gets returned. Caller is responsible
|
// Pointer to element data gets returned. Caller is responsible
|
||||||
// for freeing pointer to data.
|
// for freeing pointer to data.
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
Version: 2.2
|
Version: 2.2
|
||||||
Module: util/list.h
|
Module: util/list.h
|
||||||
Description: Generic list
|
Description: Generic list
|
||||||
https://gist.github.com/pseudomuto/6334796#file-list-h
|
https://gist.github.com/pseudomuto/6334796#file-list-h
|
||||||
Accessed: April 9, 2019
|
Accessed: April 9, 2019
|
||||||
Authors: David Muto, Modified by Michael E. Tryby
|
Authors: David Muto, Modified by Michael E. Tryby
|
||||||
Copyright: see AUTHORS
|
Copyright: see AUTHORS
|
||||||
@@ -29,17 +29,17 @@ typedef bool (*listIterator)(void *);
|
|||||||
|
|
||||||
|
|
||||||
typedef struct _listNode {
|
typedef struct _listNode {
|
||||||
void *data;
|
void *data;
|
||||||
struct _listNode *next;
|
struct _listNode *next;
|
||||||
} listNode;
|
} listNode;
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int logicalLength;
|
int logicalLength;
|
||||||
size_t elementSize;
|
size_t elementSize;
|
||||||
listNode *head;
|
listNode *head;
|
||||||
listNode *tail;
|
listNode *tail;
|
||||||
freeFunction freeFn;
|
freeFunction freeFn;
|
||||||
} list_t;
|
} list_t;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -45,16 +45,16 @@ BOOST_AUTO_TEST_CASE (test_create_destroy)
|
|||||||
|
|
||||||
struct Fixture{
|
struct Fixture{
|
||||||
Fixture() {
|
Fixture() {
|
||||||
error_message = NULL;
|
error_message = NULL;
|
||||||
error_handle = create_error_manager(&mock_lookup);
|
error_handle = create_error_manager(&mock_lookup);
|
||||||
}
|
}
|
||||||
~Fixture() {
|
~Fixture() {
|
||||||
delete_error_manager(error_handle);
|
delete_error_manager(error_handle);
|
||||||
free(error_message);
|
free(error_message);
|
||||||
}
|
}
|
||||||
int error;
|
int error;
|
||||||
error_handle_t *error_handle;
|
error_handle_t *error_handle;
|
||||||
char *error_message;
|
char *error_message;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -76,23 +76,23 @@ BOOST_AUTO_TEST_CASE(test_int_list){
|
|||||||
|
|
||||||
struct FixtureStrings{
|
struct FixtureStrings{
|
||||||
FixtureStrings() {
|
FixtureStrings() {
|
||||||
list = NULL;
|
list = NULL;
|
||||||
|
|
||||||
int numNames = 5;
|
int numNames = 5;
|
||||||
const char *names[] = { "David", "Kevin", "Michael", "Craig", "Jimi" };
|
const char *names[] = { "David", "Kevin", "Michael", "Craig", "Jimi" };
|
||||||
|
|
||||||
list = create_list(sizeof(char *), free_string);
|
list = create_list(sizeof(char *), free_string);
|
||||||
|
|
||||||
char *name;
|
char *name;
|
||||||
for (int i = 0; i < numNames; i++) {
|
for (int i = 0; i < numNames; i++) {
|
||||||
name = _strdup(names[i]);
|
name = _strdup(names[i]);
|
||||||
append_list(list, &name);
|
append_list(list, &name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
~FixtureStrings() {
|
~FixtureStrings() {
|
||||||
delete_list(list);
|
delete_list(list);
|
||||||
}
|
}
|
||||||
list_t *list;
|
list_t *list;
|
||||||
};
|
};
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(test_string_list, FixtureStrings) {
|
BOOST_FIXTURE_TEST_CASE(test_string_list, FixtureStrings) {
|
||||||
@@ -110,8 +110,8 @@ BOOST_FIXTURE_TEST_CASE(test_head_list, FixtureStrings) {
|
|||||||
BOOST_CHECK(check_string(*(char **)temp, "David"));
|
BOOST_CHECK(check_string(*(char **)temp, "David"));
|
||||||
BOOST_CHECK(size_list(list) == 4);
|
BOOST_CHECK(size_list(list) == 4);
|
||||||
|
|
||||||
// To free a node, free both the data and reference to data
|
// To free a node, free both the data and reference to data
|
||||||
free_string(temp);
|
free_string(temp);
|
||||||
free(temp);
|
free(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user