FreeRTOS C-Addons  1.1.0
C-Addon functionality to FreeRTOS
slist.c
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2017, Michael Becker (michael.f.becker@gmail.com)
4  *
5  * This file is part of the FreeRTOS Add-ons project.
6  *
7  * Source Code:
8  * https://github.com/michaelbecker/freertos-addons
9  *
10  * Project Page:
11  * http://michaelbecker.github.io/freertos-addons/
12  *
13  * On-line Documentation:
14  * http://michaelbecker.github.io/freertos-addons/docs/html/index.html
15  *
16  * Permission is hereby granted, free of charge, to any person obtaining a
17  * copy of this software and associated documentation files
18  * (the "Software"), to deal in the Software without restriction, including
19  * without limitation the rights to use, copy, modify, merge, publish,
20  * distribute, sublicense, and/or sell copies of the Software, and to
21  * permit persons to whom the Software is furnished to do so,subject to the
22  * following conditions:
23  *
24  * + The above copyright notice and this permission notice shall be included
25  * in all copies or substantial portions of the Software.
26  * + Credit is appreciated, but not required, if you find this project
27  * useful enough to include in your application, product, device, etc.
28  *
29  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
30  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
32  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
33  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
34  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
35  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36  *
37  ***************************************************************************/
38 
39 
40 #include <stdlib.h>
41 #include "slist.h"
42 
43 
45  SlNode_t *Node)
46 {
47  /********************/
48  SlNode_t *Current;
49  /********************/
50 
51  if (Head == NULL)
52  return;
53 
54  if (Node == NULL)
55  return;
56 
57  Current = Head;
58 
59  while (Current->Next != NULL){
60  Current = Current->Next;
61  }
62 
63  Current->Next = Node;
64  Node->Next = NULL;
65 }
66 
67 
69  SlNode_t *Node)
70 {
71  /********************/
72  SlNode_t *Temp;
73  /********************/
74 
75  if (Marker == NULL)
76  return;
77 
78  if (Node == NULL)
79  return;
80 
81  Temp = Marker->Next;
82  Marker->Next = Node;
83  Node->Next = Temp;
84 }
85 
86 
88  SlNode_t *Marker,
89  SlNode_t *Node)
90 {
91  /********************/
92  SlNode_t *Current;
93  SlNode_t *Prior;
94  int Found = 0;
95  /********************/
96 
97  if (Marker == NULL)
98  return;
99 
100  if (Node == NULL)
101  return;
102 
103  if (Head == NULL)
104  return;
105 
106  Current = Head->Next;
107  Prior = Head;
108 
109  while (Current != NULL){
110 
111  if (Current == Marker){
112  Found = 1;
113  break;
114  }
115 
116  Prior = Current;
117  Current = Current->Next;
118  }
119 
120  if (Found) {
121  Prior->Next = Node;
122  Node->Next = Current;
123  }
124 }
125 
126 
127 void SlRemoveNode ( SlNode_t *Head,
128  SlNode_t *Node)
129 {
130  /********************/
131  SlNode_t *Current;
132  SlNode_t *Prior;
133  int Found = 0;
134  /********************/
135 
136  if (Head == NULL)
137  return;
138 
139  if (Node == NULL)
140  return;
141 
142  Current = Head->Next;
143  Prior = Head;
144 
145  while (Current != NULL){
146 
147  if (Current == Node){
148  Found = 1;
149  break;
150  }
151 
152  Prior = Current;
153  Current = Current->Next;
154  }
155 
156  if (Found) {
157  Prior->Next = Current->Next;
158  }
159 }
160 
161 
163 {
164  /********************/
165  SlNode_t *Node;
166  /********************/
167 
168  if (Head == NULL)
169  return NULL;
170 
171  Node = Head->Next;
172 
173  if (Node != NULL) {
174  Head->Next = Node->Next;
175  }
176 
177  return Node;
178 }
179 
180 
182 {
183  /********************/
184  SlNode_t *Current;
185  SlNode_t *Prior;
186  /********************/
187 
188  if (Head == NULL)
189  return NULL;
190 
191  Current = Head->Next;
192  Prior = Head;
193 
194  if (SlIsListEmpty(Head)) {
195  return NULL;
196  }
197 
198  while (Current->Next != NULL){
199 
200  Prior = Current;
201  Current = Current->Next;
202  }
203 
204  Prior->Next = NULL;
205 
206  return Current;
207 }
208 
209 
void SlRemoveNode(SlNode_t *Head, SlNode_t *Node)
Definition: slist.c:127
struct SlNode_t_ * Next
Definition: slist.h:58
void SlInsertNodeBefore(SlNode_t *Head, SlNode_t *Marker, SlNode_t *Node)
Definition: slist.c:87
SlNode_t * SlRemoveNodeFromHead(SlNode_t *Head)
Definition: slist.c:162
#define SlIsListEmpty(_head)
Definition: slist.h:120
void SlAddNodeToTail(SlNode_t *Head, SlNode_t *Node)
Definition: slist.c:44
void SlInsertNodeAfter(SlNode_t *Marker, SlNode_t *Node)
Definition: slist.c:68
SlNode_t * SlRemoveNodeFromTail(SlNode_t *Head)
Definition: slist.c:181