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

113 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 *pName, variable_values *pValues, map_void_t* pVarMap) {
//if variable map is null
if(pVarMap == NULL) {
pVarMap = malloc(sizeof(map_void_t));
map_init(&*((map_void_t *) pVarMap));
}
map_set(&*((map_void_t* ) pVarMap), pName, &*pValues);
}
/**
* 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 *pName, map_void_t* pVarMap) {
return *map_get(&*((map_void_t* ) pVarMap), pName);
}
/**
*
* 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 *pName, 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 = pName;
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 *pName, 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 = pName;
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 *pName, 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 = pName;
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 *pName, 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 = pName;
p->value = string_value;
return p;
}