* initialize rl compat stuff */
| 289 | * initialize rl compat stuff |
| 290 | */ |
| 291 | int |
| 292 | rl_initialize(void) |
| 293 | { |
| 294 | HistEvent ev; |
| 295 | int editmode = 1; |
| 296 | struct termios t; |
| 297 | |
| 298 | if (e != NULL) |
| 299 | el_end(e); |
| 300 | if (h != NULL) |
| 301 | history_end(h); |
| 302 | |
| 303 | if (!rl_instream) |
| 304 | rl_instream = stdin; |
| 305 | if (!rl_outstream) |
| 306 | rl_outstream = stdout; |
| 307 | |
| 308 | /* |
| 309 | * See if we don't really want to run the editor |
| 310 | */ |
| 311 | if (tcgetattr(fileno(rl_instream), &t) != -1 && (t.c_lflag & ECHO) == 0) |
| 312 | editmode = 0; |
| 313 | |
| 314 | e = el_init(rl_readline_name, rl_instream, rl_outstream, stderr); |
| 315 | |
| 316 | if (!editmode) |
| 317 | el_set(e, EL_EDITMODE, 0); |
| 318 | |
| 319 | h = history_init(); |
| 320 | if (!e || !h) |
| 321 | return -1; |
| 322 | |
| 323 | history(h, &ev, H_SETSIZE, INT_MAX); /* unlimited */ |
| 324 | history_length = 0; |
| 325 | max_input_history = INT_MAX; |
| 326 | el_set(e, EL_HIST, history, h); |
| 327 | |
| 328 | /* Setup resize function */ |
| 329 | el_set(e, EL_RESIZE, _resize_fun, &rl_line_buffer); |
| 330 | |
| 331 | /* setup getc function if valid */ |
| 332 | if (rl_getc_function) |
| 333 | el_set(e, EL_GETCFN, _getc_function); |
| 334 | |
| 335 | /* for proper prompt printing in readline() */ |
| 336 | if (rl_set_prompt("") == -1) { |
| 337 | history_end(h); |
| 338 | el_end(e); |
| 339 | return -1; |
| 340 | } |
| 341 | el_set(e, EL_PROMPT, _get_prompt, RL_PROMPT_START_IGNORE); |
| 342 | el_set(e, EL_SIGNAL, rl_catch_signals); |
| 343 | |
| 344 | /* set default mode to "emacs"-style and read setting afterwards */ |
| 345 | /* so this can be overridden */ |
| 346 | el_set(e, EL_EDITOR, "emacs"); |
| 347 | if (rl_terminal_name != NULL) |
| 348 | el_set(e, EL_TERMINAL, rl_terminal_name); |
no test coverage detected