From 8efa71d30724d39379cd297bc53482c7740b9d3f Mon Sep 17 00:00:00 2001 From: Nikhil Tanwar <2002nikhiltanwar@gmail.com> Date: Tue, 5 Jul 2022 20:45:04 +0530 Subject: [PATCH] Use std namespace consistently Previously, there was an inconsistent usage of no namespace vs namespace. This change fixes that by correctly adding std:: whenever required. Adds iostream header in src/version.h to fix cout/cerr problems. --- src/server/kiwix-serve.cpp | 40 +++++++++++++++++++------------------- src/version.h | 1 + 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/server/kiwix-serve.cpp b/src/server/kiwix-serve.cpp index 0a1313a..fd01b88 100644 --- a/src/server/kiwix-serve.cpp +++ b/src/server/kiwix-serve.cpp @@ -85,20 +85,20 @@ void usage() << std::endl; } -string loadCustomTemplate (string customIndexPath) { +std::string loadCustomTemplate (std::string customIndexPath) { customIndexPath = kiwix::isRelativePath(customIndexPath) ? kiwix::computeAbsolutePath(kiwix::getCurrentDirectory(), customIndexPath) : customIndexPath; if (!kiwix::fileReadable(customIndexPath)) { - throw runtime_error("No such file exist (or file is not readable) " + customIndexPath); + throw std::runtime_error("No such file exist (or file is not readable) " + customIndexPath); } if (kiwix::getMimeTypeForFile(customIndexPath) != "text/html") { - throw runtime_error("Invalid File Mime Type " + kiwix::getMimeTypeForFile(customIndexPath)); + throw std::runtime_error("Invalid File Mime Type " + kiwix::getMimeTypeForFile(customIndexPath)); } - string indexTemplateString = kiwix::getFileContent(customIndexPath); + std::string indexTemplateString = kiwix::getFileContent(customIndexPath); if (indexTemplateString.empty()) { - throw runtime_error("Unreadable or empty file " + customIndexPath); + throw std::runtime_error("Unreadable or empty file " + customIndexPath); } return indexTemplateString; } @@ -189,12 +189,12 @@ int main(int argc, char** argv) std::string rootLocation = ""; kiwix::Library library; unsigned int nb_threads = DEFAULT_THREADS; - vector zimPathes; - string libraryPath; - string rootPath; - string address; - string customIndexPath=""; - string indexTemplateString=""; + std::vector zimPathes; + std::string libraryPath; + std::string rootPath; + std::string address; + std::string customIndexPath=""; + std::string indexTemplateString=""; int serverPort = 80; int daemonFlag [[gnu::unused]] = false; int libraryFlag = false; @@ -271,16 +271,16 @@ int main(int argc, char** argv) PPID = atoi(optarg); break; case 'i': - address = string(optarg); + address = std::string(optarg); break; case 't': nb_threads = atoi(optarg); break; case 'r': - rootLocation = string(optarg); + rootLocation = std::string(optarg); break; case 'c': - customIndexPath = string(optarg); + customIndexPath = std::string(optarg); break; case 'M': monitorLibrary = true; @@ -313,7 +313,7 @@ int main(int argc, char** argv) /* Setup the library manager and get the list of books */ kiwix::Manager manager(&library); - vector libraryPaths; + std::vector libraryPaths; if (libraryFlag) { libraryPaths = kiwix::split(libraryPath, ";"); if ( !reloadLibrary(manager, libraryPaths) ) { @@ -322,15 +322,15 @@ int main(int argc, char** argv) /* Check if the library is not empty (or only remote books)*/ if (library.getBookCount(true, false) == 0) { - cerr << "The XML library file '" << libraryPath - << "' is empty (or has only remote books)." << endl; + std::cerr << "The XML library file '" << libraryPath + << "' is empty (or has only remote books)." << std::endl; } } else { std::vector::iterator it; for (it = zimPathes.begin(); it != zimPathes.end(); it++) { if (!manager.addBookFromPath(*it, *it, "", false)) { - cerr << "Unable to add the ZIM file '" << *it - << "' to the internal library." << endl; + std::cerr << "Unable to add the ZIM file '" << *it + << "' to the internal library." << std::endl; exit(1); } } @@ -410,7 +410,7 @@ int main(int argc, char** argv) int ret = sysctl(mib, MIBSIZE, &kp, &len, NULL, 0); if (ret != -1 && len > 0) { #else /* Linux & co */ - string procPath = "/proc/" + std::to_string(PPID); + std::string procPath = "/proc/" + std::to_string(PPID); if (access(procPath.c_str(), F_OK) != -1) { #endif } else { diff --git a/src/version.h b/src/version.h index 0456fe5..9519179 100644 --- a/src/version.h +++ b/src/version.h @@ -26,6 +26,7 @@ #include #include +#include void version() {