2
//(*InternalHeaders(HeadersDetectorDlg)
8
#include <wx/stattext.h>
11
#include <encodingdetector.h>
12
#include "headersdetectordlg.h"
14
//(*IdInit(HeadersDetectorDlg)
15
const long HeadersDetectorDlg::ID_STATICTEXT1 = wxNewId();
16
const long HeadersDetectorDlg::ID_STATICTEXT3 = wxNewId();
17
const long HeadersDetectorDlg::ID_STATICTEXT2 = wxNewId();
18
const long HeadersDetectorDlg::ID_STATICTEXT4 = wxNewId();
19
const long HeadersDetectorDlg::ID_GAUGE1 = wxNewId();
20
const long HeadersDetectorDlg::ID_TIMER1 = wxNewId();
23
BEGIN_EVENT_TABLE(HeadersDetectorDlg,wxScrollingDialog)
24
//(*EventTable(HeadersDetectorDlg)
26
EVT_BUTTON(wxID_CANCEL,HeadersDetectorDlg::Cancel)
29
HeadersDetectorDlg::HeadersDetectorDlg(wxWindow* parent,cbProject* project,wxArrayString& headers)
36
//(*Initialize(HeadersDetectorDlg)
37
wxFlexGridSizer* FlexGridSizer1;
38
wxBoxSizer* BoxSizer1;
39
wxStdDialogButtonSizer* StdDialogButtonSizer1;
40
wxStaticBoxSizer* StaticBoxSizer1;
42
Create(parent, wxID_ANY, _("Detecting missing libraries..."), wxDefaultPosition, wxDefaultSize, wxCAPTION, _T("wxID_ANY"));
43
BoxSizer1 = new wxBoxSizer(wxVERTICAL);
44
StaticBoxSizer1 = new wxStaticBoxSizer(wxVERTICAL, this, _("Scanning:"));
45
FlexGridSizer1 = new wxFlexGridSizer(0, 2, 5, 5);
46
FlexGridSizer1->AddGrowableCol(1);
47
StaticText1 = new wxStaticText(this, ID_STATICTEXT1, _("Project:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT1"));
48
FlexGridSizer1->Add(StaticText1, 1, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5);
49
m_ProjectName = new wxStaticText(this, ID_STATICTEXT3, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT3"));
50
FlexGridSizer1->Add(m_ProjectName, 1, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
51
StaticText2 = new wxStaticText(this, ID_STATICTEXT2, _("File:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT2"));
52
FlexGridSizer1->Add(StaticText2, 1, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5);
53
m_FileNameTxt = new wxStaticText(this, ID_STATICTEXT4, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT4"));
54
FlexGridSizer1->Add(m_FileNameTxt, 1, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
55
StaticBoxSizer1->Add(FlexGridSizer1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
56
m_ProgressBar = new wxGauge(this, ID_GAUGE1, 100, wxDefaultPosition, wxSize(341,15), 0, wxDefaultValidator, _T("ID_GAUGE1"));
57
StaticBoxSizer1->Add(m_ProgressBar, 0, wxBOTTOM|wxLEFT|wxRIGHT|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
58
BoxSizer1->Add(StaticBoxSizer1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
59
StdDialogButtonSizer1 = new wxStdDialogButtonSizer();
60
StdDialogButtonSizer1->AddButton(new wxButton(this, wxID_CANCEL, wxEmptyString));
61
StdDialogButtonSizer1->Realize();
62
BoxSizer1->Add(StdDialogButtonSizer1, 0, wxBOTTOM|wxLEFT|wxRIGHT|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
64
Timer1.SetOwner(this, ID_TIMER1);
65
Timer1.Start(50, false);
67
BoxSizer1->SetSizeHints(this);
70
Connect(ID_TIMER1,wxEVT_TIMER,(wxObjectEventFunction)&HeadersDetectorDlg::OnTimer1Trigger);
73
m_Thread.m_Dlg = this;
77
m_ProgressBar->SetRange( m_Project->GetFilesCount() );
78
m_ProjectName->SetLabel( m_Project->GetTitle() );
81
HeadersDetectorDlg::~HeadersDetectorDlg()
85
//(*Destroy(HeadersDetectorDlg)
90
void HeadersDetectorDlg::OnTimer1Trigger(wxTimerEvent& event)
92
wxCriticalSectionLocker lock(m_Section);
94
m_FileNameTxt->SetLabel( m_FileName );
95
m_ProgressBar->SetValue( m_Progress );
98
EndModal( m_Cancel ? wxID_CANCEL : wxID_OK );
103
void HeadersDetectorDlg::Cancel(wxCommandEvent& event)
108
void HeadersDetectorDlg::ThreadProc()
110
for ( int i=0; i<m_Project->GetFilesCount(); i++ )
112
if ( m_Thread.TestDestroy() || m_Cancel )
117
ProjectFile* file = m_Project->GetFile(i);
120
wxCriticalSectionLocker lock(m_Section);
122
m_FileName = file ? file->relativeFilename : _T("");
125
ProcessFile( file, m_Headers );
130
void HeadersDetectorDlg::ProcessFile( ProjectFile* file, wxArrayString& includes )
132
// We do not care about proper encoding right now.
133
// Libraries should never use any native characters in names
134
// of their includes and in case of any multibyte encoding
135
// multibyte charcters shouldn't hurt us
136
// Encoding detector tends to work really slow in some cases
138
wxString Ext = file->file.GetExt();
141
static const wxChar* Exts[] =
143
_T("h"), _T("hxx"), _T("hpp"),
144
_T("c"), _T("cpp"), _T("cxx"),
148
bool validExt = false;
149
for ( const wxChar** ptr = Exts; *ptr; ptr++ )
163
wxFile fl( file->file.GetFullPath() );
164
if ( !fl.IsOpened() ) return;
165
wxFileOffset contentLength = fl.Length();
166
if ( contentLength <= 0 )
170
char* content = new char[contentLength+1];
171
char* line = new char[contentLength+1];
172
if ( fl.Read(content,contentLength) != contentLength )
178
content[contentLength] = 0;
180
bool blockComment = false;
181
for ( size_t pos = 0; pos < static_cast<size_t>(contentLength); )
183
// Fetching next line
185
bool lineEnd = false;
187
bool lineComment = false;
190
bool lastCharAdded = false;
193
char ch = content[pos++];
194
bool thisCharAdded = false;
198
if ( content[pos] == '\r' )
209
else if ( lastCharAdded )
211
// Removing last char since it was '\'
212
// which is removed in the
213
// preprocessor level
221
if ( content[pos] == '/' )
224
blockComment = false;
228
else if ( !lineComment )
230
thisCharAdded = true;
231
line[lineLength++] = ch;
236
if ( !blockComment && !lineComment )
244
else if ( last != '\\' )
249
thisCharAdded = true;
250
line[lineLength++] = ch;
255
if ( !blockComment && !lineComment )
263
else if ( last != '\\' )
268
thisCharAdded = true;
269
line[lineLength++] = ch;
274
if ( !blockComment && !lineComment && !inStr && !inChar )
276
if ( content[pos] == '/' )
283
if ( content[pos] == '*' )
291
// Contnue to default case
293
if ( !blockComment && !lineComment )
295
thisCharAdded = true;
296
line[lineLength++] = ch;
300
lastCharAdded = thisCharAdded;
302
while ( !lineEnd && pos < static_cast<size_t>(contentLength) );
303
line[lineLength] = 0;
305
// Searching for include
308
while ( line[i]==' ' || line[i]=='\t' ) i++;
309
if ( line[i++] == '#' )
311
while ( line[i]==' ' || line[i]=='\t' ) i++;
312
if ( !strncmp( line+i, "include", 7 ) )
315
while ( line[i]==' ' || line[i]=='\t' ) i++;
320
( line[i] == '<' ) ? '>' :
321
( line[i] == '"' ) ? '"' :
327
while ( line[i] && line[i]!=readTill )
329
include += (wxChar)line[i++];
331
if ( line[i] == readTill )
333
includes.Add( include );