venus: Remove dedebug
[openafs.git] / src / aklog / linked_list.c
index 0d4ba0b..289d645 100644 (file)
@@ -1,22 +1,18 @@
-/* 
+/*
  * $Id$
- * 
+ *
  * This file contains general linked list routines.
- * 
+ *
  * Copyright 1990,1991 by the Massachusetts Institute of Technology
  * For distribution and copying rights, see the file "mit-copyright.h"
  */
 
-#if !defined(lint) && !defined(SABER)
-static char *rcsid_list_c = "$Id$";
-#endif /* lint || SABER */
+#include <afsconfig.h>
+#include <afs/param.h>
 
-#include <stdio.h>
-#include "linked_list.h"
+#include <roken.h>
 
-#ifndef NULL
-#define NULL 0
-#endif
+#include "linked_list.h"
 
 #ifndef TRUE
 #define TRUE 1
@@ -26,11 +22,8 @@ static char *rcsid_list_c = "$Id$";
 #define FALSE 0
 #endif
 
-char *calloc();
-
-#ifdef __STDC__
 void ll_init(linked_list *list)
-  /* 
+  /*
    * Requires:
    *   List must point to a linked list structure.  It is not acceptable
    *   to pass a null pointer to this routine.
@@ -40,10 +33,6 @@ void ll_init(linked_list *list)
    *   Initializes the list to be one with no elements.  If list is
    *   NULL, prints an error message and causes the program to crash.
    */
-#else
-void ll_init(list)
-  linked_list *list;
-#endif /* __STDC__ */
 {
     if (list == NULL) {
        fprintf(stderr, "Error: calling ll_init with null pointer.\n");
@@ -51,34 +40,24 @@ void ll_init(list)
     }
 
     /* This sets everything to zero, which is what we want. */
-#ifdef WINDOWS
-       memset(list, 0, sizeof(linked_list));
-#else
     bzero((char *)list, sizeof(linked_list));
-#endif /* WINDOWS */
 }
 
-#ifdef __STDC__
 ll_node *ll_add_node(linked_list *list, ll_end which_end)
   /*
    * Modifies:
    *   list
-   * Effects: 
+   * Effects:
    *   Adds a node to one end of the list (as specified by which_end)
    *   and returns a pointer to the node added.  which_end is of type
-   *   ll_end and should be either ll_head or ll_tail as specified in 
-   *   list.h.  If there is not enough memory to allocate a node, 
+   *   ll_end and should be either ll_head or ll_tail as specified in
+   *   list.h.  If there is not enough memory to allocate a node,
    *   the program returns NULL.
    */
-#else
-ll_node *ll_add_node(list, which_end)
-  linked_list *list;
-  ll_end which_end;
-#endif /* __STDC__ */
 {
     ll_node *node = NULL;
-    
-    if ((node = (ll_node *)calloc(1, sizeof(ll_node))) != NULL) {
+
+    if ((node = calloc(1, sizeof(ll_node))) != NULL) {
        if (list->nelements == 0) {
            list->first = node;
            list->last = node;
@@ -105,75 +84,55 @@ ll_node *ll_add_node(list, which_end)
            list->nelements++;
        }
     }
-       
+
     return(node);
 }
 
 
-#ifdef __STDC__
 int ll_delete_node(linked_list *list, ll_node *node)
-  /* 
-   * Modifies: 
+  /*
+   * Modifies:
    *   list
    * Effects:
-   *   If node is in list, deletes node and returns LL_SUCCESS.  
+   *   If node is in list, deletes node and returns LL_SUCCESS.
    *   Otherwise, returns LL_FAILURE.  If node contains other data,
    *   it is the responsibility of the caller to free it.  Also, since
    *   this routine frees node, after the routine is called, "node"
    *   won't point to valid data.
    */
-#else
-int ll_delete_node(list, node)
-  linked_list *list;
-  ll_node *node;
-#endif /* __STDC__ */
 {
-    int status = LL_SUCCESS;
     ll_node *cur_node = NULL;
-    int found = FALSE;
 
     if (list->nelements == 0)
-       status = LL_FAILURE;
-    else {
-       for (cur_node = list->first; (cur_node != NULL) && !found;
-            cur_node = cur_node->next) {
-           if (cur_node == node) {
+       return LL_FAILURE;
 
-               if (cur_node->prev)
-                   cur_node->prev->next = cur_node->next;
-               else
-                   list->first = cur_node->next;
+    for (cur_node = list->first; cur_node != NULL; cur_node = cur_node->next) {
+       if (cur_node == node) {
 
-               if (cur_node->next)
-                   cur_node->next->prev = cur_node->prev;
-               else
-                   list->last = cur_node->prev;
+           if (cur_node->prev)
+               cur_node->prev->next = cur_node->next;
+           else
+               list->first = cur_node->next;
 
-               free(cur_node);
-               list->nelements--;
-               found = TRUE;
-           }
+           if (cur_node->next)
+               cur_node->next->prev = cur_node->prev;
+           else
+               list->last = cur_node->prev;
+
+           free(cur_node);
+           list->nelements--;
+           return LL_SUCCESS;
        }
     }
 
-    if (!found)
-       status = LL_FAILURE;
-
-    return(status);
+    return LL_FAILURE;
 }
 
 
 /* ll_add_data is a macro defined in linked_list.h */
 
 /* This routine maintains a list of strings preventing duplication. */
-#ifdef __STDC__
 int ll_string(linked_list *list, ll_s_action action, char *string)
-#else
-int ll_string(list, action, string)
-  linked_list *list;
-  ll_s_action action;
-  char *string;
-#endif /* __STDC__ */
 {
     int status = LL_SUCCESS;
     ll_node *cur_node;
@@ -181,21 +140,20 @@ int ll_string(list, action, string)
     switch(action) {
       case ll_s_check:
        /* Scan the list until we find the string in question */
-       for (cur_node = list->first; cur_node && (status == FALSE); 
+       for (cur_node = list->first; cur_node && (status == FALSE);
             cur_node = cur_node->next)
            status = (strcmp(string, cur_node->data) == 0);
        break;
       case ll_s_add:
        /* Add a string to the list. */
        if (!ll_string(list, ll_s_check, string)) {
-           if (cur_node = ll_add_node(list, ll_tail)) {
+           if ((cur_node = ll_add_node(list, ll_tail))) {
                char *new_string;
-               if (new_string = (char *)calloc(strlen(string) + 1, 
-                                               sizeof(char))) {
+               if ((new_string = calloc(strlen(string) + 1, sizeof(char)))) {
                    strcpy(new_string, string);
                    ll_add_data(cur_node, new_string);
                }
-               else 
+               else
                    status = LL_FAILURE;
            }
            else