int main(int argc, char* argv[]) { read_input(stdin, mybuf, sizeof(mybuf)); echo_input(mybuf); return 0; }
/* * Read a line of text from standard input, possibly echoing it. * Up to the 1st 'max' characters are transfereed to the 'buf', * and properly NUL terminated. * Extra characters at the end of the line are simply ignored. */ static bool read_line(char buf[], int max) { int ch ; int i = 0 ; for(ch = getchar(); ch != EOF && ch != '\n'; ch = getchar()) { if(echo_input()) { putchar(ch); } if(i < max) { buf[i++] = ch; } } if(echo_input() && ch == '\n') { putchar(ch) ; } buf[i] = '\0'; /* NULL terminating the string */ }
main() { int i; read_input(); echo_input(); quicksort(0,c-1); for (i=0; i < c; i++ ) { printf ( "%d\n", input[i]); } }
static void tintin(void) { int i, result, maxfd; struct timeval tv; fd_set readfdmask; #ifdef XTERM_TITLE struct session *lastsession=0; #endif char kbdbuf[BUFFER_SIZE]; WC ch; int inbuf=0; mbstate_t instate; memset(&instate, 0, sizeof(instate)); for (;;) { #ifdef XTERM_TITLE if (ui_own_output && activesession!=lastsession) { lastsession=activesession; if (activesession==nullsession) user_title(XTERM_TITLE, "(no session)"); else user_title(XTERM_TITLE, activesession->name); } #endif tv.tv_sec = check_events(); tv.tv_usec = 0; maxfd=0; FD_ZERO(&readfdmask); if (!eofinput) FD_SET(0, &readfdmask); else if (activesession==nullsession) end_command(0, activesession); for (struct session *ses = sessionlist; ses; ses = ses->next) { if (ses==nullsession) continue; if (ses->nagle) flush_socket(ses); FD_SET(ses->socket, &readfdmask); if (ses->socket>maxfd) maxfd=ses->socket; } result = select(maxfd+1, &readfdmask, 0, 0, &tv); if (need_resize) { char buf[BUFFER_SIZE]; user_resize(); sprintf(buf, "#NEW SCREEN SIZE: %dx%d.", COLS, LINES); tintin_puts1(buf, activesession); } if (result == 0) continue; else if (result < 0 && errno == EINTR) continue; /* Interrupted system call */ else if (result < 0) syserr("select"); if (FD_ISSET(0, &readfdmask)) { PROFSTART; PROFPUSH("user interface"); result=read(0, kbdbuf+inbuf, BUFFER_SIZE-inbuf); if (result==-1) myquitsig(0); if (result==0 && !isatty(0)) eofinput=true; inbuf+=result; i=0; while (i<inbuf) { result=mbrtowc(&ch, kbdbuf+i, inbuf-i, &instate); if (result==-2) /* incomplete but valid sequence */ { memmove(kbdbuf, kbdbuf+i, inbuf-i); inbuf-=i; goto partial; } else if (result==-1) /* invalid sequence */ { ch=0xFFFD; i++; errno=0; /* Shift by 1 byte. We can use a more intelligent shift, * but staying charset-agnostic makes the code simpler. */ } else if (result==0) /* literal 0 */ i++; /* oops... bad ISO/ANSI, bad */ else i+=result; if (user_process_kbd(activesession, ch)) { hist_num=-1; if (term_echoing || (got_more_kludge && done_input[0])) /* got_more_kludge: echo any non-empty line */ { if (activesession && *done_input) if (strcmp(done_input, prev_command)) do_history(done_input, activesession); if (activesession->echo) echo_input(done_input); if (activesession->logfile) write_logf(activesession, done_input, activesession->loginputprefix, activesession->loginputsuffix); } if (*done_input) strcpy(prev_command, done_input); aborting=false; activesession = parse_input(done_input, false, activesession); recursion=0; } } inbuf=0; partial: PROFEND(kbd_lag, kbd_cnt); PROFPOP; } for (struct session *ses = sessionlist; ses; ses = ses->next) { if (ses->socket && FD_ISSET(ses->socket, &readfdmask)) { aborting=false; any_closed=false; do { read_mud(ses); if (any_closed) { any_closed=false; goto after_read; /* The remaining sessions will be done after select() */ } #ifdef HAVE_ZLIB } while (ses->mccp_more); #else } while (0); #endif } } after_read: if (activesession->server_echo && (2-activesession->server_echo != gotpassword)) { gotpassword= 2-activesession->server_echo; if (!gotpassword) got_more_kludge=false; user_passwd(gotpassword && !got_more_kludge); term_echoing=!gotpassword; } }
void try_pack(INP struct s_packer_opts *packer_opts, INP const t_arch * arch, INP t_model *user_models, INP t_model *library_models) { boolean *is_clock; int num_models; t_model *cur_model; printf("Begin packing of %s \n", packer_opts->blif_file_name); /* determine number of models in the architecture */ num_models = 0; cur_model = user_models; while(cur_model) { num_models++; cur_model = cur_model->next; } cur_model = library_models; while(cur_model) { num_models++; cur_model = cur_model->next; } /* begin parsing blif input file */ read_blif (packer_opts->blif_file_name, packer_opts->sweep_hanging_nets_and_inputs, user_models, library_models); /* TODO: Do check blif here eg. for(i = 0; i < num_logical_blocks; i++) { if(logical_block[i].model->num_inputs > max_subblock_inputs) { printf(ERRTAG "logical_block %s of model %s has %d inputs but architecture only supports subblocks up to %d inputs\n", logical_block[i].name, logical_block[i].model->name, logical_block[i].model->num_inputs, max_subblock_inputs); exit(1); } } */ #ifdef DUMP_BLIF_INPUT echo_input (packer_opts->blif_file_name, "blif_input.echo", library_models); #endif absorb_buffer_luts (); compress_netlist (); /* remove unused inputs */ /* NB: It's important to mark clocks and such *after* compressing the * * netlist because the vpack_net numbers, etc. may be changed by removing * * unused inputs . */ is_clock = alloc_and_load_is_clock (packer_opts->global_clocks); printf("\nAfter removing unused inputs:\n"); printf("Total Blocks: %d. Total Nets: %d. Total inputs %d ouptuts %d\n", num_logical_blocks, num_logical_nets, num_p_inputs, num_p_outputs); /* Uncomment line below if you want a dump of compressed netlist. */ /* echo_input (packer_opts->blif_file_name, packer_opts->lut_size, "packed.echo"); */ if (packer_opts->skip_clustering == FALSE) { do_clustering (arch, num_models, packer_opts->global_clocks, is_clock, packer_opts->hill_climbing_flag, packer_opts->output_file, packer_opts->timing_driven, packer_opts->cluster_seed_type, packer_opts->alpha, packer_opts->beta, packer_opts->recompute_timing_after, packer_opts->block_delay, packer_opts->intra_cluster_net_delay, packer_opts->inter_cluster_net_delay, packer_opts->aspect, packer_opts->allow_unrelated_clustering, packer_opts->allow_early_exit, packer_opts->connection_driven, packer_opts->packer_algorithm, packer_opts->hack_no_legal_frac_lut, packer_opts->hack_safe_latch); } else { printf("Skip clustering not supported\n"); exit(1); } free (is_clock); saved_logical_blocks = logical_block; logical_block = NULL; num_saved_logical_blocks = num_logical_blocks; saved_logical_nets = vpack_net; vpack_net = NULL; num_saved_logical_nets = num_logical_nets; /* Todo: Use this for error checking */ printf("\nNetlist conversion complete.\n\n"); }