symlist.c

Mon, 17 Jan 2005 22:02:09 +0100

author
tuomov
date
Mon, 17 Jan 2005 22:02:09 +0100
changeset 85
9f94b2e96e3b
parent 62
aae5facf9fc5
child 88
308dfa54da3e
permissions
-rw-r--r--

trunk: changeset 1934
Fixed everything that requires locale stuff to check CF_NO_LOCALE.

/*
 * libtu/symlist.c
 *
 * Copyright (c) Tuomo Valkonen 1999-2004. 
 *
 * You may distribute and modify this library under the terms of either
 * the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
 */

#include "obj.h"
#include "symlist.h"
#include "types.h"
#include "dlist.h"
#include "misc.h"


static void free_node(Symlist **symlist, Symlist *node)
{
    UNLINK_ITEM(*symlist, node, next, prev);
    free(node);
}


bool symlist_insert(Symlist **symlist, void *symbol)
{
    Symlist *node;
    
    if(symbol==NULL)
        return FALSE;
    
    node=ALLOC(Symlist);
    
    if(node==NULL)
        return FALSE;
        
    node->symbol=symbol;
    
    LINK_ITEM_FIRST(*symlist, node, next, prev);
    
    return TRUE;
}


void symlist_remove(Symlist **symlist, void *symbol)
{
    Symlist *node=*symlist;
    
    while(node!=NULL){
        if(node->symbol==symbol){
            free_node(symlist, node);
            return;
        }
        node=node->next;
    }
}


void symlist_clear(Symlist **symlist)
{
    while(*symlist!=NULL)
        free_node(symlist, *symlist);
}


/* Warning: not thread-safe */


static Symlist *iter_next=NULL;


void *symlist_init_iter(Symlist *symlist)
{
    if(symlist==NULL){
        iter_next=NULL;
        return NULL;
    }
    
    iter_next=symlist->next;
    return symlist->symbol;
}


void *symlist_iter()
{
    Symlist *ret;
    
    if(iter_next==NULL)
        return NULL;
    
    ret=iter_next;
    iter_next=iter_next->next;
    
    return ret->symbol;
}

mercurial