|
3 | 3 | * |
4 | 4 | * Copyright (c) 2000-2010, PostgreSQL Global Development Group |
5 | 5 | * |
6 | | - * $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.162 2010/02/26 02:01:19 momjian Exp $ |
| 6 | + * $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.163 2010/03/06 15:28:09 mha Exp $ |
7 | 7 | */ |
8 | 8 | #include"postgres_fe.h" |
9 | 9 |
|
@@ -68,11 +68,12 @@ struct adhoc_opts |
68 | 68 | boolno_readline; |
69 | 69 | boolno_psqlrc; |
70 | 70 | boolsingle_txn; |
| 71 | +char*psqlrc; |
71 | 72 | }; |
72 | 73 |
|
73 | 74 | staticvoidparse_psql_options(intargc,char*argv[], |
74 | 75 | structadhoc_opts*options); |
75 | | -staticvoidprocess_psqlrc(char*argv0); |
| 76 | +staticvoidprocess_psqlrc(char*argv0,structadhoc_opts*options); |
76 | 77 | staticvoidprocess_psqlrc_file(char*filename); |
77 | 78 | staticvoidshowVersion(void); |
78 | 79 | staticvoidEstablishVariableSpace(void); |
@@ -247,8 +248,7 @@ main(int argc, char *argv[]) |
247 | 248 | */ |
248 | 249 | if (options.action==ACT_FILE) |
249 | 250 | { |
250 | | -if (!options.no_psqlrc) |
251 | | -process_psqlrc(argv[0]); |
| 251 | +process_psqlrc(argv[0],&options); |
252 | 252 |
|
253 | 253 | successResult=process_file(options.action_string,options.single_txn); |
254 | 254 | } |
@@ -291,8 +291,7 @@ main(int argc, char *argv[]) |
291 | 291 | */ |
292 | 292 | else |
293 | 293 | { |
294 | | -if (!options.no_psqlrc) |
295 | | -process_psqlrc(argv[0]); |
| 294 | +process_psqlrc(argv[0],&options); |
296 | 295 |
|
297 | 296 | connection_warnings(true); |
298 | 297 | if (!pset.quiet&& !pset.notty) |
@@ -355,6 +354,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options) |
355 | 354 | {"password",no_argument,NULL,'W'}, |
356 | 355 | {"expanded",no_argument,NULL,'x'}, |
357 | 356 | {"no-psqlrc",no_argument,NULL,'X'}, |
| 357 | +{"psqlrc",required_argument,NULL,1}, |
358 | 358 | {"help",no_argument,NULL,'?'}, |
359 | 359 | {NULL,0,NULL,0} |
360 | 360 | }; |
@@ -515,6 +515,9 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options) |
515 | 515 | case'X': |
516 | 516 | options->no_psqlrc= true; |
517 | 517 | break; |
| 518 | +case1: |
| 519 | +options->psqlrc=pg_strdup(optarg); |
| 520 | +break; |
518 | 521 | case'1': |
519 | 522 | options->single_txn= true; |
520 | 523 | break; |
@@ -563,20 +566,27 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options) |
563 | 566 | * Load .psqlrc file, if found. |
564 | 567 | */ |
565 | 568 | staticvoid |
566 | | -process_psqlrc(char*argv0) |
| 569 | +process_psqlrc(char*argv0,structadhoc_opts*options) |
567 | 570 | { |
568 | 571 | charhome[MAXPGPATH]; |
569 | 572 | charrc_file[MAXPGPATH]; |
570 | 573 | charmy_exec_path[MAXPGPATH]; |
571 | 574 | charetc_path[MAXPGPATH]; |
572 | 575 |
|
| 576 | +if (options->no_psqlrc) |
| 577 | +return; |
| 578 | + |
573 | 579 | find_my_exec(argv0,my_exec_path); |
574 | 580 | get_etc_path(my_exec_path,etc_path); |
575 | 581 |
|
576 | 582 | snprintf(rc_file,MAXPGPATH,"%s/%s",etc_path,SYSPSQLRC); |
577 | 583 | process_psqlrc_file(rc_file); |
578 | 584 |
|
579 | | -if (get_home_path(home)) |
| 585 | +if (options->psqlrc) |
| 586 | +{ |
| 587 | +process_psqlrc_file(options->psqlrc); |
| 588 | +} |
| 589 | +elseif (get_home_path(home)) |
580 | 590 | { |
581 | 591 | snprintf(rc_file,MAXPGPATH,"%s/%s",home,PSQLRC); |
582 | 592 | process_psqlrc_file(rc_file); |
|