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
Ruben Dahl 2023-07-30 19:28:18 +02:00
parent 56578fcba7
commit 89715d1e59
3 changed files with 342 additions and 328 deletions

@ -1 +1 @@
Subproject commit 048b26ca2bc63728de46ac2bfd5f3ce907b98fb1
Subproject commit fe9589cc829d69534f7b9db526e3088807469196

View File

@ -68,7 +68,7 @@ static int show_help() {
return 0;
}
int buildinfo() {
static int buildinfo() {
std::cout << "CeeV build " << bright_cyan(bold(GIT_COMMIT_HASH)) << "\n";
std::cout << "Commit date: " << bright_cyan(bold(GIT_COMMIT_DATE)) << "\n";
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) {
size_t start_pos = str.find(from);
if(start_pos == std::string::npos)
if (start_pos == std::string::npos)
return false;
str.replace(start_pos, from.length(), to);
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) {
fs::path config_path = fs::current_path();
std::string line;
@ -112,7 +105,8 @@ struct config_data get_config(bool ignore_err = false) {
if (!config) {
if (!ignore_err) {
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;
}
@ -142,7 +136,8 @@ int create_fs(std::deque<std::string> args) {
if (!fs::is_empty(cwd) &&
((!args.empty() && args[0] != "--force") || args.empty())) {
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;
}
fs::create_directory(cwd / ".ceev", cwd);
@ -165,26 +160,31 @@ int create_fs(std::deque<std::string> args) {
if (version == "")
version = "0.0.1";
config << "version=" << version << '\n';
std::string author = query_author();
if (author == "") {
std::cerr << bg_red(bold("ERROR")) << ": Author cannot be empty.\n";
author = query_author();
}
std::string author, author_email;
std::string host = "";
std::cout << "Author: ";
std::getline(std::cin, author);
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;
while (author.find(' ') != std::string::npos)
replace(author, " ", ".");
std::cout << "Email [" << author << "@example.org]: ";
std::cout << "Email [" << author_email << "@" << host << "]: ";
std::getline(std::cin, email);
if (email == "")
email = author + "@example.org";
email = author_email + "@" + host;
config << "email=" << email << '\n';
config.close();
return 0;
}
int build_project(std::deque<std::string> args) {
std::cout << TODO << ": Function is not made yet.\n";
NYI;
std::cout << "Building project..." << std::endl;
return 0;
}
@ -200,7 +200,7 @@ int run_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;
return 0;
}
@ -255,8 +255,8 @@ int devel_help() {
std::cout << "Tests of SDL2";
// ceev devel --help
std::cout << "\n*\t";
std::cout << GET_PROGRAM_NAME() << " devel " << bright_green("--help") << "/"
<< bright_green("-h") << "\n";
std::cout << GET_PROGRAM_NAME() << " devel " << bright_green("--help")
<< "/" << bright_green("-h") << "\n";
std::cout << "\t\t";
std::cout << "This help page.";
std::cout << std::endl;
@ -282,13 +282,19 @@ int devel_sdl2(std::deque<std::string> args) {
data.email = "user@example.org";
} else
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 == "")
return 1;
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
SDL_Window *window = nullptr;
SDL_Surface *screen_surface = nullptr;
SDL_Surface *img_surface = nullptr;
SDL_Window* window = nullptr;
SDL_Surface* screen_surface = nullptr;
SDL_Surface* img_surface = nullptr;
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
std::cerr << bg_red(bold("ERROR"))
<< ": 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);
if (window == nullptr) {
std::cerr << bg_red(bold("ERROR"))
<< ": Window could not be created! SDL_Error: " << SDL_GetError()
<< std::endl;
<< ": Window could not be created! SDL_Error: "
<< SDL_GetError() << std::endl;
return 1;
}
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) {
std::cout << TODO << ": Function is not made yet.\n";
NYI;
return 1;
}
int main(int argc, char **argv) {
int main(int argc, char** argv) {
if (argc <= 1) {
return usage();
}
if (std::getenv("DEBUG"))
CV_ISDEBUG = true;
std::deque<std::string> args;
for (int i = 1; i < argc; i++)
args.push_back(std::string(argv[i]));

View File

@ -1,8 +1,9 @@
#pragma once
#include <SDL2/SDL.h>
#include <algorithm>
#include <ceev/colors.h>
#include <unistd.h>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <deque>
@ -47,6 +48,12 @@
#define HALTED bg_red(white("HALTED"))
#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;
struct config_data {
@ -59,7 +66,6 @@ static int usage();
static int show_help();
static int buildinfo();
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);
int create_fs(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_sdl2(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);