feat(parser): add platform-specific parsers and argument conventions
Implement platform-specific parsers for Windows, Linux, and macOS Add GNU argument convention implementations Create fake parser for testing purposes Update CMakeLists to include new headers
This commit is contained in:
24
include/parser/platform_headers/linux_parser.hpp
Normal file
24
include/parser/platform_headers/linux_parser.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __linux__
|
||||
#ifndef LINUX_PARSER_HPP
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
#include <argument_parser.hpp>
|
||||
|
||||
namespace argument_parser {
|
||||
class linux_parser : public base_parser {
|
||||
public:
|
||||
linux_parser() {
|
||||
std::ifstream command_line_file{"/proc/self/cmdline"};
|
||||
std::getline(command_line_file, program_name, '\0');
|
||||
for(std::string line; std::getline(command_line_file, line, '\0');) {
|
||||
parsed_arguments.emplace_back(line);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
27
include/parser/platform_headers/macos_parser.hpp
Normal file
27
include/parser/platform_headers/macos_parser.hpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
#ifdef __APPLE__
|
||||
#ifndef MACOS_PARSER_HPP
|
||||
#define MACOS_PARSER_HPP
|
||||
|
||||
#include <argument_parser.hpp>
|
||||
#include <crt_externs.h>
|
||||
#include <string>
|
||||
|
||||
namespace argument_parser {
|
||||
class macos_parser : public base_parser {
|
||||
public:
|
||||
macos_parser() {
|
||||
int argc = *_NSGetArgc();
|
||||
char **argv = *_NSGetArgv();
|
||||
if (argc > 0 && argv != nullptr && argv[0] != nullptr) {
|
||||
program_name = argv[0];
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
if (argv[i] != nullptr) parsed_arguments.emplace_back(argv[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
20
include/parser/platform_headers/windows_parser.hpp
Normal file
20
include/parser/platform_headers/windows_parser.hpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#ifdef _WIN32
|
||||
#ifndef WINDOWS_PARSER_HPP
|
||||
|
||||
#include <argument_parser.hpp>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
namespace argument_parser {
|
||||
class windows_parser : public base_parser {
|
||||
public:
|
||||
windows_parser() {
|
||||
}
|
||||
};
|
||||
|
||||
using parser = windows_parser;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
Reference in New Issue
Block a user