X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/53e46b61bbe4ce72b92c8898907f0a879d5f012b..a83e14751f3b4bb86da3ac2edea09c7f78f3ca3e:/src/html/helpdata.cpp diff --git a/src/html/helpdata.cpp b/src/html/helpdata.cpp index 6ba01be7f7..d487a7dcb0 100644 --- a/src/html/helpdata.cpp +++ b/src/html/helpdata.cpp @@ -48,22 +48,30 @@ WX_DEFINE_OBJARRAY(wxHtmlBookRecArray) //----------------------------------------------------------------------------- // Reads one line, stores it into buf and returns pointer to new line or NULL. -static char* ReadLine(char *line, char *buf) +static char* ReadLine(char *line, char *buf, size_t bufsize) { - char *writeptr = buf, *readptr = line; + char *writeptr = buf; + char *endptr = buf + bufsize - 1; + char *readptr = line; - while (*readptr != 0 && *readptr != '\r' && *readptr != '\n') *(writeptr++) = *(readptr++); + while (*readptr != 0 && *readptr != '\r' && *readptr != '\n' && + writeptr != endptr) + *(writeptr++) = *(readptr++); *writeptr = 0; - while (*readptr == '\r' || *readptr == '\n') readptr++; - if (*readptr == 0) return NULL; - else return readptr; + while (*readptr == '\r' || *readptr == '\n') + readptr++; + if (*readptr == 0) + return NULL; + else + return readptr; } -static int LINKAGEMODE IndexCompareFunc(const void *a, const void *b) +extern "C" int LINKAGEMODE +wxHtmlHelpIndexCompareFunc(const void *a, const void *b) { - return wxStrcmp(((wxHtmlContentsItem*)a)->m_Name, ((wxHtmlContentsItem*)b)->m_Name); + return wxStricmp(((wxHtmlContentsItem*)a)->m_Name, ((wxHtmlContentsItem*)b)->m_Name); } @@ -73,9 +81,10 @@ static int LINKAGEMODE IndexCompareFunc(const void *a, const void *b) class HP_Parser : public wxHtmlParser { - public: - void AddText(const char* WXUNUSED(text)) { } - wxObject* GetProduct() { return NULL; } +public: + wxObject* GetProduct() { return NULL; } +protected: + virtual void AddText(const wxChar* WXUNUSED(txt)) {} }; @@ -523,7 +532,7 @@ bool wxHtmlHelpData::AddBookParam(const wxFSFile& bookfile, m_BookRecords.Add(bookr); if (m_IndexCnt > 0) - qsort(m_Index, m_IndexCnt, sizeof(wxHtmlContentsItem), IndexCompareFunc); + qsort(m_Index, m_IndexCnt, sizeof(wxHtmlContentsItem), wxHtmlHelpIndexCompareFunc); return TRUE; } @@ -557,10 +566,6 @@ bool wxHtmlHelpData::AddBook(const wxString& book) wxInputStream *s; wxString bookFull; - int sz; - char *buff, *lineptr; - char linebuf[300]; - wxString title = _("noname"), safetitle, start = wxEmptyString, @@ -568,7 +573,7 @@ bool wxHtmlHelpData::AddBook(const wxString& book) index = wxEmptyString, charset = wxEmptyString; -#ifdef __WXMAC__ +#if defined(__WXMAC__) && !defined(__DARWIN__) if (wxIsAbsolutePath(book)) bookFull = book; else bookFull = wxGetCwd() + book; // no slash or dot wxFileName fn( bookFull ); @@ -586,25 +591,34 @@ bool wxHtmlHelpData::AddBook(const wxString& book) } fsys.ChangePathTo(bookFull); s = fi->GetStream(); + + int sz; + char *buff, *lineptr; + char linebuf[300]; + sz = s->GetSize(); buff = new char[sz + 1]; buff[sz] = 0; s->Read(buff, sz); lineptr = buff; - do { - lineptr = ReadLine(lineptr, linebuf); - - if (strstr(linebuf, "Title=") == linebuf) - title = linebuf + strlen("Title="); - if (strstr(linebuf, "Default topic=") == linebuf) - start = linebuf + strlen("Default topic="); - if (strstr(linebuf, "Index file=") == linebuf) - index = linebuf + strlen("Index file="); - if (strstr(linebuf, "Contents file=") == linebuf) - contents = linebuf + strlen("Contents file="); - if (strstr(linebuf, "Charset=") == linebuf) - charset = linebuf + strlen("Charset="); + do + { + lineptr = ReadLine(lineptr, linebuf, 300); + + for (char *ch = linebuf; *ch != '\0' && *ch != '='; ch++) + *ch = tolower(*ch); + + if (strstr(linebuf, "title=") == linebuf) + title = linebuf + strlen("title="); + if (strstr(linebuf, "default topic=") == linebuf) + start = linebuf + strlen("default topic="); + if (strstr(linebuf, "index file=") == linebuf) + index = linebuf + strlen("index file="); + if (strstr(linebuf, "contents file=") == linebuf) + contents = linebuf + strlen("contents file="); + if (strstr(linebuf, "charset=") == linebuf) + charset = linebuf + strlen("charset="); } while (lineptr != NULL); delete[] buff;