2 * luakit.c - luakit main functions
4 * Copyright (C) 2010 Mason Larobina <mason.larobina@gmail.com>
5 * Copyright (C) 2009 Enno Boland <gottox@s01.de>
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include "globalconf.h"
27 #include "common/util.h"
31 static void sigchld(int sigint
);
36 if (signal(SIGCHLD
, sigchld
) == SIG_ERR
)
37 fatal("Can't install SIGCHLD handler");
38 while(0 < waitpid(-1, NULL
, WNOHANG
));
41 /* load command line options into luakit and return uris to load */
43 parseopts(int argc
, char *argv
[]) {
44 GOptionContext
*context
;
45 gboolean
*only_version
= NULL
;
48 /* define command line options */
49 const GOptionEntry entries
[] = {
50 { "uri", 'u', 0, G_OPTION_ARG_STRING_ARRAY
, &uris
, "uri(s) to load at startup", "URI" },
51 { "config", 'c', 0, G_OPTION_ARG_STRING
, &globalconf
.confpath
, "configuration file to use", "FILE" },
52 { "version", 'V', 0, G_OPTION_ARG_NONE
, &only_version
, "print version and exit", NULL
},
53 { "verbose", 'v', 0, G_OPTION_ARG_NONE
, &globalconf
.verbose
, "print debugging output", NULL
},
54 { NULL
, 0, 0, 0, NULL
, NULL
, NULL
},
57 /* parse command line options */
58 context
= g_option_context_new("[URI...]");
59 g_option_context_add_main_entries(context
, entries
, NULL
);
60 g_option_context_add_group(context
, gtk_get_option_group(TRUE
));
61 // TODO Passing gtk options (like --sync) to luakit causes a segfault right
62 // here. I'm clueless.
63 g_option_context_parse(context
, &argc
, &argv
, NULL
);
64 g_option_context_free(context
);
66 /* print version and exit */
68 g_printf("Version: %s\n", VERSION
);
73 fatal("invalid mix of -u and default uri arguments");
82 init_lua(gchar
**uris
)
87 /* init globalconf structs */
88 globalconf
.signals
= signal_tree_new();
89 globalconf
.windows
= g_ptr_array_new();
95 /* push a table of the statup uris */
97 for (gint i
= 0; (uri
= uris
[i
]); i
++) {
98 lua_pushstring(L
, uri
);
99 lua_rawseti(L
, -2, i
+ 1);
101 lua_setglobal(L
, "uris");
103 /* parse and run configuration file */
104 if(!luaH_parserc(globalconf
.confpath
, TRUE
))
105 fatal("couldn't find rc file");
107 if (!globalconf
.windows
->len
)
108 fatal("no windows spawned by rc file, exiting");
112 init_directories(void)
114 /* create luakit directory */
115 globalconf
.cache_dir
= g_build_filename(g_get_user_cache_dir(), "luakit", NULL
);
116 globalconf
.config_dir
= g_build_filename(g_get_user_config_dir(), "luakit", NULL
);
117 globalconf
.data_dir
= g_build_filename(g_get_user_data_dir(), "luakit", NULL
);
118 g_mkdir_with_parents(globalconf
.cache_dir
, 0771);
119 g_mkdir_with_parents(globalconf
.config_dir
, 0771);
120 g_mkdir_with_parents(globalconf
.data_dir
, 0771);
124 main(int argc
, char *argv
[]) {
127 /* clean up any zombies */
130 gtk_init(&argc
, &argv
);
131 if (!g_thread_supported())
134 /* parse command line opts and get uris to load */
135 uris
= parseopts(argc
, argv
);
144 // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80