original) (raw)
PostgreSQL Source Code: src/bin/psql/input.c File Reference (#include "[postgres_fe.h](postgres%5F%5Ffe%5F8h%5Fsource.html)"
#include <[unistd.h](unistd%5F8h%5Fsource.html)>
#include <fcntl.h>
#include <limits.h>
#include "[common.h](psql%5F2common%5F8h%5Fsource.html)"
#include "[common/logging.h](logging%5F8h%5Fsource.html)"
#include "[input.h](input%5F8h%5Fsource.html)"
#include "[settings.h](settings%5F8h%5Fsource.html)"
#include "[tab-complete.h](tab-complete%5F8h%5Fsource.html)"
Go to the source code of this file.
Functions | |
---|---|
static void | finishInput (void) |
char * | gets_interactive (const char *prompt, PQExpBuffer query_buf) |
void | pg_append_history (const char *s, PQExpBuffer history_buf) |
void | pg_send_history (PQExpBuffer history_buf) |
char * | gets_fromFile (FILE *source) |
void | initializeInput (int flags) |
bool | printHistory (const char *fname, unsigned short int pager) |
◆ PSQLHISTORY
#define PSQLHISTORY ".psql_history"
Definition at line 23 of file input.c.
◆ finishInput()
static void finishInput ( void ) | static |
---|
◆ gets_fromFile()
char * gets_fromFile | ( | FILE * | source | ) |
---|
Definition at line 186 of file input.c.
187{
189
190 char line[1024];
191
192 if (buffer == NULL)
194 else
196
197 for (;;)
198 {
199 char *result;
200
201
203
204
205 result = fgets(line, sizeof(line), source);
206
207
209
210
211 if (result == NULL)
212 {
214 {
215 pg_log_error("could not read from input file: %m");
216 return NULL;
217 }
218 break;
219 }
220
222
224 {
226 return NULL;
227 }
228
229
230 if (buffer->len > 0 && buffer->data[buffer->len - 1] == '\n')
231 {
232 buffer->data[buffer->len - 1] = '\0';
234 }
235 }
236
237 if (buffer->len > 0)
239
240
241 return NULL;
242}
volatile sig_atomic_t sigint_interrupt_enabled
char * pg_strdup(const char *in)
#define pg_log_error(...)
static rewind_source * source
PQExpBuffer createPQExpBuffer(void)
void resetPQExpBuffer(PQExpBuffer str)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
#define PQExpBufferBroken(str)
References appendPQExpBufferStr(), createPQExpBuffer(), PQExpBufferData::data, PQExpBufferData::len, pg_log_error, pg_strdup(), PQExpBufferBroken, resetPQExpBuffer(), sigint_interrupt_enabled, and source.
Referenced by exec_command_prompt(), gets_interactive(), and MainLoop().
◆ gets_interactive()
char * gets_interactive | ( | const char * | prompt, |
---|---|---|---|
PQExpBuffer | query_buf | ||
) |
◆ initializeInput()
void initializeInput | ( | int | flags | ) |
---|
Definition at line 344 of file input.c.
345{
346#ifdef USE_READLINE
347 if (flags & 1)
348 {
349 const char *histfile;
351
352 useReadline = true;
353
354
356
357#ifdef HAVE_RL_VARIABLE_BIND
358
359 (void) rl_variable_bind("comment-begin", "-- ");
360#endif
361
362
363 rl_initialize();
364
365 useHistory = true;
366 using_history();
367 history_lines_added = 0;
368
370
371 if (histfile == NULL)
372 {
373 char *envhist;
374
375 envhist = getenv("PSQL_HISTORY");
376 if (envhist != NULL && strlen(envhist) > 0)
377 histfile = envhist;
378 }
379
380 if (histfile == NULL)
381 {
384 }
385 else
386 {
387 psql_history = pg_strdup(histfile);
389 }
390
391 if (psql_history)
392 {
393 read_history(psql_history);
394 decode_history();
395 }
396 }
397#endif
398
400}
void expand_tilde(char **filename)
static void finishInput(void)
bool get_home_path(char *ret_path)
char * psprintf(const char *fmt,...)
void initialize_readline(void)
const char * GetVariable(VariableSpace space, const char *name)
References expand_tilde(), finishInput(), get_home_path(), GetVariable(), initialize_readline(), MAXPGPATH, pg_strdup(), pset, psprintf(), PSQLHISTORY, and _psqlSettings::vars.
Referenced by main().
◆ pg_append_history()
void pg_append_history | ( | const char * | s, |
---|---|---|---|
PQExpBuffer | history_buf | ||
) |
◆ pg_send_history()
◆ printHistory()
bool printHistory | ( | const char * | fname, |
---|---|---|---|
unsigned short int | pager | ||
) |
Definition at line 494 of file input.c.
495{
496#ifdef USE_READLINE
498 bool is_pager;
499
500 if (!useHistory)
501 return false;
502
503 if (fname == NULL)
504 {
505
507 is_pager = true;
508 }
509 else
510 {
511 output = fopen(fname, "w");
513 {
514 pg_log_error("could not save history to file \"%s\": %m", fname);
515 return false;
516 }
517 is_pager = false;
518 }
519
520 BEGIN_ITERATE_HISTORY(cur_hist);
521 {
523 }
524 END_ITERATE_HISTORY();
525
526 if (is_pager)
528 else
530
531 return true;
532#else
533 pg_log_error("history is not supported by this installation");
534 return false;
535#endif
536}
#define fprintf(file, fmt, msg)
FILE * PageOutput(int lines, const printTableOpt *topt)
void ClosePager(FILE *pagerpipe)
References ClosePager(), fprintf, output, PageOutput(), pg_log_error, _psqlSettings::popt, pset, and printQueryOpt::topt.
Referenced by exec_command_s().