/* * this needs to be called before initedit() */ void inithist() { if (!histc) { histc = history_init(); /* init the builtin history */ history(histc, &ev, H_SETSIZE, 100); /* remember 100 events */ } if (!histi) { histi = history_init(); history(histi, &ev, H_SETSIZE, 100); } }
/** * Add an entry with text `text` to the history list, with type `type` * ("HIST_xxx" in player-history.h), and artifact number `id` (0 for * everything else). * * Return true on success. */ bool history_add_full(struct player *p, bitflag *type, int aidx, int dlev, int clev, int turnno, const char *text) { struct player_history *h = &p->hist; /* Allocate or expand the history list if needed */ if (!h->entries) history_init(h); else if (h->next == h->length) history_realloc(h); /* Add entry */ hist_copy(h->entries[h->next].type, type); h->entries[h->next].dlev = dlev; h->entries[h->next].clev = clev; h->entries[h->next].a_idx = aidx; h->entries[h->next].turn = turnno; my_strcpy(h->entries[h->next].event, text, sizeof(h->entries[h->next].event)); h->next++; return true; }
int main() { int i; Complex cx; History hist; complex_init(&cx); history_init(&hist); srand(time(0)); read_asc(&cx, stdin); complex_compute_free_faces(&cx); printf("checking "); printf("%s", cx.serialized); printf("\n"); complex_print(&cx); fflush(stdout); for (i = 0; i < 100000; ++i) { if (!(i % 1000)) printf("%d\n", i); if (complex_collapse_random(&cx, &hist)) { printf("collapsed! yay!\n"); history_print(&hist); return 0; } } history_destroy(&hist); return 0; }
int main(int argc, char *argv[], char *envp[]) { char buff[BUFSIZ]; int rc; signal(SIGTTOU, SIG_IGN); signal(SIGINT, sigint_handler); rc = setpgid(0, 0); assert(rc != -1); builtin_init(); history_init(); job_init(); print_prompt(); while (fgets(buff, BUFSIZ, stdin)) { job_run_command(buff, envp); job_wait(); print_prompt(); } job_finalize(); history_finalize(); builtin_finalize(); return 0; }
void initialize_libedit(const char *prog) { /* Init the builtin history */ hist = history_init(); /* Remember 100 events */ #ifdef XDC_OLD_LIBEDIT history(hist, XDC_H_SETSIZE, 100); #else history(hist, &ev, XDC_H_SETSIZE, 100); #endif /* Initialize editline */ #ifdef XDC_OLD_LIBEDIT el = el_init(prog, stdin, stdout); #else el = el_init(prog, stdin, stdout, stderr); #endif el_set(el, EL_EDITOR, "emacs"); /* Default editor is emacs */ el_set(el, EL_SIGNAL, 1); /* Handle signals gracefully */ el_set(el, EL_PROMPT, get_prompt); /* Set the prompt function */ /* Tell editline to use this history interface */ el_set(el, EL_HIST, history, hist); /* * Source the user's defaults file. */ /* el_source(el, "xdebug"); */ }
void * cmdinit(struct c**t *cmds, int ncmds) { struct clitenv *env; HistEvent ev; if ((env = malloc(sizeof(*env))) == NULL) err(1, "Can't init cmd interpreter."); env->cmds = cmds; env->ncmds = ncmds; env->hist = history_init(); history(env->hist, &ev, H_SETSIZE, 100); env->el = el_init(__progname, stdin, stdout, stderr); el_set(env->el, EL_EDITOR, "emacs"); el_set(env->el, EL_PROMPT, prompt); el_set(env->el, EL_HIST, history, env->hist); el_set(env->el, EL_ADDFN, "complt", "complete", complt); el_set(env->el, EL_BIND, "\t", "complt"); el_source(env->el, NULL); /* XXX - EL_SIGNAL ? */ return env; }
int main(void) { int result = 0; printf("BIG_INT calculator version %s\n", CALC_VERSION); printf("Created by valyala ([email protected]) http://valyala.narod.ru\n"); printf("Size of word is %zu bits\n", BIG_INT_WORD_BITS_CNT); printf("BIB_INT library version: %s, build_date: %s\n", big_int_version(), big_int_build_date()); printf("type \\h or \\? for help\n"); if (history_init()) { /* error when initializing history[] array */ result = 1; goto done; } /* init the [module] */ module = big_int_create(1); if (module == NULL) { printf("cannot create [module]\n"); result = 2; goto done; } /* start parsing */ parse(); done: /* free allocated memory */ big_int_destroy(module); history_destroy(); return result; }
/*the init function, initializes the basic environment of the shell*/ void shell_init(void) { prompt = (char*)malloc(sizeof(char[16])); cwd = (char*) malloc(sizeof(char[255])); last_dir = (char*)malloc(sizeof(char[255])); strcpy(last_dir, ""); cmd_char = (char*)calloc(1, sizeof(char[255])); cmd_head = (struct cmd*) malloc(sizeof(struct cmd)); cmd_head->element = NULL; cmd_head->next = NULL; p = (char*)malloc(sizeof(char[128])); printf("*** Welcome to Shell ! ***\n"); path_list = (struct pathelement*)malloc (sizeof(struct pathelement)); path_list -> next = NULL; path_list -> element = NULL; if (getcwd(cwd, 255) == NULL) { printf("Shell: getcwd error: %s\n", strerror(errno)); } /* This is just first_step initialization * to prevent myself from forgetting it * as well as my hands are cut as a consequence... */ strcpy(prompt, "user"); bg_init(); path_list = get_path(); print_env_path(); alias_init(); history_init(); noclobber = 0; }
static char *fetchline(void) { static EditLine *el; static History *hist; HistEvent hevent; char *line; int count; if (!el) { hist = history_init(); history(hist, &hevent, H_SETSIZE, 100); el = el_init(progname, stdin, stdout, stderr); el_source(el, NULL); el_set(el, EL_SIGNAL, 1); el_set(el, EL_PROMPT, el_get_prompt); el_set(el, EL_HIST, history, (const char *)hist); } line = strdup(el_gets(el, &count)); if (line) { if (count > 0) { line[count-1] = '\0'; } if (*line) { history(hist, &hevent, H_ENTER, line); } } return line; }
static int acc_el_initialize(void) { HistEvent ev; if (el != NULL) el_end(el); if (el_hist != NULL) history_end(el_hist); el = el_init("accedian", stdin, stdout, stderr); el_set(el, EL_PROMPT, cli_prompt); el_set(el, EL_EDITMODE, 1); el_set(el, EL_EDITOR, "emacs"); el_hist = history_init(); if (!el || !el_hist) return -1; /* setup history with 100 entries */ history(el_hist, &ev, H_SETSIZE, 100); el_set(el, EL_HIST, history, el_hist); el_set(el, EL_ADDFN, "ed-complete", "Complete argument", cli_complete); /* Bind <tab> to command completion */ el_set(el, EL_BIND, "^I", "ed-complete", NULL); #if 0 // Ticket #8152 - This corrupts show_rc passwords containing question marks /* Bind ? to command completion */ el_set(el, EL_BIND, "?", "ed-complete", NULL); #endif /* Bind ^D to redisplay */ el_set(el, EL_BIND, "^D", "ed-redisplay", NULL); return 0; }
/* * ntp_readline_init - setup, set or reset prompt string */ int ntp_readline_init( const char * prompt ) { int success; success = 1; if (prompt) { if (lineedit_prompt) free(lineedit_prompt); lineedit_prompt = estrdup(prompt); } #ifdef LE_EDITLINE if (NULL == ntp_el) { # if 4 == EL_INIT_ARGS ntp_el = el_init(progname, stdin, stdout, stderr); # else ntp_el = el_init(progname, stdin, stdout); # endif if (ntp_el) { el_set(ntp_el, EL_PROMPT, ntp_prompt_callback); el_set(ntp_el, EL_EDITOR, "emacs"); ntp_hist = history_init(); if (NULL == ntp_hist) { mfprintf(stderr, "history_init(): %m\n"); fflush(stderr); el_end(ntp_el); ntp_el = NULL; success = 0; } else { ZERO(hev); #ifdef H_SETSIZE history(ntp_hist, &hev, H_SETSIZE, 128); #endif el_set(ntp_el, EL_HIST, history, ntp_hist); /* use any .editrc */ el_source(ntp_el, NULL); } } else success = 0; } #endif /* LE_EDITLINE */ ntp_readline_initted = success; return success; }
/* * ntp_readline_init - setup, set or reset prompt string */ int ntp_readline_init( const char * prompt ) { int success; success = 1; if (prompt) { if (lineedit_prompt) free(lineedit_prompt); lineedit_prompt = estrdup(prompt); } #ifdef LE_EDITLINE if (NULL == ntp_el) { ntp_el = el_init(progname, stdin, stdout, stderr); if (ntp_el) { el_set(ntp_el, EL_PROMPT, ntp_prompt_callback); el_set(ntp_el, EL_EDITOR, "emacs"); ntp_hist = history_init(); if (NULL == ntp_hist) { fprintf(stderr, "history_init(): %s\n", strerror(errno)); fflush(stderr); el_end(ntp_el); ntp_el = NULL; success = 0; } else { memset(&hev, 0, sizeof hev); history(ntp_hist, &hev, H_SETSIZE, 128); el_set(ntp_el, EL_HIST, history, ntp_hist); /* use any .editrc */ el_source(ntp_el, NULL); } } else success = 0; } #endif /* LE_EDITLINE */ ntp_readline_initted = success; return success; }
int shell(FILE * f, const char * (* prompt)(void), void (* greeting)(FILE *), const struct shell_cmd * cmd_tab) { char hist_buf[SIZEOF_CMD_HISTORY + SHELL_HISTORY_MAX * SHELL_LINE_MAX]; char line[SHELL_LINE_MAX]; struct cmd_history * history; int ret = 0; DCC_LOG(LOG_TRACE, "history_init()"); history = history_init(hist_buf, sizeof(hist_buf), SHELL_LINE_MAX); if (greeting) greeting(f); do { char * stat; char * cp; fprintf(f, "%s", prompt()); if (history_readline(history, f, line, SHELL_LINE_MAX) == NULL) return -1; if ((cp = shell_stripline(line)) == NULL) continue; history_add(history, cp); cp = line; ret = 0; while ((stat = cmd_get_next(&cp)) != NULL) { struct shell_cmd * cmd; if ((cmd = cmd_lookup(cmd_tab, stat)) == NULL) { fprintf(f, "Command not found!\n"); break; } ret = cmd_exec(f, cmd, stat); if ((ret < 0) && (ret != SHELL_ABORT)) { fprintf(f, "Error: %d\n", -ret); break; } } } while (ret != SHELL_ABORT); return 0; }
EditLineReader::EditLineReader() : _history(history_init()) , _editLine(el_init("ccons", stdin, stdout, stderr)) { reader = this; history(_history, &_event, H_SETSIZE, INT_MAX); el_set(_editLine, EL_PROMPT, ccons_prompt); el_set(_editLine, EL_EDITOR, "emacs"); el_set(_editLine, EL_HIST, history, _history); el_set(_editLine, EL_ADDFN, "ccons-ac", "autocomplete", ccons_autocomplete); el_set(_editLine, EL_BIND, "^I", "ccons-ac", NULL); }
static EditLine *initEditLine() { EditLine *e; HistEvent ev; cmdHistory = history_init(); history(cmdHistory, &ev, H_SETSIZE, 100); e = el_init("ejs", stdin, stdout, stderr); el_set(e, EL_EDITOR, "vi"); el_set(e, EL_HIST, history, cmdHistory); el_source(e, NULL); return e; }
int main(int argc, char *argv[]) { /* Name of the programme */ char progname[] = "sesh"; char progversion[] = "0.4.0"; /* Arguments table */ void *argtable[] = { help = arg_litn("h", "help", 0, 1, "Display this help and exit"), version = arg_litn("v", "version", 0, 1, "Display version info and exit"), end = arg_end(20), }; /* Number of errors analysing arguments */ int nerrors = arg_parse(argc, argv, argtable); /* If help needed we don't care about the errors */ if (help->count > 0) { printf("Usage: %s", progname); arg_print_syntax(stdout, argtable, "\n"); arg_print_glossary(stdout, argtable, " %-25s %s\n"); arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0])); return 0; } /* If errors occured */ if (nerrors > 0) { /* Displaying the error information */ arg_print_errors(stdout, end, progname); printf("Try '%s --help' for more information.\n", progname); arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0])); return 1; } if (version->count > 0) { printf("Version: %s %s\n", progname, progversion); arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0])); return 0; } history_init(); term_set_driver(); repl(); term_reset_driver(); arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0])); return 0; }
CommandPrompt::CommandPrompt() { #ifdef ZORBA_HAVE_LIBEDIT_H theEditLine = el_init("xqdb", stdin, stdout, stderr); theHistory = history_init(); HistEvent lHistoryEvent; history(theHistory, &lHistoryEvent, H_SETSIZE, 100); el_set(theEditLine, EL_PROMPT, prompt); el_set(theEditLine, EL_HIST, history, theHistory); el_set(theEditLine, EL_EDITOR, "emacs"); #endif }
void server_init(t_server *s, int port) { s->port = port; history_init(s); s->connect = init_master; s->listen = listening; s->dispatch = dispatch; s->respond = respond; s->cmds = g_cmds; s->max_clients = MAX_CLIENTS; s->users = NULL; s->opt = TRUE; s->msg = ft_strdup("KIFT 1.0 \r\n"); init_client_socks(s); }
int main(int argc, char *argv[]) { HistEvent he; static EditLine *el; static History *hist; bool interactive; acting_as_client = 1; peer = -1; strcpy(mode, "netascii"); signal(SIGINT, intr); interactive = isatty(STDIN_FILENO); if (interactive) { el = el_init("tftp", stdin, stdout, stderr); hist = history_init(); history(hist, &he, H_SETSIZE, 100); el_set(el, EL_HIST, history, hist); el_set(el, EL_EDITOR, "emacs"); el_set(el, EL_PROMPT, command_prompt); el_set(el, EL_SIGNAL, 1); el_source(el, NULL); } if (argc > 1) { if (setjmp(toplevel) != 0) exit(txrx_error); if (strncmp(argv[1], "tftp://", 7) == 0) { urihandling(argv[1]); exit(txrx_error); } setpeer(argc, argv); } if (setjmp(toplevel) != 0) { if (interactive) el_reset(el); (void)putchar('\n'); } init_options(); command(interactive, el, hist, &he); }
static void _cliDebuggerInit(struct Debugger* debugger) { struct CLIDebugger* cliDebugger = (struct CLIDebugger*) debugger; // TODO: get argv[0] cliDebugger->elstate = el_init(binaryName, stdin, stdout, stderr); el_set(cliDebugger->elstate, EL_PROMPT, _prompt); el_set(cliDebugger->elstate, EL_EDITOR, "emacs"); el_set(cliDebugger->elstate, EL_CLIENTDATA, cliDebugger); el_set(cliDebugger->elstate, EL_ADDFN, "tab-complete", "Tab completion", _tabComplete); el_set(cliDebugger->elstate, EL_BIND, "\t", "tab-complete", 0); cliDebugger->histate = history_init(); HistEvent ev; history(cliDebugger->histate, &ev, H_SETSIZE, 200); el_set(cliDebugger->elstate, EL_HIST, history, cliDebugger->histate); _activeDebugger = cliDebugger; signal(SIGINT, _breakIntoDefault); }
void repl::init_editline(FILE * infile, FILE * outfile) noexcept { setlocale(LC_CTYPE, ""); hist = history_init(); history(hist, &ev, H_SETSIZE, 100); el = el_init("./MoNS", infile, outfile, outfile); el_set(el, EL_EDITOR, "vi"); // el_set(el, EL_PROMPT_ESC, // +[](EditLine *el) -> const char * { // const char *prompt = "λ "; // return prompt; // }, // '\1'); el_set(el, EL_PROMPT_ESC, &prompt, '\1'); el_set(el, EL_HIST, history, hist); el_source(el, NULL); }
int main() { char str[STR_LINE_SIZE]; term_init(); history_init(); do{ readline_print_status(); readline(str); printf("%s\n", str); }while( strcmp(str, "exit") != 0 ); history_quit(); term_quit(); return 0; }
status_t CliContext::Init(Team* team, UserInterfaceListener* listener) { fTeam = team; fListener = listener; fTeam->AddListener(this); status_t error = fLock.InitCheck(); if (error != B_OK) return error; fBlockingSemaphore = create_sem(0, "CliContext block"); if (fBlockingSemaphore < 0) return fBlockingSemaphore; fEditLine = el_init("Debugger", stdin, stdout, stderr); if (fEditLine == NULL) return B_ERROR; fHistory = history_init(); if (fHistory == NULL) return B_ERROR; HistEvent historyEvent; history(fHistory, &historyEvent, H_SETSIZE, 100); el_set(fEditLine, EL_HIST, &history, fHistory); el_set(fEditLine, EL_EDITOR, "emacs"); el_set(fEditLine, EL_PROMPT, &_GetPrompt); fNodeManager = new(std::nothrow) ValueNodeManager(); if (fNodeManager == NULL) return B_NO_MEMORY; fNodeManager->AddListener(this); fExpressionInfo = new(std::nothrow) ExpressionInfo(); if (fExpressionInfo == NULL) return B_NO_MEMORY; fExpressionInfo->AddListener(this); return B_OK; }
int main(int argc, char **argv) { EditLine *el; History *hist; const char *buf; int num, state; check_args(argc, argv); if(connect_uri) { sql_conn = sql_connect(connect_uri); if(!sql_conn) { fprintf(stderr, "%s: [%s] %s\n", short_program_name, sql_sqlstate(NULL), sql_error(NULL)); exit(EXIT_FAILURE); } } fprintf(stderr, "%s interactive SQL shell (%s)\n\n", PACKAGE, VERSION); fprintf(stderr, "Type: \\c URI to establish a new connection\n" " \\g or ; to execute query\n" " \\G to execute the query showing results in long format\n" " \\q to end the SQL session\n" "\n" ); hist = history_init(); el = el_init(argv[0], stdin, stdout, stderr); el_set(el, EL_EDITOR, "emacs"); el_set(el, EL_SIGNAL, 1); el_set(el, EL_PROMPT, prompt); el_set(el, EL_HIST, history, hist); el_source(el, NULL); while((buf = el_gets(el, &num)) != NULL && num != 0) { state = parse_query(buf); if(state == 0) { exec_queries(hist); } } return 0; }
char * readline(const char* prompt) { static EditLine *e; #ifdef H_SETSIZE HistEvent ev; #endif int count; const char *str; if(e == NULL){ #ifdef EL_INIT_FOUR e = el_init("", stdin, stdout, stderr); #else e = el_init("", stdin, stdout); #endif el_set(e, EL_PROMPT, ret_prompt); h = history_init(); #ifdef H_SETSIZE history(h, &ev, H_SETSIZE, 25); #else history(h, H_EVENT, 25); #endif el_set(e, EL_HIST, history, h); el_set(e, EL_EDITOR, "emacs"); /* XXX? */ } pr = prompt ? prompt : ""; str = el_gets(e, &count); if (str && count > 0) { char *ret = strdup (str); if (ret == NULL) return NULL; if (ret[strlen(ret) - 1] == '\n') ret[strlen(ret) - 1] = '\0'; return ret; } return NULL; }
IoEditLine *IoEditLine_proto(void *state) { IoMethodTable methodTable[] = { {"hasEditLib", IoEditLine_hasEditLib}, {"readLine", IoEditLine_readLine}, {"addHistory", IoEditLine_addHistory}, {NULL, NULL}, }; IoObject *self = IoObject_new(state); IoObject_tag_(self, IoEditLine_newTag(state)); /* Make sure editline returns characters in the multi-byte charset of the locale */ setlocale(LC_CTYPE, ""); IoObject_setDataPointer_(self, io_calloc(1, sizeof(IoEditLineData))); DATA(self)->prompt = IOSYMBOL(""); DATA(self)->editline = el_init("io", stdin, stdout, stderr); DATA(self)->history = history_init(); el_set(DATA(self)->editline, EL_CLIENTDATA, self); el_set(DATA(self)->editline, EL_HIST, history, DATA(self)->history); el_set(DATA(self)->editline, EL_PROMPT, promptCallback); el_set(DATA(self)->editline, EL_SIGNAL, 1); el_set(DATA(self)->editline, EL_EDITOR, "emacs"); { HistEvent ev; history(DATA(self)->history, &ev, H_SETSIZE, 300); } el_source(DATA(self)->editline, NULL); IoState_registerProtoWithFunc_((IoState *)state, self, IoEditLine_proto); IoObject_addMethodTable_(self, methodTable); return self; }
void system_init(void) { init_tft(); // initialiser xps_tft init_interrupt_controller(); system_enable_caches(); microblaze_enable_interrupts(); system_init_network(); clear_screen(); // effacer la page vidéo avec du noir font_init(XPAR_FLASH_MEM0_BASEADDR, TFT_FB_ADDR); sound_init(); htmlParserInit(); connection_set_HTML_handler(DM_parseHTMLPage); connection_set_WAV_handler(wav_parse); //connection_set_BMP_handler(BMP_html_parser_handler); history_init(); DM_init(); command_line_init(); }
/* * Add an entry with text `event` to the history list, with type `type` * ("HISTORY_xxx" in defines.h), and artifact number `id` (0 for everything * else). * * Return TRUE on success. */ bool history_add_full(u16b type, byte a_idx, s16b dlev, s16b clev, s32b turn, const char *text) { /* Allocate the history list if needed */ if (!history_list) history_init(HISTORY_BIRTH_SIZE); /* Expand the history list if appropriate */ else if ((history_ctr == history_size) && !history_set_num(history_size + 10)) return FALSE; /* History list exists and is not full. Add an entry at the current counter location. */ history_list[history_ctr].type = type; history_list[history_ctr].dlev = dlev; history_list[history_ctr].clev = clev; history_list[history_ctr].a_idx = a_idx; history_list[history_ctr].turn = turn; my_strcpy(history_list[history_ctr].event, text, sizeof(history_list[history_ctr].event)); history_ctr++; return TRUE; }
char *x_readline(const char *prompt) { static char buffer[1024]; int count = 0; const char *cp; if (!el) { hist = history_init(); history(hist, &ev, H_SETSIZE, HISTORY_SIZE); history(hist, &ev, H_SETUNIQUE, 1); el = el_init("GS+", stdin, stdout, stderr); el_set(el, EL_EDITOR, "emacs"); el_set(el, EL_BIND, "-e", NULL, NULL, NULL); el_set(el, EL_HIST, history, hist); el_set(el, EL_PROMPT, prompt_fn); el_set(el, EL_SIGNAL, 1); el_source(el, NULL); } el_prompt = prompt; cp = el_gets(el, &count); el_prompt = NULL; if (count <= 0) { if (prompt) fputc('\n', stdout); return NULL; } if (count > sizeof(buffer) - 1) return ""; memcpy(buffer, cp, count); cleanup_buffer(buffer, count); if (*buffer) history(hist, &ev, H_ENTER, buffer); return buffer; }
/** * Add an entry with text `event` to the history list, with type `type` * ("HIST_xxx" in player-history.h), and artifact number `id` (0 for * everything else). * * Return true on success. */ bool history_add_full(bitflag *type, struct artifact *artifact, s16b dlev, s16b clev, s32b turnno, const char *text) { /* Allocate or expand the history list as needed */ if (!history_list) history_init(HISTORY_BIRTH_SIZE); else if ((history_ctr == history_size) && !history_set_num(history_size + 10)) return false; /* History list exists and is not full. Add an entry at the current * counter location. */ hist_copy(history_list[history_ctr].type, type); history_list[history_ctr].dlev = dlev; history_list[history_ctr].clev = clev; history_list[history_ctr].a_idx = artifact ? artifact->aidx : 0; history_list[history_ctr].turn = turnno; my_strcpy(history_list[history_ctr].event, text, sizeof(history_list[history_ctr].event)); history_ctr++; return true; }