⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 r2tlist.c

📁 这是一个C程序分析工具
💻 C
字号:
/*====================================================================*/
/*  UNIT   :  @(#)r2tlist.c	2.3  -  08/04/99 */
/*====================================================================*/
/*  PURPOSE:  Abstract Data Type implementation of a Single Linked    */
/*            List of Test Nodes.                                     */
/*                                                                    */
/*  SYSTEM :  RECON II                                                */
/*                                                                    */
/*  USED BY:  main(), ReadTestData(), and BuildCompList().            */
/*                                                                    */
/*  HISTORY:                                                          */
/*  VER   DATE       AUTHOR        DESCRIPTION                        */
/*  1.00  23 Feb 93  L. Richard    Created unit.                      */
/*  1.01  25 Feb 93  L. Richard    Altered TestListSize().     	      */
/*  2.2   31 Jan 98  W. Hall       Added #include r2util.h to clean   */
/*                                 up a compiler warning issue.       */
/*--------------------------------------------------------------------*/

/*==[ INTERFACE ]=====================================================*/

#include "r2.h" 
#include "r2tlist.h"
#include "r2util.h"
#include <stdio.h>

/*==[ PUBLIC IMPLEMENTATION =========================================*/

/*--------------------------------------------------------------------*/
/* FUNCTION: AddTestNode                                              */
/*--------------------------------------------------------------------*/
/* PURPOSE : Allocates memory for a List Node structure and appends   */
/*           the node to the list.                                    */
/*                                                                    */
/* PRECOND : List exists and is size n.                               */
/* POSTCOND: List exists and is size n+1.                             */
/*                                                    		      */
/* HISTORY :                                                          */
/* VER   DATE       AUTHOR        DESCRIPTION                         */
/* 1.00  23 Feb 93  L. Richard    Created function.                   */
/*--------------------------------------------------------------------*/

extern void AddTestNode(
  TESTLIST	*tl,			/* Test list		      */
  TESTNODE	*node			/* Test node		      */
)
{
  TESTNODE	*ptr;			/* Temporary node pointer     */

  /* PRECOND : List exists and is size n. */

  /* Allocate space for the node */
  ptr = (TESTNODE *) malloc( sizeof( TESTNODE ) );

  if (NULL == ptr)
    AbortMsg( "FATAL ERROR: Not enough memory for new Test List Node." );

  *ptr      = *node;		/* Update node data 		      */
  ptr->Next = NULL;

  if (NULL == tl->Head)
    tl->Head = ptr;		/* List is empty, put node at head    */
  else
    tl->Tail->Next = ptr;	/* Append node to end of list  	      */

  tl->Num++;			/* Adjust list header info	      */
  tl->Tail = ptr;

  /* POSTCOND: List exists and is size n+1. */

} /* AddTestNode() */

/*--------------------------------------------------------------------*/
/* FUNCTION: CreateTestList                                           */
/*--------------------------------------------------------------------*/
/* PURPOSE : Creates an empty Test list.                              */
/*                                                                    */
/* PRECOND : List does not exist.                                     */
/* POSTCOND: List exists and is empty.                                */
/*                                                    		      */
/* HISTORY :                                                          */
/* VER   DATE       AUTHOR        DESCRIPTION                         */
/* 1.00  23 Feb 93  L. Richard    Created function.                   */
/*--------------------------------------------------------------------*/

extern void CreateTestList(
  TESTLIST	**tl			/* Test list		      */
)
{
  TESTLIST	*ptr;

  /* PRECOND : List does not exist. */
  if (NULL != *tl)
    AbortMsg( "FATAL ERROR: Attempted to re-create existing list." );

  /* Create */
  ptr = (TESTLIST *) malloc( sizeof( TESTLIST ) );

  if (NULL == ptr)
    AbortMsg( "FATAL ERROR: Not enough memory for new Test List node." );

  /* Initialize */
  ptr->Num  = 0;
  ptr->Head = NULL;
  ptr->Tail = NULL;

  /* Designate as list */
  *tl = ptr;

  /* POSTCOND: List exists and is empty. */

} /* CreateTestList() */

/*--------------------------------------------------------------------*/
/* FUNCTION: DeleteTestList                                           */
/*--------------------------------------------------------------------*/
/* PURPOSE : Disposes of all nodes in a Test list and returns the     */
/*           memory previously allocated.                             */
/*                                                                    */
/* PRECOND : List exists and is not empty.                            */
/* POSTCOND: List does not exist.                                     */
/*                                                    		      */
/* HISTORY :                                                          */
/* VER   DATE       AUTHOR        DESCRIPTION                         */
/* 1.00  23 Feb 93  L. Richard    Created function.                   */
/*--------------------------------------------------------------------*/

