X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/91fa114d88972cdfe698343560f3ef5d17b4eac1..224021239085a3c1d71fc865c14ee45e1adc87f2:/src/html/helpdata.cpp diff --git a/src/html/helpdata.cpp b/src/html/helpdata.cpp index 32aad95196..9aa5f8d1b9 100644 --- a/src/html/helpdata.cpp +++ b/src/html/helpdata.cpp @@ -9,10 +9,6 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) -#pragma implementation "helpdata.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -59,14 +55,14 @@ static const wxChar* ReadLine(const wxChar *line, wxChar *buf, size_t bufsize) const wxChar *readptr = line; while (*readptr != 0 && *readptr != _T('\r') && *readptr != _T('\n') && - writeptr != endptr) + writeptr != endptr) *(writeptr++) = *(readptr++); *writeptr = 0; while (*readptr == _T('\r') || *readptr == _T('\n')) readptr++; if (*readptr == 0) return NULL; - else + else return readptr; } @@ -78,6 +74,11 @@ wxHtmlHelpIndexCompareFunc(wxHtmlHelpDataItem **a, wxHtmlHelpDataItem **b) wxHtmlHelpDataItem *ia = *a; wxHtmlHelpDataItem *ib = *b; + if (ia == NULL) + return -1; + if (ib == NULL) + return 1; + if (ia->parent == ib->parent) { return ia->name.CmpNoCase(ib->name); @@ -90,7 +91,7 @@ wxHtmlHelpIndexCompareFunc(wxHtmlHelpDataItem **a, wxHtmlHelpDataItem **b) { wxHtmlHelpDataItem *ia2 = ia; wxHtmlHelpDataItem *ib2 = ib; - + while (ia2->level > ib2->level) { ia2 = ia2->parent; @@ -99,7 +100,7 @@ wxHtmlHelpIndexCompareFunc(wxHtmlHelpDataItem **a, wxHtmlHelpDataItem **b) { ib2 = ib2->parent; } - + wxASSERT(ia2); wxASSERT(ib2); int res = wxHtmlHelpIndexCompareFunc(&ia2, &ib2); @@ -147,7 +148,7 @@ class HP_TagHandler : public wxHtmlTagHandler int m_count; wxHtmlHelpDataItem *m_parentItem; wxHtmlBookRecord *m_book; - + wxHtmlHelpDataItems *m_data; public: @@ -157,7 +158,7 @@ class HP_TagHandler : public wxHtmlTagHandler m_book = b; m_name = m_page = wxEmptyString; m_level = 0; - m_id = -1; + m_id = wxID_ANY; m_count = 0; m_parentItem = NULL; } @@ -220,7 +221,7 @@ bool HP_TagHandler::HandleTag(const wxHtmlTag& tag) item->id = m_id; item->page = m_page; item->name = m_name; - + item->book = m_book; m_data->Add(item); m_count++; @@ -320,7 +321,7 @@ bool wxHtmlHelpData::LoadMSProject(wxHtmlBookRecord *book, wxFileSystem& fsys, { wxLogError(_("Cannot open index file: %s"), indexfile.c_str()); } - return TRUE; + return true; } inline static void CacheWriteInt32(wxOutputStream *f, wxInt32 value) @@ -337,7 +338,7 @@ inline static wxInt32 CacheReadInt32(wxInputStream *f) } inline static void CacheWriteString(wxOutputStream *f, const wxString& str) -{ +{ const wxWX2MBbuf mbstr = str.mb_str(wxConvUTF8); size_t len = strlen((const char*)mbstr)+1; CacheWriteInt32(f, len); @@ -366,12 +367,12 @@ bool wxHtmlHelpData::LoadCachedBook(wxHtmlBookRecord *book, wxInputStream *f) /* load header - version info : */ version = CacheReadInt32(f); - + if (version != CURRENT_CACHED_BOOK_VERSION) { - // NB: We can just silently return FALSE here and don't worry about + // NB: We can just silently return false here and don't worry about // it anymore, because AddBookParam will load the MS project in - // absence of (properly versioned) .cached file and automatically + // absence of (properly versioned) .cached file and automatically // create new .cached file immediately afterward. return false; } @@ -425,14 +426,14 @@ bool wxHtmlHelpData::SaveCachedBook(wxHtmlBookRecord *book, wxOutputStream *f) /* save contents : */ int len = m_contents.size(); - for (cnt = 0, i = 0; i < len; i++) + for (cnt = 0, i = 0; i < len; i++) if (m_contents[i].book == book && m_contents[i].level > 0) cnt++; CacheWriteInt32(f, cnt); for (i = 0; i < len; i++) { - if (m_contents[i].book != book || m_contents[i].level == 0) + if (m_contents[i].book != book || m_contents[i].level == 0) continue; CacheWriteInt32(f, m_contents[i].level); CacheWriteInt32(f, m_contents[i].id); @@ -442,14 +443,14 @@ bool wxHtmlHelpData::SaveCachedBook(wxHtmlBookRecord *book, wxOutputStream *f) /* save index : */ len = m_index.size(); - for (cnt = 0, i = 0; i < len; i++) - if (m_index[i].book == book && m_index[i].level > 0) + for (cnt = 0, i = 0; i < len; i++) + if (m_index[i].book == book && m_index[i].level > 0) cnt++; CacheWriteInt32(f, cnt); for (i = 0; i < len; i++) { - if (m_index[i].book != book || m_index[i].level == 0) + if (m_index[i].book != book || m_index[i].level == 0) continue; CacheWriteString(f, m_index[i].name); CacheWriteString(f, m_index[i].page); @@ -461,17 +462,17 @@ bool wxHtmlHelpData::SaveCachedBook(wxHtmlBookRecord *book, wxOutputStream *f) } else { - int cnt = 0; + int cnt2 = 0; wxHtmlHelpDataItem *parent = m_index[i].parent; for (int j = i-1; j >= 0; j--) { if (m_index[j].book == book && m_index[j].level > 0) - cnt++; + cnt2++; if (&m_index[j] == parent) break; } - wxASSERT(cnt > 0); - CacheWriteInt32(f, cnt); + wxASSERT(cnt2 > 0); + CacheWriteInt32(f, cnt2); } } return true; @@ -518,7 +519,7 @@ bool wxHtmlHelpData::AddBookParam(const wxFSFile& bookfile, ContentsOld = m_contents.size(); if (!path.IsEmpty()) - fsys.ChangePathTo(path, TRUE); + fsys.ChangePathTo(path, true); size_t booksCnt = m_bookRecords.GetCount(); for (size_t i = 0; i < booksCnt; i++) @@ -528,7 +529,7 @@ bool wxHtmlHelpData::AddBookParam(const wxFSFile& bookfile, } bookr = new wxHtmlBookRecord(bookfile.GetLocation(), fsys.GetPath(), title, deftopic); - + wxHtmlHelpDataItem *bookitem = new wxHtmlHelpDataItem; bookitem->level = 0; bookitem->id = 0; @@ -633,7 +634,7 @@ bool wxHtmlHelpData::AddBook(const wxString& book) { wxFileSystem fsys; wxString s; - bool rt = FALSE; + bool rt = false; #if wxUSE_LIBMSPACK if (extension == wxT(".chm")) @@ -644,7 +645,7 @@ bool wxHtmlHelpData::AddBook(const wxString& book) while (!s.IsEmpty()) { - if (AddBook(s)) rt = TRUE; + if (AddBook(s)) rt = true; s = fsys.FindNext(); } @@ -665,7 +666,7 @@ bool wxHtmlHelpData::AddBook(const wxString& book) if (fi == NULL) { wxLogError(_("Cannot open HTML help book: %s"), book.c_str()); - return FALSE; + return false; } fsys.ChangePathTo(book); @@ -676,12 +677,12 @@ bool wxHtmlHelpData::AddBook(const wxString& book) tmp = filter.ReadFile(*fi); lineptr = tmp.c_str(); - do + do { lineptr = ReadLine(lineptr, linebuf, 300); - + for (wxChar *ch = linebuf; *ch != wxT('\0') && *ch != wxT('='); ch++) - *ch = tolower(*ch); + *ch = (wxChar)wxTolower(*ch); if (wxStrstr(linebuf, _T("title=")) == linebuf) title = linebuf + wxStrlen(_T("title=")); @@ -694,10 +695,12 @@ bool wxHtmlHelpData::AddBook(const wxString& book) if (wxStrstr(linebuf, _T("charset=")) == linebuf) charset = linebuf + wxStrlen(_T("charset=")); } while (lineptr != NULL); - - wxFontEncoding enc; - if (charset == wxEmptyString) enc = wxFONTENCODING_SYSTEM; - else enc = wxFontMapper::Get()->CharsetToEncoding(charset); + + wxFontEncoding enc = wxFONTENCODING_SYSTEM; +#if wxUSE_FONTMAP + if (charset != wxEmptyString) + enc = wxFontMapper::Get()->CharsetToEncoding(charset); +#endif bool rtval = AddBookParam(*fi, enc, title, contents, index, start, fsys.GetPath()); @@ -778,7 +781,7 @@ wxString wxHtmlHelpData::FindPageById(int id) #if WXWIN_COMPATIBILITY_2_4 wxHtmlContentsItem::wxHtmlContentsItem() - : m_Level(0), m_ID(-1), m_Name(NULL), m_Page(NULL), m_Book(NULL), + : m_Level(0), m_ID(wxID_ANY), m_Name(NULL), m_Page(NULL), m_Book(NULL), m_autofree(false) { } @@ -971,7 +974,7 @@ void wxHtmlSearchEngine::LookFor(const wxString& keyword, bool case_sensitive, b m_WholeWords = whole_words_only; m_Keyword = keyword; - if (m_CaseSensitive) + if (!m_CaseSensitive) m_Keyword.LowerCase(); } @@ -987,7 +990,7 @@ bool wxHtmlSearchEngine::Scan(const wxFSFile& file) int i, j; int wrd = m_Keyword.Length(); - bool found = FALSE; + bool found = false; wxHtmlFilterHTML filter; wxString tmp = filter.ReadFile(file); int lng = tmp.length(); @@ -997,7 +1000,7 @@ bool wxHtmlSearchEngine::Scan(const wxFSFile& file) tmp.LowerCase(); const wxChar *kwd = m_Keyword.c_str(); - + if (m_WholeWords) { for (i = 0; i < lng - wrd; i++)