mirror of https://github.com/aria2/aria2
global cout and cerr is now retrieved using global::cout() and global::cerr()
This is necessary to avoid global variable initialization order problem.pull/1/head
parent
e8e3a6f259
commit
37016c6587
|
@ -196,7 +196,7 @@ public:
|
||||||
o, rg->inMemoryDownload());
|
o, rg->inMemoryDownload());
|
||||||
o << "\n"
|
o << "\n"
|
||||||
<< std::setfill(SEP_CHAR) << std::setw(cols_) << SEP_CHAR << "\n";
|
<< std::setfill(SEP_CHAR) << std::setw(cols_) << SEP_CHAR << "\n";
|
||||||
global::cout->write(o.str().c_str());
|
global::cout()->write(o.str().c_str());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -227,7 +227,7 @@ void printProgressSummary
|
||||||
}
|
}
|
||||||
o << " *** " << "\n"
|
o << " *** " << "\n"
|
||||||
<< std::setfill(SEP_CHAR) << std::setw(cols) << SEP_CHAR << "\n";
|
<< std::setfill(SEP_CHAR) << std::setw(cols) << SEP_CHAR << "\n";
|
||||||
global::cout->write(o.str().c_str());
|
global::cout()->write(o.str().c_str());
|
||||||
std::for_each(groups.begin(), groups.end(),
|
std::for_each(groups.begin(), groups.end(),
|
||||||
PrintSummary(cols, e, sizeFormatter));
|
PrintSummary(cols, e, sizeFormatter));
|
||||||
}
|
}
|
||||||
|
@ -273,7 +273,7 @@ ConsoleStatCalc::calculateStat(const DownloadEngine* e)
|
||||||
#endif // HAVE_TERMIOS_H
|
#endif // HAVE_TERMIOS_H
|
||||||
#endif // !__MINGW32__
|
#endif // !__MINGW32__
|
||||||
std::string line(cols, ' ');
|
std::string line(cols, ' ');
|
||||||
global::cout->printf("\r%s\r", line.c_str());
|
global::cout()->printf("\r%s\r", line.c_str());
|
||||||
}
|
}
|
||||||
std::ostringstream o;
|
std::ostringstream o;
|
||||||
if(e->getRequestGroupMan()->countRequestGroup() > 0) {
|
if(e->getRequestGroupMan()->countRequestGroup() > 0) {
|
||||||
|
@ -283,8 +283,8 @@ ConsoleStatCalc::calculateStat(const DownloadEngine* e)
|
||||||
lastSummaryNotified_ = global::wallclock();
|
lastSummaryNotified_ = global::wallclock();
|
||||||
printProgressSummary(e->getRequestGroupMan()->getRequestGroups(), cols, e,
|
printProgressSummary(e->getRequestGroupMan()->getRequestGroups(), cols, e,
|
||||||
sizeFormatter);
|
sizeFormatter);
|
||||||
global::cout->write("\n");
|
global::cout()->write("\n");
|
||||||
global::cout->flush();
|
global::cout()->flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!readoutVisibility_) {
|
if(!readoutVisibility_) {
|
||||||
|
@ -372,11 +372,11 @@ ConsoleStatCalc::calculateStat(const DownloadEngine* e)
|
||||||
if(truncate_ && readout.size() > cols) {
|
if(truncate_ && readout.size() > cols) {
|
||||||
readout[cols] = '\0';
|
readout[cols] = '\0';
|
||||||
}
|
}
|
||||||
global::cout->write(readout.c_str());
|
global::cout()->write(readout.c_str());
|
||||||
global::cout->flush();
|
global::cout()->flush();
|
||||||
} else {
|
} else {
|
||||||
global::cout->write(readout.c_str());
|
global::cout()->write(readout.c_str());
|
||||||
global::cout->write("\n");
|
global::cout()->write("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ void Logger::openFile(const std::string& filename)
|
||||||
{
|
{
|
||||||
closeFile();
|
closeFile();
|
||||||
if(filename == DEV_STDOUT) {
|
if(filename == DEV_STDOUT) {
|
||||||
fpp_ = global::cout;
|
fpp_ = global::cout();
|
||||||
} else {
|
} else {
|
||||||
fpp_.reset(new BufferedFile(filename, BufferedFile::APPEND));
|
fpp_.reset(new BufferedFile(filename, BufferedFile::APPEND));
|
||||||
if(!fpp_) {
|
if(!fpp_) {
|
||||||
|
@ -170,11 +170,11 @@ void Logger::writeLog
|
||||||
fpp_->flush();
|
fpp_->flush();
|
||||||
}
|
}
|
||||||
if(toConsole) {
|
if(toConsole) {
|
||||||
global::cout->printf("\n");
|
global::cout()->printf("\n");
|
||||||
writeHeader(*global::cout, level, 0, 0);
|
writeHeader(*global::cout(), level, 0, 0);
|
||||||
global::cout->printf("%s\n", msg);
|
global::cout()->printf("%s\n", msg);
|
||||||
writeStackTrace(*global::cout, trace);
|
writeStackTrace(*global::cout(), trace);
|
||||||
global::cout->flush();
|
global::cout()->flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,8 +95,6 @@ bool Platform::setUp()
|
||||||
}
|
}
|
||||||
initialized_ = true;
|
initialized_ = true;
|
||||||
|
|
||||||
global::initConsole();
|
|
||||||
|
|
||||||
#ifdef ENABLE_NLS
|
#ifdef ENABLE_NLS
|
||||||
setlocale (LC_CTYPE, "");
|
setlocale (LC_CTYPE, "");
|
||||||
setlocale (LC_MESSAGES, "");
|
setlocale (LC_MESSAGES, "");
|
||||||
|
@ -129,8 +127,8 @@ bool Platform::setUp()
|
||||||
#ifdef CARES_HAVE_ARES_LIBRARY_INIT
|
#ifdef CARES_HAVE_ARES_LIBRARY_INIT
|
||||||
int aresErrorCode;
|
int aresErrorCode;
|
||||||
if((aresErrorCode = ares_library_init(ARES_LIB_INIT_ALL)) != 0) {
|
if((aresErrorCode = ares_library_init(ARES_LIB_INIT_ALL)) != 0) {
|
||||||
global::cerr->printf("ares_library_init() failed:%s\n",
|
global::cerr()->printf("ares_library_init() failed:%s\n",
|
||||||
ares_strerror(aresErrorCode));
|
ares_strerror(aresErrorCode));
|
||||||
}
|
}
|
||||||
#endif // CARES_HAVE_ARES_LIBRARY_INIT
|
#endif // CARES_HAVE_ARES_LIBRARY_INIT
|
||||||
|
|
||||||
|
|
|
@ -39,30 +39,32 @@ namespace aria2 {
|
||||||
namespace global {
|
namespace global {
|
||||||
|
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
SharedHandle<WinConsoleFile> cout;
|
const SharedHandle<WinConsoleFile>& cout()
|
||||||
#else // !__MINGW32__
|
|
||||||
SharedHandle<BufferedFile> cout;
|
|
||||||
#endif // !__MINGW32__
|
|
||||||
|
|
||||||
#ifdef __MINGW32__
|
|
||||||
SharedHandle<WinConsoleFile> cerr;
|
|
||||||
#else // !__MINGW32__
|
|
||||||
SharedHandle<BufferedFile> cerr;
|
|
||||||
#endif // !__MINGW32__
|
|
||||||
|
|
||||||
void initConsole()
|
|
||||||
{
|
{
|
||||||
#ifdef __MINGW32__
|
static SharedHandle<WinConsoleFile> f(new WinConsoleFile(STD_INPUT_HANDLE));
|
||||||
cout.reset(new WinConsoleFile(STD_INPUT_HANDLE));
|
return f;
|
||||||
#else // !__MINGW32__
|
|
||||||
cout.reset(new BufferedFile(stdout));
|
|
||||||
#endif // !__MINGW32__
|
|
||||||
#ifdef __MINGW32__
|
|
||||||
cerr.reset(new WinConsoleFile(STD_ERROR_HANDLE));
|
|
||||||
#else // !__MINGW32__
|
|
||||||
cerr.reset(new BufferedFile(stderr));
|
|
||||||
#endif // !__MINGW32__
|
|
||||||
}
|
}
|
||||||
|
#else // !__MINGW32__
|
||||||
|
const SharedHandle<BufferedFile>& cout()
|
||||||
|
{
|
||||||
|
static SharedHandle<BufferedFile> f(new BufferedFile(stdout));
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
#endif // !__MINGW32__
|
||||||
|
|
||||||
|
#ifdef __MINGW32__
|
||||||
|
const SharedHandle<WinConsoleFile>& cerr()
|
||||||
|
{
|
||||||
|
static SharedHandle<WinConsoleFile> f(new WinConsoleFile(STD_ERROR_HANDLE));
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
#else // !__MINGW32__
|
||||||
|
const SharedHandle<BufferedFile>& cerr()
|
||||||
|
{
|
||||||
|
static SharedHandle<BufferedFile> f(new BufferedFile(stderr));
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
#endif // !__MINGW32__
|
||||||
|
|
||||||
} // namespace global
|
} // namespace global
|
||||||
|
|
||||||
|
|
|
@ -48,19 +48,17 @@ namespace aria2 {
|
||||||
namespace global {
|
namespace global {
|
||||||
|
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
extern SharedHandle<WinConsoleFile> cout;
|
const SharedHandle<WinConsoleFile>& cout();
|
||||||
#else // !__MINGW32__
|
#else // !__MINGW32__
|
||||||
extern SharedHandle<BufferedFile> cout;
|
const SharedHandle<BufferedFile>& cout();
|
||||||
#endif // !__MINGW32__
|
#endif // !__MINGW32__
|
||||||
|
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
extern SharedHandle<WinConsoleFile> cerr;
|
const SharedHandle<WinConsoleFile>& cerr();
|
||||||
#else // !__MINGW32__
|
#else // !__MINGW32__
|
||||||
extern SharedHandle<BufferedFile> cerr;
|
const SharedHandle<BufferedFile>& cerr();
|
||||||
#endif // !__MINGW32__
|
#endif // !__MINGW32__
|
||||||
|
|
||||||
void initConsole();
|
|
||||||
|
|
||||||
} // namespace global
|
} // namespace global
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
18
src/main.cc
18
src/main.cc
|
@ -107,7 +107,7 @@ SharedHandle<OutputFile> getSummaryOut(const SharedHandle<Option>& op)
|
||||||
if(op->getAsBool(PREF_QUIET)) {
|
if(op->getAsBool(PREF_QUIET)) {
|
||||||
return SharedHandle<OutputFile>(new NullOutputFile());
|
return SharedHandle<OutputFile>(new NullOutputFile());
|
||||||
} else {
|
} else {
|
||||||
return global::cout;
|
return global::cout();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ void showTorrentFile(const std::string& uri)
|
||||||
SharedHandle<Option> op(new Option());
|
SharedHandle<Option> op(new Option());
|
||||||
SharedHandle<DownloadContext> dctx(new DownloadContext());
|
SharedHandle<DownloadContext> dctx(new DownloadContext());
|
||||||
bittorrent::load(uri, dctx, op);
|
bittorrent::load(uri, dctx, op);
|
||||||
bittorrent::print(*global::cout, dctx);
|
bittorrent::print(*global::cout(), dctx);
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
#endif // ENABLE_BITTORRENT
|
#endif // ENABLE_BITTORRENT
|
||||||
|
@ -133,9 +133,9 @@ void showMetalinkFile
|
||||||
op->get(PREF_METALINK_BASE_URI));
|
op->get(PREF_METALINK_BASE_URI));
|
||||||
std::vector<SharedHandle<FileEntry> > fileEntries;
|
std::vector<SharedHandle<FileEntry> > fileEntries;
|
||||||
MetalinkEntry::toFileEntry(fileEntries, metalinkEntries);
|
MetalinkEntry::toFileEntry(fileEntries, metalinkEntries);
|
||||||
util::toStream(fileEntries.begin(), fileEntries.end(), *global::cout);
|
util::toStream(fileEntries.begin(), fileEntries.end(), *global::cout());
|
||||||
global::cout->write("\n");
|
global::cout()->write("\n");
|
||||||
global::cout->flush();
|
global::cout()->flush();
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
#endif // ENABLE_METALINK
|
#endif // ENABLE_METALINK
|
||||||
|
@ -167,7 +167,7 @@ void showFiles
|
||||||
printf("\n\n");
|
printf("\n\n");
|
||||||
}
|
}
|
||||||
} catch(RecoverableException& e) {
|
} catch(RecoverableException& e) {
|
||||||
global::cout->printf("%s\n", e.stackTrace().c_str());
|
global::cout()->printf("%s\n", e.stackTrace().c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -268,7 +268,7 @@ error_code::Value main(int argc, char* argv[])
|
||||||
op->remove(PREF_SELECT_FILE);
|
op->remove(PREF_SELECT_FILE);
|
||||||
op->remove(PREF_PAUSE);
|
op->remove(PREF_PAUSE);
|
||||||
if(!op->getAsBool(PREF_ENABLE_RPC) && requestGroups.empty()) {
|
if(!op->getAsBool(PREF_ENABLE_RPC) && requestGroups.empty()) {
|
||||||
global::cout->printf("%s\n", MSG_NO_FILES_TO_DOWNLOAD);
|
global::cout()->printf("%s\n", MSG_NO_FILES_TO_DOWNLOAD);
|
||||||
} else {
|
} else {
|
||||||
exitStatus = MultiUrlRequestInfo(requestGroups, op, getStatCalc(op),
|
exitStatus = MultiUrlRequestInfo(requestGroups, op, getStatCalc(op),
|
||||||
getSummaryOut(op)).execute();
|
getSummaryOut(op)).execute();
|
||||||
|
@ -285,7 +285,9 @@ int main(int argc, char* argv[])
|
||||||
aria2::Platform platform;
|
aria2::Platform platform;
|
||||||
r = aria2::main(argc, argv);
|
r = aria2::main(argc, argv);
|
||||||
} catch(aria2::Exception& ex) {
|
} catch(aria2::Exception& ex) {
|
||||||
std::cerr << EX_EXCEPTION_CAUGHT << "\n" << ex.stackTrace() << std::endl;
|
aria2::global::cerr()->printf("%s\n%s\n",
|
||||||
|
EX_EXCEPTION_CAUGHT,
|
||||||
|
ex.stackTrace().c_str());
|
||||||
r = ex.getErrorCode();
|
r = ex.getErrorCode();
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
|
|
|
@ -76,7 +76,7 @@ void overrideWithEnv(Option& op, const OptionParser& optionParser,
|
||||||
try {
|
try {
|
||||||
optionParser.findByName(pref)->parse(op, value);
|
optionParser.findByName(pref)->parse(op, value);
|
||||||
} catch(Exception& e) {
|
} catch(Exception& e) {
|
||||||
global::cerr->printf
|
global::cerr()->printf
|
||||||
("Caught Error while parsing environment variable '%s'\n%s\n",
|
("Caught Error while parsing environment variable '%s'\n%s\n",
|
||||||
envName.c_str(),
|
envName.c_str(),
|
||||||
e.stackTrace().c_str());
|
e.stackTrace().c_str());
|
||||||
|
@ -144,25 +144,25 @@ void option_processing(Option& op, std::vector<std::string>& uris,
|
||||||
try {
|
try {
|
||||||
oparser.parse(op, ss);
|
oparser.parse(op, ss);
|
||||||
} catch(OptionHandlerException& e) {
|
} catch(OptionHandlerException& e) {
|
||||||
global::cerr->printf("Parse error in %s\n%s\n",
|
global::cerr()->printf("Parse error in %s\n%s\n",
|
||||||
cfname.c_str(),
|
cfname.c_str(),
|
||||||
e.stackTrace().c_str());
|
e.stackTrace().c_str());
|
||||||
SharedHandle<OptionHandler> h = oparser.findByName(e.getOptionName());
|
SharedHandle<OptionHandler> h = oparser.findByName(e.getOptionName());
|
||||||
if(h) {
|
if(h) {
|
||||||
global::cerr->printf
|
global::cerr()->printf
|
||||||
("Usage:\n%s\n",
|
("Usage:\n%s\n",
|
||||||
oparser.findByName(e.getOptionName())->getDescription().c_str());
|
oparser.findByName(e.getOptionName())->getDescription().c_str());
|
||||||
}
|
}
|
||||||
exit(e.getErrorCode());
|
exit(e.getErrorCode());
|
||||||
} catch(Exception& e) {
|
} catch(Exception& e) {
|
||||||
global::cerr->printf("Parse error in %s\n%s\n",
|
global::cerr()->printf("Parse error in %s\n%s\n",
|
||||||
cfname.c_str(),
|
cfname.c_str(),
|
||||||
e.stackTrace().c_str());
|
e.stackTrace().c_str());
|
||||||
exit(e.getErrorCode());
|
exit(e.getErrorCode());
|
||||||
}
|
}
|
||||||
} else if(!ucfname.empty()) {
|
} else if(!ucfname.empty()) {
|
||||||
global::cerr->printf("Configuration file %s is not found.\n",
|
global::cerr()->printf("Configuration file %s is not found.\n",
|
||||||
cfname.c_str());
|
cfname.c_str());
|
||||||
showUsage(TAG_HELP, oparser);
|
showUsage(TAG_HELP, oparser);
|
||||||
exit(error_code::UNKNOWN_ERROR);
|
exit(error_code::UNKNOWN_ERROR);
|
||||||
}
|
}
|
||||||
|
@ -188,16 +188,16 @@ void option_processing(Option& op, std::vector<std::string>& uris,
|
||||||
}
|
}
|
||||||
#endif // __MINGW32__
|
#endif // __MINGW32__
|
||||||
} catch(OptionHandlerException& e) {
|
} catch(OptionHandlerException& e) {
|
||||||
global::cerr->printf("%s\n", e.stackTrace().c_str());
|
global::cerr()->printf("%s\n", e.stackTrace().c_str());
|
||||||
SharedHandle<OptionHandler> h = oparser.findByName(e.getOptionName());
|
SharedHandle<OptionHandler> h = oparser.findByName(e.getOptionName());
|
||||||
if(h) {
|
if(h) {
|
||||||
std::ostringstream ss;
|
std::ostringstream ss;
|
||||||
ss << *h;
|
ss << *h;
|
||||||
global::cerr->printf("Usage:\n%s\n", ss.str().c_str());
|
global::cerr()->printf("Usage:\n%s\n", ss.str().c_str());
|
||||||
}
|
}
|
||||||
exit(e.getErrorCode());
|
exit(e.getErrorCode());
|
||||||
} catch(Exception& e) {
|
} catch(Exception& e) {
|
||||||
global::cerr->printf("%s\n", e.stackTrace().c_str());
|
global::cerr()->printf("%s\n", e.stackTrace().c_str());
|
||||||
showUsage(TAG_HELP, oparser);
|
showUsage(TAG_HELP, oparser);
|
||||||
exit(e.getErrorCode());
|
exit(e.getErrorCode());
|
||||||
}
|
}
|
||||||
|
@ -210,7 +210,7 @@ void option_processing(Option& op, std::vector<std::string>& uris,
|
||||||
#endif // ENABLE_METALINK
|
#endif // ENABLE_METALINK
|
||||||
op.blank(PREF_INPUT_FILE)) {
|
op.blank(PREF_INPUT_FILE)) {
|
||||||
if(uris.empty()) {
|
if(uris.empty()) {
|
||||||
global::cerr->printf("%s\n", MSG_URI_REQUIRED);
|
global::cerr()->printf("%s\n", MSG_URI_REQUIRED);
|
||||||
showUsage(TAG_HELP, oparser);
|
showUsage(TAG_HELP, oparser);
|
||||||
exit(error_code::UNKNOWN_ERROR);
|
exit(error_code::UNKNOWN_ERROR);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue