AmendHub

Download

ftech

/

SList

/

README

 

(View History)

Francois Techene   Changed license to MIT + refactored to feature camel case syntax. Latest amendment: 4 on 2026-04-01

1 SList: a C library that implements Singly Linked Lists for classic Macintosh programs.
2
3 SList is free software; see the LICENSE file for copyright/licensing
4 ---
5
6 # Install
7
8 This library has been built and tested using THINK C v5 on a Macintosh SE.
9
10 In order to install it, just import `Slist.Lib` from the `build` folder to your project and include it in your source files.
11
12 You can also add `slist.c` and `slist.h` directly to your project.
13 ---
14
15 # Usage
16
17 ## Creating a new list
18 ```
19 // Create a new SList object.
20 SList* myList = NewSList();
21 ```
22
23 ## Adding objects to the list
24 ```
25 // Append an object at the end of the list.
26 SListAppend(myList, (Ptr)myObject);
27
28 // Insert an object at a given 0 based index position in the list.
29 // (Third position in this case).
30 SListInsertAt(myList, (Ptr)myObject, 2);
31
32 // Insert an object after the first occurence of another one.
33 SListInsertAfter(myList, (Ptr)myObject, (Ptr)otherObject);
34 ```
35
36 ## Removing objects from the list
37 ```
38 // Remove the first occurence of an object from the list.
39 SListRemoveValue(myList, (Ptr)myObject);
40
41 // Remove an object at a given 0 based index postion from the list.
42 // (Third position in this case).
43 SListRemoveAt(myList, 2);
44
45 // Remove the last object from the list.
46 SListRemoveLast(myList);
47
48 // Remove all objects from the list.
49 SListEmpty(myList);
50 ```
51
52 ## Parsing a list
53 ```
54 SL_FOREACH(item, list) {
55 obj = (MyObject*)item->data;
56 }
57 ```
58
59 You can customize the SL_FOREACH macro by re-implementing `SList.first()`, `SList.last()` and `SList.next()` for your own needs.