整合UMDH结果的一个小工具

ua.exe使用方法:

1、将UMDH生成的logcompare.txt改名为1.txt,内容示例:

  1 // Debug library initialized ...

  2 DBGHELP: moxia_d - private symbols & lines 

  3          E:\p06\run_client\Bin\moxia_d.pdb

  4 DBGHELP: ntdll - export symbols

  5 DBGHELP: kernel32 - export symbols

  6 DBGHELP: KERNELBASE - export symbols

  7 DBGHELP: dbghelp - public symbols  

  8          D:\Symbols\dbghelp.pdb\4BC9BC6DED254508BF3551E750E992643\dbghelp.pdb

  9 DBGHELP: msvcrt - public symbols  

 10          D:\Symbols\msvcrt.pdb\F1D253F9555C46DF8076400A52B3A9292\msvcrt.pdb

 11 DBGHELP: ADVAPI32 - export symbols

 12 DBGHELP: sechost - public symbols  

 13          D:\Symbols\sechost.pdb\7AF14D02D41E4CD6942745FE0E6372B11\sechost.pdb

 14 DBGHELP: RPCRT4 - export symbols

 15 DBGHELP: WINMM - public symbols  

 16          D:\Symbols\winmm.pdb\7AFD98FCAAD34F6B8B31A4667C4E2BFC2\winmm.pdb

 17 DBGHELP: USER32 - public symbols  

 18          D:\Symbols\user32.pdb\DD74D86F12624845A42A6A5BAAB4D7A82\user32.pdb

 19 DBGHELP: GDI32 - export symbols

 20 DBGHELP: LPK - export symbols

 21 DBGHELP: USP10 - export symbols

 22 DBGHELP: PSAPI - public symbols  

 23          D:\Symbols\psapi.pdb\A895A052F325481B9E2DA00A29E8D5DF2\psapi.pdb

 24 DBGHELP: wke - private symbols & lines 

 25          E:\p06\run_client\Bin\wke.pdb

 26 DBGHELP: ole32 - private symbols & lines 

 27          D:\Symbols\ole32.pdb\5061F11A9A57433595EA5EA75A156F4B2\ole32.pdb

 28 DBGHELP: iphlpapi - public symbols  

 29          D:\Symbols\iphlpapi.pdb\F162D2E137ED42978BF38C99AEE2DAAB2\iphlpapi.pdb

 30 DBGHELP: NSI - public symbols  

 31          D:\Symbols\nsi.pdb\D15A81679FAE4A7392344B6FD26867942\nsi.pdb

 32 DBGHELP: WINNSI - public symbols  

 33          D:\Symbols\winnsi.pdb\F7A0C25B1B0E4FA6876494D3F6BFD1012\winnsi.pdb

 34 DBGHELP: WS2_32 - public symbols  

 35          D:\Symbols\ws2_32.pdb\18C960B958404C4F80F686EE978A33D42\ws2_32.pdb

 36 DBGHELP: SHELL32 - export symbols

 37 DBGHELP: SHLWAPI - public symbols  

 38          D:\Symbols\shlwapi.pdb\E128B1CEE2EB438C8646E6967118F33E2\shlwapi.pdb

 39 DBGHELP: VERSION - public symbols  

 40          D:\Symbols\version.pdb\52234E5C7EC44646B62D56357B2C94872\version.pdb

 41 DBGHELP: MSIMG32 - public symbols  

 42          D:\Symbols\msimg32.pdb\13C89B70614E4E7FB1C677D443D15D182\msimg32.pdb

 43 DBGHELP: ijl15 - export symbols

 44 DBGHELP: MFC80D - private symbols & lines 

 45          D:\Symbols\MFC80D.i386.pdb\86AA8DF59ABF432D8650175ACAE12170e\MFC80D.i386.pdb

 46 DBGHELP: MSVCR80D - private symbols & lines 

 47          D:\Symbols\msvcr80d.i386.pdb\5B7548CDAC834BBCB4600BC0177659C61\msvcr80d.i386.pdb

 48 DBGHELP: COMCTL32 - export symbols

 49 DBGHELP: OLEAUT32 - public symbols  

 50          D:\Symbols\oleaut32.pdb\68047829A4754E789AC1C8035BA168CD2\oleaut32.pdb

 51 DBGHELP: MSVCP80D - private symbols & lines 

 52          D:\Symbols\msvcp80d.i386.pdb\C9DDCE5461B6402B8832D85B19A8B92F1\msvcp80d.i386.pdb

 53 DBGHELP: d3d9 - public symbols  

 54          D:\Symbols\d3d9.pdb\F55AEB50462B473F9733515DC6532DAF2\d3d9.pdb

 55 DBGHELP: d3d8thk - public symbols  

 56          D:\Symbols\d3d8thk.pdb\D9C3A335615F448EA0B012D76716E6B72\d3d8thk.pdb

 57 DBGHELP: dwmapi - public symbols  

 58          D:\Symbols\dwmapi.pdb\D8D91B3F339A4FDC960FC7121D146DF42\dwmapi.pdb

 59 DBGHELP: IMM32 - public symbols  

 60          D:\Symbols\imm32.pdb\91A0004474E24AA89F185029E31144892\imm32.pdb

 61 DBGHELP: MSCTF - public symbols  

 62          D:\Symbols\msctf.pdb\173DAEF86B2548DBA6134EB74C4D2F232\msctf.pdb

 63 DBGHELP: DSOUND - public symbols  

 64          D:\Symbols\dsound.pdb\F38F478065E247C68EDA699606F56EED2\dsound.pdb

 65 DBGHELP: POWRPROF - public symbols  

 66          D:\Symbols\powrprof.pdb\B1F8F66CCBAD4869BADFD20C1F24AC832\powrprof.pdb

 67 DBGHELP: SETUPAPI - public symbols  

 68          D:\Symbols\setupapi.pdb\C6B7CC380FCD42C29EDB1B61757DFD922\setupapi.pdb

 69 DBGHELP: CFGMGR32 - public symbols  

 70          D:\Symbols\cfgmgr32.pdb\93B1A0A82F114743AF9AABB1A17382462\cfgmgr32.pdb

 71 DBGHELP: DEVOBJ - public symbols  

 72          D:\Symbols\devobj.pdb\5EC40EC65C5045EB96F4CFDCFC6E19062\devobj.pdb

 73 DBGHELP: MFC80CHS - no symbols loaded

 74 DBGHELP: uxtheme - public symbols  

 75          D:\Symbols\UxTheme.pdb\5BECAB35E7714835A6BF3DADD891BB3A2\UxTheme.pdb

 76 DBGHELP: CRYPTBASE - public symbols  

 77          D:\Symbols\cryptbase.pdb\E62FEAE559EE4CD995614215B01AC2102\cryptbase.pdb

 78 DBGHELP: CLBCatQ - public symbols  

 79          D:\Symbols\CLBCatQ.pdb\00A720C79BAC402295B6EBDC147257182\CLBCatQ.pdb

 80 DBGHELP: mlang - export symbols

 81 DBGHELP: nvd3dum - export symbols

 82 DBGHELP: MMDevApi - public symbols  

 83          D:\Symbols\MMDevAPI.pdb\941E45A63E8F457D90CE29CC508C34B92\MMDevAPI.pdb

 84 DBGHELP: PROPSYS - public symbols  

 85          D:\Symbols\propsys.pdb\D0EDA507E53D4579A337F875012D7B482\propsys.pdb

 86 DBGHELP: AUDIOSES - public symbols  

 87          D:\Symbols\AudioSes.pdb\A88FCF91944949A8A1863D1592BB2FD12\AudioSes.pdb

 88 DBGHELP: quartz - public symbols  

 89          D:\Symbols\quartz.pdb\80E345FD1EE54FBAB8211528D99BC28C2\quartz.pdb

 90 DBGHELP: dhcpcsvc6 - export symbols

 91 DBGHELP: dhcpcsvc - public symbols  

 92          D:\Symbols\dhcpcsvc.pdb\D3E01A80603143AC83EA5801BEC674D82\dhcpcsvc.pdb

 93 DBGHELP: devenum - public symbols  

 94          D:\Symbols\devenum.pdb\728AEF77CC244D8BADC3F6255CE396B31\devenum.pdb

 95 DBGHELP: DShowRdpFilter - public symbols  

 96          D:\Symbols\DShowRdpFilter.pdb\4722ABE2B47D49B994FE311D5B2097BC1\DShowRdpFilter.pdb

 97 DBGHELP: WTSAPI32 - public symbols  

 98          D:\Symbols\wtsapi32.pdb\1F1D3CBAE8A447E5BF304735F21CB4132\wtsapi32.pdb

 99 DBGHELP: WINSTA - public symbols  

100          D:\Symbols\winsta.pdb\2A3148024D094FFEB24C3996E47658312\winsta.pdb

101 DBGHELP: slc - export symbols

102 DBGHELP: LAVSplitter - export symbols

103 DBGHELP: COMCTL32 - public symbols  

104          D:\Symbols\comctl32.pdb\B4CE90AAB95E4B89A22A7711DFD7E6EF2\comctl32.pdb

105 DBGHELP: avformat-lav-54 - export symbols

106 DBGHELP: avcodec-lav-54 - export symbols

107 DBGHELP: avutil-lav-51 - export symbols

108 DBGHELP: libbluray - export symbols

109 DBGHELP: VSFilter - export symbols

110 DBGHELP: COMDLG32 - public symbols  

111          D:\Symbols\comdlg32.pdb\96BC483CDFF04D1AAFE462F093B954EC2\comdlg32.pdb

112 DBGHELP: WINSPOOL - public symbols  

113          D:\Symbols\winspool.pdb\B165BBE7CD8C4F39BE373C0D9DFCD77B2\winspool.pdb

114 DBGHELP: WININET - export symbols

115 DBGHELP: urlmon - export symbols

116 DBGHELP: CRYPT32 - export symbols

117 DBGHELP: MSASN1 - public symbols  

118          D:\Symbols\msasn1.pdb\003D5F0E24804B20953A7A021B52FC322\msasn1.pdb

119 DBGHELP: iertutil - export symbols

120 DBGHELP: AviSplitter - export symbols

121 DBGHELP: OggSplitter - export symbols

122 DBGHELP: MpegSplitter - export symbols

123 DBGHELP: MpaSplitter - export symbols

124 DBGHELP: ffdshow - export symbols

125 DBGHELP: DINPUT - public symbols  

126          D:\Symbols\dinput.pdb\A355C027AC914C65A03AE2C06EBC117C1\dinput.pdb

127 DBGHELP: SspiCli - export symbols

128 DBGHELP: LAVAudio - export symbols

129 DBGHELP: msdmo - public symbols  

130          D:\Symbols\msdmo.pdb\7E91458399E34CF99F0C993D9128BB301\msdmo.pdb

131 DBGHELP: qasf - public symbols  

132          D:\Symbols\qasf.pdb\9BD26FFA3B5F4FDBA04379D9F92935DD1\qasf.pdb

133 DBGHELP: mp3dmod - public symbols  

134          D:\Symbols\MP3DMOD.pdb\54618A168148428DADB4CE0B4628168F2\MP3DMOD.pdb

135 DBGHELP: mfplat - public symbols  

136          D:\Symbols\MFPLAT.pdb\F512BAE9BAA14B87A898050CB20C0E3B2\MFPLAT.pdb

137 DBGHELP: AVRT - public symbols  

138          D:\Symbols\avrt.pdb\A15E148ACFC74F88A0A6DAF71CC916472\avrt.pdb

139 DBGHELP: ac3filter - export symbols

140 DBGHELP: ac3filter_intl - export symbols

141 DBGHELP: wdmaud - public symbols  

142          D:\Symbols\wdmaud.pdb\F232D0B492574D7992D5805BEF84A01E2\wdmaud.pdb

143 DBGHELP: ksuser - public symbols  

144          D:\Symbols\ksuser.pdb\7AE6BFAC128C4C57BAAF1C0B79FA95B42\ksuser.pdb

145 DBGHELP: msacm32 - public symbols  

146          D:\Symbols\msacm32.pdb\EB29395AE01743DB8C5DCB7F5A1350F91\msacm32.pdb

147 DBGHELP: MSACM32 - public symbols  

148          D:\Symbols\msacm32.pdb\3D318D5E38C54502B64578F0710A510F2\msacm32.pdb

149 DBGHELP: midimap - public symbols  

150          D:\Symbols\midimap.pdb\49F76FA53B854E54A748A2B4301471B62\midimap.pdb

151 DBGHELP: CRYPTSP - export symbols

152 DBGHELP: rsaenh - export symbols

153 //                                                                          

154 // Each log entry has the following syntax:                                 

155 //                                                                          

156 // + BYTES_DELTA (NEW_BYTES - OLD_BYTES) NEW_COUNT allocs BackTrace TRACEID 

157 // + COUNT_DELTA (NEW_COUNT - OLD_COUNT) BackTrace TRACEID allocations      

158 //     ... stack trace ...                                                  

159 //                                                                          

160 // where:                                                                   

161 //                                                                          

162 //     BYTES_DELTA - increase in bytes between before and after log         

163 //     NEW_BYTES - bytes in after log                                       

164 //     OLD_BYTES - bytes in before log                                      

165 //     COUNT_DELTA - increase in allocations between before and after log   

166 //     NEW_COUNT - number of allocations in after log                       

167 //     OLD_COUNT - number of allocations in before log                      

168 //     TRACEID - decimal index of the stack trace in the trace database     

169 //         (can be used to search for allocation instances in the original  

170 //         UMDH logs).                                                      

171 //                                                                          

172 

173 

174 + 80330496 ( 80330496 -      0)   5382 allocs    BackTrace1628EDB8

175 +    5382 (   5382 -      0)    BackTrace1628EDB8    allocations

176 

177     ntdll!EtwSetMark+000023ED

178     MSVCR80D!_heap_alloc_base+0000005C (f:\dd\vctools\crt_bld\self_x86\crt\src\malloc.c, 105)

179     MSVCR80D!_heap_alloc_dbg+000001F5 (f:\dd\vctools\crt_bld\self_x86\crt\src\dbgheap.c, 411)

180     MSVCR80D!_nh_malloc_dbg+00000019 (f:\dd\vctools\crt_bld\self_x86\crt\src\dbgheap.c, 268)

181     MSVCR80D!malloc+00000019 (f:\dd\vctools\crt_bld\self_x86\crt\src\dbgheap.c, 154)

182     moxia_d!stRleFrame::Read+0000012D (e:\p06\sources\cache\stframe.cpp, 1331)

183     moxia_d!stRleGroup::Load+0000011E (e:\p06\sources\cache\stframe.cpp, 1521)

184     moxia_d!cResourceRle::LoadAGroup+00000072 (e:\p06\sources\cache\cresourcerle.cpp, 615)

185     moxia_d!Load+0000007A (e:\p06\sources\cache\cresource.cpp, 89)

186     moxia_d!PreloadRes+000000C9 (e:\p06\sources\cache\cresource.cpp, 119)

187     MFC80D!_AfxThreadEntry+000002DC (f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\thrdcore.cpp, 109)

188     MSVCR80D!_callthreadstartex+00000051 (f:\dd\vctools\crt_bld\self_x86\crt\src\threadex.c, 348)

189     MSVCR80D!_threadstartex+00000087 (f:\dd\vctools\crt_bld\self_x86\crt\src\threadex.c, 331)

190     kernel32!BaseThreadInitThunk+00000012

191     ntdll!RtlInitializeExceptionChain+000000EF

192     ntdll!RtlInitializeExceptionChain+000000C2

193 

194 + 15728662 ( 15728662 -      0)      1 allocs    BackTrace849BAB0

195 +       1 (      1 -      0)    BackTrace849BAB0    allocations

196 

197     ntdll!EtwSetMark+000023ED

198     MSVCR80D!_heap_alloc_base+0000005C (f:\dd\vctools\crt_bld\self_x86\crt\src\malloc.c, 105)

199     MSVCR80D!_heap_alloc_dbg+000001F5 (f:\dd\vctools\crt_bld\self_x86\crt\src\dbgheap.c, 411)

200     MSVCR80D!_nh_malloc_dbg+00000019 (f:\dd\vctools\crt_bld\self_x86\crt\src\dbgheap.c, 268)

201     MSVCR80D!malloc+00000019 (f:\dd\vctools\crt_bld\self_x86\crt\src\dbgheap.c, 154)

202     MSVCR80D!operator new+0000000F (f:\dd\vctools\crt_bld\self_x86\crt\src\new.cpp, 59)

203     MSVCP80D!std::_Allocate<char>+00000043 (f:\dd\vctools\crt_bld\self_x86\crt\src\xmemory, 44)

204     MSVCP80D!std::allocator<char>::allocate+00000012 (f:\dd\vctools\crt_bld\self_x86\crt\src\xmemory, 152)

205     moxia_d!std::vector<char,std::allocator<char> >::_Insert_n+00000139

206     moxia_d!std::vector<char,std::allocator<char> >::resize+00000075

207     moxia_d!std::vector<char,std::allocator<char> >::resize+0000001C

208     moxia_d!cBmp::Load+00000176 (e:\p06\sources\cache\cfont.cpp, 346)

209     moxia_d!cFont::Load+000001C0 (e:\p06\sources\cache\cfont.cpp, 91)

210     moxia_d!CMainWnd::OnCreate+000001DE (e:\p06\sources\client\mainwnd.cpp, 910)

211     MFC80D!CWnd::OnWndMsg+000007FE (f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\wincore.cpp, 2000)

212     MFC80D!CWnd::WindowProc+00000030 (f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\wincore.cpp, 1741)

213     moxia_d!CMainWnd::WindowProc+000018C0 (e:\p06\sources\client\mainwndinput.cpp, 3967)

214     MFC80D!AfxCallWndProc+000000EE (f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\wincore.cpp, 240)

215     MFC80D!AfxWndProc+000000A4 (f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\wincore.cpp, 389)

216     MFC80D!AfxWndProcBase+00000059 (f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\afxstate.cpp, 411)

217     USER32!InternalCallWinProc+00000023

218     USER32!UserCallWinProcCheckWow+000000E0

219     USER32!DispatchClientMessage+000000DA

220     USER32!__fnINLPCREATESTRUCT+0000008B

221     ntdll!KiUserCallbackDispatcher+0000002E

222     USER32!_CreateWindowEx+00000201

223     USER32!CreateWindowExA+00000033

224     MFC80D!AfxCtxCreateWindowExA+000000A1 (f:\dd\vctools\vc7libs\ship\atlmfc\include\afxcomctl32.h, 438)

225     MFC80D!CWnd::CreateEx+0000014A (f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\wincore.cpp, 694)

226     MFC80D!CWnd::CreateEx+0000005B (f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\wincore.cpp, 659)

227     moxia_d!CMainWnd::Create+000003B7 (e:\p06\sources\client\mainwnd.cpp, 778)

228     moxia_d!CGameClient::InitInstance+00000984 (e:\p06\sources\client\client.cpp, 558)

229 

230 

231 /////////////////////////////////////////////////////////

232 // 后面还有很多 ............

 

2、使用脚本运行:

 1 ua.exe 1.txt -yes:ScriptMgr::LoadFile

 2 ua.exe 2.txt -yes:cBmp::Load

 3 ua.exe 3.txt -yes:cStatic::RestoreDeviceObjects

 4 ua.exe 4.txt -yes:cBackground::LoadFile

 5 ua.exe 5.txt -yes:cPropertyTable::Load

 6 ua.exe 6.txt -yes:CD3DApplication::Create

 7 ua.exe 7.txt -yes:PreloadRes

 8 ua.exe 8.txt -yes:LeaderBoardCMgr::Init

 9 ua.exe 9.txt -yes:Magic_CreateStatic

10 ua.exe 10.txt -yes:CMainWnd::CreateGui

11 ua.exe 11.txt -yes:cDevice::MDDrawPresent

12 ua.exe 12.txt -yes:cMp3::PlayNext

13 ua.exe 13.txt -yes:e:\p06\sources\tolua\lparser.c

14 ua.exe 14.txt -yes:cWorldClient::CreateTable

15 ua.exe 15.txt -yes:CMainWnd::CreateSoundManager

16 ua.exe 16.txt -yes:CMainWnd::OnCreate

17 ua.exe 17.txt -no:moxia_d!

18 ua.exe 18.txt -yes:CMainWnd::Draw

19 ua.exe 19.txt -whatever

3、生成结果示例:

整合UMDH结果的一个小工具

生成ua.exe的代码:

  1 #include <stdafx.h>

  2 #include <windows.h>

  3 #include <assert.h>

  4 #include <string>

  5 #include <vector>

  6 #include <Psapi.h>

  7 using namespace std;

  8 

  9 // void string_MakeSurePathExists2( string path )

 10 // {

 11 //     assert(path.find('/') == string::npos);

 12 // 

 13 //     int index = path.find("\\", 0);

 14 //     while (index != string::npos)

 15 //     {

 16 //         CreateDirectoryA(path.substr(0, index).c_str(), NULL);

 17 //         index = path.find("\\", index + 1);

 18 //     }

 19 // }

 20 #define LINES 64

 21 #define BUFS 1024

 22 

 23 typedef char TBUFF[BUFS];

 24 

 25 bool readline(FILE* fp, TBUFF buf)

 26 {

 27     int index = 0;

 28     while (1)

 29     {

 30         char& ch = buf[index];

 31         if (0 == fread(&ch, 1, 1, fp))

 32         {

 33             if (index > 0)

 34             {

 35                 buf[index + 1] = 0;

 36                 return true;

 37             }

 38 

 39             return false;

 40         }

 41         if (ch == '\n')

 42         {

 43             buf[index + 1] = 0;

 44             return true;

 45         }

 46         if (++index >= BUFS - 1)

 47             return false;

 48     }

 49     return false;

 50 }

 51 

 52 inline bool isemptychar(char ch)

 53 {

 54     return (ch == ' ' || ch == '\r' || ch == '\n' || ch == '\t');

 55 }

 56 

 57 bool isemptyline(TBUFF buf)

 58 {

 59     int i = 0;

 60     char ch;

 61     while (ch = buf[i++])

 62     {

 63         if (!isemptychar(ch))

 64             return false;

 65     }

 66     return true;

 67 }

 68 

 69 bool readblock(FILE* fp, TBUFF bufs[LINES], int& lines)

 70 {

 71     bool bPlus = false;

 72     bool bGTH = false;

 73     lines = 0;

 74 

 75     while (1)

 76     {

 77         TBUFF& pLine = bufs[lines];

 78         if (!readline(fp, pLine))

 79         {

 80             return bPlus;

 81         }

 82 

 83         bool bFirst = ((pLine[0] == '+' || pLine[0] == '-') && strstr(pLine, "allocs"));

 84         if (!bPlus)

 85         {

 86             if (bFirst)

 87                 bPlus = true;

 88         }

 89         else

 90         {

 91             if (!bGTH)

 92             {

 93                 if (strstr(pLine, "!"))

 94                     bGTH = true;

 95             }

 96             else 

 97             {

 98                 if (isemptyline(pLine))

 99                 {

100                     ++lines;

101                     return true;

102                 }

103             }

104         }

105 

106         if (bPlus)

107             ++lines;

108     }

109 }

110 

111 int getbytesfromrow(TBUFF buf)

112 {

113 //    int positive = (buf[0] == '+');

114 

115     char nums[16] = {0};

116     int N = 0;

117 

118     int B = 0;

119     char ch;

120 

121     bool bFound = false;

122 

123     while (ch = buf[B++])

124     {

125         if (!bFound)

126         {

127             if (ch >= '0' && ch <= '9')

128             {

129                 bFound = true;

130                 nums[N++] = ch;

131             }

132         }

133         else

134         {

135             if (ch >= '0' && ch <= '9')

136                 nums[N++] = ch;

137             else

138                 break;

139         }

140     }

141 

142     if (N == 0)

143         return 0;

144     return atoi(nums);

145 }

146 

147 void handleinvalidfilename(char* p)

