1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- #include <stdlib.h>
- #include <string.h>
- #include "utils/Structs.h"
- void stAddVariable(Struct* st, const char* name, DataType type) {
- int index = st->amount;
- st->amount++;
- st->vars = realloc(st->vars, sizeof(StructVariable) * st->amount);
- st->vars[index].name = name;
- st->vars[index].type = type;
- }
- void stsInit(Structs* sts) {
- sts->capacity = 4;
- sts->entries = 0;
- sts->data = malloc(sizeof(Struct) * sts->capacity);
- }
- void stsDelete(Structs* sts) {
- for(int i = 0; i < sts->entries; i++) {
- free(sts->data[i].vars);
- }
- free(sts->data);
- }
- Struct* stsSearch(Structs* sts, const char* name) {
- for(int i = 0; i < sts->entries; i++) {
- if(strcmp(sts->data[i].name, name) == 0) {
- return sts->data + i;
- }
- }
- return NULL;
- }
- Struct* stsAdd(Structs* sts, const char* name) {
- if(sts->entries >= sts->capacity) {
- sts->capacity *= 2;
- sts->data = realloc(sts->data, sizeof(Struct) * sts->capacity);
- }
- int index = sts->entries++;
- sts->data[index].id = index;
- sts->data[index].amount = 0;
- sts->data[index].name = name;
- sts->data[index].vars = NULL;
- return sts->data + index;
- }
|