1234567891011121314151617181920212223242526272829303132333435363738 |
- #include <stdlib.h>
- #include <string.h>
- #include "FunctionMap.h"
- void fmInit(FunctionMap* fm) {
- fm->capacity = 16;
- fm->entries = 0;
- fm->data = malloc(sizeof(Function) * fm->capacity);
- }
- void fmDelete(FunctionMap* fm) {
- free(fm->data);
- }
- int fmSearchAddress(FunctionMap* fm, const char* name, int arguments) {
- for(int i = 0; i < fm->entries; i++) {
- if(fm->data[i].arguments == arguments && strcmp(fm->data[i].name, name) == 0) {
- return fm->data[i].address;
- }
- }
- return -1;
- }
- bool fmAdd(FunctionMap* fm, const char* name, int arguments, int address) {
- if(fmSearchAddress(fm, name, arguments) != -1) {
- return false;
- }
- if(fm->entries >= fm->capacity) {
- fm->capacity *= 2;
- fm->data = realloc(fm->data, sizeof(Function) * fm->capacity);
- }
- int index = fm->entries++;
- fm->data[index].name = name;
- fm->data[index].arguments = arguments;
- fm->data[index].address = address;
- return true;
- }
|