3 * \author written by Emmanuel Roullit emmanuel.roullit@gmail.com (c) 2012
7 /* __LICENSE_HEADER_BEGIN__ */
10 * Copyright (C) 2012 Emmanuel Roullit <emmanuel.roullit@gmail.com>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or (at
15 * your option) any later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
28 /* __LICENSE_HEADER_END__ */
36 #include <libdabba/macros.h>
38 static const char dabba_usage_string
[] = "dabba [--help] <command> [<args>]\n";
39 static const char dabba_more_info_string
[] =
40 "See 'dabba help <command>' for more info on a specific command.";
47 void show_usage(const struct option
const *opt
)
51 printf("%s", dabba_usage_string
);
54 while (opt
->name
!= NULL
) {
55 printf(" --%s", opt
->name
);
56 if (opt
->has_arg
== required_argument
)
58 else if (opt
->has_arg
== optional_argument
)
67 static inline void mput_char(char c
, uint32_t num
)
73 void help_unknown_cmd(const char const *cmd
)
76 printf("'%s' is not a dabba command. See 'dabba --help'.\n", cmd
);
79 static void list_common_cmds_help(void)
81 size_t i
, longest
= 0;
83 static struct cmdname_help common_cmds
[] = {
84 {"interface", "perform an interface related command"},
85 {"capture", "capture live traffic from an interface"}
88 for (i
= 0; i
< ARRAY_SIZE(common_cmds
); i
++) {
89 if (longest
< strlen(common_cmds
[i
].name
))
90 longest
= strlen(common_cmds
[i
].name
);
93 printf("The most commonly used dabba commands are:\n");
94 for (i
= 0; i
< ARRAY_SIZE(common_cmds
); i
++) {
95 printf(" %s ", common_cmds
[i
].name
);
96 mput_char(' ', longest
- strlen(common_cmds
[i
].name
));
97 printf("%s\n", common_cmds
[i
].help
);
103 * \param[in] argc Argument counter
104 * \param[in] argv Argument vector
105 * \return Returns 0 when the help could be printed, \c errno otherwise
107 * This function prints the basic dabba usage help message.
108 * Furthermore, it lists all available command.
111 int cmd_help(int argc
, const char **argv
)
116 if (argc
< 1 || !argv
[0]) {
117 printf("usage: %s\n\n", dabba_usage_string
);
118 list_common_cmds_help();
119 printf("\n%s\n", dabba_more_info_string
);
121 snprintf(help_name
, sizeof(help_name
), "dabba-%s", argv
[0]);
122 rc
= execlp("man", "man", help_name
, (char *)NULL
);
125 return rc
? errno
: rc
;