82 newvar =
psprintf(
"%s%s", *var, more);
93 const char *whitespace =
" \t\n\r";
115 token =
strtokx(NULL, whitespace,
".,()",
"\"",
130 token =
strtokx(NULL, whitespace,
"()",
"\"'",
136 else if (token[0] ==
')')
143 token =
strtokx(NULL, whitespace,
".,()",
"\"",
156 token =
strtokx(NULL, whitespace,
".,()",
"\"",
161 token =
strtokx(NULL, whitespace,
".,()",
"\"",
174 token =
strtokx(NULL, whitespace,
"()",
"\"",
183 token =
strtokx(NULL, whitespace,
".,()",
"\"",
192 result->
from =
false;
197 token =
strtokx(NULL, whitespace,
";",
"'",
206 token =
strtokx(NULL, whitespace,
";",
"'",
215 toklen = strlen(token);
216 if (token[0] !=
'\'' || toklen < 2 || token[toklen - 1] !=
'\'')
244 token =
strtokx(NULL,
"", NULL, NULL,
343 if ((result =
fstat(fileno(copystream), &st)) < 0)
380 int pclose_rc = pclose(copystream);
385 pg_log_error(
"could not close pipe to external command: %m");
391 reason ? reason :
"");
401 if (fclose(copystream) != 0)
451 if (OK && copystream && fwrite(
buf, 1, ret, copystream) != ret)
461 if (OK && copystream &&
fflush(copystream))
510 #define COPYBUFSIZ 8192
530 _(
"canceled by user"));
537 if (isatty(fileno(copystream)))
541 puts(
_(
"Enter data to be copied followed by a newline.\n"
542 "End with a backslash and a period on a line by itself, or an EOF signal."));
583 bool copydone =
false;
585 bool at_line_begin =
true;
598 if (at_line_begin && showprompt)
609 fgresult = fgets(&
buf[buflen],
COPYBUFSIZ - buflen, copystream);
619 linelen = strlen(fgresult);
623 if (
buf[buflen - 1] ==
'\n')
633 if ((linelen == 3 && memcmp(fgresult,
"\\.\n", 3) == 0) ||
634 (linelen == 4 && memcmp(fgresult,
"\\.\r\n", 4) == 0))
645 at_line_begin =
true;
648 at_line_begin =
false;
659 if (buflen >=
COPYBUFSIZ - 5 || (copydone && buflen > 0))
673 if (ferror(copystream))
684 _(
"aborted because of read failure")) <= 0)
697 clearerr(copystream);
718 _(
"trying to exit copy mode"));
void expand_tilde(char **filename)
sigjmp_buf sigint_interrupt_jmp
volatile bool sigint_interrupt_enabled
bool standard_strings(void)
bool SendQuery(const char *query)
static struct copy_options * parse_slash_copy(const char *args)
bool handleCopyOut(PGconn *conn, FILE *copystream, PGresult **res)
bool do_copy(const char *args)
static void xstrcat(char **var, const char *more)
bool handleCopyIn(PGconn *conn, FILE *copystream, bool isbinary, PGresult **res)
static void free_copy_options(struct copy_options *ptr)
static void PGresult * res
int PQprotocolVersion(const PGconn *conn)
char * PQerrorMessage(const PGconn *conn)
void PQfreemem(void *ptr)
ExecStatusType PQresultStatus(const PGresult *res)
void PQclear(PGresult *res)
int PQputCopyEnd(PGconn *conn, const char *errormsg)
int PQputCopyData(PGconn *conn, const char *buffer, int nbytes)
PGresult * PQgetResult(PGconn *conn)
int PQgetCopyData(PGconn *conn, char **buffer, int async)
void * pg_malloc0(size_t size)
char * pg_strdup(const char *in)
void restore_sigpipe_trap(void)
void disable_sigpipe_trap(void)
static void const char fflush(stdout)
#define pg_log_error(...)
int pg_strcasecmp(const char *s1, const char *s2)
void canonicalize_path(char *path)
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void initPQExpBuffer(PQExpBuffer str)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
void termPQExpBuffer(PQExpBuffer str)
char * get_prompt(promptStatus_t status, ConditionalStack cstack)
char * psprintf(const char *fmt,...)
char * strtokx(const char *s, const char *whitespace, const char *delim, const char *quote, char escape, bool e_strings, bool del_quotes, int encoding)
void strip_quotes(char *source, char quote, char escape, int encoding)
char * wait_result_to_str(int exitstatus)