--- src/bin/psql/startup.c +++ src/bin/psql/startup.c @@ -44,7 +44,7 @@ */ PsqlSettings pset; -#define PSQLRC ".psqlrc" +#define PSQLRC ".desk/psqlrc" /* * Structures to pass information between the option parsing routine @@ -75,6 +75,7 @@ struct adhoc_opts * options); static void process_psqlrc(void); static void showVersion(void); +char *DecoreBeg, *DecoreEnd; #ifdef USE_SSL static void printSSLInfo(void); @@ -100,6 +101,8 @@ char *password = NULL; bool need_pass; + DecoreBeg = NULL; + DecoreEnd = NULL; setlocale(LC_ALL, ""); #ifdef ENABLE_NLS bindtextdomain("psql", LOCALEDIR); @@ -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) { @@ -348,11 +351,11 @@ extern char *optarg; extern int optind; int c; - bool used_old_u_option = false; + bool used_old_u_option = false, sqlbang = false; memset(options, 0, sizeof *options); - while ((c = getopt_long(argc, argv, "aAc:d:eEf:F:h:Hlno:p:P:qR:sStT:uU:v:VWxX?", + while ((c = getopt_long(argc, argv, "aAc:d:D:eEf:F:h:Hlno:p:P:qQ:R:sStT:uU:v:VWxX?", long_options, &optindex)) != -1) { switch (c) @@ -376,6 +379,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; @@ -435,6 +442,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 = xstrdup(optarg); break; @@ -525,21 +538,45 @@ } } - /* - * 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 (!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 (!QUIET()) - fprintf(stderr, gettext("%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 (!QUIET()) + fprintf(stderr, gettext("%s: warning: extra command-line argument \"%s\" ignored\n"), + pset.progname, argv[optind]); - optind++; + optind++; + } } if (used_old_u_option && !QUIET()) @@ -550,7 +587,7 @@ /* - * Load .psqlrc file, if found. + * Load .desk/psqlrc file, if found. */ static void process_psqlrc(void)