void hash_interface(){ int end = 0, unit = 100; char input, string[MAX_LINE_LENGTH]; while(!end){ if(PPRINT){ printf("\n \033[1;31mHash Table commands:\033[0m \n %3s \t %s \n %3s \t %s \n %3s \t %s \n %3s \t %s \n %3s \t %s \n \n: ", "\033[1;32mh\033[0m", "calculate the hash of a string", "\033[1;32ml\033[0m", "print the load factor of the authors' hash table", "\033[1;32md\033[0m", "print a histogram of the collisions in the hash table", "\033[1;32mc\033[0m", "print the number of keys in the hash table", "\033[1;32mq\033[0m", "return to main menu"); } else{ printf("\n Hash Table commands: \n %3s \t %s \n %3s \t %s \n %3s \t %s \n %3s \t %s \n %3s \t %s \n \n: ", "h", "calculate the hash of a string", "l", "print the load factor of the authors' hash table", "d", "print a histogram of the collisions in the hash table", "c", "print the number of authors in the hash table", "q", "return to main menu"); } scanf(" %c", &input); switch (input) { case 'h': printf("string to hash: "); flush_input_buffer(); fgets(string, MAX_LINE_LENGTH, stdin); printf("\n %ld\n", hashf(string, AUTHORS_HASH_DIM)); break; case 'l' : printf("load factor: %f", (float)authors_dict->n_keys / (float) authors_dict->modulo); break; case 'd': printf("set the number of authors a dot in the histogram corresponds to (default %d): ", unit); flush_input_buffer(); fgets(string, MAX_LINE_LENGTH, stdin); if(strcmp(string, "\n") != 0) unit = atoi(string); print_hash_histogram(authors_dict, unit); break; case 'c': printf("\n %d keys \n", authors_dict->n_keys); break; case 'q': end = 1; break; } } }
void speech_stream::flush() { if(!sonic_stream) return; flush_input_buffer(); sonicFlushStream(sonic_stream); }
void wordwrap_wrap_z_ucs(WORDWRAP *wrapper, z_ucs *input) { size_t len, chars_to_copy, space_in_buffer; len = z_ucs_len(input); while (len > 0) { space_in_buffer = wrapper->input_buffer_size - 1 - wrapper->input_index; chars_to_copy = len > space_in_buffer ? space_in_buffer : len; TRACE_LOG("chars_to_copy: %d, len:%d, space_in_buffer:%d.\n", chars_to_copy, len, space_in_buffer); z_ucs_ncpy( wrapper->input_buffer + wrapper->input_index, input, chars_to_copy); wrapper->input_index += chars_to_copy; wrapper->input_buffer[wrapper->input_index] = 0; input += chars_to_copy; len -= chars_to_copy; TRACE_LOG("chars copied: %d, chars left: %ld.\n",chars_to_copy,(long)len); if ( (wrapper->input_index == wrapper->input_buffer_size - 1) || ( (wrapper->flush_after_newline == true) && ( (wrapper->input_index + wrapper->chars_already_on_line > wrapper->line_length) || (z_ucs_chr(wrapper->input_buffer, Z_UCS_NEWLINE) != NULL) ) ) ) { flush_input_buffer(wrapper, false); //FIXME: Increase buffer size in case flush not possible. } } }
void speech_stream::write(short sample) { if(offset<start_offset) { ++offset; return; } samples.push_back(sample); ++offset; if(!sonic_stream) return; if(samples.size()<buffer_size) return; flush_input_buffer(); }
bool speech_stream::read(speech_stream::buffer_type& buffer,int min_size) { if(sonic_stream) { if(min_size==0) flush_input_buffer(); int nsamples=sonicSamplesAvailable(sonic_stream); if((nsamples==0)||(nsamples<min_size)) return false; buffer.resize(nsamples,0); sonicReadShortFromStream(sonic_stream,&buffer[0],nsamples); } else { if(samples.empty()||(samples.size()<min_size)) return false; buffer=samples; samples.clear(); } return true; }
void wordwrap_flush_output(WORDWRAP *wrapper) { flush_input_buffer(wrapper, true); }
void graph_interface(){ char input, string[MAX_LINE_LENGTH]; list_node * ln; int end=0, i, min_weight = 1, bfs_depth, min_nodes = 0; clusters * clst; clst = NULL; while(!end){ if(PPRINT){ printf("\n \033[1;31mGraph commands:\033[0m \n %3s \t %s \n %3s \t %s \n %3s \t %s \n %3s \t %s \n %3s \t %s \n %3s \t %s \n %3s \t %s \n %3s \t %s \n %3s \t %s \n %3s \t %s \n %3s \t %s \n \n: ", "\033[1;32ma\033[0m", "print an author and its articles", "\033[1;32mA\033[0m", "print an article and its authors", "\033[1;32mn\033[0m", "print an article and its neighbors in the article graph", "\033[1;32mc\033[0m", "print the article count (number of nodes in graph)", "\033[1;32mt\033[0m", "print the graph total edges", "\033[1;32mm\033[0m", "print the graph nodes' medium edges", "\033[1;32mM\033[0m", "print the graph nodes' max_edges", "\033[1;32mw\033[0m", "print the edge mean weight", "\033[1;32mC\033[0m", "calculate clusters", "\033[1;32mr\033[0m", "print representatives from last calculated clusters", "\033[1;32mq\033[0m", "return to main menu"); } else{ printf("\n Graph commands: \n %3s \t %s \n %3s \t %s \n %3s \t %s \n %3s \t %s \n %3s \t %s \n %3s \t %s \n %3s \t %s \n %3s \t %s \n %3s \t %s \n %3s \t %s \n %3s \t %s \n \n: ", "a", "print an author and its articles", "A", "print an article and its authors", "n", "print an article and its neighbors in the article graph", "c", "print the article count (number of nodes in graph)", "t", "print the graph total edges", "m", "print the graph nodes' medium edges", "M", "print the graph nodes' max_edges", "w", "print the edge mean weight", "C", "calculate clusters", "r", "print representatives from last calculated clusters", "q", "return to main menu"); } scanf(" %c", &input); switch(input) { case 'a': printf("\n Author Name: "); flush_input_buffer(); fgets(string, MAX_LINE_LENGTH, stdin); remove_ending_newline(string); ln = search_in_hash(string, authors_dict); if(ln == NULL) printf("\n sorry, author not present \n"); else author_print((author *) ln->key); break; case 'A': printf("\n Article Id: "); flush_input_buffer(); scanf("%d", &i); print_article_node(artcl_graph->nodes[i]); break; case 'n': printf("\n Article Id: "); flush_input_buffer(); scanf("%d", &i); printf("\n Minimum edge weight: "); flush_input_buffer(); scanf("%d", &min_weight); printf("\n Depth of search: "); flush_input_buffer(); scanf("%d", &bfs_depth); print_neighbours(artcl_graph->nodes[i], bfs_depth, min_weight); break; case 'c': printf("\n %d Articles", artcl_graph->n_nodes); break; case 't': printf("\n %d edges in the article graph", total_edges(artcl_graph)); break; case 'm': printf("\n Articles in the graph have %f edges in mean", mean_edges(artcl_graph)); break; case 'M': printf("\n The article with the biggest number of edges is:"); print_article_node(max_edges(artcl_graph)); break; case 'w': printf("\n The mean edge weight is: %f", mean_edge_weight(artcl_graph)); break; case 'C': printf("\n Minimum edge weight: "); flush_input_buffer(); scanf("%d", &min_weight); if(clst != NULL){ free(clst->representatives); free(clst->nodes_in_cluster); free(clst); } clst = find_clusters(artcl_graph, min_weight); printf("\n %d clusters found", clst->n_rpr); break; case 'r': printf("\n Minimum nodes in cluster: "); flush_input_buffer(); scanf("%d", &min_nodes); if(clst != NULL){ for(i=0;i<clst->n_rpr;++i){ if(clst->nodes_in_cluster[i]>= min_nodes){ if(PPRINT) printf("\n \033[1;32mCluster %d has %d nodes. Representative:\033[0m", i, clst->nodes_in_cluster[i]); else printf("\n Cluster %d has %d nodes. Representative:", i, clst->nodes_in_cluster[i]); print_article_node(clst->representatives[i]); } } } break; case 'q': end=1; break; } } }
//end interface routine void main() { unsigned char temp; unsigned char sid;//id of serial to send long i=1000; IE = 0;//close int sjSerialInit(); //set serial port parameter (clock 11.0592M) //9600 baut rate 8 data non parity and 1 stop. SCON = 0x70; PCON = 0x00; //timer count TH1 = 0xfd; //use timer 1 to be serial //use timer 0 to be analog I/O TMOD = 0x22; TR1 = 1; init_uart(); turn_rx_on();//enable I/O serial flush_input_buffer(); IE = 0x92;//enable serial int and timer0 interrupt//IE=90 sid = 0; asp_tx = 1;//set the asp_tx to be output pin if(asp_rx);//set the asp_rx to be input pin // sjSerialSendByte('?'); swiReset(); /* * Protocal routine: * 1. HMARK sid(!=HMARK) :set sid * 2. normal HMARK is repeated */ swiDelay(0x0f,0xff); while(1) { if(sjSerialIsDataWaiting()) { temp = sjSerialWaitForOneByte(); if(temp == HMARK) { temp = sjSerialWaitForOneByte(); if(temp != HMARK) { sid = temp; continue; } } if(sid == 's')//send to switch { if(temp == HMARK) { while(1) { temp = sjSerialWaitForOneByte(); if(temp == EMARK) break; if(temp == RMARK) { swiReset(); continue; } if(temp == QMARK) continue; swiAction(temp); } sjSerialSendByte(HMARK); temp = P2; sjSerialSendByte(temp); temp = P3; /* temp = 0; if(P3^4) temp |= (0x10); if(P3^5) temp |= (0x20); */ sjSerialSendByte(temp); sjSerialSendByte(EMARK); } } if(sid == 'n')//send to navmeter { ioputchar(temp); } if(sid == 't') { P0=sjSerialWaitForOneByte(); P1=sjSerialWaitForOneByte(); sjSerialSendByte(EMARK); } } if(kbhit()) { temp = iogetchar(); sjSerialSendByte(temp); } } }