Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Examples  

replacer.c File Reference

Go to the source code of this file.

Data Structures

struct  couple
 Type of the elements strored into the hash table. More...


Defines

#define INIT_DYNAMIC_STRING   100
 Initial size for a dynamic string.

#define HASH_TABLE_ENTRIES   150
 Number of linked lists for the hash tables used to store the couples (tags, values).


Functions

int hash_function (const void *key)
 Hash function used by the hash table to hash the tags.

void free_user_data (void *d)
 Function used to free memory allocated for the elements of the hash table.

int compare_user_data (const void *d1, const void *d2)
 Function used to compare two elements of the hash table (two tags).

char * replace_tags (char *text, char **tags, char **values, int nb_tags)
 Replace tags by their values in a text.


Variables

char ** txt_tokens
 Array of strings. This variable is defined in the parser's module (see file 'replacer.lex'). It will contain all the tokens extracted by the parser.

size_t nb_tokens
 Number of tokens in the array 'txt_tokens'. This variable is defined in the parser's module (see file 'replacer.lex').


Detailed Description

This file contains the implementation of the Search / Replace API.

Definition in file replacer.c.


Function Documentation

int compare_user_data const void *    d1,
const void *    d2
[static]
 

Function used to compare two elements of the hash table (two tags).

Parameters:
d1 First element to compare.
d2 Second element to compare.
Returns:
The function return 1 if d1 == d2, 0 otherwise.
Examples:
test_hash_table.c.

Definition at line 94 of file replacer.c.

References couple::key.

Referenced by replace_tags().

void free_user_data void *    d [static]
 

Function used to free memory allocated for the elements of the hash table.

Parameters:
d Pointer to a structure couple to be freed.
Examples:
test_hash_table.c.

Definition at line 79 of file replacer.c.

Referenced by replace_tags().

int hash_function const void *    key [static]
 

Hash function used by the hash table to hash the tags.

Parameters:
key Pointer to a structure couple that contains the couple (tag, value).
Returns:
The function returns an integer.
Warning:
Make sure that the structure pointed by key has been initialized!
Examples:
test_hash_table.c.

Definition at line 60 of file replacer.c.

References couple::key.

Referenced by replace_tags().

char* replace_tags char *    text,
char **    tags,
char **    values,
int    nb_tags
 

Replace tags by their values in a text.

Parameters:
text Pointer to a zero terminated string of characters. This string contains the original text.
tags Pointer to an array of tags (that will be searched in 'text').
values Pointer to an array of values (a tag is replaced by a value). Please note that: 'tags[i]' will be replaced by 'values[i]'.
nb_tags Number of elements in the arrays 'text' and 'tags'.
Returns:
The function returns a pointer to a zero terminated string of characters that represents the final text. If the function could not allocate memory, then the returned value is NULL.
Warning:
  • The returned string of characters has been allocated within the function. Therefore you must free it yourself (using free()).
  • This function is NOT REENTRANT, DO NOT use it with threads!
  • This function works in memory, so if the input text is too large, the function may fail because the process is running out of memory. In this case the function returns the value NULL. If you get NULL, you should abort the process execution, because the function does not clean the memory allocated...
Examples:
test_replacer_final.c.

Definition at line 127 of file replacer.c.

References chtbl_destroy(), chtbl_init(), chtbl_insert(), chtbl_lookup(), compare_user_data(), dstring_add(), dstring_free(), dstring_get_data(), dstring_init(), free_user_data(), hash_function(), HASH_TABLE_ENTRIES, INIT_DYNAMIC_STRING, couple::key, nb_tokens, txt_tokens, and couple::value.


Generated on Thu Apr 3 16:23:46 2003 for Common_C_libraries by doxygen1.3-rc1