first
This commit is contained in:
37
source/commands.c
Normal file
37
source/commands.c
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "commands.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define MIN_NOM_COMMANDS 30
|
||||
|
||||
#define COMMAND_SUCCESS 0;
|
||||
#define COMMAND_NOT_FOUND 1;
|
||||
#define COMMAND_FAILER 2;
|
||||
|
||||
struct nomi_command __commands__[MIN_NOM_COMMANDS];
|
||||
int __command_count__ = 0;
|
||||
|
||||
void InitCommands() {
|
||||
for(int i = 0; i < MIN_NOM_COMMANDS; i++) {
|
||||
__commands__[i] = (struct nomi_command){0,""};
|
||||
}
|
||||
}
|
||||
|
||||
void AddCommand(nomi_command_func func, const char* command) {
|
||||
if(__command_count__ < MIN_NOM_COMMANDS) {
|
||||
__commands__[__command_count__] = (struct nomi_command) {
|
||||
.func = func,
|
||||
.command = command
|
||||
};
|
||||
__command_count__++;
|
||||
}
|
||||
}
|
||||
unsigned char CommandRun(char* command, int size) {
|
||||
for(int i = 0; i < MIN_NOM_COMMANDS; i++) {
|
||||
if(!strcmp(command, __commands__[i].command)) {
|
||||
__commands__[i].func(&__commands__[i]);
|
||||
return COMMAND_SUCCESS;
|
||||
}
|
||||
}
|
||||
return COMMAND_NOT_FOUND;
|
||||
}
|
||||
Reference in New Issue
Block a user