Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/Directory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@
#include <sys/stat.h>
#include <regex> // for substitute

#include <libgen.h> // For dirname()
#include <cstring>


#if defined(_WIN32) && (defined(__MINGW32__) || defined(_MSC_BUILD))
#include <direct.h>
#include <io.h>

#include <windows.h>
#endif // __WINDOWS Mingw or MSVC compiler__


Expand Down Expand Up @@ -138,3 +143,21 @@ bool copyText(const std::string &src, const std::string &dest) {

return srcFile && destFile;
}

// Function to get the directory of the executable
std::string getExecutableDirectory(const char* argv0) {
#if defined(_WIN32) || defined(_WIN64)
// Windows: Use GetModuleFileNameA to get the executable path
char buffer[MAX_PATH];
GetModuleFileNameA(NULL, buffer, MAX_PATH); // Get the path of the executable
std::string path(buffer);
size_t found = path.find_last_of("/\\"); // Find the last '/' or '\\'
return path.substr(0, found); // Return the directory part
#else
// Linux/macOS: Use dirname from <libgen.h> to get the executable directory
char* path = strdup(argv0); // Make a copy of argv[0] because dirname modifies the string
std::string dir = dirname(path);
free(path);
return dir;
#endif
}
1 change: 1 addition & 0 deletions src/Directory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ bool copyBin(const std::string &src, const std::string &dest);

bool copyText(const std::string &src, const std::string &dest);

std::string getExecutableDirectory(const char* executable);

#endif // GARAGEN_DIRECTORY_HPP__
73 changes: 49 additions & 24 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,42 +21,67 @@
#include "ProductToString.hpp"


int main(int argc, char** argv) {

// Default output directory
std::string outputDirectory = "output/";

const std::string executableDir = getExecutableDirectory(argv[0]);
std::string templateDataDirectory = executableDir + "/../data/";

// Check the program arguments
for (int i = 1; i < argc; ++i) {
if (std::strcmp(argv[i], "-o") == 0) {
if (i + 1 < argc) {
outputDirectory = argv[++i]; // Get the next argument as the output directory
} else {
std::cerr << "error: option '-o' requires a directory path" << std::endl;
return EXIT_FAILURE;
}
}
if (std::strcmp(argv[i], "-d") == 0) {
if (i + 1 < argc) {
templateDataDirectory = argv[++i]; // Get the next argument as the data directory
} else {
std::cerr << "error: option '-d' requires a directory path" << std::endl;
return EXIT_FAILURE;
}
}
}

int main(int argc, char** argv){

// check the program arguments
if(argc != 2){
std::cerr << "usage: " << argv[0] << " file.conf" << std::endl;
// Check if the required configuration file argument is provided
if (argc < 2) {
std::cerr << "usage: " << argv[0] << " [-o output_dir] [-d data_dir] file.conf" << std::endl;
std::cerr << "where 'file.conf' is the file that defines your algebra." << std::endl;
return EXIT_FAILURE;;
return EXIT_FAILURE;
}

// configuration file
const std::string configurationFilesDirectory = argv[1];

const std::string templateDataDirectory = "../data/";
const std::string outputDirectory = "output/";
// Configuration file
const std::string configurationFilesDirectory = argv[argc - 1]; // The last argument should be the config file



// read the configuration data
// Read the configuration data
std::cout << "load meta data ..." << std::endl;
// Assuming MetaData class exists as shown in your code snippet
MetaData metaData(configurationFilesDirectory);
metaData.display();

// define the arborescence
// Define the project directory structure
std::cout << "define the project arborescence ..." << std::endl;
std::string projectDirectory = outputDirectory + "garamon_" + metaData.namespaceName;
std::string srcDirectoryMain = projectDirectory + "/src";
std::string srcDirectory = projectDirectory + "/src/" + metaData.namespaceName;
std::string docDirectory = projectDirectory + "/doc";
std::string docImageDirectory = projectDirectory + "/doc/images";
std::string docHowToDirectory = projectDirectory + "/doc/HOWTO";
std::string sampleDirectory = projectDirectory + "/sample";
std::string srcSampleDirectory = projectDirectory + "/sample/src";
std::string projectDirectory = outputDirectory + "/garamon_" + metaData.namespaceName;
std::string srcDirectoryMain = projectDirectory + "/src";
std::string srcDirectory = projectDirectory + "/src/" + metaData.namespaceName;
std::string docDirectory = projectDirectory + "/doc";
std::string docImageDirectory = projectDirectory + "/doc/images";
std::string docHowToDirectory = projectDirectory + "/doc/HOWTO";
std::string sampleDirectory = projectDirectory + "/sample";
std::string srcSampleDirectory = projectDirectory + "/sample/src";
std::string moduleSampleDirectory = projectDirectory + "/sample/modules";

// check if the directories are not already existing
if(directoryOrFileExists(projectDirectory)){
std::cout.flush(); // does not fixe the problem of asynchronous output between cout and cerr
// Check if the directories are not already existing
if (directoryOrFileExists(projectDirectory)) {
std::cout.flush(); // Flushing the stream to avoid asynchronous output issues
std::cerr << "error: a data or directory '" << projectDirectory << "' already exists" << std::endl;
return EXIT_FAILURE;
}
Expand Down