sfinx

sphincs+ inspired signing utility
git clone git://git.finwo.net/app/sfinx
Log | Files | Refs | README

registry.c (792B)


      1 #include <stdlib.h>
      2 #include <string.h>
      3 #include "registry.h"
      4 
      5 #define CLI_MAX 32
      6 
      7 static const char *cli_names[CLI_MAX];
      8 static cli_main_fn cli_fns[CLI_MAX];
      9 static int cli_count = 0;
     10 
     11 void cli_register(const char *name, cli_main_fn fn) {
     12   if (cli_count >= CLI_MAX) return;
     13   cli_names[cli_count] = name;
     14   cli_fns[cli_count] = fn;
     15   cli_count++;
     16 }
     17 
     18 cli_main_fn cli_find(const char *name) {
     19   for (int i = 0; i < cli_count; i++) {
     20     if (!strcmp(cli_names[i], name)) return cli_fns[i];
     21   }
     22   return NULL;
     23 }
     24 
     25 char * cli_registered() {
     26   char *out;
     27   int len=1;
     28   for(int i=0; i<cli_count; i++) {
     29     if (i) len+=2;
     30     len+=strlen(cli_names[i]);
     31   }
     32   out = calloc(1, len);
     33   for(int i=0; i<cli_count; i++) {
     34     if (i) strcat(out, ", ");
     35     strcat(out, cli_names[i]);
     36   }
     37   return out;
     38 }