extern void DeleteTestList(
  TESTLIST	**tl		/* test list pointer	   */
)
{
  TESTLIST	*tlm;           /* temporary list marker   */
  TESTNODE	*ptr;        	/* temporary node marker   */

  /* PRECOND : List exists and is not empty. */
  if (0 == (*tl)->Num)
    AbortMsg( "FATAL ERROR: Attempted to delete a non-existant list." );

  while (NULL != (*tl)->Head)	/* if non-empty list       */
  {
    ptr      = (*tl)->Head;	/* mark node to delete     */
    (*tl)->Head = ptr->Next;	/* mark new top of list    */
    free( ptr );                /* remove old top node     */
  }

  tlm = *tl;			/* mark list          	*/
  free( tlm );                  /* remove list      	*/
  *tl = NULL;                   /* clear list pointer	*/

  /* POSTCOND: List does not exist. */

} /* DeleteTestList() */

/*--------------------------------------------------------------------*/
/* FUNCTION: RemoveTestNode                                          */
/*--------------------------------------------------------------------*/
/* PURPOSE : Removes a node from a test list.                         */
/*                                                                    */
/* PRECOND : List exists of size n > 0                                */
/* POSTCOND: List exists of size n-1 (n > 0 ).                        */
/*                                                    		      */
/* HISTORY :                                                          */
/* VER   DATE       AUTHOR        DESCRIPTION                         */
/* 1.00  23 Feb 93  L. Richard    Created function.                   */
/*--------------------------------------------------------------------*/

extern void RemoveTestNode(
  TESTLIST	*tl,			/* Test list		      */
  TESTNODE	*node			/* Test node		      */
)
{
  TESTNODE *ptr;

  /* PRECOND : List exists of size n > 0. */
  if (0 == TestListSize( tl ))
    AbortMsg( "FATAL ERROR: Attempted to remove Test Node from empty list." );

  /* Retrieve node */
  *node    = *tl->Head;

  /* Remove node from list */
  ptr      = tl->Head;
  tl->Head = tl->Head->Next;

  /* Adjust size */
  tl->Num--;

  /* Return memory */
  free( ptr );

  /* POSTCOND: List exists of size n-1 (n > 0 ). */

} /* RemoveTestNode() */

/*--------------------------------------------------------------------*/
/* FUNCTION: ShowTestList                                             */
/*--------------------------------------------------------------------*/
/* PURPOSE : Displays the information from the nodes in a Test list.  */
/*                                                                    */
/* PRECOND : List exists.                                             */
/* POSTCOND: n/a                                                      */
/*                                                    		      */
/* HISTORY :                                                          */
/* VER   DATE       AUTHOR        DESCRIPTION                         */
/* 1.00  23 Feb 93  L. Richard    Created function.                   */
/*--------------------------------------------------------------------*/

extern void ShowTestList(
  TESTLIST	*tl			/* Test list		      */
)
{
  TESTNODE	*ptr;        	/* temporay node marker    */
  int		i = 1;

  /* PRECOND : List exists. */

  /* Display banner */
  printf( "\n----- TestList -----\n" );
  printf( "Addr = DS:%p\nNum  = %d\nHead = DS:%p\nTail = DS:%p\n",
	  tl, tl->Num, tl->Head, tl->Tail );

  /* Traverse list from top */
  ptr = tl->Head;
  while (NULL != ptr)
  {
    /* Display node information */
    printf( "%4d = DS:%p -> %s, %d  DS:%p\n",
	    i, ptr, ptr->Output, ptr->Exhibits, ptr->Next );

    ptr = ptr->Next;
    i++;
  }
  printf( "\n" );

  /* POSTCOND: n/a */

} /* ShowTestList() */

/*--------------------------------------------------------------------*/
/* FUNCTION: TestListSize                                             */
/*--------------------------------------------------------------------*/
/* PURPOSE : Returns the number of nodes in the list.                 */
/*                                                                    */
/* PRECOND : List exists (may be empty).                              */
/* POSTCOND: n/a                                                      */
/*                                                    		      */
/* HISTORY :                                                          */
/* VER   DATE       AUTHOR        DESCRIPTION                         */
/* 1.00  23 Feb 93  L. Richard    Created function.                   */
/* 1.01  25 Feb 93  L. Richard    Relaxed precondition		      */
/*--------------------------------------------------------------------*/

extern int  TestListSize(
  TESTLIST	*tl			/* Test list		      */
)
{
  /* PRECOND : List exists (may be empty). */

  /* POSTCOND: n/a */

  return( tl->Num );

} /* TestListSize() */

/*====================================================================*/
/*  EOF    :  r2tlist.c                                               */
/*====================================================================*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -