CWB
Functions | Variables
macros.c File Reference
#include "globals.h"
#include "macros.h"
#include <time.h>

Functions

void * cl_malloc (size_t bytes)
 Safely allocates memory malloc-style. More...
 
void * cl_calloc (size_t nr_of_elements, size_t element_size)
 Safely allocates memory calloc-style. More...
 
void * cl_realloc (void *block, size_t bytes)
 Safely reallocates memory. More...
 
char * cl_strdup (const char *string)
 Safely duplicates a string. More...
 
void cl_set_rng_state (unsigned int i1, unsigned int i2)
 Restores the state of the CL-internal random number generator. More...
 
void cl_get_rng_state (unsigned int *i1, unsigned int *i2)
 Reads current state of CL-internal random number generator. More...
 
void cl_set_seed (unsigned int seed)
 Initialises the CL-internal random number generator. More...
 
void cl_randomize (void)
 Initialises the CL-internal random number generator from the current system time. More...
 
unsigned int cl_random (void)
 Gets a random number. More...
 
double cl_runif (void)
 Gets a random number in the range [0,1] with uniform distribution. More...
 
void progress_bar_child_mode (int on_off)
 Activates or deactivates child (simple) mode for progress_bar. More...
 
void progress_bar_clear_line (void)
 Clears the progress bar currently displayed on the terminal. More...
 
void progress_bar_message (int pass, int total, char *message)
 Prints a new progress bar (passes-plus-message format). More...
 
void progress_bar_percentage (int pass, int total, int percentage)
 Prints a new progress bar (passes-plus-percentage-done format). More...
 
void ilist_print_blanks (int n)
 
void start_indented_list (int linewidth, int tabsize, int indent)
 Begins the printing of a line in an indented 'tabularised' list. More...
 
void print_indented_list_br (char *label)
 Starts a new line in an indented 'tabularised' list. More...
 
void print_indented_list_item (char *string)
 Prints an item into an ongoing indented list. More...
 
void end_indented_list (void)
 Ends the printing of a line in an indented 'tabularised' list. More...
 

Variables

static unsigned int RNG_I1 =1234
 
static unsigned int RNG_I2 =5678
 
int progress_bar_pass = 1
 
int progress_bar_total = 1
 
int progress_bar_simple = 0
 
int ilist_cursor
 
int ilist_linewidth
 
int ilist_tab
 
int ilist_indent
 

Function Documentation

void* cl_calloc ( size_t  nr_of_elements,
size_t  element_size 
)

Safely allocates memory calloc-style.

See also
cl_malloc
Parameters
nr_of_elementsNumber of elements to allocate
element_sizeSize of each element
Returns
Pointer to the block of allocated memory

Referenced by alloc_mblob(), cl_new_int_list(), cl_new_lexhash(), cl_new_ngram_hash(), cl_new_string_list(), cl_ngram_hash_stats(), cl_regex2id(), compute_code_lengths(), do_translate(), evaluate_target(), range_declare(), and validate_revcorp().

void cl_get_rng_state ( unsigned int *  i1,
unsigned int *  i2 
)

Reads current state of CL-internal random number generator.

The (unsigned, 32-bit) integers currently held in RNG_I1 and RNG_I2 are written to the two memory locations supplied as arguments.

Parameters
i1Target location for the value of RNG_I1
i2Target location for the value of RNG_I2

References RNG_I1, and RNG_I2.

void* cl_malloc ( size_t  bytes)

Safely allocates memory malloc-style.

This function allocates a block of memory of the requested size, and does a test for malloc() failure which aborts the program and prints an error message if the system is out of memory. So the return value of this function can be used without further testing for malloc() failure.

Parameters
bytesNumber of bytes to allocate
Returns
Pointer to the block of allocated memory

