2003-05-03 Havoc Pennington <hp@pobox.com>
[platform/upstream/dbus.git] / tools / dbus-launch.c
1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-launch.c  dbus-launch utility
3  *
4  * Copyright (C) 2003 Red Hat, Inc.
5  *
6  * Licensed under the Academic Free License version 1.2
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  *
22  */
23 #include <config.h>
24 #include <dbus/dbus.h>
25 #include <stdlib.h>
26 #include <unistd.h>
27 #include <fcntl.h>
28 #include <signal.h>
29 #include <sys/wait.h>
30 #include <errno.h>
31 #include <stdio.h>
32 #include <string.h>
33 #ifdef DBUS_BUILD_X11
34 #include <X11/Xlib.h>
35 #endif
36
37 static void
38 usage (void)
39 {
40   fprintf (stderr, "dbus-launch [--version] [--exit-with-session]\n");
41   exit (1);
42 }
43
44 static void
45 version (void)
46 {
47   printf ("D-BUS Message Bus Launcher %s\n"
48           "Copyright (C) 2003 Red Hat, Inc.\n"
49           "This is free software; see the source for copying conditions.\n"
50           "There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
51           VERSION);
52   exit (0);
53 }
54
55 int
56 main (int argc, char **argv)
57 {
58   const char *prev_arg;
59   dbus_bool_t exit_with_session;
60   int i;  
61
62   exit_with_session = FALSE;
63   
64   prev_arg = NULL;
65   i = 1;
66   while (i < argc)
67     {
68       const char *arg = argv[i];
69       
70       if (strcmp (arg, "--help") == 0 ||
71           strcmp (arg, "-h") == 0 ||
72           strcmp (arg, "-?") == 0)
73         usage ();
74       else if (strcmp (arg, "--version") == 0)
75         version ();
76       else if (strcmp (arg, "--exit-with-session") == 0)
77         exit_with_session = TRUE;
78       else
79         usage ();
80       
81       prev_arg = arg;
82       
83       ++i;
84     }
85   
86   
87   
88   return 0;
89 }