--- src/bin/psql/startup.c Mon Nov 5 20:46:31 2001 +++ src/bin/psql/startup.c Wed May 8 02:52:43 2002 @@ -89,6 +89,7 @@ printSSLInfo(void); #endif +char *DecoreBeg, *DecoreEnd; /* * @@ -105,6 +106,8 @@ char *password = NULL; bool need_pass; + DecoreBeg = NULL; + DecoreEnd = NULL; #ifdef ENABLE_NLS setlocale(LC_ALL, ""); bindtextdomain("psql", LOCALEDIR); @@ -237,7 +240,7 @@ */ /* - * process file given by -f + * process file given by -f or -Q */ if (options.action == ACT_FILE && strcmp(options.action_string, "-") != 0) { @@ -369,19 +372,19 @@ 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); #ifdef HAVE_GETOPT_LONG - while ((c = getopt_long(argc, argv, "aAc:d:eEf:F:h:Hlno:p:P:qR:sStT:uU:v:VWxX?", long_options, &optindex)) != -1) + 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) #else /* not HAVE_GETOPT_LONG */ /* * Be sure to leave the '-' in here, so we can catch accidental long * options. */ - while ((c = getopt(argc, argv, "aAc:d:eEf:F:h:Hlno:p:P:qR:sStT:uU:v:VWxX?-")) != -1) + while ((c = getopt(argc, argv, "aAc:d:D:eEf:F:h:Hlno:p:P:qQ:R:sStT:uU:v:VWxX?-")) != -1) #endif /* not HAVE_GETOPT_LONG */ { switch (c) @@ -405,6 +408,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; @@ -464,6 +471,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; @@ -563,21 +576,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 option %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 option %s ignored\n"), + pset.progname, argv[optind]); - optind++; + optind++; + } } if (used_old_u_option && !QUIET()) @@ -588,7 +625,7 @@ /* - * Load .psqlrc file, if found. + * Load .desk/psqlrc file, if found. */ static void process_psqlrc(void) @@ -605,19 +642,19 @@ if (home) { - psqlrc = malloc(strlen(home) + 20); + psqlrc = malloc(strlen(home) + 26); if (!psqlrc) { fprintf(stderr, gettext("%s: out of memory\n"), pset.progname); exit(EXIT_FAILURE); } - sprintf(psqlrc, "%s/.psqlrc-" PG_VERSION, home); + sprintf(psqlrc, "%s/.desk/psqlrc-" PG_VERSION, home); if (access(psqlrc, R_OK) == 0) process_file(psqlrc); else { - sprintf(psqlrc, "%s/.psqlrc", home); + sprintf(psqlrc, "%s/.desk/psqlrc", home); if (access(psqlrc, R_OK) == 0) process_file(psqlrc); }