Referenced by accessible(), add_corpus_property(), add_grant_to_last_user(), add_host_to_list(), add_hosts_in_subnet_to_list(), add_tabular_pattern(), add_user_to_list(), AddNameToAL(), alloc_mblob(), attach_subcorpus(), binsert_g(), check_alignment_constraints(), cl_autostring_new(), cl_id2cpos_oldstyle(), cl_idlist2cpos_oldstyle(), cl_lexhash_add(), cl_make_set(), cl_new_int_list(), cl_new_lexhash(), cl_new_ngram_hash(), cl_new_regex(), cl_new_string_list(), cl_ngram_hash_add(), cl_ngram_hash_get_entries(), cl_open_stream(), cl_path_registry_quote(), cl_regex2id(), cl_string_latex2iso(), cl_string_qsort_compare(), combine_subcorpus_spec(), compute_code_lengths(), compute_grouping(), ComputeGroupExternally(), ComputeGroupInternally(), cqi_read_bool_list(), cqi_read_byte_list(), cqi_read_int_list(), cqi_read_string(), cqi_read_string_list(), cqp_run_mu_query(), cqp_run_tab_query(), creat_rev_corpus(), creat_rev_corpus_idx(), create_bitfield(), define_macro(), do_cqi_cqp_query(), do_flagged_re_variable(), do_MeetStatement(), do_mval_string(), do_undump(), do_UnionStatement(), do_XMLTag(), duplicate_corpus(), encode_generate_registry_file(), encode_scan_directory(), evaltree2searchstr(), find_corpus_registry(), FormState(), get_leaf_value(), get_matched_corpus_positions(), GetVariableItems(), GetVariableStrings(), initialize_cqp(), labellookup(), list_macros(), LookUp(), macro_iterator_next_prototype(), MacroAddSegment(), MacroHashAdd(), main(), make_attribute_hash(), make_first_tabular_pattern(), make_temp_corpus(), MakeExp(), MakeMacroHash(), mallocfile(), matchfirstpattern(), meet_mu(), mval_string_conversion(), new_reftab(), new_symbol_table(), new_tabulation_item(), NewAttributeList(), NewContextDescriptor(), NewVariable(), open_input_stream(), OptimizeStringConstraint(), parse_macro_name(), PushInputBuffer(), RangeSetop(), RangeSort(), read_mapping(), ReadHCD(), regex2dfa(), set_corpus_matchlists(), set_target(), Setop(), show_corpora_files1(), simulate_dfa(), SL_insert_after_point(), SortExternally(), SortSubcorpus(), SortSubcorpusRandomize(), Store(), strdupto(), try_optimization(), and VariableAddItem().

unsigned int cl_random ( void  )

Gets a random number.

Part of the CL-internal random number generator.

Returns
The random number, an unsigned 32-bit integer with uniform distribution

References RNG_I1, and RNG_I2.

Referenced by cl_runif(), and SortSubcorpusRandomize().

void cl_randomize ( void  )

Initialises the CL-internal random number generator from the current system time.

References cl_set_seed().

Referenced by initialize_cqp(), and main().

void* cl_realloc ( void *  block,
size_t  bytes 
)

Safely reallocates memory.

See also
cl_malloc
Parameters
blockPointer to the block to be reallocated
bytesNumber of bytes to allocate to the resized memory block @ return Pointer to the block of reallocated memory

Referenced by AddBuf(), AddEquiv(), AddState(), binsert_g(), cl_autostring_concat(), cl_autostring_copy(), cl_autostring_reclaim_mem(), cl_id2cpos_oldstyle(), cl_int_list_set(), cl_string_list_set(), ComputeGroupExternally(), ComputeGroupInternally(), load_macro_file(), MakeExp(), meet_mu(), NewVariable(), PushQ(), RangeSetop(), read_mapping(), Setop(), and VariableAddItem().

double cl_runif ( void  )

Gets a random number in the range [0,1] with uniform distribution.

Part of the CL-internal random number generator.

Returns
The generated random number.

References cl_random().

Referenced by do_cqi_cqp_query(), and do_reduce().

void cl_set_rng_state ( unsigned int  i1,
unsigned int  i2 
)

Restores the state of the CL-internal random number generator.

Parameters
i1The value to set the first RNG integer to (if zero, resets it to 1)
i2The value to set the second RNG integer to (if zero, resets it to 1)

