lnvis

nanovg lightning network visualizer
git clone git://jb55.com/lnvis
Log | Files | Refs | README | LICENSE

commander.h (1380B)


      1 
      2 //
      3 // commander.h
      4 //
      5 // Copyright (c) 2012 TJ Holowaychuk <tj@vision-media.ca>
      6 //
      7 
      8 #ifndef COMMANDER_H
      9 #define COMMANDER_H
     10 
     11 /*
     12  * Max options that can be defined.
     13  */
     14 
     15 #ifndef COMMANDER_MAX_OPTIONS
     16 #define COMMANDER_MAX_OPTIONS 32
     17 #endif
     18 
     19 /*
     20  * Max arguments that can be passed.
     21  */
     22 
     23 #ifndef COMMANDER_MAX_ARGS
     24 #define COMMANDER_MAX_ARGS 32
     25 #endif
     26 
     27 /*
     28  * Command struct.
     29  */
     30 
     31 struct command;
     32 
     33 /*
     34  * Option callback.
     35  */
     36 
     37 typedef void (* command_callback_t)(struct command *self);
     38 
     39 /*
     40  * Command option.
     41  */
     42 
     43 typedef struct {
     44   int optional_arg;
     45   int required_arg;
     46   char *argname;
     47   char *large;
     48   const char *small;
     49   const char *large_with_arg;
     50   const char *description;
     51   command_callback_t cb;
     52 } command_option_t;
     53 
     54 /*
     55  * Command.
     56  */
     57 
     58 typedef struct command {
     59   void *data;
     60   const char *usage;
     61   const char *arg;
     62   const char *name;
     63   const char *version;
     64   int option_count;
     65   command_option_t options[COMMANDER_MAX_OPTIONS];
     66   int argc;
     67   char *argv[COMMANDER_MAX_ARGS];
     68   char **nargv;
     69 } command_t;
     70 
     71 // prototypes
     72 
     73 void
     74 command_init(command_t *self, const char *name, const char *version);
     75 
     76 void
     77 command_free(command_t *self);
     78 
     79 void
     80 command_help(command_t *self);
     81 
     82 void
     83 command_option(command_t *self, const char *small, const char *large, const char *desc, command_callback_t cb);
     84 
     85 void
     86 command_parse(command_t *self, int argc, char **argv);
     87 
     88 #endif /* COMMANDER_H */