Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 102824
Collapse All | Expand All

(-)stardict-2.4.5/src/floatwin.cpp (-184 / +184 lines)
Lines 174-224 Link Here
174
174
175
void FloatWin::ShowText(gchar **word, gchar **data,const gchar * sOriginWord)
175
void FloatWin::ShowText(gchar **word, gchar **data,const gchar * sOriginWord)
176
{
176
{
177
	QueryingWord = sOriginWord;
177
  QueryingWord = sOriginWord;
178
	found_result = FLOAT_WIN_FOUND;
178
  found_result = FLOAT_WIN_FOUND;
179
	std::string mark;
179
  std::string mark;
180
	gchar *m_str;
180
  gchar *m_str;
181
	mark = "<b><big>";
181
  mark = "<b><big>";
182
	m_str = g_markup_escape_text(sOriginWord,-1);
182
  m_str = g_markup_escape_text(sOriginWord,-1);
183
	mark += m_str;
183
  mark += m_str;
184
	g_free(m_str);
184
  g_free(m_str);
185
	mark += "</big></b>";
185
  mark += "</big></b>";
186
	
186
  
187
	gchar *p;
187
  gchar *p;
188
  guint32 data_size, sec_size=0;
188
  guint32 data_size, sec_size=0;
189
  for (int i=0;i< gpAppFrame->oAppCore.oLibs.total_libs();i++) {
189
  for (int i=0;i< gpAppFrame->oAppCore.oLibs.total_libs();i++) {
190
		if (word[i]) {
190
    if (word[i]) {
191
			mark += "\n<span foreground=\"blue\">*--- ";
191
      mark += "\n<span foreground=\"blue\">*--- ";
192
			m_str = g_markup_escape_text(gpAppFrame->oAppCore.oLibs.GetBookname(i),-1);
192
      m_str = g_markup_escape_text(gpAppFrame->oAppCore.oLibs.GetBookname(i),-1);
193
			mark += m_str;
193
      mark += m_str;
194
			g_free(m_str);
194
      g_free(m_str);
195
			mark += " ---*</span>";
195
      mark += " ---*</span>";
196
			
196
      
197
			if (strcmp(word[i],sOriginWord)) {
197
      if (strcmp(word[i],sOriginWord)) {
198
				mark +=	"\n<span foreground=\"purple\">";
198
	mark +=	"\n<span foreground=\"purple\">";
199
				m_str = g_markup_escape_text(word[i],-1);
199
	m_str = g_markup_escape_text(word[i],-1);
200
				mark += m_str;
200
	mark += m_str;
201
				g_free(m_str);
201
	g_free(m_str);
202
				mark += "</span>";
202
	mark += "</span>";
203
			}
203
      }
204
		}
204
    }
205
		if (data[i]) {			
205
    if (data[i]) {			
206
      p=data[i];
206
      p=data[i];
207
      data_size=*reinterpret_cast<guint32 *>(p);
207
      data_size=*reinterpret_cast<guint32 *>(p);
208
      p+=sizeof(guint32);
208
      p+=sizeof(guint32);
209
      while (guint32(p - (data[i] + sizeof(guint32)))< data_size) {
209
      while (guint32(p - data[i])< data_size) {
210
	switch (*p++) {
210
	switch (*p++) {
211
					case 'm':
211
	case 'm':
212
	case 'l'://need more work
212
	case 'l'://need more work
213
	  sec_size = strlen(p);
213
	  sec_size = strlen(p);
214
						if (sec_size) {							
214
	  if (sec_size) {
215
							mark+= "\n";
215
	    mark+= "\n";
216
	    m_str = g_markup_escape_text(p, sec_size);
216
	    m_str = g_markup_escape_text(p, sec_size);
217
							mark += m_str;
217
	    mark += m_str;
218
							g_free(m_str);							
218
	    g_free(m_str);
219
						}
219
	  }
220
						sec_size++;
220
	  sec_size++;
221
						break;
221
	  break;
222
	case 'g':
222
	case 'g':
223
	  sec_size = strlen(p);
223
	  sec_size = strlen(p);
224
	  if (sec_size) {
224
	  if (sec_size) {
Lines 227-375 Link Here
227
	  }
227
	  }
228
	  sec_size++;
228
	  sec_size++;
229
	  break;
229
	  break;
230
					case 't':
230
	case 't':
231
	  sec_size = strlen(p);
231
	  sec_size = strlen(p);
232
						if (sec_size) {
232
	  if (sec_size) {
233
							mark += "\n<big>[";
233
	    mark += "\n<big>[";
234
	    m_str = g_markup_escape_text(p, sec_size);
234
	    m_str = g_markup_escape_text(p, sec_size);
235
							mark += m_str;
235
	    mark += m_str;
236
							g_free(m_str);
236
	    g_free(m_str);
237
							mark+= "]</big>";
237
	    mark+= "]</big>";
238
						}
238
	  }
239
						sec_size++;
239
	  sec_size++;
240
						break;
240
	  break;
241
					case 'y':
241
	case 'y':
242
	  sec_size = strlen(p);
242
	  sec_size = strlen(p);
243
						if (sec_size) {
243
	  if (sec_size) {
244
							mark += "\n<span foreground=\"red\">[";
244
	    mark += "\n<span foreground=\"red\">[";
245
	    m_str = g_markup_escape_text(p, sec_size);
245
	    m_str = g_markup_escape_text(p, sec_size);
246
							mark += m_str;
246
	    mark += m_str;
247
							g_free(m_str);
247
	    g_free(m_str);
248
							mark+= "]</span>";
248
	    mark+= "]</span>";
249
						}
249
	  }
250
						sec_size++;						
250
	  sec_size++;						
251
						break;
251
	  break;
252
					case 'W':
252
	case 'W':
253
	  sec_size=*reinterpret_cast<guint32 *>(p);
253
	  sec_size=*reinterpret_cast<guint32 *>(p);
254
	  sec_size=g_ntohl(sec_size);
254
	  sec_size=g_ntohl(sec_size);
255
						//enbale sound button.
255
	  //enbale sound button.
256
	  sec_size+=sizeof(guint32);
256
	  sec_size+=sizeof(guint32);
257
						break;
257
	  break;
258
					case 'P':
258
	case 'P':
259
	  sec_size=*reinterpret_cast<guint32 *>(p);
259
	  sec_size=*reinterpret_cast<guint32 *>(p);
260
	  sec_size=g_ntohl(sec_size);
260
	  sec_size=g_ntohl(sec_size);
261
	  sec_size+= sizeof(guint32);
261
	  sec_size+= sizeof(guint32);
262
						break;						
262
	  break;						
263
	default:
263
	default:
264
	  /*nothing*/;
264
	  /*nothing*/;
265
				}								
265
	}								
266
	p += sec_size;
266
	p += sec_size;
267
			}
267
      }
268
		}		
268
    }		
269
	}
269
  }
270
	SetText(mark.c_str());
270
  SetText(mark.c_str());
271
	
271
  
272
	gboolean canRead = gpAppFrame->oReadWord.canRead(sOriginWord);
272
  gboolean canRead = gpAppFrame->oReadWord.canRead(sOriginWord);
273
	if (canRead) {
273
  if (canRead) {
274
		PronounceWord = sOriginWord;
274
    PronounceWord = sOriginWord;
275
  } else {
275
  } else {
276
		for (int i=0;i< gpAppFrame->oAppCore.oLibs.total_libs(); i++) {
276
    for (int i=0;i< gpAppFrame->oAppCore.oLibs.total_libs(); i++) {
277
			if (word[i] && strcmp(word[i], sOriginWord)) {
277
      if (word[i] && strcmp(word[i], sOriginWord)) {
278
				if (gpAppFrame->oReadWord.canRead(word[i])) {
278
	if (gpAppFrame->oReadWord.canRead(word[i])) {
279
					canRead = true;
279
	  canRead = true;
280
					PronounceWord = word[i];
280
	  PronounceWord = word[i];
281
				}
281
	}
282
				break;
282
	break;
283
			}
283
      }
284
		}
284
    }
285
	}
285
  }
286
	gtk_widget_set_sensitive(PronounceWordButton, canRead);	
286
  gtk_widget_set_sensitive(PronounceWordButton, canRead);	
287
	Popup(true);
287
  Popup(true);
288
288
  
289
	if (canRead && conf->get_pronounce_when_popup())
289
  if (canRead && conf->get_pronounce_when_popup())
290
		gpAppFrame->oReadWord.read(PronounceWord.c_str());
290
    gpAppFrame->oReadWord.read(PronounceWord.c_str());
291
}
291
}
292
292
293
void FloatWin::ShowText(gchar *** pppWord, gchar *** pppWordData, 
293
void FloatWin::ShowText(gchar *** pppWord, gchar *** pppWordData, 
294
			const gchar ** ppOriginWord, gint count,
294
			const gchar ** ppOriginWord, gint count,
295
			const gchar * sOriginWord)
295
			const gchar * sOriginWord)
296
{
296
{
297
	QueryingWord = sOriginWord;
297
  QueryingWord = sOriginWord;
298
	found_result = FLOAT_WIN_FUZZY_FOUND;
298
  found_result = FLOAT_WIN_FUZZY_FOUND;
299
	std::string mark;
299
  std::string mark;
300
	gchar *m_str;
300
  gchar *m_str;
301
	mark = _("Fuzzy query");
301
  mark = _("Fuzzy query");
302
	mark += " <b><big>";
302
  mark += " <b><big>";
303
	m_str = g_markup_escape_text(sOriginWord,-1);
303
  m_str = g_markup_escape_text(sOriginWord,-1);
304
	mark += m_str;
304
  mark += m_str;
305
	g_free(m_str);
305
  g_free(m_str);
306
	mark += "</big></b> ";
306
  mark += "</big></b> ";
307
	mark += _("has succeeded.\n");
307
  mark += _("has succeeded.\n");
308
	mark += _("Found ");
308
  mark += _("Found ");
309
	if (count ==1)
309
  if (count ==1)
310
		mark+= _("1 word:\n");
310
    mark+= _("1 word:\n");
311
  else {
311
  else {
312
		m_str=g_strdup_printf("%d",count);
312
    m_str=g_strdup_printf("%d",count);
313
		mark += m_str;
313
    mark += m_str;
314
		g_free(m_str);
314
    g_free(m_str);
315
		mark+= _(" words:\n");
315
    mark+= _(" words:\n");
316
	}
316
  }
317
	int j;
317
  int j;
318
  for (j=0; j<count-1; j++) {
318
  for (j=0; j<count-1; j++) {
319
		mark += "<b><big>";
319
    mark += "<b><big>";
320
    m_str = g_markup_escape_text(ppOriginWord[j], -1);
320
    m_str = g_markup_escape_text(ppOriginWord[j], -1);
321
		mark += m_str;
321
    mark += m_str;
322
		g_free(m_str);
322
    g_free(m_str);
323
		mark += "</big></b> ";
323
    mark += "</big></b> ";
324
	}
324
  }
325
	mark += "<b><big>";
325
  mark += "<b><big>";
326
	m_str = g_markup_escape_text(ppOriginWord[count-1],-1);
326
  m_str = g_markup_escape_text(ppOriginWord[count-1],-1);
327
	mark += m_str;
327
  mark += m_str;
328
	g_free(m_str);
328
  g_free(m_str);
329
	mark += "</big></b>";
329
  mark += "</big></b>";
330
	
330
  
331
	gchar *p;
331
  gchar *p;
332
  guint32 data_size,sec_size=0;
332
  guint32 data_size,sec_size=0;
333
  for (j=0; j<count; j++) {
333
  for (j=0; j<count; j++) {
334
		mark += "\n\n<span foreground=\"red\">#----- ";
334
    mark += "\n\n<span foreground=\"red\">#----- ";
335
		m_str = g_markup_escape_text(ppOriginWord[j],-1);
335
    m_str = g_markup_escape_text(ppOriginWord[j],-1);
336
		mark += m_str;
336
    mark += m_str;
337
		g_free(m_str);
337
    g_free(m_str);
338
		mark += " -----#</span>";
338
    mark += " -----#</span>";
339
		
339
    
340
    for (int i=0; i<gpAppFrame->oAppCore.oLibs.total_libs(); i++) {
340
    for (int i=0; i<gpAppFrame->oAppCore.oLibs.total_libs(); i++) {
341
			if (pppWord[j][i]) {
341
      if (pppWord[j][i]) {
342
				mark += "\n<span foreground=\"blue\">*--- ";
342
	mark += "\n<span foreground=\"blue\">*--- ";
343
				m_str = g_markup_escape_text(gpAppFrame->oAppCore.oLibs.GetBookname(i),-1);
343
	m_str = g_markup_escape_text(gpAppFrame->oAppCore.oLibs.GetBookname(i),-1);
344
				mark += m_str;
344
	mark += m_str;
345
				g_free(m_str);
345
	g_free(m_str);
346
				mark += " ---*</span>";
346
	mark += " ---*</span>";
347
				
347
	
348
				if (strcmp(ppOriginWord[j],pppWord[j][i])) {
348
	if (strcmp(ppOriginWord[j],pppWord[j][i])) {
349
					mark +=	"\n<span foreground=\"purple\">";
349
	  mark +=	"\n<span foreground=\"purple\">";
350
					m_str = g_markup_escape_text(pppWord[j][i],-1);
350
	  m_str = g_markup_escape_text(pppWord[j][i],-1);
351
					mark += m_str;
351
	  mark += m_str;
352
					g_free(m_str);
352
	  g_free(m_str);
353
					mark += "</span>";
353
	  mark += "</span>";
354
				}
354
	}
355
			}
355
      }
356
			if (pppWordData[j][i]) {			
356
      if (pppWordData[j][i]) {			
357
	p=pppWordData[j][i];
357
	p=pppWordData[j][i];
358
	data_size=*reinterpret_cast<guint32 *>(p);
358
	data_size=*reinterpret_cast<guint32 *>(p);
359
	p+=sizeof(guint32);
359
	p+=sizeof(guint32);
360
	while (guint32(p - (pppWordData[j][i] + sizeof(guint32)))< data_size) {
360
	while (guint32(p - pppWordData[j][i])< data_size) {
361
	  switch (*p++) {
361
	  switch (*p++) {
362
						case 'm':
362
	  case 'm':
363
	  case 'l': //need more work...
363
	  case 'l': //need more work...
364
	    sec_size = strlen(p);
364
	    sec_size = strlen(p);
365
							if (sec_size) {
365
	    if (sec_size) {
366
								mark+= "\n";
366
	      mark+= "\n";
367
	      m_str = g_markup_escape_text(p,sec_size);
367
	      m_str = g_markup_escape_text(p,sec_size);
368
								mark += m_str;
368
	      mark += m_str;
369
								g_free(m_str);
369
	      g_free(m_str);
370
							}
370
	    }
371
							sec_size++;
371
	    sec_size++;
372
							break;
372
	    break;
373
	  case 'g':
373
	  case 'g':
374
	    sec_size = strlen(p);
374
	    sec_size = strlen(p);
375
	    if (sec_size) {
375
	    if (sec_size) {
Lines 378-434 Link Here
378
	    }
378
	    }
379
	    sec_size++;
379
	    sec_size++;
380
	    break;
380
	    break;
381
						case 't':
381
	  case 't':
382
	    sec_size = strlen(p);
382
	    sec_size = strlen(p);
383
							if (sec_size) {
383
	    if (sec_size) {
384
								mark += "\n<big>[";
384
	      mark += "\n<big>[";
385
	      m_str = g_markup_escape_text(p, sec_size);
385
	      m_str = g_markup_escape_text(p, sec_size);
386
								mark += m_str;
386
	      mark += m_str;
387
								g_free(m_str);
387
	      g_free(m_str);
388
								mark+= "]</big>";
388
	      mark+= "]</big>";
389
							}
389
	    }
390
							sec_size++;
390
	    sec_size++;
391
							break;
391
	    break;
392
						case 'y':
392
	  case 'y':
393
	    sec_size = strlen(p);
393
	    sec_size = strlen(p);
394
							if (sec_size) {
394
	    if (sec_size) {
395
								mark += "\n<span foreground=\"red\">[";
395
	      mark += "\n<span foreground=\"red\">[";
396
	      m_str = g_markup_escape_text(p, sec_size);
396
	      m_str = g_markup_escape_text(p, sec_size);
397
								mark += m_str;
397
	      mark += m_str;
398
								g_free(m_str);
398
	      g_free(m_str);
399
								mark+= "]</span>";
399
	      mark+= "]</span>";
400
							}
400
	    }
401
							sec_size++;						
401
	    sec_size++;						
402
							break;
402
	    break;
403
						case 'W':
403
	  case 'W':
404
	    sec_size=*reinterpret_cast<guint32 *>(p);
404
	    sec_size=*reinterpret_cast<guint32 *>(p);
405
	    sec_size=g_ntohl(sec_size);
405
	    sec_size=g_ntohl(sec_size);
406
							//enbale sound button.
406
	    //enbale sound button.
407
	    sec_size+= sizeof(guint32);
407
	    sec_size+= sizeof(guint32);
408
							break;
408
	    break;
409
						case 'P':
409
	  case 'P':
410
	    sec_size=*reinterpret_cast<guint32 *>(p);
410
	    sec_size=*reinterpret_cast<guint32 *>(p);
411
	    sec_size=g_ntohl(sec_size);
411
	    sec_size=g_ntohl(sec_size);
412
	    sec_size+= sizeof(guint32);
412
	    sec_size+= sizeof(guint32);
413
							break;						
413
	    break;						
414
	  default:
414
	  default:
415
	    /*nothing*/;
415
	    /*nothing*/;
416
					}								
416
	  }								
417
	  p += sec_size;
417
	  p += sec_size;
418
				}				
418
	}				
419
			}		
419
      }		
420
		}		
420
    }		
421
	}		
421
  }		
422
	SetText(mark.c_str());
422
  SetText(mark.c_str());
423
	gboolean canRead = gpAppFrame->oReadWord.canRead(sOriginWord);
423
  gboolean canRead = gpAppFrame->oReadWord.canRead(sOriginWord);
424
	if (canRead)
424
  if (canRead)
425
		PronounceWord = sOriginWord;
425
    PronounceWord = sOriginWord;
426
	gtk_widget_set_sensitive(PronounceWordButton, canRead);
426
  gtk_widget_set_sensitive(PronounceWordButton, canRead);
427
427
  
428
	Popup(false);
428
  Popup(false);
429
	
429
  
430
	if (canRead && conf->get_pronounce_when_popup())
430
  if (canRead && conf->get_pronounce_when_popup())
431
		gpAppFrame->oReadWord.read(PronounceWord.c_str());
431
    gpAppFrame->oReadWord.read(PronounceWord.c_str());
432
}
432
}
433
433
434
void FloatWin::ShowNotFound(const char* sWord,const char* sReason, gboolean fuzzy)
434
void FloatWin::ShowNotFound(const char* sWord,const char* sReason, gboolean fuzzy)
(-)stardict-2.4.5/src/lib.cpp (-171 / +140 lines)
Lines 121-152 Link Here
121
            return false;            
