command.c 597 B

12345678910111213141516171819202122232425
  1. //
  2. // Created by 李建 on 2023/12/6.
  3. //
  4. #include "command.h"
  5. #include <string.h>
  6. #define MAX_COMMANDS 16
  7. static sparrow_command sparrowCommandList[MAX_COMMANDS];
  8. static int commandListIndex = 0;
  9. void register_sparrow_command(sparrow_command cmd) {
  10. if(commandListIndex > MAX_COMMANDS - 1) return;
  11. sparrowCommandList[commandListIndex++] = cmd;
  12. }
  13. sparrow_command * find_sparrow_command(char * name) {
  14. for (int i =0;i < commandListIndex; i++) {
  15. if(strcmp(sparrowCommandList[i].name, name) == 0) {
  16. return &sparrowCommandList[i];
  17. }
  18. }
  19. return NULL;
  20. }