Fixing indent

Spaces not tabs
This commit is contained in:
Michael Tryby
2019-04-10 11:25:01 -04:00
parent dba0d1cf52
commit fbecf1b915
4 changed files with 42 additions and 43 deletions

View File

@@ -4,8 +4,8 @@
Version: 2.2
Module: util/list.h
Description: Generic list
https://gist.github.com/pseudomuto/6334796#file-list-c
Accessed: April 9, 2019
https://gist.github.com/pseudomuto/6334796#file-list-c
Accessed: April 9, 2019
Authors: David Muto, Modified by Michael E. Tryby
Copyright: see AUTHORS
License: see LICENSE
@@ -29,8 +29,8 @@
list_t *create_list(size_t elementSize, freeFunction freeFn)
{
list_t *list;
list = (list_t *)calloc(1, sizeof(list_t));
list_t *list;
list = (list_t *)calloc(1, sizeof(list_t));
assert(elementSize > 0);
list->logicalLength = 0;
@@ -54,8 +54,7 @@ void delete_list(list_t *list)
free(current->data);
free(current);
}
free(list);
free(list);
}
void prepend_list(list_t *list, void *element)
@@ -113,21 +112,21 @@ void *head_list(list_t *list, bool removeFromList)
assert(list->head != NULL);
listNode *node = list->head;
// Allocating and copying pointer to node data
// Allocating and copying pointer to node data
void *element = (void *)malloc(list->elementSize);
memcpy(element, node->data, list->elementSize);
if(removeFromList) {
// Disconnecting head node
// Disconnecting head node
list->head = node->next;
list->logicalLength--;
// Freeing pointer to node->data and node
// Freeing pointer to node->data and node
free(node->data);
free(node);
}
// Now element points to data formerly pointed to by node. Caller
// is responsible for freeing both pointer to data and data.
// Now element points to data formerly pointed to by node. Caller
// is responsible for freeing both pointer to data and data.
return element;
}
@@ -139,12 +138,12 @@ void *tail_list(list_t *list)
assert(list->tail != NULL);
listNode *node = list->tail;
// Allocating and copying pointer to node data
// Allocating and copying pointer to node data
void *element = (void *)malloc(list->elementSize);
memcpy(element, node->data, list->elementSize);
// Pointer to element data gets returned. Caller is responsible
// for freeing pointer to data.
// Pointer to element data gets returned. Caller is responsible
// for freeing pointer to data.
return element;
}

View File

@@ -29,17 +29,17 @@ typedef bool (*listIterator)(void *);
typedef struct _listNode {
void *data;
struct _listNode *next;
void *data;
struct _listNode *next;
} listNode;
typedef struct {
int logicalLength;
size_t elementSize;
listNode *head;
listNode *tail;
freeFunction freeFn;
int logicalLength;
size_t elementSize;
listNode *head;
listNode *tail;
freeFunction freeFn;
} list_t;

View File

@@ -45,16 +45,16 @@ BOOST_AUTO_TEST_CASE (test_create_destroy)
struct Fixture{
Fixture() {
error_message = NULL;
error_message = NULL;
error_handle = create_error_manager(&mock_lookup);
}
~Fixture() {
delete_error_manager(error_handle);
free(error_message);
}
int error;
error_handle_t *error_handle;
char *error_message;
}
int error;
error_handle_t *error_handle;
char *error_message;
};

View File

@@ -76,23 +76,23 @@ BOOST_AUTO_TEST_CASE(test_int_list){
struct FixtureStrings{
FixtureStrings() {
list = NULL;
list = NULL;
int numNames = 5;
const char *names[] = { "David", "Kevin", "Michael", "Craig", "Jimi" };
list = create_list(sizeof(char *), free_string);
list = create_list(sizeof(char *), free_string);
char *name;
for (int i = 0; i < numNames; i++) {
name = _strdup(names[i]);
append_list(list, &name);
}
char *name;
for (int i = 0; i < numNames; i++) {
name = _strdup(names[i]);
append_list(list, &name);
}
}
~FixtureStrings() {
delete_list(list);
}
list_t *list;
}
list_t *list;
};
BOOST_FIXTURE_TEST_CASE(test_string_list, FixtureStrings) {
@@ -111,7 +111,7 @@ BOOST_FIXTURE_TEST_CASE(test_head_list, FixtureStrings) {
BOOST_CHECK(size_list(list) == 4);
// To free a node, free both the data and reference to data
free_string(temp);
free_string(temp);
free(temp);
}