From 1f843bcc4738cbf097aeb7db3fcfce4a09b2e8fa Mon Sep 17 00:00:00 2001 From: kin fuyuki Date: Tue, 17 Jun 2025 23:36:16 -0300 Subject: [PATCH] aur --- .SRCINFO | 13 ++++++ .gitignore | 10 ++++ PKGBUILD | 33 ++++++++++++++ README.md | 59 ++++++++++++++++++++++++ main.cpp | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++++ term.cpp | 57 +++++++++++++++++++++++ term.h | 52 +++++++++++++++++++++ 7 files changed, 356 insertions(+) create mode 100644 .SRCINFO create mode 100644 .gitignore create mode 100644 PKGBUILD create mode 100644 README.md create mode 100644 main.cpp create mode 100644 term.cpp create mode 100644 term.h diff --git a/.SRCINFO b/.SRCINFO new file mode 100644 index 0000000..10b9eea --- /dev/null +++ b/.SRCINFO @@ -0,0 +1,13 @@ +pkgbase = tiny + pkgdesc = tiny script runner + pkgver = 1.0 + pkgrel = 1 + url = https://github.com/J-K-Tech/tiny + arch = any + license = AGPLv3 + makedepends = gcc + options = !debug + source = https://github.com/J-K-Tech/tiny/archive/refs/tags/1.0.tar.gz + sha256sums = 2af3bfa2937e7452f74895db7e12c60b67000dc9c2e9f1aa1e53f7e1537d2636 + +pkgname = tiny diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..db80f6a --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +out +*.tmk +.gitattributes +.git +*.exe +tiny +src +*.tar* +*.out +pkg diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 0000000..f5bb78b --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,33 @@ +pkgname=tiny + +pkgver=1.0 + +pkgrel=1 + +pkgdesc="tiny script runner" + +arch=('any') + +url="https://crystalsoft.neocities.org" + +license=('AGPL3') + +makedepends=('gcc') + +source=("https://github.com/J-K-Tech/${pkgname}/archive/refs/tags/${pkgver}.tar.gz") + +sha256sums=('2af3bfa2937e7452f74895db7e12c60b67000dc9c2e9f1aa1e53f7e1537d2636') + + +build() { + +cd "${srcdir}/${pkgname}-${pkgver}" +g++ -O3 src/term.cpp src/main.cpp -o tiny + +} + + +package() { +cd "${srcdir}/${pkgname}-${pkgver}" +install -Dm755 tiny "$pkgdir/usr/bin/tiny" +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..a2b7974 --- /dev/null +++ b/README.md @@ -0,0 +1,59 @@ +# Tiny + +A tiny command line interpreter for organizing, you can split huge single line commands into lines and even add comments and variables! + +## Features + +Multi-command: You can make multiple commands in same `.tmk` file by having a line that starts with `\n` + +Comments: You can use comments in the file to your peers or future you remember what you done, also useful to separate sections of a command + +Variables: If a line starts with `%` it will get all the name of it until hit the second `%` and to set variables the line has to start with `set` + +Ignore space: Add `\` at the start of the line so it will not add an space before it. + +(all written in this line after the `\n` and `%var%` will be ignored and be seen as comments) + +## example + +``` +;set variables +set flags=-Os +;compiler +g++ +%flags% + +;files +main.cpp + +;includes +-lstdc++ + +-I/usr/ +;to not add space between /usr/ and include, you add \ so it will be "/usr/include" and not "/usr/ include" +\include + +;output +-o tiny.exe + +;end command +\n +;run tiny +tiny.exe +``` + +# WARNING, THIS PROGRAM HAS STRICT SYNTAX +## The line MUST to have `;`,`set` and `%` as first character to be detected as comment, setter and variable, so you can have it in the command (without being interpreted by Tiny) by adding a space before. + + +# Roadmap + +- Add variables when loading a Tiny script + +- Create functions + +- Stuff people ask for + +# Compatibility + +This is supposed to run anywhere, if it dont work in a platform please warn me (maybe exotic systems with uncommon headers like master system or whatever might not work out of the box... idk.. if it even has a CLI lol) diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..8f75a1c --- /dev/null +++ b/main.cpp @@ -0,0 +1,132 @@ +#include +#include +#include +#include +std::string get(std::string); +std::map variables; +std::map functions; + +#define CALL "" +#ifdef _WIN32 +#undef CALL +#define CALL "call" +#endif + +#ifdef linux +#undef CALL +#define CALL "exec" +#endif + +#ifdef __APPLE__ +#undef CALL +#define CALL "exec" +#endif +#include "term.h" +int call( + std::string lines){ + std::string com; + com.append(CALL); + + success("command:%s\nexecuting\n\n",lines.c_str()); + com.append(lines.c_str()); + + system(com.c_str()); + success("\n\n"); + return 0; +} +ErrorLevel level(1); +int set(std::string setter){ + std::string name=setter.substr(setter.find_first_of(" ")+1,setter.find("=")-4); + std::string value=setter.substr(setter.find("=")+1); + variables[name]=value; + warning("key %s set as value %s\n\n",name.c_str(),value.c_str()); + //success("\nvar: %s\n",variables[name].c_str()); + return 0; +} + +int fn(std::string setter,int pos){ + std::string name=setter.substr(setter.find_first_of(":")+1); + functions[name]=pos; + warning("function %s set in position %i\n\n",name.c_str(),pos); + //success("\nvar: %s\n",variables[name].c_str()); + return 0; +} +std::string get(std::string key){ + std::string k=key.substr(key.find_first_of('%')+1,key.find_last_of('%')-1); + std::string var=variables[k]; + if (var==""){ + error("\ncould not get variable with key \"%s\"\n",k.c_str()); + exit(1); + } + //success("\ngetting variable \"%s\" with key \"%s\"\n",var.c_str(),k.c_str()); + return var; +} + +#define A lines.append +int main(int argc, char *argv[]){ + + for (int i=2;i +#include +#include +#include + +#define ending \ + mixer.append(info); mixer.append("\033[0m\n");\ + const char * finalinfo=mixer.c_str();\ + va_start (arg, finalinfo);\ + vfprintf (stdout, finalinfo, arg);\ + va_end (arg); + +void echo(char * info,...){ + if (level.value==4) + { + va_list arg; + std::string mixer=info; + mixer.append("\n"); + const char * finalinfo=mixer.c_str(); + va_start (arg, finalinfo); + vfprintf (stdout, finalinfo, arg); + va_end (arg);} +} +void warning( char * info,...){ + if (level.value>=1) + { + va_list arg; + std::string mixer=YELLOW;ending +} +} +void error( char * info,...){ + if (level.value>=0) + { + va_list arg; + std::string mixer=BOLDRED;ending +}} +void success(char * info , ...){ + if (level.value>=2) + { + va_list arg; + std::string mixer=GREEN;ending} +} +void message(char * info , ...){ + if (level.value>=3) + { + va_list arg; + std::string mixer=BOLDWHITE;ending} +} +void startup(char* game,char*version){ + + echo("%s %s",game,version); + warning("be warned that"); + error("ERRORS MIGHT OCCUR!!!"); + success("but dont worry"); + message("this is not an error"); +} \ No newline at end of file diff --git a/term.h b/term.h new file mode 100644 index 0000000..668ec3e --- /dev/null +++ b/term.h @@ -0,0 +1,52 @@ +#pragma once +void echo(char* info,...); +void warning( char * info,...); +void error( char * info,...); +void success(char * info , ...); +void message(char * info , ...); +void startup(char* game,char*version); +struct ErrorLevel { + int value; + ErrorLevel(int var){ + + this->value=var; + } + void setvalue(int var){ + this->value=var; + } +}; +extern ErrorLevel level; +/* +-1: none +0: error +1: success +2: warning +3: message +4: echo +*/ + + + + + + + + + +#define WHITE "\033[0m" /* White */ +#define BLACK "\033[30m" /* Black */ +#define RED "\033[31m" /* Red */ +#define GREEN "\033[32m" /* Green */ +#define YELLOW "\033[33m" /* Yellow */ +#define BLUE "\033[34m" /* Blue */ +#define MAGENTA "\033[35m" /* Magenta */ +#define CYAN "\033[36m" /* Cyan */ +#define WHITE "\033[37m" /* White */ +#define BOLDBLACK "\033[1m\033[30m" /* Bold Black */ +#define BOLDRED "\033[1m\033[31m" /* Bold Red */ +#define BOLDGREEN "\033[1m\033[32m" /* Bold Green */ +#define BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */ +#define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */ +#define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */ +#define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */ +#define BOLDWHITE "\033[1m\033[37m" /* Bold White */ \ No newline at end of file