|
3 | 3 | *
|
4 | 4 | * Copyright (c) 2000-2005, PostgreSQL Global Development Group
|
5 | 5 | *
|
6 |
| - * $PostgreSQL: pgsql/src/bin/psql/input.c,v 1.43 2005/01/06 18:29:09 tgl Exp $ |
| 6 | + * $PostgreSQL: pgsql/src/bin/psql/input.c,v 1.44 2005/06/10 15:34:26 momjian Exp $ |
7 | 7 | */
|
8 | 8 | #include "postgres_fe.h"
|
9 | 9 |
|
|
24 | 24 | #ifdef USE_READLINE
|
25 | 25 | static bool useReadline;
|
26 | 26 | static bool useHistory;
|
| 27 | +char *psql_history; |
| 28 | + |
27 | 29 |
|
28 | 30 | enum histcontrol
|
29 | 31 | {
|
@@ -177,16 +179,24 @@ initializeInput(int flags)
|
177 | 179 | if (GetVariable(pset.vars, "HISTSIZE") == NULL)
|
178 | 180 | SetVariable(pset.vars, "HISTSIZE", "500");
|
179 | 181 | using_history();
|
180 |
| - if (get_home_path(home)) |
| 182 | + |
| 183 | + if (GetVariable(pset.vars, "HISTFILE") == NULL) |
| 184 | + { |
| 185 | + if (get_home_path(home)) |
| 186 | + { |
| 187 | + psql_history = pg_malloc(strlen(home) + 1 + |
| 188 | + strlen(PSQLHISTORY) + 1); |
| 189 | + snprintf(psql_history, MAXPGPATH, "%s/%s", home, PSQLHISTORY); |
| 190 | + } |
| 191 | + } |
| 192 | + else |
181 | 193 | {
|
182 |
| - char *psql_history; |
| 194 | + psql_history = pg_strdup(GetVariable(pset.vars, "HISTFILE")); |
| 195 | + expand_tilde(&psql_history); |
| 196 | + } |
183 | 197 |
|
184 |
| - psql_history = pg_malloc(strlen(home) + 1 + |
185 |
| - strlen(PSQLHISTORY) + 1); |
186 |
| - sprintf(psql_history, "%s/%s", home, PSQLHISTORY); |
| 198 | + if (psql_history) |
187 | 199 | read_history(psql_history);
|
188 |
| - free(psql_history); |
189 |
| - } |
190 | 200 | }
|
191 | 201 | #endif
|
192 | 202 |
|
@@ -227,25 +237,17 @@ finishInput(int exitstatus, void *arg)
|
227 | 237 | #endif
|
228 | 238 | {
|
229 | 239 | #ifdef USE_READLINE
|
230 |
| - if (useHistory) |
| 240 | + if (useHistory && psql_history) |
231 | 241 | {
|
232 |
| - char home[MAXPGPATH]; |
| 242 | + int hist_size; |
233 | 243 |
|
234 |
| - if (get_home_path(home)) |
235 |
| - { |
236 |
| - char *psql_history; |
237 |
| - int hist_size; |
238 |
| - |
239 |
| - hist_size = GetVariableNum(pset.vars, "HISTSIZE", -1, -1, true); |
240 |
| - if (hist_size >= 0) |
241 |
| - stifle_history(hist_size); |
242 |
| - |
243 |
| - psql_history = pg_malloc(strlen(home) + 1 + |
244 |
| - strlen(PSQLHISTORY) + 1); |
245 |
| - sprintf(psql_history, "%s/%s", home, PSQLHISTORY); |
246 |
| - write_history(psql_history); |
247 |
| - free(psql_history); |
248 |
| - } |
| 244 | + hist_size = GetVariableNum(pset.vars, "HISTSIZE", -1, -1, true); |
| 245 | + if (hist_size >= 0) |
| 246 | + stifle_history(hist_size); |
| 247 | + |
| 248 | + write_history(psql_history); |
| 249 | + free(psql_history); |
| 250 | + psql_history = NULL; |
249 | 251 | }
|
250 | 252 | #endif
|
251 | 253 | }
|
0 commit comments