121
            return false;            
122
  return true;	
122
  return true;	
123
}
123
}
124
125
inline gint stardict_strcmp(const gchar *s1, const gchar *s2) 
126
{
124
#ifndef NEW_CMP
127
#ifndef NEW_CMP
125
inline gint stardict_strcmp(const gchar *s1, const gchar *s2) {
126
  gint a=g_ascii_strcasecmp(s1, s2);
128
  gint a=g_ascii_strcasecmp(s1, s2);
127
  if (a == 0)
129
  if (a == 0)
128
    return strcmp(s1, s2);
130
    return strcmp(s1, s2);
129
  else
131
  else
130
    return a;
132
    return a;
131
}
132
#else
133
#else
133
inline gint stardict_strcmp2(const gchar *s1, const gchar *s2) {
134
  gint res=0;
134
	gint res=0;
135
  while (*s1 && *s2) {
135
	while (*s1 && *s2) {
136
    res=g_unichar_tolower(g_utf8_get_char(s1))-g_unichar_tolower(g_utf8_get_char(s2));
136
		res=g_unichar_tolower(g_utf8_get_char(s1))-g_unichar_tolower(g_utf8_get_char(s2));
137
    if (res!=0)
137
		if (res!=0)
138
      return res;
138
			return res;
139
    s1=g_utf8_next_char(s1);
139
		s1=g_utf8_next_char(s1);
140
    s2=g_utf8_next_char(s2);
140
		s2=g_utf8_next_char(s2);
141
  }
141
	}
142
  
142
143
  if (*s1 && !*s2)
143
	if (*s1 && !*s2)
144
    return 1;
144
		return 1;
145
  if (!*s1 && *s2)
145
	if (!*s1 && *s2)
146
    return -1;
146
		return -1;
147
  return 0;
147
	return 0;
148
}
149
#endif
148
#endif
149
}
150
150
bool DictInfo::load_from_ifo_file(const gchar *ifofilename,
151
bool DictInfo::load_from_ifo_file(const gchar *ifofilename,
151
				  bool istreedict)
152
				  bool istreedict)