148 {

149     static const char invalid_ch[] = { '/','\\',':','*','?','<','>','|' };

150     while (*p)

151     {

152         for (int i = 0; i < sizeof(invalid_ch); i++)

153         {

154             if (*p == invalid_ch[i])

155             {

156                 *p = '_';

157                 break;

158             }

159         }

160         p++;

161     }

162 }

163 

164 struct ParamInfo

165 {

166     BOOL bWhatever; // 当这个为TRUE,下面2个无效

167     std::vector<std::string > vecKeyYes;

168     std::vector<std::string > vecKeyNo;

169 };

170 

171 bool matchparam(TBUFF bufs[LINES], int lines, ParamInfo* param)

172 {

173     if (param->bWhatever)

174         return true;

175 

176     bool bHaveNo = param->vecKeyNo.size() > 0;

177     bool bHaveYes = param->vecKeyYes.size() > 0;

178 

179     if (bHaveNo)

180     {

181         for (int i = 0; i < lines; i++)

182         {

183             TBUFF& buf = bufs[i];

184             for (int j = 0; j < (int)param->vecKeyNo.size(); j++)

185             {

186                 if (strstr(buf, param->vecKeyNo[j].c_str()))

187                     return false;

188             }

189         }

190     }

191 

192     if (bHaveYes)

193     {

194         for (int i = 0; i < lines; i++)

195         {

196             TBUFF& buf = bufs[i];

197             for (int j = 0; j < (int)param->vecKeyYes.size(); j++)

198             {

199                 if (strstr(buf, param->vecKeyYes[j].c_str()))

200                     return true;

201             }

202         }

203         return false;

204     }

205     else

206     {

207         return true;

208     }

209 }

210 

211 #define KeyWhatever  "-whatever"    // 随便什么都算

212 #define KeyYes  "-yes:"             // 必须某一行包含这个

213 #define KeyNo  "-no:"               // 所有行不得包含这个

214 

215 void parseparam(char* argv, ParamInfo* param)

216 {

217     param->bWhatever = FALSE;

218     char* p;

219     if (strstr(argv, KeyWhatever) == argv)

220     {

221         param->bWhatever = TRUE;

222     }

223     else if (strstr(argv, KeyYes) == argv)

224     {

225         p = argv + strlen(KeyYes);

226         param->vecKeyYes.push_back(p);

227     }

228     else if (strstr(argv, KeyNo) == argv)

229     {

230         p = argv + strlen(KeyNo);

231         param->vecKeyNo.push_back(p);

232     }

233 }

234 

235 // 检查参数

236 // 返回 true表示可以继续执行

237 bool checkparam(ParamInfo* param)

238 {

239     if (param->bWhatever)

240     {

241         if (param->vecKeyYes.size() > 0 || param->vecKeyNo.size() > 0)

242         {

243             printf("警告:已指定%s,将忽略其它参数\n", KeyWhatever);

244         }

245         return true;

246     }

247     else

248     {

249         if (param->vecKeyYes.size() > 0 || param->vecKeyNo.size() > 0)

250         {

251             return true;

252         }

253         else

254         {

255             printf("错误:没有指定任何有效参数\n");

256             return false;

257         }

258     }

259 }

260 

261 void printusage()

262 {

263     printf("用法: this.exe TARGETFILE [%s] | [[%sxxx] * N] [[%syyy] * N]"

264         "\nTARGETFILE 请从 1.txt 开始"

265         "\n%s表示所有都匹配"

266         "\n%s表示任何一行带有这个就行"

267         "\n%s表示任何一行都不得带这个"

268         "\n例如:this.exe 1.txt %s"

269         "\n例如:this.exe 1.txt %sScriptMgr::LoadFile %scBmp::Load"

270         "\n例如:this.exe 1.txt %smoxia_d!"

271         "\n",

272         KeyWhatever, KeyYes, KeyNo, 

273         KeyWhatever, 

274         KeyYes, 

275         KeyNo, 

276         KeyWhatever, 

277         KeyYes, KeyYes, 

278         KeyNo

279         );

280 

281     getchar();

282 }

283 

284 void main(int argc, char* argv[])

285 {   

286     if (argc < 3)

287     {

288         printusage();

289         return;

290     }

291 

292     FILE* fpSrc = 0;

293     FILE* fpDst = 0;

294     std::string t1, t2;

295     FILE* fpT1 = 0;

296     FILE* fpT2 = 0;

297 

298     int bytesSum = 0;

299     char outputFolderName[MAX_PATH];

300     char outputFolderNameR[MAX_PATH];

301 

302     do

303     {

304         // src file

305         const char* fileName = argv[1];

306         fpSrc = fopen(fileName, "r");

307         if (NULL == fpSrc) 

308         {

309             printf("open %s error.\n", fileName);

310             break;

311         }

312 

313         // dst file

314         char RfileName[MAX_PATH];

315         sprintf(RfileName, "%d.txt", atoi(fileName) + 1);

316         fpDst = fopen(RfileName, "w");

317         if (NULL == fpDst) 

318         {

319             printf("open %s error.\n", RfileName);

320             break;

321         }

322 

323         // parameters

324         ParamInfo param;

325         for (int i = 2; i < argc; i++)

326         {

327             parseparam(argv[i], &param);

328         }

329         if (!checkparam(&param))

330         {

331             printusage();

332             break;

333         }

334 

335         // dst folder

336         memset(outputFolderName, 0, MAX_PATH);

337         if (param.bWhatever)

338             sprintf(outputFolderName, "%d %s", atoi(fileName), KeyWhatever);

339         else if (param.vecKeyYes.size() > 0)

340             sprintf(outputFolderName, "%d %s", atoi(fileName), param.vecKeyYes[0].c_str());

341         else if (param.vecKeyNo.size() > 0)

342             sprintf(outputFolderName, "%d no %s", atoi(fileName), param.vecKeyNo[0].c_str());

343         else

344             sprintf(outputFolderName, "%d", atoi(fileName));

345         handleinvalidfilename(outputFolderName);

346         if (!CreateDirectory(outputFolderName, NULL))

347         {

348             printf("CreateDirectory %s error.\n", outputFolderName);

349             break;

350         }

351         t1 = std::string(outputFolderName) + "\\1.txt";

352         t2 = std::string(outputFolderName) + "\\2.txt";

353         fpT1 = fopen(t1.c_str(), "w");

354         fpT2 = fopen(t2.c_str(), "w");

355 

356         TBUFF bufs[LINES];

357         int lines;

358         while (1)

359         {

360             if (!readblock(fpSrc, bufs, lines))

361             {

362                 break;

363             }

364 

365             // 是否 match

366             bool bMatch = matchparam(bufs, lines, &param);

367             if (!bMatch)

368             {

369                 // 不匹配就输出到下一个文本中

370                 for (int i = 0; i < lines; i++)

371                     fprintf(fpDst, bufs[i]);

372             }

373             else

374             {

375                 // 匹配就输出到对应的文件夹内

376                 int bytes = getbytesfromrow(bufs[0]);

377                 if (bufs[0][0] == '-')

378                     bytes = -bytes;

379                 fprintf(fpT1, "%d\n", bytes);

380                 bytesSum += bytes;

381                 for (int i = 0; i < lines; i++)

382                     fprintf(fpT2, bufs[i]);

383             }

384         }

385 

386         fprintf(fpT1, "Total %d\n", bytesSum);

387 

388     } while(false);

389 

390     if (fpSrc) fclose(fpSrc);

391     if (fpDst) fclose(fpDst);

392     if (fpT1) fclose(fpT1);

393     if (fpT2) fclose(fpT2);   

394 

395     if (abs(bytesSum) >= 1024 * 1024)

396         sprintf(outputFolderNameR, "%s (%.1f MB)", outputFolderName, (float)bytesSum/1024/1024);

397     else if (abs(bytesSum) >= 1024)

398         sprintf(outputFolderNameR, "%s (%d KB)", outputFolderName, bytesSum/1024);

399     else

400         sprintf(outputFolderNameR, "%s (%d Bytes)", outputFolderName, bytesSum);

401     rename(outputFolderName, outputFolderNameR);

402 }

 

你可能感兴趣的:(整合)