📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "DiffRidder.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_COMMAND(IDM_SAMELINE_RIDDER, OnSamelineRidder)
ON_COMMAND(IDM_GETRIDOFF_OFFSET_ADDRESS, OnGetridoffOffsetAddress)
ON_COMMAND(IDM_GETRIDOFF_OFFSET_AND_U, OnGetridoffOffsetAndU)
ON_MESSAGE(WM_USR_CALL_SETPANETEXT, OnCallSetPaneText)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.cx = ::GetSystemMetrics(SM_CXFULLSCREEN) * 4 / 5;
cs.cy = ::GetSystemMetrics(SM_CYFULLSCREEN) * 4 / 5;
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::OnSamelineRidder()
{
// TODO: Add your command handler code here
CSelectFileDialog dlg;
if(IDOK == dlg.DoModal()){
m_strFileOne = dlg.m_strFilenameOne;
m_strFileTwo = dlg.m_strFilenameTwo;
m_strFileOne.TrimLeft(); if(m_strFileOne.IsEmpty()){ return; }
m_strFileTwo.TrimLeft(); if(m_strFileTwo.IsEmpty()){ return; }
DWORD ThreadID;
HANDLE hThread = CreateThread(NULL, 0, ThreadGetRifOffSameLine, NULL, CREATE_SUSPENDED, &ThreadID);
BOOL bPrior = SetThreadPriority(hThread, THREAD_PRIORITY_NORMAL);
ASSERT(bPrior);
ResumeThread(hThread);
// return hThread;
}
}
void CMainFrame::OnGetridoffOffsetAddress()
{
// TODO: Add your command handler code here
// TODO: Add your command handler code here
CFileDialogEx dlg(TRUE,
_T(""),
_T(""),
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("所有文件(*.*)|*.*|"));
if(IDOK == dlg.DoModal()){
CString strFileName = dlg.GetPathName();
CString strFileDst = strFileName + _T(".o");
FILE * fsrc = NULL;
FILE * fdst = NULL;
if(NULL == (fsrc = fopen(strFileName.GetBuffer(0), "rb"))){
return;
}
if(NULL == (fdst = fopen(strFileDst.GetBuffer(0), "wb"))){
fclose(fsrc);
return;
}
BYTE *prev, *curr, *shft, *anchor, buffer[4096];
LONG reads, bytes = 0;
do{
if((reads = fread(buffer + bytes, 1, sizeof(buffer) - bytes, fsrc)) < 0){
break;
}else{
prev = buffer;
curr = buffer;
shft = buffer;
anchor = buffer;
}
while(curr < (buffer + reads)){
if(*curr == '\n'){
BOOL fcheck = FALSE;
BYTE * p = prev;
if(*p == '0'){
while(isxdigit(*p)){ ++ p; } if(*p == ' '){ ++p; fcheck = TRUE; }
}else if(*p == ' '){
while(*p == ' '){ ++p; } if((p - prev) >= 8) { fcheck = TRUE; }
}
if(TRUE == fcheck && p < curr && *(p+1)==' ' &&
(*p=='T' || *p=='t' || *p=='U' || *p=='D' || *p=='R' || *p=='C')){
;/* Is a line with offset address, shift left from p */
}else{
/* a line with unkown format, shift left from prev */
p = prev;
}
while(p <= curr){
*shft ++ = *p++;
}
prev = curr + 1;
anchor = curr;
}
++curr;
}
bytes = shft - buffer;
if(bytes > 0 && fwrite(buffer, bytes, 1, fdst) <= 0){
break;
}
if(anchor && *anchor == '\n'){ /* bytes not writen to destfile, shift left to start */
++anchor;
bytes = sizeof(buffer) - (anchor - buffer);
memcpy(buffer, anchor, bytes);
}else{
bytes = 0;
}
}
while(reads > 0);
if(bytes > 0){
fwrite(buffer, bytes, 1, fdst);
}
fclose(fsrc);
fclose(fdst);
}
}
void CMainFrame::OnGetridoffOffsetAndU()
{
// TODO: Add your command handler code here
CFileDialogEx dlg(TRUE,
_T(""),
_T(""),
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("所有文件(*.*)|*.*|"));
if(IDOK == dlg.DoModal()){
CString strFileName = dlg.GetPathName();
CString strFileDst = strFileName + _T(".o");
FILE * fsrc = NULL;
FILE * fdst = NULL;
if(NULL == (fsrc = fopen(strFileName.GetBuffer(0), "rb"))){
return;
}
if(NULL == (fdst = fopen(strFileDst.GetBuffer(0), "wb"))){
fclose(fsrc);
return;
}
BYTE *prev, *curr, *shft, *anchor, buffer[4096];
LONG reads, bytes = 0;
do{
if((reads = fread(buffer + bytes, 1, sizeof(buffer) - bytes, fsrc)) < 0){
break;
}else{
prev = buffer;
curr = buffer;
shft = buffer;
anchor = buffer;
}
while(curr < (buffer + reads)){
if(*curr == '\n'){
BOOL isrefer = FALSE;
BOOL fcheck = FALSE;
BYTE * p = prev;
if(*p == '0'){
while(isxdigit(*p)){ ++ p; } if(*p == ' '){ ++p; fcheck = TRUE; }
}else if(*p == ' '){
while(*p == ' '){ ++p; } if((p - prev) >= 8) { fcheck = TRUE; }
}
if(TRUE == fcheck && p < curr && *(p+1)==' ' &&
(*p=='T' || *p=='t' || *p=='U' || *p=='D' || *p=='R' || *p=='C')){
;/* Is a line with offset address, shift left from p */
if(*p == 'U'){
isrefer = TRUE;
}
}else{
/* a line with unkown format, shift left from prev */
p = prev;
}
if(FALSE == isrefer){
while(p <= curr){
*shft ++ = *p++;
}
}
prev = curr + 1;
anchor = curr;
}
++curr;
}
bytes = shft - buffer;
if(bytes > 0 && fwrite(buffer, bytes, 1, fdst) <= 0){
break;
}
if(anchor && *anchor == '\n'){ /* bytes not writen to destfile, shift left to start */
++anchor;
bytes = sizeof(buffer) - (anchor - buffer);
memcpy(buffer, anchor, bytes);
}else{
bytes = 0;
}
}
while(reads > 0);
if(bytes > 0){
fwrite(buffer, bytes, 1, fdst);
}
fclose(fsrc);
fclose(fdst);
}
}
DWORD WINAPI CMainFrame::ThreadGetRifOffSameLine(LPVOID lpParam)
{
CMainFrame * lpFrame = (CMainFrame *)AfxGetMainWnd();
CString strFileOne = lpFrame->m_strFileOne;
CString strFileTwo = lpFrame->m_strFileTwo;
CStringList listone;
CStringList listtwo;
strFileOne.TrimLeft(); if(strFileOne.IsEmpty()){ return -1L; }
strFileTwo.TrimLeft(); if(strFileTwo.IsEmpty()){ return -1L; }
for(int step = 0; step < 2; ++step)
{
BYTE *prev, *curr, *anchor, buffer[4096];
FILE *fsrc = NULL;
CString str;
LONG reads, bytes = 0;
if(NULL == (fsrc = fopen((step==0 ? strFileOne.GetBuffer(0) : strFileTwo.GetBuffer(0)), "rb"))){
return -1L;
}else{
bytes = 0L;
}
do{
if((reads = fread(buffer + bytes, 1, sizeof(buffer) - bytes, fsrc)) < 0){
break;
}else{
prev = buffer;
curr = buffer;
anchor = buffer;
}
while(curr < (buffer + reads)){
if(*curr == '\n' || *curr=='\r'){
/* store line to stringlist */
*curr = '\0';
str = _T(prev);
if(0 == step){
listone.AddTail(str);
}else{
listtwo.AddTail(str);
}
for(++curr; (*curr == '\n' || *curr=='\r') && curr < (buffer + reads); ++curr){
; /* do nothing */
}
prev = curr;
anchor = curr;
}else{
++curr;
}
}
if(anchor < (buffer + reads)){ /* bytes not writen to destfile, shift left to start */
bytes = sizeof(buffer) - (anchor - buffer);
memcpy(buffer, anchor, bytes);
}else{
bytes = 0;
}
}
while(reads > 0);
if(bytes > 0){
buffer[bytes] = '\0';
str = _T(buffer);
if(0 == step){
listone.AddTail(str);
}else{
listtwo.AddTail(str);
}
}
fclose(fsrc);
}
POSITION posOne = listone.GetHeadPosition();
LONG iTotal = listone.GetCount();
LONG iCount = 0L;
LONG i, j;
LONG iRemand = iTotal;
while(posOne){
CString & strOne = listone.GetNext(posOne);
++iCount;
if(!strOne.IsEmpty()){
CMainFrame * lpFrame = (CMainFrame *)AfxGetMainWnd();
POSITION cursor;
POSITION postemp;
BOOL fDiff;
static char szHint[256] ;
wsprintf(szHint, " %d: %d / %d", iTotal, iCount, iRemand);
::SendMessage(lpFrame->GetSafeHwnd(), WM_USR_CALL_SETPANETEXT, 0, (LPARAM)szHint);
cursor = posOne;
fDiff = FALSE;
i = 0;
while(cursor){
postemp = cursor;
CString & strTmp = listone.GetNext(cursor);
++i;
if(strTmp == strOne){
if(FALSE == fDiff){
posOne = cursor;
}
--iRemand;
listone.RemoveAt(postemp);
}else{
fDiff = TRUE;
}
}
cursor = listtwo.GetHeadPosition();
j = 0;
while(cursor){
postemp = cursor;
CString & strTmp = listtwo.GetNext(cursor);
++j;
if(strOne == strTmp){
listtwo.RemoveAt(postemp);
}
}
}
}
strFileOne += _T(".o");
strFileTwo += _T(".o");
FILE *fp = NULL;
if(NULL == (fp = fopen(strFileOne.GetBuffer(0), "wb"))){
return -1L;
}else{
POSITION cursor = listone.GetHeadPosition();
while(cursor){
CString & strRef = listone.GetNext(cursor);
CString str = strRef + _T("\n");
fwrite(str.GetBuffer(0), str.GetLength(), 1, fp);
}
fclose(fp);
}
if(NULL == (fp = fopen(strFileTwo.GetBuffer(0), "wb"))){
return -1L;
}else{
POSITION cursor = listtwo.GetHeadPosition();
while(cursor){
CString & strRef = listtwo.GetNext(cursor);
CString str = strRef + _T("\n");
fwrite(str.GetBuffer(0), str.GetLength(), 1, fp);
}
fclose(fp);
}
return 0L;
}
void CMainFrame::OnCallSetPaneText(WPARAM wParam, LPARAM lParam)
{
if((INT)wParam >= 0 && NULL != (LPCTSTR)lParam){
m_wndStatusBar.SetPaneText((INT)wParam, (LPCTSTR)lParam, TRUE);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -