CWB
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "../cl/corpus.h"
#include "../cl/attributes.h"
#include "../cl/cdaccess.h"
#include "../cl/macros.h"
#include "variables.h"
#include "output.h"
#include "options.h"
Macros | |
#define | ITEM_REALLOC 8 |
How many pointers to allocate space for at one time to a Variable's ->items array. More... | |
#define | VARIABLE_REALLOC 16 |
How many pointers to allocate space for at one time to the global array VariableSpace. More... | |
Functions | |
Variable | FindVariable (char *varname) |
Finds the Variable object of the given name, if it exists in VariableSpace. More... | |
int | VariableItemMember (Variable v, char *item) |
Tests whether a given string exists within the variable. More... | |
int | VariableAddItem (Variable v, char *item) |
Adds a string to the variable. More... | |
int | VariableSubtractItem (Variable v, const char *item) |
Remove a string from a defined Variable. More... | |
int | VariableDeleteItems (Variable v) |
Deletes and frees up all memory associated with the strings contained by this variable. More... | |
int | DropVariable (Variable *vp) |
Deletes all the memory associated with a given variable. More... | |
Variable | NewVariable (char *varname) |
Creates a new Variable (set of strings) with the specified name within the global VariableSpace. More... | |
int | SetVariableValue (char *varName, char operator, char *varValues) |
Sets the value of a variable; returns true for success, false for failure. More... | |
void | variables_iterator_new (void) |
Resets the global variables iterator to the beginning of the global VariableSpace array. More... | |
Variable | variables_iterator_next (void) |
Gets the next Variable object from the variables iterator. More... | |
int | VerifyVariable (Variable v, Corpus *corpus, Attribute *attribute) |
Verify a variable for use with a given p-attribute of a given corpus. More... | |
static int | intcompare (const void *i, const void *j) |
comparison function for qsort() of id_list returned by GetVariableItems More... | |
int * | GetVariableItems (Variable v, Corpus *corpus, Attribute *attribute, int *nr_items) |
Get lexicon IDs of variable's strings in corpus.attribute lexicon. More... | |
char ** | GetVariableStrings (Variable v, int *nr_items) |
Returns an array of pointers to a variable's strings. More... | |
Variables | |
int | nr_variables = 0 |
Number of variables in VariableArray (exported) More... | |
Variable * | VariableSpace = NULL |
Global array of Variables (exported) More... | |
int | variables_iterator_idx |
#define ITEM_REALLOC 8 |
How many pointers to allocate space for at one time to a Variable's ->items array.
Referenced by VariableAddItem().
#define VARIABLE_REALLOC 16 |
How many pointers to allocate space for at one time to the global array VariableSpace.
Referenced by NewVariable().
int DropVariable | ( | Variable * | vp | ) |
Deletes all the memory associated with a given variable.
If the Variable is in VariableSpace, that slot in VariableSpace is emptied out.
vp | Note that this function takes a POINTER to a Variable object, not a Variable itself (even though Variable IS a pointer type)... allowing the object to be set to NULL once emptied out. |
References cl_free, _variable_buf::my_attribute, _variable_buf::my_corpus, _variable_buf::my_name, nr_variables, and VariableDeleteItems().
Variable FindVariable | ( | char * | varname | ) |
Finds the Variable object of the given name, if it exists in VariableSpace.
varname | The name of the variable required. |
References nr_variables.
Referenced by do_AddSubVariables(), do_flagged_re_variable(), do_printVariableSize(), do_PrintVariableValue(), do_SetVariableValue(), SetVariableValue(), and Varref2IDList().
Get lexicon IDs of variable's strings in corpus.attribute lexicon.
v | The Variable object. |
corpus | The corpus we are working with. |
attribute | The attribute against which to verify the Variable's items |
nr_items | This will be set to the number of integers in the returned array. |
References cl_malloc(), _variable_item::free, intcompare(), _variable_buf::items, _variable_item::ival, _variable_buf::nr_items, _variable_buf::nr_valid_items, and VerifyVariable().
Referenced by Varref2IDList().
char** GetVariableStrings | ( | Variable | v, |
int * | nr_items | ||
) |
Returns an array of pointers to a variable's strings.
Return value is NULL if there were no strings stored in the variable. The number of strings that were found is inserted into nr_items.
The array that is returned must be freed by the caller.
v | The Variable whose strings you want. |
nr_items | The number of strings found will be put here. |
References cl_malloc(), _variable_item::free, _variable_buf::items, _variable_buf::nr_items, and _variable_item::sval.
Referenced by do_AddSubVariables(), and do_flagged_re_variable().
|
static |
comparison function for qsort() of id_list returned by GetVariableItems
Referenced by GetVariableItems().
Variable NewVariable | ( | char * | varname | ) |
Creates a new Variable (set of strings) with the specified name within the global VariableSpace.
Returns NULL only if the variable string name was NULL.
References cl_malloc(), cl_realloc(), cl_strdup(), _variable_buf::items, _variable_buf::my_attribute, _variable_buf::my_corpus, _variable_buf::my_name, _variable_buf::nr_items, nr_variables, _variable_buf::valid, and VARIABLE_REALLOC.
Referenced by do_SetVariableValue(), and SetVariableValue().
int SetVariableValue | ( | char * | varName, |
char | operator, | ||
char * | varValues | ||
) |
Sets the value of a variable; returns true for success, false for failure.
References cl_close_stream(), cl_error(), CL_MAX_LINE_LENGTH, cl_open_stream(), CL_STREAM_MAGIC, CL_STREAM_MAGIC_NOPIPE, CL_STREAM_READ, cqpmessage(), Error, FindVariable(), insecure, NewVariable(), VariableAddItem(), VariableDeleteItems(), VariableSubtractItem(), and Warning.
Referenced by do_SetVariableValue().
int VariableAddItem | ( | Variable | v, |
char * | item | ||
) |
Adds a string to the variable.
References cl_malloc(), cl_realloc(), cl_strdup(), _variable_item::free, ITEM_REALLOC, _variable_buf::items, _variable_item::ival, _variable_buf::nr_items, _variable_item::sval, _variable_buf::valid, and VariableItemMember().
Referenced by do_AddSubVariables(), and SetVariableValue().
int VariableDeleteItems | ( | Variable | v | ) |
Deletes and frees up all memory associated with the strings contained by this variable.
The variable continues to exist, but is now empty.
References cl_free, _variable_buf::items, _variable_buf::nr_invalid_items, _variable_buf::nr_items, _variable_buf::nr_valid_items, _variable_item::sval, and _variable_buf::valid.
Referenced by DropVariable(), and SetVariableValue().
int VariableItemMember | ( | Variable | v, |
char * | item | ||
) |
Tests whether a given string exists within the variable.
References _variable_item::free, _variable_buf::items, _variable_buf::nr_items, and _variable_item::sval.
Referenced by VariableAddItem().
void variables_iterator_new | ( | void | ) |
Resets the global variables iterator to the beginning of the global VariableSpace array.
References variables_iterator_idx.
Referenced by do_PrintAllVariables().
Variable variables_iterator_next | ( | void | ) |
Gets the next Variable object from the variables iterator.
Returns NULL if the iterator has reached the end of the global VariableSpace array.
References nr_variables, and variables_iterator_idx.
Referenced by do_PrintAllVariables().
int VariableSubtractItem | ( | Variable | v, |
const char * | item | ||
) |
Remove a string from a defined Variable.
Identification of the string to remove is by bytewise identity.
v | The variable. |
item | The string to take out of the variable. |
References cl_free, _variable_item::free, _variable_buf::items, _variable_item::ival, _variable_buf::nr_items, _variable_item::sval, and _variable_buf::valid.
Referenced by do_AddSubVariables(), and SetVariableValue().
Verify a variable for use with a given p-attribute of a given corpus.
This associates the variable with the supplied corpus/attribute, plus checks the variable's strings against the relevant attribute lexicon.
References _Attribute::any, ATT_POS, TCorpus::charset, cl_free, cl_str2id(), cl_strdup(), cl_string_canonical(), cl_string_validate_encoding(), cqpmessage(), Error, _variable_item::free, _variable_buf::items, _variable_item::ival, _variable_buf::my_attribute, _variable_buf::my_corpus, _variable_buf::my_name, _variable_buf::nr_invalid_items, _variable_buf::nr_items, _variable_buf::nr_valid_items, TCorpus::registry_name, REQUIRE_NFC, _variable_item::sval, utf8, and _variable_buf::valid.
Referenced by GetVariableItems().
int nr_variables = 0 |
Number of variables in VariableArray (exported)
Referenced by DropVariable(), FindVariable(), NewVariable(), and variables_iterator_next().
int variables_iterator_idx |
Referenced by variables_iterator_new(), and variables_iterator_next().
Variable* VariableSpace = NULL |
Global array of Variables (exported)