CWB
Functions
attlist.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../cl/macros.h"
#include "../cl/corpus.h"
#include "../cl/attributes.h"
#include "attlist.h"

Functions

AttributeListNewAttributeList (int element_type)
 Creates a new AttributeList. More...
 
int DestroyAttributeList (AttributeList **list)
 Deletes an AttributeList object. More...
 
AttributeInfoAddNameToAL (AttributeList *list, char *name, int initial_status, int position)
 Adds a new AttributeInfo to an AttributeList object. More...
 
int RemoveNameFromAL (AttributeList *list, char *name)
 Deletes an AttributeInfo from the AttributeList. More...
 
int Unchain (AttributeList *list, AttributeInfo *this)
 Deletes an AttributeInfo from the AttributeList. More...
 
int NrOfElementsAL (AttributeList *list)
 Gets the number of entries in an AttributeList. More...
 
int MemberAL (AttributeList *list, char *name)
 Checks whether the AttributeList contains an entry with the given attribute name. More...
 
AttributeInfoFindInAL (AttributeList *list, char *name)
 Finds an entry in an AttribvuteList. More...
 
int RecomputeAL (AttributeList *list, Corpus *corpus, int init_status)
 Goes through an AttributeList, deletes entries for attributes that don't exist, and adds entries for those that do. More...
 
int VerifyList (AttributeList *list, Corpus *corpus, int remove_illegal_entries)
 Verifies an AttributeList. More...
 

Function Documentation

AttributeInfo* AddNameToAL ( AttributeList list,
char *  name,
int  initial_status,
int  position 
)

Adds a new AttributeInfo to an AttributeList object.

Parameters
listThe list to add to.
nameThe name of the Attribvute that this AttributeInfo refers to.
initial_statusInitial setting for the status member of the new AttributeInfo.
positionIf this is 1, the new AttributeInfo is added at the beginning of the list. If it is 0, it is added at the end of the list. Otherwise, this specifies a particular insertion position (the given number of steps down the linked list).
Returns
A pointer to the new AttributeInfo, or NULL for error.

References _attrbuf::attribute, cl_malloc(), cl_strdup(), _attlist::list, _attlist::list_valid, MemberAL(), _attrbuf::name, _attrbuf::next, _attrbuf::prev, and _attrbuf::status.

Referenced by compose_kwic_line(), ComputePrintStructures(), and RecomputeAL().

int DestroyAttributeList ( AttributeList **  list)

Deletes an AttributeList object.

Parameters
listAddress of the pointer to the list to delete.

References _attrbuf::attribute, cl_free, _attrbuf::name, _attrbuf::next, _attrbuf::prev, and _attrbuf::status.

Referenced by ComputePrintStructures(), execute_side_effects(), set_current_corpus(), and verify_context_descriptor().

AttributeInfo* FindInAL ( AttributeList list,
char *  name 
)

Finds an entry in an AttribvuteList.

Parameters
listThe list to search.
nameThe name of the element to search for.
Returns
Pointer to the AttributeInfo with the matching name, or NULL if the name was not found.

References _attlist::list.

Referenced by compose_kwic_line(), do_attribute_show(), MemberAL(), printAlignedStrings(), and set_current_corpus().

int MemberAL ( AttributeList list,
char *  name 
)

Checks whether the AttributeList contains an entry with the given attribute name.

Parameters
listThe list to search.
nameThe name of the element to search for.
Returns
Boolean: true if the element is found as a member of the list.

References FindInAL().

Referenced by AddNameToAL().

AttributeList* NewAttributeList ( int  element_type)

Creates a new AttributeList.

Parameters
element_typeWhat type of attribute is this? ATT_POS, ATT_STRUC, etc.
Returns
Pointer to the new AttributeList object.

References cl_malloc(), _attlist::element_type, _attlist::list, and _attlist::list_valid.

Referenced by compose_kwic_line(), ComputePrintStructures(), and update_context_descriptor().

int NrOfElementsAL ( AttributeList list)

Gets the number of entries in an AttributeList.

Parameters
listThe list to size up.
Returns
The number of elements in the list.

References _attlist::list, and _attrbuf::next.

int RecomputeAL ( AttributeList list,
Corpus corpus,
int  init_status 
)

Goes through an AttributeList, deletes entries for attributes that don't exist, and adds entries for those that do.

Note that all AttributeInfo entries are linked to the actual Attribute objects by this function.

Parameters
listThe AttributeList to recompute.
corpusThe corpus in which these attributes are found.
init_statusNot currently used.
Returns
Always 1.

References AddNameToAL(), _Attribute::any, _attrbuf::attribute, TCorpus::attributes, cl_free, _attlist::element_type, find_attribute, _attlist::list, _attlist::list_valid, _attrbuf::next, _attrbuf::prev, and _Attribute::type.

Referenced by update_context_descriptor().

int RemoveNameFromAL ( AttributeList list,
char *  name 
)

Deletes an AttributeInfo from the AttributeList.

Parameters
listThe list from which to delete.
nameThe name of the AttributeInfo to delete.
Returns
True if the attribute info was found and deleted; otherwise false.

References cl_free, _attlist::list, _attrbuf::next, and _attrbuf::prev.

Referenced by update_context_descriptor().

int Unchain ( AttributeList list,
AttributeInfo this 
)

Deletes an AttributeInfo from the AttributeList.

Unlike RemoveNameFromAL(), this function deletes an AttributeInfo known by its pointer, rather than one known by its name.

See also
RemoveNameFromAL
Parameters
listThe list from which to delete.
thisThe address (pointer) of the AttributeInfo to delete.
Returns
True if the attribute info was found and deleted; otherwise false.

References cl_free, _attlist::list, _attrbuf::next, and _attrbuf::prev.

int VerifyList ( AttributeList list,
Corpus corpus,
int  remove_illegal_entries 
)

Verifies an AttributeList.

Note that all AttributeInfo entries are linked to the actual Attribute objects by this function.

If the relevant attribute cannot be found, the entry is deleted iff remove_illegal_entries.

Parameters
listThe list to verify.
corpusThe corpus for which this list should be valid.
remove_illegal_entriesBoolean: see function description.
Returns
Boolean: true for all OK, false for error.

References _attrbuf::attribute, cl_free, _attlist::element_type, find_attribute, _attlist::list, _attlist::list_valid, _attrbuf::name, _attrbuf::next, and _attrbuf::prev.

Referenced by compose_kwic_line(), ComputePrintStructures(), and verify_context_descriptor().