📄 ip51_csc.c
字号:
/*************************************************************************/
/* DESCRIPTION */
/* */
/* This file contains linked list manipulation facilities used */
/* throughout the Nucleus PLUS system. These facilities operate */
/* on doubly-linked circular lists. */
/* */
/* DATA STRUCTURES */
/* */
/* None */
/* */
/* FUNCTIONS */
/* */
/* CSC_Place_On_List Place node at the end of a */
/* list */
/* CSC_Priority_Place_On_List Place node in priority order */
/* on a list */
/* CSC_Remove_From_List Remove a node from a list */
/* */
/* DEPENDENCIES */
/* */
/* */
/* HISTORY */
/* */
/* DATE REMARKS */
/* */
/* 02-09-2004 Created initial version 1.0 */
/*************************************************************************/
#include "ip51_cs_defs.h" /* Include CS definitions */
#include "ip51_cs_extr.h" /* Common service functions */
#define NULL 0
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* CSC_Place_On_List */
/* */
/* DESCRIPTION */
/* */
/* This function places the specified node at the end of specified */
/* linked list. */
/* */
/* CALLED BY */
/* */
/* various components */
/* */
/* CALLS */
/* */
/* None */
/* */
/* INPUTS */
/* */
/* head Pointer to head pointer */
/* node Pointer to node to add */
/* */
/* OUTPUTS */
/* */
/* modified list */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* wang qinglin 02-10-2004 Created initial version 1.0 */
/* */
/*************************************************************************/
void CSC_Place_On_List(CS_NODE **head, CS_NODE *new_node)
{
/* Determine if the list in non-empty. */
if (*head)
{
/* The list is not empty. Add the new node to the end of
the list. */
new_node -> cs_previous = (*head) -> cs_previous;
(new_node -> cs_previous) -> cs_next = new_node;
new_node -> cs_next = (*head);
(new_node -> cs_next) -> cs_previous = new_node;
}
else
{
/* The list is empty, setup the head and the new node. */
(*head) = new_node;
new_node -> cs_previous = new_node;
new_node -> cs_next = new_node;
}
}
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* CSC_Priority_Place_On_List */
/* */
/* DESCRIPTION */
/* */
/* This function places the specified node after all other nodes on */
/* the list of equal or greater priority. Note that lower */
/* numerical values indicate greater priority. */
/* */
/* CALLED BY */
/* */
/* various components */
/* */
/* CALLS */
/* */
/* None */
/* */
/* INPUTS */
/* */
/* head Pointer to head pointer */
/* node Pointer to node to add */
/* */
/* OUTPUTS */
/* */
/* modified list */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* wang qinglin 02-10-2004 Created initial version 1.0 */
/*************************************************************************/
void CSC_Priority_Place_On_List(CS_NODE **head, CS_NODE *new_node)
{
CS_NODE *search_ptr; /* List search pointer */
/* Determine if the list in non-empty. */
if (*head)
{
/* Search the list to find the proper place for the new node. */
search_ptr = (*head);
/* Check for insertion before the first node on the list. */
if (search_ptr -> cs_priority > new_node -> cs_priority)
{
/* Update the head pointer to point at the new node. */
(*head) = new_node;
}
else
{
/* We know that the new node is not the highest priority and
must be placed somewhere after the head pointer. */
/* Move search pointer up to the next node since we are trying
to find the proper node to insert in front of. */
search_ptr = search_ptr -> cs_next;
while ((search_ptr -> cs_priority <= new_node -> cs_priority) &&
(search_ptr != (*head)))
{
/* Move along to the next node. */
search_ptr = search_ptr -> cs_next;
}
}
/* Insert before search pointer. */
new_node -> cs_previous = search_ptr -> cs_previous;
(new_node -> cs_previous) -> cs_next = new_node;
new_node -> cs_next = search_ptr;
(new_node -> cs_next) -> cs_previous = new_node;
}
else
{
/* The list is empty, setup the head and the new node. */
(*head) = new_node;
new_node -> cs_previous = new_node;
new_node -> cs_next = new_node;
}
}
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* CSC_Remove_From_List */
/* */
/* DESCRIPTION */
/* */
/* This function removes the specified node from the specified */
/* linked list. */
/* */
/* CALLED BY */
/* */
/* various components */
/* */
/* CALLS */
/* */
/* None */
/* */
/* INPUTS */
/* */
/* head Pointer to head pointer */
/* node Pointer to node to add */
/* */
/* OUTPUTS */
/* */
/* modified list */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* wang qinglin 02-10-2004 Created initial version 1.0 */
/*************************************************************************/
void CSC_Remove_From_List(CS_NODE **head, CS_NODE *node)
{
/* Determine if this is the only node in the system. */
if (node -> cs_previous == node)
{
/* Yes, this is the only node in the system. Clear the node's
pointers and the head pointer. */
(*head) = NULL;
}
else
{
/* Unlink the node from a multiple node list. */
(node -> cs_previous) -> cs_next = node -> cs_next;
(node -> cs_next) -> cs_previous = node -> cs_previous;
/* Check to see if the node to delete is at the head of the
list. */
if (node == *head)
/* Move the head pointer to the node after. */
*head = node -> cs_next;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -