15 #ifdef HAVE_UNIX_SOCKETS 72 #define MAX_PROMPT_SIZE 256 77 const char *prompt_string =
"? ";
78 static size_t last_prompt1_width = 0;
100 destination[0] =
'\0';
102 for (p = prompt_string;
103 *p && strlen(destination) <
sizeof(destination) - 1;
106 memset(buf, 0,
sizeof(buf));
122 ((var = getenv(
"PGDATABASE")) && strcmp(var,
PQdb(
pset.
db)) == 0))
123 strlcpy(buf,
"~",
sizeof(buf));
133 Min(last_prompt1_width,
sizeof(buf) - 1));
146 strlcpy(buf, host,
sizeof(buf));
148 buf[strcspn(buf,
".")] =
'\0';
150 #ifdef HAVE_UNIX_SOCKETS 157 strlcpy(buf,
"[local]",
sizeof(buf));
159 snprintf(buf,
sizeof(buf),
"[local:%s]", host);
181 snprintf(buf,
sizeof(buf),
"%d", pid);
193 *buf = (char) strtol(p,
unconstify(
char **, &p), 8);
273 int cmdend = strcspn(p + 1,
"`");
274 char *file =
pnstrdup(p + 1, cmdend);
275 FILE *
fd = popen(file,
"r");
279 if (fgets(buf,
sizeof(buf), fd) == NULL)
295 int nameend = strcspn(p + 1,
":");
301 strlcpy(buf, val,
sizeof(buf));
309 #if defined(USE_READLINE) && defined(RL_PROMPT_START_IGNORE) 316 buf[0] = (*p ==
'[') ? RL_PROMPT_START_IGNORE : RL_PROMPT_END_IGNORE;
339 strlcat(destination, buf,
sizeof(destination));
345 char *p = destination;
346 char *end = p + strlen(p);
349 last_prompt1_width = 0;
352 #if defined(USE_READLINE) && defined(RL_PROMPT_START_IGNORE) 353 if (*p == RL_PROMPT_START_IGNORE)
358 else if (*p == RL_PROMPT_END_IGNORE)
377 last_prompt1_width += chwidth;
bool conditional_active(ConditionalStack cstack)
char * pnstrdup(const char *in, Size len)
int pg_strip_crlf(char *str)
int PQdsplen(const char *s, int encoding)
char * get_prompt(promptStatus_t status, ConditionalStack cstack)
char * PQport(const PGconn *conn)
static int fd(const char *x, int i)
char * PQuser(const PGconn *conn)
const char * session_username(void)
#define is_absolute_path(filename)
PGTransactionStatusType PQtransactionStatus(const PGconn *conn)
#define unconstify(underlying_type, expr)
const char * GetVariable(VariableSpace space, const char *name)
int PQbackendPID(const PGconn *conn)
char * PQhost(const PGconn *conn)
size_t strlcpy(char *dst, const char *src, size_t siz)
char * PQdb(const PGconn *conn)
enum _promptStatus promptStatus_t
static bool is_superuser(Archive *fout)
static void static void status(const char *fmt,...) pg_attribute_printf(1
int PQmblen(const char *s, int encoding)
size_t strlcat(char *dst, const char *src, size_t siz)
#define DEFAULT_PGSOCKET_DIR