152
{
153
{
Lines 284-392 Link Here
284
{
285
{
285
  for (int i=0; i<WORDDATA_CACHE_NUM; i++)	
286
  for (int i=0; i<WORDDATA_CACHE_NUM; i++)	
286
    if (cache[i].data && cache[i].offset == idxitem_offset)
287
    if (cache[i].data && cache[i].offset == idxitem_offset)
287
			return cache[i].data;
288
      return cache[i].data;
288
			
289
  
289
  if (dictfile)
290
  if (dictfile)
290
		fseek(dictfile, idxitem_offset, SEEK_SET);
291
    fseek(dictfile, idxitem_offset, SEEK_SET);
291
	
292
  
292
	gchar *data;
293
  gchar *data;
293
	if (sametypesequence) {
294
  if (sametypesequence) {
294
    gchar *origin_data = (gchar *)g_malloc(idxitem_size);
295
    gchar *origin_data = (gchar *)g_malloc(idxitem_size);
295
		
296
    
296
		if (dictfile)
297
    if (dictfile)
297
      fread(origin_data, idxitem_size, 1, dictfile);
298
      fread(origin_data, idxitem_size, 1, dictfile);
298
		else
299
    else
299
      dict_data_read(dictdzfile, origin_data, idxitem_offset, idxitem_size);
300
      dict_data_read(dictdzfile, origin_data, idxitem_offset, idxitem_size);
300
	
301
    
301
    guint32 data_size;
302
    guint32 data_size;
302
		gint sametypesequence_len;
303
    gint sametypesequence_len;
303
		sametypesequence_len = strlen(sametypesequence);
304
    sametypesequence_len = strlen(sametypesequence);
304
		//there have sametypesequence_len char being omitted.
305
    //there have sametypesequence_len char being omitted.
305
    data_size = idxitem_size + sizeof(guint32) + sametypesequence_len;
306
    data_size = idxitem_size + sizeof(guint32) + sametypesequence_len;
306
		//if the last item's size is determined by the end up '\0',then +=sizeof(gchar);
307
    //if the last item's size is determined by the end up '\0',then +=sizeof(gchar);
307
    //if the last item's size is determined by the head guint32 type data,then +=sizeof(guint32);
308
    //if the last item's size is determined by the head guint32 type data,then +=sizeof(guint32);
308
		switch (sametypesequence[sametypesequence_len-1]) {
309
    switch (sametypesequence[sametypesequence_len-1]) {
309
			case 'm':
310
    case 'm':
310
			case 't':
311
    case 't':
311
			case 'y':
312
    case 'y':
312
    case 'l':
313
    case 'l':
313
    case 'g':
314
    case 'g':
314
				data_size += sizeof(gchar);
315
      data_size += sizeof(gchar);
315
				break;
316
      break;
316
			case 'W':
317
    case 'W':
317
			case 'P':
318
    case 'P':
318
      data_size += sizeof(guint32);
319
      data_size += sizeof(guint32);
319
				break;
320
      break;
320
		}			
321
    }			
321
		data = (gchar *)g_malloc(data_size);
322
    data = (gchar *)g_malloc(data_size);
322
		gchar *p1,*p2;
323
    gchar *p1,*p2;
323
    p1 = data + sizeof(guint32);
324
    p1 = data + sizeof(guint32);
324
		p2 = origin_data;
325
    p2 = origin_data;
325
    guint32 sec_size;
326
    guint32 sec_size;
326
		//copy the head items.
327
    //copy the head items.
327
    for (int i=0; i<sametypesequence_len-1; i++) {
328
    for (int i=0; i<sametypesequence_len-1; i++) {
328
      *p1=sametypesequence[i];
329
      *p1=sametypesequence[i];
329
      p1+=sizeof(gchar);
330
      p1+=sizeof(gchar);
330
			switch (sametypesequence[i]) {
331
      switch (sametypesequence[i]) {
331
				case 'm':
332
      case 'm':
332
				case 't':
333
      case 't':
333
				case 'y':
334
      case 'y':
334
      case 'l':
335
      case 'l':
335
      case 'g':
336
      case 'g':
336
					sec_size = strlen(p2)+1;
337
	sec_size = strlen(p2)+1;
337
					memcpy(p1, p2, sec_size);
338
	memcpy(p1, p2, sec_size);
338
	p1+=sec_size;
339
	p1+=sec_size;
339
	p2+=sec_size;
340
	p2+=sec_size;
340
					break;
341
	break;
341
				case 'W':
342
      case 'W':
342
				case 'P':
343
      case 'P':
343
	sec_size = *reinterpret_cast<guint32 *>(p2);
344
	sec_size = *reinterpret_cast<guint32 *>(p2);
344
	sec_size += sizeof(guint32);
345
	sec_size += sizeof(guint32);
345
					memcpy(p1, p2, sec_size);
346
	memcpy(p1, p2, sec_size);
346
	p1+=sec_size;
347
	p1+=sec_size;
347
	p2+=sec_size;
348
	p2+=sec_size;
348
					break;
349
	break;
349
			}							
350
      }							
350
		}	
351
    }	
351
		//calculate the last item 's size.
352
    //calculate the last item 's size.
352
		sec_size = idxitem_size - (p2-origin_data);
353
    sec_size = idxitem_size - (p2-origin_data);
353
    *p1=sametypesequence[sametypesequence_len-1];
354
    *p1=sametypesequence[sametypesequence_len-1];
354
    p1+=sizeof(gchar);
355
    p1+=sizeof(gchar);
355
		switch (sametypesequence[sametypesequence_len-1]) {
356
    switch (sametypesequence[sametypesequence_len-1]) {
356
			case 'm':
357
    case 'm':
357
			case 't':
358
    case 't':
358
			case 'y':
359
    case 'y':
359
    case 'l':
360
    case 'l':
360
    case 'g':
361
    case 'g':
361
				memcpy(p1, p2, sec_size);
362
      memcpy(p1, p2, sec_size);
362
				p1 += sec_size;				
363
      p1 += sec_size;				
363
      *p1='\0';//add the end up '\0';
364
      *p1='\0';//add the end up '\0';
364
				break;
365
      break;
365
			case 'W':
366
    case 'W':
366
			case 'P':
367
    case 'P':
367
      *reinterpret_cast<guint32 *>(p1)=sec_size;
368
      *reinterpret_cast<guint32 *>(p1)=sec_size;
368
      p1 += sizeof(guint32);
369
      p1 += sizeof(guint32);
369
				memcpy(p1, p2, sec_size);
370
      memcpy(p1, p2, sec_size);
370
				break;
371
      break;
371
		}		
372
    }		
372
		g_free(origin_data);		
373
    g_free(origin_data);		
373
    *reinterpret_cast<guint32 *>(data)=data_size;
374
    *reinterpret_cast<guint32 *>(data)=data_size;
374
  } else {		
375
  } else {		
375
    data = (gchar *)g_malloc(idxitem_size + sizeof(guint32));
376
    data = (gchar *)g_malloc(idxitem_size + sizeof(guint32));
376
		if (dictfile)
377
    if (dictfile)
377
      fread(data+sizeof(guint32), idxitem_size, 1, dictfile);		
378
      fread(data+sizeof(guint32), idxitem_size, 1, dictfile);		
378
		else
379
    else
379
      dict_data_read(dictdzfile, data+sizeof(guint32), idxitem_offset, idxitem_size);
380
      dict_data_read(dictdzfile, data+sizeof(guint32), idxitem_offset, idxitem_size);
380
    *reinterpret_cast<guint32 *>(data)=idxitem_size;
381
    *reinterpret_cast<guint32 *>(data)=idxitem_size+sizeof(guint32);
381
	}	
382
  }	
382
		g_free(cache[cache_cur].data);
383
  g_free(cache[cache_cur].data);
383
384
  
384
	cache[cache_cur].data = data;
385
  cache[cache_cur].data = data;
385
	cache[cache_cur].offset = idxitem_offset;
386
  cache[cache_cur].offset = idxitem_offset;
386
	cache_cur++;
387
  cache_cur++;
387
	if (cache_cur==WORDDATA_CACHE_NUM)
388
  if (cache_cur==WORDDATA_CACHE_NUM)
388
    cache_cur = 0;
389
    cache_cur = 0;
389
    return data;
390
  return data;
390
}
391
}
391
392
392
393
Lines 507-517 Link Here
507
}
508
}
508
509
509
inline bool less_for_compare(const char *lh, const char *rh) {
510
inline bool less_for_compare(const char *lh, const char *rh) {
510
#ifndef NEW_CMP
511
  return stardict_strcmp(lh, rh)<0;
511
  return stardict_strcmp(lh, rh)<0;
512
#else
513
  return stardict_strcmp2(lh, rh)<0;
514
#endif
515
}
512
}
516
#ifdef NEW_CMP
513
#ifdef NEW_CMP
517
struct CharacterArea1 {
514
struct CharacterArea1 {
Lines 588-598 Link Here
588
#endif
585
#endif
589
}
586
}
590
#ifdef NEW_CMP
587
#ifdef NEW_CMP
591
class StarDictCompare2 {
588
class StarDictCompare {
592
public:
589
public:
593
  explicit StarDictCompare2(const gchar *data_value) : data(data_value) {}
590
  explicit StarDictCompare(const gchar *data_value) : data(data_value) {}
594
  bool operator()(const Lib::WordCoord & lh, const Lib::WordCoord & rh) {
591
  bool operator()(const Lib::WordCoord & lh, const Lib::WordCoord & rh) {
595
    return stardict_strcmp2(data+lh.offset, data+rh.offset)<0;
592
    return stardict_strcmp(data+lh.offset, data+rh.offset)<0;
596
  }
593
  }
597
private:
594
private:
598
  const gchar *data;
595
  const gchar *data;
Lines 663-670 Link Here
663
    ++ptr;
660
    ++ptr;
664
  }
661
  }
665
662
666
  StarDictCompare2 stardict_compare2(idxdatabuffer);
663
  StarDictCompare stardict_compare(idxdatabuffer);
667
  std::sort(wordoffset, wordoffset+wordcount, stardict_compare2);
664
  std::sort(wordoffset, wordoffset+wordcount, stardict_compare);
668
#endif
665
#endif
669
}
666
}
670
667
Lines 675-695 Link Here
675
#endif
672
#endif
676
  bool bFound=false;
673
  bool bFound=false;
677
  glong iTo=wordcount-1;
674
  glong iTo=wordcount-1;
678
#ifndef NEW_CMP
675
679
	if (stardict_strcmp(sWord, GetWord(0))<0) {
676
  if (stardict_strcmp(sWord, GetWord(0))<0) {
680
#else
677
    *pIndex = 0;
681
  if (stardict_strcmp2(sWord, GetWord(0))<0) {
678
682
#endif
683
		*pIndex = 0;
684
#ifndef NEW_CMP
685
  } else if (stardict_strcmp(sWord, GetWord(iTo)) >0) {
679
  } else if (stardict_strcmp(sWord, GetWord(iTo)) >0) {
686
#else
680
    *pIndex = INVALID_INDEX;
687
  } else if (stardict_strcmp2(sWord, GetWord(iTo)) >0) {
688
#endif
689
		*pIndex = INVALID_INDEX;
690
  } else {
681
  } else {
691
	    glong iThisIndex=0;
682
    glong iThisIndex=0;
692
    	glong iFrom=0;
683
    glong iFrom=0;
693
#ifdef NEW_CMP
684
#ifdef NEW_CMP
694
#if 1
685
#if 1
695
    Character first;
686
    Character first;
Lines 708-745 Link Here
708
#endif
699
#endif
709
    gint cmpint;
700
    gint cmpint;
710
    while (iFrom<=iTo) {
701
    while (iFrom<=iTo) {
711
        	iThisIndex=(iFrom+iTo)/2;
702
      iThisIndex=(iFrom+iTo)/2;
712
#ifndef NEW_CMP
703
      
713
			cmpint = stardict_strcmp(sWord, GetWord(iThisIndex));
704
      cmpint = stardict_strcmp(sWord, GetWord(iThisIndex));
714
#else
705
      
715
      cmpint = stardict_strcmp2(sWord, GetWord(iThisIndex));
716
#endif
717
718
      if (cmpint>0)
706
      if (cmpint>0)
719
				iFrom=iThisIndex+1;
707
	iFrom=iThisIndex+1;
720
      else if (cmpint<0)
708
      else if (cmpint<0)
721
				iTo=iThisIndex-1;
709
	iTo=iThisIndex-1;
722
      else {	
710
      else {	
723
	bFound=true;
711
	bFound=true;
724
	break;
712
	break;
725
			}
713
      }
726
    	}
714
    }
727
715
    
728
    if (!bFound) {
716
    if (!bFound) {
729
			/*glong len = g_utf8_strlen(sWord, -1);
717
      /*glong len = g_utf8_strlen(sWord, -1);
730
			gchar *last_str = g_utf8_offset_to_pointer(sWord, len-1);
718
	gchar *last_str = g_utf8_offset_to_pointer(sWord, len-1);
731
			gunichar last = g_utf8_get_char(last_str);
719
	gunichar last = g_utf8_get_char(last_str);
732
			if (((g_unichar_isspace(last) || g_unichar_ispunct(last)) || g_unichar_isdigit(last))
720
	if (((g_unichar_isspace(last) || g_unichar_ispunct(last)) || g_unichar_isdigit(last))
733
				&& (g_ascii_strncasecmp(sWord, GetWord(iTo), (last_str - sWord))==0))
721
	&& (g_ascii_strncasecmp(sWord, GetWord(iTo), (last_str - sWord))==0))
734
				*pIndex = iTo;      //previous
722
	*pIndex = iTo;      //previous
735
			else 
723
	else 
736
            	*pIndex = iFrom;    //next
724
	*pIndex = iFrom;    //next
737
			*/
725
	*/
738
			*pIndex = iFrom;    //next
726
      *pIndex = iFrom;    //next
739
    } else
727
    } else
740
			*pIndex = iThisIndex;		
728
      *pIndex = iThisIndex;		
741
	}		
729
  }		
742
730
  
743
#ifdef MEASURE_TIME
731
#ifdef MEASURE_TIME
744
  t=clock()-t;
732
  t=clock()-t;
745
  middle_lookup_time*=measure_time;
733
  middle_lookup_time*=measure_time;
Lines 937-964 Link Here
937
925
938
gchar *Libs::poGetCurrentWord(glong * iCurrent)
926
gchar *Libs::poGetCurrentWord(glong * iCurrent)
939
{
927
{
940
	gchar * poCurrentWord = NULL;
928
  gchar * poCurrentWord = NULL;
941
	gchar *word;
929
  gchar *word;
942
    for (int iLib=0;iLib<libcount;iLib++) {
930
  for (int iLib=0;iLib<libcount;iLib++) {
943
		if (iCurrent[iLib]==INVALID_INDEX)
931
    if (iCurrent[iLib]==INVALID_INDEX)
944
            continue;
932
      continue;
945
		if ( iCurrent[iLib]>=iLength(iLib) || iCurrent[iLib]<0)
933
    if ( iCurrent[iLib]>=iLength(iLib) || iCurrent[iLib]<0)
946
			continue;
934
      continue;
947
		if ( poCurrentWord == NULL ) {
935
    if ( poCurrentWord == NULL ) {
948
			poCurrentWord = poGetWord(iCurrent[iLib],iLib);
936
      poCurrentWord = poGetWord(iCurrent[iLib],iLib);
949
		}
937
    } else {
950
		else {
938
      word = poGetWord(iCurrent[iLib],iLib);
951
			word = poGetWord(iCurrent[iLib],iLib);
939
      
952
#ifndef NEW_CMP
940
      if (stardict_strcmp(poCurrentWord, word) > 0 )
953
			if (stardict_strcmp(poCurrentWord, word) > 0 )
941
	poCurrentWord = word;
954
#else
942
    }
955
	if (stardict_strcmp2(poCurrentWord, word) > 0 )
943
  }
956
#endif
944
  return poCurrentWord;
957
				poCurrentWord = word;
945
}
958
		}
959
	}
960
    return poCurrentWord;
961
 }
962
946
963
gchar *
947
gchar *
964
Libs::poGetNextWord(const gchar *sWord, glong * iCurrent)
948
Libs::poGetNextWord(const gchar *sWord, glong * iCurrent)
Lines 983-993 Link Here
983
		}
967
		}
984
		else {
968
		else {
985
			word = poGetWord(iCurrent[iLib],iLib);
969
			word = poGetWord(iCurrent[iLib],iLib);
986
#ifndef NEW_CMP
970
987
			if (  stardict_strcmp(poCurrentWord, word) > 0 ) {
971
			if (  stardict_strcmp(poCurrentWord, word) > 0 ) {
988
#else
989
			if (  stardict_strcmp2(poCurrentWord, word) > 0 ) {
990
#endif
991
				poCurrentWord = word;
972
				poCurrentWord = word;
992
				iCurrentLib = iLib;
973
				iCurrentLib = iLib;
993
			}
974
			}
Lines 1030-1040 Link Here
1030
		}
1011
		}
1031
		else {
1012
		else {
1032
			word = poGetWord(iCurrent[iLib]-1,iLib);
1013
			word = poGetWord(iCurrent[iLib]-1,iLib);
1033
#ifndef NEW_CMP
1034
			if (stardict_strcmp(poCurrentWord, word) < 0 ) {
1014
			if (stardict_strcmp(poCurrentWord, word) < 0 ) {
1035
#else
1036
                        if (stardict_strcmp2(poCurrentWord, word) < 0 ) {
1037
#endif
1038
				poCurrentWord = word;
1015
				poCurrentWord = word;
1039
				iCurrentLib = iLib;
1016
				iCurrentLib = iLib;
1040
			}
1017
			}
Lines 1399-1409 Link Here
1399
    return lh.iMatchWordDistance<rh.iMatchWordDistance;
1376
    return lh.iMatchWordDistance<rh.iMatchWordDistance;
1400
1377
1401
  if (lh.pMatchWord && rh.pMatchWord)
1378
  if (lh.pMatchWord && rh.pMatchWord)
1402
#ifndef NEW_CMP
1403
    return stardict_strcmp(lh.pMatchWord, rh.pMatchWord)<0;
1379
    return stardict_strcmp(lh.pMatchWord, rh.pMatchWord)<0;
1404
#else
1405
    return stardict_strcmp2(lh.pMatchWord, rh.pMatchWord)<0;
1406
#endif
1407
  
1380
  
1408
  return false;
1381
  return false;
1409
}
1382
}
Lines 1434-1446 Link Here
1434
  for (int iLib=0; iLib<libcount; iLib++) {
1407
  for (int iLib=0; iLib<libcount; iLib++) {
1435
    if (ProgressFunc)
1408
    if (ProgressFunc)
1436
      ProgressFunc();
1409
      ProgressFunc();
1437
#ifndef NEW_CMP
1410
1438
    if (stardict_strcmp(sWord, poGetWord(0,iLib))>=0 && 
1411
    if (stardict_strcmp(sWord, poGetWord(0,iLib))>=0 && 
1439
	stardict_strcmp(sWord, poGetWord(iLength(iLib)-1,iLib))<=0) {
1412
	stardict_strcmp(sWord, poGetWord(iLength(iLib)-1,iLib))<=0) {
1440
#else
1441
    if (stardict_strcmp2(sWord, poGetWord(0,iLib))>=0 && 
1442
	stardict_strcmp2(sWord, poGetWord(iLength(iLib)-1,iLib))<=0) {
1443
#endif
1444
      //there are Chinese dicts and English dicts...        
1413
      //there are Chinese dicts and English dicts...        
1445
      const int iwords = iLength(iLib);
1414
      const int iwords = iLength(iLib);
1446
      for (int index=0; index<iwords; index++) {
1415
      for (int index=0; index<iwords; index++) {
(-)stardict-2.4.5/src/mainwin.cpp (-78 / +78 lines)
Lines 1329-1368 Link Here
1329
1329
1330
void TextWin::Show(gchar **Word, gchar **WordData, const gchar * sOriginWord)
1330
void TextWin::Show(gchar **Word, gchar **WordData, const gchar * sOriginWord)
1331
{
1331
{
1332
	gchar *p;
1332
  gchar *p;
1333
  guint32 data_size,sec_size=0;
1333
  guint32 data_size,sec_size=0;
1334
	GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
1334
  GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
1335
	gtk_text_buffer_begin_user_action(buffer); // will this speed up the showing?
1335
  gtk_text_buffer_begin_user_action(buffer); // will this speed up the showing?
1336
	
1336
  
1337
	GtkTextIter start, end;	
1337
  GtkTextIter start, end;	
1338
	gtk_text_buffer_get_bounds(buffer,&start,&end);
1338
  gtk_text_buffer_get_bounds(buffer,&start,&end);
1339
	gtk_text_buffer_delete(buffer,&start,&end);
1339
  gtk_text_buffer_delete(buffer,&start,&end);
1340
	gtk_adjustment_set_value(gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW(scrolled_window)), 0);
1340
  gtk_adjustment_set_value(gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW(scrolled_window)), 0);
1341
	
1341
  
1342
	GtkTextIter iter;
1342
  GtkTextIter iter;
1343
	gtk_text_buffer_get_iter_at_offset (buffer, &iter, 0);
1343
  gtk_text_buffer_get_iter_at_offset (buffer, &iter, 0);
1344
  for (int i=0; i<gpAppFrame->oAppCore.oLibs.total_libs(); i++)	{
1344
  for (int i=0; i<gpAppFrame->oAppCore.oLibs.total_libs(); i++)	{
1345
		if (Word[i]) {
1345
    if (Word[i]) {
1346
			gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "<--- ",-1, "DictNameTag", NULL);
1346
      gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "<--- ",-1, "DictNameTag", NULL);
1347
      gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, gpAppFrame->oAppCore.oLibs.GetBookname(i),
1347
      gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, gpAppFrame->oAppCore.oLibs.GetBookname(i),
1348
					       -1, "DictNameTag", NULL);
1348
					       -1, "DictNameTag", NULL);
1349
			gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, " --->\n",-1, "DictNameTag", NULL);
1349
      gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, " --->\n",-1, "DictNameTag", NULL);
1350
			gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, Word[i],-1, "WordTag", NULL);	
1350
      gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, Word[i],-1, "WordTag", NULL);	
1351
			gtk_text_buffer_insert (buffer, &iter,"\n", 1);
1351
      gtk_text_buffer_insert (buffer, &iter,"\n", 1);
1352
		}
1352
    }
1353
		if (WordData[i]) {
1353
    if (WordData[i]) {
1354
      p=WordData[i];
1354
      p=WordData[i];
1355
      data_size=*reinterpret_cast<guint32 *>(p);
1355
      data_size=*reinterpret_cast<guint32 *>(p);
1356
      p+=sizeof(guint32);
1356
      p+=sizeof(guint32);
1357
      while (guint32(p - (WordData[i] + sizeof(guint32)))< data_size) {
1357
      while (guint32(p - WordData[i])< data_size) {
1358
	switch (*p++) {
1358
	switch (*p++) {
1359
					case 'm':
1359
	case 'm':
1360
	case 'l'://need more work...
1360
	case 'l'://need more work...
1361
	  sec_size = strlen(p);
1361
	  sec_size = strlen(p);
1362
	  if (sec_size)
1362
	  if (sec_size)
1363
	    gtk_text_buffer_insert(buffer, &iter, p, sec_size);	  
1363
	    gtk_text_buffer_insert(buffer, &iter, p, sec_size);	  
1364
						sec_size++;
1364
	  sec_size++;
1365
						break;
1365
	  break;
1366
	case 'g':
1366
	case 'g':
1367
	  sec_size = strlen(p);
1367
	  sec_size = strlen(p);
1368
	  if (sec_size) {
1368
	  if (sec_size) {
Lines 1374-1447 Link Here
1374
	  }
1374
	  }
1375
	  sec_size++;
1375
	  sec_size++;
1376
	  break;
1376
	  break;
1377
					case 't':
1377
	case 't':
1378
	  sec_size = strlen(p);
1378
	  sec_size = strlen(p);
1379
						if (sec_size) {
1379
	  if (sec_size) {
1380
	    gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "[", 1, "PhoneticTag", NULL);
1380
	    gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "[", 1, "PhoneticTag", NULL);
1381
	    gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, p, sec_size, "PhoneticTag", NULL);
1381
	    gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, p, sec_size, "PhoneticTag", NULL);
1382
	    gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "]", 1, "PhoneticTag", NULL);
1382
	    gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "]", 1, "PhoneticTag", NULL);
1383
						}
1383
	  }
1384
						sec_size++;						
1384
	  sec_size++;						
1385
						break;
1385
	  break;
1386
					case 'y':
1386
	case 'y':
1387
	  sec_size = strlen(p);
1387
	  sec_size = strlen(p);
1388
						if (sec_size) {
1388
	  if (sec_size) {
1389
	    gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "[", 1, "YinBiaoTag", NULL);
1389
	    gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "[", 1, "YinBiaoTag", NULL);
1390
	    gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, p, sec_size, "YinBiaoTag", NULL);
1390
	    gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, p, sec_size, "YinBiaoTag", NULL);
1391
	    gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "]", 1, "YinBiaoTag", NULL);
1391
	    gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "]", 1, "YinBiaoTag", NULL);
1392
						}
1392
	  }
1393
						sec_size++;
1393
	  sec_size++;
1394
						break;
1394
	  break;
1395
					case 'W':
1395
	case 'W':
1396
	  sec_size=*reinterpret_cast<guint32 *>(p);
1396
	  sec_size=*reinterpret_cast<guint32 *>(p);
1397
	  sec_size=g_ntohl(sec_size);
1397
	  sec_size=g_ntohl(sec_size);
1398
						//enbale sound button.
1398
	  //enbale sound button.
1399
	  sec_size += sizeof(guint32);
1399
	  sec_size += sizeof(guint32);
1400
						break;
1400
	  break;
1401
					case 'P':
1401
	case 'P':
1402
	  sec_size=*reinterpret_cast<guint32 *>(p);
1402
	  sec_size=*reinterpret_cast<guint32 *>(p);
1403
	  sec_size=g_ntohl(sec_size);
1403
	  sec_size=g_ntohl(sec_size);
1404
						//show this picture.
1404
	  //show this picture.
1405
	  sec_size += sizeof(guint32);
1405
	  sec_size += sizeof(guint32);
1406
						break;
1406
	  break;
1407
	default:
1407
	default:
1408
	  /*nothing*/;
1408
	  /*nothing*/;
1409
				}
1409
	}
1410
	gtk_text_buffer_insert(buffer, &iter, "\n", 1);
1410
	gtk_text_buffer_insert(buffer, &iter, "\n", 1);
1411
	p += sec_size;
1411
	p += sec_size;
1412
			}
1412
      }
1413
		}		
1413
    }		
1414
	}
1414
  }
1415
	gtk_text_buffer_end_user_action(buffer);
1415
  gtk_text_buffer_end_user_action(buffer);
1416
}
1416
}
1417
1417
1418
void TextWin::ShowTreeDictData(const gchar *data)
1418
void TextWin::ShowTreeDictData(const gchar *data)
1419
{
1419
{
1420
	GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
1420
  GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
1421
	gtk_text_buffer_begin_user_action(buffer);
1421
  gtk_text_buffer_begin_user_action(buffer);
1422
	
1422
  
1423
	GtkTextIter start, end;	
1423
  GtkTextIter start, end;	
1424
	gtk_text_buffer_get_bounds(buffer,&start,&end);
1424
  gtk_text_buffer_get_bounds(buffer,&start,&end);
1425
	gtk_text_buffer_delete(buffer,&start,&end);
1425
  gtk_text_buffer_delete(buffer,&start,&end);
1426
	gtk_adjustment_set_value(gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW(scrolled_window)), 0);
1426
  gtk_adjustment_set_value(gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW(scrolled_window)), 0);
1427
	
1427
  
1428
	GtkTextIter iter;
1428
  GtkTextIter iter;
1429
	gtk_text_buffer_get_iter_at_offset (buffer, &iter, 0);
1429
  gtk_text_buffer_get_iter_at_offset (buffer, &iter, 0);
1430
1430
  
1431
1431
1432
  guint32 data_size,sec_size=0;
1432
  guint32 data_size,sec_size=0;
1433
  const gchar *p=data;
1433
  const gchar *p=data;
1434
  data_size=*reinterpret_cast<const guint32 *>(p);
1434
  data_size=*reinterpret_cast<const guint32 *>(p);
1435
  p+=sizeof(guint32);
1435
  p+=sizeof(guint32);
1436
  while (guint32(p - (data + sizeof(guint32)))< data_size) {
1436
  while (guint32(p - data)< data_size) {
1437
    switch (*p++) {
1437
    switch (*p++) {
1438
			case 'm':
1438
    case 'm':
1439
    case 'l'://need more work...
1439
    case 'l'://need more work...
1440
      sec_size = strlen(p);
1440
      sec_size = strlen(p);
1441
				if (sec_size)
1441
      if (sec_size)
1442
	gtk_text_buffer_insert(buffer, &iter, p, sec_size);
1442
	gtk_text_buffer_insert(buffer, &iter, p, sec_size);
1443
				sec_size++;
1443
      sec_size++;
1444
				break;
1444
      break;
1445
    case 'g':
1445
    case 'g':
1446
      sec_size=strlen(p);
1446
      sec_size=strlen(p);
1447
      if (sec_size) {
1447
      if (sec_size) {
Lines 1453-1495 Link Here
1453
      }
1453
      }
1454
      sec_size++;
1454
      sec_size++;
1455
      break;
1455
      break;
1456
			case 't':
1456
    case 't':
1457
      sec_size = strlen(p);
1457
      sec_size = strlen(p);
1458
				if (sec_size) {
1458
      if (sec_size) {
1459
	gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "[", 1, "PhoneticTag", NULL);
1459
	gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "[", 1, "PhoneticTag", NULL);
1460
	gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, p, sec_size, "PhoneticTag", NULL);
1460
	gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, p, sec_size, "PhoneticTag", NULL);
1461
	gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "]", 1, "PhoneticTag", NULL);
1461
	gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "]", 1, "PhoneticTag", NULL);
1462
				}
1462
      }
1463
				sec_size++;						
1463
      sec_size++;						
1464
				break;
1464
      break;
1465
			case 'y':
1465
    case 'y':
1466
      sec_size = strlen(p);
1466
      sec_size = strlen(p);
1467
				if (sec_size) {
1467
      if (sec_size) {
1468
	gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "[", 1, "YinBiaoTag", NULL);
1468
	gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "[", 1, "YinBiaoTag", NULL);
1469
	gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, p, sec_size, "YinBiaoTag", NULL);
1469
	gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, p, sec_size, "YinBiaoTag", NULL);
1470
	gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "]", 1, "YinBiaoTag", NULL);
1470
	gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "]", 1, "YinBiaoTag", NULL);
1471
				}
1471
      }
1472
				sec_size++;
1472
      sec_size++;
1473
				break;
1473
      break;
1474
			case 'W':
1474
    case 'W':
1475
      sec_size=*reinterpret_cast<const guint32 *>(p);
1475
      sec_size=*reinterpret_cast<const guint32 *>(p);
1476
      sec_size=g_ntohl(sec_size);
1476
      sec_size=g_ntohl(sec_size);
1477
				//enbale sound button.
1477
      //enbale sound button.
1478
      sec_size += sizeof(guint32);
1478
      sec_size += sizeof(guint32);
1479
				break;
1479
      break;
1480
			case 'P':
1480
    case 'P':
1481
      sec_size=*reinterpret_cast<const guint32 *>(p);
1481
      sec_size=*reinterpret_cast<const guint32 *>(p);
1482
      sec_size=g_ntohl(sec_size);
1482
      sec_size=g_ntohl(sec_size);
1483
				//show this picture.
1483
      //show this picture.
1484
      sec_size += sizeof(guint32);
1484
      sec_size += sizeof(guint32);
1485
				break;
1485
      break;
1486
    default:
1486
    default:
1487
      /*nothing*/;
1487
      /*nothing*/;
1488
		}
1488
    }
1489
    gtk_text_buffer_insert(buffer, &iter,"\n", 1);
1489
    gtk_text_buffer_insert(buffer, &iter,"\n", 1);
1490
    p += sec_size;
1490
    p += sec_size;
1491
	}
1491
  }
1492
	gtk_text_buffer_end_user_action(buffer);
1492
  gtk_text_buffer_end_user_action(buffer);
1493
}
1493
}
1494
1494
1495
gboolean TextWin::Find (const gchar *text, gboolean start)
1495
gboolean TextWin::Find (const gchar *text, gboolean start)

Return to bug 102824