main.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. This file is part of cpp-ethereum.
  3. cpp-ethereum is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. cpp-ethereum is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. /** @file main.cpp
  15. * @author Gav Wood <i@gavwood.com>
  16. * @date 2014
  17. * Ethereum client.
  18. */
  19. // Solves the problem of including windows.h before including winsock.h
  20. // as detailed here:
  21. // http://stackoverflow.com/questions/1372480/c-redefinition-header-files-winsock2-h
  22. #if defined(_WIN32)
  23. #define _WINSOCKAPI_
  24. #include <windows.h>
  25. #endif // defined(_WIN32)
  26. #include <clocale>
  27. #include "MinerAux.h"
  28. using namespace std;
  29. using namespace dev;
  30. using namespace dev::eth;
  31. using namespace boost::algorithm;
  32. #undef RETURN
  33. void help()
  34. {
  35. cout
  36. << "Usage ethminer [OPTIONS]" << endl
  37. << "Options:" << endl << endl;
  38. MinerCLI::streamHelp(cout);
  39. cout
  40. << "General Options:" << endl
  41. << " -v,--verbosity <0 - 9> Set the log verbosity from 0 to 9 (default: 8)." << endl
  42. << " -V,--version Show the version and exit." << endl
  43. << " -h,--help Show this help message and exit." << endl
  44. ;
  45. exit(0);
  46. }
  47. void version()
  48. {
  49. cout << "ethminer version " << dev::Version << endl;
  50. cout << "Build: " << DEV_QUOTED(ETH_BUILD_PLATFORM) << "/" << DEV_QUOTED(ETH_BUILD_TYPE) << endl;
  51. exit(0);
  52. }
  53. /*
  54. The equivalent of setlocale(LC_ALL, “C”) is called before any user code is run.
  55. If the user has an invalid environment setting then it is possible for the call
  56. to set locale to fail, so there are only two possible actions, the first is to
  57. throw a runtime exception and cause the program to quit (default behaviour),
  58. or the second is to modify the environment to something sensible (least
  59. surprising behaviour).
  60. The follow code produces the least surprising behaviour. It will use the user
  61. specified default locale if it is valid, and if not then it will modify the
  62. environment the process is running in to use a sensible default. This also means
  63. that users do not need to install language packs for their OS.
  64. */
  65. void setDefaultOrCLocale()
  66. {
  67. #if __unix__
  68. if (!std::setlocale(LC_ALL, ""))
  69. {
  70. setenv("LC_ALL", "C", 1);
  71. }
  72. #endif
  73. }
  74. int main(int argc, char** argv)
  75. {
  76. setDefaultOrCLocale();
  77. MinerCLI m(MinerCLI::OperationMode::Farm);
  78. for (int i = 1; i < argc; ++i)
  79. {
  80. string arg = argv[i];
  81. if (m.interpretOption(i, argc, argv))
  82. {}
  83. else if ((arg == "-v" || arg == "--verbosity") && i + 1 < argc)
  84. g_logVerbosity = atoi(argv[++i]);
  85. else if (arg == "-h" || arg == "--help")
  86. help();
  87. else if (arg == "-V" || arg == "--version")
  88. version();
  89. else
  90. {
  91. cerr << "Invalid argument: " << arg << endl;
  92. exit(-1);
  93. }
  94. }
  95. m.execute();
  96. return 0;
  97. }