标题: powerimg一款图显脚本解释器 [打印本页]
作者: happy886rr 时间: 2016-11-27 20:02 标题: powerimg一款图显脚本解释器
本帖最后由 happy886rr 于 2016-11-27 20:05 编辑
POWERIMG.EXE
_____________________________________________________________________________
powerimg是一款强大的控制台图显脚本解释器,支持jpg、png、bmp等多种图片格式
该脚本解析器具有类似批处理的标签、跳转、循环、CALL等语法。完全是逐行解释
逐行运行,与批处理的解释机制非常相似,但语法风格略有不同,所有关键字一律
只有3个字符。
_____________________________________________________________________________
下载图片存为a.zip解压即是。
-----------------------------------------------------------------------------
主要关键字:(不区分大小写)
"add", "rot", "zom", "rev", "alp", "arg", "img", "slp", "lib", "jmp", "pos",
"exi", "pau", "cls", "tit", "mod", "cot", "mvw", "cal", "eof", "ech", "cur"
ROT [旋转中心x坐标] [旋转中心y坐标] [初始相位角度值] [角度增量]
ZOM [缩放中心x坐标] [缩放中心y坐标] [横向缩放率] [纵向缩放率] [横向缩放率增量] [纵向缩放率增量]
REV [模式值(-2到2)]
ALP [模式值( 0或1)] [R] [G] [B]
ADD [x坐标增量] [y坐标增量] [宽度大小增量] [高度大小增量] [x剪切坐标增量] [y剪切坐标增量] [显示的长度增量] [显示的高度增量]
ARG [x坐标] [y坐标] [宽度大小] [高度大小] [x剪切坐标] [y剪切坐标] [显示的长度] [显示的高度]
IMG [图片名]
JMP [#标签名]
CAL [#标签名]
COT [1|2|4|8] [1|2|4|8] [1|2|4|8] [16|32|64|128]
POS [x] [y]
MVW [x] [y]
CUR [光标尺寸]
SLP [延时毫秒]
其余ECH、PAU、TIT、CLS、EXI、MOD、CAL、均同批处理的echo, pause, title, cls,
exit, mode, con, call.
-----------------------------------------------------------------------------
注释符格式:
行注释 // 行内容
段注释 /*
段内容
*/
-----------------------------------------------------------------------------
自然宏命令:
||start the img script //每个powerimg脚本必须有的,脚本的开始标记
||using desktop window //使用桌面而非控制台来显示
||hide the cursor //隐藏光标
||end the img script //脚本的结束
||eof
-----------------------------------------------------------------------------
库调用格式:
LIB ||[库文件路径] [参数1] |[参数2]
-----------------------------------------------------------------------------
百叶窗示例:
//////////////////////////////////////////////////////
Shutter effects
//////////////////////////////////////////////////////
||start img script
||hide the cursor
[
[
ADD 0 -50
ARG 0 500, 0 0, 0 0, 500 50
IMG test.jpg
ADD 0 -50
ARG 0 550, 500 50
IMG
SLP 3
]10
ADD 0 0, 0 0, 0 50
]18,-1
||eof
-----------------------------------------------------------------------------
旋转图片示例:
//////////////////////////////////////////////////////
Rote effects
//////////////////////////////////////////////////////
||start img script
||hide the cursor
[
ROT 0 0, 0 10
IMG test.jpg
SLP 3
]18,-1
||eof
-----------------------------------------------------------------------------
标签的使用:
//在批处理中:代表标签的开始,但在powerimg中#才是一个标签的开始,goto用JMP代替
//////////////////////////////////////////////////////
Label effects
//////////////////////////////////////////////////////
||start img script
||hide the cursor
#start
ECH 你好!
EOF
JMP #start
CAL #start
||eof
-----------------------------------------------------------------------------
循环的使用:
//在powerimg中中括号就是循环,括号后的数字就是循环的次数
//////////////////////////////////////////////////////
For effects
//////////////////////////////////////////////////////
||start img script
||hide the cursor
[
ECH 循环内容
//8代表循环8次
]8
||eof
-----------------------------------------------------------------------------
英译:
THE CONSOLE DISPLAYS A PICTURE SCRIPT, VERSION 1.0
COPYRIGHT@2016~2018 BY HAPPY
POWERIMG.EXE
USAGE: powerimg [scriptfile]
-----------------------------------------------------------------------------
11/27/2016
核心源码:- /*
- THE CONSOLE DISPLAYS A PICTURE SCRIPT, VERSION 1.0
- POWERIMG.EXE
- COPYRIGHT@2016~2018 BY HAPPY
- LINK: -lgdi32 -lgdiplus -lole32 -lmsimg32
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #include <stdbool.h>
- #include <windows.h>
- #include <wincon.h>
- #include <gdiplus\gdiplus.h>
- #include <io.h>
- #include <conio.h>
- #include <math.h>
- #include <time.h>
-
-
- //定义π值
- #define M_PI 3.14159265358979323846
-
- //定义移位嵌套层数
- #define LOOP_LEVELS 16
- //限制解释关键词数量
- #define SENSITIVE_NUM 22
- //添加关键词(请用小写定义),解释时不区分大小写。
- static const char* KEY_WORDS[]={"add", "rot", "zom", "rev", "alp", "arg", "img", "slp", "lib", "jmp", "pos", "exi", "pau", "cls", "tit", "mod", "cot", "mvw", "cal", "eof", "ech", "cur"};
-
- //申明函数
- HWND WINAPI GetConsoleWindow();
- BOOL WINAPI AlphaBlend(HDC,int,int,int,int,HDC,int,int,int,int,BLENDFUNCTION);
- BOOL WINAPI TransparentBlt(HDC,int,int,int,int,HDC,int,int,int,int,UINT);
- int Drawgif(HWND hCMD, wchar_t* gifFile, int cmd_x, int cmd_y, int size_W, int size_H, int CYCtimes, int playSpeed);
- int FileScript(char* sfile, char* LIB_ARGS[16]);
- WCHAR* AnsiToWCHAR(const char* str);
-
-
- //定义接收整形容器
- int ATOI[16]={0};
- //定义旋转器
- int ROTE[16]={0};
- //定义缩放器
- float ZOOM[16]={0};
- //定义反转器
- int REVE[16]={0};
- //定义透明器
- int ALPH[16]={0};
-
- //设主句柄
- HWND hCMD;
-
- //图形结构体
- typedef struct{
- HBITMAP hBitmap;
- int Width;
- int Height;
- }IMAGE;
- //整形结构体
- typedef struct{
- int x;
- int y;
- }RPOINT;
- //比率结构体
- typedef struct{
- float x;
- float y;
- }RATE;
-
- //移位结构体
- typedef struct{
- long FTEL;
- int CYCL;
- int CADD;
- int LNUM;
- //定义嵌套累加器
- int ADD[16];
- }fori;
-
-
- /***************图形函数群***************/
- //图形旋转
- int RotateDC(HDC hdc, int angle, RPOINT rpoint)
- {
- if(angle==0){return 1;}
- XFORM Matrix;
- double rad =-angle/180.0*M_PI;
- Matrix.eM11 = (float)cos(rad);
- Matrix.eM12 = (float)sin(rad);
- Matrix.eM21 =-(float)sin(rad);
- Matrix.eM22 = (float)cos(rad);
- Matrix.eDx = (float)(rpoint.x-cos(rad)*rpoint.x+sin(rad)*rpoint.y);
- Matrix.eDy = (float)(rpoint.y-cos(rad)*rpoint.y-sin(rad)*rpoint.x);
- SetGraphicsMode(hdc, GM_ADVANCED);
- SetWorldTransform(hdc, &Matrix);
- return 0;
- }
- //图形缩放
- int ZoomDC(HDC hdc, RATE rate, RPOINT rpoint)
- {
- XFORM Matrix;
- Matrix.eM11 = (float)rate.x;
- Matrix.eM12 = (float)0;
- Matrix.eM21 = (float)0;
- Matrix.eM22 = (float)rate.y;
- Matrix.eDx = (float)(rpoint.x-rate.x*rpoint.x);
- Matrix.eDy = (float)(rpoint.y-rate.y*rpoint.y);
- SetGraphicsMode(hdc, GM_ADVANCED);
- SetWorldTransform(hdc, &Matrix);
- return 0;
- }
- //图形反转
- int ReverseDC(HDC hdc, int reverse_mode, IMAGE img)
- {
- XFORM Matrix;
- if (reverse_mode== 1){
- Matrix.eM11 =-(float)1;
- Matrix.eM12 = (float)0;
- Matrix.eM21 = (float)0;
- Matrix.eM22 = (float)1;
- Matrix.eDx = (float)img.Width;
- Matrix.eDy = (float)0;
- }else if(reverse_mode== 2){
- Matrix.eM11 = (float)1;
- Matrix.eM12 = (float)0;
- Matrix.eM21 = (float)0;
- Matrix.eM22 =-(float)1;
- Matrix.eDx = (float)0;
- Matrix.eDy = img.Height;
- }else if(reverse_mode== 0){
- Matrix.eM11 =-(float)1;
- Matrix.eM12 = (float)0;
- Matrix.eM21 = (float)0;
- Matrix.eM22 =-(float)1;
- Matrix.eDx = (float)img.Width;
- Matrix.eDy = (float)img.Height;
- }else if(reverse_mode==-1){
- Matrix.eM11 = (float)0;
- Matrix.eM12 = (float)1;
- Matrix.eM21 = (float)1;
- Matrix.eM22 = (float)0;
- Matrix.eDx = (float)0;
- Matrix.eDy = (float)0;
- }else if(reverse_mode==-2){
- Matrix.eM11 = (float)0;
- Matrix.eM12 = (float)1;
- Matrix.eM21 =-(float)1;
- Matrix.eM22 = (float)0;
- Matrix.eDx = (float)img.Height;
- Matrix.eDy = (float)0;
- }
- SetGraphicsMode(hdc, GM_ADVANCED);
- SetWorldTransform(hdc, &Matrix);
- return 0;
- }
- //图形加载
- IMAGE LoadImg(char* imgFile, int _nWidth, int _nHeight)
- {
- GpImage* thisImage;
- GpGraphics* graphics=NULL;
- ULONG_PTR gdiplusToken;
- IMAGE _img;
- GdiplusStartupInput GSI={1, NULL, false, false};
- HDC hdc=GetDC(NULL);
- HDC hdcMem=CreateCompatibleDC(hdc);
-
- GdiplusStartup(&gdiplusToken, &GSI, NULL);
- GdipLoadImageFromFile(AnsiToWCHAR(imgFile), &thisImage);
- GdipGetImageWidth(thisImage, &_img.Width);
- GdipGetImageHeight(thisImage, &_img.Height);
- if (_nWidth !=0 && _nHeight==0){
- _img.Height=(int)( (_img.Height*1.0 / _img.Width) * (_nWidth ) );
- _img.Width =_nWidth;
- }else if(_nWidth ==0 && _nHeight!=0){
- _img.Width =(int)( (_img.Width*1.0 / _img.Height) * (_nHeight) );
- _img.Height=_nHeight;
- }else if(_nWidth !=0 && _nHeight!=0){
- _img.Width =_nWidth;
- _img.Height=_nHeight;
- }
- _img.hBitmap=CreateCompatibleBitmap(hdc, _img.Width, _img.Height);
-
- SelectObject(hdcMem, _img.hBitmap);
- GdipCreateFromHDC(hdcMem, &graphics);
- GdipDrawImageRectI(graphics, thisImage, 0, 0, _img.Width, _img.Height);
- GdipDisposeImage(thisImage);
- GdipDeleteGraphics(graphics);
- DeleteDC (hdcMem);
- ReleaseDC(NULL, hdc);
- GdiplusShutdown(gdiplusToken);
- return _img;
- }
- //绘图函数
- int DrawImg(
- char* imgfile, //图形文件
- int cmd_x, int cmd_y, //相对于cmd窗口位置
- int size_W, int size_H, //图片的显示宽高
- int src_x, int src_y, //对相原图 截取位置
- int disp_W, int disp_H, //要显示多少宽高
- fori* FORI[LOOP_LEVELS], //循环结构体指针
- int KLevel //循环层号
- ){
-
- IMAGE P=LoadImg(imgfile, size_W, size_H);
- HDC hCUR=GetDC(hCMD);
- HDC hSRC=CreateCompatibleDC(hCUR);
- SelectObject(hSRC, P.hBitmap);
-
- if(ROTE[0]!=0){
- RPOINT rpoint={ROTE[1], ROTE[2]};
- RotateDC(hCUR, ROTE[3]+ROTE[0]*ROTE[4], rpoint);
- }
- if(ZOOM[0]!=0){
- RPOINT rpoint={(int)ZOOM[1], (int)ZOOM[2]};
- if(
- (ZOOM[3]+ZOOM[0]*ZOOM[5])<0 ||
- (ZOOM[4]+ZOOM[0]*ZOOM[6])<0
- ){
- return 1;
- }
- RATE rate={ZOOM[3]+ZOOM[0]*ZOOM[5], ZOOM[4]+ZOOM[0]*ZOOM[6]};
- ZoomDC(hCUR, rate, rpoint);
- }
- if(REVE[0]!=0){
- ReverseDC(hCUR, REVE[1], P);
- }
- if(FORI[KLevel]->ADD[0]!=0){
- int i=0;
- for(i=0; i<=KLevel; i++){
- cmd_x +=FORI[i]->ADD[0] * FORI[i]->ADD[1], cmd_y += FORI[i]->ADD[0] * FORI[i]->ADD[2];
- size_W+=FORI[i]->ADD[0] * FORI[i]->ADD[3], size_H+= FORI[i]->ADD[0] * FORI[i]->ADD[4];
- src_x +=FORI[i]->ADD[0] * FORI[i]->ADD[5], src_y += FORI[i]->ADD[0] * FORI[i]->ADD[6];
- disp_W+=FORI[i]->ADD[0] * FORI[i]->ADD[7], disp_H+= FORI[i]->ADD[0] * FORI[i]->ADD[8];
- }
- }
- disp_W=(disp_W<=0) ?P.Width :disp_W;
- disp_H=(disp_H<=0) ?P.Height :disp_H;
-
- if (ALPH[0]==1 && ALPH[1]==1){
- TransparentBlt(hCUR, cmd_x, cmd_y, disp_W, disp_H, hSRC, src_x, src_y, P.Width, P.Height, RGB(ALPH[2],ALPH[3],ALPH[4]));
- }else if(ALPH[0]==1 && ALPH[1]==0){
- BLENDFUNCTION blendFunction={0, 0, (ALPH[2]==0)?-1:ALPH[2], 1};
- AlphaBlend(hCUR, cmd_x, cmd_y, disp_W, disp_H, hSRC, src_x, src_y, P.Width, P.Height, blendFunction);
- }else if(ALPH[0]==0){
- BitBlt(hCUR, cmd_x, cmd_y, disp_W, disp_H, hSRC, src_x, src_y, SRCCOPY);
- }
-
- ROTE[0]=ZOOM[0]=REVE[0]=ALPH[0]=0;
- FORI[KLevel]->ADD[0]=0;
- DeleteObject(P.hBitmap);
- ReleaseDC(hCMD, hCUR);
- DeleteDC(hSRC);
- return 0;
- }
- //擦图函数
- int CleanImg(
- HWND hd, //句柄
- LONG cmd_x, LONG cmd_y, //起始擦除点,相对于cmd窗口位置的
- LONG size_W, LONG size_H, //要擦除的宽高尺寸
- BOOL mode,
- fori* FORI[LOOP_LEVELS], //循环结构体指针
- int KLevel //循环层号
- ){
- RECT z={cmd_x+FORI[KLevel]->ADD[0]*FORI[KLevel]->ADD[1], cmd_y+FORI[KLevel]->ADD[0]*FORI[KLevel]->ADD[2], cmd_x+size_W+FORI[KLevel]->ADD[0]*FORI[KLevel]->ADD[3], cmd_y+size_H+FORI[KLevel]->ADD[0]*FORI[KLevel]->ADD[4]};
- if(mode){
- InvalidateRect(hd, &z, FALSE);
- }else{
- InvalidateRect(hd, NULL, FALSE);
- }
- return 0;
- }
-
-
- /***************功能函数群***************/
- //子串查找,忽略大小写
- char* stristr(const char* str1, const char* str2)
- {
- char* cp=(char *)str1;
- char* s1, *s2;
- if(!*str2){return (char *)str1;}
- while(*cp){
- s1=cp;
- s2=(char *)str2;
-
- while(
- *s1 &&
- *s2 &&
- !(_tolower(*s1)-_tolower(*s2))
- ){s1++, s2++;}
-
- if (!*s2){return cp;}
- cp++;
- }
- return NULL;
- }
- //转码函数
- WCHAR* AnsiToWCHAR(const char* str)
- {
- if(!str){return NULL;}
- int wLen=MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, -1, NULL, 0);
- WCHAR* wstr=(WCHAR*)malloc(sizeof(WCHAR)*wLen + 1);
- MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, -1, wstr, wLen);
- wstr[wLen]='\0';
- return wstr;
- }
- //显示光标
- void DispyCursor(int size,bool mode)
- {
- CONSOLE_CURSOR_INFO cursor_info ={(DWORD)size, mode};
- SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
- return;
- }
- //移动光标
- int SetPos(int x,int y)
- {
- COORD pos;
- HANDLE hOutput;
- pos.X=x, pos.Y=y;
- hOutput=GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleCursorPosition(hOutput,pos);
- return 0;
- }
- //测空字符
- inline bool isNULL(const char c){
- if(
- c=='\t' ||
- c==' ' ||
- c=='\r' ||
- c=='\n' ||
- c=='\0'
-
- ){
- return true;
- }
- return false;
- }
- //过滤行TAB缩进或前空格
- char* passNULL(char* Str){
- if(Str!=NULL){
- while(*Str=='\t' ||*Str==' '){Str++;}
- }
- return Str;
- }
- //切分参数
- int args(char* Str, char* delims, char* ARGS[16], char* LIB_ARGS[16])
- {
- int i=0;
- char* p;
- ARGS[i]=strtok(Str, delims);
- while(ARGS[i]!=NULL){
- if( (p=stristr(ARGS[i], "*"))!=NULL){
- ARGS[i]=LIB_ARGS[atoi(p+1)];
- }
- ARGS[++i]=strtok(NULL, delims);
- }
- return i;
- }
- //整化参数
- int ATOIargs(int* taner, int MAX_ARGC, int add, char* ARGS[16])
- {
- int j;
- for(j=0; j<16; j++){taner[j]=0;}
- for(j=0; j<MAX_ARGC; j++){
- taner[j+add]=atoi(ARGS[j]);
- }
- return 0;
- }
- //关键词解析函数
- int Identify_KeyWords(const char* Line)
- {
- int i, SN;
- for(SN=0; SN<SENSITIVE_NUM; SN++){
- for(i=0; KEY_WORDS[SN][i]!='\0'; i++){
- if(
- Line[i] !=KEY_WORDS[SN][i] &&
- Line[i]+32!=KEY_WORDS[SN][i]
-
- ){
- break;
- }
- }
- if(
- KEY_WORDS[SN][i]=='\0' &&
- isNULL(Line[i])
- ){
- return SN;
- }
- }
- return 255;
- }
-
- //绘图函数
- int Shell_IMG(char* imgfile, fori* FORI[LOOP_LEVELS], int KLevel, int LineNUM)
- {
- //为空则表示擦除
- if(
- imgfile==NULL ||
- isNULL(imgfile[0])
- ){
- if(ATOI[0]==0){
- CleanImg(hCMD, 0, 0, 0, 0, FALSE, FORI, KLevel);
- }else{
- CleanImg(hCMD, ATOI[1], ATOI[2], ATOI[3], ATOI[4], TRUE, FORI, KLevel);
- }
-
- //否则为图片显示
- }else{
- if(access(imgfile, 0)==-1){
- fprintf(stdout, "[%d]:图片不存在。\n", LineNUM);
- exit(1);
- }
- DrawImg(imgfile, ATOI[1], ATOI[2], ATOI[3], ATOI[4], ATOI[5], ATOI[6], ATOI[7], ATOI[8], FORI, KLevel);
- }
- return 0;
- }
-
-
- /***************Shell函数群***************/
- //清屏函数
- int Shell_CLS()
- {
- HANDLE hConsole=GetStdHandle(STD_OUTPUT_HANDLE);
- COORD coordScreen={0,0};
- DWORD cCharsWritten;
- CONSOLE_SCREEN_BUFFER_INFO csbi;
- GetConsoleScreenBufferInfo(hConsole, &csbi);
- FillConsoleOutputCharacter(hConsole, (TCHAR)' ', csbi.dwSize.X*csbi.dwSize.Y, coordScreen, &cCharsWritten);
- GetConsoleScreenBufferInfo(hConsole, &csbi);
- FillConsoleOutputAttribute(hConsole, csbi.wAttributes, csbi.dwSize.X*csbi.dwSize.Y, coordScreen, &cCharsWritten);
- SetConsoleCursorPosition(hConsole,coordScreen);
- return 0;
- }
- //标题函数
- int Shell_TITLE(char* Str)
- {
- SetConsoleTitle(Str);
- return 0;
- }
- //按键函数
- int Shell_KEY(clock_t delay)
- {
- 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<=50;i++);
- }while((clock()-start)<delay);
- return -1;
- }
- //鼠标点击函数:KEY_V取值1、2对应鼠标左右键点击;当取值为0时则隐藏光标;
- int Shell_MOUSE(int KEY_V)
- {
- if(KEY_V==0){
- CONSOLE_CURSOR_INFO cursor_info={1,0};
- SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);
- return 0;
- }
- HANDLE StdIn=GetStdHandle(STD_INPUT_HANDLE);
- DWORD OrgMode, Res;
- INPUT_RECORD InR;
- GetConsoleMode(StdIn, &OrgMode);
- SetConsoleMode(StdIn, OrgMode | ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT);
- for(;;){
- ReadConsoleInput(StdIn, &InR, 1, &Res);
- if(
- InR.Event.MouseEvent.dwEventFlags ==0 &&
- InR.Event.MouseEvent.dwButtonState==KEY_V
- ){
- SetConsoleMode(StdIn, OrgMode);
- return (InR.Event.MouseEvent.dwMousePosition.Y)*1000+(InR.Event.MouseEvent.dwMousePosition.X);
- }
- }
- }
- //窗口大小
- int Shell_MODE_CON(int x, int y)
- {
-
- HANDLE StdOut=GetStdHandle(STD_OUTPUT_HANDLE);
- CONSOLE_SCREEN_BUFFER_INFO scbi;
- COORD size={x, 300};
- GetConsoleScreenBufferInfo(StdOut, &scbi);
- SetConsoleScreenBufferSize(StdOut, size);
- SMALL_RECT rc={0, 0, x-1, y-1};
- SetConsoleWindowInfo(StdOut, 1, &rc);
- CloseHandle(StdOut);
- return 0;
- }
- //字体颜色: 1,2,4,8前景;16,32,64,128后景;
- int Shell_COLOR(unsigned short A,unsigned short B,unsigned short C,unsigned short D)
- {
- HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE);
- CONSOLE_SCREEN_BUFFER_INFO csbi;
- GetConsoleScreenBufferInfo(handle_out, &csbi);
- SetConsoleTextAttribute(handle_out, A | B | C | D);
- return 0;
- }
- //移动窗口
- int Shell_MW(int x, int y)
- {
- HWND cmd=GetConsoleWindow();
- SetWindowPos(cmd, HWND_TOP, x, y, 0, 0, SWP_NOSIZE);
- return 0;
- }
-
-
- /***************解析函数群***************/
- //脚本解析函数
- int FileScript(char* sfile, char* LIB_ARGS[16])
- {
- //初始参数 KLevel为当前循环层号;
- int i=0, j=0, KLevel=0, Line_LEN=0, MAX_ARGC=0, SN=255;
-
- //读取脚本文件
- FILE* fp;
- if( (fp=fopen(sfile, "rb"))==NULL ){
- fprintf(stdout, "[%d]:读取文件失败。\n", i);
- exit(1);
- }
-
- //初始化开关参数,SFLAG[0]==1开始; SFLAG[1]==1跳转; SFLAG[2]==1 呼叫归位;
- int* SFLAG=(int*)calloc(8, sizeof(int));
-
- //初始化循环结构体
- fori* FORI[LOOP_LEVELS];
- for(j=0; j<LOOP_LEVELS; j++){
- FORI[j]=(fori*)calloc(1, sizeof(FORI));
- FORI[j]->FTEL=(long)0;
- FORI[j]->CYCL=0;
- FORI[j]->LNUM=0;
- FORI[j]->CADD=0;
- FORI[j]->ADD[16]=(int)calloc(16, sizeof(int));
- }
-
- //定义切分字串容器
- char* ARGS[16];
- for(j=0; j<16; j++){
- ARGS[j]=(char*)calloc(128, sizeof(char*));
- }
-
- //分配行容器
- char* LCache=(char*)calloc(1025, sizeof(char));
- //辅助行指针
- char* Line;
-
- //标签跳转指针
- char* JMP_MARK=(char*)malloc(128*sizeof(char));
- //标签呼叫指针
- long CAL_MARK;
-
- while(!feof(fp)){
- memset(LCache, 0, 1024*sizeof(char));
- fgets(LCache, 1024, fp);
-
- //指针置换
- Line=LCache;
-
- //行计数器
- i++;
-
- //过滤行TAB缩进或前空格
- while(*Line=='\t'|| *Line==' '){Line++;}
-
- //过滤注释符
- if(Line[0]=='/' &&Line[1]=='/'){
- continue;
- }
- //过滤段间注释符
- if(
- (Line[0]=='/' &&Line[1]=='*' )
- ){
- SFLAG[0]=0;
- continue;
-
- }else if(
- (Line[0]=='*' &&Line[1]=='/' )
- ){
- SFLAG[0]=1;
- continue;
-
- }else if(Line[0]=='#'){
- if(SFLAG[1]==0){
- continue;
- }else{
- j=0;
- while(
- JMP_MARK[j]==Line[j] ||
- JMP_MARK[j]==Line[j]-32
- ){j++;}
- if( isNULL(JMP_MARK[j]) && isNULL(Line[j]) ){SFLAG[1]=0;}
- continue;
- }
- }
-
- //识别自然宏
- if(
- (Line[0]=='|') &&
- (Line[1]=='|')
- ){
- if(
- stristr(Line+2, "start" )!=NULL ||
- stristr(Line+2, "begin" )!=NULL ||
- stristr(Line+2, "run" )!=NULL
- ){
- SFLAG[0]=1;
- continue;
- }
-
- if(
- stristr(Line+2, "end" )!=NULL ||
- stristr(Line+2, "eof" )!=NULL
- ){
- return 0;
- }
-
- if(
- stristr(Line+2, "desktop")!=NULL ||
- stristr(Line+2, "desk" )!=NULL
- ){
- hCMD=GetDesktopWindow();
- continue;
- }
-
- if(
- stristr(Line+2, "hide" )!=NULL
- ){
- DispyCursor(25, FALSE);
- }
- continue;
- }
-
- //开始开关未打开,或遇到空行,或正在执行JMP跳转,则跳过该行
- if(
- SFLAG[0]==0 ||
- isNULL(Line[0]) ||
- SFLAG[1]==1
- ){continue;}
-
- //解析循环开始标签
- if(
- (Line[0]=='[' ) &&
- (isNULL(Line[1])) //为空则开始循环
- ){
- FORI[++KLevel]->FTEL=ftell(fp);
- FORI[KLevel]->CYCL=0;
- FORI[KLevel+1]->CADD=0;
- FORI[KLevel]->LNUM=i+1;
- continue;
- }
-
- //解析循环结束标签
- if(Line[0]==']'){
-
- (FORI[KLevel]->CYCL)++;
- int TIM=atoi(strtok(Line+1,","));
-
- //移位器嵌套增量
- FORI[KLevel+1]->CADD=atoi(strtok(NULL, ","));
-
- if ( FORI[KLevel]->CYCL < TIM+(FORI[KLevel]->CADD)*(FORI[KLevel-1]->CYCL) ){
- fseek(fp, FORI[KLevel]->FTEL, SEEK_SET);
- i=FORI[KLevel]->LNUM-1;
-
- }else if( FORI[KLevel]->CYCL >= TIM+(FORI[KLevel]->CADD)*(FORI[KLevel-1]->CYCL) ){
- FORI[KLevel--]->CYCL=0;
- }
- continue;
- }
- //过滤回车符
- if((Line_LEN=strlen(Line))==2){
- continue;
- }else{
- Line[Line_LEN-2]='\0';
- }
- //解析命令行
- switch(Identify_KeyWords(Line)){
- case 0:
- //累加器
- MAX_ARGC=args(Line+4, " ", ARGS, LIB_ARGS);
- ATOIargs(FORI[KLevel]->ADD, MAX_ARGC, 1, ARGS);
- FORI[KLevel]->ADD[0]=FORI[KLevel]->CYCL+1;
- break;
- case 1:
- //旋转器
- MAX_ARGC=args(Line+4, " ", ARGS, LIB_ARGS);
- ATOIargs(ROTE, MAX_ARGC, 1, ARGS);
- ROTE[0]=FORI[KLevel]->CYCL+1;
- break;
- case 2:
- //缩放器
- MAX_ARGC=args(Line+4, " ", ARGS, LIB_ARGS);
- for(j=0; j<MAX_ARGC; j++){ ZOOM[j+1]=atof(ARGS[j]);}
- ZOOM[0]=FORI[KLevel]->CYCL+1;
- break;
- case 3:
- //反转器
- MAX_ARGC=args(Line+4, " ", ARGS, LIB_ARGS);
- ATOIargs(REVE, MAX_ARGC, 1, ARGS);
- REVE[0]=FORI[KLevel]->CYCL+1;
- break;
- case 4:
- //透明器
- MAX_ARGC=args(Line+4, " ", ARGS, LIB_ARGS);
- ATOIargs(ALPH, MAX_ARGC, 1, ARGS);
- ALPH[0]=1;
- break;
- case 5:
- //参数器
- MAX_ARGC=args(Line+4, " ", ARGS, LIB_ARGS);
- ATOIargs(ATOI, MAX_ARGC, 1, ARGS);
- ATOI[0]=1;
- break;
- case 6:
- //绘图器
- MAX_ARGC=args(Line+4, " ", ARGS, LIB_ARGS);
- Shell_IMG(passNULL(ARGS[0]), FORI, KLevel, i);
- break;
- case 7:
- //延时毫秒
- Sleep(atoi(Line+4));
- break;
- case 8:
- //调用LIB脚本库
- Line=passNULL(Line+4);
- if(Line[0]=='|'&&Line[1]=='|'){
- MAX_ARGC=args(Line+2, "|", ARGS, LIB_ARGS);
- FileScript(ARGS[0], ARGS);
- }else{
- fprintf(stdout, "[%d]:缺少库名。\n", i);
- exit(1);
- }
-
- break;
- case 9:
- //跳转器
- strcpy(JMP_MARK, strupr(passNULL(Line+4)));
- i=KLevel=i=SFLAG[0]=0, SFLAG[1]=1;
- fseek(fp, 0, SEEK_SET);
- break;
- case 10:
- //移动光标
- if(args(Line+4, " ", ARGS, LIB_ARGS) >1){SetPos(atoi(ARGS[0]), atoi(ARGS[1]));}
- break;
- case 11:
- //退出
- exit( atoi(Line+4) );
- break;
- case 12:
- //暂停
- getch();
- break;
- case 13:
- //清屏
- Shell_CLS();
- break;
- case 14:
- //标题
- SetConsoleTitle(Line+4);
- break;
- case 15:
- //窗口尺寸
- if( args(Line+4, " ", ARGS, LIB_ARGS) >1){Shell_MODE_CON(atoi(ARGS[0]), atoi(ARGS[1]));}
- break;
- case 16:
- //字体颜色
- if( args(Line+4, " ", ARGS, LIB_ARGS) >3){Shell_COLOR(atoi(ARGS[0]), atoi(ARGS[1]), atoi(ARGS[2]), atoi(ARGS[3]));}
- break;
- case 17:
- //移动窗口
- if( args(Line+4, " ", ARGS, LIB_ARGS) >1){Shell_MW(atoi(ARGS[0]), atoi(ARGS[1]));}
- break;
- case 18:
- //呼叫器
- CAL_MARK=ftell(fp);
- SFLAG[2]=1;
- strcpy(JMP_MARK, strupr(passNULL(Line+4)));
- i=KLevel=i=SFLAG[0]=0, SFLAG[1]=1;
- fseek(fp, 0, SEEK_SET);
- break;
- case 19:
- //EOF结尾标签
- if(SFLAG[2]==1){
- fseek(fp, CAL_MARK, SEEK_SET);
- SFLAG[2]==0;
- }else{
- return 0;
- }
- break;
- case 20:
- //字符显示函数
- fputs(Line+4,stdout);
- fputs("\r\n",stdout);
- break;
- case 21:
- //设置光标尺寸
- DispyCursor(atoi(Line+4), TRUE);
- break;
- case 255:
- fprintf(stdout, "[%d]:错误指令。\n", i);
- exit(1);
- break;
- }
- }
- free(SFLAG);
- free(FORI);
- free(LCache);
- fclose(fp);
- return 0;
- }
-
-
- /*************MAIN主函数入口*************/
- int main(int argc, char** argv)
- {
- if(argc==2){
- //获得控制台窗口句柄
- hCMD=GetConsoleWindow();
- char* LIB_ARGS[16];
- FileScript(argv[1], LIB_ARGS);
- return 0;
- }
-
- //异常则抛出使用说明
- fputs(
- "THE CONSOLE DISPLAYS A PICTURE SCRIPT, COPYRIGHT@2016~2018 BY HAPPY\n"
- "VERSION 1.0\n"
- "usage: powerimg [scriptfile]\n"
- ,stdout
- );
- return 1;
- }
复制代码
作者: zhangzsky 时间: 2016-11-28 13:51
楼主是第三方专业户了,很好很强大
作者: zhangzsky 时间: 2016-11-29 02:01
回复 3# happy886rr
我只是打发下时间,感谢你的意见。有空我去看看lua和html5
作者: happy886rr 时间: 2016-11-29 09:14
回复 4# zhangzsky
如果你学了lua游戏开发的话,我想你会被其惊人的功能所震惊,这年头java都得借用lua。当年大话西游就是靠lua开发的。推荐你学学lua游戏制作,那可是一天就能搞出个三国志单机版。我都打算用lua 去做powerimg的解释器核心,但是迫于体积太大,lua有200KB之多。我的做第三方不愿体积超过30KB。
作者: zhangzsky 时间: 2016-11-29 12:35
本帖最后由 zhangzsky 于 2016-11-29 12:39 编辑
回复 5# happy886rr
起初我只是想偶尔学学bat,然后想着写点什么,后来上班的电脑上到处都是,我基本上就双击下……
所以空出来时间写个游戏什么的锻炼下批处理……
已经跟起初的想法有出入了,自己文化水平有限。看来lua得空就看看也好
作者: happy886rr 时间: 2016-11-29 12:55
回复 6# zhangzsky
批处理的优势在于批量操作,批量调用exe。
你做游戏,需要的是高效的工具,需要多媒体接口,能播放声音,显示动态画面,能2.5D旋转,这些批处理都不能实现。我觉得你的游戏设计思想很不错,你不应该被工具所局限,用批处理你只能做出那种简单的逐帧动画,但是你学学真正的游戏开发技术,会让你获得新生。
作者: CrLf 时间: 2017-1-7 17:06
求exe
作者: gfwlxx 时间: 2018-5-8 08:02
你多大年纪了
我要把你写的所有的都重新写一份
我正在写一款万能p-code虚拟机,
大神,收徒弟嘛,请收下我的膝盖
pm给我联系方式
作者: 523066680 时间: 2018-5-8 09:44
回复 8# gfwlxx
听说他物理很好。
作者: liujingcheng 时间: 2020-4-22 08:59
编译不了,vs都不行,你这是设么鬼
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |