#!PECMD2012
IFEX %&CurFile%.LOG, LOGS * %&CurFile%.LOG
TEAM ENVI^ EnviMode=1| ENVI^ ForceLocal=1
SET-env-def ProgramFiles=%ProgramFiles%
//要求 >= PECMD2012.1.69.40
SET ::WM_SIZE=0x0005
SET ::SIZE_MAXHIDE=4
SET ::SIZE_MAXSHOW=3
SET ::SIZE_MAXIMIZED=2
SET ::SIZE_MINIMIZED=1
SET ::SIZE_RESTORED=0
SET ::WM_RBUTTONDOWN=0x0204

//初始化变量名
_SUB INITVAR *
TEAM SET &N=1| SET &I=1| SET &SNAME=|  SET &ONAME=| SET &RUN=1
TEAM SET$ &NL=0d 0a|  SET &MSG=| SET &HTM=| SET &LS=0| SET &LNO=0
TEAM SET &CharSet=gbk| SET &LINES=
_END

//HTML
_SUB INIT_HTML
    SET HTM=1
    SET &COL[1]="#0000FF" //BLUE    //命令
    SET &COL[2]="#FF0000" //RED     //说明
    SET &COL[3]="#FFFF00" //YELLO   //控件
    SET &COLF="#00FF00"   //LGREEN  //符号 
    SET &COLM="#80A080"   //DGREEN  //注释 dark_green  gray
    SET &COLN="#000000"
    SET &ADDR=&amp;
    SET &LT=&lt;
    TEAM SET &CurCol=|  SET &BR=| SET &COLS1=<font color=|SET &COLS2=>| SET &COLE=</font>|
    CALL * INIT_WORD
    
    SET &MSGH=<HTML><HEAD><META charset=%CharSet%></HEAD> <BODY> <font face="宋体"> <table style="border-collapse:collapse;mso-table-layout-alt:fixed;padding:0.0000pt 5.4000pt 0.0000pt 5.4000pt;"> <tr><td width=138  valign=top  style="width:28.7500pt; padding:0.0000pt 5.4000pt 0.0000pt 5.4000pt; border-left:0.5000pt solid rgb(0,0,0); mso-border-left-alt:0.5000pt solid rgb(0,0,0); border-right:0.5000pt solid rgb(0,0,0); mso-border-right-alt:0.5000pt solid rgb(0,0,0); border-top:0.5000pt solid rgb(0,0,0); mso-border-top-alt:0.5000pt solid rgb(0,0,0); border-bottom:0.5000pt solid rgb(0,0,0); mso-border-bottom-alt:0.5000pt solid rgb(0,0,0); " ><pre>  
    SET &MSGHEND= </td><td   valign=top  style="width:100%;; padding:0.0000pt 5.4000pt 0.0000pt 5.4000pt; border-left:none;; mso-border-left-alt:none;; border-right:0.5000pt solid rgb(0,0,0); mso-border-right-alt:0.5000pt solid rgb(0,0,0); border-top:0.5000pt solid rgb(0,0,0); mso-border-top-alt:0.5000pt solid rgb(0,0,0); border-bottom:0.5000pt solid rgb(0,0,0); mso-border-bottom-alt:0.5000pt solid rgb(0,0,0); background:rgb(255,255,200);"><pre>
    SET MSG=
    SET &MSGEND=</td></tr></table> %NL%</font> </BODY> </HTML> %NL%
_END

//BBS
_SUB INIT_BBS
    SET HTM=0
    SET &COL[1]=navy       //BLUE    //命令
    SET &COL[2]=red        //RED     //说明
    SET &COL[3]=darkorange //YELLO   //控件
    SET &COLF=lime         //LGREEN  //符号 
    SET &COLM=dimgray      //DGREEN  //注释 dark_green
    SET &COLN=
    SET &ADDR=&
    SET &LT=<
    TEAM SET &CurCol=|  SET &BR=| SET &COLS1=[color=|SET &COLS2=]| SET &COLE=[/color]|
    CALL * INIT_WORD
   
    SET MSGH=[font=宋体][table=100%,lemonchiffon][tr][td=30]
    SET MSGHEND=[/td]
    SET MSG=[td]
    SET &MSGEND=[/td][/tr][/table][/font]
_END


_SUB INIT_WORD *
    SET &CMDS= ADSL BASE BROW CALC CALL CMPS CODE COME DATE DEVI DISK DISP EJEC ENVI EXEC EXIT FBWF FDIR FDRV FEXT FILE FIND FLNK FNAM FONT FORM FORX GETF 
    SET CMDS=%CMDS% HASH HELP HIDE HIVE HKEY HOME HOTK IFEX INIT KILL LINK LOAD LOCK LOGO LOGS LOOP LPOS LSTR MAIN MDIR MOUN MSTR 
    SET CMDS=%CMDS% NAME NOTE NUMK NTPC PAGE PART PATH PCIP PINT PUTF 
    SET CMDS=%CMDS% RAMD RAND READ RECY REGI RPOS RSTR RUNS SCRN SEND SERV SET  SITE SIZE SHEL SHOW SHUT SSTR STRL SUBJ 
    SET CMDS=%CMDS% TEAM TEXT THREAD TIME USER WALL WAIT WRIT 
    SET CMDS=%CMDS% ALias MSG SENDMSG POSTMSG DeskTopFresh  TaskIcoMenu  HelpColor  Clipboard FVER  DROPFILE Cur FPOS MouseCapture EATEKEYS  RMENU
    SET CMDS=%CMDS% poprmenu  runrmenu  InstallService  RemoveService 
    
    
    SET &SuoMing=  IMPORT _ENDFILE _SUB {  }  EnviMode EXPORTLOCAL FORCELOCAL this 
    
    SET &KongJian= CHEK EDIT GROU IMAG ITEM LABE LIST MEMO MENU MESS PBAR RADI TIPS  _END
    
    SET &FuHao= + -  *  = %  & | ^  /  @  
    SET &Comment1=;
    SET &Comment2=`
    SET &Comment=// %Comment1%  %Comment2%   
    
    SET &WORDS= 
    SET &I=1
    SET &v=
    FORX *      %CMDS%,&v,TEAM  SET &K[%I%]=%v%| SET WORDS=%WORDS% %v%|  SET &C[%I%]=%COL[1]%| CALC  #&I=%I% + 1
    
    FORX *   %SuoMing%,&v,TEAM  SET &K[%I%]=%v%| SET WORDS=%WORDS% %v%|  SET &C[%I%]=%COL[2]%| CALC  #&I=%I% + 1
    
    FORX *  %KongJian%,&v,TEAM  SET &K[%I%]=%v%| SET WORDS=%WORDS% %v%|  SET &C[%I%]=%COL[3]%| CALC  #&I=%I% + 1
    
    SET &NUM=
    CALC #NUM=%I% - 1
    TEAM SET &K[%I%]=|SET &C[%I%]=
    SET LNO=0
_END


_SUB TreatLineHtm
    CALC #LNO=%LNO% + 1
    IFEX $1=%LNO%,! SET MSGH=%MSGH%%NL%%BR%
    SET MSGH=%MSGH%%LNO%
    SET &MSG1=
    IFEX $1=%LNO%,! SET &MSG1=%NL%%BR%
    TEAM SET &J=0|SET &K=1| SET &E1=1|  SET &BCOML=0| SET &SPS=1 
    ENVI^ arg=*[:sp:=+-*/^@,;><?~`!|&$#%%]%L%
//    ENVI^ arg=*[:sp:=+-*/^,;><?~`!|&%%]%L%
    
    TEAM SET &LEN=| SET &M=|  SET &M2=
    LOOP #%J% < %#,
    {
        SET~. &W=%J%  // 函数参数 空
        IFEX $1= %BCOML%,  
        {
            SET MSG1=%MSG1%%W%
        }
        IFEX $1= %BCOML%,!  
        {
            STRL &LEN=%W%
            TEAM  SET M=1|  SET M2=2| ENVI CM=| ENVI CM2=
            LOOP #%M% <= %LEN%,
            {
                MSTR &CM=%M%,1,%W%
                MSTR &CM2=%M2%,1,%W%
                FIND $0 = %SPS%,! FIND $/= %CM%,!!  FIND $/= %CM2%,!! SET BCOML=1
                FIND $1=%BCOML%,!!  TEAM SET MSG1=%MSG1%%COLS1%%COLM%%COLS2%| MSTR &CM=%M%,-1,%W%

                SET OK=
                FIND $0=%BCOML%, FIND $/ = %CM%, SET OK=1!     FIND $& = %CM%, SET OK=1 
                FIND $+ = %CM%, SET OK=1!   
              \ FIND $- = %CM%, SET OK=1!  
              \ FIND $* = %CM%, SET OK=1!  
              \ FIND $| = %CM%, SET OK=1! 
              \ FIND $^ = %CM%, SET OK=1! 
              \ FIND $@ = %CM%, SET OK=1! 
              \ FIND $"%CM%"="=", SET OK=1
               
               FIND $& = %CM%, SET CM=%ADDR% 
               FIND $"%CM%"="<", SET CM=%LT% 
              
                FIND $1 = %OK%, SET MSG1=%MSG1%%COLS1%%COLF%%COLS2%
                SET MSG1=%MSG1%%CM%
                FIND $1 = %OK%, SET MSG1=%MSG1%%COLE%
                FIND $1=%BCOML%,!!  EXIT LOOP
                FIND $ = %CM%, SET SPS=1! SET SPS=0 
                SET M=%M2%
                CALC #&M2 = %M2% + 1
            }
            
            
            IFEX $1= %BCOML%,!  
            {
                CALC  #&J = %J% + 1 
                IFEX $#%J% >= %#, EXIT LOOP
        
        
                ENVI~. &W=%J%  // 函数参数
                TEAM SET &K=1| SET &OK=0
                LOOP #%K% <= %NUM%,
                {
                    SET~ &WK=K[%K%]
                    FIND $%W% = %WK% , TEAM SET OK=1| EXIT LOOP
                    CALC  #&K = %K% + 1 
                }
                SET~ &COLK=C[%K%]
                FIND $1 = %OK%, SET MSG1=%MSG1%%COLS1%%COLK%%COLS2%
                SET MSG1=%MSG1%%W%
                FIND $1 = %OK%, SET MSG1=%MSG1%%COLE%
            }
        }
        CALC #&J = %J% + 1 
    
    }
    FIND $1=%BCOML%,!!  TEAM SET MSG1=%MSG1%%COLE%
    SET MSG=%MSG%%MSG1%
_END



_SUB TreatLineBBS
    CALC #LNO=%LNO% + 1
    IFEX $1=%LNO%,! SET MSGH=%MSGH%%NL%%BR%
    SET MSGH=%MSGH%%LNO%
    SET &MSG1=
    IFEX $1=%LNO%,! SET &MSG1=%NL%%BR%
    TEAM SET &J=0|SET &K=1| SET &E1=1|  SET &BCOML=0| SET &SPS=1 
    ENVI^ arg=*[:sp:=+-*/^@,;><?~`!|&$#%%]%L%
    
    TEAM SET &LEN=| SET &M=|  SET &M2=
    LOOP #%J% < %#,
    {
        SET~. &W=%J%  // 函数参数 空
        IFEX $1= %BCOML%,  
        {
            SET MSG1=%MSG1%%W%
        }
        IFEX $1= %BCOML%,!  
        {
            STRL &LEN=%W%
            TEAM  SET M=1|  SET M2=2| ENVI CM=| ENVI CM2=
            LOOP #%M% <= %LEN%,
            {
                MSTR &CM=%M%,1,%W%
                MSTR &CM2=%M2%,1,%W%
                FIND $0 = %SPS%,! FIND $/= %CM%,!!  FIND $/= %CM2%,!! SET BCOML=1
                FIND $1=%BCOML%,!!  TEAM SET MSG1=%MSG1%%COLS1%%COLM%%COLS2%| MSTR &CM=%M%,-1,%W%

                SET OK=
                FIND $0=%BCOML%, FIND $/ = %CM%, SET OK=1!     FIND $& = %CM%, SET OK=1 
                FIND $+ = %CM%, SET OK=1!   
              \ FIND $- = %CM%, SET OK=1!  
              \ FIND $* = %CM%, SET OK=1!  
              \ FIND $| = %CM%, SET OK=1! 
              \ FIND $^ = %CM%, SET OK=1! 
              \ FIND $@ = %CM%, SET OK=1! 
              \ FIND $"%CM%" = "=", SET OK=1 

               //FIND $& = %CM%, SET CM=%ADDR% 
               //FIND $"%CM%" = "<", SET CM=%LT% 
              
                FIND $1 = %OK%, SET MSG1=%MSG1%%COLS1%%COLF%%COLS2%
                SET MSG1=%MSG1%%CM%
                FIND $1 = %OK%, SET MSG1=%MSG1%%COLE%
                FIND $1=%BCOML%,!!  EXIT LOOP
                FIND $X=X%CM%, SET SPS=1! SET SPS=0 
                SET M=%M2%
                CALC #&M2 = %M2% + 1
            }
            
            
            IFEX $1= %BCOML%,!  
            {
                CALC  #&J = %J% + 1 
                IFEX $#%J% >= %#, EXIT LOOP
        
        
                ENVI~. &W=%J%  // 函数参数
                TEAM SET &K=1| SET &OK=0
                LOOP #%K% <= %NUM%,
                {
                    SET~ &WK=K[%K%]
                    FIND $%W% = %WK% , TEAM SET OK=1| EXIT LOOP
                    CALC  #&K = %K% + 1 
                }
                SET~ &COLK=C[%K%]
                FIND $1 = %OK%, SET MSG1=%MSG1%%COLS1%%COLK%%COLS2%
                SET MSG1=%MSG1%%W%
                FIND $1 = %OK%, SET MSG1=%MSG1%%COLE%
            }
        }
        CALC #&J = %J% + 1 
    
    }
    FIND $1=%BCOML%,!!  TEAM SET MSG1=%MSG1%%COLE%
    SET MSG=%MSG%%MSG1%
_END


_SUB MAINTREAT
    IFEX $ 1 = %HTM%,  CALL * INIT_HTML!  CALL * INIT_BBS

    SET I=1
    
    SET LS=0
    READ %SNAME%,-1,&LS   
    
    CALC #&LS = %LS% + 0
    TEAM SET &N=1|  SET I=1
//DEBUG D111 111 
    
    SET &L=
//    LOOP #%N% <= %LS%,
    FORX *NL &LINES,&L,
    {
       IFEX $1 = %HTM%, CALL TreatLineHtm //%L%
       IFEX $0 = %HTM%, CALL TreatLineBBS //%L%
       FIND $1=%RUN%,! EXIT _SUB
       
       CALC  #&N = %N% + 1 
    }
//MESS. D111 222 @#OK
    
    SET &=222222222
    SET MSG=%MSGH%%MSGHEND%%MSG%  %MSGEND%
    //SET MSG=%MSG%  %MSGEND%
    
    FIND $=%ONAME%,!  FILE %ONAME%
    FIND $=%ONAME%,!  WRIT %ONAME%,$+0,%MSG%
  //MESS. %MSG% @#OK
//MESS. MAINTREAT END@#OK
_END

_SUB DEBUG
    MESS. %*@调试#OK
_END

///GUI

_SUB SELSRC
        TEAM BROW SRC,%ESRC%,请选择源文件,EXE| ENVI  @ESRC=%SRC%|  SET SNAME=%SRC%  
_END
_SUB SELOUT
        TEAM BROW OUT,&%EOUT%,请选择目标文件,EXE| ENVI  @EOUT=%OUT%|  SET ONAME=%OUT% 
_END

_SUB TRANS
    FIND $1 = %DisableWork%, EXIT _SUB 
    CALL TRANS1
    THREAD* CALL  TRANS_T
_END
_SUB TRANS_T
    CALL  MAINTREAT 
    ENVI @this.POSTMSG=#1
_END

_SUB TRANS1
     SET DisableWork=1
     SET RUN=1
     FIND $1= %RHTM.Check%, SET HTM=1!  SET HTM=0
     SET SNAME=%ESRC%  
     SET ONAME=%EOUT% 
     SET CharSet=%ECODE%
    
     SET TOCLIP=%KB.Check%
     SET LINES=
     READ %SNAME%,*r,&LINES
     FIND $ = %SNAME%, SET LINES=%EESRC%
     
     FIND $ = %LINES%, TEAM  MESS 输入源文件名或源内容 @#OK| EXIT _SUB
     ENVI @EEDST=  %SNAME%=>%ONAME% %NL%  转换中 ... ..    //CLEAR
     CALL  OnEEDST
     
     ENVI @BTRANS.Enable=0
_END
_SUB TRANS2
     FIND $1 = %RUN%,! SET MSG=
     ENVI @EEDST=%MSG%

     IFEX $1 = %TOCLIP%,  ENVI^ CLIPBOARD=%MSG%
     SET &br=1
     FIND $=%ONAME%, SET br=0
     FIND $0=%HTM%,  SET br=0
     FIND $1 = %KHTML.Check%,! SET br=0
     FDIR  --fullfile &&FullOName=%ONAME%
     FIND $0=%br%,! IFEX %ProgramFiles%\Internet Explorer\iexplore.exe,!! EXEC "%ProgramFiles%\Internet Explorer\iexplore.exe" %FullOName%
     FIND $0=%br%,! IFEX %ProgramFiles%\Internet Explorer\iexplore.exe,!  THREAD*  EXEC $%FullOName%
     ENVI @BTRANS.Enable=1
     WAIT 10
     SET DisableWork=0
_END


_SUB OnEESRC
     TEAM ENVI @RDST.Check=0|  ENVI @RSRC.Check=1| ENVI @EEDST.Visable=0|  ENVI @EESRC.Visable=1
_END

_SUB OnEEDST
     TEAM ENVI @RSRC.Check=0|  ENVI @RDST.Check=1| ENVI @EESRC.Visable=0|  ENVI @EEDST.Visable=1
_END

_SUB  MAKE_WIN, W600H400,PECMD脚本转换成语法着色HTML/BBS,SET RUN=0,,,,-size -maxb
      CALL * INITVAR
//    SET SNAME=T.WCS
      SET ONAME=T.HTM

      RADI RHTM, L20T20W65H20,HTML,,0,1

      LABE ,      L30T40W50H20,HTM编码: 
      EDIT ECODE, L30T60W50H20,%CharSet%
      
      RADI RBBS,  L20T90W65H20,BBS,,1,1


      CHEK KB,       L20T130W60H20,剪切板,,1 
      
      CHEK KHTML,       L20T160W70H20,打开HTML,,1 

      ITEM BTRANS,   L20T190W65H20,转换,     CALL TRANS
      
      RADI RSRC,     L200T98W50H20,输入,CALL OnEESRC,1,2
      RADI RDST,     L300T98W50H20,输出,CALL OnEEDST,0,2

      EDIT|- EESRC,   L100T128W450H220,%MSG%,,4 
      EDIT|- EEDST,   L100T128W450H220,%MSG%,,0x14 
//      ENVI @EEDST.Visable=0
      
      LABE ,         L100T32W70H20,  源文件: 
      EDIT ESRC,     L170T30W330H20,%SNAME%,,0x100
        ITEM ,       L500T30W50H20,选择, CALL SELSRC
        
      LABE ,         L100T62W70H20,目标文件:
      EDIT EOUT,     L170T60W330H20,%ONAME%,,0x100
        ITEM ,       L500T60W50H20,选择, CALL SELOUT
//TEAM ENVI @RSRC.Check=0|  ENVI @RDST.Check=1
      SET &DisableWork=0
      ENVI @this.MSG=%WM_SIZE%::&&wParm,&&lParm,CALL OnSize_WIN1 %wParm%  %lParm% 
      ////ENVI @this.MSG=_%::WM_RBUTTONDOWN%:  
      ENVI @this.MSG=#1: CALL TRANS2
      ENVI @this.POS=?::&&w0:&&h0
      SET &TOCLIP=1
        
_END
_SUB OnT1
    ENVI @this.POS=?::&&w:&&h
    FIND $%w% = %w0%,!! FIND $%h% = %h0%,!!  EXIT _SUB
    IFEX $%w% < 10, EXIT _SUB
    IFEX $%h% < 10, EXIT _SUB
    CALC #&w= %w% - (600 - 450)
    CALC #&h= %h% - (400 - 220)

    ENVI @EESRC.POS=::%w%:%h%
    ENVI @EEDST.POS=::%w%:%h%
_END

_SUB OnSize_WIN1
   TEAM SET &sz=0| SET &w=0| SET &h=0
   IFEX $%1 = %SIZE_MAXIMIZED%, SET sz=1
   IFEX $%1 = %SIZE_MAXSHOW%, SET sz=1
   IFEX $%1 = %SIZE_RESTORED%, SET sz=1
   IFEX $1=%sz%, CALL OnT1
_END



CALL  MAKE_WIN
