diff --git "a/Documentation/RU/Moroz_\320\272\320\276\320\274\320\260\320\275\320\264\321\213.txt" "b/Documentation/RU/Moroz_\320\272\320\276\320\274\320\260\320\275\320\264\321\213.txt" old mode 100644 new mode 100755 diff --git "a/Documentation/RU/\320\230\320\275\321\201\321\202\321\200\321\203\320\272\321\206\320\270\321\217_\321\201\320\276\320\267\320\264\320\260\320\275\320\270\320\265_\320\262\320\275\321\203\321\202\321\200\320\270\320\275\320\265\320\271_\320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\321\213_\320\264\320\273\321\217_ANTbin.txt" "b/Documentation/RU/\320\230\320\275\321\201\321\202\321\200\321\203\320\272\321\206\320\270\321\217_\321\201\320\276\320\267\320\264\320\260\320\275\320\270\320\265_\320\262\320\275\321\203\321\202\321\200\320\270\320\275\320\265\320\271_\320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\321\213_\320\264\320\273\321\217_ANTbin.txt" old mode 100644 new mode 100755 diff --git a/Documentation/logo/ANT_art.svg b/Documentation/logo/ANT_art.svg old mode 100644 new mode 100755 diff --git a/Documentation/logo/ANT_logo.svg b/Documentation/logo/ANT_logo.svg old mode 100644 new mode 100755 diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/Makefile b/Makefile old mode 100644 new mode 100755 index 5568e2c..bdeca2d --- a/Makefile +++ b/Makefile @@ -1,7 +1,8 @@ ARCH ?= x86 CC := gcc + ifeq ($(ARCH),arm64) -CC := aarch64-linux-gnu-gcc +CC := aarch64-suse-linux-gcc endif CFLAGS += -Wall -Wextra -O2 -flto=auto -ffunction-sections -fdata-sections -Iinclude -MMD -MP diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/ant_bin/antf.c b/ant_bin/antf.c old mode 100644 new mode 100755 index 2311fd3..e7ba28f --- a/ant_bin/antf.c +++ b/ant_bin/antf.c @@ -2,16 +2,33 @@ #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], "-yellow") == 0) { + TXT_COLOR = TXT_YELLOW; + } + if (strcmp(args[i], "-green") == 0) { + TXT_COLOR = TXT_GREEN; + } + } + (void)args; prt(stderr, "- ANTFetch 0.6\n"); - prt(stderr, " .--. \n"); - prt(stderr, " |o_o | \n"); - prt(stderr, " |:_/ | \n"); - prt(stderr, " // \\\\ \n"); - prt(stderr, " (| |) \n"); - prt(stderr, " /'\\_ _/`\\ \n"); - prt(stderr, " \\___)=(___/ \n"); - prt(stderr, "- ANTarktida Shell "ANT_VER"\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"); diff --git a/ant_bin/help.c b/ant_bin/help.c old mode 100644 new mode 100755 diff --git a/ant_bin/ptest.c b/ant_bin/ptest.c old mode 100644 new mode 100755 index e2dd265..f41117c --- a/ant_bin/ptest.c +++ b/ant_bin/ptest.c @@ -11,6 +11,17 @@ MRZ_CFILE("test.mrz"); MRZ_CDIR("test"); + MRZ_PFILE("test.mrz", "test = ptest!", 0); + + char *val = MRZ_RFILE("test.mrz", "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; + } + prt(stderr, "\n"); return 0; } diff --git a/ant_bin/ver.c b/ant_bin/ver.c old mode 100644 new mode 100755 diff --git a/include/ANTbin.h b/include/ANTbin.h old mode 100644 new mode 100755 index ecc6d3a..eed557b --- a/include/ANTbin.h +++ b/include/ANTbin.h @@ -16,6 +16,6 @@ int ANTbin_help(char **args); int ANTbin_antf(char **args); int ANTbin_ptest(char **args); - +int ANTbin_cfg(char **args); #endif diff --git a/include/config.h b/include/config.h old mode 100644 new mode 100755 index 3fba59b..89d4252 --- a/include/config.h +++ b/include/config.h @@ -1,8 +1,15 @@ #ifndef CONFIG_H #define CONFIG_H -#define ANT_VER "PRE-Alpha 0.6.0" -#define ANT_BIN_VER "0.4" +#define ANT_VER "PRE-Alpha 0.7.2" +#define ANT_BIN_VER "0.5" #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 old mode 100644 new mode 100755 index c16ac8f..03ff459 --- a/include/moroz.h +++ b/include/moroz.h @@ -1,7 +1,7 @@ #ifndef MOROZ_H #define MOROZ_H -#define MOROZ_VER "0.2" +#define MOROZ_VER "0.4" #include #include @@ -51,5 +51,8 @@ void MRZ_CDIR(const char *dirname); #define MRZ_CDIR(dirname) MRZ_CDIR(dirname) +char *MRZ_RFILE(const char *path, const char *tag); + +void MRZ_PFILE(const char *path, const char *pline, long offset); #endif diff --git a/locale/tyt_poka_nety_necego.txt b/locale/tyt_poka_nety_necego.txt old mode 100644 new mode 100755 diff --git a/src/ANTbin.c b/src/ANTbin.c old mode 100644 new mode 100755 index 131d14f..97e0d4f --- a/src/ANTbin.c +++ b/src/ANTbin.c @@ -6,6 +6,7 @@ { "help", ANTbin_help }, { "antf", ANTbin_antf }, { "ptest", ANTbin_ptest }, + { "cfg", ANTbin_cfg }, { NULL, NULL } }; diff --git a/src/init.c b/src/init.c old mode 100644 new mode 100755 index e69de29..ddd1df1 --- a/src/init.c +++ b/src/init.c @@ -0,0 +1,40 @@ +#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_host = getenv("HOSTNAME"); + if (sys_host) { + snprintf(ANT_NHOST, sizeof(ANT_NHOST), "%s", sys_host); + } else { + snprintf(ANT_NHOST, sizeof(ANT_NHOST), "%s", "ant_ah"); + } + } 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 old mode 100644 new mode 100755 index d1a6eea..992c53a --- a/src/main.c +++ b/src/main.c @@ -5,10 +5,12 @@ #include #include #include +#include "moroz.h" #include "config.h" #include "ANTbin.h" -char *usr_name = "PIN"; +extern char ANT_NAME[64]; +extern char ANT_NHOST[64]; char **parse_line(char *line) { char **args = malloc(MAX_ARGS * sizeof(char *)); @@ -31,7 +33,13 @@ int main(void) { char prompt[128]; - snprintf(prompt, sizeof(prompt), "\033[1;36m%s@ant_sh -> \033[0m", usr_name); + if (!init()) { + fprintf(stderr, TXT_RED "Initialization failed. Exiting...\n" TXT_RESET); + return 1; + } + + + snprintf(prompt, sizeof(prompt), "\033[1;36m%s@%s -> \033[0m", ANT_NAME, ANT_NHOST); while (1) { @@ -56,10 +64,7 @@ } if (strcmp(args[0], "sys") == 0) { - if (args[1]) { - int status = system(args[1]); - (void)status; - } + if (args[1]) system(args[1]); free(args); free(line); continue; diff --git a/src/moroz/moroz.c b/src/moroz/moroz.c old mode 100644 new mode 100755 index 5c9474a..434fa11 --- a/src/moroz/moroz.c +++ b/src/moroz/moroz.c @@ -27,28 +27,47 @@ } } -char *MRF_RFILE(const char *patch, const char *tag) { - FILE *file = fopen(patch, "r"); - if (!file) { - return NULL; - } +char *MRZ_RFILE(const char *path, const char *tag) { + FILE *file = fopen(path, "r"); + if (!file) return NULL; - char *line = NULL; - size_t len = 0; - char tag_line[64] = {0}; - char *result = NULL; + char line[128]; + char key[64], val[64]; + static char result[64]; + result[0] = '\0'; - char format[128]; - snprintf(format, sizeof(format), "%s %%63s", tag); - - while (getline(&line, &len, file) != -1) { - if (sscanf(line, format, tag_line) == 1) { - result = strdup(tag_line); - break; + while (fgets(line, sizeof(line), file)) { + if (sscanf(line, "%63s = %63s", key, val) == 2) { + if (strcmp(key, tag) == 0) { + strncpy(result, val, sizeof(result) - 1); + result[sizeof(result) - 1] = '\0'; + fclose(file); + return result; + } } } - free(line); fclose(file); - return result; + return NULL; +} + +void MRZ_PFILE(const char *path, const char *pline, long offset) { + FILE *ffile = fopen(path, "r+"); + if (!ffile) { + fprintf(stderr, TXT_RED "ERROR !\n" TXT_RESET); + return; + } + + if (offset < 0) { + fseek(ffile, 0, SEEK_END); + } else { + fseek(ffile, offset, SEEK_SET); + } + + fprintf(ffile, "%s\n", pline); + + fflush(ffile); + fsync(fileno(ffile)); + + fclose(ffile); }