Skip to content

Commit 3016a44

Browse files
committed
Initial commit - v0.0.1
0 parents  commit 3016a44

File tree

16 files changed

+721
-0
lines changed

16 files changed

+721
-0
lines changed

install.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
make -C src/
2+
mv src/bin/enma /bin/
3+
echo "installed"

src/include/inc.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <fstream>
2+
#include <filesystem>
3+
#include <iostream>
4+
#include <stdio.h>
5+
#include <vector>
6+
#include <cctype>
7+
#include <algorithm>
8+
9+
struct ccodes {
10+
std::string color_execute_s = "\033[32m";
11+
std::string color_execute_e = "\033[0m";
12+
std::string color_warning_s = "\033[33m";
13+
std::string color_warning_e = "\033[0m";
14+
std::string color_error_s = "\033[31m";
15+
std::string color_error_f = "\033[0m";
16+
};
17+
18+
struct var_struct {
19+
std::vector<std::string> var_name;
20+
std::vector<std::string> var_value;
21+
bool sys_controller = false;
22+
bool target_controller = false;
23+
};
24+
25+
//==
26+
27+
static void set_ter_color(ccodes& color_ref) {
28+
color_ref.color_execute_s = "";
29+
color_ref.color_execute_e = "";
30+
std::string color_warning_s = "";
31+
std::string color_warning_e = "";
32+
color_ref.color_error_s = "";
33+
color_ref.color_error_f = "";
34+
}

src/include/macros.h

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#ifndef MACROS_H
2+
#define MACROS_H
3+
4+
//VER
5+
#define VERSION "v0.0.1"
6+
#define VERSION_OUT "enma version\n"
7+
8+
/* === GENERIC KEYS === */
9+
#define FILE_READ_KEY "enmafile"
10+
#define DEFAULT_ARG "enma"
11+
#define VAR_KEY "!"
12+
#define ASSIGNMENT_KEY '='
13+
#define USE_VAR_START "^"
14+
#define USE_VAR_END "^"
15+
#define COMMENT_KEY "#"
16+
#define DIRECTIVE_KEY "\t"
17+
#define AC_CON_KEY "\t"
18+
#define DEP_KEY "deps->"
19+
#define SILENCE_KEY "@"
20+
21+
/**/
22+
#define UP_TO_DATE_0 "[enma "
23+
#define UP_TO_DATE_1 " is up to date]"
24+
25+
/* === LOGICAL KEYS === */
26+
#define IF_KEY "if->"
27+
#define IFEQ_KEY "ifeq->"
28+
#define ELSE_KEY "else->"
29+
30+
#define DEF_KEY "def->"
31+
32+
/* === ERROR MACROS === */
33+
#define ERROR_FILE_NOT_EXISTS "ec000"
34+
#define EC000 "File not exists"
35+
36+
#define ERROR_TARGET_NOT_EXISTS "ec001"
37+
#define EC001 "Target not exists"
38+
39+
#define ERROR_NULL_VAR_NAME "ec00"
40+
#define EC00 "Var name is null"
41+
42+
#define ERROR_NULL_VALUE "ec01"
43+
#define EC01 "Value is null"
44+
45+
#define ERROR_VAR_NOT_EXISTS "ec02"
46+
#define EC02 "Var not exists"
47+
48+
#define ERROR_DEPS_NOT_EXISTS "ec03"
49+
#define EC03 "One or more missing"
50+
51+
#define ERROR_0 "LINE -> "
52+
#define ERROR_1 " ERROR; "
53+
54+
#define RES_ERROR_0 "[enma directive result -> "
55+
#define RES_ERROR_1 "]"
56+
57+
#endif

src/include/run.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef RUN_H
2+
#define RUN_H
3+
4+
namespace run {
5+
void execute_directive(const std::string& directive, bool silence_control);
6+
std::string execute_command_and_return(const char* command);
7+
bool error_control(const std::string& control_value, const int& error_line, std::string parameter = "");
8+
}
9+
10+
#endif

src/include/utils.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef UTILS_H
2+
#define UTILS_H
3+
4+
namespace str_utils {
5+
std::string ltrim(const std::string& data);
6+
std::string rtrim(const std::string& data);
7+
std::string trim(const std::string& data);
8+
int find_key_index(const std::string& data, std::string key);
9+
int find_index(const std::vector<std::string>& find_index_vector, const std::string& find_index_value);
10+
}
11+
12+
namespace enma_utils {
13+
std::string find_var_name(const std::string& line, char assignment_char);
14+
std::string find_var_value(const std::string& line, char assignment_char);
15+
}
16+
17+
#endif

src/main.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include "inc.h"
2+
#include "run.h"
3+
#include "utils.h"
4+
#include "macros.h"
5+
#include "parser.h"
6+
7+
ccodes color_codes;
8+
var_struct var_struct_ref;
9+
10+
parsers parsers_ref;
11+
12+
int main(int argc, char* argv[]) {
13+
const std::string current_path = std::filesystem::current_path().string();
14+
std::string argument;
15+
16+
if(argc != 2) {argument = DEFAULT_ARG;}
17+
else {argument = argv[1];}
18+
19+
if(argument == "-v" || argument == "--version") {
20+
std::cout << VERSION_OUT << VERSION << "\n";
21+
return 0;
22+
}
23+
24+
const std::string file_path = current_path + "/" + FILE_READ_KEY;
25+
26+
if(std::filesystem::exists(file_path) && !(std::filesystem::is_directory(file_path))) {
27+
// SET SYSTEM AND RUN PARSING
28+
29+
#ifdef _WIN32
30+
set_ter_color(color_codes);
31+
#else
32+
(void)0;
33+
#endif
34+
35+
// RUN PARSING
36+
parsers_ref.main_parser(file_path, argument);
37+
38+
if(var_struct_ref.sys_controller == false) {
39+
return 1;
40+
} return 0;
41+
}else {
42+
run::error_control(ERROR_FILE_NOT_EXISTS, 0);
43+
return 1;
44+
}
45+
}

src/makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
COMPILER = g++
2+
LIBS = include/
3+
SRC = main.cpp parser.cpp utils.cpp run.cpp
4+
TARGET = bin/enma
5+
6+
make:
7+
$(COMPILER) $(SRC) -I$(LIBS) -o $(TARGET)
8+
9+
nt:
10+
x86_64-w64-mingw32-g++ $(SRC) -Ilib/ -o $(TARGET)
11+
12+
run:
13+
./$(TARGET)
14+
15+
clean:
16+
rm $(TARGET)

0 commit comments

Comments
 (0)