* Put any startup stuff related to input in here. It's good to maintain * abstraction this way. * * The only "flag" right now is 1 for use readline & history. */
| 343 | * The only "flag" right now is 1 for use readline & history. |
| 344 | */ |
| 345 | void |
| 346 | initializeInput(int flags) |
| 347 | { |
| 348 | #ifdef USE_READLINE |
| 349 | if (flags & 1) |
| 350 | { |
| 351 | const char *histfile; |
| 352 | char home[MAXPGPATH]; |
| 353 | |
| 354 | useReadline = true; |
| 355 | |
| 356 | /* these two things must be done in this order: */ |
| 357 | initialize_readline(); |
| 358 | rl_initialize(); |
| 359 | |
| 360 | useHistory = true; |
| 361 | using_history(); |
| 362 | history_lines_added = 0; |
| 363 | |
| 364 | histfile = GetVariable(pset.vars, "HISTFILE"); |
| 365 | |
| 366 | if (histfile == NULL) |
| 367 | { |
| 368 | char *envhist; |
| 369 | |
| 370 | envhist = getenv("PSQL_HISTORY"); |
| 371 | if (envhist != NULL && strlen(envhist) > 0) |
| 372 | histfile = envhist; |
| 373 | } |
| 374 | |
| 375 | if (histfile == NULL) |
| 376 | { |
| 377 | if (get_home_path(home)) |
| 378 | psql_history = psprintf("%s/%s", home, PSQLHISTORY); |
| 379 | } |
| 380 | else |
| 381 | { |
| 382 | psql_history = pg_strdup(histfile); |
| 383 | expand_tilde(&psql_history); |
| 384 | } |
| 385 | |
| 386 | if (psql_history) |
| 387 | { |
| 388 | read_history(psql_history); |
| 389 | decode_history(); |
| 390 | } |
| 391 | } |
| 392 | #endif |
| 393 | |
| 394 | atexit(finishInput); |
| 395 | } |
| 396 | |
| 397 | |
| 398 | /* |
no test coverage detected