Added webserver, parse args, A1066

This commit is contained in:
2023-03-22 06:45:51 +05:00
parent dc9a742471
commit 4f74b0a1b8
9 changed files with 272 additions and 68 deletions

28
inc/args.hpp Normal file
View File

@ -0,0 +1,28 @@
#include <cstdio>
#include <string>
#include <algorithm>
class InputParser {
public:
InputParser (int &argc, char **argv){
for (int i=1; i < argc; ++i)
this->tokens.push_back(std::string(argv[i]));
}
/// @author iain
const std::string& getCmdOption(const std::string &option) const{
std::vector<std::string>::const_iterator itr;
itr = std::find(this->tokens.begin(), this->tokens.end(), option);
if (itr != this->tokens.end() && ++itr != this->tokens.end()){
return *itr;
}
static const std::string empty_string("");
return empty_string;
}
/// @author iain
bool cmdOptionExists(const std::string &option) const{
return std::find(this->tokens.begin(), this->tokens.end(), option) != this->tokens.end();
}
private:
std::vector <std::string> tokens;
};

15
inc/colors.hpp Normal file
View File

@ -0,0 +1,15 @@
#ifndef BIT_COLORS_HPP
#define BIT_COLORS_HPP
#define RESET "\033[0m"
#define BLACK "\033[30m"
#define RED "\033[31m"
#define GREEN "\033[32m"
#define YELLOW "\033[33m"
#define BLUE "\033[34m"
#define MAGENTA "\033[35m"
#define CYAN "\033[36m"
#define WHITE "\033[37m"
#define BOLD "\033[1m"
#endif //BIT_COLORS_HPP

View File

@ -1,15 +1,15 @@
#ifndef BITWI2DL_GETOSNAME_H
#define BITWI2DL_GETOSNAME_H
#ifndef BIT_GETOSNAME_H
#define BIT_GETOSNAME_H
#include <string>
std::string getOsName() {
#ifdef _WIN64
return "windows 64-bit";
return "mustdie64";
#elif _WIN32
return "windows 32-bit";
return "mustdie32";
#elif __APPLE__ || __MACH__
return "mac osx";
return "osx";
#elif __linux__
return "linux";
#elif __FreeBSD__

24
inc/macros.hpp Normal file
View File

@ -0,0 +1,24 @@
#include "colors.hpp"
#ifndef BIT_MACROS_HPP
#define BIT_MACROS_HPP
#define INFO(...) std::cout , "[INFO] " , __VA_ARGS__ , std::endl;
#define WARN(...) std::cout , YELLOW , "[WARN] " , __VA_ARGS__ , RESET , std::endl;
#define ERR(...) std::cout , RED , "[ERROR] " , __VA_ARGS__ , RESET , std::endl;
#define CRIT(...) std::cout , BOLD , RED , "[CRIT] " , __VA_ARGS__ , RESET , std::endl;
template <typename T>
std::ostream& operator,(std::ostream& out, const T& t) {
out << t;
return out;
}
//overloaded version to handle all those special std::endl and others...
std::ostream& operator,(std::ostream& out, std::ostream&(*f)(std::ostream&)) {
out << f;
return out;
}
#endif //BIT_MACROS_HPP