You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
109 lines
2.6 KiB
109 lines
2.6 KiB
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include "../includes/include.h"
|
|
|
|
/**
|
|
* Version: 0.2
|
|
*
|
|
* adds var to hashmap if its not already set
|
|
* else it will update the var with provided values.
|
|
* @return null
|
|
* @param string for var name
|
|
*
|
|
*/
|
|
void add_var(char *p_name, variable_values *p_values, map_void_t* p_var_map)
|
|
{
|
|
//if variable map is null
|
|
if(!p_var_map)
|
|
{
|
|
p_var_map = malloc(sizeof(map_void_t));
|
|
map_init(&*((map_void_t *) p_var_map));
|
|
}
|
|
map_set(&*((map_void_t* ) p_var_map), p_name, &*p_values);
|
|
}
|
|
|
|
/**
|
|
* returns variables values from hashmap
|
|
*
|
|
* @see [variable_values]
|
|
* @see [char *string]
|
|
* @return [variable_values] containing variables data
|
|
* @param [char *string] Variable name.
|
|
*
|
|
*/
|
|
variable_values *get_value(char *p_name, map_void_t* p_var_map)
|
|
{
|
|
return *map_get(&*((map_void_t* ) p_var_map), p_name);
|
|
}
|
|
|
|
/**
|
|
*
|
|
* This makes an integer varible and adds it to the linked list of
|
|
* vars.
|
|
* @return the head of the linked list which just points to all of the vars
|
|
*
|
|
*/
|
|
variable* make_variable_int(char *p_name, int value)
|
|
{
|
|
variable *p = malloc(sizeof(variable));
|
|
variable_values *int_value = malloc(sizeof(variable_values));
|
|
int_value->type = VAR_INT;
|
|
int_value->_int = value;
|
|
p->name = p_name;
|
|
p->value = int_value;
|
|
return p;
|
|
}
|
|
|
|
|
|
/**
|
|
* makes a variable of type double.
|
|
* @param name of the varible.
|
|
* @param double data to be stored in the variable.
|
|
*/
|
|
variable* make_variable_double(char *p_name, double value)
|
|
{
|
|
variable *new_var = malloc(sizeof(variable));
|
|
variable_values *double_value = malloc(sizeof(variable_values));
|
|
double_value->type = VAR_DOUBLE;
|
|
double_value->_double = value;
|
|
new_var->name = p_name;
|
|
new_var->value = double_value;
|
|
return new_var;
|
|
}
|
|
|
|
/**
|
|
* makes a char variable.
|
|
*
|
|
* @param name of the variable.
|
|
* @param char value to be stored.
|
|
*/
|
|
variable* make_variable_char(char *p_name, char value)
|
|
{
|
|
variable *p = malloc(sizeof(variable));
|
|
variable_values *char_value = malloc(sizeof(variable_values));
|
|
char_value->type = VAR_CHAR;
|
|
char_value->_char = value;
|
|
p->name = p_name;
|
|
p->value = char_value;
|
|
return p;
|
|
}
|
|
|
|
/**
|
|
* makes a variable of type string.
|
|
*
|
|
* @param name of the variable.
|
|
* @param value to be stored.
|
|
*/
|
|
variable* make_variable_string(char *p_name, char *value)
|
|
{
|
|
variable *p = malloc(sizeof(variable));
|
|
variable_values *string_value = malloc(sizeof(variable_values));
|
|
string_value->type = VAR_STRING;
|
|
string_value->_string = value;
|
|
p->name = p_name;
|
|
p->value = string_value;
|
|
return p;
|
|
}
|