From 9ad3df57cae93eef00682e715aea4c7580383914 Mon Sep 17 00:00:00 2001 From: Poul Sander Date: Fri, 2 Sep 2016 22:14:09 +0200 Subject: [PATCH] Corrected a few mistakes. --- Makefile | 2 +- README.md | 25 ++++++++++++------------- platform_folders.cpp | 30 ++++++++++++++++-------------- sago/platform_folders.cpp | 4 ++-- sago/platform_folders.h | 8 ++++---- 5 files changed, 35 insertions(+), 34 deletions(-) diff --git a/Makefile b/Makefile index 69a4618..bf6b328 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ PKG_CONFIG=$(CROSS)pkg-config endif BASE_LIBS= -BASE_CFLAGS=-c -g -O2 -Wall -pedantic-errors +BASE_CFLAGS=-c -g -O2 -Wall -Wextra -pedantic-errors #The files should compile on both C++03 and C++11 ifdef TESTCPP11 diff --git a/README.md b/README.md index be7e0f5..661ff88 100644 --- a/README.md +++ b/README.md @@ -39,22 +39,21 @@ This sample program gets all folders from the system: #include #include "sago/platform_folders.h" -using namespace std; -using namespace sago; +using std::cout; int main() { - cout << "Config: " << getConfigHome() << endl; - cout << "Data: " << getDataHome() << endl; - cout << "Cache: " << getCacheDir() << endl; - PlatformFolders p; - cout << "Documents: " << p.getDocumentsFolder() << endl; - cout << "Desktop: " << p.getDesktopFolder() << endl; - cout << "Pictures: " << p.getPicturesFolder() << endl; - cout << "Music: " << p.getMusicFolder() << endl; - cout << "Video: " << p.getVideoFolder() << endl; - cout << "Download: " << p.getDownloadFolder1() << endl; - cout << "Save Games 1: " << p.getSaveGamesFolder1() << endl; + cout << "Config: " << sago::getConfigHome() << "\n"; + cout << "Data: " << sago::getDataHome() << "\n"; + cout << "Cache: " << sago::getCacheDir() << "\n"; + sago::PlatformFolders p; + cout << "Documents: " << p.getDocumentsFolder() << "\n"; + cout << "Desktop: " << p.getDesktopFolder() << "\n"; + cout << "Pictures: " << p.getPicturesFolder() << "\n"; + cout << "Music: " << p.getMusicFolder() << "\n"; + cout << "Video: " << p.getVideoFolder() << "\n"; + cout << "Download: " << p.getDownloadFolder1() << "\n"; + cout << "Save Games 1: " << p.getSaveGamesFolder1() << "\n"; return 0; } ``` diff --git a/platform_folders.cpp b/platform_folders.cpp index bb6ff9e..bcfd00c 100644 --- a/platform_folders.cpp +++ b/platform_folders.cpp @@ -27,21 +27,23 @@ #include #include "sago/platform_folders.h" -using namespace std; -using namespace sago; - int main() { - cout << "Config: " << getConfigHome() << endl; - cout << "Data: " << getDataHome() << endl; - cout << "Cache: " << getCacheDir() << endl; - PlatformFolders p; - cout << "Documents: " << p.getDocumentsFolder() << endl; - cout << "Desktop: " << p.getDesktopFolder() << endl; - cout << "Pictures: " << p.getPicturesFolder() << endl; - cout << "Music: " << p.getMusicFolder() << endl; - cout << "Video: " << p.getVideoFolder() << endl; - cout << "Download: " << p.getDownloadFolder1() << endl; - cout << "Save Games 1: " << p.getSaveGamesFolder1() << endl; + std::cout << "Config: " << sago::getConfigHome() << "\n"; + std::cout << "Data: " << sago::getDataHome() << "\n"; + std::cout << "Cache: " << sago::getCacheDir() << "\n"; + sago::PlatformFolders p; + std::cout << "Documents: " << p.getDocumentsFolder() << "\n"; + std::cout << "Desktop: " << p.getDesktopFolder() << "\n"; + std::cout << "Pictures: " << p.getPicturesFolder() << "\n"; + std::cout << "Music: " << p.getMusicFolder() << "\n"; + std::cout << "Video: " << p.getVideoFolder() << "\n"; + std::cout << "Download: " << p.getDownloadFolder1() << "\n"; + std::cout << "Save Games 1: " << p.getSaveGamesFolder1() << "\n"; + std::vector extraData; + sago::appendAdditionalDataDirectories(extraData); + for (size_t i=0; i < extraData.size(); ++i) { + std::cout << "Additional data " << i << ": " << extraData.at(i) << "\n"; + } return 0; } diff --git a/sago/platform_folders.cpp b/sago/platform_folders.cpp index 4aa637d..8559ec8 100644 --- a/sago/platform_folders.cpp +++ b/sago/platform_folders.cpp @@ -132,9 +132,9 @@ static std::string getLinuxFolderDefault(const char* envName, const char* defaul } static void appendExtraFoldersTokenizer(const char* envName, const char* envValue, std::vector& folders) { - std::vector buffer(envValue, envValue + strlen(envValue)); + std::vector buffer(envValue, envValue + strlen(envValue) + 1); char *saveptr; - const char* p = strtok_r (buffer.data(), ":", &saveptr); + const char* p = strtok_r ( &buffer[0], ":", &saveptr); while (p != NULL) { if (p[0] == '/') { folders.push_back(p); diff --git a/sago/platform_folders.h b/sago/platform_folders.h index fddee5c..008aa2b 100644 --- a/sago/platform_folders.h +++ b/sago/platform_folders.h @@ -92,10 +92,10 @@ void appendAdditionalDataDirectories(std::vector& homes); * This does not normally include the path returned by GetConfigHome(). * If you want all the folders you should do something like: * @code{.cpp} - * vector folders; - * folders.push_back(getConfigHome()); - * appendAdditionalConfigDirectories(folders); - * for (string s& : folders) { + * std::vector folders; + * folders.push_back(sago::getConfigHome()); + * sago::appendAdditionalConfigDirectories(folders); + * for (std::string s& : folders) { * s+="/My Program Name/"; * } * @endcode