Go to:
Gentoo Home
Documentation
Forums
Lists
Bugs
Planet
Store
Wiki
Get Gentoo!
Gentoo's Bugzilla – Attachment 66132 Details for
Bug 102824
stardict-2.4.5 ebuild
Home
|
New
–
[Ex]
|
Browse
|
Search
|
Privacy Policy
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Fix writing to not allocated memory
get_data_fix.patch (text/plain), 30.24 KB, created by
Evgeniy Dushistov
on 2005-08-17 05:56:45 UTC
(
hide
)
Description:
Fix writing to not allocated memory
Filename:
MIME Type:
Creator:
Evgeniy Dushistov
Created:
2005-08-17 05:56:45 UTC
Size:
30.24 KB
patch
obsolete
>diff -urN stardict-2.4.5/src/floatwin.cpp stardict/src/floatwin.cpp >--- stardict-2.4.5/src/floatwin.cpp 2005-07-18 09:29:50.000000000 +0000 >+++ stardict/src/floatwin.cpp 2005-08-05 13:03:48.000000000 +0000 >@@ -174,51 +174,51 @@ > > void FloatWin::ShowText(gchar **word, gchar **data,const gchar * sOriginWord) > { >- QueryingWord = sOriginWord; >- found_result = FLOAT_WIN_FOUND; >- std::string mark; >- gchar *m_str; >- mark = "<b><big>"; >- m_str = g_markup_escape_text(sOriginWord,-1); >- mark += m_str; >- g_free(m_str); >- mark += "</big></b>"; >- >- gchar *p; >+ QueryingWord = sOriginWord; >+ found_result = FLOAT_WIN_FOUND; >+ std::string mark; >+ gchar *m_str; >+ mark = "<b><big>"; >+ m_str = g_markup_escape_text(sOriginWord,-1); >+ mark += m_str; >+ g_free(m_str); >+ mark += "</big></b>"; >+ >+ gchar *p; > guint32 data_size, sec_size=0; > for (int i=0;i< gpAppFrame->oAppCore.oLibs.total_libs();i++) { >- if (word[i]) { >- mark += "\n<span foreground=\"blue\">*--- "; >- m_str = g_markup_escape_text(gpAppFrame->oAppCore.oLibs.GetBookname(i),-1); >- mark += m_str; >- g_free(m_str); >- mark += " ---*</span>"; >- >- if (strcmp(word[i],sOriginWord)) { >- mark += "\n<span foreground=\"purple\">"; >- m_str = g_markup_escape_text(word[i],-1); >- mark += m_str; >- g_free(m_str); >- mark += "</span>"; >- } >- } >- if (data[i]) { >+ if (word[i]) { >+ mark += "\n<span foreground=\"blue\">*--- "; >+ m_str = g_markup_escape_text(gpAppFrame->oAppCore.oLibs.GetBookname(i),-1); >+ mark += m_str; >+ g_free(m_str); >+ mark += " ---*</span>"; >+ >+ if (strcmp(word[i],sOriginWord)) { >+ mark += "\n<span foreground=\"purple\">"; >+ m_str = g_markup_escape_text(word[i],-1); >+ mark += m_str; >+ g_free(m_str); >+ mark += "</span>"; >+ } >+ } >+ if (data[i]) { > p=data[i]; > data_size=*reinterpret_cast<guint32 *>(p); > p+=sizeof(guint32); >- while (guint32(p - (data[i] + sizeof(guint32)))< data_size) { >+ while (guint32(p - data[i])< data_size) { > switch (*p++) { >- case 'm': >+ case 'm': > case 'l'://need more work > sec_size = strlen(p); >- if (sec_size) { >- mark+= "\n"; >+ if (sec_size) { >+ mark+= "\n"; > m_str = g_markup_escape_text(p, sec_size); >- mark += m_str; >- g_free(m_str); >- } >- sec_size++; >- break; >+ mark += m_str; >+ g_free(m_str); >+ } >+ sec_size++; >+ break; > case 'g': > sec_size = strlen(p); > if (sec_size) { >@@ -227,149 +227,149 @@ > } > sec_size++; > break; >- case 't': >+ case 't': > sec_size = strlen(p); >- if (sec_size) { >- mark += "\n<big>["; >+ if (sec_size) { >+ mark += "\n<big>["; > m_str = g_markup_escape_text(p, sec_size); >- mark += m_str; >- g_free(m_str); >- mark+= "]</big>"; >- } >- sec_size++; >- break; >- case 'y': >+ mark += m_str; >+ g_free(m_str); >+ mark+= "]</big>"; >+ } >+ sec_size++; >+ break; >+ case 'y': > sec_size = strlen(p); >- if (sec_size) { >- mark += "\n<span foreground=\"red\">["; >+ if (sec_size) { >+ mark += "\n<span foreground=\"red\">["; > m_str = g_markup_escape_text(p, sec_size); >- mark += m_str; >- g_free(m_str); >- mark+= "]</span>"; >- } >- sec_size++; >- break; >- case 'W': >+ mark += m_str; >+ g_free(m_str); >+ mark+= "]</span>"; >+ } >+ sec_size++; >+ break; >+ case 'W': > sec_size=*reinterpret_cast<guint32 *>(p); > sec_size=g_ntohl(sec_size); >- //enbale sound button. >+ //enbale sound button. > sec_size+=sizeof(guint32); >- break; >- case 'P': >+ break; >+ case 'P': > sec_size=*reinterpret_cast<guint32 *>(p); > sec_size=g_ntohl(sec_size); > sec_size+= sizeof(guint32); >- break; >+ break; > default: > /*nothing*/; >- } >+ } > p += sec_size; >- } >- } >- } >- SetText(mark.c_str()); >- >- gboolean canRead = gpAppFrame->oReadWord.canRead(sOriginWord); >- if (canRead) { >- PronounceWord = sOriginWord; >+ } >+ } >+ } >+ SetText(mark.c_str()); >+ >+ gboolean canRead = gpAppFrame->oReadWord.canRead(sOriginWord); >+ if (canRead) { >+ PronounceWord = sOriginWord; > } else { >- for (int i=0;i< gpAppFrame->oAppCore.oLibs.total_libs(); i++) { >- if (word[i] && strcmp(word[i], sOriginWord)) { >- if (gpAppFrame->oReadWord.canRead(word[i])) { >- canRead = true; >- PronounceWord = word[i]; >- } >- break; >- } >- } >- } >- gtk_widget_set_sensitive(PronounceWordButton, canRead); >- Popup(true); >- >- if (canRead && conf->get_pronounce_when_popup()) >- gpAppFrame->oReadWord.read(PronounceWord.c_str()); >+ for (int i=0;i< gpAppFrame->oAppCore.oLibs.total_libs(); i++) { >+ if (word[i] && strcmp(word[i], sOriginWord)) { >+ if (gpAppFrame->oReadWord.canRead(word[i])) { >+ canRead = true; >+ PronounceWord = word[i]; >+ } >+ break; >+ } >+ } >+ } >+ gtk_widget_set_sensitive(PronounceWordButton, canRead); >+ Popup(true); >+ >+ if (canRead && conf->get_pronounce_when_popup()) >+ gpAppFrame->oReadWord.read(PronounceWord.c_str()); > } > > void FloatWin::ShowText(gchar *** pppWord, gchar *** pppWordData, > const gchar ** ppOriginWord, gint count, > const gchar * sOriginWord) > { >- QueryingWord = sOriginWord; >- found_result = FLOAT_WIN_FUZZY_FOUND; >- std::string mark; >- gchar *m_str; >- mark = _("Fuzzy query"); >- mark += " <b><big>"; >- m_str = g_markup_escape_text(sOriginWord,-1); >- mark += m_str; >- g_free(m_str); >- mark += "</big></b> "; >- mark += _("has succeeded.\n"); >- mark += _("Found "); >- if (count ==1) >- mark+= _("1 word:\n"); >+ QueryingWord = sOriginWord; >+ found_result = FLOAT_WIN_FUZZY_FOUND; >+ std::string mark; >+ gchar *m_str; >+ mark = _("Fuzzy query"); >+ mark += " <b><big>"; >+ m_str = g_markup_escape_text(sOriginWord,-1); >+ mark += m_str; >+ g_free(m_str); >+ mark += "</big></b> "; >+ mark += _("has succeeded.\n"); >+ mark += _("Found "); >+ if (count ==1) >+ mark+= _("1 word:\n"); > else { >- m_str=g_strdup_printf("%d",count); >- mark += m_str; >- g_free(m_str); >- mark+= _(" words:\n"); >- } >- int j; >+ m_str=g_strdup_printf("%d",count); >+ mark += m_str; >+ g_free(m_str); >+ mark+= _(" words:\n"); >+ } >+ int j; > for (j=0; j<count-1; j++) { >- mark += "<b><big>"; >+ mark += "<b><big>"; > m_str = g_markup_escape_text(ppOriginWord[j], -1); >- mark += m_str; >- g_free(m_str); >- mark += "</big></b> "; >- } >- mark += "<b><big>"; >- m_str = g_markup_escape_text(ppOriginWord[count-1],-1); >- mark += m_str; >- g_free(m_str); >- mark += "</big></b>"; >- >- gchar *p; >+ mark += m_str; >+ g_free(m_str); >+ mark += "</big></b> "; >+ } >+ mark += "<b><big>"; >+ m_str = g_markup_escape_text(ppOriginWord[count-1],-1); >+ mark += m_str; >+ g_free(m_str); >+ mark += "</big></b>"; >+ >+ gchar *p; > guint32 data_size,sec_size=0; > for (j=0; j<count; j++) { >- mark += "\n\n<span foreground=\"red\">#----- "; >- m_str = g_markup_escape_text(ppOriginWord[j],-1); >- mark += m_str; >- g_free(m_str); >- mark += " -----#</span>"; >- >+ mark += "\n\n<span foreground=\"red\">#----- "; >+ m_str = g_markup_escape_text(ppOriginWord[j],-1); >+ mark += m_str; >+ g_free(m_str); >+ mark += " -----#</span>"; >+ > for (int i=0; i<gpAppFrame->oAppCore.oLibs.total_libs(); i++) { >- if (pppWord[j][i]) { >- mark += "\n<span foreground=\"blue\">*--- "; >- m_str = g_markup_escape_text(gpAppFrame->oAppCore.oLibs.GetBookname(i),-1); >- mark += m_str; >- g_free(m_str); >- mark += " ---*</span>"; >- >- if (strcmp(ppOriginWord[j],pppWord[j][i])) { >- mark += "\n<span foreground=\"purple\">"; >- m_str = g_markup_escape_text(pppWord[j][i],-1); >- mark += m_str; >- g_free(m_str); >- mark += "</span>"; >- } >- } >- if (pppWordData[j][i]) { >+ if (pppWord[j][i]) { >+ mark += "\n<span foreground=\"blue\">*--- "; >+ m_str = g_markup_escape_text(gpAppFrame->oAppCore.oLibs.GetBookname(i),-1); >+ mark += m_str; >+ g_free(m_str); >+ mark += " ---*</span>"; >+ >+ if (strcmp(ppOriginWord[j],pppWord[j][i])) { >+ mark += "\n<span foreground=\"purple\">"; >+ m_str = g_markup_escape_text(pppWord[j][i],-1); >+ mark += m_str; >+ g_free(m_str); >+ mark += "</span>"; >+ } >+ } >+ if (pppWordData[j][i]) { > p=pppWordData[j][i]; > data_size=*reinterpret_cast<guint32 *>(p); > p+=sizeof(guint32); >- while (guint32(p - (pppWordData[j][i] + sizeof(guint32)))< data_size) { >+ while (guint32(p - pppWordData[j][i])< data_size) { > switch (*p++) { >- case 'm': >+ case 'm': > case 'l': //need more work... > sec_size = strlen(p); >- if (sec_size) { >- mark+= "\n"; >+ if (sec_size) { >+ mark+= "\n"; > m_str = g_markup_escape_text(p,sec_size); >- mark += m_str; >- g_free(m_str); >- } >- sec_size++; >- break; >+ mark += m_str; >+ g_free(m_str); >+ } >+ sec_size++; >+ break; > case 'g': > sec_size = strlen(p); > if (sec_size) { >@@ -378,57 +378,57 @@ > } > sec_size++; > break; >- case 't': >+ case 't': > sec_size = strlen(p); >- if (sec_size) { >- mark += "\n<big>["; >+ if (sec_size) { >+ mark += "\n<big>["; > m_str = g_markup_escape_text(p, sec_size); >- mark += m_str; >- g_free(m_str); >- mark+= "]</big>"; >- } >- sec_size++; >- break; >- case 'y': >+ mark += m_str; >+ g_free(m_str); >+ mark+= "]</big>"; >+ } >+ sec_size++; >+ break; >+ case 'y': > sec_size = strlen(p); >- if (sec_size) { >- mark += "\n<span foreground=\"red\">["; >+ if (sec_size) { >+ mark += "\n<span foreground=\"red\">["; > m_str = g_markup_escape_text(p, sec_size); >- mark += m_str; >- g_free(m_str); >- mark+= "]</span>"; >- } >- sec_size++; >- break; >- case 'W': >+ mark += m_str; >+ g_free(m_str); >+ mark+= "]</span>"; >+ } >+ sec_size++; >+ break; >+ case 'W': > sec_size=*reinterpret_cast<guint32 *>(p); > sec_size=g_ntohl(sec_size); >- //enbale sound button. >+ //enbale sound button. > sec_size+= sizeof(guint32); >- break; >- case 'P': >+ break; >+ case 'P': > sec_size=*reinterpret_cast<guint32 *>(p); > sec_size=g_ntohl(sec_size); > sec_size+= sizeof(guint32); >- break; >+ break; > default: > /*nothing*/; >- } >+ } > p += sec_size; >- } >- } >- } >- } >- SetText(mark.c_str()); >- gboolean canRead = gpAppFrame->oReadWord.canRead(sOriginWord); >- if (canRead) >- PronounceWord = sOriginWord; >- gtk_widget_set_sensitive(PronounceWordButton, canRead); >- >- Popup(false); >- >- if (canRead && conf->get_pronounce_when_popup()) >- gpAppFrame->oReadWord.read(PronounceWord.c_str()); >+ } >+ } >+ } >+ } >+ SetText(mark.c_str()); >+ gboolean canRead = gpAppFrame->oReadWord.canRead(sOriginWord); >+ if (canRead) >+ PronounceWord = sOriginWord; >+ gtk_widget_set_sensitive(PronounceWordButton, canRead); >+ >+ Popup(false); >+ >+ if (canRead && conf->get_pronounce_when_popup()) >+ gpAppFrame->oReadWord.read(PronounceWord.c_str()); > } > > void FloatWin::ShowNotFound(const char* sWord,const char* sReason, gboolean fuzzy) >diff -urN stardict-2.4.5/src/lib.cpp stardict/src/lib.cpp >--- stardict-2.4.5/src/lib.cpp 2005-07-19 14:20:01.000000000 +0000 >+++ stardict/src/lib.cpp 2005-08-05 16:48:29.000000000 +0000 >@@ -121,32 +121,33 @@ > return false; > return true; > } >+ >+inline gint stardict_strcmp(const gchar *s1, const gchar *s2) >+{ > #ifndef NEW_CMP >-inline gint stardict_strcmp(const gchar *s1, const gchar *s2) { > gint a=g_ascii_strcasecmp(s1, s2); > if (a == 0) > return strcmp(s1, s2); > else > return a; >-} > #else >-inline gint stardict_strcmp2(const gchar *s1, const gchar *s2) { >- gint res=0; >- while (*s1 && *s2) { >- res=g_unichar_tolower(g_utf8_get_char(s1))-g_unichar_tolower(g_utf8_get_char(s2)); >- if (res!=0) >- return res; >- s1=g_utf8_next_char(s1); >- s2=g_utf8_next_char(s2); >- } >- >- if (*s1 && !*s2) >- return 1; >- if (!*s1 && *s2) >- return -1; >- return 0; >-} >+ gint res=0; >+ while (*s1 && *s2) { >+ res=g_unichar_tolower(g_utf8_get_char(s1))-g_unichar_tolower(g_utf8_get_char(s2)); >+ if (res!=0) >+ return res; >+ s1=g_utf8_next_char(s1); >+ s2=g_utf8_next_char(s2); >+ } >+ >+ if (*s1 && !*s2) >+ return 1; >+ if (!*s1 && *s2) >+ return -1; >+ return 0; > #endif >+} >+ > bool DictInfo::load_from_ifo_file(const gchar *ifofilename, > bool istreedict) > { >@@ -284,109 +285,109 @@ > { > for (int i=0; i<WORDDATA_CACHE_NUM; i++) > if (cache[i].data && cache[i].offset == idxitem_offset) >- return cache[i].data; >- >+ return cache[i].data; >+ > if (dictfile) >- fseek(dictfile, idxitem_offset, SEEK_SET); >- >- gchar *data; >- if (sametypesequence) { >+ fseek(dictfile, idxitem_offset, SEEK_SET); >+ >+ gchar *data; >+ if (sametypesequence) { > gchar *origin_data = (gchar *)g_malloc(idxitem_size); >- >- if (dictfile) >+ >+ if (dictfile) > fread(origin_data, idxitem_size, 1, dictfile); >- else >+ else > dict_data_read(dictdzfile, origin_data, idxitem_offset, idxitem_size); >- >+ > guint32 data_size; >- gint sametypesequence_len; >- sametypesequence_len = strlen(sametypesequence); >- //there have sametypesequence_len char being omitted. >+ gint sametypesequence_len; >+ sametypesequence_len = strlen(sametypesequence); >+ //there have sametypesequence_len char being omitted. > data_size = idxitem_size + sizeof(guint32) + sametypesequence_len; >- //if the last item's size is determined by the end up '\0',then +=sizeof(gchar); >+ //if the last item's size is determined by the end up '\0',then +=sizeof(gchar); > //if the last item's size is determined by the head guint32 type data,then +=sizeof(guint32); >- switch (sametypesequence[sametypesequence_len-1]) { >- case 'm': >- case 't': >- case 'y': >+ switch (sametypesequence[sametypesequence_len-1]) { >+ case 'm': >+ case 't': >+ case 'y': > case 'l': > case 'g': >- data_size += sizeof(gchar); >- break; >- case 'W': >- case 'P': >+ data_size += sizeof(gchar); >+ break; >+ case 'W': >+ case 'P': > data_size += sizeof(guint32); >- break; >- } >- data = (gchar *)g_malloc(data_size); >- gchar *p1,*p2; >+ break; >+ } >+ data = (gchar *)g_malloc(data_size); >+ gchar *p1,*p2; > p1 = data + sizeof(guint32); >- p2 = origin_data; >+ p2 = origin_data; > guint32 sec_size; >- //copy the head items. >+ //copy the head items. > for (int i=0; i<sametypesequence_len-1; i++) { > *p1=sametypesequence[i]; > p1+=sizeof(gchar); >- switch (sametypesequence[i]) { >- case 'm': >- case 't': >- case 'y': >+ switch (sametypesequence[i]) { >+ case 'm': >+ case 't': >+ case 'y': > case 'l': > case 'g': >- sec_size = strlen(p2)+1; >- memcpy(p1, p2, sec_size); >+ sec_size = strlen(p2)+1; >+ memcpy(p1, p2, sec_size); > p1+=sec_size; > p2+=sec_size; >- break; >- case 'W': >- case 'P': >+ break; >+ case 'W': >+ case 'P': > sec_size = *reinterpret_cast<guint32 *>(p2); > sec_size += sizeof(guint32); >- memcpy(p1, p2, sec_size); >+ memcpy(p1, p2, sec_size); > p1+=sec_size; > p2+=sec_size; >- break; >- } >- } >- //calculate the last item 's size. >- sec_size = idxitem_size - (p2-origin_data); >+ break; >+ } >+ } >+ //calculate the last item 's size. >+ sec_size = idxitem_size - (p2-origin_data); > *p1=sametypesequence[sametypesequence_len-1]; > p1+=sizeof(gchar); >- switch (sametypesequence[sametypesequence_len-1]) { >- case 'm': >- case 't': >- case 'y': >+ switch (sametypesequence[sametypesequence_len-1]) { >+ case 'm': >+ case 't': >+ case 'y': > case 'l': > case 'g': >- memcpy(p1, p2, sec_size); >- p1 += sec_size; >+ memcpy(p1, p2, sec_size); >+ p1 += sec_size; > *p1='\0';//add the end up '\0'; >- break; >- case 'W': >- case 'P': >+ break; >+ case 'W': >+ case 'P': > *reinterpret_cast<guint32 *>(p1)=sec_size; > p1 += sizeof(guint32); >- memcpy(p1, p2, sec_size); >- break; >- } >- g_free(origin_data); >+ memcpy(p1, p2, sec_size); >+ break; >+ } >+ g_free(origin_data); > *reinterpret_cast<guint32 *>(data)=data_size; > } else { > data = (gchar *)g_malloc(idxitem_size + sizeof(guint32)); >- if (dictfile) >+ if (dictfile) > fread(data+sizeof(guint32), idxitem_size, 1, dictfile); >- else >+ else > dict_data_read(dictdzfile, data+sizeof(guint32), idxitem_offset, idxitem_size); >- *reinterpret_cast<guint32 *>(data)=idxitem_size; >- } >- g_free(cache[cache_cur].data); >- >- cache[cache_cur].data = data; >- cache[cache_cur].offset = idxitem_offset; >- cache_cur++; >- if (cache_cur==WORDDATA_CACHE_NUM) >+ *reinterpret_cast<guint32 *>(data)=idxitem_size+sizeof(guint32); >+ } >+ g_free(cache[cache_cur].data); >+ >+ cache[cache_cur].data = data; >+ cache[cache_cur].offset = idxitem_offset; >+ cache_cur++; >+ if (cache_cur==WORDDATA_CACHE_NUM) > cache_cur = 0; >- return data; >+ return data; > } > > >@@ -507,11 +508,7 @@ > } > > inline bool less_for_compare(const char *lh, const char *rh) { >-#ifndef NEW_CMP > return stardict_strcmp(lh, rh)<0; >-#else >- return stardict_strcmp2(lh, rh)<0; >-#endif > } > #ifdef NEW_CMP > struct CharacterArea1 { >@@ -588,11 +585,11 @@ > #endif > } > #ifdef NEW_CMP >-class StarDictCompare2 { >+class StarDictCompare { > public: >- explicit StarDictCompare2(const gchar *data_value) : data(data_value) {} >+ explicit StarDictCompare(const gchar *data_value) : data(data_value) {} > bool operator()(const Lib::WordCoord & lh, const Lib::WordCoord & rh) { >- return stardict_strcmp2(data+lh.offset, data+rh.offset)<0; >+ return stardict_strcmp(data+lh.offset, data+rh.offset)<0; > } > private: > const gchar *data; >@@ -663,8 +660,8 @@ > ++ptr; > } > >- StarDictCompare2 stardict_compare2(idxdatabuffer); >- std::sort(wordoffset, wordoffset+wordcount, stardict_compare2); >+ StarDictCompare stardict_compare(idxdatabuffer); >+ std::sort(wordoffset, wordoffset+wordcount, stardict_compare); > #endif > } > >@@ -675,21 +672,15 @@ > #endif > bool bFound=false; > glong iTo=wordcount-1; >-#ifndef NEW_CMP >- if (stardict_strcmp(sWord, GetWord(0))<0) { >-#else >- if (stardict_strcmp2(sWord, GetWord(0))<0) { >-#endif >- *pIndex = 0; >-#ifndef NEW_CMP >+ >+ if (stardict_strcmp(sWord, GetWord(0))<0) { >+ *pIndex = 0; >+ > } else if (stardict_strcmp(sWord, GetWord(iTo)) >0) { >-#else >- } else if (stardict_strcmp2(sWord, GetWord(iTo)) >0) { >-#endif >- *pIndex = INVALID_INDEX; >+ *pIndex = INVALID_INDEX; > } else { >- glong iThisIndex=0; >- glong iFrom=0; >+ glong iThisIndex=0; >+ glong iFrom=0; > #ifdef NEW_CMP > #if 1 > Character first; >@@ -708,38 +699,35 @@ > #endif > gint cmpint; > while (iFrom<=iTo) { >- iThisIndex=(iFrom+iTo)/2; >-#ifndef NEW_CMP >- cmpint = stardict_strcmp(sWord, GetWord(iThisIndex)); >-#else >- cmpint = stardict_strcmp2(sWord, GetWord(iThisIndex)); >-#endif >- >+ iThisIndex=(iFrom+iTo)/2; >+ >+ cmpint = stardict_strcmp(sWord, GetWord(iThisIndex)); >+ > if (cmpint>0) >- iFrom=iThisIndex+1; >+ iFrom=iThisIndex+1; > else if (cmpint<0) >- iTo=iThisIndex-1; >+ iTo=iThisIndex-1; > else { > bFound=true; > break; >- } >- } >- >+ } >+ } >+ > if (!bFound) { >- /*glong len = g_utf8_strlen(sWord, -1); >- gchar *last_str = g_utf8_offset_to_pointer(sWord, len-1); >- gunichar last = g_utf8_get_char(last_str); >- if (((g_unichar_isspace(last) || g_unichar_ispunct(last)) || g_unichar_isdigit(last)) >- && (g_ascii_strncasecmp(sWord, GetWord(iTo), (last_str - sWord))==0)) >- *pIndex = iTo; //previous >- else >- *pIndex = iFrom; //next >- */ >- *pIndex = iFrom; //next >+ /*glong len = g_utf8_strlen(sWord, -1); >+ gchar *last_str = g_utf8_offset_to_pointer(sWord, len-1); >+ gunichar last = g_utf8_get_char(last_str); >+ if (((g_unichar_isspace(last) || g_unichar_ispunct(last)) || g_unichar_isdigit(last)) >+ && (g_ascii_strncasecmp(sWord, GetWord(iTo), (last_str - sWord))==0)) >+ *pIndex = iTo; //previous >+ else >+ *pIndex = iFrom; //next >+ */ >+ *pIndex = iFrom; //next > } else >- *pIndex = iThisIndex; >- } >- >+ *pIndex = iThisIndex; >+ } >+ > #ifdef MEASURE_TIME > t=clock()-t; > middle_lookup_time*=measure_time; >@@ -937,28 +925,24 @@ > > gchar *Libs::poGetCurrentWord(glong * iCurrent) > { >- gchar * poCurrentWord = NULL; >- gchar *word; >- for (int iLib=0;iLib<libcount;iLib++) { >- if (iCurrent[iLib]==INVALID_INDEX) >- continue; >- if ( iCurrent[iLib]>=iLength(iLib) || iCurrent[iLib]<0) >- continue; >- if ( poCurrentWord == NULL ) { >- poCurrentWord = poGetWord(iCurrent[iLib],iLib); >- } >- else { >- word = poGetWord(iCurrent[iLib],iLib); >-#ifndef NEW_CMP >- if (stardict_strcmp(poCurrentWord, word) > 0 ) >-#else >- if (stardict_strcmp2(poCurrentWord, word) > 0 ) >-#endif >- poCurrentWord = word; >- } >- } >- return poCurrentWord; >- } >+ gchar * poCurrentWord = NULL; >+ gchar *word; >+ for (int iLib=0;iLib<libcount;iLib++) { >+ if (iCurrent[iLib]==INVALID_INDEX) >+ continue; >+ if ( iCurrent[iLib]>=iLength(iLib) || iCurrent[iLib]<0) >+ continue; >+ if ( poCurrentWord == NULL ) { >+ poCurrentWord = poGetWord(iCurrent[iLib],iLib); >+ } else { >+ word = poGetWord(iCurrent[iLib],iLib); >+ >+ if (stardict_strcmp(poCurrentWord, word) > 0 ) >+ poCurrentWord = word; >+ } >+ } >+ return poCurrentWord; >+} > > gchar * > Libs::poGetNextWord(const gchar *sWord, glong * iCurrent) >@@ -983,11 +967,8 @@ > } > else { > word = poGetWord(iCurrent[iLib],iLib); >-#ifndef NEW_CMP >+ > if ( stardict_strcmp(poCurrentWord, word) > 0 ) { >-#else >- if ( stardict_strcmp2(poCurrentWord, word) > 0 ) { >-#endif > poCurrentWord = word; > iCurrentLib = iLib; > } >@@ -1030,11 +1011,7 @@ > } > else { > word = poGetWord(iCurrent[iLib]-1,iLib); >-#ifndef NEW_CMP > if (stardict_strcmp(poCurrentWord, word) < 0 ) { >-#else >- if (stardict_strcmp2(poCurrentWord, word) < 0 ) { >-#endif > poCurrentWord = word; > iCurrentLib = iLib; > } >@@ -1399,11 +1376,7 @@ > return lh.iMatchWordDistance<rh.iMatchWordDistance; > > if (lh.pMatchWord && rh.pMatchWord) >-#ifndef NEW_CMP > return stardict_strcmp(lh.pMatchWord, rh.pMatchWord)<0; >-#else >- return stardict_strcmp2(lh.pMatchWord, rh.pMatchWord)<0; >-#endif > > return false; > } >@@ -1434,13 +1407,9 @@ > for (int iLib=0; iLib<libcount; iLib++) { > if (ProgressFunc) > ProgressFunc(); >-#ifndef NEW_CMP >+ > if (stardict_strcmp(sWord, poGetWord(0,iLib))>=0 && > stardict_strcmp(sWord, poGetWord(iLength(iLib)-1,iLib))<=0) { >-#else >- if (stardict_strcmp2(sWord, poGetWord(0,iLib))>=0 && >- stardict_strcmp2(sWord, poGetWord(iLength(iLib)-1,iLib))<=0) { >-#endif > //there are Chinese dicts and English dicts... > const int iwords = iLength(iLib); > for (int index=0; index<iwords; index++) { >diff -urN stardict-2.4.5/src/mainwin.cpp stardict/src/mainwin.cpp >--- stardict-2.4.5/src/mainwin.cpp 2005-07-19 14:54:37.000000000 +0000 >+++ stardict/src/mainwin.cpp 2005-08-05 13:01:10.000000000 +0000 >@@ -1329,40 +1329,40 @@ > > void TextWin::Show(gchar **Word, gchar **WordData, const gchar * sOriginWord) > { >- gchar *p; >+ gchar *p; > guint32 data_size,sec_size=0; >- GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)); >- gtk_text_buffer_begin_user_action(buffer); // will this speed up the showing? >- >- GtkTextIter start, end; >- gtk_text_buffer_get_bounds(buffer,&start,&end); >- gtk_text_buffer_delete(buffer,&start,&end); >- gtk_adjustment_set_value(gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW(scrolled_window)), 0); >- >- GtkTextIter iter; >- gtk_text_buffer_get_iter_at_offset (buffer, &iter, 0); >+ GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)); >+ gtk_text_buffer_begin_user_action(buffer); // will this speed up the showing? >+ >+ GtkTextIter start, end; >+ gtk_text_buffer_get_bounds(buffer,&start,&end); >+ gtk_text_buffer_delete(buffer,&start,&end); >+ gtk_adjustment_set_value(gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW(scrolled_window)), 0); >+ >+ GtkTextIter iter; >+ gtk_text_buffer_get_iter_at_offset (buffer, &iter, 0); > for (int i=0; i<gpAppFrame->oAppCore.oLibs.total_libs(); i++) { >- if (Word[i]) { >- gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "<--- ",-1, "DictNameTag", NULL); >+ if (Word[i]) { >+ gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "<--- ",-1, "DictNameTag", NULL); > gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, gpAppFrame->oAppCore.oLibs.GetBookname(i), > -1, "DictNameTag", NULL); >- gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, " --->\n",-1, "DictNameTag", NULL); >- gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, Word[i],-1, "WordTag", NULL); >- gtk_text_buffer_insert (buffer, &iter,"\n", 1); >- } >- if (WordData[i]) { >+ gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, " --->\n",-1, "DictNameTag", NULL); >+ gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, Word[i],-1, "WordTag", NULL); >+ gtk_text_buffer_insert (buffer, &iter,"\n", 1); >+ } >+ if (WordData[i]) { > p=WordData[i]; > data_size=*reinterpret_cast<guint32 *>(p); > p+=sizeof(guint32); >- while (guint32(p - (WordData[i] + sizeof(guint32)))< data_size) { >+ while (guint32(p - WordData[i])< data_size) { > switch (*p++) { >- case 'm': >+ case 'm': > case 'l'://need more work... > sec_size = strlen(p); > if (sec_size) > gtk_text_buffer_insert(buffer, &iter, p, sec_size); >- sec_size++; >- break; >+ sec_size++; >+ break; > case 'g': > sec_size = strlen(p); > if (sec_size) { >@@ -1374,74 +1374,74 @@ > } > sec_size++; > break; >- case 't': >+ case 't': > sec_size = strlen(p); >- if (sec_size) { >+ if (sec_size) { > gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "[", 1, "PhoneticTag", NULL); > gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, p, sec_size, "PhoneticTag", NULL); > gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "]", 1, "PhoneticTag", NULL); >- } >- sec_size++; >- break; >- case 'y': >+ } >+ sec_size++; >+ break; >+ case 'y': > sec_size = strlen(p); >- if (sec_size) { >+ if (sec_size) { > gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "[", 1, "YinBiaoTag", NULL); > gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, p, sec_size, "YinBiaoTag", NULL); > gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "]", 1, "YinBiaoTag", NULL); >- } >- sec_size++; >- break; >- case 'W': >+ } >+ sec_size++; >+ break; >+ case 'W': > sec_size=*reinterpret_cast<guint32 *>(p); > sec_size=g_ntohl(sec_size); >- //enbale sound button. >+ //enbale sound button. > sec_size += sizeof(guint32); >- break; >- case 'P': >+ break; >+ case 'P': > sec_size=*reinterpret_cast<guint32 *>(p); > sec_size=g_ntohl(sec_size); >- //show this picture. >+ //show this picture. > sec_size += sizeof(guint32); >- break; >+ break; > default: > /*nothing*/; >- } >+ } > gtk_text_buffer_insert(buffer, &iter, "\n", 1); > p += sec_size; >- } >- } >- } >- gtk_text_buffer_end_user_action(buffer); >+ } >+ } >+ } >+ gtk_text_buffer_end_user_action(buffer); > } > > void TextWin::ShowTreeDictData(const gchar *data) > { >- GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)); >- gtk_text_buffer_begin_user_action(buffer); >- >- GtkTextIter start, end; >- gtk_text_buffer_get_bounds(buffer,&start,&end); >- gtk_text_buffer_delete(buffer,&start,&end); >- gtk_adjustment_set_value(gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW(scrolled_window)), 0); >- >- GtkTextIter iter; >- gtk_text_buffer_get_iter_at_offset (buffer, &iter, 0); >- >+ GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)); >+ gtk_text_buffer_begin_user_action(buffer); >+ >+ GtkTextIter start, end; >+ gtk_text_buffer_get_bounds(buffer,&start,&end); >+ gtk_text_buffer_delete(buffer,&start,&end); >+ gtk_adjustment_set_value(gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW(scrolled_window)), 0); >+ >+ GtkTextIter iter; >+ gtk_text_buffer_get_iter_at_offset (buffer, &iter, 0); >+ > > guint32 data_size,sec_size=0; > const gchar *p=data; > data_size=*reinterpret_cast<const guint32 *>(p); > p+=sizeof(guint32); >- while (guint32(p - (data + sizeof(guint32)))< data_size) { >+ while (guint32(p - data)< data_size) { > switch (*p++) { >- case 'm': >+ case 'm': > case 'l'://need more work... > sec_size = strlen(p); >- if (sec_size) >+ if (sec_size) > gtk_text_buffer_insert(buffer, &iter, p, sec_size); >- sec_size++; >- break; >+ sec_size++; >+ break; > case 'g': > sec_size=strlen(p); > if (sec_size) { >@@ -1453,43 +1453,43 @@ > } > sec_size++; > break; >- case 't': >+ case 't': > sec_size = strlen(p); >- if (sec_size) { >+ if (sec_size) { > gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "[", 1, "PhoneticTag", NULL); > gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, p, sec_size, "PhoneticTag", NULL); > gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "]", 1, "PhoneticTag", NULL); >- } >- sec_size++; >- break; >- case 'y': >+ } >+ sec_size++; >+ break; >+ case 'y': > sec_size = strlen(p); >- if (sec_size) { >+ if (sec_size) { > gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "[", 1, "YinBiaoTag", NULL); > gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, p, sec_size, "YinBiaoTag", NULL); > gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "]", 1, "YinBiaoTag", NULL); >- } >- sec_size++; >- break; >- case 'W': >+ } >+ sec_size++; >+ break; >+ case 'W': > sec_size=*reinterpret_cast<const guint32 *>(p); > sec_size=g_ntohl(sec_size); >- //enbale sound button. >+ //enbale sound button. > sec_size += sizeof(guint32); >- break; >- case 'P': >+ break; >+ case 'P': > sec_size=*reinterpret_cast<const guint32 *>(p); > sec_size=g_ntohl(sec_size); >- //show this picture. >+ //show this picture. > sec_size += sizeof(guint32); >- break; >+ break; > default: > /*nothing*/; >- } >+ } > gtk_text_buffer_insert(buffer, &iter,"\n", 1); > p += sec_size; >- } >- gtk_text_buffer_end_user_action(buffer); >+ } >+ gtk_text_buffer_end_user_action(buffer); > } > > gboolean TextWin::Find (const gchar *text, gboolean start)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 102824
:
66131
| 66132