static void test_autogrow(void) { { bighash_table_t *table = bighash_table_create(BIGHASH_AUTOGROW); biglist_t *entries = NULL; insert__(table, 63, &entries); AIM_ASSERT(table->bucket_count == 128); test_table_data__(table, &entries); bighash_table_destroy(table, NULL); } { bighash_table_t *table = bighash_table_create(BIGHASH_AUTOGROW); biglist_t *entries = NULL; insert__(table, 64, &entries); AIM_ASSERT(table->bucket_count == 256); test_table_data__(table, &entries); bighash_table_destroy(table, NULL); } }
int sourceview___::proc__(deque<ustring>* p,char*buf,long siz,char**addr_ret,void*shangji,void*ce) { char sdz=0; if((*p)[0]==name__()){ if(siz==-1)return 1; sdz='s'; }else return 0; if(p->size()<=2){ d_(sh_,err_show_buzu_,p); return 1; } switch(sdz){ case's': { SourceView* sv=NULL; char sdz1=0; const ustring& p1=(*p)[1]; if(p1=="撤销") sdz1='u'; else if(p1=="重做") sdz1='r'; else if(p1=="撤销不记始") sdz1='B'; else if(p1=="撤销不记终") sdz1='E'; else if(p1=="语法高亮") sdz1='h'; #ifdef ver_all_ else if(p1=="剪切") sdz1='x'; else if(p1=="复制") sdz1='c'; else if(p1=="粘贴") sdz1='v'; else if(p1=="已修改") sdz1='m'; else if(p1=="内容") sdz1=' '; else if(p1=="打开文件") sdz1='o'; else if(p1=="保存文件") sdz1='s'; else if(p1=="焦点") sdz1='.'; else if(p1=="不可编辑") sdz1='e'; else if(p1=="光标位置") sdz1='p'; else if(p1=="光标行列") sdz1='l'; else if(p1=="插入") return insert__(p,1); #endif else{ switch(sdz){ case's': { Gtk::ScrolledWindow* sw; sh_->builder_->get_widget((*p)[2], sw); if(!sw){ d_(sh_,err_show_wufa_,2,p,2); return 1; } sv=Gtk::manage(new SourceView()); sv->set_show_line_numbers(true); sv->set_auto_indent (true); sv->set_tab_width(4); //GTK_SOURCE_SMART_HOME_END_ALWAYS sv->set_smart_home_end((SourceSmartHomeEndType)2); sv->set_can_focus(true); names_[p1]=sv; sw->add(*sv); sw->show_all_children (); return 1; } } } sv=tv__(p,2); if(!sv) return 1; RefPtr < SourceBuffer > sb=sv->get_source_buffer(); switch(sdz1){ #ifdef ver_all_ case'x': case'c': case'v': { RefPtr<Gtk::Clipboard> cb = Gtk::Clipboard::get(); switch(sdz1){ case'x': sb->cut_clipboard(cb); break; case'c': sb->copy_clipboard(cb); break; case'v': sb->paste_clipboard(cb); break; } break; } case'm': if(p->size()>3){ const ustring&s=(*p)[3]; if(s=="侦听"){ control___* ctl=Gtk::manage(new control___(sh_,d_,(*p)[0],(*p)[2],p1)); if(p->size()>4) ctl->code__((*p)[4]); sb->signal_modified_changed().connect(sigc::mem_fun(*ctl,&control___::modified_changed__),false); }else sb->set_modified(d_(sh_,bool_,s.c_str())); }else l2s__(sb->get_modified(),buf); break; case' ': if(p->size()>3) sb->set_text((*p)[3]); else *addr_ret=dup__(sb->get_text().c_str()); break; case'o': if(p->size()>3){ ustring s; file_get__((*p)[3].c_str(),s); sb->set_text(s); } break; case's': if(p->size()>3){ GError *error = NULL; g_file_set_contents ((*p)[3].c_str(), sb->get_text().c_str(), -1, &error); if (error != NULL) { cpy__(buf,error->message,siz); g_clear_error(&error); } } break; case'.': sv->grab_focus(); break; case'e': if(p->size()>3) sv->set_editable(d_(sh_,bool_,(*p)[3].c_str())); else sv->set_editable(false); break; case'p': case'l': { Gtk::TextIter ti=sb->get_iter_at_mark(sb->get_mark("insert")); if(sdz1=='l'){ if(p->size()<=3) sprintf(buf,"%d,%d,",ti.get_line (),ti.get_line_offset ()); else{ int line_offset=ti.get_line_offset (); if(p->size()>3) ti.set_line (s2i_plus__((*p)[3],ti.get_line ())); if(p->size()>4) ti.set_line_offset (s2i_plus__((*p)[4],line_offset)); //sb->place_cursor(ti); scroll2__(sv,ti); } }else{ if(p->size()>3){ ti.set_offset (s2i_plus__((*p)[3],ti.get_offset ())); //sb->place_cursor(ti); scroll2__(sv,ti); }else l2s__(ti.get_offset (),buf); } break; } #endif case'u': if(sb->can_undo()) sb->undo(); break; case'r': if(sb->can_redo()) sb->redo(); break; case'B': sb->begin_not_undoable_action(); break; case'E': sb->end_not_undoable_action(); break; case'h': if(p->size()>3){ RefPtr<SourceLanguageManager> slm=SourceLanguageManager::get_default(); RefPtr<SourceLanguage> sl=slm->get_language((*p)[3]); if(sl){ sb->set_language(sl); sb->set_highlight_syntax(true); break; } } sb->set_highlight_syntax(false); break; } break; } } return 1; }
int textview___::proc__(std::deque<Glib::ustring>* p,char*buf,long siz,char**addr_ret,void*shangji) { char sdz=0; if((*p)[0]=="插入"){ if(siz==-1)return 1; sdz='i'; }else if((*p)[0]==name__()){ if(siz==-1)return 1; sdz='t'; }else return 0; if(p->size()<=2){ d_(sh_,err_show_buzu_,p); return 1; } switch(sdz){ case'i': return insert__(p,0); case't': { Gtk::TextView* tv; char sdz1=0; const Glib::ustring& p1=(*p)[1]; if(p1=="剪切") sdz1='x'; else if(p1=="复制") sdz1='c'; else if(p1=="粘贴") sdz1='v'; else if(p1=="已修改") sdz1='m'; else if(p1=="内容") sdz1=' '; else if(p1=="焦点") sdz1='.'; else if(p1=="不可编辑") sdz1='e'; else if(p1=="光标位置") sdz1='p'; else if(p1=="光标行列") sdz1='l'; else if(p1=="选择") sdz1='S'; else if(p1=="插入") return insert__(p,1); else{ switch(sdz){ case't': d_(sh_,err_show_buzhichi_,2,p,1); return 1; } } tv=tv__(p,2); if(!tv) return 1; Glib::RefPtr < Gtk::TextBuffer > tb = tv->get_buffer(); switch(sdz1){ case'x': case'c': case'v': { Glib::RefPtr<Gtk::Clipboard> cb = Gtk::Clipboard::get(); switch(sdz1){ case'x': tb->cut_clipboard(cb); break; case'c': tb->copy_clipboard(cb); break; case'v': tb->paste_clipboard(cb); break; } break; } case'm': if(p->size()>3){ const Glib::ustring&s=(*p)[3]; if(s=="侦听"){ control___* ctl=Gtk::manage(new control___(sh_,d_,(*p)[0],(*p)[2],p1)); if(p->size()>4) ctl->code__((*p)[4]); tb->signal_modified_changed().connect(sigc::mem_fun(*ctl,&control___::modified_changed__),false); }else tb->set_modified(d_(sh_,bool_,s.c_str())); }else l2s__(tb->get_modified(),buf); break; case' ': if(p->size()>3) tb->set_text((*p)[3]); else *addr_ret=dup__(tb->get_text().c_str()); break; case'.': tv->grab_focus(); break; case'e': if(p->size()>3) tv->set_editable(d_(sh_,bool_,(*p)[3].c_str())); else tv->set_editable(false); break; case'p': case'l': { Gtk::TextIter ti=tb->get_iter_at_mark(tb->get_mark("insert")); if(sdz1=='l'){ if(p->size()<=3) sprintf(buf,"%d,%d,",ti.get_line (),ti.get_line_offset ()); else{ int line_offset=ti.get_line_offset (); if(p->size()>3) ti.set_line (s2i_plus__((*p)[3],ti.get_line ())); if(p->size()>4) ti.set_line_offset (s2i_plus__((*p)[4],line_offset)); tb->place_cursor(ti); } }else{ if(p->size()>3){ ti.set_offset (s2i_plus__((*p)[3],ti.get_offset ())); tb->place_cursor(ti); }else l2s__(ti.get_offset (),buf); } break; } case'S': if(p->size()>4){ Gtk::TextIter ti1=tb->begin(),ti2=tb->begin(); ti1.set_offset(s2i__((*p)[3])); ti2.set_offset(s2i__((*p)[4])); tb->select_range(ti1,ti2); } break; } break; } } return 1; }
int main(int argc, char *argv[]) { biglist_t *entries = NULL; /** Basic Hashing -- statically allocated table */ bighash_table_init_static(&static_table); insert__(&static_table, 10000, &entries); test_table_data__(&static_table, &entries); bighash_table_destroy(&static_table, NULL); /** Basic hashing -- dynamically allocated table */ { bighash_table_t *dtable; dtable = bighash_table_create(64); insert__(dtable, 10000, &entries); test_table_data__(dtable, &entries); bighash_table_destroy(dtable, NULL); } /** Count and removal while iterating */ { bighash_table_t *table; bighash_iter_t iter; bighash_entry_t *e; test_entry_t *te; int ecount=100; int count = 0; table = bighash_table_create(64); insert__(table, ecount, NULL); if(bighash_entry_count(table) != ecount) { AIM_DIE("Entry count mismatch: expected %d, got %d", ecount, bighash_entry_count(table)); } /* Iterate once, just counting */ for(te = (test_entry_t*)bighash_iter_start(table, &iter); te; te = (test_entry_t*)bighash_iter_next(&iter)) { count++; } if(count != ecount) { AIM_DIE("Iteration count incorrect (%d)", count); } /* Iterate again, removing elements. Tests both iteration restart * and remove-while-iterating. */ for(e = bighash_iter_start(table, &iter); e; e = bighash_iter_next(&iter)) { test_entry_t *te = container_of(e, hash_entry, test_entry_t); bighash_remove(table, &te->hash_entry); /* Clear the list links on this element to make sure the * removal was done properly. */ memset(te, 0, sizeof(*te)); aim_free(te); } if(bighash_entry_count(table) != 0) { AIM_DIE("Count is not zero after iterated removal (count=%d)", bighash_entry_count(table)); } bighash_table_destroy(table, NULL); } /** Migrating between tables */ { bighash_table_t *src; bighash_table_t *dst; src = bighash_table_create(64); dst = bighash_table_create(128); insert__(src, 1000, &entries); bighash_entries_move(dst, src); if(bighash_entry_count(src) != 0) { AIM_DIE("Source table is not empty."); } bighash_table_destroy(src, NULL); test_table_data__(dst, &entries); bighash_table_destroy(dst, NULL); } /** Check utilization and automatic element destruction */ bighash_table_init_static(&static_table); insert__(&static_table, 100000, 0); bighash_table_utilization_show(&static_table, &aim_pvs_stdout); bighash_table_destroy(&static_table, free_test_entry); test_template(); return 0; }