Skip to content

Commit

Permalink
Remove unused code from oldlist
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Jan 3, 2019
1 parent 3377ed2 commit f76d8a1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 294 deletions.
184 changes: 24 additions & 160 deletions src/cutil/oldlist.cpp
Expand Up @@ -4,11 +4,6 @@
# File: oldlist.cpp
# Description: List processing procedures.
# Author: Mark Seaman, Software Productivity
# Created: Thu Jul 23 13:24:09 1987
# Modified: Thu Dec 22 10:59:52 1988 (Mark Seaman) marks@hpgrlt
# Language: C
# Package: N/A
# Status: Reusable Software Component
#
# (c) Copyright 1987, Hewlett-Packard Company.
** Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -53,21 +48,6 @@
count LENGTH x = count(l);
search MEMBER if (search(l, x, nullptr))
To implement SETS use:
adjoin l = adjoin(l, x);
set_union l = set_union(r, s);
intersection l = intersection(r, s);
set_difference l = set_difference(r, s);
delete l = delete(s, x, nullptr);
search if (search(l, x, nullptr))
To Implement Associated LISTS use:
lpush l = lpush(l, p);
assoc s = assoc(l, x);
adelete l = adelete(l, x);
The following rules of closure exist for the functions provided.
a = first_node (push (a, b))
b = list_rest (push (a, b))
Expand All @@ -87,9 +67,31 @@
#define add_on(l, x) l = push(l, first_node(x))
#define next_one(l) l = list_rest(l)

/**********************************************************************
* c o p y f i r s t
*
* Do the appropriate kind a push operation to copy the first node from
* one list to another.
*
**********************************************************************/

#define copy_first(l1,l2) \
(l2=push(l2, first_node(l1)))

/*----------------------------------------------------------------------
F u n c t i o n s
----------------------------------------------------------------------*/

/**********************************************************************
* i s s a m e
*
* Compare the list node with the key value return TRUE (non-zero)
* if they are equivalent strings. (Return FALSE if not)
**********************************************************************/
static int is_same(void *item1, void *item2) {
return strcmp((char *)item1, (char *)item2) == 0;
}

/**********************************************************************
* c o u n t
*
Expand All @@ -108,8 +110,7 @@ int count(LIST var_list) {
* Delete all the elements out of the current list that match the key.
* This operation destroys the original list. The caller will supply a
* routine that will compare each node to the
* key, and return a non-zero value when they match. If the value
* nullptr is supplied for is_equal, the is_key routine will be used.
* key, and return a non-zero value when they match.
**********************************************************************/
LIST delete_d(LIST list, void *key, int_compare is_equal) {
LIST result = NIL_LIST;
Expand Down Expand Up @@ -137,31 +138,6 @@ LIST delete_d(LIST list, void *key, int_compare is_equal) {
return (result);
}

LIST delete_d(LIST list, void *key,
TessResultCallback2<int, void *, void *> *is_equal) {
LIST result = NIL_LIST;
LIST last_one = NIL_LIST;

while (list != NIL_LIST) {
if (!(*is_equal).Run(first_node(list), key)) {
if (last_one == NIL_LIST) {
last_one = list;
list = list_rest(list);
result = last_one;
set_rest(last_one, NIL_LIST);
} else {
set_rest(last_one, list);
last_one = list;
list = list_rest(list);
set_rest(last_one, NIL_LIST);
}
} else {
list = pop(list);
}
}
return (result);
}

/**********************************************************************
* d e s t r o y
*
Expand Down Expand Up @@ -192,48 +168,6 @@ void destroy_nodes(LIST list, void_dest destructor) {
}
}

/**********************************************************************
* i n s e r t
*
* Create a list element and rearange the pointers so that the first
* element in the list is the second aurgment.
**********************************************************************/
void insert(LIST list, void *node) {
LIST element;

if (list != NIL_LIST) {
element = push(NIL_LIST, node);
set_rest(element, list_rest(list));
set_rest(list, element);
node = first_node(list);
list->node = first_node(list_rest(list));
list->next->node = (LIST)node;
}
}

/**********************************************************************
* i s s a m e
*
* Compare the list node with the key value return TRUE (non-zero)
* if they are equivalent strings. (Return FALSE if not)
**********************************************************************/
int is_same(void *item1, void *item2) {
return strcmp((char *)item1, (char *)item2) == 0 ? 1 : 0;
}

/**********************************************************************
* j o i n
*
* Join the two lists together. This function is similar to concat
* except that concat creates a new list. This function returns the
* first list updated.
**********************************************************************/
LIST join(LIST list1, LIST list2) {
if (list1 == NIL_LIST) return (list2);
set_rest(last(list1), list2);
return (list1);
}

/**********************************************************************
* l a s t
*
Expand All @@ -244,19 +178,6 @@ LIST last(LIST var_list) {
return (var_list);
}

/**********************************************************************
* n t h c e l l
*
* Return nth list cell in the list.
**********************************************************************/
void *nth_cell(LIST var_list, int item_num) {
int x = 0;
iterate(var_list) {
if (x++ == item_num) return (var_list);
}
return (var_list);
}

/**********************************************************************
* p o p
*
Expand Down Expand Up @@ -305,73 +226,16 @@ LIST push_last(LIST list, void *item) {
return (push(NIL_LIST, item));
}

/**********************************************************************
* r e v e r s e
*
* Create a new list with the elements reversed. The old list is not
* destroyed.
**********************************************************************/
LIST reverse(LIST list) {
LIST newlist = NIL_LIST;

iterate(list) copy_first(list, newlist);
return (newlist);
}

/**********************************************************************
* r e v e r s e d
*
* Create a new list with the elements reversed. The old list is
* destroyed.
**********************************************************************/
LIST reverse_d(LIST list) {
LIST result = reverse(list);
destroy(list);
return (result);
}

/**********************************************************************
* s a d j o i n
*
* Adjoin an element to an assorted list. The original list is
* modified. Returns the modified list.
**********************************************************************/
LIST s_adjoin(LIST var_list, void *variable, int_compare compare) {
LIST l;
int result;

if (compare == nullptr) compare = (int_compare)strcmp;

l = var_list;
iterate(l) {
result = (*compare)(variable, first_node(l));
if (result == 0)
return (var_list);
else if (result < 0) {
insert(l, variable);
return (var_list);
}
}
return (push_last(var_list, variable));
}

/**********************************************************************
* s e a r c h
*
* Search list, return NIL_LIST if not found. Return the list starting from
* the item if found. The compare routine "is_equal" is passed in as
* the third parameter to this routine. If the value nullptr is supplied
* for is_equal, the is_key routine will be used.
* the third parameter to this routine.
**********************************************************************/
LIST search(LIST list, void *key, int_compare is_equal) {
if (is_equal == nullptr) is_equal = is_same;

iterate(list) if ((*is_equal)(first_node(list), key)) return (list);
return (NIL_LIST);
}

LIST search(LIST list, void *key,
TessResultCallback2<int, void *, void *> *is_equal) {
iterate(list) if ((*is_equal).Run(first_node(list), key)) return (list);
return (NIL_LIST);
}

0 comments on commit f76d8a1

Please sign in to comment.