找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 21253|回复: 9

powerimg一款图显脚本解释器

[复制链接]
发表于 2016-11-27 20:02:36 | 显示全部楼层 |阅读模式
本帖最后由 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


核心源码:
  1. /*
  2.         THE CONSOLE DISPLAYS A PICTURE SCRIPT, VERSION 1.0
  3.         POWERIMG.EXE
  4.         COPYRIGHT@2016~2018 BY HAPPY
  5.         LINK: -lgdi32 -lgdiplus -lole32 -lmsimg32
  6. */

  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <ctype.h>
  11. #include <stdbool.h>
  12. #include <windows.h>
  13. #include <wincon.h>
  14. #include <gdiplus\gdiplus.h>
  15. #include <io.h>
  16. #include <conio.h>
  17. #include <math.h>
  18. #include <time.h>


  19. //定义π值
  20. #define M_PI 3.14159265358979323846

  21. //定义移位嵌套层数
  22. #define LOOP_LEVELS 16
  23. //限制解释关键词数量                        
  24. #define SENSITIVE_NUM 22
  25. //添加关键词(请用小写定义),解释时不区分大小写。
  26. 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"};

  27. //申明函数
  28. HWND    WINAPI GetConsoleWindow();
  29. BOOL    WINAPI AlphaBlend(HDC,int,int,int,int,HDC,int,int,int,int,BLENDFUNCTION);
  30. BOOL    WINAPI TransparentBlt(HDC,int,int,int,int,HDC,int,int,int,int,UINT);
  31. int     Drawgif(HWND hCMD, wchar_t* gifFile, int cmd_x,  int cmd_y, int size_W, int size_H, int CYCtimes, int playSpeed);
  32. int     FileScript(char* sfile, char* LIB_ARGS[16]);
  33. WCHAR*  AnsiToWCHAR(const char* str);


  34. //定义接收整形容器
  35. int   ATOI[16]={0};
  36. //定义旋转器
  37. int   ROTE[16]={0};
  38. //定义缩放器
  39. float ZOOM[16]={0};
  40. //定义反转器
  41. int   REVE[16]={0};
  42. //定义透明器
  43. int   ALPH[16]={0};

  44. //设主句柄
  45. HWND  hCMD;

  46. //图形结构体
  47. typedef struct{
  48.         HBITMAP hBitmap;
  49.         int Width;
  50.         int Height;
  51. }IMAGE;
  52. //整形结构体
  53. typedef struct{
  54.         int x;
  55.         int y;
  56. }RPOINT;
  57. //比率结构体
  58. typedef struct{
  59.         float x;
  60.         float y;
  61. }RATE;

  62. //移位结构体
  63. typedef struct{
  64.         long FTEL;
  65.         int  CYCL;
  66.         int  CADD;
  67.         int  LNUM;
  68.         //定义嵌套累加器
  69.         int  ADD[16];
  70. }fori;


  71. /***************图形函数群***************/
  72. //图形旋转
  73. int RotateDC(HDC hdc, int angle, RPOINT rpoint)  
  74. {
  75.         if(angle==0){return 1;}
  76.         XFORM Matrix;
  77.         double rad =-angle/180.0*M_PI;
  78.         Matrix.eM11 = (float)cos(rad);  
  79.         Matrix.eM12 = (float)sin(rad);  
  80.         Matrix.eM21 =-(float)sin(rad);  
  81.         Matrix.eM22 = (float)cos(rad);  
  82.         Matrix.eDx  = (float)(rpoint.x-cos(rad)*rpoint.x+sin(rad)*rpoint.y);  
  83.         Matrix.eDy  = (float)(rpoint.y-cos(rad)*rpoint.y-sin(rad)*rpoint.x);
  84.         SetGraphicsMode(hdc, GM_ADVANCED);
  85.         SetWorldTransform(hdc, &Matrix);
  86.         return 0;  
  87. }
  88. //图形缩放
  89. int ZoomDC(HDC hdc, RATE rate, RPOINT rpoint)  
  90. {
  91.         XFORM Matrix;
  92.         Matrix.eM11 = (float)rate.x;  
  93.         Matrix.eM12 = (float)0;  
  94.         Matrix.eM21 = (float)0;  
  95.         Matrix.eM22 = (float)rate.y;  
  96.         Matrix.eDx  = (float)(rpoint.x-rate.x*rpoint.x);  
  97.         Matrix.eDy  = (float)(rpoint.y-rate.y*rpoint.y);
  98.         SetGraphicsMode(hdc, GM_ADVANCED);
  99.         SetWorldTransform(hdc, &Matrix);
  100.         return 0;  
  101. }
  102. //图形反转
  103. int ReverseDC(HDC hdc, int reverse_mode, IMAGE img)
  104. {
  105.         XFORM Matrix;
  106.         if      (reverse_mode== 1){
  107.                 Matrix.eM11 =-(float)1;  
  108.                 Matrix.eM12 = (float)0;  
  109.                 Matrix.eM21 = (float)0;  
  110.                 Matrix.eM22 = (float)1;  
  111.                 Matrix.eDx  = (float)img.Width;  
  112.                 Matrix.eDy  = (float)0;       
  113.         }else if(reverse_mode== 2){
  114.                 Matrix.eM11 = (float)1;  
  115.                 Matrix.eM12 = (float)0;  
  116.                 Matrix.eM21 = (float)0;  
  117.                 Matrix.eM22 =-(float)1;  
  118.                 Matrix.eDx  = (float)0;  
  119.                 Matrix.eDy  = img.Height;
  120.         }else if(reverse_mode== 0){
  121.                 Matrix.eM11 =-(float)1;  
  122.                 Matrix.eM12 = (float)0;  
  123.                 Matrix.eM21 = (float)0;  
  124.                 Matrix.eM22 =-(float)1;  
  125.                 Matrix.eDx  = (float)img.Width;  
  126.                 Matrix.eDy  = (float)img.Height;
  127.         }else if(reverse_mode==-1){
  128.                 Matrix.eM11 = (float)0;  
  129.                 Matrix.eM12 = (float)1;  
  130.                 Matrix.eM21 = (float)1;  
  131.                 Matrix.eM22 = (float)0;  
  132.                 Matrix.eDx  = (float)0;  
  133.                 Matrix.eDy  = (float)0;
  134.         }else if(reverse_mode==-2){
  135.                 Matrix.eM11 = (float)0;  
  136.                 Matrix.eM12 = (float)1;  
  137.                 Matrix.eM21 =-(float)1;  
  138.                 Matrix.eM22 = (float)0;  
  139.                 Matrix.eDx  = (float)img.Height;  
  140.                 Matrix.eDy  = (float)0;
  141.         }
  142.         SetGraphicsMode(hdc, GM_ADVANCED);
  143.         SetWorldTransform(hdc, &Matrix);
  144.         return 0;  
  145. }
  146. //图形加载
  147. IMAGE LoadImg(char* imgFile, int _nWidth, int _nHeight)
  148. {
  149.         GpImage*     thisImage;
  150.         GpGraphics*  graphics=NULL;
  151.         ULONG_PTR    gdiplusToken;
  152.         IMAGE       _img;       
  153.         GdiplusStartupInput GSI={1, NULL, false, false};
  154.         HDC hdc=GetDC(NULL);
  155.         HDC hdcMem=CreateCompatibleDC(hdc);
  156.        
  157.         GdiplusStartup(&gdiplusToken, &GSI, NULL);   
  158.         GdipLoadImageFromFile(AnsiToWCHAR(imgFile), &thisImage);
  159.         GdipGetImageWidth(thisImage, &_img.Width);
  160.         GdipGetImageHeight(thisImage, &_img.Height);
  161.         if      (_nWidth !=0 && _nHeight==0){
  162.                 _img.Height=(int)( (_img.Height*1.0 / _img.Width) * (_nWidth ) );
  163.                 _img.Width =_nWidth;
  164.         }else if(_nWidth ==0 && _nHeight!=0){
  165.                 _img.Width =(int)( (_img.Width*1.0 / _img.Height) * (_nHeight) );
  166.                 _img.Height=_nHeight;
  167.         }else if(_nWidth !=0 && _nHeight!=0){
  168.                 _img.Width =_nWidth;
  169.                 _img.Height=_nHeight;
  170.         }
  171.         _img.hBitmap=CreateCompatibleBitmap(hdc, _img.Width, _img.Height);

  172.         SelectObject(hdcMem, _img.hBitmap);
  173.         GdipCreateFromHDC(hdcMem, &graphics);
  174.         GdipDrawImageRectI(graphics, thisImage, 0, 0, _img.Width, _img.Height);
  175.         GdipDisposeImage(thisImage);
  176.         GdipDeleteGraphics(graphics);
  177.         DeleteDC (hdcMem);
  178.         ReleaseDC(NULL, hdc);
  179.         GdiplusShutdown(gdiplusToken);
  180.         return _img;
  181. }
  182. //绘图函数
  183. int DrawImg(
  184.         char* imgfile,           //图形文件
  185.         int cmd_x,  int cmd_y,   //相对于cmd窗口位置
  186.         int size_W, int size_H,  //图片的显示宽高
  187.         int src_x,  int src_y,   //对相原图 截取位置
  188.         int disp_W, int disp_H,  //要显示多少宽高
  189.         fori* FORI[LOOP_LEVELS], //循环结构体指针
  190.         int KLevel               //循环层号
  191. ){

  192.         IMAGE P=LoadImg(imgfile, size_W, size_H);
  193.         HDC   hCUR=GetDC(hCMD);
  194.         HDC   hSRC=CreateCompatibleDC(hCUR);
  195.         SelectObject(hSRC, P.hBitmap);

  196.         if(ROTE[0]!=0){
  197.                 RPOINT rpoint={ROTE[1], ROTE[2]};
  198.                 RotateDC(hCUR, ROTE[3]+ROTE[0]*ROTE[4], rpoint);
  199.         }
  200.         if(ZOOM[0]!=0){
  201.                 RPOINT rpoint={(int)ZOOM[1], (int)ZOOM[2]};
  202.                 if(
  203.                         (ZOOM[3]+ZOOM[0]*ZOOM[5])<0 ||
  204.                         (ZOOM[4]+ZOOM[0]*ZOOM[6])<0
  205.                 ){
  206.                         return 1;
  207.                 }
  208.                 RATE rate={ZOOM[3]+ZOOM[0]*ZOOM[5], ZOOM[4]+ZOOM[0]*ZOOM[6]};
  209.                 ZoomDC(hCUR, rate, rpoint);
  210.         }
  211.         if(REVE[0]!=0){
  212.                 ReverseDC(hCUR, REVE[1], P);
  213.         }
  214.         if(FORI[KLevel]->ADD[0]!=0){
  215.                 int i=0;
  216.                 for(i=0; i<=KLevel; i++){
  217.                         cmd_x +=FORI[i]->ADD[0] * FORI[i]->ADD[1], cmd_y += FORI[i]->ADD[0] * FORI[i]->ADD[2];
  218.                         size_W+=FORI[i]->ADD[0] * FORI[i]->ADD[3], size_H+= FORI[i]->ADD[0] * FORI[i]->ADD[4];
  219.                         src_x +=FORI[i]->ADD[0] * FORI[i]->ADD[5], src_y += FORI[i]->ADD[0] * FORI[i]->ADD[6];
  220.                         disp_W+=FORI[i]->ADD[0] * FORI[i]->ADD[7], disp_H+= FORI[i]->ADD[0] * FORI[i]->ADD[8];
  221.                 }
  222.         }
  223.         disp_W=(disp_W<=0) ?P.Width  :disp_W;
  224.         disp_H=(disp_H<=0) ?P.Height :disp_H;

  225.         if      (ALPH[0]==1 && ALPH[1]==1){
  226.                 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]));
  227.         }else if(ALPH[0]==1 && ALPH[1]==0){
  228.                 BLENDFUNCTION blendFunction={0, 0, (ALPH[2]==0)?-1:ALPH[2], 1};
  229.                 AlphaBlend(hCUR, cmd_x, cmd_y, disp_W, disp_H, hSRC, src_x, src_y, P.Width, P.Height, blendFunction);
  230.         }else if(ALPH[0]==0){
  231.                 BitBlt(hCUR, cmd_x, cmd_y, disp_W, disp_H, hSRC, src_x, src_y, SRCCOPY);
  232.         }

  233.         ROTE[0]=ZOOM[0]=REVE[0]=ALPH[0]=0;
  234.         FORI[KLevel]->ADD[0]=0;
  235.         DeleteObject(P.hBitmap);
  236.         ReleaseDC(hCMD, hCUR);
  237.         DeleteDC(hSRC);
  238.         return 0;
  239. }
  240. //擦图函数
  241. int CleanImg(
  242.         HWND  hd,                   //句柄
  243.         LONG  cmd_x,  LONG  cmd_y,  //起始擦除点,相对于cmd窗口位置的
  244.         LONG  size_W, LONG  size_H, //要擦除的宽高尺寸
  245.         BOOL  mode,
  246.         fori* FORI[LOOP_LEVELS],    //循环结构体指针
  247.         int KLevel                  //循环层号
  248. ){
  249.         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]};
  250.         if(mode){
  251.                 InvalidateRect(hd, &z, FALSE);
  252.         }else{
  253.                 InvalidateRect(hd, NULL, FALSE);
  254.         }
  255.         return 0;
  256. }


  257. /***************功能函数群***************/
  258. //子串查找,忽略大小写
  259. char* stristr(const char* str1, const char* str2)
  260. {
  261.         char* cp=(char *)str1;
  262.         char* s1, *s2;
  263.         if(!*str2){return (char *)str1;}
  264.         while(*cp){
  265.                 s1=cp;
  266.                 s2=(char *)str2;

  267.                 while(
  268.                         *s1 &&
  269.                         *s2 &&
  270.                         !(_tolower(*s1)-_tolower(*s2))
  271.                 ){s1++, s2++;}

  272.                 if (!*s2){return cp;}
  273.                 cp++;
  274.         }
  275.         return NULL;
  276. }
  277. //转码函数
  278. WCHAR* AnsiToWCHAR(const char* str)
  279. {
  280.         if(!str){return NULL;}
  281.         int wLen=MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, -1, NULL, 0);
  282.         WCHAR* wstr=(WCHAR*)malloc(sizeof(WCHAR)*wLen + 1);
  283.         MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, -1, wstr, wLen);
  284.         wstr[wLen]='\0';
  285.         return wstr;
  286. }
  287. //显示光标
  288. void DispyCursor(int size,bool mode)
  289. {       
  290.         CONSOLE_CURSOR_INFO cursor_info ={(DWORD)size, mode};
  291.         SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
  292.         return;
  293. }
  294. //移动光标
  295. int SetPos(int x,int y)
  296. {
  297.         COORD pos;
  298.         HANDLE hOutput;
  299.         pos.X=x, pos.Y=y;
  300.         hOutput=GetStdHandle(STD_OUTPUT_HANDLE);
  301.         SetConsoleCursorPosition(hOutput,pos);
  302.         return 0;
  303. }
  304. //测空字符
  305. inline bool isNULL(const char c){
  306.         if(
  307.                 c=='\t' ||
  308.                 c==' '  ||
  309.                 c=='\r' ||
  310.                 c=='\n' ||
  311.                 c=='\0'

  312.         ){
  313.                 return true;
  314.         }
  315.         return false;
  316. }
  317. //过滤行TAB缩进或前空格
  318. char* passNULL(char* Str){
  319.         if(Str!=NULL){
  320.                 while(*Str=='\t' ||*Str==' '){Str++;}
  321.         }
  322.         return Str;
  323. }
  324. //切分参数
  325. int args(char* Str, char* delims, char* ARGS[16], char* LIB_ARGS[16])
  326. {
  327.         int i=0;
  328.         char* p;
  329.         ARGS[i]=strtok(Str, delims);
  330.         while(ARGS[i]!=NULL){
  331.                 if( (p=stristr(ARGS[i], "*"))!=NULL){
  332.                         ARGS[i]=LIB_ARGS[atoi(p+1)];
  333.                 }
  334.                 ARGS[++i]=strtok(NULL, delims);
  335.         }       
  336.         return i;
  337. }
  338. //整化参数
  339. int ATOIargs(int* taner, int MAX_ARGC, int add, char* ARGS[16])
  340. {
  341.         int j;
  342.         for(j=0; j<16; j++){taner[j]=0;}
  343.         for(j=0; j<MAX_ARGC; j++){       
  344.                 taner[j+add]=atoi(ARGS[j]);
  345.         }
  346.         return 0;
  347. }
  348. //关键词解析函数
  349. int Identify_KeyWords(const char* Line)
  350. {
  351.         int i, SN;
  352.         for(SN=0; SN<SENSITIVE_NUM; SN++){
  353.                 for(i=0; KEY_WORDS[SN][i]!='\0'; i++){
  354.                         if(
  355.                                  Line[i]   !=KEY_WORDS[SN][i] &&
  356.                                  Line[i]+32!=KEY_WORDS[SN][i]
  357.                                 
  358.                         ){
  359.                                 break;
  360.                         }
  361.                 }
  362.                  if(
  363.                          KEY_WORDS[SN][i]=='\0' &&
  364.                         isNULL(Line[i])
  365.                 ){
  366.                         return SN;
  367.                 }
  368.         }                               
  369.         return 255;
  370. }

  371. //绘图函数
  372. int Shell_IMG(char* imgfile, fori* FORI[LOOP_LEVELS], int KLevel, int LineNUM)
  373. {
  374.         //为空则表示擦除
  375.         if(
  376.                 imgfile==NULL      ||
  377.                 isNULL(imgfile[0])
  378.         ){
  379.                         if(ATOI[0]==0){
  380.                                 CleanImg(hCMD, 0, 0, 0, 0, FALSE, FORI, KLevel);
  381.                         }else{
  382.                                 CleanImg(hCMD, ATOI[1], ATOI[2], ATOI[3], ATOI[4], TRUE, FORI, KLevel);
  383.                         }

  384.         //否则为图片显示
  385.         }else{
  386.                 if(access(imgfile, 0)==-1){
  387.                         fprintf(stdout, "[%d]:图片不存在。\n", LineNUM);
  388.                         exit(1);
  389.                 }
  390.                 DrawImg(imgfile,  ATOI[1], ATOI[2], ATOI[3], ATOI[4], ATOI[5], ATOI[6], ATOI[7], ATOI[8], FORI, KLevel);
  391.         }
  392.         return 0;
  393. }


  394. /***************Shell函数群***************/
  395. //清屏函数
  396. int Shell_CLS()
  397. {
  398.         HANDLE hConsole=GetStdHandle(STD_OUTPUT_HANDLE);
  399.         COORD coordScreen={0,0};
  400.         DWORD cCharsWritten;
  401.         CONSOLE_SCREEN_BUFFER_INFO csbi;
  402.         GetConsoleScreenBufferInfo(hConsole, &csbi);
  403.         FillConsoleOutputCharacter(hConsole,       (TCHAR)' ', csbi.dwSize.X*csbi.dwSize.Y, coordScreen, &cCharsWritten);
  404.         GetConsoleScreenBufferInfo(hConsole, &csbi);
  405.         FillConsoleOutputAttribute(hConsole, csbi.wAttributes, csbi.dwSize.X*csbi.dwSize.Y, coordScreen, &cCharsWritten);
  406.         SetConsoleCursorPosition(hConsole,coordScreen);
  407.         return 0;
  408. }
  409. //标题函数
  410. int Shell_TITLE(char* Str)
  411. {
  412.         SetConsoleTitle(Str);
  413.         return 0;
  414. }
  415. //按键函数
  416. int Shell_KEY(clock_t delay)
  417. {
  418.         int i,KEY_V,start=clock();
  419.         do{
  420.                 if(kbhit()){
  421.                          KEY_V=(int)(getch());
  422.                         if(KEY_V<97){KEY_V+=32;}
  423.                         return KEY_V;
  424.                 }
  425.                 for(i=0;i<=50;i++);
  426.         }while((clock()-start)<delay);
  427.         return -1;
  428. }
  429. //鼠标点击函数:KEY_V取值1、2对应鼠标左右键点击;当取值为0时则隐藏光标;
  430. int Shell_MOUSE(int KEY_V)
  431. {
  432.         if(KEY_V==0){
  433.                 CONSOLE_CURSOR_INFO cursor_info={1,0};
  434.                 SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);
  435.                 return 0;
  436.         }
  437.         HANDLE StdIn=GetStdHandle(STD_INPUT_HANDLE);
  438.         DWORD  OrgMode, Res;
  439.         INPUT_RECORD InR;
  440.         GetConsoleMode(StdIn, &OrgMode);
  441.         SetConsoleMode(StdIn, OrgMode | ENABLE_WINDOW_INPUT |  ENABLE_MOUSE_INPUT);
  442.         for(;;){
  443.                 ReadConsoleInput(StdIn, &InR, 1, &Res);
  444.                 if(
  445.                         InR.Event.MouseEvent.dwEventFlags ==0  &&
  446.                         InR.Event.MouseEvent.dwButtonState==KEY_V
  447.                 ){
  448.                         SetConsoleMode(StdIn, OrgMode);
  449.                         return (InR.Event.MouseEvent.dwMousePosition.Y)*1000+(InR.Event.MouseEvent.dwMousePosition.X);
  450.                 }
  451.         }
  452. }
  453. //窗口大小
  454. int Shell_MODE_CON(int x, int y)
  455. {

  456.         HANDLE StdOut=GetStdHandle(STD_OUTPUT_HANDLE);
  457.         CONSOLE_SCREEN_BUFFER_INFO scbi;
  458.         COORD size={x, 300};
  459.         GetConsoleScreenBufferInfo(StdOut, &scbi);
  460.         SetConsoleScreenBufferSize(StdOut, size);
  461.         SMALL_RECT rc={0, 0, x-1, y-1};
  462.         SetConsoleWindowInfo(StdOut, 1, &rc);
  463.         CloseHandle(StdOut);
  464.         return 0;
  465. }
  466. //字体颜色: 1,2,4,8前景;16,32,64,128后景;
  467. int Shell_COLOR(unsigned short A,unsigned short B,unsigned short C,unsigned short D)
  468. {
  469.         HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE);
  470.         CONSOLE_SCREEN_BUFFER_INFO csbi;
  471.         GetConsoleScreenBufferInfo(handle_out, &csbi);
  472.         SetConsoleTextAttribute(handle_out, A | B | C | D);
  473.         return 0;
  474. }
  475. //移动窗口
  476. int Shell_MW(int x, int y)
  477. {
  478.         HWND cmd=GetConsoleWindow();
  479.         SetWindowPos(cmd, HWND_TOP, x, y, 0, 0, SWP_NOSIZE);       
  480.         return 0;
  481. }


  482. /***************解析函数群***************/
  483. //脚本解析函数
  484. int FileScript(char* sfile, char* LIB_ARGS[16])
  485. {               
  486.         //初始参数 KLevel为当前循环层号;
  487.         int i=0, j=0, KLevel=0, Line_LEN=0, MAX_ARGC=0, SN=255;
  488.        
  489.         //读取脚本文件
  490.         FILE* fp;
  491.         if( (fp=fopen(sfile, "rb"))==NULL ){
  492.                 fprintf(stdout, "[%d]:读取文件失败。\n", i);
  493.                 exit(1);
  494.         }
  495.        
  496.         //初始化开关参数,SFLAG[0]==1开始; SFLAG[1]==1跳转; SFLAG[2]==1 呼叫归位;
  497.         int* SFLAG=(int*)calloc(8, sizeof(int));
  498.        
  499.         //初始化循环结构体
  500.         fori* FORI[LOOP_LEVELS];
  501.         for(j=0; j<LOOP_LEVELS; j++){
  502.                 FORI[j]=(fori*)calloc(1, sizeof(FORI));
  503.                 FORI[j]->FTEL=(long)0;
  504.                 FORI[j]->CYCL=0;
  505.                 FORI[j]->LNUM=0;
  506.                 FORI[j]->CADD=0;
  507.                 FORI[j]->ADD[16]=(int)calloc(16, sizeof(int));
  508.         }
  509.        
  510.         //定义切分字串容器
  511.         char* ARGS[16];       
  512.         for(j=0; j<16; j++){
  513.                 ARGS[j]=(char*)calloc(128, sizeof(char*));
  514.         }
  515.        
  516.         //分配行容器
  517.         char* LCache=(char*)calloc(1025, sizeof(char));
  518.         //辅助行指针
  519.         char* Line;

  520.         //标签跳转指针
  521.         char* JMP_MARK=(char*)malloc(128*sizeof(char));
  522.         //标签呼叫指针
  523.         long  CAL_MARK;

  524.         while(!feof(fp)){
  525.                 memset(LCache, 0,  1024*sizeof(char));
  526.                 fgets(LCache, 1024, fp);

  527.                 //指针置换
  528.                 Line=LCache;

  529.                 //行计数器
  530.                 i++;

  531.                 //过滤行TAB缩进或前空格
  532.                 while(*Line=='\t'|| *Line==' '){Line++;}

  533.                 //过滤注释符
  534.                 if(Line[0]=='/' &&Line[1]=='/'){
  535.                         continue;
  536.                 }
  537.                 //过滤段间注释符
  538.                 if(
  539.                         (Line[0]=='/' &&Line[1]=='*' )
  540.                 ){
  541.                         SFLAG[0]=0;
  542.                         continue;
  543.                        
  544.                 }else if(
  545.                         (Line[0]=='*' &&Line[1]=='/' )
  546.                 ){
  547.                         SFLAG[0]=1;
  548.                         continue;
  549.                        
  550.                 }else if(Line[0]=='#'){
  551.                         if(SFLAG[1]==0){
  552.                                 continue;               
  553.                         }else{
  554.                                 j=0;
  555.                                 while(
  556.                                         JMP_MARK[j]==Line[j] ||
  557.                                         JMP_MARK[j]==Line[j]-32
  558.                                 ){j++;}
  559.                                 if( isNULL(JMP_MARK[j]) && isNULL(Line[j]) ){SFLAG[1]=0;}
  560.                                 continue;
  561.                         }
  562.                 }

  563.                 //识别自然宏
  564.                 if(
  565.                         (Line[0]=='|') &&
  566.                         (Line[1]=='|')
  567.                 ){
  568.                         if(
  569.                                 stristr(Line+2, "start"  )!=NULL ||
  570.                                 stristr(Line+2, "begin"  )!=NULL ||
  571.                                 stristr(Line+2, "run"    )!=NULL
  572.                         ){
  573.                                 SFLAG[0]=1;
  574.                                 continue;
  575.                         }

  576.                         if(
  577.                                 stristr(Line+2, "end"    )!=NULL ||
  578.                                 stristr(Line+2, "eof"    )!=NULL
  579.                         ){
  580.                                 return 0;
  581.                         }

  582.                         if(
  583.                                 stristr(Line+2, "desktop")!=NULL ||
  584.                                 stristr(Line+2, "desk"   )!=NULL
  585.                         ){
  586.                                 hCMD=GetDesktopWindow();
  587.                                 continue;
  588.                         }

  589.                         if(
  590.                                 stristr(Line+2, "hide"   )!=NULL
  591.                         ){
  592.                                 DispyCursor(25, FALSE);
  593.                         }
  594.                         continue;
  595.                 }               

  596.                 //开始开关未打开,或遇到空行,或正在执行JMP跳转,则跳过该行
  597.                 if(
  598.                         SFLAG[0]==0     ||
  599.                         isNULL(Line[0]) ||
  600.                         SFLAG[1]==1
  601.                 ){continue;}
  602.                
  603.                 //解析循环开始标签
  604.                 if(
  605.                         (Line[0]=='['   ) &&
  606.                         (isNULL(Line[1])) //为空则开始循环
  607.                 ){
  608.                         FORI[++KLevel]->FTEL=ftell(fp);
  609.                         FORI[KLevel]->CYCL=0;
  610.                         FORI[KLevel+1]->CADD=0;
  611.                         FORI[KLevel]->LNUM=i+1;
  612.                         continue;
  613.                 }

  614.                 //解析循环结束标签
  615.                 if(Line[0]==']'){

  616.                         (FORI[KLevel]->CYCL)++;
  617.                         int TIM=atoi(strtok(Line+1,","));

  618.                         //移位器嵌套增量
  619.                         FORI[KLevel+1]->CADD=atoi(strtok(NULL,  ","));

  620.                         if      ( FORI[KLevel]->CYCL <  TIM+(FORI[KLevel]->CADD)*(FORI[KLevel-1]->CYCL) ){
  621.                                 fseek(fp, FORI[KLevel]->FTEL, SEEK_SET);
  622.                                 i=FORI[KLevel]->LNUM-1;

  623.                         }else if( FORI[KLevel]->CYCL >= TIM+(FORI[KLevel]->CADD)*(FORI[KLevel-1]->CYCL) ){
  624.                                 FORI[KLevel--]->CYCL=0;
  625.                         }
  626.                         continue;
  627.                 }
  628.                 //过滤回车符
  629.                 if((Line_LEN=strlen(Line))==2){
  630.                         continue;
  631.                 }else{
  632.                         Line[Line_LEN-2]='\0';
  633.                 }
  634.                 //解析命令行
  635.                 switch(Identify_KeyWords(Line)){
  636.                 case 0:
  637.                         //累加器
  638.                         MAX_ARGC=args(Line+4, " ", ARGS, LIB_ARGS);
  639.                         ATOIargs(FORI[KLevel]->ADD, MAX_ARGC, 1, ARGS);
  640.                         FORI[KLevel]->ADD[0]=FORI[KLevel]->CYCL+1;
  641.                         break;
  642.                 case 1:
  643.                         //旋转器
  644.                         MAX_ARGC=args(Line+4, " ", ARGS, LIB_ARGS);
  645.                         ATOIargs(ROTE, MAX_ARGC, 1, ARGS);
  646.                         ROTE[0]=FORI[KLevel]->CYCL+1;
  647.                         break;
  648.                 case 2:
  649.                         //缩放器
  650.                         MAX_ARGC=args(Line+4, " ", ARGS, LIB_ARGS);
  651.                         for(j=0; j<MAX_ARGC; j++){ ZOOM[j+1]=atof(ARGS[j]);}
  652.                         ZOOM[0]=FORI[KLevel]->CYCL+1;
  653.                         break;
  654.                 case 3:
  655.                         //反转器
  656.                         MAX_ARGC=args(Line+4, " ", ARGS, LIB_ARGS);
  657.                         ATOIargs(REVE, MAX_ARGC, 1, ARGS);
  658.                         REVE[0]=FORI[KLevel]->CYCL+1;
  659.                         break;
  660.                 case 4:
  661.                         //透明器
  662.                         MAX_ARGC=args(Line+4, " ", ARGS, LIB_ARGS);
  663.                         ATOIargs(ALPH, MAX_ARGC, 1, ARGS);
  664.                         ALPH[0]=1;
  665.                         break;
  666.                 case 5:
  667.                         //参数器
  668.                         MAX_ARGC=args(Line+4, " ", ARGS, LIB_ARGS);
  669.                         ATOIargs(ATOI, MAX_ARGC, 1, ARGS);
  670.                         ATOI[0]=1;
  671.                         break;
  672.                 case 6:
  673.                         //绘图器
  674.                         MAX_ARGC=args(Line+4, " ", ARGS, LIB_ARGS);
  675.                         Shell_IMG(passNULL(ARGS[0]), FORI, KLevel, i);
  676.                         break;
  677.                 case 7:
  678.                         //延时毫秒
  679.                         Sleep(atoi(Line+4));
  680.                         break;
  681.                 case 8:
  682.                         //调用LIB脚本库
  683.                         Line=passNULL(Line+4);
  684.                         if(Line[0]=='|'&&Line[1]=='|'){
  685.                                 MAX_ARGC=args(Line+2, "|", ARGS, LIB_ARGS);
  686.                                 FileScript(ARGS[0], ARGS);
  687.                         }else{
  688.                                 fprintf(stdout, "[%d]:缺少库名。\n", i);
  689.                                 exit(1);                       
  690.                         }

  691.                         break;
  692.                 case 9:
  693.                         //跳转器                       
  694.                         strcpy(JMP_MARK, strupr(passNULL(Line+4)));
  695.                         i=KLevel=i=SFLAG[0]=0, SFLAG[1]=1;
  696.                         fseek(fp, 0, SEEK_SET);
  697.                         break;
  698.                 case 10:
  699.                         //移动光标
  700.                         if(args(Line+4, " ", ARGS, LIB_ARGS) >1){SetPos(atoi(ARGS[0]), atoi(ARGS[1]));}
  701.                         break;
  702.                 case 11:
  703.                         //退出
  704.                         exit( atoi(Line+4) );
  705.                         break;
  706.                 case 12:
  707.                         //暂停
  708.                         getch();
  709.                         break;
  710.                 case 13:
  711.                         //清屏
  712.                         Shell_CLS();
  713.                         break;
  714.                 case 14:
  715.                         //标题
  716.                         SetConsoleTitle(Line+4);
  717.                         break;
  718.                 case 15:
  719.                         //窗口尺寸
  720.                         if( args(Line+4, " ", ARGS, LIB_ARGS) >1){Shell_MODE_CON(atoi(ARGS[0]), atoi(ARGS[1]));}
  721.                         break;
  722.                 case 16:
  723.                         //字体颜色
  724.                         if( args(Line+4, " ", ARGS, LIB_ARGS) >3){Shell_COLOR(atoi(ARGS[0]), atoi(ARGS[1]), atoi(ARGS[2]), atoi(ARGS[3]));}
  725.                         break;
  726.                 case 17:
  727.                         //移动窗口
  728.                         if( args(Line+4, " ", ARGS, LIB_ARGS) >1){Shell_MW(atoi(ARGS[0]), atoi(ARGS[1]));}
  729.                         break;
  730.                 case 18:
  731.                         //呼叫器
  732.                         CAL_MARK=ftell(fp);
  733.                         SFLAG[2]=1;
  734.                         strcpy(JMP_MARK, strupr(passNULL(Line+4)));
  735.                         i=KLevel=i=SFLAG[0]=0, SFLAG[1]=1;
  736.                         fseek(fp, 0, SEEK_SET);
  737.                         break;
  738.                 case 19:
  739.                         //EOF结尾标签
  740.                         if(SFLAG[2]==1){
  741.                                 fseek(fp, CAL_MARK, SEEK_SET);
  742.                                 SFLAG[2]==0;
  743.                         }else{
  744.                                 return 0;
  745.                         }
  746.                         break;
  747.                 case 20:
  748.                         //字符显示函数
  749.                         fputs(Line+4,stdout);
  750.                         fputs("\r\n",stdout);
  751.                         break;
  752.                 case 21:
  753.                         //设置光标尺寸
  754.                         DispyCursor(atoi(Line+4), TRUE);
  755.                         break;
  756.                 case 255:
  757.                         fprintf(stdout, "[%d]:错误指令。\n", i);
  758.                         exit(1);
  759.                         break;
  760.                 }
  761.         }
  762.         free(SFLAG);
  763.         free(FORI);
  764.         free(LCache);
  765.         fclose(fp);
  766.         return 0;
  767. }


  768. /*************MAIN主函数入口*************/
  769. int main(int argc, char** argv)
  770. {
  771.         if(argc==2){
  772.                 //获得控制台窗口句柄
  773.                 hCMD=GetConsoleWindow();
  774.                 char* LIB_ARGS[16];
  775.                 FileScript(argv[1], LIB_ARGS);
  776.                 return 0;
  777.         }

  778.         //异常则抛出使用说明
  779.         fputs(
  780.                 "THE CONSOLE DISPLAYS A PICTURE SCRIPT, COPYRIGHT@2016~2018 BY HAPPY\n"
  781.                 "VERSION 1.0\n"
  782.                 "usage: powerimg [scriptfile]\n"
  783.                 ,stdout
  784.         );
  785.         return 1;
  786. }
