change makefile and cleanup code

This commit is contained in:
lucaspalomodevelop 2023-04-13 20:10:36 +02:00
parent ac141ec143
commit cc5235838a
7 changed files with 129 additions and 87 deletions

16
.vscode/settings.json vendored
View File

@ -48,6 +48,20 @@
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"typeinfo": "cpp"
"typeinfo": "cpp",
"compare": "cpp",
"concepts": "cpp",
"ios": "cpp",
"xfacet": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocinfo": "cpp",
"xlocnum": "cpp",
"xmemory": "cpp",
"xstddef": "cpp",
"xstring": "cpp",
"xtr1common": "cpp",
"xtree": "cpp",
"xutility": "cpp"
}
}

View File

@ -1,5 +1,11 @@
all:
g++ -c ./src/main.cpp
g++ -c ./src/command.cpp
g++ -std=c++11 main.o command.o -o ./bin/autom
./bin/autom help
CC = g++
CFLAGS = -std=c++11 -Wall
SRCDIR = ./src
BINDIR = ./bin
$(BINDIR)/main: $(SRCDIR)/main.cpp $(SRCDIR)/command.cpp $(SRCDIR)/inputparser.cpp
$(CC) $(CFLAGS) $^ -o $@
.PHONY: clean
clean:
rm -f $(BINDIR)/autom

View File

@ -1,5 +1,5 @@
#include "command.h"
#include <iostream>
Command::Command() {}

View File

@ -3,6 +3,7 @@
#include <map>
#include <string>
#include <iostream>
class Command
{

38
src/inputparser.cpp Normal file
View File

@ -0,0 +1,38 @@
#include "./inputparser.h"
InputParser::InputParser(int argc, char *argv[])
{
for (int i = 1; i < argc; i++)
{
std::string arg(argv[i]);
if (arg.find("-") == 0)
{
std::string key = arg.substr(1);
if (i + 1 < argc)
{
std::string value(argv[i + 1]);
if (value.find("-") != 0)
{
args[key] = value;
i++;
}
else
{
args[key] = "";
}
}
else
{
args[key] = "";
}
}
}
}
std::string InputParser::getValue(std::string key)
{
return args[key];
}
bool InputParser::hasKey(std::string key)
{
return args.count(key) > 0;
}

View File

@ -1,37 +1,20 @@
#ifndef INPUTPARSER_H
#define INPUTPARSER_H
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
class InputParser
{
std::map<std::string, std::string> args;
public:
InputParser(int argc, char *argv[]) {
for (int i = 1; i < argc; i++) {
std::string arg(argv[i]);
if (arg.find("-") == 0) {
std::string key = arg.substr(1);
if (i + 1 < argc) {
std::string value(argv[i + 1]);
if (value.find("-") != 0) {
args[key] = value;
i++;
} else {
args[key] = "";
}
} else {
args[key] = "";
}
}
}
}
std::string getValue(std::string key) {
return args[key];
}
bool hasKey(std::string key) {
return args.count(key) > 0;
}
public:
InputParser(int argc, char *argv[]);
std::string getValue(std::string key);
bool hasKey(std::string key);
};
#endif // INPUTPARSER_H

View File

@ -2,8 +2,8 @@
int main(int argc, char *argv[])
{
#ifdef _WIN32
#include <direct.h>
_mkdir(dir.c_str());
#else
mkdir(dir.c_str(), 0777);