/* Display registers window */ GtkWidget* dbgregs_create_window(void) { GladeXML *xml = NULL; GtkWidget *dbox; GtkWidget *data; xml = glade_xml_new (tilp_paths_build_glade("dbg_regs-2.glade"), "dbgregs_window", PACKAGE); if (!xml) g_error(_("%s: GUI loading failed !\n"), __FILE__); glade_xml_signal_autoconnect(xml); dbox = glade_xml_get_widget(xml, "dbgregs_window"); if(options3.transient) gtk_window_set_transient_for(GTK_WINDOW(dbox), GTK_WINDOW(main_wnd)); data = glade_xml_get_widget(xml, "treeview1"); store = ctree_create(data); ctree_populate(store); gtk_tree_view_expand_all(GTK_TREE_VIEW(data)); return dbox; }
gint dbgentry_display_dbox(void) { GladeXML *xml; GtkWidget *dbox; GtkWidget *data; gint result; xml = glade_xml_new (tilp_paths_build_glade("dbg_entry-2.glade"), "dbgentry_dbox", PACKAGE); if (!xml) g_error(_("%s: GUI loading failed!\n"), __FILE__); glade_xml_signal_autoconnect(xml); dbox = glade_xml_get_widget(xml, "dbgentry_dbox"); //gtk_window_resize(GTK_WINDOW(dbox), 320, 240); data = glade_xml_get_widget(xml, "treeview1"); ctree_create(data); ctree_populate(data); result = gtk_dialog_run(GTK_DIALOG(dbox)); switch (result) { case GTK_RESPONSE_OK: ctree_get_selection(); dbgbkpts_refresh_window(); break; default: break; } gtk_widget_destroy(dbox); return 0; }
int main(int argc, char **argv) { uint8_t codelen[128]; struct Histogram32 h32; struct Codebook cb; struct Encoder enc; struct Tree tree; FILE *fout; int i,L; if(argc == 1) L = 16; //else if(argv == 2) L = atoi(argv[1]); else { fprintf(stderr,"Usage: %s\n", argv[0]); fprintf(stderr,"\treads input data from stdin, compresses it using\n"); fprintf(stderr,"\tlength-restricted canonical huffman codes and writes\n"); fprintf(stderr,"\tthe result to 'enc.out'.\n"); exit(1); } read_text(stdin); histogram32_init(&h32); histogram32_add(&h32, buffer, buffer_fill); package_merge(&h32, L, codelen); //printf("final codelengths:\n"); //codelen_dump(codelen, stdout); fprintf(stderr,"weight of huffman tree = %f\n", weight_of_tree(codelen)); fprintf(stderr,"compression factor = %.11f\n",compr_factor(buffer,buffer_fill,codelen)); ctree_create(&tree, codelen); //tree_print_flat(&tree,stderr); //ccodebook_create(&cb, codelen); codebook_create(&cb,&tree); //codebook_print(&cb,stderr); encoder_init(&enc, &cb); fout = fopen("enc.out","w"); fwrite(&buffer_fill,4,1,fout); fwrite(codelen,128,1,fout); for(i = 0; i < buffer_fill; i++) { int c; //fprintf(stderr,"byte %d of %d\n",i,buffer_fill); encoder_put_symbol(&enc, buffer[i]); while((c = encoder_get_byte(&enc)) != ENCODER_NEED_INPUT) { uint8_t tmp = c; fwrite(&tmp,1,1,fout); } } i = encoder_get_last_byte(&enc); if(i != ENCODER_NEED_INPUT) { uint8_t tmp = i; fwrite(&tmp,1,1,fout); } fclose(fout); return 0; }
static void encode(int sock) { struct Histogram16 h16; struct Tree tree; struct Codebook cb; struct Encoder encoder; uint8_t codelen[128]; mqd_t mq_histogram_in, mq_histogram_out; unsigned char *recv_buffer; unsigned char send_buffer[SEND_BUFFER_SIZE + 1]; int send_len = 0; // number of bytes in send buffer int send_total = 0; int i; int b; int error; int32_t sym_count = 0; // allocate memory for the receive buffer recv_buffer = malloc(RECV_BUFFER_SIZE + 1); if(!recv_buffer){ fprintf(stderr,"could not allocate buffer (%d bytes)\n", RECV_BUFFER_SIZE); return; } // receive input text sym_count = recv(sock, recv_buffer, RECV_BUFFER_SIZE + 1, MSG_WAITALL); if(sym_count <= 0){ perror("recv"); free(recv_buffer); return; } if(sym_count == RECV_BUFFER_SIZE + 1){ fprintf(stderr,"buffer overflow! do not send more than %d bytes per connection\n", RECV_BUFFER_SIZE); free(recv_buffer); return; } printf("#symbols = %d\n", sym_count); // build the histogram // this is done in a separate thread, so we first create the thread // and then open two message queues for communication printf("creating histogram...\n"); build_histogram_thread_create(); mq_histogram_in = mq_open("/mq_build_histogram_in",O_RDWR); if(mq_histogram_in == (mqd_t)(-1)){ perror("could not open /mq_build_histogram_in"); exit(1); } mq_histogram_out = mq_open("/mq_build_histogram_out",O_RDWR); if(mq_histogram_out == (mqd_t)(-1)){ perror("could not open /mq_build_histogram_out"); exit(1); } // send the number of blocks to the build_histogram thread i = sym_count/BLOCK_SIZE_MAX; if(sym_count % BLOCK_SIZE_MAX > 0) i++; error = mq_send( mq_histogram_in, (char*)&i, 4, 0); if(error){ perror("mq_send: /mq_build_histogram_input (1)"); } // send the input text block by block for(i = 0; i < sym_count; i += BLOCK_SIZE_MAX) { int len = sym_count - i; if(len > BLOCK_SIZE_MAX) len = BLOCK_SIZE_MAX; error = mq_send( mq_histogram_in, (char*)(recv_buffer + i), len, 0); if(error){ perror("mq_send: /mq_build_histogram_input (2)"); } } // receive the histogram i = mq_receive(mq_histogram_out, (char*)&h16, BLOCK_SIZE_MAX, NULL); assert(i == sizeof h16); // send the number of symbols and the histogram to the network connection printf("sending histogram...\n"); if(send(sock, &sym_count, 4, 0) != 4){ perror("send (1)"); free(recv_buffer); return; } printf("using package-merge to create codelengths...\n"); package_merge2(&h16,16,codelen); send_total = send(sock, codelen, 128, 0); if(send_total != 128){ perror("send (2)"); free(recv_buffer); return; } printf("creating tree...\n"); ctree_create(&tree, codelen); printf("creating codebook...\n"); codebook_create(&cb,&tree); printf("initializing encoder...\n"); encoder_init(&encoder,&cb); printf("encoding...\n"); // encode the input text symbol by symbol and send the code // to the network connection for(i = 0; i < sym_count; i++){ encoder_put_symbol(&encoder,recv_buffer[i]); while((b = encoder_get_byte(&encoder)) != ENCODER_NEED_INPUT){ send_buffer[send_len++] = b; if(send_len >= SEND_BUFFER_SIZE){ int res = send(sock, send_buffer, send_len, 0); if(res == -1){ perror("send"); free(recv_buffer); return; } send_total += send_len; send_len = 0; } } } b = encoder_get_last_byte(&encoder); if(b != ENCODER_NEED_INPUT){ send_buffer[send_len++] = b; } if(send_len > 0){ int res = send(sock, &send_buffer, send_len, 0); if(res == -1){ perror("send"); free(recv_buffer); return; } } free(recv_buffer); printf("encoding done\n\n"); }