Initial commit
This commit is contained in:
commit
ac17ed2067
4
Bobfile
Normal file
4
Bobfile
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
compiler "g++";
|
||||||
|
binary "bob";
|
||||||
|
source "src/main.cpp";
|
||||||
|
compile;
|
153
src/main.cpp
Normal file
153
src/main.cpp
Normal file
|
@ -0,0 +1,153 @@
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
string version = "0.0.1";
|
||||||
|
|
||||||
|
bool isDebug = false;
|
||||||
|
|
||||||
|
void error(string input) {
|
||||||
|
cout << "\033[31mError: \033[39m" << input << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void debug(string input) {
|
||||||
|
if (isDebug) cout << "\033[35mDebug: \033[39m" << input << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void log(string input) {
|
||||||
|
cout << "\033[37mInfo: \033[39m" << input << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
int compile(string compiler, string source, string binary) {
|
||||||
|
string cmd = compiler + " " + source + " -o " + binary;
|
||||||
|
log("Compiling with command " + cmd);
|
||||||
|
return system(cmd.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char* argv[]) {
|
||||||
|
string bobfile;
|
||||||
|
bool bobfileLock = false;
|
||||||
|
for (int i = 1; i < argc; i++) {
|
||||||
|
string currentArg = argv[i];
|
||||||
|
if (currentArg == "--version") {
|
||||||
|
cout << version << endl;
|
||||||
|
return 0;
|
||||||
|
} else if (currentArg == "--help") {
|
||||||
|
cout << "bob" << endl;
|
||||||
|
cout << "Bob is a builder frontend for C and C++." << endl;
|
||||||
|
cout << "Create a Bobfile and follow the documentation online." << endl;
|
||||||
|
cout << "Then, run 'bob' and build your project!" << endl;
|
||||||
|
cout << "Arguments:" << endl;
|
||||||
|
cout << " (filename) Specify a custom bobfile location" << endl;
|
||||||
|
cout << " --help Print out this message" << endl;
|
||||||
|
cout << " --debug Get debug info for bug hunting" << endl;
|
||||||
|
cout << " --version Get Bob's version number" << endl;
|
||||||
|
return 0;
|
||||||
|
} else if (currentArg == "--debug") {
|
||||||
|
isDebug = true;
|
||||||
|
} else if (currentArg.substr(0,2) == "--") {
|
||||||
|
error("Argument " + currentArg + " not understood");
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
if (!bobfileLock) {
|
||||||
|
if (!filesystem::exists(currentArg)) {
|
||||||
|
error("Couldn't find the file " + currentArg);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
bobfile = currentArg;
|
||||||
|
bobfileLock = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bobfile.empty()) {
|
||||||
|
if (!filesystem::exists("Bobfile")) {
|
||||||
|
error("Please provide an argument, or write a Bobfile in the current directory.");
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
bobfile = "Bobfile";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log("Using bobfile " + bobfile);
|
||||||
|
ifstream file(bobfile);
|
||||||
|
string content;
|
||||||
|
string line;
|
||||||
|
while (getline(file, line)) {
|
||||||
|
content += line;
|
||||||
|
}
|
||||||
|
debug("Bobfile content: " + content);
|
||||||
|
|
||||||
|
vector<vector<string>> parsed;
|
||||||
|
vector<string> buffera;
|
||||||
|
string bufferb;
|
||||||
|
bool isString = false;
|
||||||
|
debug("Parsing...");
|
||||||
|
for (long unsigned int i = 0; i < content.size(); i++) {
|
||||||
|
if (content[i] == '"') {
|
||||||
|
debug("String time");
|
||||||
|
isString = !isString;
|
||||||
|
if (!isString && !bufferb.empty()) {
|
||||||
|
buffera.push_back(bufferb);
|
||||||
|
bufferb.clear();
|
||||||
|
}
|
||||||
|
} else if (content[i] == ';') {
|
||||||
|
debug("Next term...");
|
||||||
|
parsed.push_back(buffera);
|
||||||
|
buffera.clear();
|
||||||
|
} else if (content[i] == ' ') {
|
||||||
|
if (!isString) {
|
||||||
|
debug("Next thing...");
|
||||||
|
buffera.push_back(bufferb);
|
||||||
|
bufferb.clear();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
bufferb += content[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
buffera.push_back(bufferb);
|
||||||
|
parsed.push_back(buffera);
|
||||||
|
if (isDebug) {
|
||||||
|
debug("Finished parsing bobfile. Contents:");
|
||||||
|
for (long unsigned int i = 0; i < parsed.size(); i++) {
|
||||||
|
for (long unsigned int j = 0; j < parsed[i].size(); j++) {
|
||||||
|
cout << parsed[i][j] << " ";
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
string compiler;
|
||||||
|
string binary;
|
||||||
|
string source;
|
||||||
|
|
||||||
|
string editingTarget;
|
||||||
|
|
||||||
|
for (int i = 0; i < parsed.size(); i++) {
|
||||||
|
for (int j = 0; j < parsed[i].size(); j++) {
|
||||||
|
debug("Token is " + parsed[i][j]);
|
||||||
|
if (j == 0) {
|
||||||
|
if (parsed[i][j] == "compile") {
|
||||||
|
compile(compiler, source, binary);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
editingTarget = parsed[i][j];
|
||||||
|
debug("Editing target set to " + editingTarget);
|
||||||
|
} else {
|
||||||
|
if (editingTarget == "compiler") {
|
||||||
|
debug("Setting compiler");
|
||||||
|
compiler = parsed[i][j];
|
||||||
|
} else if (editingTarget == "binary") {
|
||||||
|
debug("Setting binary");
|
||||||
|
binary = parsed[i][j];
|
||||||
|
} else if (editingTarget == "source") {
|
||||||
|
debug("Setting source");
|
||||||
|
source = parsed[i][j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user