diff --git a/.gitignore b/.gitignore index 567609b..3c86f7c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ build/ +*~ +.#* +#*# diff --git a/ANT.cfg~ b/ANT.cfg~ deleted file mode 100755 index c6717bd..0000000 --- a/ANT.cfg~ +++ /dev/null @@ -1,4 +0,0 @@ -name = PINgvin -hthn = false -nhost = ANT -welcome = true \ No newline at end of file diff --git a/ant_bin/antf.c~ b/ant_bin/antf.c~ deleted file mode 100755 index b0b654e..0000000 --- a/ant_bin/antf.c~ +++ /dev/null @@ -1,33 +0,0 @@ -#include "moroz.h" -#include "ANTbin.h" - -int ANTbin_antf(char **args) { - const char *TXT_COLOR = TXT_BLUE; - - for (int i = 1; args[i] != NULL; i++) { - if (strcmp(args[i], "-blue") == 0) { - TXT_COLOR = TXT_CYAN; - } - if (strcmp(args[i], "-red") == 0) { - TXT_COLOR = TXT_RED; - } - if (strcmp(args[i], "-blue") == 0) { - TXT_COLOR = TXT_CYAN; - } - } - - (void)args; - prt(stderr, "- ANTFetch 0.6\n"); - prt(stderr, "%s .--. \n", TXT_COLOR); - prt(stderr, "%s |o_o | \n", TXT_COLOR); - prt(stderr, "%s |:_/ | \n", TXT_COLOR); - prt(stderr, "%s // \\\\ \n", TXT_COLOR); - prt(stderr, "%s (| |) \n", TXT_COLOR); - prt(stderr, "%s /'\\_ _/`\\ \n", TXT_COLOR); - prt(stderr, "%s \\___)=(___/ \n", TXT_COLOR); - prt(stderr, TXT_RESET "- ANTarktida Shell "ANT_VER"\n"); - prt(stderr, "- MoRoZ "ANT_BIN_VER"\n"); - prt(stderr, "- GNU/Linux "); - system("uname -r"); - return 0; -} diff --git a/ant_bin/cfg_master.c~ b/ant_bin/cfg_master.c~ deleted file mode 100755 index c713a16..0000000 --- a/ant_bin/cfg_master.c~ +++ /dev/null @@ -1,23 +0,0 @@ -#include "moroz.h" -#include "ANTbin.h" - -int ANTbin_cfg(char **args) { - for (int i = 1; args[i] != NULL; i++) { - if (strcmp(args[i], "-r") == 0 || strcmp(args[i], "--read") == 0) { - system("cat ANT.cfg"); - prt(stderr, "\n"); - } - if (strcmp(args[i], "-c") == 0 || strcmp(args[i], "--check") == 0) { - char *name = MRZ_RFILE("ANT.cfg", "name"); - if (name) { - - } else { - prt(stderr, TXT_RED "No name in config !\n" TXT_RESET); - prt(stderr, "Default name \"pin\"\n"); - } - } - if (strcmp(args[i], "-c") == 0 || strcmp(args[i], "--check") == 0) { - system("cat ANT.cfg"); - } - } -} diff --git a/ant_bin/ptest.c~ b/ant_bin/ptest.c~ deleted file mode 100755 index 487139e..0000000 --- a/ant_bin/ptest.c~ +++ /dev/null @@ -1,43 +0,0 @@ -#include "ANTbin.h" -#include "moroz.h" - -int ANTbin_ptest(char **args) { - (void)args; - prt(stderr, TXT_RED "TEST\n"); - prt(stderr, TXT_BLUE "TEST\n"); - prt(stderr, TXT_YELLOW "TEST\n"); - prt(stderr, TXT_GREEN "TEST\n\n"); - - MRZ_CFILE("test.mrz"); - MRZ_CDIR("test"); - - MRZ_PFILE("test.mrz", "test = ptest.txt") - - char *val = MRZ_RFILE("test.txt", "test"); - - if (val && strcmp(val, "ptest!") == 0) { - prt(stderr, TXT_GREEN "TEST! (Config read success)\n" TXT_RESET); - } else { - prt(stderr, TXT_RED "ERORR: Tag not found or value mismatch\n" TXT_RESET); - return 1; - } - - bool byrn = "true"; - - while (byrn) { - prt(stderr, "rm \"test.mrz\" file ?"); - prt(stderr, "Y/N = "); - char yrn = getchar(); - if (yrn == y || yrn == Y) { - system("rm test.mrz"); - byrn = "false"; - } if else (yrn == n || yrn == N) { - byrn = "false"; - } else { - continue; - } - } - - prt(stderr, "\n"); - return 0; -} diff --git a/include/ANTbin.h~ b/include/ANTbin.h~ deleted file mode 100755 index ecc6d3a..0000000 --- a/include/ANTbin.h~ +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef ANTBIN_H -#define ANTBIN_H - -typedef int (*ANTbin_fn)(char **args); - -typedef struct { - const char *name; - ANTbin_fn fn; -} ANTbin_t; - -extern const ANTbin_t ANTbin[]; - -ANTbin_fn ANTbin_find(const char *name); - -int ANTbin_ver(char **args); -int ANTbin_help(char **args); -int ANTbin_antf(char **args); -int ANTbin_ptest(char **args); - - -#endif diff --git a/include/config.h~ b/include/config.h~ deleted file mode 100755 index bea1010..0000000 --- a/include/config.h~ +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef CONFIG_H -#define CONFIG_H - -#define ANT_VER "PRE-Alpha 0.6.0" -#define ANT_BIN_VER "0.4" -#define MAX_ARGS 64 - -extern char ANT_NAME[64]; -extern char ANT_NHOST[64]; - -#include - -bool init(void); - -#endif diff --git a/include/moroz.h~ b/include/moroz.h~ deleted file mode 100755 index 5106398..0000000 --- a/include/moroz.h~ +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef MOROZ_H -#define MOROZ_H - -#define MOROZ_VER "0.4" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "config.h" - -#define TXT_RESET "\033[0m" /* Сброс всех стилей */ - -#define TXT_BOLD "\033[1m" /* Жирный или же Яркий */ -#define TXT_DIM "\033[2m" /* Тусклый */ -#define TXT_ITALIC "\033[3m" /* Курсив */ -#define TXT_UNDERLINE "\033[4m" /* Подчёркнутый */ -#define TXT_BLINK "\033[5m" /* Мигающий */ -#define TXT_REVERSE "\033[7m" /* Инверсия */ -#define TXT_HIDDEN "\033[8m" /* Скрытый */ -#define TXT_STRIKE "\033[9m" /* Перечёркнутый */ - -#define TXT_RED "\033[0;31m" /* Красный */ -#define TXT_GREEN "\033[0;32m" /* Зеленный */ -#define TXT_YELLOW "\033[0;33m" /* Желтый */ -#define TXT_BLUE "\033[0;34m" /* Синий */ -#define TXT_PURPLE "\033[0;35m" /* Фиолетовый */ -#define TXT_CYAN "\033[0;36m" /* Сине-зеленый */ -#define TXT_WHITE "\033[0;37m" /* Белый */ - -#define TXT_BG_RED "\033[41m" /* Фоновый красный */ -#define TXT_BG_GREEN "\033[42m" /* Фоновый зеленный */ -#define TXT_BG_YELLOW "\033[43m" /* Фоновый желтый */ -#define TXT_BG_BLUE "\033[44m" /* Фоновый синий */ -#define TXT_BG_PURPLE "\033[45m" /* Фоновый фиолетовый */ -#define TXT_BG_CYAN "\033[46m" /* Фоновый сине-зеленый */ -#define TXT_BG_WHITE "\033[47m" /* Фоновый белый */ - -#define prt(stream, ...) fprintf(stream, __VA_ARGS__) - -void MRZ_CFILE(const char *filename); -#define MRZ_CFILE(filename) MRZ_CFILE(filename) - -void MRZ_CDIR(const char *dirname); -#define MRZ_CDIR(dirname) MRZ_CDIR(dirname) - -char *MRZ_RFILE(const char *path, const char *tag); - -#endif diff --git a/src/ANTbin.c~ b/src/ANTbin.c~ deleted file mode 100755 index 131d14f..0000000 --- a/src/ANTbin.c~ +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include "ANTbin.h" - -const ANTbin_t ANTbin[] = { - { "ver", ANTbin_ver }, - { "help", ANTbin_help }, - { "antf", ANTbin_antf }, - { "ptest", ANTbin_ptest }, - { NULL, NULL } -}; - -ANTbin_fn ANTbin_find(const char *name) { - for (int i = 0; ANTbin[i].name != NULL; i++) - if (strcmp(ANTbin[i].name, name) == 0) - return ANTbin[i].fn; - return NULL; -} diff --git a/src/init.c~ b/src/init.c~ deleted file mode 100755 index dd73fc9..0000000 --- a/src/init.c~ +++ /dev/null @@ -1,40 +0,0 @@ -#include "config.h" -#include "moroz.h" - -char ANT_NAME[64] = "pin"; -char ANT_NHOST[64] = "ant_sh"; - -bool init(void) { - char *name = MRZ_RFILE("ANT.cfg", "name"); - if (name) { - snprintf(ANT_NAME, sizeof(ANT_NAME), "%s", name); - } else { - prt(stderr, TXT_RED "No name in config !\n" TXT_RESET); - prt(stderr, "Default name \"pin\"\n"); - } - - char *HTHN = MRZ_RFILE("ANT.cfg", "hthn"); - if (HTHN && strcmp(HTHN, "true") == 0) { - char *sys_user = getenv("USER"); - if (sys_user) { - snprintf(ANT_NHOST, sizeof(ANT_NHOST), "%s", sys_user); - } else { - snprintf(ANT_NHOST, sizeof(ANT_NHOST), "%s", "pin"); - } - } else if (HTHN && strcmp(HTHN, "false") == 0) { - char *nhost = MRZ_RFILE("ANT.cfg", "nhost"); - if (nhost) { - snprintf(ANT_NHOST, sizeof(ANT_NHOST), "%s", nhost); - } else { - prt(stderr, TXT_RED "No custom name host in config !\n" TXT_RESET); - prt(stderr, "Default name \"ant_sh\"\n"); - } - } - - char *welcome = MRZ_RFILE("ANT.cfg", "welcome"); - if (welcome && strcmp(welcome, "true") == 0) { - prt(stderr, "Dobro Pozalivat v " TXT_BLUE "ANT Shell !" TXT_RESET " %s\n", ANT_NAME); - } - - return true; -} diff --git a/src/main.c~ b/src/main.c~ deleted file mode 100755 index 2c002f8..0000000 --- a/src/main.c~ +++ /dev/null @@ -1,98 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include "config.h" -#include "ANTbin.h" - -extern char ANT_NAME[64]; -extern char ANT_NHOST[64]; - -char **parse_line(char *line) { - char **args = malloc(MAX_ARGS * sizeof(char *)); - - if (args == NULL) { - perror("ant_sh: malloc failed"); - return NULL; - } - - int i = 0; - char *token = strtok(line, " \t\n"); - while (token != NULL && i < MAX_ARGS - 1) { - args[i++] = token; - token = strtok(NULL, " \t\n"); - } - args[i] = NULL; - return args; -} - -int main(void) { - char prompt[128]; - - init(void); - - snprintf(prompt, sizeof(prompt), "\033[1;36m%s@%s -> \033[0m", ANT_NAME, ANT_NHOST); - - while (1) { - - char *line = readline(prompt); - - if (line == NULL) { - fprintf(stderr, "\033[1;36m\nDosvidanie...\033[0m\n"); - break; - } - - if (*line == '\0') { - free(line); - continue; - } - - add_history(line); - - char **args = parse_line(line); - if (args == NULL || args[0] == NULL) { - if (args) free(args); - continue; - } - - if (strcmp(args[0], "sys") == 0) { - if (args[1]) system(args[1]); - free(args); - free(line); - continue; - } - - ANTbin_fn fn = ANTbin_find(args[0]); - if (fn) { - fn(args); - free(args); - free(line); - continue; - } - - if (strcmp(args[0], "exit") == 0) { - fprintf(stderr, "\033[1;36mDosvidanie...\033[0m\n"); - free(args); - free(line); - break; - } - - pid_t pid = fork(); - if (pid == 0) { - execvp(args[0], args); - perror("ant_sh"); - _exit(127); - } else if (pid > 0) { - int status; - waitpid(pid, &status, 0); - } - - free(args); - free(line); - } - - return 0; -}