Richard Alpe | f043759 | 2015-05-07 15:07:36 +0200 | [diff] [blame] | 1 | /* |
| 2 | * tipc. TIPC utility frontend. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; either version |
| 7 | * 2 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * Authors: Richard Alpe <richard.alpe@ericsson.com> |
| 10 | */ |
| 11 | |
| 12 | #include <stdio.h> |
| 13 | #include <stdlib.h> |
| 14 | #include <getopt.h> |
| 15 | #include <unistd.h> |
| 16 | |
| 17 | #include "bearer.h" |
| 18 | #include "link.h" |
| 19 | #include "nametable.h" |
| 20 | #include "socket.h" |
| 21 | #include "media.h" |
| 22 | #include "node.h" |
| 23 | #include "cmdl.h" |
| 24 | |
| 25 | int help_flag; |
| 26 | |
| 27 | static void about(struct cmdl *cmdl) |
| 28 | { |
| 29 | fprintf(stderr, |
| 30 | "Transparent Inter-Process Communication Protocol\n" |
| 31 | "Usage: %s [OPTIONS] COMMAND [ARGS] ...\n" |
| 32 | "\n" |
| 33 | "Options:\n" |
| 34 | " -h, --help \t\tPrint help for last given command\n" |
| 35 | "\n" |
| 36 | "Commands:\n" |
| 37 | " bearer - Show or modify bearers\n" |
| 38 | " link - Show or modify links\n" |
| 39 | " media - Show or modify media\n" |
| 40 | " nametable - Show nametable\n" |
| 41 | " node - Show or modify node related parameters\n" |
| 42 | " socket - Show sockets\n", |
| 43 | cmdl->argv[0]); |
| 44 | } |
| 45 | |
| 46 | int main(int argc, char *argv[]) |
| 47 | { |
| 48 | int i; |
| 49 | int res; |
| 50 | struct cmdl cmdl; |
| 51 | const struct cmd cmd = {"tipc", NULL, about}; |
| 52 | struct option long_options[] = { |
| 53 | {"help", no_argument, 0, 'h'}, |
| 54 | {0, 0, 0, 0} |
| 55 | }; |
| 56 | const struct cmd cmds[] = { |
| 57 | { "bearer", cmd_bearer, cmd_bearer_help}, |
| 58 | { "link", cmd_link, cmd_link_help}, |
| 59 | { "media", cmd_media, cmd_media_help}, |
| 60 | { "nametable", cmd_nametable, cmd_nametable_help}, |
| 61 | { "node", cmd_node, cmd_node_help}, |
Richard Alpe | f043759 | 2015-05-07 15:07:36 +0200 | [diff] [blame] | 62 | { "socket", cmd_socket, cmd_socket_help}, |
| 63 | { NULL } |
| 64 | }; |
| 65 | |
| 66 | do { |
| 67 | int option_index = 0; |
| 68 | |
| 69 | i = getopt_long(argc, argv, "h", long_options, &option_index); |
| 70 | |
| 71 | switch (i) { |
| 72 | case 'h': |
| 73 | /* |
| 74 | * We want the help for the last command, so we flag |
| 75 | * here in order to print later. |
| 76 | */ |
| 77 | help_flag = 1; |
| 78 | break; |
| 79 | case -1: |
| 80 | /* End of options */ |
| 81 | break; |
| 82 | default: |
| 83 | /* Invalid option, error msg is printed by getopts */ |
| 84 | return 1; |
| 85 | } |
| 86 | } while (i != -1); |
| 87 | |
| 88 | cmdl.optind = optind; |
| 89 | cmdl.argc = argc; |
| 90 | cmdl.argv = argv; |
| 91 | |
| 92 | if ((res = run_cmd(NULL, &cmd, cmds, &cmdl, NULL)) != 0) |
| 93 | return 1; |
| 94 | |
| 95 | return 0; |
| 96 | } |