复制代码
发表于 2016-11-28 13:51:40 | 显示全部楼层
楼主是第三方专业户了,很好很强大
发表于 2016-11-29 02:01:07 | 显示全部楼层
回复 3# happy886rr

我只是打发下时间,感谢你的意见。有空我去看看lua和html5
 楼主| 发表于 2016-11-29 09:14:49 | 显示全部楼层
回复 4# zhangzsky
如果你学了lua游戏开发的话,我想你会被其惊人的功能所震惊,这年头java都得借用lua。当年大话西游就是靠lua开发的。推荐你学学lua游戏制作,那可是一天就能搞出个三国志单机版。我都打算用lua 去做powerimg的解释器核心,但是迫于体积太大,lua有200KB之多。我的做第三方不愿体积超过30KB。
发表于 2016-11-29 12:35:52 | 显示全部楼层
本帖最后由 zhangzsky 于 2016-11-29 12:39 编辑

回复 5# happy886rr


    起初我只是想偶尔学学bat,然后想着写点什么,后来上班的电脑上到处都是,我基本上就双击下……
所以空出来时间写个游戏什么的锻炼下批处理……
已经跟起初的想法有出入了,自己文化水平有限。看来lua得空就看看也好
 楼主| 发表于 2016-11-29 12:55:22 | 显示全部楼层
回复 6# zhangzsky
批处理的优势在于批量操作,批量调用exe。
你做游戏,需要的是高效的工具,需要多媒体接口,能播放声音,显示动态画面,能2.5D旋转,这些批处理都不能实现。我觉得你的游戏设计思想很不错,你不应该被工具所局限,用批处理你只能做出那种简单的逐帧动画,但是你学学真正的游戏开发技术,会让你获得新生。
发表于 2017-1-7 17:06:55 | 显示全部楼层
求exe
发表于 2018-5-8 08:02:50 | 显示全部楼层
你多大年纪了
我要把你写的所有的都重新写一份
我正在写一款万能p-code虚拟机,
大神,收徒弟嘛,请收下我的膝盖
pm给我联系方式
发表于 2018-5-8 09:44:50 | 显示全部楼层
回复 8# gfwlxx


    听说他物理很好。
发表于 2020-4-22 08:59:09 | 显示全部楼层
编译不了,vs都不行,你这是设么鬼
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-16 23:26 , Processed in 0.025943 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表