Cleaning up main.cc and adding help text.

git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@296 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2005-02-20 18:02:32 +00:00
parent c4d548bafd
commit 75ef138118
2 changed files with 51 additions and 21 deletions
+2
View File
@@ -2,6 +2,8 @@ Options and flags:
-p <a-b> Open a port in the range a to b.
-s <dir> Use <dir> as the session directory. The torrents will be
saved with the info-hash in hex as the filename.
All:
+49 -21
View File
@@ -85,6 +85,17 @@ test_dir(const std::string& s) {
exit(0);
}
int
parse_options(ui::Control* c, int argc, char** argv) {
OptionParser optionParser;
optionParser.insert_flag('h', sigc::ptr_fun(&print_help));
optionParser.insert_option('p', sigc::bind(sigc::ptr_fun(OptionParser::call_int_pair),
sigc::mem_fun(c->get_core(), &core::Manager::set_port_range)));
optionParser.insert_option('s', sigc::mem_fun(c->get_core().get_download_store(), &core::DownloadStore::activate));
return optionParser.process(argc, argv);
}
void
load_session_torrents(ui::Control* c) {
// Load session torrents.
@@ -98,23 +109,31 @@ load_arg_torrents(ui::Control* c, char** begin, char** end) {
std::for_each(begin, end, std::bind1st(std::mem_fun(&core::Manager::insert), &c->get_core()));
}
int
main(int argc, char** argv) {
ui::Control uiControl;
try {
void
register_signals(ui::Control* c) {
SignalHandler::set_handler(SIGINT, sigc::ptr_fun(&set_shutdown));
SignalHandler::set_handler(SIGSEGV, sigc::bind(sigc::ptr_fun(&do_panic), SIGSEGV));
SignalHandler::set_handler(SIGBUS, sigc::bind(sigc::ptr_fun(&do_panic), SIGBUS));
}
OptionParser optionParser;
optionParser.insert_flag('h', sigc::ptr_fun(&print_help));
optionParser.insert_option('p', sigc::bind(sigc::ptr_fun(OptionParser::call_int_pair),
sigc::mem_fun(uiControl.get_core(), &core::Manager::set_port_range)));
optionParser.insert_option('s', sigc::mem_fun(uiControl.get_core().get_download_store(), &core::DownloadStore::activate));
void
register_main_keys(ui::Control* c, input::Bindings* b) {
c->get_input().push_back(b);
int firstArg = optionParser.process(argc, argv);
(*b)[KEY_RESIZE] = sigc::mem_fun(c->get_display(), &display::Manager::adjust_layout);
(*b)['\x11'] = sigc::ptr_fun(&set_shutdown);
}
int
main(int argc, char** argv) {
ui::Control uiControl;
input::Bindings inputMain;
try {
register_signals(&uiControl);
int firstArg = parse_options(&uiControl, argc, argv);
display::Canvas::init();
@@ -123,12 +142,7 @@ main(int argc, char** argv) {
uiDownloadList.activate();
uiDownloadList.slot_open_uri(sigc::mem_fun(uiControl.get_core(), &core::Manager::insert));
// Register main key events.
input::Bindings inputMain;
uiControl.get_input().push_back(&inputMain);
inputMain[KEY_RESIZE] = sigc::mem_fun(uiControl.get_display(), &display::Manager::adjust_layout);
inputMain['\x11'] = sigc::ptr_fun(&set_shutdown);
register_main_keys(&uiControl, &inputMain);
uiControl.get_core().get_poll().slot_read_stdin(sigc::mem_fun(uiControl.get_input(), &input::Manager::pressed));
uiControl.get_core().get_poll().slot_select_interrupted(sigc::ptr_fun(display::Canvas::do_update));
@@ -193,12 +207,26 @@ do_panic(int signum) {
void
print_help() {
std::cout << "Rakshasa's Torrent client. Neko-Mimi Mode-o!" << std::endl;
std::cout << "Rakshasa's Torrent client. <Neko-Mimi Mode-o!>" << std::endl;
std::cout << std::endl;
std::cout << "Usage: rtorrent [OPTIONS]... [FILE]... [URL]..." << std::endl;
std::cout << std::endl;
std::cout << " -h Display this very helpfull text" << std::endl;
std::cout << " -h Display this very helpful text" << std::endl;
std::cout << " -p <int>-<int> Set port range for incoming connections" << std::endl;
std::cout << " -s <directory> Set the session directory" << std::endl;
std::cout << std::endl;
std::cout << "Main view keys:" << std::endl;
std::cout << " backspace Add a torrent url or path" << std::endl;
std::cout << " ^s Start torrent" << std::endl;
std::cout << " ^d Stop torrent or delete a stopped torrent" << std::endl;
std::cout << " ^q Initiate shutdown or skip shutdown process" << std::endl;
std::cout << " a,s,d,z,x,c Adjust throttle" << std::endl;
std::cout << std::endl;
std::cout << "Download view keys:" << std::endl;
std::cout << " 1,2 Adjust max uploads" << std::endl;
std::cout << " 3,4,5,6 Adjust min/max connected peers" << std::endl;
std::cout << " t Query tracker for more peers" << std::endl;
std::cout << std::endl;
std::cout << "Report bugs to <jaris@ifi.uio.no>." << std::endl;
exit(0);