udphole

Basic UDP wormhole proxy
git clone git://git.finwo.net/app/udphole
Log | Files | Refs | README | LICENSE

list_commands.c (765B)


      1 #include "list_commands.h"
      2 
      3 #include <stdio.h>
      4 #include <string.h>
      5 
      6 #include "../common.h"
      7 
      8 int cli_cmd_list_commands(int argc, const char **argv) {
      9   (void)argc;
     10   (void)argv;
     11   int                 len;
     12   int                 name_longest = 0;
     13   struct cli_command *cmd          = cli_commands;
     14   while (cmd) {
     15     len = (int)strlen(cmd->cmd);
     16     if (len > name_longest) {
     17       name_longest = len;
     18     }
     19     cmd = cmd->next;
     20   }
     21 
     22   int width    = cli_get_output_width(80);
     23   int left_col = name_longest + 3;
     24 
     25   printf("\n");
     26   printf("Available commands:\n");
     27   cmd = cli_commands;
     28   while (cmd) {
     29     printf("\n  %*s ", name_longest, cmd->cmd);
     30     cli_print_wrapped(stdout, cmd->desc, width, left_col);
     31     cmd = cmd->next;
     32   }
     33   printf("\n\n");
     34 
     35   return 0;
     36 }