This commit is contained in:
kin fuyuki 2025-06-17 23:36:16 -03:00
commit 1f843bcc47
No known key found for this signature in database
GPG key ID: 0E4E8E519FB71401
7 changed files with 356 additions and 0 deletions

13
.SRCINFO Normal file
View file

@ -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

10
.gitignore vendored Normal file
View file

@ -0,0 +1,10 @@
out
*.tmk
.gitattributes
.git
*.exe
tiny
src
*.tar*
*.out
pkg

33
PKGBUILD Normal file
View file

@ -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"
}

59
README.md Normal file
View file

@ -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)

132
main.cpp Normal file
View file

@ -0,0 +1,132 @@
#include <sstream>
#include <string>
#include <fstream>
#include <map>
std::string get(std::string);
std::map<std::string,std::string> variables;
std::map<std::string,int> 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<argc;i++){
if (argv[i][0]=='-'&&argv[i][1]=='w'){i++;
level= std::stoi(argv[i]);
}else{
std::string key="set ";
key.append(std::to_string(i-2)).append("=").append(argv[i]);
set(key);
}}
warning("tiny runner v0.8\n\n\n");
std::fstream fileStream;
fileStream.open(argv[1]);
if (!fileStream.fail()){
std::ifstream infile(argv[1]);
std::string line;
std::string lines;
int mode=-1;
bool infunc=false;
while (std::getline(infile, line))
{
const char * l=line.c_str();
error((char *)l);
if (line.length()!=0){
switch (l[0])
{
case '\\':
if (l[1]=='n'){
call(lines);
lines.clear();}
else{
A(++l);
}
break;
case '%':
lines.append(get(line));
break;
case ';':
break;
case 's':
if (l[1]=='e'&&l[2]=='t'){
call(lines);
lines.clear();
set(line);}
else{
A(" "+line);
}
break;
case ':':
fn(line, infile.cur);
/* code */
default:
A(" "+line);
break;
}
}
}
call(lines);
return 0;
}
error("could not locate file %s",argv[1]);
return 1;
}

57
term.cpp Normal file
View file

@ -0,0 +1,57 @@
#include "term.h"
#include <cstdio>
#include <cstring>
#include <stdarg.h>
#include <string>
#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");
}

52
term.h Normal file
View file

@ -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 */