Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages

pdl_variable.c File Reference

Implementation of the pdl variables. More...

#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lcmaps_log.h"
#include "pdl_variable.h"
#include "pdl_rule.h"

Go to the source code of this file.

Functions

BOOL _add_variable (const record_t *name, const record_t *value)
var_tfind_variable (const char *name)
var_tdetect_loop (const char *name, const char *value)
void add_variable (record_t *name, record_t *value)
void free_variables (void)
void reduce_to_var (const char **name, rule_type_t rule_type)
var_tget_variables (void)
void show_variables (void)


Detailed Description

Implementation of the pdl variables.

Not all functions defined in this file are accessible to everyone. A subset is used by the pdl variable functions themselves. For the list API functions look in pdl_variables.h.

Author:
G.M. Venekamp (venekamp@nikhef.nl)
Version:
Revision
1.12
Date:
Date
2005/03/01 17:05:10

Definition in file pdl_variable.c.


Function Documentation

BOOL _add_variable const record_t name,
const record_t value
 

Actual implementation of the add_variable call. When the variable has been added the call returns TRUE, otherwise its FALSE. There can be several reasons for failure:

  • Variable allready exists;
  • Variable refers to itself through a loop;
  • No more resources to allocate for variable.

Parameters:
name Name of the variable to be added.
value Value of the variable.
Returns:
TRUE in case the variable has been added, FALSE otherwise.

Definition at line 96 of file pdl_variable.c.

References detect_loop(), find_variable(), record_s::lineno, var_s::lineno, var_s::name, var_s::next, var_s::okay, PDL_ERROR, PDL_SAME, record_t, record_s::string, TRUE, var_s::value, var_t, and warning().

Referenced by add_variable().

void add_variable record_t name,
record_t value
 

Wrapper function for the _add_variable() function call. The hard work is done in the _add_variable() call. When that call succeeds only the resources allocated for holding the name and value parameters are freed, i.e. the structures name and value. In case the _add_variable() calls fails, the string that is contained within the name and value strutures is freed as well.

Parameters:
name Name of the variable.
value Value of the variable.

Definition at line 71 of file pdl_variable.c.

References _add_variable(), record_t, and record_s::string.

var_t * detect_loop const char *  name,
const char *  value
 

Try to detect a loop in the variable references. When e.g. a=b, b=c and c=a, then the call should detect a loop.

Parameters:
name Name of the variable.
value Value of the variable.
Returns:
0 if no loop was detected. When a loop is detected, the first variable in the loop is returned.

Definition at line 200 of file pdl_variable.c.

References find_variable(), var_s::next, var_s::value, and var_t.

Referenced by _add_variable().

var_t * find_variable const char *  name  ) 
 

Find a variable based on the variable name. This way the value of a variable can be retrieved.

Parameters:
name Name of the variable to find.
Returns:
Pointer to the corresponding variable, or 0 when not found.

Definition at line 175 of file pdl_variable.c.

References find_variable(), var_s::name, var_s::next, and var_t.

Referenced by _add_variable(), detect_loop(), find_variable(), and reduce_to_var().

void free_variables void   ) 
 

Free the resources allocated for the variables.

Definition at line 149 of file pdl_variable.c.

References var_s::name, var_s::next, var_s::value, and var_t.

Referenced by free_resources().

var_t* get_variables void   ) 
 

Get a list of all variables in the configure file.

Returns:
First variable of the list.

Definition at line 277 of file pdl_variable.c.

References var_t.

void reduce_to_var const char **  name,
rule_type_t  rule_type
 

Reduce the variable to its real value. When a variable has another variable as its value, the variable will be reduced to the value of the referring variable.

Parameters:
name Name of the variable to be reduced.
rule_type Type of the rule.
Returns:
Real value of the redunced variable.

Definition at line 247 of file pdl_variable.c.

References find_variable(), left_side, lineno, var_s::lineno, var_s::name, var_s::okay, PDL_WARNING, right_side, rule_t, STATE, TRUE, var_s::value, var_t, and warning().

Referenced by reduce_rule().

void show_variables void   ) 
 

Print all variables and their value as described in the configure file to stdout.

Definition at line 288 of file pdl_variable.c.

References lcmaps_log_debug(), var_s::name, var_s::next, var_s::value, and var_t.


Generated on Sun May 29 21:22:13 2005 for lcmaps by doxygen 1.3.5