moving stuff around
This commit is contained in:
parent
0901ba3a75
commit
236dec903e
3 changed files with 0 additions and 241 deletions
132
main.cpp
132
main.cpp
|
|
@ -1,132 +0,0 @@
|
||||||
#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
57
term.cpp
|
|
@ -1,57 +0,0 @@
|
||||||
#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
52
term.h
|
|
@ -1,52 +0,0 @@
|
||||||
#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 */
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue