bhwhui 发表于 2013-9-16 12:12:47

请教:Autoit怎么写个代码美化的程序?

本帖最后由 bhwhui 于 2013-9-19 17:55 编辑

最近用到EasyLanguage,竟然没有代码美化功能。程序长了,没法看啊。想用Autoit写个简单的代码美化程序,不用那么完美,只需实现Begin ... End对齐功能就行了。各位可以帮下忙,给个思路么?

easylanghuage代码片段如下:




inputs:oop1(500),oop2(500),oop3(500);

variable: sj(false),str0(""), str1(""), str2(""), str3(""), str4(""),tj1(0),tj2(0),tj3(0),tj4(0),dtx1(0),dtx2(0),dt1(0),dt2(0),dt3(0),
          appinfo1(0), close1(0),con1(0), fx1(1), mswitch1(0),real1(0), EnP1(0), ExP1(0), opennet1(0), nday1(0), ndate1(0),ntime1(0),xday1(0),
          appinfo2(0), close2(0),con2(0), fx2(1), mswitch2(0),real2(0), EnP2(0), ExP2(0), opennet2(0), nday2(0), ndate2(0),ntime2(0),xday2(0),
          appinfo3(0), close3(0),con3(0), fx3(1), mswitch3(0),real3(0), EnP3(0), ExP3(0), opennet3(0), nday3(0), ndate3(0),ntime3(0),xday3(0);

sj=((Currenttime_s >= 090000 and Currenttime_s <= 113000) or (Currenttime_s >= 130000 and Currenttime_s <= 151500) or Currenttime_s >= 210000 or Currenttime_s <= 023000);
appinfo1 = GVGetNamedInt("gvfour1_appinfo", - 999);
appinfo2 = GVGetNamedInt("gvfour2_appinfo", - 999);
appinfo3 = GVGetNamedInt("gvfour3_appinfo", - 999);

if getappinfo(aistrategyauto) = 1 and appinfo1 = 1 and appinfo2 = 1 and appinfo3 = 1 and sj then
begin
    //close1=GVGetNamedInt("gvfour1_close", - 999);
    con1 = GVGetNamedInt("gvfour1_con", - 999);
    fx1 = GVGetNamedInt("gvfour1_fx", - 999);
    real1 = GVGetNamedInt("gvfour1_real", - 999);
    EnP1 = GVGetNamedInt("gvfour1_entryp", - 999);
    ExP1 = GVGetNamedInt("gvfour1_exitp", - 999);
    nday1 = GVGetNamedInt("gvfour1_nday", - 999);
    ndate1 = GVGetNamedInt("gvfour1_ndate", - 999);
    ntime1 = GVGetNamedInt("gvfour1_ntime", - 999);
    xday1 = GVGetNamedInt("gvfour1_xday", - 999);
    opennet1 = GVGetNamedInt("gvfour1_opennet", - 999);
   
    //close2=GVGetNamedInt("gvfour2_close", - 999);
    con2 = GVGetNamedInt("gvfour2_con", - 999);
    fx2 = GVGetNamedInt("gvfour2_fx", - 999);
    real2 = GVGetNamedInt("gvfour2_real", - 999);
    EnP2 = GVGetNamedInt("gvfour2_entryp", - 999);
    ExP2 = GVGetNamedInt("gvfour2_exitp", - 999);
    nday2 = GVGetNamedInt("gvfour2_nday", - 999);
    ndate2 = GVGetNamedInt("gvfour2_ndate", - 999);
    ntime2 = GVGetNamedInt("gvfour2_ntime", - 999);
    xday2 = GVGetNamedInt("gvfour2_xday", - 999);
    opennet2 = GVGetNamedInt("gvfour2_opennet", - 999);
   
    //close3=GVGetNamedInt("gvfour3_close", - 999);
    con3 = GVGetNamedInt("gvfour3_con", - 999);
    fx3 = GVGetNamedInt("gvfour3_fx", - 999);
    real3 = GVGetNamedInt("gvfour3_real", - 999);
    EnP3 = GVGetNamedInt("gvfour3_entryp", - 999);
    ExP3 = GVGetNamedInt("gvfour3_exitp", - 999);
    nday3 = GVGetNamedInt("gvfour3_nday", - 999);
    ndate3 = GVGetNamedInt("gvfour3_ndate", - 999);
    ntime3 = GVGetNamedInt("gvfour3_ntime", - 999);
    xday3 = GVGetNamedInt("gvfour3_xday", - 999);
    opennet3 = GVGetNamedInt("gvfour3_opennet", - 999);

    if opennet1 <= (-1) * oop1 then
    begin
    real1=0;
    mswitch1=0;
    end;
   
    if opennet2 <= (-1) * oop2 then
    begin
    real2 = 0;
    mswitch2=0;
    end;

    if opennet3 <= (-1) * oop3 then
    begin
    real3 = 0;
    mswitch3=0;
    end;

   //mswitch1=0;
   //mswitch2=0;

   //Normal
if absvalue(real1)+absvalue(real2)+absvalue(real3)=0 then
   begin
   mswitch1=0;
   mswitch2=0;
   mswitch3=0;
   end;

   if absvalue(real1)+absvalue(real2)+absvalue(real3)=1 then
   begin
   mswitch1=real1;
   mswitch2=real2;
   mswitch3=real3;
   end;
   
   // ChongTu
    ifabsvalue(real1)+absvalue(real2)+absvalue(real3)>1 then
    begin
       //Fileappend("d:\gv_main422_Market.ini"," ...<<<TS: Main ChongTu>>>..." + newline);
      
       dtx1=ndate1-IntPortion(ndate1/10000)*10000;
       dtx2=IntPortion(dtx2/100);
       dt1=dtx2*31*24*60;

       dtx2=dtx1-IntPortion(dtx1/100)*100;
       dt1=dt1+dtx2*24*60;
       dtx2=IntPortion(ntime1/100);
       dt1=dt1+dtx2*60;
       dtx2=ntime1-IntPortion(ntime1/100)*100;
       dt1=dt1+dtx2;
      
      
       if opennet2<0 and nday2>0 and nday1=0 then
       begin
          Fileappend("d:\gv_main422_Market.ini", "   <Main ChongTu --> opennet2<0 and nday2>0 and nday1=0 >- - > 2 Ping ..." + newline + newline);
          mswitch2=0;
      end;

   end;//CT

GVSetNamedInt("mswitch1",mswitch1);
GVSetNamedInt("mswitch2",mswitch2);

if LastBarOnChart_sthen
begin
str1 = "Time:" + RightStr("000000" + NumToStr(currenttime_s, 0), 6) + " App1=" + NumToStr(appinfo1, 0) + " App2=" + NumToStr(appinfo2, 0) + " App3=" + NumToStr(appinfo3, 0) + " " +NewLine;
str2 = "            " En1=" + NumToStr(EnP1, 0) + " Ex1=" + NumToStr(ExP1, 0) + " Opennet1=" + NumToStr(opennet1, 0) + " Nday1=" + NumToStr(nday1, 0) + " Ndate1=" + NumToStr(ndate1, 0)+ " Ntime1=" + NumToStr(ntime1, 0)+ " Xday1=" + NumTostr(xday1, 0) + " "+NewLine;
str3 = "            " En2=" + NumToStr(EnP2, 0) + " Ex2=" + NumToStr(ExP2, 0) + " Opennet2=" + NumToStr(opennet2, 0) + " Nday2=" + NumToStr(nday2, 0) + " Ndate2=" + NumToStr(ndate2, 0)+ " Ntime2=" + NumToStr(ntime2, 0)+ " Xday2=" + NumToStr(xday2, 0) + " "+NewLine;
str4 = "            " En3=" + NumToStr(EnP3, 0) + " Ex3=" + NumToStr(ExP3, 0) + " Opennet3=" + NumToStr(opennet3, 0) + " Nday3=" + NumToStr(nday3, 0) + " Ndate3=" + NumToStr(ndate3, 0)+ " Ntime3=" + NumToStr(ntime3, 0)+ " Xday3=" + NumToStr(xday3, 0) + " "+NewLine;
str0 = str1 + str2 + str3+str4;
Fileappend("d:\gv_four_main.ini", str0);

//if mswitch1<>real1 then Fileappend("d:\gv_main422_Market.ini", "   <...Gzq1 Not Same ...>" + newline);
//if mswitch2<>real2 then Fileappend("d:\gv_main422_Market.ini", "   <...Gzq2 Not Same ...>" + newline);
end;

end; //if

kevinch 发表于 2013-9-16 21:01:10

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 623, 442, 192, 124)
$Edit1 = GUICtrlCreateEdit("", 8, 8, 601, 377)
GUICtrlSetData(-1, "")
$Button1 = GUICtrlCreateButton("整理", 8, 392, 89, 33)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        _Arrange()

        EndSwitch
WEnd

Func _Arrange()
           $str=StringRegExpReplace(GUICtrlRead($Edit1),"(?<=^|[\r\n])[\t ]+|[\t ]+(?=[\r\n]|$)","")
           $arr=StringSplit($str,@CRLF,1)
           $i=0
           $str=""
           For $n=1 To $arr
                   If stringregexp($arr[$n],"^begin",0)=1 Then
                        $str&=_StrRept(@tab,$i)&StringStripWS($arr[$n],3)&@CRLF
                           $i+=1
                   ElseIf StringRegExp($arr[$n],"^end;",0)=1 Then
                           $i-=1
                        $str&=_StrRept(@tab,$i)&StringStripWS($arr[$n],3)&@CRLF
                Else
                        $str&=_StrRept(@tab,$i)&StringStripWS($arr[$n],3)&@CRLF
                   EndIf
           Next
           GUICtrlSetData($Edit1,$str)
EndFunc

Func _StrRept($str,$n)
        $tmp=""
        If $n>0 Then
                For $i=1 To $n
                        $tmp&=$str
                Next
        EndIf
        Return $tmp
EndFunc这个试下

bhwhui 发表于 2013-9-19 17:51:46

谢谢,好用!

bhwhui 发表于 2013-9-19 17:55:56

已解决问题,改个标签就行了?
页: [1]
查看完整版本: 请教:Autoit怎么写个代码美化的程序?