ftech
/SList
/amendments
/4
Changed license to MIT + refactored to feature camel case syntax.
Francois Techene made amendment 4 about 2 days ago
--- LICENSE Wed Mar 26 11:02:46 2025
+++ LICENSE Wed Apr 1 21:19:35 2026
@@ -1,7 +1,20 @@
-Copyright (c) 2025 Francois Techene <ftechene@yahoo.fr>
+Copyright (c) 2026 Francois Techene <ftechene@yahoo.fr>
-The SList Library for classic Mac 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 3 of the License, or (at your option) any later version.
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
-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.
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
-<https://www.gnu.org/licenses/gpl-3.0.en.html>.
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--- README Mon Mar 31 19:32:05 2025
+++ README Wed Apr 1 21:54:18 2026
@@ -7,8 +7,9 @@ SList is free software; see the LICENSE file for copyr
This library has been built and tested using THINK C v5 on a Macintosh SE.
-In order to install it, just import `slist.c` and `slist.h` to your project and include `slist.h` in your source files.
+In order to install it, just import `Slist.Lib` from the `build` folder to your project and include it in your source files.
+You can also add `slist.c` and `slist.h` directly to your project.
---
# Usage
@@ -16,42 +17,42 @@ In order to install it, just import `slist.c` and `sli
## Creating a new list
```
// Create a new SList object.
-SList* my_list = SList_new();
+SList* myList = NewSList();
```
## Adding objects to the list
```
// Append an object at the end of the list.
-slist_append(my_list, (Ptr)my_object);
+SListAppend(myList, (Ptr)myObject);
// Insert an object at a given 0 based index position in the list.
// (Third position in this case).
-slist_insert_at(my_list, (Ptr)my_object, 2);
+SListInsertAt(myList, (Ptr)myObject, 2);
// Insert an object after the first occurence of another one.
-slist_insert_after(my_list, (Ptr)my_object, (Ptr)other_object);
+SListInsertAfter(myList, (Ptr)myObject, (Ptr)otherObject);
```
## Removing objects from the list
```
// Remove the first occurence of an object from the list.
-slist_remove_value(my_list, (Ptr)my_object);
+SListRemoveValue(myList, (Ptr)myObject);
// Remove an object at a given 0 based index postion from the list.
// (Third position in this case).
-slist_remove_at(my_list, 2);
+SListRemoveAt(myList, 2);
// Remove the last object from the list.
-slist_remove_last(my_list);
+SListRemoveLast(myList);
// Remove all objects from the list.
-slist_empty(my_list);
+SListEmpty(myList);
```
## Parsing a list
```
SL_FOREACH(item, list) {
- obj = (MyObject*)item->data;
+ obj = (MyObject*)item->data;
}
```
--- slist-test.c Mon Mar 31 18:59:30 2025
+++ slist-test.c Wed Apr 1 21:37:45 2026
@@ -1,21 +1,30 @@
/* slist_test.c
*
- * Copyright 2025 Francois Techene
+ * Copyright 2026 Francois Techene
*
- * 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 3 of the License, or
- * (at your option) any later version.
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
*
- * 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.
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
*
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
- * SPDX-License-Identifier: GPL-3.0-or-later
+ * Except as contained in this notice, the name(s) of the above copyright
+ * holders shall not be used in advertising or otherwise to promote the sale,
+ * use or other dealings in this Software without prior written
+ * authorization.
*/
#include <stdarg.h>
@@ -36,7 +45,7 @@ typedef struct _MyObject {
} MyObject;
-MyObject* MyObject_new(char* text, int num)
+MyObject* NewMyObject(char* text, int num)
{
MyObject* self = (MyObject*)malloc(sizeof(MyObject));
@@ -53,101 +62,101 @@ MyObject* obj3 = NULL;
SList* list = NULL;
-bool found_error = false;
+bool foundError = false;
//////////////////////////////////////////////////////////
// Assert Functions
//
bool
-ut_asser_ptr_equal(void* value_1, void* value_2, char* msg)
+UtAsserPtrEqual(void* value1, void* value2, char* msg)
{
- if (value_1 != value_2) {
+ if (value1 != value2) {
printf(" FAILED: %s - Pointers do not match\n", msg);
- found_error = true;
+ foundError = true;
return 0;
}
return 1;
}
bool
-ut_asser_null(void* value, char* msg)
+UtAsserNull(void* value, char* msg)
{
if (value) {
printf(" FAILED: %s - Should be NULL\n", msg);
- found_error = true;
+ foundError = true;
return 0;
}
return 1;
}
bool
-ut_asser_not_null(void* value, char* msg)
+UtAsserNotNull(void* value, char* msg)
{
if (!value) {
printf(" FAILED: %s - Should not be NULL\n", msg);
- found_error = true;
+ foundError = true;
return 0;
}
return 1;
}
bool
-ut_asser_true(bool value, char* msg)
+UtAsserTrue(bool value, char* msg)
{
if (!value) {
printf(" FAILED: %s - Should be true\n", msg);
- found_error = true;
+ foundError = true;
return 0;
}
return 1;
}
bool
-ut_asser_false(bool value, char* msg)
+UtAsserFalse(bool value, char* msg)
{
if (value) {
printf(" FAILED: %s - Should be false\n", msg);
- found_error = true;
+ foundError = true;
return 0;
}
return 1;
}
bool
-ut_asser_greater_int(int value_1, int value_2, char* msg)
+UtAsserGreaterInt(int value1, int value2, char* msg)
{
- if (value_1 > value_2) {
+ if (value1 > value2) {
printf(" FAILED: %s - Should be greater than %d and is %d\n",
msg,
- value_2,
- value_1);
- found_error = true;
+ value2,
+ value1);
+ foundError = true;
return 0;
}
return 1;
}
bool
-ut_asser_not_equal_int(int value_1, int value_2, char* msg)
+UtAsserNotEqualInt(int value1, int value2, char* msg)
{
- if (value_1 == value_2) {
- printf(" FAILED: %s - Should not equal %d\n", msg, value_2);
- found_error = true;
+ if (value1 == value2) {
+ printf(" FAILED: %s - Should not equal %d\n", msg, value2);
+ foundError = true;
return 0;
}
return 1;
}
bool
-ut_asser_equal_int(int value_1, int value_2, char* msg)
+UtAsserEqualInt(int value1, int value2, char* msg)
{
- if (value_1 != value_2) {
+ if (value1 != value2) {
printf(" FAILED: %s - Value is %d, should be %d\n",
msg,
- value_1,
- value_2);
- found_error = true;
+ value1,
+ value2);
+ foundError = true;
return 0;
}
return 1;
@@ -157,32 +166,32 @@ ut_asser_equal_int(int value_1, int value_2, char* msg
// Unit Test
//
void
-init_tests()
+InitTests()
{
printf("Initializing Objects... \n");
- obj1 = MyObject_new("Obj1", 1);
- obj2 = MyObject_new("Obj2", 2);
- obj3 = MyObject_new("Obj3", 3);
+ obj1 = NewMyObject("Obj1", 1);
+ obj2 = NewMyObject("Obj2", 2);
+ obj3 = NewMyObject("Obj3", 3);
- list = SList_new();
+ list = NewSList();
- ut_asser_equal_int(obj1->num, 1,
- "init_tests() - obj1->num");
- ut_asser_equal_int(obj2->num, 2,
- "init_tests() - obj2->num");
- ut_asser_equal_int(obj3->num, 3,
- "init_tests() - obj3->num");
+ UtAsserEqualInt(obj1->num, 1,
+ "InitTests() - obj1->num");
+ UtAsserEqualInt(obj2->num, 2,
+ "InitTests() - obj2->num");
+ UtAsserEqualInt(obj3->num, 3,
+ "InitTests() - obj3->num");
- ut_asser_null(list->head,
- "init_tests() - list->head");
+ UtAsserNull(list->head,
+ "InitTests() - list->head");
- ut_asser_equal_int(list->count, 0,
- "init_tests() - list->count");
+ UtAsserEqualInt(list->count, 0,
+ "InitTests() - list->count");
}
void
-test_append()
+TestAppend()
{
MyObject* obj = NULL;
SListItem* item = NULL;
@@ -190,25 +199,25 @@ test_append()
printf("Testing append... \n");
- slist_append(list, obj1);
- slist_append(list, obj2);
- slist_append(list, obj3);
+ SListAppend(list, obj1);
+ SListAppend(list, obj2);
+ SListAppend(list, obj3);
SL_FOREACH(item, list) {
count++;
obj = (MyObject*)item->data;
- ut_asser_equal_int(obj->num, count,
- "test_append() - obj->num");
+ UtAsserEqualInt(obj->num, count,
+ "TestAppend() - obj->num");
}
- ut_asser_equal_int(count, 3,
- "test_append() - FOREACH count");
+ UtAsserEqualInt(count, 3,
+ "TestAppend() - FOREACH count");
}
void
-test_remove_item()
+TestRemoveItem()
{
MyObject* obj = NULL;
SListItem* item = NULL;
@@ -216,33 +225,33 @@ test_remove_item()
printf("Testing remove item...\n");
- slist_remove_value(list, obj2);
+ SListRemoveValue(list, obj2);
SL_FOREACH(item, list) {
count++;
obj = (MyObject*)item->data;
if (count == 1) {
- ut_asser_equal_int(obj->num, 1,
- "test_remove_item() - obj->num");
+ UtAsserEqualInt(obj->num, 1,
+ "TestRemoveItem() - obj->num");
}
if (count == 2) {
- ut_asser_equal_int(obj->num, 3,
- "test_remove_item() - obj->num");
+ UtAsserEqualInt(obj->num, 3,
+ "TestRemoveItem() - obj->num");
}
}
- ut_asser_equal_int(list->count, 2,
- "test_remove_item() - list->count");
+ UtAsserEqualInt(list->count, 2,
+ "TestRemoveItem() - list->count");
- ut_asser_equal_int(count, 2,
- "test_remove_item() - FOREACH count");
+ UtAsserEqualInt(count, 2,
+ "TestRemoveItem() - FOREACH count");
}
void
-test_insert_at()
+TestInsertAt()
{
MyObject* obj = NULL;
SListItem* item = NULL;
@@ -250,36 +259,36 @@ test_insert_at()
printf("Testing insert at... \n");
- slist_insert_at(list, obj2, 1);
+ SListInsertAt(list, obj2, 1);
SL_FOREACH(item, list) {
count++;
obj = (MyObject*)item->data;
if (count == 1) {
- ut_asser_equal_int(obj->num, 1,
- "test_insert_at() - obj->num");
+ UtAsserEqualInt(obj->num, 1,
+ "TestInsertAt() - obj->num");
}
if (count == 2) {
- ut_asser_equal_int(obj->num, 2,
- "test_insert_at() - obj->num");
+ UtAsserEqualInt(obj->num, 2,
+ "TestInsertAt() - obj->num");
}
if (count == 3) {
- ut_asser_equal_int(obj->num, 3,
- "test_insert_at() - obj->num");
+ UtAsserEqualInt(obj->num, 3,
+ "TestInsertAt() - obj->num");
}
}
- ut_asser_equal_int(list->count, 3,
- "test_insert_at() - list->count");
+ UtAsserEqualInt(list->count, 3,
+ "TestInsertAt() - list->count");
- ut_asser_equal_int(count, 3,
- "test_insert_at() - FOREACH count");
+ UtAsserEqualInt(count, 3,
+ "TestInsertAt() - FOREACH count");
}
void
-test_remove_at()
+TestRemoveAt()
{
MyObject* obj = NULL;
SListItem* item = NULL;
@@ -287,33 +296,33 @@ test_remove_at()
printf("Testing remove first...\n");
- slist_remove_at(list, 1);
+ SListRemoveAt(list, 1);
SL_FOREACH(item, list) {
count++;
obj = (MyObject*)item->data;
if (count == 1) {
- ut_asser_equal_int(obj->num, 1,
- "test_remove_at() - obj->num");
+ UtAsserEqualInt(obj->num, 1,
+ "TestRemoveAt() - obj->num");
}
if (count == 2) {
- ut_asser_equal_int(obj->num, 3,
- "test_remove_at() - obj->num");
+ UtAsserEqualInt(obj->num, 3,
+ "TestRemoveAt() - obj->num");
}
}
- ut_asser_equal_int(list->count, 2,
- "test_remove_at() - list->count");
+ UtAsserEqualInt(list->count, 2,
+ "TestRemoveAt() - list->count");
- ut_asser_equal_int(count, 2,
- "test_remove_at() - FOREACH count");
+ UtAsserEqualInt(count, 2,
+ "TestRemoveAt() - FOREACH count");
}
void
-test_insert_after()
+TestInsertAfter()
{
MyObject* obj = NULL;
SListItem* item = NULL;
@@ -321,36 +330,36 @@ test_insert_after()
printf("Testing insert after... \n");
- slist_insert_after(list, obj2, obj1);
+ SListInsertAfter(list, obj2, obj1);
SL_FOREACH(item, list) {
count++;
obj = (MyObject*)item->data;
if (count == 1) {
- ut_asser_equal_int(obj->num, 1,
- "test_insert_after()");
+ UtAsserEqualInt(obj->num, 1,
+ "TestInsertAfter()");
}
if (count == 2) {
- ut_asser_equal_int(obj->num, 2,
- "test_insert_after()");
+ UtAsserEqualInt(obj->num, 2,
+ "TestInsertAfter()");
}
if (count == 3) {
- ut_asser_equal_int(obj->num, 3,
- "test_insert_after()");
+ UtAsserEqualInt(obj->num, 3,
+ "TestInsertAfter()");
}
}
- ut_asser_equal_int(list->count, 3,
- "test_insert_after() - list->count");
+ UtAsserEqualInt(list->count, 3,
+ "TestInsertAfter() - list->count");
- ut_asser_equal_int(count, 3,
- "test_insert_after() - FOREACH count");
+ UtAsserEqualInt(count, 3,
+ "TestInsertAfter() - FOREACH count");
}
void
-test_remove_last()
+TestRemoveLast()
{
MyObject* obj = NULL;
SListItem* item = NULL;
@@ -358,31 +367,31 @@ test_remove_last()
printf("Testing remove last...\n");
- slist_remove_last(list);
+ SListRemoveLast(list);
SL_FOREACH(item, list) {
count++;
obj = (MyObject*)item->data;
if (count == 1) {
- ut_asser_equal_int(obj->num, 1,
- "test_remove_last()");
+ UtAsserEqualInt(obj->num, 1,
+ "TestRemoveLast()");
}
if (count == 2) {
- ut_asser_equal_int(obj->num, 2,
- "test_remove_last()");
+ UtAsserEqualInt(obj->num, 2,
+ "TestRemoveLast()");
}
}
- ut_asser_equal_int(list->count, 2,
- "test_remove_last() - list->count");
+ UtAsserEqualInt(list->count, 2,
+ "TestRemoveLast() - list->count");
- ut_asser_equal_int(count, 2,
- "test_remove_last() - FOREACH count");
+ UtAsserEqualInt(count, 2,
+ "TestRemoveLast() - FOREACH count");
}
void
-test_empty_list()
+TestEmptyList()
{
MyObject* obj = NULL;
SListItem* item = NULL;
@@ -390,69 +399,69 @@ test_empty_list()
printf("Testing empty list...\n");
- slist_append(list, obj1);
- slist_append(list, obj2);
+ SListAppend(list, obj1);
+ SListAppend(list, obj2);
- ut_asser_not_equal_int(list->count, 0,
- "test_empty_list() - list->count");
+ UtAsserNotEqualInt(list->count, 0,
+ "TestEmptyList() - list->count");
- slist_empty(list);
+ SListEmpty(list);
SL_FOREACH(item, list) {
count++;
obj = (MyObject*)item->data;
}
- ut_asser_equal_int(count, 0,
- "test_empty_list() - FOREACH count");
+ UtAsserEqualInt(count, 0,
+ "TestEmptyList() - FOREACH count");
- ut_asser_equal_int(list->count, 0,
- "test_empty_list() - list->count");
+ UtAsserEqualInt(list->count, 0,
+ "TestEmptyList() - list->count");
}
-void test_memory()
+void TestMemory()
{
- long total_mem;
- long mem_1;
- long mem_2;
- long mem_3;
- long mem_4;
- long mem_5;
- long mem_empty;
+ long totalMem;
+ long mem1;
+ long mem2;
+ long mem3;
+ long mem4;
+ long mem5;
+ long memEmpty;
printf("\nTesting memory...\n\n");
- total_mem = FreeMem();
+ totalMem = FreeMem();
- slist_append(list, obj1);
- slist_append(list, obj2);
- slist_append(list, obj3);
- mem_1 = total_mem - FreeMem();
+ SListAppend(list, obj1);
+ SListAppend(list, obj2);
+ SListAppend(list, obj3);
+ mem1 = totalMem - FreeMem();
- slist_remove_at(list, 0);
- mem_2 = total_mem - FreeMem();
+ SListRemoveAt(list, 0);
+ mem2 = totalMem - FreeMem();
- slist_remove_last(list);
- mem_3 = total_mem - FreeMem();
+ SListRemoveLast(list);
+ mem3 = totalMem - FreeMem();
- slist_remove_value(list, obj2);
- mem_4 = total_mem - FreeMem();
+ SListRemoveValue(list, obj2);
+ mem4 = totalMem - FreeMem();
- slist_append(list, obj1);
- slist_append(list, obj2);
- slist_append(list, obj3);
- mem_5 = total_mem - FreeMem();
+ SListAppend(list, obj1);
+ SListAppend(list, obj2);
+ SListAppend(list, obj3);
+ mem5 = totalMem - FreeMem();
- slist_empty(list);
- mem_empty = total_mem - FreeMem();
+ SListEmpty(list);
+ memEmpty = totalMem - FreeMem();
- printf("After appending 3 items: using %ld bytes\n", mem_1);
- printf("After removing first: using %ld bytes\n", mem_2);
- printf("After removing last: using %ld bytes\n", mem_3);
- printf("After removing item: using %ld bytes\n", mem_4);
- printf("After re-appending 3 items: using %ld bytes\n", mem_5);
- printf("After emptying: using %ld bytes\n", mem_empty);
+ printf("After appending 3 items: using %ld bytes\n", mem1);
+ printf("After removing first: using %ld bytes\n", mem2);
+ printf("After removing last: using %ld bytes\n", mem3);
+ printf("After removing item: using %ld bytes\n", mem4);
+ printf("After re-appending 3 items: using %ld bytes\n", mem5);
+ printf("After emptying: using %ld bytes\n", memEmpty);
}
int
@@ -466,19 +475,19 @@ main(void)
printf("| SList Unit Test |\n");
printf("+-----------------------------------+\n\n");
- init_tests();
+ InitTests();
- test_append();
- test_remove_item();
- test_insert_at();
- test_remove_at();
- test_insert_after();
- test_remove_last();
- test_empty_list();
+ TestAppend();
+ TestRemoveItem();
+ TestInsertAt();
+ TestRemoveAt();
+ TestInsertAfter();
+ TestRemoveLast();
+ TestEmptyList();
- test_memory();
+ TestMemory();
- if (!found_error) {
+ if (!foundError) {
printf("\nSuccessful!\n");
}
else {
--- slist.c Mon Mar 31 18:56:11 2025
+++ slist.c Wed Apr 1 21:21:27 2026
@@ -1,21 +1,30 @@
/* slist.c
*
- * Copyright 2025 Francois Techene
+ * Copyright 2026 Francois Techene
*
- * 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 3 of the License, or
- * (at your option) any later version.
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
*
- * 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.
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
*
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
- * SPDX-License-Identifier: GPL-3.0-or-later
+ * Except as contained in this notice, the name(s) of the above copyright
+ * holders shall not be used in advertising or otherwise to promote the sale,
+ * use or other dealings in this Software without prior written
+ * authorization.
*/
#include "slist.h"
@@ -24,7 +33,7 @@
SListItem*
-SListItem_new(void* data)
+NewSListItem(void* data)
{
SListItem* self = (SListItem*)NewPtr(sizeof(SListItem));
self->data = data;
@@ -34,22 +43,21 @@ SListItem_new(void* data)
}
void
-SListItem_delete(SListItem** item)
+DeleteSListItem(SListItem* item)
{
- if (*item) {
- DisposPtr(*item);
- *item = NULL;
+ if (item) {
+ DisposePtr((Ptr)(item));
}
}
SList*
-SList_new()
+NewSList()
{
SList* self = (SList*)NewPtr(sizeof(SList));
- self->first = slist_first;
- self->last = slist_last;
- self->next = slist_next;
+ self->first = SListFirst;
+ self->last = SListLast;
+ self->next = SListNext;
self->head = NULL;
self->count = 0;
@@ -58,42 +66,41 @@ SList_new()
}
void
-SList_delete(SList** list)
+DeleteSList(SList* list)
{
- slist_empty(*list);
+ SListEmpty(list);
- if (*list) {
- DisposPtr(*list);
- *list = NULL;
+ if (list) {
+ DisposePtr((Ptr)list);
}
}
void*
-slist_first(SList* self)
+SListFirst(SList* self)
{
return self->head;
}
void*
-slist_last(SList* self)
+SListLast(SList* self)
{
return NULL;
}
void*
-slist_next(SList* self, SListItem* item)
+SListNext(SList* self, SListItem* item)
{
return item->next;
}
void
-slist_append(SList* self, void* data)
+SListAppend(SList* self, void* data)
{
SListItem* elem = self->head;
- SListItem* new_elem = SListItem_new(data);
+ SListItem* newElem = NewSListItem(data);
if (!elem) {
- self->head = new_elem;
+ self->head = newElem;
self->count++;
return;
}
@@ -101,45 +108,45 @@ slist_append(SList* self, void* data)
while (elem->next) {
elem = elem->next;
}
- elem->next = new_elem;
+ elem->next = newElem;
self->count++;
}
void
-slist_insert_at(SList* self, void* data, int index)
+SListInsertAt(SList* self, void* data, int index)
{
int count = 0;
- SListItem* prev_elem = NULL;
+ SListItem* prevElem = NULL;
SListItem* elem = self->head;
- SListItem* new_elem = SListItem_new(data);
+ SListItem* newElem = NewSListItem(data);
while (elem && count < index) {
- prev_elem = elem;
- elem = elem->next;
+ prevElem = elem;
+ elem = elem->next;
count++;
}
- new_elem->next = elem;
+ newElem->next = elem;
- if (!prev_elem) {
- self->head = new_elem;
+ if (!prevElem) {
+ self->head = newElem;
}
else {
- prev_elem->next = new_elem;
+ prevElem->next = newElem;
}
self->count++;
}
void
-slist_insert_after(SList* self, void* data, void* value)
+SListInsertAfter(SList* self, void* data, void* value)
{
SListItem* elem = self->head;
- SListItem* new_elem = SListItem_new(data);
+ SListItem* newElem = NewSListItem(data);
if (!self->head) {
- self->head = new_elem;
+ self->head = newElem;
self->count++;
return;
}
@@ -148,27 +155,27 @@ slist_insert_after(SList* self, void* data, void* valu
elem = elem->next;
}
- new_elem->next = elem->next;
- elem->next = new_elem;
+ newElem->next = elem->next;
+ elem->next = newElem;
self->count++;
}
-void slist_empty(SList* self)
+void SListEmpty(SList* self)
{
while (self->head) {
- slist_remove_at(self, 0);
+ SListRemoveAt(self, 0);
}
self->head = NULL;
self->count = 0;
}
void
-slist_remove_at(SList* self, int index)
+SListRemoveAt(SList* self, int index)
{
int count = 0;
- SListItem* prev_elem = NULL;
+ SListItem* prevElem = NULL;
SListItem* elem = self->head;
if (!elem) {
@@ -176,8 +183,8 @@ slist_remove_at(SList* self, int index)
}
while (elem && count < index) {
- prev_elem = elem;
- elem = elem->next;
+ prevElem = elem;
+ elem = elem->next;
count++;
}
@@ -185,23 +192,23 @@ slist_remove_at(SList* self, int index)
return; // No element at that index position.
}
- if (!prev_elem) {
+ if (!prevElem) {
self->head = elem->next;
}
else {
- prev_elem->next = elem->next;
+ prevElem->next = elem->next;
}
- SListItem_delete(&elem);
+ DeleteSListItem(elem);
elem = NULL;
self->count--;
}
void
-slist_remove_last(SList* self)
+SListRemoveLast(SList* self)
{
- SListItem* prev_elem = NULL;
+ SListItem* prevElem = NULL;
SListItem* elem = self->head;
if (!elem) {
@@ -209,15 +216,15 @@ slist_remove_last(SList* self)
}
while (elem->next) {
- prev_elem = elem;
+ prevElem = elem;
elem = elem->next;
}
- // prev_elem->next is freed and set to NULL by the
+ // prevElem->next is freed and set to NULL by the
// delete method.
//
- SListItem_delete(&(prev_elem->next));
- prev_elem->next = NULL;
+ DeleteSListItem(prevElem->next);
+ prevElem->next = NULL;
self->count--;
}
@@ -226,32 +233,32 @@ slist_remove_last(SList* self)
// as 'value'.
//
void
-slist_remove_value(SList* self, void* value)
+SListRemoveValue(SList* self, void* value)
{
- SListItem* prev_elem = NULL;
+ SListItem* prevElem = NULL;
SListItem* elem = self->head;
while (elem != NULL) {
if (elem->data == value) {
- if (!prev_elem) {
+ if (!prevElem) {
self->head = elem->next;
}
else {
- prev_elem->next = elem->next;
+ prevElem->next = elem->next;
}
// elem is freed and set to NULL by the
// delete method.
//
- SListItem_delete(&elem);
+ DeleteSListItem(elem);
elem = NULL;
self->count--;
}
else {
- prev_elem = elem;
+ prevElem = elem;
elem = elem->next;
}
}
--- slist.h Mon Mar 31 19:27:35 2025
+++ slist.h Wed Apr 1 21:21:42 2026
@@ -1,25 +1,34 @@
/* slist.h
*
- * Copyright 2025 Francois Techene
+ * Copyright 2026 Francois Techene
*
- * 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 3 of the License, or
- * (at your option) any later version.
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
*
- * 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.
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
*
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
- * SPDX-License-Identifier: GPL-3.0-or-later
+ * Except as contained in this notice, the name(s) of the above copyright
+ * holders shall not be used in advertising or otherwise to promote the sale,
+ * use or other dealings in this Software without prior written
+ * authorization.
*/
-#ifndef SLIST_H
-#define SLIST_H
+#ifndef __SLIST_H__
+#define __SLIST_H__
typedef struct _SListItem {
@@ -41,26 +50,26 @@ typedef struct _SList {
// SListItem ////////////////
//
-SListItem* SListItem_new();
-void SListItem_delete(SListItem** item);
+SListItem* NewSListItem();
+void DeleteSListItem(SListItem* item);
// SList ////////////////////
//
-SList* SList_new();
-void SList_delete(SList** self);
+SList* NewSList();
+void DeleteSList(SList* self);
-void* slist_first(SList* self);
-void* slist_last(SList* self);
-void* slist_next(SList* self, SListItem* item);
+void* SListFirst(SList* self);
+void* SListLast(SList* self);
+void* SListNext(SList* self, SListItem* item);
-void slist_append(SList* self, void* data);
-void slist_insert_at(SList* self, void* data, int index);
-void slist_insert_after(SList* self, void* data, void* value);
+void SListAppend(SList* self, void* data);
+void SListInsertAt(SList* self, void* data, int index);
+void SListInsertAfter(SList* self, void* data, void* value);
-void slist_remove_at(SList* self, int index);
-void slist_remove_last(SList* self);
-void slist_remove_value(SList* self, void* data);
-void slist_empty(SList* self);
+void SListRemoveAt(SList* self, int index);
+void SListRemoveLast(SList* self);
+void SListRemoveValue(SList* self, void* data);
+void SListEmpty(SList* self);
#define SL_FOREACH(item, list) \