References RNG_I1, and RNG_I2.

Referenced by cl_set_seed(), and SortSubcorpusRandomize().

void cl_set_seed ( unsigned int  seed)

Initialises the CL-internal random number generator.

Parameters
seedA single 32bit number to use as the seed

References cl_set_rng_state().

Referenced by cl_randomize().

char* cl_strdup ( const char *  string)
void end_indented_list ( void  )

Ends the printing of a line in an indented 'tabularised' list.

References ilist_cursor.

Referenced by list_macros(), printSingleVariableValue(), and show_corpora_files1().

void ilist_print_blanks ( int  n)
void print_indented_list_br ( char *  label)

Starts a new line in an indented 'tabularised' list.

Used when a line break is needed within an indented list; this function starts a new line (as
in HTML), an showing optional label in indentation.

Parameters
labelThe optional label, if this is NULL, no label is used; if it is a string, then the string appears on the far left hand side.

References ilist_cursor, ilist_indent, and ilist_print_blanks().

Referenced by list_macros(), print_indented_list_item(), and show_corpora_files1().

void print_indented_list_item ( char *  string)

Prints an item into an ongoing indented list.

Parameters
stringThe string to print as a list item.

References ilist_cursor, ilist_linewidth, ilist_tab, and print_indented_list_br().

Referenced by describecorpus_show_attribute_names(), list_macros(), printSingleVariableValue(), and show_corpora_files1().

void progress_bar_child_mode ( int  on_off)

Activates or deactivates child (simple) mode for progress_bar.

Parameters
on_offThe new setting for the progress bar mode, where 1 = simple messages ON STDOUT, 0 = pretty-printed messages with carriage returns ON STDERR

References progress_bar_simple.

Referenced by parse_options().

void progress_bar_clear_line ( void  )

Clears the progress bar currently displayed on the terminal.

Note: assumes line width of 60 characters.

References progress_bar_simple.

Referenced by ComputeGroupInternally(), do_subset(), evaluate_target(), prepare_do_subset(), and simulate_dfa().

void progress_bar_message ( int  pass,
int  total,
char *  message 
)

Prints a new progress bar (passes-plus-message format).

The progress bar printed is as follows:

[pass {pass} of {total}: {message}]

If total is equal to zero, the function uses the pass and total values from the last call of this function.

References progress_bar_pass, progress_bar_simple, and progress_bar_total.

Referenced by ComputeGroupInternally(), evaluate_subset(), evaluate_target(), prepare_do_subset(), progress_bar_percentage(), and simulate_dfa().

void progress_bar_percentage ( int  pass,
int  total,
int  percentage 
)

Prints a new progress bar (passes-plus-percentage-done format).

The progress bar printed is as follows:

[pass {pass} of {total}: {percentage}% complete]

If total is equal to zero, the function uses the pass and total values from the last call of this function.

References progress_bar_message().

Referenced by ComputeGroupInternally(), evaluate_subset(), evaluate_target(), and simulate().

void start_indented_list ( int  linewidth,
int  tabsize,
int  indent 
)

Begins the printing of a line in an indented 'tabularised' list.

This function begins the printing of the first line of an indented If any of the three parameters are zero, this function uses the internal default value for that parameter instead (ILIST macro constants).

Parameters
linewidthWidth of the line (in characters)
tabsizeTabulator steps (in characters)
indentIndentation of the list from left margin (in characters)

References ilist_cursor, ILIST_INDENT, ilist_indent, ILIST_LINEWIDTH, ilist_linewidth, ilist_print_blanks(), ILIST_TAB, and ilist_tab.

Referenced by describecorpus_show_attribute_names(), list_macros(), printSingleVariableValue(), and show_corpora_files1().

Variable Documentation

int ilist_cursor
int ilist_indent
int ilist_linewidth
int ilist_tab
int progress_bar_pass = 1

Referenced by progress_bar_message().

int progress_bar_simple = 0
int progress_bar_total = 1

Referenced by progress_bar_message().

unsigned int RNG_I1 =1234
static
unsigned int RNG_I2 =5678
static