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.
eon/vars/vars.c

109 lines
2.6 KiB

5 years ago
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
5 years ago
#include "../includes/include.h"
5 years ago
/**
* 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)
{
5 years ago
//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));
5 years ago
}
map_set(&*((map_void_t* ) p_var_map), p_name, &*p_values);
5 years ago
}
/**
* returns variables values from hashmap
*
5 years ago
* @see [variable_values]
5 years ago
* @see [char *string]
5 years ago
* @return [variable_values] containing variables data
5 years ago
* @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);
5 years ago
}
/**
*
* 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)
{
5 years ago
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;
5 years ago
p->value = int_value;
5 years ago
return p;
}
5 years ago
/**
* 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)
{
5 years ago
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;
5 years ago
new_var->value = double_value;
return new_var;
5 years ago
}
5 years ago
/**
* makes a char variable.
*
* @param name of the variable.
* @param char value to be stored.
*/
variable* make_variable_char(char *p_name, char value)
{
5 years ago
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;
5 years ago
p->value = char_value;
return p;
5 years ago
}
5 years ago
/**
* 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)
{
5 years ago
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;
5 years ago
p->value = string_value;
5 years ago
return p;
}