home *** CD-ROM | disk | FTP | other *** search
- /*
- * This is a semi-generic List class
- * This was written for FolkScan v2.2
- * Copyright (C) 1992 Cory West
- * corywest@rice.edu ; List.cc ; Fri Nov 13 17:34:46 CST 1992
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 1, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
- #include "List.h"
-
- void List::dump(void)
- {
- ListLink* current = head;
- head = NULL;
- ListLink* old = NULL;
-
- // Clean up all of our garbage
- while (current != NULL)
- {
- old = current;
- current = current->next;
- delete old;
- }
- length = 0;
- }
-
- void List::AddElement(String newMember)
- {
- ListLink* current = head;
-
- if (current == NULL)
- // The special case of the new list
- {
- head = new ListLink;
- head->name = newMember;
- length++;
- return;
- }
-
- // Walk to the last element in the list
- while (current->next != NULL)
- current = current->next;
-
- current->next = new ListLink;
- (current->next)->prev = current;
- (current->next)->name = newMember;
- length++;
- }
-
- String List::GetElement(int location)
- {
- ListLink* current = head;
-
- if (location > length-1)
- // Then it's out of range. The minus
- // one is because length is index 1 based
- // and location is index 0 based.
- {
- cerr << "Index reference error in List::GetElement! Send bug report!\n";
- return String("BOGUS");
- }
-
- for (int i = 0; i < location; i++)
- current = current->next;
-
- return current->name;
- }
-
- bool List::unify(char* element)
- {
- // If char* exists in this List, return FALSE.
- // Otherwise, remember the char* and return TRUE.
-
- String Selement(element);
-
- for(int i = 0; i < length; i++)
- {
- if (Selement == GetElement(i))
- // We have a match
- return FALSE;
- }
-
- AddElement(Selement);
- return TRUE;
- }
-
- void List::MarkDead(String element)
- {
- ListLink* current = head;
-
- for (int i = 0; i < length; i++)
- {
- if (current->name == element)
- current->alive--;
- current = current->next;
- }
- }
-
- void List::RemoveDead(WINDOW* errwin)
- {
- ListLink* current = head;
- ListLink* DeadLink = NULL;
- char ErrBuf[80];
- int looper = length;
-
- for (int i = 0; i < looper; i++)
- {
- if (current->alive <= 0)
- {
- strcpy(ErrBuf, "Giving up on RPC host ");
- strcat(ErrBuf, current->name);
- strcat(ErrBuf, "!\n");
- waddstr(errwin, ErrBuf);
- wrefresh(errwin);
-
- if (current->next == NULL &&
- current->prev == NULL)
- // Then this is the only element in the list
- {
- DeadLink = current;
- head = NULL;
- length = 0;
- delete DeadLink;
- return;
- }
-
- // Then we have to remove it
- if (current->prev != NULL)
- (current->prev)->next = current->next;
- if (current->next != NULL)
- (current->next)->prev = current->prev;
- DeadLink = current;
- current = current->next;
- delete DeadLink;
- length--;
- }
- else
- current = current->next;
- }
- }
-
- void List::printall()
- {
- ListLink* current = head;
-
- for (int i = 0; i < length; i++)
- {
- cerr << "*** Element " << i << " ***\n"
- << current->name << "\n"
- << current->alive << "\n";
- current = current->next;
- }
- }
-
- void List::Seen(int k)
- {
- ListLink* current = head;
-
- for (int i = 0; i < k; i++)
- current = current->next;
-
- current->seen = TRUE;
- }
-
- void List::UnSee(int k)
- {
- ListLink* current = head;
-
- for (int i = 0; i < k; i++)
- current = current->next;
-
- current->seen = FALSE;
- }
-
- bool List::Saw(int k)
- {
- ListLink* current = head;
-
- for (int i = 0; i < k; i++)
- current = current->next;
-
- return current->seen;
- }
-
- void List::CleanAll()
- {
- ListLink* current = head;
-
- for (int i = 0; i < length; i++)
- {
- current->clean = TRUE;
- current = current->next;
- }
- }
-
- void List::MakeDirty(int k)
- {
- ListLink* current = head;
-
- for (int i = 0; i < k; i++)
- current = current->next;
-
- current->clean = FALSE;
- }
-
- bool List::isClean(int k)
- {
- ListLink* current = head;
-
- for (int i = 0; i < k; i++)
- current = current->next;
-
- return current->clean;
- }
-