char *ft_readline(char *prompt, t_hist *hist, int settings) { t_rl rl; char *line; if (rl_init(&rl, hist, settings, prompt) < 0) return (NULL); cur_cwrite(rl.prompt, rl.promptsize, ft_strlen(rl.prompt)); if (readline_loop(&rl) < 0) return (NULL); line = NULL; if (ISIN(rl.bitset, RL_BS_FLUSH) && rl.dyn.used) { line = ft_strjoin(rl.dyn.str, rl.dyn.strend - rl.dyn.post); if (ISIN(settings, RL_HISTORY)) { if (!(hist->cursor = ft_dlstnew(line, rl.dyn.used + 1))) ft_memdel((void **)&line); else ft_dlstaddn(&hist->list, hist->cursor); } } rl_destroy(&rl); write(1, "\n", 1); return (line); }
char *ft_readline(char *prompt, int settings) { t_rl rl; char *line; int code; ft_initcap(); if (rl_init(&rl, settings, prompt) < 0) return (NULL); write(1, prompt, rl.promptsize); while (!ISIN(rl.bitset, RL_BS_FLUSH)) { dumpdyn(rl.dyn); if (!(code = rl_read())) continue ; if (rl_maj(&rl, code) < 0) { rl_destroy(&rl); return (NULL); } } line = ft_strjoin(rl.dyn.str, rl.dyn.strend - rl.dyn.post); rl_destroy(&rl); return (line); }
char *ft_readline(char *prompt, t_hist *hist, int settings) { t_rl rl; char *line; if (rl_init(&rl, hist, settings, prompt) < 0) //Init readline return (NULL); cur_cwrite(rl.prompt, rl.promptsize, ft_strlen(rl.prompt)); //Cwrite the prompt if (readline_loop(&rl) < 0) //Launch the main readline loop until \n, \0 or error occured return (NULL); line = NULL; if (ISIN(rl.bitset, RL_BS_FLUSH) && rl.dyn.used) { line = ft_strjoin(rl.dyn.str, rl.dyn.strend - rl.dyn.post); //Get the line wth the concatenate of the ante cursor buffer and the post cursor buffer if (ISIN(settings, RL_HISTORY)) { if (!(hist->cursor = ft_dlstnew(line, rl.dyn.used + 1))) ft_memdel((void **)&line); else ft_dlstaddn(&hist->list, hist->cursor); //If history handled, add this new entry to it } } rl_destroy(&rl); write(1, "\n", 1); return (line); }
main() { int error = 0; if(!rl_init(">> ", 1024, 100)) exit(0); printf("notty=%d\n", notty); while(1) printf("command=(%s)\n", rl_getline(&error)); }
/*===========================================================================* * main * *===========================================================================*/ int main(int argc, char *argv[]) { int r; int ipc_status; /* SEF local startup. */ env_setargs(argc, argv); sef_local_startup(); while (TRUE) { if ((r = netdriver_receive(ANY, &m, &ipc_status)) != OK) panic("netdriver_receive failed: %d", r); if (is_ipc_notify(ipc_status)) { switch (_ENDPOINT_P(m.m_source)) { case CLOCK: /* * Under MINIX, synchronous alarms are used * instead of watchdog functions. * The approach is very different: MINIX VMD * timeouts are handled within the kernel * (the watchdog is executed by CLOCK), and * notify() the driver in some cases. MINIX * timeouts result in a SYN_ALARM message to * the driver and thus are handled where they * should be handled. Locally, watchdog * functions are used again. */ rl_watchdog_f(NULL); break; case HARDWARE: do_hard_int(); if (int_event_check) { check_int_events(); } break ; default: panic("illegal notify from: %d", m.m_type); } /* done, get nwe message */ continue; } switch (m.m_type) { case DL_WRITEV_S: rl_writev_s(&m, FALSE); break; case DL_READV_S: rl_readv_s(&m, FALSE); break; case DL_CONF: rl_init(&m); break; case DL_GETSTAT_S: rl_getstat_s(&m); break; default: panic("illegal message: %d", m.m_type); } } }
int main (int argc, char **argv) { rl_init (); setuptrap(); mngr_start (); main_loop (); mngr_shutdown (); rl_shutdown (); return 0; }
int main(int argc, char **argv) { rl_init(); my_pid = getpid(); printf("my pid: %ld\n", my_pid); if (0 == bridge_start()) { main_loop(); } bridge_shutdown(); rl_shutdown(); return 0; }
int main (int argc, char **argv) { toptions *opt; tsequence *seq; treadseq *rs = NULL; ttokenizer *tokenizer = NULL; char *command; opt = (toptions *) calloc(1,sizeof(toptions)); init_defaults(opt); process_args(opt, 0, argc, argv); if (!opt->terminate) { if (optind < argc) rs = readseq_open(READSEQ_STRING, argv[optind]); else if (opt->inputfile) rs = readseq_open(READSEQ_FILE, opt->inputfile); else if (!isatty(fileno(stdin))) rs = readseq_open(READSEQ_STDIN, NULL); else { printf("Interactive mode. Try `./RNAfold -h` for more information.\n", argv[0]); rl_init(); opt->interactive = 1; opt->colored_output = 1 - opt->colored_output; tokenizer = tokenizer_new(); rs = readseq_open(READSEQ_STRING, ""); } while (1) { if (opt->interactive) { if (opt->colored_output) printf("%s\nInput sequence (upper or lower case); :q to quit, -h for help.\n....,....1....,....2....,....3....,....4....,....5....,....6....,....7....,....8\n%s",COLOR_RED,COLOR_DEFAULT); else printf("\nInput sequence (upper or lower case); :q to quit, -h for help.\n....,....1....,....2....,....3....,....4....,....5....,....6....,....7....,....8\n"); command = rl_gets(); if (!command || (command[0] == '@') || ((command[0] == ':') && (command[1] == 'q'))) { pcolor(opt->colored_output,COLOR_BLUE); printf("Leaving RNAfold."); pcolor(opt->colored_output,COLOR_DEFAULT); printf("\n"); exit(0); } else if (command[0] == ':') { pcolor(opt->colored_output,COLOR_BLUE); if (command[1] == 's') print_settings(opt); if (command[1] == 'd') { init_defaults(opt); opt->colored_output = 1; opt->interactive = 1; printf("Activated default configuration.\n"); pcolor(opt->colored_output,COLOR_DEFAULT); } if (command[1] == 'e') { system(command + 2); } if (command[1] == 'r') { system("make update"); system("./RNAfold"); exit(0); } } else if (command[0] == '-') { tokenizer_exec(tokenizer, argv[0], command); process_args(opt, 1, tokenizer->count, tokenizer->token); if (opt->inputfile) { rs = readseq_free(rs); rs = readseq_open(READSEQ_FILE, opt->inputfile); } free(opt->inputfile); opt->inputfile = NULL; } else { rs = readseq_free(rs); rs = readseq_open(READSEQ_STRING, command); } } while (1) { seq = readseq_next_fasta(rs); if (!(seq->success)) break; if (1) { main_rnafold_mfe(opt, seq); } sequence_free(seq); } if (!opt->interactive) break; } } exit(0); }