Skip to content

Commit

Permalink
Add setLang() to replace global variables
Browse files Browse the repository at this point in the history
  • Loading branch information
drew5494 committed Nov 25, 2021
1 parent 92ebe8e commit 19d82c7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
10 changes: 6 additions & 4 deletions thegreatsitegenerator/CMakeLists.txt
Expand Up @@ -4,6 +4,8 @@ cmake_minimum_required(VERSION 3.10)
# Name of the project
project(TGSG VERSION 0.1)

configure_file(TGSGConfig.h.in TGSGConfig.h)

# Build for C++17
set(CMAKE_CXX_STANDARD 17)

Expand All @@ -21,11 +23,11 @@ enable_testing()

add_executable(
tgsg
reading-test.cpp
main.cpp
)
target_link_libraries(
tgsg
gtest_main
gtest_main
)
include(GoogleTest)
gtest_discover_tests(tgsg)
#include(GoogleTest)
#gtest_discover_tests(tgsg)
10 changes: 5 additions & 5 deletions thegreatsitegenerator/main.cpp
Expand Up @@ -11,6 +11,10 @@ using namespace std;

int main(int argc, const char** argv)
{
if (argc != 2) {
cerr << "Type -h for more details.\n"; // Identify user
return 1;
}
Reading r;
if (argv[1] == "-h"sv || argv[1] == "--help"sv) {
cout << "Please type -i followed by the name of the the text file or "
Expand All @@ -25,8 +29,7 @@ int main(int argc, const char** argv)
if (argv[3]) {
if (argv[3] == "-l"sv || argv[3] == "--lang"sv) {
if (argv[4] && (argv[4] == "en-ca"sv || argv[4] == "pt-br"sv || argv[4] == "fr"sv)) {
lang = argv[4];
hasLang = true;
r.setLang(argv[4]);
} else {
cerr
<< "Please enter a valid language. Type -h for more details.\n";
Expand Down Expand Up @@ -79,9 +82,6 @@ int main(int argc, const char** argv)
<< "Please enter a valid file name. Type -h for more details.\n"; // Identify user
return 1;
}
} else {
cerr << "Type -h for more details.\n"; // Identify user
return 1;
}
return 0;
}
12 changes: 10 additions & 2 deletions thegreatsitegenerator/reading.h
Expand Up @@ -6,14 +6,22 @@
#include <sys/types.h>

using namespace std;
bool hasLang;
const char* lang;

class Reading {
private:
bool hasLang;
const char* lang;

public:
void readFile(string fname, int type);
void readFolder(string filename, int type);
void setLang(const char* hello);
};
void Reading::setLang(const char* hello)
{
lang = hello;
hasLang = true;
}
void Reading::readFile(string fname, int type)
{
std::ifstream file(fname.c_str());
Expand Down

0 comments on commit 19d82c7

Please sign in to comment.