--- src/bin/psql/startup.c +++ src/bin/psql/startup.c @@ -37,7 +37,7 @@ #ifndef WIN32 #define SYSPSQLRC "psqlrc" -#define PSQLRC ".psqlrc" +#define PSQLRC ".desk/psqlrc" #else #define SYSPSQLRC "psqlrc" #define PSQLRC "psqlrc.conf" @@ -76,6 +76,7 @@ static void process_psqlrc_file(char *filename); static void showVersion(void); static void EstablishVariableSpace(void); +char *DecoreBeg, *DecoreEnd; /* * @@ -91,6 +92,8 @@ char *password_prompt = NULL; bool new_pass; + DecoreBeg = NULL; + DecoreEnd = NULL; set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("psql")); if (argc > 1) @@ -223,7 +226,7 @@ */ /* - * process file given by -f + * process file given by -f or -Q */ if (options.action == ACT_FILE && strcmp(options.action_string, "-") != 0) { @@ -343,10 +346,11 @@ extern char *optarg; extern int optind; int c; + bool sqlbang = false; memset(options, 0, sizeof *options); - while ((c = getopt_long(argc, argv, "aAc:d:eEf:F:h:HlL:no:p:P:qR:sStT:U:v:VwWxX?1", + while ((c = getopt_long(argc, argv, "aAc:d:D:eEf:F:h:HlL:no:p:P:qQ:R:sStT:U:v:VwWxX?1", long_options, &optindex)) != -1) { switch (c) @@ -370,6 +374,10 @@ case 'd': options->dbname = optarg; break; + case 'D': + if (DecoreBeg) DecoreEnd = optarg; + else DecoreBeg = optarg; + break; case 'e': SetVariable(pset.vars, "ECHO", "queries"); break; @@ -432,6 +440,12 @@ case 'q': SetVariableBool(pset.vars, "QUIET"); break; + case 'Q': + SetVariableBool(pset.vars, "ON_ERROR_STOP"); + options->action = ACT_FILE; + options->action_string = optarg; + sqlbang = true; + break; case 'R': pset.popt.topt.recordSep = pg_strdup(optarg); break; @@ -521,26 +535,50 @@ } } - /* - * if we still have arguments, use it as the database name and username - */ - while (argc - optind >= 1) + if (sqlbang) + { + char optname[] = "1"; + while (argc - optind >= 1) + { + if (optname[0] <= '9') + { + if (!SetVariable(pset.vars, optname, argv[optind])) + { + fprintf(stderr, "%s: could not set variable %s\n", + pset.progname, optname); + exit(EXIT_FAILURE); + } + } + else if (!pset.quiet) + fprintf(stderr, "%s: warning: extra option %s ignored\n", + pset.progname, argv[optind]); + optname[0]++; + optind++; + } + } + else { - if (!options->dbname) - options->dbname = argv[optind]; - else if (!options->username) - options->username = argv[optind]; - else if (!pset.quiet) - fprintf(stderr, _("%s: warning: extra command-line argument \"%s\" ignored\n"), - pset.progname, argv[optind]); + /* + * if we still have arguments, use it as the database name and username + */ + while (argc - optind >= 1) + { + if (!options->dbname) + options->dbname = argv[optind]; + else if (!options->username) + options->username = argv[optind]; + else if (!pset.quiet) + fprintf(stderr, _("%s: warning: extra command-line argument \"%s\" ignored\n"), + pset.progname, argv[optind]); - optind++; + optind++; + } } } /* - * Load .psqlrc file, if found. + * Load .desk/psqlrc file, if found. */ static void process_psqlrc(char *argv0)