Definition at line 67 of file prompt.c.
68{
69#define MAX_PROMPT_SIZE 256
72 bool esc = false;
73 const char *p;
74 const char *prompt_string = "? ";
75 static size_t last_prompt1_width = 0;
76
77 switch (status)
78 {
81 break;
82
90 break;
91
94 break;
95 }
96
97 destination[0] = '\0';
98
99 for (p = prompt_string;
100 *p && strlen(destination) < sizeof(destination) - 1;
101 p++)
102 {
103 memset(
buf, 0,
sizeof(
buf));
104 if (esc)
105 {
106 switch (*p)
107 {
108
109 case '/':
112 break;
113 case '~':
115 {
116 const char *var;
117
119 ((var = getenv(
"PGDATABASE")) && strcmp(var,
PQdb(
pset.
db)) == 0))
121 else
123 }
124 break;
125
126
127 case 'w':
130 Min(last_prompt1_width,
sizeof(
buf) - 1));
131 break;
132
133
134 case 'M':
135 case 'm':
137 {
139
140
142 {
144 if (*p == 'm')
145 buf[strcspn(
buf,
".")] =
'\0';
146 }
147
148 else
149 {
150 if (!host
152 || *p == 'm')
154 else
156 }
157 }
158 break;
159
160 case '>':
163 break;
164
165 case 'n':
168 break;
169
170 case 's':
173 break;
174
175 case 'p':
177 {
179
180 if (pid)
182 }
183 break;
184
185 case '0':
186 case '1':
187 case '2':
188 case '3':
189 case '4':
190 case '5':
191 case '6':
192 case '7':
194 --p;
195 break;
196 case 'R':
197 switch (status)
198 {
206 else
208 break;
211 break;
214 break;
217 break;
220 break;
223 break;
226 break;
227 default:
229 break;
230 }
231 break;
232
233 case 'x':
236 else
238 {
241 break;
245 break;
248 break;
249 default:
251 break;
252 }
253 break;
254
255 case 'l':
257 break;
258
259 case '?':
260
261 break;
262
263 case '#':
266 else
268 break;
269
270
271 case '`':
272 {
273 int cmdend = strcspn(p + 1, "`");
274 char *file =
pnstrdup(p + 1, cmdend);
276
278 fd = popen(file,
"r");
280 {
281 if (fgets(
buf,
sizeof(
buf),
fd) == NULL)
284 }
285
286
288
290 p += cmdend + 1;
291 break;
292 }
293
294
295 case ':':
296 {
297 int nameend = strcspn(p + 1, ":");
300
305 p += nameend + 1;
306 break;
307 }
308
309 case '[':
310 case ']':
311#if defined(USE_READLINE) && defined(RL_PROMPT_START_IGNORE)
312
313
314
315
316
317
318 buf[0] = (*p ==
'[') ? RL_PROMPT_START_IGNORE : RL_PROMPT_END_IGNORE;
320#endif
321 break;
322
323 default:
326 break;
327 }
328 esc = false;
329 }
330 else if (*p == '%')
331 esc = true;
332 else
333 {
336 esc = false;
337 }
338
339 if (!esc)
340 strlcat(destination,
buf,
sizeof(destination));
341 }
342
343
345 {
346 char *p = destination;
347 char *end = p + strlen(p);
348 bool visible = true;
349
350 last_prompt1_width = 0;
351 while (*p)
352 {
353#if defined(USE_READLINE) && defined(RL_PROMPT_START_IGNORE)
354 if (*p == RL_PROMPT_START_IGNORE)
355 {
356 visible = false;
357 ++p;
358 }
359 else if (*p == RL_PROMPT_END_IGNORE)
360 {
361 visible = true;
362 ++p;
363 }
364 else
365#endif
366 {
367 int chlen,
368 chwidth;
369
371 if (p + chlen > end)
372 break;
373
374 if (visible)
375 {
377
378 if (*p == '\n')
379 last_prompt1_width = 0;
380 else if (chwidth > 0)
381 last_prompt1_width += chwidth;
382 }
383
384 p += chlen;
385 }
386 }
387 }
388
389 return destination;
390}
const char * session_username(void)
#define unconstify(underlying_type, expr)
bool conditional_active(ConditionalStack cstack)
char * PQdb(const PGconn *conn)
char * PQport(const PGconn *conn)
PGTransactionStatusType PQtransactionStatus(const PGconn *conn)
char * PQhost(const PGconn *conn)
char * PQservice(const PGconn *conn)
int PQbackendPID(const PGconn *conn)
char * PQuser(const PGconn *conn)
int PQmblen(const char *s, int encoding)
int PQdsplen(const char *s, int encoding)
static void const char fflush(stdout)
char * pnstrdup(const char *in, Size len)
#define DEFAULT_PGSOCKET_DIR
static bool is_superuser(Archive *fout)
size_t strlcat(char *dst, const char *src, size_t siz)
size_t strlcpy(char *dst, const char *src, size_t siz)
static bool is_unixsock_path(const char *path)
static int fd(const char *x, int i)
int pg_strip_crlf(char *str)
const char * GetVariable(VariableSpace space, const char *name)
References buf, conditional_active(), _psqlSettings::db, DEFAULT_PGSOCKET_DIR, _psqlSettings::encoding, fd(), fflush(), free, GetVariable(), is_superuser(), is_unixsock_path(), MAX_PROMPT_SIZE, Min, name, pg_strip_crlf(), pnstrdup(), PQbackendPID(), PQdb(), PQdsplen(), PQhost(), PQmblen(), PQport(), PQservice(), PQTRANS_ACTIVE, PQTRANS_IDLE, PQTRANS_INERROR, PQTRANS_INTRANS, PQtransactionStatus(), PQuser(), _psqlSettings::prompt1, _psqlSettings::prompt2, _psqlSettings::prompt3, PROMPT_COMMENT, PROMPT_CONTINUE, PROMPT_COPY, PROMPT_DOLLARQUOTE, PROMPT_DOUBLEQUOTE, PROMPT_PAREN, PROMPT_READY, PROMPT_SINGLEQUOTE, pset, session_username(), _psqlSettings::singleline, snprintf, _psqlSettings::stmt_lineno, strlcat(), strlcpy(), UINT64_FORMAT, unconstify, val, and _psqlSettings::vars.
Referenced by handleCopyIn(), and MainLoop().