返回列表 发帖

基于CLGO的COOL解释器发布

本帖最后由 happy886rr 于 2017-5-3 12:31 编辑

COOL解释器基于CLGO,但核心架构完全重写了一次,增加按键支持,改进了变量表识别机制,改进了语法体系,总代码量也突破1800行,跟CLGO语法和运行机制不再一样。此次发布的是COOL解释器1.0版。并附上一个测试:希尔波特催眠术。
百度网盘下载:https://pan.baidu.com/s/1i4ZswEL
图片均为外链


希尔波特催眠术脚本
@echo off
mode con cols=100 lines=30
cool "%~f0"
exit
//主函数入口
to main
make :penw=3
for  :a 5 7
(
make :penx=500 :peny=-500
hilbert_curve 1000/(2^:a-1) :a 90
)
for  :a 6 3
(
make :penx=500 :peny=-500
hilbert_curve 1000/(2^:a-1) :a 90
)-1
functions_img 1
exit
//希尔波特曲线
to hilbert_curve :len :recursive_times :angle
if :recursive_times=0
(
stop
)
if :recursive_times/3=1
(
make :penc=rand(15)+1
)
if or :penc=9 :penc=10
(
make :penc=7
)
lt :angle
hilbert_curve :len :recursive_times-1 -:angle
fd :len
rt :angle
hilbert_curve :len :recursive_times-1  :angle
fd :len
hilbert_curve :len :recursive_times-1  :angle
rt :angle  
fd :len  
hilbert_curve :len :recursive_times-1 -:angle
lt :angle
//旋转体系
to functions_img :add
memuse
for :a 1 36000
(
make :penx=0 :peny=0
rote :a
memsee
):add
memoutCOPY
COOL解释器源码(仅支持gcc编译器):
/*
COOL SCRIPT, COPYRIGHT@2017~2019 BY HAPPY, VERSION 1.0
COOL.EXE
LINK: -L./ -lgdi32 -lgdiplus
*/
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <windows.h>
#include <wincon.h>
#include <io.h>
#include <conio.h>
#include <time.h>
#include <gdiplus\gdiplus.h>
//定义isINF和isNAN
#ifndef Nan__
#define Nan__
#define NAN log(-1.0) //无效值NAN
#define isNAN(x) ((x)!=(x))
#define NINF log(0.0) //负无穷大
#define INF -NINF //无穷大
#define PINF -NINF //正无穷大
#define isINF(x) (((x)==PINF)||((x)==NINF))
#define isPINF(x) ((x)==PINF)
#define isNINF(x) ((x)==NINF)
#endif
//声明函数
extern "C" HWND WINAPI GetConsoleWindow();
//使用GDI+
using namespace Gdiplus;
/***************定义宏变量***************/
//堆栈尺寸
#define STACK_SIZE         1024
//循环体最大层数
#define LOOP_LEVELS        64
//变量名最大长度
#define MAX_WORDS_SIZE     64
//绘图系关键词数
#define KEY_SIZE           23
//循环系关键词数
#define CYC_SIZE           5
//逻辑系关键词
#define LGC_SIZE           3
//全局变量解释数
#define GLOBAL_SIZE        18
/***************全局类变量***************/
//主窗区域
RECT     winRECT= {0};
LPRECT   lrRECT;
double   base_X, base_Y;
//主窗句柄
HWND  hCMD;
HWND  hWND2;
HWND  hWND3;
//当前行行号
int   CUR_LINENUM;
//当前行指针
char* CUR_LINEPOINTER;
//画布句柄
HDC   hDC;
HDC   hDC1;
HDC   hDC2;
HDC   hDC3;
//内存变量
char* tRAM;
//缓存容器
char  CacheTain[1024]= {0};
//辅助容器
char  Auxiliary[1024]= {0};
//画线是否可见
BOOL  penMODE=TRUE;
//启用内存背景
BOOL  memMODE=FALSE;
/***************关键词类目***************/
//运算符栈
char   STACK1[STACK_SIZE]= {0};
//逆波兰栈
char   STACK2[STACK_SIZE]= {0};
//浮点数栈
double STACK3[STACK_SIZE]= {0};
//数学函数关键词
static const char* MATH_WORDS[]= {"TIME", "PI", "SQRT", "LG", "LN", "SIN", "COS", "TAN", "ARCSIN", "ARCCOS", "ARCTAN", "DEG", "ABS", "ROUND", "READ", "CEIL", "EXP", "SINH", "COSH", "TANH", "ARCSINH", "ARCCOSH", "ARCTANH", "RAND", "INT", "FACT", NULL};
//绘图系关键词
static const char* KEY_WORDS[]= {"FD", "BK", "LT", "RT", "PU", "PD", "PE", "CS", "PR", "HM", "STOP", "EXIT", "FILL", "TEXT", "WAIT", "ROTE", "MEMUSE", "MEMSEE", "MEMOUT", "MAKE", "SETXY", "OVAL", "RECT"};
static const char  KEY_LLENS[]= {   2,    2,    2,    2,    2,    2,    2,    2,    2,    2,      4,      4,      4,      4,      4,      4,        4,        4,        4,      4,      5,       4,      4};
//循环系关键词
static const char* CYC_WORDS[]= {"IF", "REPEAT", "WHILE", "FOR", "ELIF"};
static const char  CYC_LLENS[]= {   2,        6,       5,     3,      4};
//逻辑系关键词
static const char* LGC_WORDS[]= {"NOT", "AND", "OR"};
static const char  LGC_LLENS[]= {   3,      3,    2};
//定义解释器全局变量
static const char* GLOBAL_WORDS[]= {":PENX", ":PENY", ":HEADING", ":PENB", ":PENW", ":PENC", ":PENS", ":PENA", ":PEN0", ":PEN1", ":PEN2", ":PEN3", ":PEN4", ":PEN5", ":PEN6", ":PEN7", ":PEN8", ":PEN9"};
double  GLOBAL_VALUE[]= {      0,       0,          0,       0,       1,      15,       0,     255,       0,       0,       0,       0,       0,       0,       0,       0,       0,       0};
/***************申明函数类***************/
int     Identify_KeyWords(char* Line, int SENSITIVE_NUM, char** WORDS, const char* endstring);
double  RevPolishCore(const char* expression, int PRO_NUM, char** WORDS, double* VALUE);
/***************RGB 结构体***************/
typedef struct
{
BYTE R;
BYTE G;
BYTE B;
COLORREF VALUE;
} STRGB;
//十六色系数组
STRGB LOGO_RGB[16]=
{
{  0,  0,  0,RGB(  0,  0,  0)}, //黑色
{  0,  0,255,RGB(  0,  0,255)}, //蓝色
{  0,255,  0,RGB(  0,255,  0)}, //绿色
{  0,255,255,RGB(  0,255,255)}, //青色
{255,  0,  0,RGB(255,  0,  0)}, //红色
{238,130,238,RGB(238,130,238)}, //紫兰
{165, 42, 42,RGB(165, 42, 42)}, //棕色
{211,211,211,RGB(211,211,211)}, //浅灰
{169,169,169,RGB(169,169,169)}, //深灰
{173,216,230,RGB(173,216,230)}, //淡蓝
{144,238,144,RGB(144,238,144)}, //浅绿
{224,255,255,RGB(224,255,255)}, //淡青
{248, 29, 56,RGB(248, 29, 56)}, //亮红
{255,  0,255,RGB(255,  0,255)}, //洋紫
{255,255,  0,RGB(255,255,  0)}, //黄色
{255,255,255,RGB(255,255,255)}  //白色
};
/***************辅助函数群***************/
//获取时间
int getTIME(int i)
{
time_t timep;
struct tm *p;
time(&timep);
p=localtime(&timep);
switch(i)
{
case 0:
return p->tm_year+1900;
case 1:
return p->tm_mon+1;
case 2:
return p->tm_mday;
case 3:
return p->tm_hour;
case 4:
return p->tm_min;
case 5:
return p->tm_sec;
default:
break;
}
}
//按键获取
int getKEY(int N,int T)
{
int i,KEY_V,start=clock();
do
{
if(_kbhit())
{
KEY_V=(int)(_getch());
if(KEY_V<97)
{
KEY_V+=32;
}
return KEY_V;
}
for(i=0; i<=N; i++);
}
while((clock()-start)<T);
return -1;
}
//转码函数
static WCHAR  Tainer[1024]= {0};
WCHAR* AnsiToWCHAR(const CHAR* str)
{
if(!str)
{
return NULL;
}
int wLen=MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, -1, NULL, 0);
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, -1, Tainer, wLen);
Tainer[wLen]='\0';
return Tainer;
}
//阶乘函数
long long fact(long long n)
{
return (n<2) ?1 :n*(fact(n-1));
}
//测空字符
inline BOOL isEND(const char c,const char* endstring)
{
if(c=='\0')
{
return TRUE;
}
while(*endstring!='\0')
{
if(c==*(endstring++))
{
return TRUE;
}
}
return FALSE;
}
//过滤行TAB缩进或前空格
char* passNULL(char* Str)
{
if(Str!=NULL)
{
while(*Str=='\t' ||*Str==' ')
{
Str++;
}
}
return Str;
}
//错误反馈
inline int errorEXIT(char* errorTYPE)
{
fprintf(stderr, "[%d]:%s    '%s\n", CUR_LINENUM, errorTYPE, passNULL(CUR_LINEPOINTER));
exit(1);
}
//识别关键字
BOOL isKEY(char* Line, char* key, const char* endstring)
{
char *op=Line, *kp=key;
while(*kp!='\0')
{
if((('a'<= *op && *op<='z')?*op-32:*op) != (('a'<= *kp && *kp<='z')?*kp-32:*kp))
{
break;
}
op++;
kp++;
}
if(
    *kp=='\0' &&
    isEND(*op, endstring)
)
{
return TRUE;
}
return FALSE;
}
//切分变量名
int ARGS(char* Str, char** WORDS, int PRO_NUM, int LineNUM, char* Line)
{
if(PRO_NUM==0)
{
return 0;
}
int i=0;
char* lp=Str;
char* tp;
strtok(lp, " \t");
WORDS[0]=(char*)calloc(MAX_WORDS_SIZE, sizeof(char));
strcpy(WORDS[0], ":\n");
while((++i)<PRO_NUM)
{
if((tp=strtok(NULL, " \t"))==NULL)
{
break;
}
WORDS[i]=(char*)calloc(MAX_WORDS_SIZE, sizeof(char));
strcpy(WORDS[i], tp);
}
//参数不匹配时则退出
if(i<PRO_NUM)
{
errorEXIT("Missing parameter");
}
return i;
}
//切分参数
int ARGP(char* Str, double* WVALUE, int PRO_NUM, char** PRO_WORDS, double* PRO_VALUE)
{
int i=0;
char* tp;
strtok(Str, " \t");
while((tp=strtok(NULL, " \t"))!=NULL && *tp!='\0')
{
WVALUE[++i]=RevPolishCore(tp, PRO_NUM, PRO_WORDS, PRO_VALUE);
}
return i+1;
}
//关键词解析函数
int Identify_KeyWords(char* Line, int SENSITIVE_NUM, char** WORDS, const char* endstring)
{
int SN;
for(SN=0; SN<SENSITIVE_NUM; SN++)
{
char *op=Line, *kp=WORDS[SN];
while(*kp!='\0')
{
if(
    (('a'<= *op && *op<='z')?*op-32:*op) != (('a'<= *kp && *kp<='z')?*kp-32:*kp)
)
{
break;
}
op++;
kp++;
}
if(
    *kp=='\0' &&
    isEND(*op, endstring)
)
{
return SN;
}
}
return -1;
}
/***************计算函数群***************/
//逆波兰核心
double RevPolishCore(const char* expression, int PRO_NUM, char** WORDS, double* VALUE)
{
STACK3[0]=0;
int si, brackets=0;
char   *op=(char*)expression, *S1=STACK1, *S2=STACK2, **key, *cp, *kp;
double *S3=STACK3, di, ni;
//生成逆波兰
while(*op!='\0' && *op!=' ' && *op!='\t')
{
switch(*op)
{
case ' ' :
case '\t':
//过滤空字符
op++;
continue;
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
//识别数学函数关键词
key=(char**)MATH_WORDS;
while(*key !=NULL)
{
cp=op, kp=*key;
//比对关键词字母
while((*cp==*kp||*cp==*kp+32) && *kp!='\0')
{
cp++, kp++;
}
//验证关键词结尾
if( ((*cp<'A')||('Z'<*cp && *cp<'a')||(*cp>'z')) && (*kp=='\0') )
{
op=cp;
break;
}
key++;
}
//构建伪双目
if(*key !=NULL)
{
*(S2++)='.';
*(S2++)=' ';
//伪双目入栈
while( ('A'<=(*S1) && (*S1)<='Z') )
{
*(S2++)=*(S1--);
}
*(++S1)=key-(char**)MATH_WORDS+65;
continue;
}
else
{
//无法识别的数学函数
errorEXIT("Unrecognized math function");
}
break;
case '(':
brackets++;
*(++S1)=*op;
if(*(op+1)=='-' || *(op+1)=='+')
{
*(S2++)='0', *(S2++)=' ';
}
break;
case ')':
brackets--;
while(*S1!='(')
{
*(S2++)=*(S1--);
}
//舍弃'('
S1--;
break;
case '+':
case '-':
while(S1!=STACK1 && *S1!='(')
{
*(S2++)=*(S1--);
}
*(++S1)=*op;
break;
case '^':
//指数符
while( ('A'<=(*S1) && (*S1)<='Z') )
{
*(S2++)=*(S1--);
}
*(++S1)=*op;
break;
case '%':
case '*':
case '/':
while(('A'<=(*S1) && (*S1)<='Z') ||*S1=='%' ||*S1=='*' ||*S1=='/' ||*S1=='^')
{
*(S2++)=*(S1--);
}
*(++S1)=*op;
break;
case ':':
//识别变量 :VAR
for(si=PRO_NUM-1; si>=0-GLOBAL_SIZE; si--)
{
cp=op, kp=(si<0)?(char *)GLOBAL_WORDS[-1-si]:WORDS[si];
//比对变量字母
while((*cp==*kp||*cp==*kp+32) && *kp!='\0')
{
cp++, kp++;
}
//验证变量结尾
if(!(('a'<=*cp && *cp<='z')||('A'<=*cp && *cp<='Z')||('0'<=*cp && *cp<='9')||(*cp=='_' || *cp=='#')) && (*kp=='\0'))
{
op=cp-1;
break;
}
}
//判断变量是否存在
if(si>=0-GLOBAL_SIZE)
{
//变量 :VAR入栈
*(S2++)=':', *(S2++)=si, *(S2++)=' ';
}
else
{
//变量 :VAR无效
errorEXIT("Variable  not exist");
}
break;
default :
if((*op<'0' || *op>'9') && (*op!='.'))
{
//无法识别的数字
errorEXIT("Unrecognized number");
}
//浮点数入栈
while(('0'<=*op && *op<='9') ||*op=='.')
{
*(S2++)=*(op++);
}
op--;
*(S2++)=' ';
break;
}
op++;
}
//验证括号是否闭合
if(brackets)
{
errorEXIT("The brackets '(' or ')' are not closed");
}
//收尾逆波兰
while(S1 !=STACK1)
{
*(S2++)=*(S1--);
}
*S2=' ';
//计算逆波兰
op=STACK2;
while(*op!=' ')
{
switch(*op)
{
case 'A':
if(*S3 <0 || *S3 >5)
{
//time(n)函数需要一个整形自变量介于0到5
errorEXIT("The 'time(n)' requires 'n' between 0 to 5");
}
*(S3-1)=getTIME((int)*S3);
S3--;
break;
case 'B':
*S3=3.1415926535897932;
break;
case 'C':
if(*S3 <0)
{
//负数没有平方根
errorEXIT("Negative numbers have no square root");
}
*(S3-1)=sqrt(*S3);
S3--;
break;
case 'D':
if(*S3 <0)
{
//负数没有对数
errorEXIT("Negative numbers are not logarithmic");
}
*(S3-1)=log10(*S3);
S3--;
break;
case 'E':
if(*S3 <0)
{
//负数没有自然对数
errorEXIT("Negative numbers have no natural logarithms");
}
*(S3-1)=log(*S3);
S3--;
break;
case 'F':
*(S3-1)=sin(*S3);
S3--;
break;
case 'G':
*(S3-1)=cos(*S3);
S3--;
break;
case 'H':
if(*S3==3.1415926535897932/2)
{
//π/2没有正切值
errorEXIT("The pi/2 has no tangent");
}
*(S3-1)=tan(*S3);
S3--;
break;
case 'I':
*(S3-1)=asin(*S3);
S3--;
break;
case 'J':
*(S3-1)=acos(*S3);
S3--;
break;
case 'K':
*(S3-1)=atan(*S3);
S3--;
break;
case 'L':
*(S3-1)=(*S3)*3.1415926535897932/180.0;
S3--;
break;
case 'M':
*(S3-1)=fabs(*S3);
S3--;
break;
case 'N':
*(S3-1)=(*S3<=0)?(int)(*S3-0.5):(int)(*S3+0.5);
S3--;
break;
case 'O':
*(S3-1)=getKEY(50, (int)fabs(*S3));
S3--;
break;
case 'P':
*(S3-1)=ceil(*S3);
S3--;
break;
case 'Q':
*(S3-1)=exp(*S3);
S3--;
break;
case 'R':
*(S3-1)=sinh(*S3);
S3--;
break;
case 'S':
*(S3-1)=cosh(*S3);
S3--;
break;
case 'T':
*(S3-1)=tanh(*S3);
S3--;
break;
case 'U':
*(S3-1)=log(*S3+sqrt((*S3)*(*S3)+1));
S3--;
break;
case 'V':
*(S3-1)=log(*S3+sqrt((*S3)*(*S3)-1));
S3--;
break;
case 'W':
*(S3-1)=log((1+(*S3))/(1-(*S3)))/2;
S3--;
break;
case 'X':
//随机数生成器
if(*S3 <0)
{
//负数不能作为随机数的上限
errorEXIT("A negative number can not be used as a random upper bound");
}
else if(*S3 <2)
{
//小于2的随机数为0~1之间的小数
*(S3-1)=rand() % 1024 /1024.0;
}
else
{
*(S3-1)=rand() % (int)(*S3);
}
S3--;
break;
case 'Y':
*(S3-1)=(int)(*S3);
S3--;
break;
case 'Z':
if(*S3 <0)
{
//负数没有阶乘
errorEXIT("Negative numbers have no factorial");
}
*(S3-1)=fact((*S3));
S3--;
break;
case '+':
*(S3-1)+=*S3;
S3--;
break;
case '-':
*(S3-1)-=*S3;
S3--;
break;
case '*':
*(S3-1)*=*S3;
S3--;
break;
case '%':
case '/':
if(*S3 !=0)
{
if(*op=='%')
{
//取余数
*(S3-1)=(int)*(S3-1) % (int)*S3;
}
else
{
*(S3-1)/=*S3;
}
}
else
{
//除数不能为零
errorEXIT("Divisor is zero error");
}
S3--;
break;
case '^':
if(*(S3-1)==0 && *S3<0)
{
//除数不能为零
errorEXIT("Function pow's divisor is zero error");
}
*(S3-1)=pow(*(S3-1), *S3);
S3--;
break;
case ':':
op++;
*(++S3)=(*op<0)?GLOBAL_VALUE[-1-(*op)]:VALUE[*op];
op++;
break;
default :
//字符串转浮点
di=0, ni=1;
while('0'<=*op && *op<='9')
{
di=10*di+(*op)-'0';
op++;
}
if(*op=='.')
{
op++;
while('0'<=*op && *op<='9')
{
di=10*di+(*op)-'0';
op++, ni*=10;
}
}
*(++S3)=di/ni;
break;
}
op++;
}
if(isINF(*S3)||isNAN(*S3))
{
errorEXIT("Overflow or illegal operation is calculated");
}
//返回计算结果
return *S3;
}
//赋值函数
BOOL AssignMent(const char* exp, int PRO_NUM, char** WORDS, double* VALUE)
{
char *op=(char*)exp, *ep=op, *cp, *kp;
int si, i;
//寻找等号
while(!isEND(*(ep++), "=")) {;}
//查找变量
if(op[0]==':')
{
if(op[1]==':')
{
//循环中的瞬时变量::VAR不可赋值
errorEXIT("The loop variables '::' are not assignable");
}
//识别变量 :VAR
for(si=PRO_NUM-1; si>=0-GLOBAL_SIZE; si--)
{
cp=op, kp=(si<0)?(char *)GLOBAL_WORDS[-1-si]:WORDS[si];
//比对变量字母
while((*cp==*kp||*cp==*kp+32) && *kp!='\0')
{
cp++, kp++;
}
//验证变量结尾
if( ((*cp==' ')||(*cp=='\t')||(*cp=='=')) && (*kp=='\0') )
{
op=cp-1;
break;
}
}
//判断变量是否存在
if(si>=0-GLOBAL_SIZE)
{
//笔属性变量赋值
if(si<0)
{
i=-1-si;
GLOBAL_VALUE[i]=RevPolishCore(ep, PRO_NUM, WORDS, VALUE);
STRGB* bgRGB;
HBRUSH m_brush;
switch(i)
{
case 3:
if(GLOBAL_VALUE[i]<0 ||GLOBAL_VALUE[i]>15)
{
//:PENB变量代表背景色,取值只能在0~15之间
errorEXIT("The ':PENB' represents the background color, and only be between 0 to 15");
}
bgRGB=&LOGO_RGB[(int)GLOBAL_VALUE[i]];
//创建画刷
m_brush=CreateSolidBrush(bgRGB->VALUE);
//填充背景
FillRect(hDC1, lrRECT, m_brush);
//删除画刷
DeleteObject(m_brush);
break;
case 4:
if(GLOBAL_VALUE[i]<0 ||GLOBAL_VALUE[i]>99)
{
//:PENW变量代表笔粗细,取值只能在0~99之间
errorEXIT("The ':PENW' represents the width of the pen, and only be between 0 to 99");
}
break;
case 5:
if(GLOBAL_VALUE[i]<0 ||GLOBAL_VALUE[i]>15)
{
//:PENC变量代表笔颜色,取值只能在0~15之间
errorEXIT("The ':PENC' represents the color of the pen, and only be between 0 to 15");
}
break;
case 6:
if(GLOBAL_VALUE[i]<0 ||GLOBAL_VALUE[i]>5)
{
//:PENS变量代表笔光滑,取值只能在0~5之间
errorEXIT("The ':PENS' represents the smooth of the pen, and only be between 0 to 5");
}
break;
case 7:
if(GLOBAL_VALUE[i]<0 ||GLOBAL_VALUE[i]>255)
{
//:PENA变量代表笔透明,取值只能在0~255之间
errorEXIT("The ':PENA' represents the alpha of the pen, and only be between 0 to 255");
}
break;
default:
break;
}
}
else
{
//普通变量赋值
VALUE[si]=RevPolishCore(ep, PRO_NUM, WORDS, VALUE);
}
}
else
{
//无效变量
errorEXIT("Variable  not exist");
}
}
return TRUE;
}
//批量赋值
BOOL MoreAssignMent(const char* Line, int PRO_NUM, char** WORDS, double* VALUE)
{
if(Line[0] !=':')
{
errorEXIT("Variable  not exist");
}
char *gp=(char*)Line;
while(isEND(*gp, ":"))
{
AssignMent(gp, PRO_NUM, WORDS, VALUE);
gp++;
while(!isEND(*gp, " \t\0"))
{
gp++;
}
while(!isEND(*gp, ":\0"))
{
gp++;
}
if(*gp=='\0')
{
return TRUE;
}
}
return TRUE;
}
//测FOR循环
inline BOOL isForTrue(const char* Line, int PRO_NUM, char** WORDS, double* VALUE, int CYC)
{
if(CYC ==0)
{
return TRUE;
}
char *pCHA1, *pCHA2, *pCHA3;
pCHA1=strtok((char*)Line, " \t");
pCHA2=strtok(       NULL, " \t");
pCHA3=strtok(       NULL, " \t");
if(pCHA3 !=NULL)
{
int i=Identify_KeyWords(pCHA1, PRO_NUM, WORDS, " \t");
if(i==-1)
{
errorEXIT("Variable  not exist");
}
int staNUM=RevPolishCore(pCHA2, PRO_NUM, WORDS, VALUE);
int endNUM=RevPolishCore(pCHA3, PRO_NUM, WORDS, VALUE);
int var   =VALUE[i];
if(staNUM-endNUM<0)
{
return (var<=endNUM)?TRUE:FALSE;
}
return (var>=endNUM)?TRUE:FALSE;
}
else
{
errorEXIT("Needs more parameters");
}
}
//真值条件判断
BOOL JudgMent(const char* exp, int PRO_NUM, char** WORDS, double* VALUE)
{
char* op=CacheTain;
char* cp=(char*)exp;
//过滤行TAB缩进或空格
while(*cp=='\t'|| *cp==' ')
{
cp++;
}
if(*cp =='\0')
{
return TRUE;
}
char* Line_Cache=op;
int   i=-1, flag=0;
while(!isEND(*cp, " \t\0"))
{
switch(*cp)
{
case '!':
flag+=8;
break;
case '>':
if(flag==0||flag==8)
{
*(op++)='-', *(op++)='(';
}
flag+=4;
break;
case '<':
if(flag==0||flag==8)
{
*(op++)='-', *(op++)='(';
}
flag+=2;
break;
case '=':
if(flag==0||flag==8)
{
*(op++)='-', *(op++)='(';
}
flag+=1;
break;
default:
*(op++)=*(cp++);
continue;
}
cp++;
}
//闭合括号
*(op++)=(flag!=8)?')':'\0';
*op='\0' ;
float m=RevPolishCore(Line_Cache, PRO_NUM, WORDS, VALUE);
switch(flag)
{
case 8:
//逻辑非
return (m==0)?TRUE:FALSE;
case 4:
return (m >0)?TRUE:FALSE;
break;
case 2:
return (m <0)?TRUE:FALSE;
break;
case 1:
return (m==0)?TRUE:FALSE;
break;
case 3:
case 12:
return (m<=0)?TRUE:FALSE;
break;
case 5:
case 10:
return (m>=0)?TRUE:FALSE;
break;
case 6:
case 9:
return (m!=0)?TRUE:FALSE;
break;
default:
errorEXIT("Wrong logic");
}
}
//批量真值判断
BOOL MoreJudgMent(const char* Line, int PRO_NUM, char** WORDS, double* VALUE)
{
char *gp=(char*)Line;
int li=Identify_KeyWords(gp, LGC_SIZE, (char**)LGC_WORDS, " \t");
if(li !=-1)
{
gp+=LGC_LLENS[li];
}
do
{
while(isEND(*gp, " \t"))
{
gp++;
}
if(JudgMent(gp, PRO_NUM, WORDS, VALUE))
{
switch(li)
{
case 0:
return FALSE;
case 1:
break;
case 2:
return TRUE;
default:
return TRUE;
}
}
else
{
switch(li)
{
case 0:
break;
case 1:
return FALSE;
case 2:
break;
default:
return FALSE;
}
}
while(!isEND(*gp, " \t\0"))
{
gp++;
}
if(*gp=='\0')
{
switch(li)
{
case 0:
return TRUE;
case 1:
return TRUE;
case 2:
return FALSE;
}
}
while(isEND(*gp, " \t"))
{
gp++;
}
}
while(*gp !='\0');
}
//PR输出函数
char* SuperPrintf(const char* pline, int PRO_NUM, char** WORDS, double* VALUE)
{
char* op=(char*)pline;
char* cp;
char* sp=Auxiliary;
while(*op !='\0')
{
switch(*op)
{
case '\\':
switch(*(++op))
{
case 'b':
case 'B':
*(sp++)='\b';
break;
case 'e':
case 'E':
*(sp++)='\0';
break;
case 'r':
case 'R':
*(sp++)='\r';
break;
case 'n':
case 'N':
*(sp++)='\n';
break;
case 't':
case 'T':
*(sp++)='\t';
break;
case '{':
case '}':
*(sp++)=*op;
break;
case '\\':
*(sp++)='\\';
break;
default:
errorEXIT("Uninterpreted characters");
}
break;
case '{':
op++, cp=CacheTain;
while(*op!='\0' && *op!='}')
{
*(cp++)=*(op++);
}
if(*op=='\0')
{
errorEXIT("Missing '}'");
}
*cp='\0';
sprintf(sp, "%.12g", RevPolishCore(CacheTain, PRO_NUM, WORDS, VALUE));
while(*(sp++)!='\0') {;}
sp--;
break;
default:
*(sp++)=*(op);
break;
}
op++;
}
*(sp++)='\n', *(sp++)='\0';
return Auxiliary;
}
/***************绘图函数群***************/
//隐藏光标
BOOL SizeCursor(int size)
{
CONSOLE_CURSOR_INFO cursor_info = {(DWORD)((size==0)?25:size), (size==0)?FALSE:TRUE};
return SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
//平滑画线函数
void drawSMOOTHLINE(HDC hDC, float penWith, SmoothingMode mode, BYTE sharpMODE, BYTE alpha, STRGB* penRGB, float x1, float y1, float x2, float y2, float angel)
{
Graphics gp(hDC);
gp.SetSmoothingMode(mode);
Pen pen(Color(alpha,penRGB->R,penRGB->G,penRGB->B), penWith);
if(angel !=0)
{
Matrix matrix;
matrix.RotateAt(angel, PointF(x1, y1)); // 旋转angel度
gp.SetTransform(&matrix);
}
switch(sharpMODE)
{
case 0:
gp.DrawLine(&pen, PointF(x1, y1), PointF(x2, y2));
break;
case 1:
gp.DrawEllipse(&pen, RectF(x1-x2,y1-y2,x2*2,y2*2));
break;
case 2:
gp.DrawRectangle(&pen, RectF(x1-x2,y1-y2,x2*2,y2*2));
break;
}
DeleteObject(&pen);
}
//画线函数,实现FD
BOOL drawLINE(HDC hDC, float d)
{
float x1=GLOBAL_VALUE[0], y1=GLOBAL_VALUE[1];
GLOBAL_VALUE[0]+=d * sin(GLOBAL_VALUE[2]*0.017453292519943);
GLOBAL_VALUE[1]+=d * cos(GLOBAL_VALUE[2]*0.017453292519943);
//当为PU抬笔时,不做绘图
if(!penMODE)
{
return FALSE;
}
drawSMOOTHLINE(hDC, (float)GLOBAL_VALUE[4], (SmoothingMode)(int)GLOBAL_VALUE[6], 0, (BYTE)GLOBAL_VALUE[7], &LOGO_RGB[(int)GLOBAL_VALUE[5]], base_X+x1, base_Y-y1, base_X+GLOBAL_VALUE[0], base_Y-GLOBAL_VALUE[1], 0);
return TRUE;
}
//退步函数,实现BK
void backWARD(float d)
{
GLOBAL_VALUE[0]-=d * sin(GLOBAL_VALUE[2]*0.017453292519943);
GLOBAL_VALUE[1]-=d * cos(GLOBAL_VALUE[2]*0.017453292519943);
}
//图形旋转
int RotateDC(HDC hDC, double angle)
{
if(angle==0)
{
return 1;
}
XFORM Matrix;
double rad =-angle * 0.017453292519943, rtmp1=base_X+GLOBAL_VALUE[0], rtmp2=base_Y-GLOBAL_VALUE[1];
Matrix.eM11 = (float)cos(rad);
Matrix.eM12 = (float)sin(rad);
Matrix.eM21 =-(float)sin(rad);
Matrix.eM22 = (float)cos(rad);
Matrix.eDx  = (float)(rtmp1-cos(rad)*rtmp1+sin(rad)*rtmp2);
Matrix.eDy  = (float)(rtmp2-cos(rad)*rtmp2-sin(rad)*rtmp1);
SetGraphicsMode(hDC, GM_ADVANCED);
SetWorldTransform(hDC, &Matrix);
return 0;
}
//文字绘制
void drawTEXT(HDC hDC, int fontSIZE, int fontSTYLE, int fontCOLOR, char* fontNAME, char* pSTRING)
{
Graphics graphicsp(hDC), *graph=&graphicsp;
FontFamily fontFAMILY(AnsiToWCHAR(fontNAME));
Font fontp(&fontFAMILY, fontSIZE, (FontStyle)fontSTYLE, UnitPixel);
STRGB* txRGB=&LOGO_RGB[fontCOLOR];
SolidBrush brushp(Color((int)GLOBAL_VALUE[7], txRGB->R, txRGB->G, txRGB->B));
graph->DrawString(AnsiToWCHAR(pSTRING), -1, &fontp, PointF(base_X+GLOBAL_VALUE[0],base_Y-GLOBAL_VALUE[1]), &brushp);
//清理绘图工具
DeleteObject(&brushp);
DeleteObject(&fontp);
DeleteObject(&fontFAMILY);
DeleteObject(&graphicsp);
}
/***************解析函数群***************/
//脚本解析函数
BOOL FileScript(char* prossName, int PRO_NUM, double* PRO_VALUE)
{
//初始参数,其中KLevel为当前循环层号;
int i=0, j=0, ki, KLevel=0, SN=-1, Line_LEN=0, fcolor=-1, BASE_VAR_NUM=PRO_NUM;
float pTMP1, pTMP2, pTMP3, pTMP4, pTMP5, wTIME;
char *prepos=NULL, *pCHA1, *pCHA2, *pCHA3, *pCHA4, *pCHA5;
double tpadd;
//定义过程变量存储容器,即定义 :A型变量,后接 ::A型变量
char** PRO_WORDS=(char**)calloc(LOOP_LEVELS, sizeof(char*));
//初始化开关参数,SFLAG[0]==1开始;
char* SFLAG=(char*)calloc(8, sizeof(char));
SFLAG[2]=-1;
//初始化循环参量数组
int*   FORI_CYCL=(int  *)calloc(LOOP_LEVELS,   sizeof(int  ));
int*   FORI_LNUM=(int  *)calloc(LOOP_LEVELS,   sizeof(int  ));
char** FORI_FTEL=(char**)calloc(LOOP_LEVELS,   sizeof(char*));
char** FORI_FEND=(char**)calloc(LOOP_LEVELS,   sizeof(char*));
BOOL*  FORI_IFOT=(BOOL *)calloc(LOOP_LEVELS,   sizeof(BOOL ));
//分配行容器
char* LCache=(char*)calloc(1025, sizeof(char));
//用于错误反馈的行指针标记
CUR_LINEPOINTER=LCache;
//辅助行指针
char* Line;
//辅助流指针
char* tmpfp=tRAM;
while(*tmpfp !='\0')
{
//记录位置
char* prepos=tmpfp;
//指针置换
Line=LCache;
while(*tmpfp !='\n' && *tmpfp !='\0')
{
*(Line++)=*(tmpfp++);
}
if(*tmpfp =='\n')
{
tmpfp++;
}
*Line='\0';
//指针回首
Line=LCache;
//行计数器
i++, CUR_LINENUM=i;
//过滤行TAB缩进或前空格
while(*Line=='\t'|| *Line==' ')
{
Line++;
}
//过滤空行或行注释
if(
    (Line[0]=='\0')                 ||
    (Line[0]=='/' && Line[1]=='/')
)
{
continue;
}
//过滤段间注释
if(
    (Line[0]=='/' &&Line[1]=='*')
)
{
SFLAG[3]=1;
continue;
}
else if(
    (Line[0]=='*' &&Line[1]=='/')
)
{
SFLAG[3]=0;
continue;
}
//识别子过程名
if(
    (isEND(Line[2], " \t\0") )      &&
    (Line[0]=='T' || Line[0]=='t')  &&
    (Line[1]=='O' || Line[1]=='o')
)
{
Line+=2;
//过滤TO后TAB缩进,或TO后空格
while(*Line=='\t'|| *Line==' ')
{
Line++;
}
if(isKEY(Line, prossName, " \t\0"))
{
SFLAG[0]=1, SFLAG[4]=1;
ARGS(Line, PRO_WORDS, PRO_NUM, i, Line);
}
else
{
SFLAG[0]=0;
}
continue;
}
//开始开关未打开,或遇到段注释,或遇到空行
if(
    SFLAG[0]==0        ||
    SFLAG[3]==1        ||
    Line[0]=='('
)
{
continue;
}
//IF...ELIF连带性分析
if(
    (FORI_IFOT[KLevel+1] && SFLAG[1]==0) &&
    (Line[0]!='E'&&Line[0]!='e')   ||
    (Line[1]!='L'&&Line[1]!='l')   ||
    (Line[2]!='I'&&Line[2]!='i')   ||
    (Line[3]!='F'&&Line[3]!='f')
)
{
FORI_IFOT[KLevel+1]=FALSE;
}
//解析循环结束标签,循环加速
if(Line[0]==')')
{
if(KLevel>SFLAG[1])
{
if(FORI_CYCL[KLevel] <0)
{
tpadd=RevPolishCore(Line+1, PRO_NUM, PRO_WORDS, PRO_VALUE);
PRO_VALUE[0-FORI_CYCL[KLevel]]+=(tpadd==0)?1:tpadd;
}
if(FORI_FEND[KLevel]==NULL)
{
FORI_FEND[KLevel]=tmpfp;
}
tmpfp=FORI_FTEL[KLevel];
i=FORI_LNUM[KLevel];
}
else
{
FORI_FTEL[KLevel]=NULL;
FORI_FEND[KLevel]=NULL;
FORI_CYCL[KLevel]=0;
SFLAG[1]=0;
}
KLevel--;
continue;
}
else
{
if((ki=Identify_KeyWords(Line, CYC_SIZE, (char**)CYC_WORDS, " \t\0")) !=-1)
{
Line=passNULL(Line+CYC_LLENS[ki]);
KLevel++;
//解析循环
if(
    ki==0 && FORI_CYCL[KLevel]<1 && MoreJudgMent(Line, PRO_NUM, PRO_WORDS, PRO_VALUE)                     ||
    ki==1 && FORI_CYCL[KLevel]<RevPolishCore(Line, PRO_NUM, PRO_WORDS, PRO_VALUE)                         ||
    ki==2 && MoreJudgMent(Line, PRO_NUM, PRO_WORDS, PRO_VALUE)                                            ||
    ki==3 && isForTrue(Line, PRO_NUM, PRO_WORDS, PRO_VALUE,  FORI_CYCL[KLevel])                           ||
    ki==4 && (FORI_IFOT[KLevel]) && FORI_CYCL[KLevel]<1 && MoreJudgMent(Line, PRO_NUM, PRO_WORDS, PRO_VALUE)
)
{
if( FORI_FTEL[KLevel]==NULL )
{
FORI_FTEL[KLevel]=prepos;
FORI_LNUM[KLevel]=i-1;
if(ki==3)
{
char *tp1, *tp2;
//提取瞬时变量名
if((tp1=strtok(Line, " \t"))==NULL)
{
errorEXIT("Missing parameter");
}
PRO_WORDS[PRO_NUM]=(char*)calloc(MAX_WORDS_SIZE, sizeof(char));
strcpy(PRO_WORDS[PRO_NUM], tp1);
//提取始步
if((tp2=strtok(NULL, " \t"))==NULL)
{
errorEXIT("Missing parameter");
}
PRO_VALUE[PRO_NUM]=RevPolishCore(tp2, PRO_NUM, PRO_WORDS, PRO_VALUE);
FORI_CYCL[KLevel] =0-PRO_NUM;
PRO_NUM++;
}
if(ki==0 || ki==4)
{
FORI_IFOT[KLevel]=FALSE;
}
}
if(ki !=3)
{
FORI_CYCL[KLevel]  ++;
}
}
else
{
if((ki==0) && FORI_CYCL[KLevel]==0)
{
FORI_IFOT[KLevel]=TRUE;
}
if(FORI_FEND[KLevel] !=NULL)
{
if(FORI_CYCL[KLevel] <0)
{
free(PRO_WORDS[PRO_NUM]);
PRO_NUM-=1;
}
tmpfp=FORI_FEND[KLevel];
i=FORI_LNUM[KLevel]-1;
FORI_FTEL[KLevel]=NULL;
FORI_FEND[KLevel]=NULL;
FORI_CYCL[KLevel]=0;
KLevel--;
}
else
{
SFLAG[1]=KLevel;
}
}
continue;
}
}
//语句块循环开关
if(SFLAG[1]!=0)
{
continue;
}
//解析命令行
if((SN=Identify_KeyWords(Line, KEY_SIZE, (char**)KEY_WORDS, " \t\0")) !=-1)
{
Line=(SN==8)?Line+KEY_LLENS[SN]+1:passNULL(Line+KEY_LLENS[SN]);
}
else
{
//定义过程传参容器
double* PAR_VALUE=(double*)calloc(LOOP_LEVELS, sizeof(double));
//调用子过程
if(! FileScript(Line,    ARGP(Line, PAR_VALUE, PRO_NUM, PRO_WORDS, PRO_VALUE),    PAR_VALUE) )
{
fprintf(stderr, "[%d]:Undefined procedure name    '%s\n", i, passNULL(LCache));
exit(1);
}
free(PAR_VALUE);
continue;
}
switch(SN)
{
case  0:
//FD
drawLINE(hDC, RevPolishCore(Line, PRO_NUM, PRO_WORDS, PRO_VALUE));
break;
case  1:
//BK
backWARD(RevPolishCore(Line, PRO_NUM, PRO_WORDS, PRO_VALUE));
break;
case  2:
//LT
GLOBAL_VALUE[2]-=RevPolishCore(Line, PRO_NUM, PRO_WORDS, PRO_VALUE);
break;
case  3:
//RT
GLOBAL_VALUE[2]+=RevPolishCore(Line, PRO_NUM, PRO_WORDS, PRO_VALUE);
break;
case  4:
//PU
penMODE=FALSE;
break;
case  5:
//PD
if(SFLAG[2] !=-1)
{
GLOBAL_VALUE[5]=SFLAG[2];
SFLAG[2] =-1;
}
penMODE=TRUE;
break;
case  6:
//PE
if(SFLAG[2] ==-1)
{
SFLAG[2]=GLOBAL_VALUE[5];
GLOBAL_VALUE[5]=GLOBAL_VALUE[3];
}
break;
case  7:
//CS
InvalidateRect(hCMD, NULL, FALSE);
GLOBAL_VALUE[0]=GLOBAL_VALUE[1]=GLOBAL_VALUE[2]=0;
break;
case  8:
//PR, 打印输出
fputs(SuperPrintf(Line, PRO_NUM, PRO_WORDS, PRO_VALUE), stdout);
break;
case  9:
//HM
GLOBAL_VALUE[0]=GLOBAL_VALUE[1]=GLOBAL_VALUE[2]=0;
break;
case 10:
//STOP
free(PRO_WORDS);
free(SFLAG);
free(FORI_CYCL);
free(FORI_LNUM);
free(FORI_FTEL);
free(FORI_IFOT);
free(LCache);
return TRUE;
case 11:
//EXIT
exit(0);
case 12:
//FILL
if((fcolor=RevPolishCore(Line, PRO_NUM, PRO_WORDS, PRO_VALUE)) !=-1)
{
//创建画刷
STRGB* bgRGB=&LOGO_RGB[fcolor];
HBRUSH m_brush=CreateSolidBrush(bgRGB->VALUE);
SelectObject(hDC1, m_brush);
ExtFloodFill(hDC1,  base_X+GLOBAL_VALUE[0], base_Y-GLOBAL_VALUE[1],  GetPixel(hDC1,base_X+GLOBAL_VALUE[0],base_Y-GLOBAL_VALUE[1]),FLOODFILLSURFACE);
//删除画刷
DeleteObject(m_brush);
}
break;
case 13:
//TEXT
pCHA1=strtok(Line, " \t"), pCHA2=strtok(NULL, " \t"), pCHA3=strtok(NULL, " \t"), pCHA4=strtok(NULL, " \t"), pCHA5=strtok(NULL, " \t");
if(pCHA5 !=NULL)
{
pTMP1=RevPolishCore(pCHA1, PRO_NUM, PRO_WORDS, PRO_VALUE);
pTMP2=RevPolishCore(pCHA2, PRO_NUM, PRO_WORDS, PRO_VALUE);
pTMP3=RevPolishCore(pCHA3, PRO_NUM, PRO_WORDS, PRO_VALUE);
drawTEXT(hDC, (int)fabs(pTMP1), (int)fabs(pTMP2)%5, (int)fabs(pTMP3)%16, pCHA4, SuperPrintf(pCHA5, PRO_NUM, PRO_WORDS, PRO_VALUE));
}
else
{
errorEXIT("Needs more parameters");
}
break;
case 14:
//WAIT
wTIME=RevPolishCore(Line, PRO_NUM, PRO_WORDS, PRO_VALUE);
if(wTIME>0)
{
Sleep(wTIME);
}
else
{
getch();
}
break;
case 15:
//ROTE
RotateDC(hDC1, (double)RevPolishCore(Line, PRO_NUM, PRO_WORDS, PRO_VALUE));
break;
case 16:
//MEMUSE,开辟内存画布
if(!memMODE)
{
BitBlt(hDC3,0,0,lrRECT->right,lrRECT->bottom, hDC1,0,0,SRCCOPY);
memMODE=TRUE;
}
BitBlt(hDC2,0,0,lrRECT->right,lrRECT->bottom, hDC3,0,0,SRCCOPY);
hDC=hDC2;
break;
case 17:
//MEMSEE,展示内存画布
BitBlt(hDC1,0,0,lrRECT->right,lrRECT->bottom, hDC2,0,0,SRCCOPY);
BitBlt(hDC2,0,0,lrRECT->right,lrRECT->bottom, hDC3,0,0,SRCCOPY);
break;
case 18:
//MEMOUT,丢弃内存画布
memMODE=FALSE;
hDC=hDC1;
break;
case 19:
//MAKE,  赋值
MoreAssignMent(passNULL(Line), PRO_NUM, PRO_WORDS, PRO_VALUE);
break;
case 20:
//SETXY,画线函数
pCHA1=strtok(Line, " \t"), pCHA2=strtok(NULL, " \t");
if(pCHA2 !=NULL)
{
pTMP1=RevPolishCore(pCHA1, PRO_NUM, PRO_WORDS, PRO_VALUE);
pTMP2=RevPolishCore(pCHA2, PRO_NUM, PRO_WORDS, PRO_VALUE);
if(penMODE)
{
drawSMOOTHLINE(hDC, (float)GLOBAL_VALUE[4], (SmoothingMode)(int)GLOBAL_VALUE[6], 0, (BYTE)GLOBAL_VALUE[7], &LOGO_RGB[(int)GLOBAL_VALUE[5]], base_X+GLOBAL_VALUE[0], base_Y-GLOBAL_VALUE[1], base_X+pTMP1, base_Y-pTMP2, 0);
}
GLOBAL_VALUE[0]=pTMP1, GLOBAL_VALUE[1]=pTMP2;
}
else
{
errorEXIT("Needs more parameters");
}
break;
case 21:
//RECT,画方函数
pCHA1=strtok(Line, " \t"), pCHA2=strtok(NULL, " \t"), pCHA3=strtok(NULL, " \t");
if(pCHA3 !=NULL)
{
pTMP1=RevPolishCore(pCHA1, PRO_NUM, PRO_WORDS, PRO_VALUE);
pTMP2=RevPolishCore(pCHA2, PRO_NUM, PRO_WORDS, PRO_VALUE);
pTMP3=RevPolishCore(pCHA3, PRO_NUM, PRO_WORDS, PRO_VALUE);
drawSMOOTHLINE(hDC, (float)GLOBAL_VALUE[4], (SmoothingMode)(int)GLOBAL_VALUE[6], 1, (BYTE)GLOBAL_VALUE[7], &LOGO_RGB[(int)GLOBAL_VALUE[5]], base_X+GLOBAL_VALUE[0], base_Y-GLOBAL_VALUE[1], pTMP1, pTMP2, pTMP3);
}
else
{
errorEXIT("Needs more parameters");
}
break;
case 22:
//OVAL,画圆函数
pCHA1=strtok(Line, " \t"), pCHA2=strtok(NULL, " \t"), pCHA3=strtok(NULL, " \t");
if(pCHA3 !=NULL)
{
pTMP1=RevPolishCore(pCHA1, PRO_NUM, PRO_WORDS, PRO_VALUE);
pTMP2=RevPolishCore(pCHA2, PRO_NUM, PRO_WORDS, PRO_VALUE);
pTMP3=RevPolishCore(pCHA3, PRO_NUM, PRO_WORDS, PRO_VALUE);
drawSMOOTHLINE(hDC, (float)GLOBAL_VALUE[4], (SmoothingMode)(int)GLOBAL_VALUE[6], 2, (BYTE)GLOBAL_VALUE[7], &LOGO_RGB[(int)GLOBAL_VALUE[5]], base_X+GLOBAL_VALUE[0], base_Y-GLOBAL_VALUE[1], pTMP1, pTMP2, pTMP3);
}
else
{
errorEXIT("Needs more parameters");
}
break;
default:
errorEXIT("Error line");
}
}
if(!(BOOL)SFLAG[4])
{
return FALSE;
}
free(PRO_WORDS);
free(SFLAG);
free(FORI_CYCL);
free(FORI_LNUM);
free(FORI_FTEL);
free(FORI_IFOT);
free(LCache);
return TRUE;
}
/*************MAIN主函数入口*************/
int main(int argc, char** argv)
{
if(argc!=2)
{
//异常则抛出使用说明
fputs("COPYRIGHT@2017~2019 BY HAPPY, VERSION 1.0\nUSAGE: COOL [FILE]\n", stdout);
return 1;
}
//读文件流
FILE* fp=fopen(argv[1], "r");
if(fp==NULL)
{
fputs("Failed to read file.", stdout);
return 2;
}
//隐藏光标
SizeCursor(0);
//测量尺寸
int fsize=0;
fseek(fp, 0, SEEK_END);
fsize=ftell(fp);
//指针复原
fseek(fp, 0, SEEK_SET);
//超过1M的脚本,拒绝执行
if(fsize > 1*1024*1024)
{
fputs("File size is too large, out of memory.", stdout);
return 1;
}
//读入内存
tRAM=(char*)malloc((fsize+1)*sizeof(char));
fread(tRAM, fsize, 1, fp);
tRAM[fsize]='\0';
//释放文件
fclose(fp);
//初始化随机种子
srand((unsigned)time(NULL));
//初始化GdiPlus
ULONG_PTR gdipludToken;
GdiplusStartupInput gdiplusInput;
GdiplusStartup(&gdipludToken,&gdiplusInput,NULL);
{
//获取CMD窗口句柄
hCMD=GetConsoleWindow();
//获取CMD窗口大小
lrRECT=&winRECT;
GetClientRect(hCMD, lrRECT);
//获取像素坐标基值
base_X=lrRECT->right/2, base_Y=lrRECT->bottom/2;
lrRECT->right=base_X*2, lrRECT->bottom=base_Y*2;
//CMD画布
hDC1=GetDC(hCMD);
HBITMAP hBitmap1=CreateCompatibleBitmap(hDC1, lrRECT->right, lrRECT->bottom);
SelectObject(hDC1, hBitmap1);
//内存画布
hWND2=NULL;
hDC2=CreateCompatibleDC(GetDC(hWND2));
HBITMAP hBitmap2=CreateCompatibleBitmap(hDC1, lrRECT->right, lrRECT->bottom);
SelectObject(hDC2, hBitmap2);
//辅助画布
hWND3=NULL;
hDC3=CreateCompatibleDC(GetDC(hWND3));
HBITMAP hBitmap3=CreateCompatibleBitmap(hDC1, lrRECT->right, lrRECT->bottom);
SelectObject(hDC3, hBitmap3);
//运行脚本
double* PAR_VALUE=(double*)calloc(LOOP_LEVELS, sizeof(double));
//主DC选择CMD画布
hDC=hDC1;
//寻找主函数入口点
FileScript("MAIN", 1, PAR_VALUE);
//释放DC
ReleaseDC(NULL, hDC3);
ReleaseDC(NULL, hDC2);
ReleaseDC(hCMD, hDC1);
DeleteDC(hDC3);
DeleteDC(hDC2);
DeleteDC(hDC1);
DeleteObject(hBitmap3);
DeleteObject(hBitmap2);
DeleteObject(hBitmap1);
//释放内存
free(PAR_VALUE);
free(tRAM);
}
//关闭GdiPlus
GdiplusShutdown(gdipludToken);
return 0;
}COPY
1

评分人数

    • 老刘1号: 沉迷于绘图无法自拔的happy兄技术 + 1

返回列表