Starting rework on this project
Starting with refactoring a bunch of stuff, then moving on to the roadmap. Might make a small planner for this as well.master
parent
56578fcba7
commit
89715d1e59
2
ceevlang
2
ceevlang
|
@ -1 +1 @@
|
||||||
Subproject commit 048b26ca2bc63728de46ac2bfd5f3ce907b98fb1
|
Subproject commit fe9589cc829d69534f7b9db526e3088807469196
|
70
src/ceev.cc
70
src/ceev.cc
|
@ -68,7 +68,7 @@ static int show_help() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int buildinfo() {
|
static int buildinfo() {
|
||||||
std::cout << "CeeV build " << bright_cyan(bold(GIT_COMMIT_HASH)) << "\n";
|
std::cout << "CeeV build " << bright_cyan(bold(GIT_COMMIT_HASH)) << "\n";
|
||||||
std::cout << "Commit date: " << bright_cyan(bold(GIT_COMMIT_DATE)) << "\n";
|
std::cout << "Commit date: " << bright_cyan(bold(GIT_COMMIT_DATE)) << "\n";
|
||||||
std::cout << "Commited by: " << bright_cyan(bold(GIT_COMMIT_AUTHOR))
|
std::cout << "Commited by: " << bright_cyan(bold(GIT_COMMIT_AUTHOR))
|
||||||
|
@ -91,19 +91,12 @@ static int show_version() {
|
||||||
|
|
||||||
bool replace(std::string& str, const std::string& from, const std::string& to) {
|
bool replace(std::string& str, const std::string& from, const std::string& to) {
|
||||||
size_t start_pos = str.find(from);
|
size_t start_pos = str.find(from);
|
||||||
if(start_pos == std::string::npos)
|
if (start_pos == std::string::npos)
|
||||||
return false;
|
return false;
|
||||||
str.replace(start_pos, from.length(), to);
|
str.replace(start_pos, from.length(), to);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string query_author() {
|
|
||||||
std::string author;
|
|
||||||
std::cout << "Author: ";
|
|
||||||
std::getline(std::cin, author);
|
|
||||||
return author;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct config_data get_config(bool ignore_err = false) {
|
struct config_data get_config(bool ignore_err = false) {
|
||||||
fs::path config_path = fs::current_path();
|
fs::path config_path = fs::current_path();
|
||||||
std::string line;
|
std::string line;
|
||||||
|
@ -112,7 +105,8 @@ struct config_data get_config(bool ignore_err = false) {
|
||||||
if (!config) {
|
if (!config) {
|
||||||
if (!ignore_err) {
|
if (!ignore_err) {
|
||||||
std::cerr << bg_red(bold("ERROR")) << ": Could not open config\n";
|
std::cerr << bg_red(bold("ERROR")) << ": Could not open config\n";
|
||||||
std::cerr << "Run `ceev init' to create a new project." << std::endl;
|
std::cerr << "Run `ceev init' to create a new project."
|
||||||
|
<< std::endl;
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
@ -142,7 +136,8 @@ int create_fs(std::deque<std::string> args) {
|
||||||
if (!fs::is_empty(cwd) &&
|
if (!fs::is_empty(cwd) &&
|
||||||
((!args.empty() && args[0] != "--force") || args.empty())) {
|
((!args.empty() && args[0] != "--force") || args.empty())) {
|
||||||
std::cerr << bg_red(bold("ERROR")) << ": Folder not empty.\n"
|
std::cerr << bg_red(bold("ERROR")) << ": Folder not empty.\n"
|
||||||
<< "Run the command with `--force' to run anyways" << std::endl;
|
<< "Run the command with `--force' to run anyways"
|
||||||
|
<< std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
fs::create_directory(cwd / ".ceev", cwd);
|
fs::create_directory(cwd / ".ceev", cwd);
|
||||||
|
@ -165,26 +160,31 @@ int create_fs(std::deque<std::string> args) {
|
||||||
if (version == "")
|
if (version == "")
|
||||||
version = "0.0.1";
|
version = "0.0.1";
|
||||||
config << "version=" << version << '\n';
|
config << "version=" << version << '\n';
|
||||||
std::string author = query_author();
|
std::string author, author_email;
|
||||||
if (author == "") {
|
std::string host = "";
|
||||||
std::cerr << bg_red(bold("ERROR")) << ": Author cannot be empty.\n";
|
std::cout << "Author: ";
|
||||||
author = query_author();
|
std::getline(std::cin, author);
|
||||||
}
|
|
||||||
config << "author=" << author << '\n';
|
config << "author=" << author << '\n';
|
||||||
|
char* login = (char*)malloc(sizeof(char*) * 100);
|
||||||
|
getlogin_r(login, 100);
|
||||||
|
author_email = std::string(login);
|
||||||
|
free(login);
|
||||||
|
char* hostname = (char*)malloc(sizeof(char*) * 100);
|
||||||
|
gethostname(hostname, 100);
|
||||||
|
host = std::string(hostname);
|
||||||
|
free(hostname);
|
||||||
std::string email;
|
std::string email;
|
||||||
while (author.find(' ') != std::string::npos)
|
std::cout << "Email [" << author_email << "@" << host << "]: ";
|
||||||
replace(author, " ", ".");
|
|
||||||
std::cout << "Email [" << author << "@example.org]: ";
|
|
||||||
std::getline(std::cin, email);
|
std::getline(std::cin, email);
|
||||||
if (email == "")
|
if (email == "")
|
||||||
email = author + "@example.org";
|
email = author_email + "@" + host;
|
||||||
config << "email=" << email << '\n';
|
config << "email=" << email << '\n';
|
||||||
config.close();
|
config.close();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int build_project(std::deque<std::string> args) {
|
int build_project(std::deque<std::string> args) {
|
||||||
std::cout << TODO << ": Function is not made yet.\n";
|
NYI;
|
||||||
std::cout << "Building project..." << std::endl;
|
std::cout << "Building project..." << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -200,7 +200,7 @@ int run_project(std::deque<std::string> args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int clean_project(std::deque<std::string> args) {
|
int clean_project(std::deque<std::string> args) {
|
||||||
std::cout << TODO << ": Function is not made yet.\n";
|
NYI;
|
||||||
std::cout << "Cleaning project..." << std::endl;
|
std::cout << "Cleaning project..." << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -255,8 +255,8 @@ int devel_help() {
|
||||||
std::cout << "Tests of SDL2";
|
std::cout << "Tests of SDL2";
|
||||||
// ceev devel --help
|
// ceev devel --help
|
||||||
std::cout << "\n*\t";
|
std::cout << "\n*\t";
|
||||||
std::cout << GET_PROGRAM_NAME() << " devel " << bright_green("--help") << "/"
|
std::cout << GET_PROGRAM_NAME() << " devel " << bright_green("--help")
|
||||||
<< bright_green("-h") << "\n";
|
<< "/" << bright_green("-h") << "\n";
|
||||||
std::cout << "\t\t";
|
std::cout << "\t\t";
|
||||||
std::cout << "This help page.";
|
std::cout << "This help page.";
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
@ -282,13 +282,19 @@ int devel_sdl2(std::deque<std::string> args) {
|
||||||
data.email = "user@example.org";
|
data.email = "user@example.org";
|
||||||
} else
|
} else
|
||||||
data = get_config();
|
data = get_config();
|
||||||
|
if (CV_ISDEBUG) {
|
||||||
|
std::cout << "data.name = " << data.name << '\n';
|
||||||
|
std::cout << "data.version = " << data.version << '\n';
|
||||||
|
std::cout << "data.author = " << data.author << '\n';
|
||||||
|
std::cout << "data.email = " << data.email << '\n';
|
||||||
|
}
|
||||||
if (data.name == "")
|
if (data.name == "")
|
||||||
return 1;
|
return 1;
|
||||||
const int SCREEN_WIDTH = 640;
|
const int SCREEN_WIDTH = 640;
|
||||||
const int SCREEN_HEIGHT = 480;
|
const int SCREEN_HEIGHT = 480;
|
||||||
SDL_Window *window = nullptr;
|
SDL_Window* window = nullptr;
|
||||||
SDL_Surface *screen_surface = nullptr;
|
SDL_Surface* screen_surface = nullptr;
|
||||||
SDL_Surface *img_surface = nullptr;
|
SDL_Surface* img_surface = nullptr;
|
||||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||||
std::cerr << bg_red(bold("ERROR"))
|
std::cerr << bg_red(bold("ERROR"))
|
||||||
<< ": SDL could not initialize! SDL_Error: " << SDL_GetError()
|
<< ": SDL could not initialize! SDL_Error: " << SDL_GetError()
|
||||||
|
@ -302,8 +308,8 @@ int devel_sdl2(std::deque<std::string> args) {
|
||||||
SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
|
SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
|
||||||
if (window == nullptr) {
|
if (window == nullptr) {
|
||||||
std::cerr << bg_red(bold("ERROR"))
|
std::cerr << bg_red(bold("ERROR"))
|
||||||
<< ": Window could not be created! SDL_Error: " << SDL_GetError()
|
<< ": Window could not be created! SDL_Error: "
|
||||||
<< std::endl;
|
<< SDL_GetError() << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
screen_surface = SDL_GetWindowSurface(window);
|
screen_surface = SDL_GetWindowSurface(window);
|
||||||
|
@ -329,14 +335,16 @@ int devel_sdl2(std::deque<std::string> args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int devel_lang(std::deque<std::string> args) {
|
int devel_lang(std::deque<std::string> args) {
|
||||||
std::cout << TODO << ": Function is not made yet.\n";
|
NYI;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char** argv) {
|
||||||
if (argc <= 1) {
|
if (argc <= 1) {
|
||||||
return usage();
|
return usage();
|
||||||
}
|
}
|
||||||
|
if (std::getenv("DEBUG"))
|
||||||
|
CV_ISDEBUG = true;
|
||||||
std::deque<std::string> args;
|
std::deque<std::string> args;
|
||||||
for (int i = 1; i < argc; i++)
|
for (int i = 1; i < argc; i++)
|
||||||
args.push_back(std::string(argv[i]));
|
args.push_back(std::string(argv[i]));
|
||||||
|
|
12
src/ceev.h
12
src/ceev.h
|
@ -1,8 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <algorithm>
|
|
||||||
#include <ceev/colors.h>
|
#include <ceev/colors.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <algorithm>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
|
@ -47,6 +48,12 @@
|
||||||
#define HALTED bg_red(white("HALTED"))
|
#define HALTED bg_red(white("HALTED"))
|
||||||
#define STATUS bg_green(bold("STATUS"))
|
#define STATUS bg_green(bold("STATUS"))
|
||||||
|
|
||||||
|
#define WIP std::cout << TODO << ": Function is a work in progress" << std::endl
|
||||||
|
#define NYI \
|
||||||
|
std::cout << TODO << ": Function is not yet implemented" << std::endl
|
||||||
|
|
||||||
|
bool CV_ISDEBUG = false;
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
struct config_data {
|
struct config_data {
|
||||||
|
@ -59,7 +66,6 @@ static int usage();
|
||||||
static int show_help();
|
static int show_help();
|
||||||
static int buildinfo();
|
static int buildinfo();
|
||||||
bool replace(std::string& str, const std::string& from, const std::string& to);
|
bool replace(std::string& str, const std::string& from, const std::string& to);
|
||||||
static std::string query_author();
|
|
||||||
struct config_data get_config(bool ignore_err);
|
struct config_data get_config(bool ignore_err);
|
||||||
int create_fs(std::deque<std::string> args);
|
int create_fs(std::deque<std::string> args);
|
||||||
int build_project(std::deque<std::string> args);
|
int build_project(std::deque<std::string> args);
|
||||||
|
@ -70,4 +76,4 @@ int devel_help();
|
||||||
int devel_roadmap();
|
int devel_roadmap();
|
||||||
int devel_sdl2(std::deque<std::string> args);
|
int devel_sdl2(std::deque<std::string> args);
|
||||||
int devel_lang(std::deque<std::string> args);
|
int devel_lang(std::deque<std::string> args);
|
||||||
int main(int argc, char **argv);
|
int main(int argc, char** argv);
|
||||||
|
|
Loading…
Reference in New Issue