2006-11-26 03:43:56 -07:00
|
|
|
/* $Xorg: list.c,v 1.4 2001/02/09 02:05:59 xorgcvs Exp $ */
|
|
|
|
/******************************************************************************
|
|
|
|
|
|
|
|
Copyright 1993, 1998 The Open Group
|
|
|
|
|
|
|
|
Permission to use, copy, modify, distribute, and sell this software and its
|
|
|
|
documentation for any purpose is hereby granted without fee, provided that
|
|
|
|
the above copyright notice appear in all copies and that both that
|
|
|
|
copyright notice and this permission notice appear in supporting
|
|
|
|
documentation.
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
|
|
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
Except as contained in this notice, the name of The Open Group shall not be
|
|
|
|
used in advertising or otherwise to promote the sale, use or other dealings
|
|
|
|
in this Software without prior written authorization from The Open Group.
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#include "xsm.h"
|
|
|
|
|
|
|
|
List *
|
2010-10-31 14:17:58 -06:00
|
|
|
ListInit(void)
|
2006-11-26 03:43:56 -07:00
|
|
|
{
|
|
|
|
List *l;
|
|
|
|
|
|
|
|
l = (List *)XtMalloc(sizeof *l);
|
|
|
|
if(!l) return l;
|
|
|
|
l->next = l;
|
|
|
|
l->prev = l;
|
|
|
|
l->thing = NULL;
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
|
|
|
List *
|
2010-10-31 14:17:58 -06:00
|
|
|
ListFirst(List *l)
|
2006-11-26 03:43:56 -07:00
|
|
|
{
|
|
|
|
if(l->next->thing) return l->next;
|
|
|
|
else return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
List *
|
2010-10-31 14:17:58 -06:00
|
|
|
ListNext(List *l)
|
2006-11-26 03:43:56 -07:00
|
|
|
{
|
|
|
|
if(l->next->thing) return l->next;
|
|
|
|
else return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-10-31 14:17:58 -06:00
|
|
|
ListFreeAll(List *l)
|
2006-11-26 03:43:56 -07:00
|
|
|
{
|
|
|
|
char *thing;
|
|
|
|
List *next;
|
|
|
|
|
|
|
|
next = l->next;
|
|
|
|
do {
|
|
|
|
l = next;
|
|
|
|
next = l->next;
|
|
|
|
thing = l->thing;
|
|
|
|
XtFree((char *)l);
|
|
|
|
} while(thing);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-10-31 14:17:58 -06:00
|
|
|
ListFreeAllButHead(List *l)
|
2006-11-26 03:43:56 -07:00
|
|
|
{
|
|
|
|
List *p, *next;
|
|
|
|
|
|
|
|
p = ListFirst(l);
|
|
|
|
|
|
|
|
while (p)
|
|
|
|
{
|
|
|
|
next = ListNext (p);
|
|
|
|
XtFree((char *) p);
|
|
|
|
p = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
l->next = l;
|
|
|
|
l->prev = l;
|
|
|
|
}
|
|
|
|
|
|
|
|
List *
|
2010-10-31 14:17:58 -06:00
|
|
|
ListAddFirst(List *l, char *v)
|
2006-11-26 03:43:56 -07:00
|
|
|
{
|
|
|
|
List *e;
|
|
|
|
|
|
|
|
e = (List *)XtMalloc(sizeof *e);
|
|
|
|
if(!e) return NULL;
|
|
|
|
|
|
|
|
e->thing = v;
|
|
|
|
e->prev = l;
|
|
|
|
e->next = e->prev->next;
|
|
|
|
e->prev->next = e;
|
|
|
|
e->next->prev = e;
|
|
|
|
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
List *
|
2010-10-31 14:17:58 -06:00
|
|
|
ListAddLast(List *l, char *v)
|
2006-11-26 03:43:56 -07:00
|
|
|
{
|
|
|
|
List *e;
|
|
|
|
|
|
|
|
e = (List *)XtMalloc(sizeof *e);
|
|
|
|
if(!e) return NULL;
|
|
|
|
|
|
|
|
e->thing = v;
|
|
|
|
e->next = l;
|
|
|
|
e->prev = e->next->prev;
|
|
|
|
e->prev->next = e;
|
|
|
|
e->next->prev = e;
|
|
|
|
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-10-31 14:17:58 -06:00
|
|
|
ListFreeOne(List *e)
|
2006-11-26 03:43:56 -07:00
|
|
|
{
|
|
|
|
e->next->prev = e->prev;
|
|
|
|
e->prev->next = e->next;
|
|
|
|
XtFree((char *)e);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Status
|
2010-10-31 14:17:58 -06:00
|
|
|
ListSearchAndFreeOne(List *l, char *thing)
|
2006-11-26 03:43:56 -07:00
|
|
|
{
|
|
|
|
List *p;
|
|
|
|
|
|
|
|
for (p = ListFirst (l); p; p = ListNext (p))
|
|
|
|
if (((char *) p->thing) == (char *) thing)
|
|
|
|
{
|
|
|
|
ListFreeOne (p);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2010-10-31 14:17:58 -06:00
|
|
|
ListCount(List *l)
|
2006-11-26 03:43:56 -07:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
List *e;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
for(e = ListFirst(l); e; e = ListNext(e)) i++;
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|