From aa405810db44a121d42cab88d5bfecef40049e2e Mon Sep 17 00:00:00 2001 From: rakshasa Date: Fri, 18 Feb 2005 21:51:13 +0000 Subject: [PATCH] Added help text and port range option. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@288 e378c898-3ddf-0310-93e7-cc216c733640 --- README | 5 ++++ src/main.cc | 70 ++++++++++++++++++++++++++++---------------- src/option_parser.cc | 2 +- 3 files changed, 50 insertions(+), 27 deletions(-) diff --git a/README b/README index 659d05aa..8b2bc1a9 100644 --- a/README +++ b/README @@ -1,3 +1,8 @@ +Options and flags: + + -p Open a port in the range a to b. + + All: Ctrl-Q - Quit diff --git a/src/main.cc b/src/main.cc index 4765c016..fb50fae3 100644 --- a/src/main.cc +++ b/src/main.cc @@ -27,6 +27,9 @@ int64_t Timer::m_cache; bool start_shutdown = false; bool is_shutting_down = false; +void do_panic(int signum); +void print_help(); + bool is_resized() { static int x = 0; @@ -66,32 +69,6 @@ do_shutdown(ui::Control* c) { start_shutdown = false; } -void -do_panic(int signum) { - display::Canvas::cleanup(); - - std::cout << "Signal " << (signum == SIGSEGV ? "SIGSEGV" : "SIGBUS") << " recived, dumping stack:" << std::endl; - -#ifdef USE_EXECINFO - void* stackPtrs[20]; - - // Print the stack and exit. - int stackSize = backtrace(stackPtrs, 20); - char** stackStrings = backtrace_symbols(stackPtrs, stackSize); - - for (int i = 0; i < stackSize; ++i) - std::cout << i << ' ' << stackStrings[i] << std::endl; - -#else - std::cout << "Stack dump not enabled." << std::endl; -#endif - - if (signum == SIGBUS) - std::cout << "A bus error might mean you ran out of diskspace." << std::endl; - - exit(-1); -} - int main(int argc, char** argv) { ui::Control uiControl; @@ -103,6 +80,7 @@ main(int argc, char** argv) { 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))); @@ -149,9 +127,49 @@ main(int argc, char** argv) { display::Canvas::cleanup(); std::cout << "Caught exception: \"" << e.what() << '"' << std::endl; + return -1; } uiControl.get_core().cleanup(); return 0; } + +void +do_panic(int signum) { + display::Canvas::cleanup(); + + std::cout << "Signal " << (signum == SIGSEGV ? "SIGSEGV" : "SIGBUS") << " recived, dumping stack:" << std::endl; + +#ifdef USE_EXECINFO + void* stackPtrs[20]; + + // Print the stack and exit. + int stackSize = backtrace(stackPtrs, 20); + char** stackStrings = backtrace_symbols(stackPtrs, stackSize); + + for (int i = 0; i < stackSize; ++i) + std::cout << i << ' ' << stackStrings[i] << std::endl; + +#else + std::cout << "Stack dump not enabled." << std::endl; +#endif + + if (signum == SIGBUS) + std::cout << "A bus error might mean you ran out of diskspace." << std::endl; + + exit(-1); +} + +void +print_help() { + std::cout << "Rakshasa's Torrent client. Neko-Mimi Mode-o!" << 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 << " -p - Set port range for incoming connections" << std::endl; + std::cout << std::endl; + std::cout << "Report bugs to ." << std::endl; + + exit(0); +} diff --git a/src/option_parser.cc b/src/option_parser.cc index 83939178..5d40933f 100644 --- a/src/option_parser.cc +++ b/src/option_parser.cc @@ -30,7 +30,7 @@ OptionParser::process(int argc, char** argv) { while ((c = getopt(argc, argv, optString.c_str())) != -1) { if (c == '?') { std::stringstream s; - s << "Invalid use of option flag -" << (char)optopt; + s << "Invalid use of option flag -" << (char)optopt << ". Try rtorrent -h for more information."; throw std::runtime_error(s.str());