dbus: fix 64-bit compiler warnings
[platform/upstream/dbus.git] / tools / test-tool.c
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* dbus-test-tool - D-Bus swiss army knife
3  *
4  * Copyright © 2003 Philip Blundell <philb@gnu.org>
5  * Copyright © 2011 Nokia Corporation
6  * Copyright © 2014 Collabora Ltd.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  *
22  */
23
24 #include <config.h>
25 #include "test-tool.h"
26
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30
31 #include <dbus/dbus.h>
32
33 static struct {
34     const char *name;
35     int (*callback) (int, char **);
36 } subcommands[] = {
37       { "black-hole", dbus_test_tool_black_hole },
38       { "echo",       dbus_test_tool_echo },
39       { "spam",       dbus_test_tool_spam },
40       { NULL, NULL }
41 };
42
43 static void usage (int exit_with) _DBUS_GNUC_NORETURN;
44
45 static void
46 usage (int exit_with)
47 {
48   int i;
49
50   fprintf (stderr,
51            "Usage: dbus-test-tool SUBCOMMAND [OPTIONS]\n"
52            "\n"
53            "Known SUBCOMMANDs are:\n"
54            "\n"
55            );
56
57   for (i = 0; subcommands[i].name != NULL; i++)
58     {
59       fprintf (stderr, "- %s\n", subcommands[i].name);
60     }
61
62   fprintf (stderr,
63            "\n"
64            "For more information: dbus-test-tool SUBCOMMAND --help\n"
65            );
66
67   exit (exit_with);
68 }
69
70 int
71 main (int argc, char **argv)
72 {
73   int i;
74
75   if (argc < 2)
76     {
77       usage (2);
78     }
79
80   for (i = 0; subcommands[i].name != NULL; i++)
81     {
82       if (!strcmp (argv[1], subcommands[i].name))
83         return subcommands[i].callback (argc, argv);
84     }
85
86   usage (2);
87   return 2;
88 }