aboutsummarylogtreecommitdiffstats
path: root/main.cpp
blob: 8f75a1c1ee51e69bd42c12e0469b498844acf0eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
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;
}