extract main kakoune code to a kakoune function

This commit is contained in:
Maxime Coste 2013-09-19 19:53:04 +01:00
parent 03588f1b78
commit 0b63074f90

View File

@ -174,22 +174,11 @@ void signal_handler(int signal)
abort(); abort();
} }
int main(int argc, char* argv[]) int kakoune(memoryview<String> params)
{ {
try ParametersParser parser(params, { { "c", true },
{ { "e", true },
setlocale(LC_ALL, ""); { "n", false } });
signal(SIGSEGV, signal_handler);
signal(SIGFPE, signal_handler);
signal(SIGQUIT, signal_handler);
signal(SIGTERM, signal_handler);
std::vector<String> params;
for (size_t i = 1; i < argc; ++i)
params.push_back(argv[i]);
ParametersParser parser(params, { { "c", true }, { "e", true }, { "n", false } });
EventManager event_manager;
String init_command; String init_command;
if (parser.has_option("e")) if (parser.has_option("e"))
@ -197,8 +186,17 @@ int main(int argc, char* argv[])
if (parser.has_option("c")) if (parser.has_option("c"))
{ {
for (auto opt : { "n" })
{
if (parser.has_option(opt))
{
fprintf(stderr, "error: -%s makes not sense with -c", opt);
return -1;
}
}
try try
{ {
EventManager event_manager;
auto client = connect_to(parser.option_value("c"), auto client = connect_to(parser.option_value("c"),
std::unique_ptr<UserInterface>{new NCursesUI{}}, std::unique_ptr<UserInterface>{new NCursesUI{}},
init_command); init_command);
@ -207,11 +205,14 @@ int main(int argc, char* argv[])
} }
catch (peer_disconnected&) catch (peer_disconnected&)
{ {
puts("disconnected"); fputs("disconnected from server", stderr);
return -1;
} }
return 0; return 0;
} }
else
{
EventManager event_manager;
GlobalOptions global_options; GlobalOptions global_options;
GlobalHooks global_hooks; GlobalHooks global_hooks;
ShellManager shell_manager; ShellManager shell_manager;
@ -284,6 +285,26 @@ int main(int argc, char* argv[])
Context empty_context; Context empty_context;
global_hooks.run_hook("KakEnd", "", empty_context); global_hooks.run_hook("KakEnd", "", empty_context);
} }
return 0;
}
}
int main(int argc, char* argv[])
{
try
{
setlocale(LC_ALL, "");
signal(SIGSEGV, signal_handler);
signal(SIGFPE, signal_handler);
signal(SIGQUIT, signal_handler);
signal(SIGTERM, signal_handler);
std::vector<String> params;
for (size_t i = 1; i < argc; ++i)
params.push_back(argv[i]);
kakoune(params);
} }
catch (Kakoune::exception& error) catch (Kakoune::exception& error)
{ {