diff options
| author | Bruce Momjian <bruce@momjian.us> | 2006-10-04 00:30:14 +0000 |
|---|---|---|
| committer | Bruce Momjian <bruce@momjian.us> | 2006-10-04 00:30:14 +0000 |
| commit | f99a569a2ee3763b4ae174e81250c95ca0fdcbb6 (patch) | |
| tree | 76e6371fe8b347c73d7020c0bc54b9fba519dc10 /src/bin | |
| parent | 451e419e9852cdf9d7e7cefc09d5355abb3405e9 (diff) | |
| download | postgresql-f99a569a2ee3763b4ae174e81250c95ca0fdcbb6.tar.gz | |
pgindent run for 8.2.
Diffstat (limited to 'src/bin')
32 files changed, 975 insertions, 896 deletions
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index 70f481c372..f001d43b25 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -42,7 +42,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * Portions taken from FreeBSD. * - * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.123 2006/10/03 21:11:55 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.124 2006/10/04 00:30:04 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -120,7 +120,7 @@ static int output_errno = 0; /* defaults */ static int n_connections = 10; static int n_buffers = 50; -static int n_fsm_pages = 20000; +static int n_fsm_pages = 20000; /* * Warning messages for authentication methods @@ -191,8 +191,9 @@ static int locale_date_order(const char *locale); static bool chklocale(const char *locale); static void setlocales(void); static void usage(const char *progname); + #ifdef WIN32 -static int CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION *processInfo); +static int CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION * processInfo); #endif @@ -1102,21 +1103,21 @@ test_config_settings(void) { /* * These macros define the minimum shared_buffers we want for a given - * max_connections value, and the max_fsm_pages setting to be used for - * a given shared_buffers value. The arrays show the settings to try. + * max_connections value, and the max_fsm_pages setting to be used for a + * given shared_buffers value. The arrays show the settings to try. * */ -#define MIN_BUFS_FOR_CONNS(nconns) ((nconns) * 10 * (BLCKSZ/1024)) -#define FSM_FOR_BUFS(nbuffers) ((nbuffers) > 1000 ? 50 * (nbuffers) : 20000) +#define MIN_BUFS_FOR_CONNS(nconns) ((nconns) * 10 * (BLCKSZ/1024)) +#define FSM_FOR_BUFS(nbuffers) ((nbuffers) > 1000 ? 50 * (nbuffers) : 20000) static const int trial_conns[] = { 100, 50, 40, 30, 20, 10 }; /* - * Candidate values for shared_buffers in kB. When the value is - * divisible by 1024, we write it in MB-unit to configuration files. + * Candidate values for shared_buffers in kB. When the value is divisible + * by 1024, we write it in MB-unit to configuration files. */ static const int trial_bufs[] = { 32768, 28672, 24576, 20480, 16384, 12288, @@ -1124,15 +1125,15 @@ test_config_settings(void) }; char cmd[MAXPGPATH]; - const int connslen = sizeof(trial_conns) / sizeof(int); - const int bufslen = sizeof(trial_bufs) / sizeof(int); + const int connslen = sizeof(trial_conns) / sizeof(int); + const int bufslen = sizeof(trial_bufs) / sizeof(int); int i, status, test_conns, test_buffs, - test_max_fsm, - ok_buffers = 0; - + test_max_fsm, + ok_buffers = 0; + printf(_("selecting default max_connections ... ")); fflush(stdout); @@ -1195,7 +1196,7 @@ test_config_settings(void) n_fsm_pages = FSM_FOR_BUFS(n_buffers); if (n_buffers % 1024 == 0) - printf("%dMB/%d\n", n_buffers/1024, n_fsm_pages); + printf("%dMB/%d\n", n_buffers / 1024, n_fsm_pages); else printf("%dkB/%d\n", n_buffers, n_fsm_pages); } @@ -1221,7 +1222,7 @@ setup_config(void) conflines = replace_token(conflines, "#max_connections = 100", repltok); if (n_buffers % 1024 == 0) - snprintf(repltok, sizeof(repltok), "shared_buffers = %dMB", n_buffers/1024); + snprintf(repltok, sizeof(repltok), "shared_buffers = %dMB", n_buffers / 1024); else snprintf(repltok, sizeof(repltok), "shared_buffers = %dkB", n_buffers); conflines = replace_token(conflines, "#shared_buffers = 32MB", repltok); @@ -1250,7 +1251,8 @@ setup_config(void) escape_quotes(lc_time)); conflines = replace_token(conflines, "#lc_time = 'C'", repltok); - switch (locale_date_order(lc_time)) { + switch (locale_date_order(lc_time)) + { case DATEORDER_YMD: strcpy(repltok, "datestyle = 'iso, ymd'"); break; @@ -2083,7 +2085,7 @@ check_ok(void) * * Note: this is used to process both postgresql.conf entries and SQL * string literals. Since postgresql.conf strings are defined to treat - * backslashes as escapes, we have to double backslashes here. Hence, + * backslashes as escapes, we have to double backslashes here. Hence, * when using this for a SQL string literal, use E'' syntax. * * We do not need to worry about encoding considerations because all @@ -2245,8 +2247,9 @@ setlocales(void) } #ifdef WIN32 -typedef BOOL (WINAPI *__CreateRestrictedToken)(HANDLE, DWORD, DWORD, PSID_AND_ATTRIBUTES, DWORD, PLUID_AND_ATTRIBUTES, DWORD, PSID_AND_ATTRIBUTES, PHANDLE); -#define DISABLE_MAX_PRIVILEGE 0x1 +typedef BOOL(WINAPI * __CreateRestrictedToken) (HANDLE, DWORD, DWORD, PSID_AND_ATTRIBUTES, DWORD, PLUID_AND_ATTRIBUTES, DWORD, PSID_AND_ATTRIBUTES, PHANDLE); + +#define DISABLE_MAX_PRIVILEGE 0x1 /* * Create a restricted token and execute the specified process with it. @@ -2256,75 +2259,75 @@ typedef BOOL (WINAPI *__CreateRestrictedToken)(HANDLE, DWORD, DWORD, PSID_AND_AT * On NT4, or any other system not containing the required functions, will * NOT execute anything. */ -static int -CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION *processInfo) +static int +CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION * processInfo) { - BOOL b; - STARTUPINFO si; - HANDLE origToken; - HANDLE restrictedToken; - SID_IDENTIFIER_AUTHORITY NtAuthority = {SECURITY_NT_AUTHORITY}; - SID_AND_ATTRIBUTES dropSids[2]; - __CreateRestrictedToken _CreateRestrictedToken = NULL; - HANDLE Advapi32Handle; - - ZeroMemory(&si, sizeof(si)); - si.cb = sizeof(si); - - Advapi32Handle = LoadLibrary("ADVAPI32.DLL"); - if (Advapi32Handle != NULL) - { - _CreateRestrictedToken = (__CreateRestrictedToken) GetProcAddress(Advapi32Handle, "CreateRestrictedToken"); - } - - if (_CreateRestrictedToken == NULL) - { - fprintf(stderr,"WARNING: Unable to create restricted tokens on this platform\n"); - if (Advapi32Handle != NULL) - FreeLibrary(Advapi32Handle); - return 0; - } - - /* Open the current token to use as a base for the restricted one */ - if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &origToken)) - { - fprintf(stderr, "Failed to open process token: %lu\n", GetLastError()); - return 0; - } - - /* Allocate list of SIDs to remove */ - ZeroMemory(&dropSids, sizeof(dropSids)); - if (!AllocateAndInitializeSid(&NtAuthority, 2, - SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0,0,0,0,0, - 0, &dropSids[0].Sid) || - !AllocateAndInitializeSid(&NtAuthority, 2, - SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_POWER_USERS, 0,0,0,0,0, - 0, &dropSids[1].Sid)) - { - fprintf(stderr,"Failed to allocate SIDs: %lu\n", GetLastError()); - return 0; - } - - b = _CreateRestrictedToken(origToken, - DISABLE_MAX_PRIVILEGE, - sizeof(dropSids)/sizeof(dropSids[0]), - dropSids, - 0, NULL, - 0, NULL, - &restrictedToken); - - FreeSid(dropSids[1].Sid); - FreeSid(dropSids[0].Sid); - CloseHandle(origToken); - FreeLibrary(Advapi32Handle); - - if (!b) - { - fprintf(stderr,"Failed to create restricted token: %lu\n", GetLastError()); - return 0; - } - - return CreateProcessAsUser(restrictedToken, NULL, cmd, NULL, NULL, TRUE, 0, NULL, NULL, &si, processInfo); + BOOL b; + STARTUPINFO si; + HANDLE origToken; + HANDLE restrictedToken; + SID_IDENTIFIER_AUTHORITY NtAuthority = {SECURITY_NT_AUTHORITY}; + SID_AND_ATTRIBUTES dropSids[2]; + __CreateRestrictedToken _CreateRestrictedToken = NULL; + HANDLE Advapi32Handle; + + ZeroMemory(&si, sizeof(si)); + si.cb = sizeof(si); + + Advapi32Handle = LoadLibrary("ADVAPI32.DLL"); + if (Advapi32Handle != NULL) + { + _CreateRestrictedToken = (__CreateRestrictedToken) GetProcAddress(Advapi32Handle, "CreateRestrictedToken"); + } + + if (_CreateRestrictedToken == NULL) + { + fprintf(stderr, "WARNING: Unable to create restricted tokens on this platform\n"); + if (Advapi32Handle != NULL) + FreeLibrary(Advapi32Handle); + return 0; + } + + /* Open the current token to use as a base for the restricted one */ + if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &origToken)) + { + fprintf(stderr, "Failed to open process token: %lu\n", GetLastError()); + return 0; + } + + /* Allocate list of SIDs to remove */ + ZeroMemory(&dropSids, sizeof(dropSids)); + if (!AllocateAndInitializeSid(&NtAuthority, 2, + SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, + 0, &dropSids[0].Sid) || + !AllocateAndInitializeSid(&NtAuthority, 2, + SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_POWER_USERS, 0, 0, 0, 0, 0, + 0, &dropSids[1].Sid)) + { + fprintf(stderr, "Failed to allocate SIDs: %lu\n", GetLastError()); + return 0; + } + + b = _CreateRestrictedToken(origToken, + DISABLE_MAX_PRIVILEGE, + sizeof(dropSids) / sizeof(dropSids[0]), + dropSids, + 0, NULL, + 0, NULL, + &restrictedToken); + + FreeSid(dropSids[1].Sid); + FreeSid(dropSids[0].Sid); + CloseHandle(origToken); + FreeLibrary(Advapi32Handle); + + if (!b) + { + fprintf(stderr, "Failed to create restricted token: %lu\n", GetLastError()); + return 0; + } + + return CreateProcessAsUser(restrictedToken, NULL, cmd, NULL, NULL, TRUE, 0, NULL, NULL, &si, processInfo); } #endif @@ -2382,7 +2385,7 @@ main(int argc, char *argv[]) {"lc-messages", required_argument, NULL, 7}, {"no-locale", no_argument, NULL, 8}, {"auth", required_argument, NULL, 'A'}, - {"pwprompt", no_argument, NULL, 'W'}, + {"pwprompt", no_argument, NULL, 'W'}, {"pwfile", required_argument, NULL, 9}, {"username", required_argument, NULL, 'U'}, {"help", no_argument, NULL, '?'}, @@ -2398,13 +2401,14 @@ main(int argc, char *argv[]) ret; int option_index; char *short_version; - char *effective_user; + char *effective_user; char *pgdenv; /* PGDATA value gotten from and sent to * environment */ char bin_dir[MAXPGPATH]; char *pg_data_native; + #ifdef WIN32 - char *restrict_env; + char *restrict_env; #endif static const char *subdirs[] = { "global", @@ -2592,43 +2596,47 @@ main(int argc, char *argv[]) canonicalize_path(pg_data); #ifdef WIN32 - /* - * Before we execute another program, make sure that we are running with a - * restricted token. If not, re-execute ourselves with one. - */ - if ((restrict_env = getenv("PG_RESTRICT_EXEC")) == NULL - || strcmp(restrict_env,"1") != 0) - { - PROCESS_INFORMATION pi; - char *cmdline; - - ZeroMemory(&pi, sizeof(pi)); + /* + * Before we execute another program, make sure that we are running with a + * restricted token. If not, re-execute ourselves with one. + */ - cmdline = xstrdup(GetCommandLine()); + if ((restrict_env = getenv("PG_RESTRICT_EXEC")) == NULL + || strcmp(restrict_env, "1") != 0) + { + PROCESS_INFORMATION pi; + char *cmdline; + + ZeroMemory(&pi, sizeof(pi)); + + cmdline = xstrdup(GetCommandLine()); putenv("PG_RESTRICT_EXEC=1"); - - if (!CreateRestrictedProcess(cmdline, &pi)) - { - fprintf(stderr,"Failed to re-exec with restricted token: %lu.\n", GetLastError()); - } - else - { - /* Successfully re-execed. Now wait for child process to capture exitcode. */ - DWORD x; - - CloseHandle(pi.hThread); - WaitForSingleObject(pi.hProcess, INFINITE); - - if (!GetExitCodeProcess(pi.hProcess, &x)) - { - fprintf(stderr,"Failed to get exit code from subprocess: %lu\n", GetLastError()); - exit(1); - } - exit(x); - } - } + + if (!CreateRestrictedProcess(cmdline, &pi)) + { + fprintf(stderr, "Failed to re-exec with restricted token: %lu.\n", GetLastError()); + } + else + { + /* + * Successfully re-execed. Now wait for child process to capture + * exitcode. + */ + DWORD x; + + CloseHandle(pi.hThread); + WaitForSingleObject(pi.hProcess, INFINITE); + + if (!GetExitCodeProcess(pi.hProcess, &x)) + { + fprintf(stderr, "Failed to get exit code from subprocess: %lu\n", GetLastError()); + exit(1); + } + exit(x); + } + } #endif /* diff --git a/src/bin/pg_config/pg_config.c b/src/bin/pg_config/pg_config.c index edd4a6af36..788ffed786 100644 --- a/src/bin/pg_config/pg_config.c +++ b/src/bin/pg_config/pg_config.c @@ -17,7 +17,7 @@ * * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/pg_config/pg_config.c,v 1.21 2006/09/27 16:19:42 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/pg_config/pg_config.c,v 1.22 2006/10/04 00:30:04 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -43,10 +43,10 @@ cleanup_path(char *path) char *ptr; /* - * GetShortPathName() will fail if the path does not exist, or short names - * are disabled on this file system. In both cases, we just return the - * original path. This is particularly useful for --sysconfdir, which - * might not exist. + * GetShortPathName() will fail if the path does not exist, or short names + * are disabled on this file system. In both cases, we just return the + * original path. This is particularly useful for --sysconfdir, which + * might not exist. */ GetShortPathName(path, path, MAXPGPATH - 1); diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c index c94fe04a54..728538b971 100644 --- a/src/bin/pg_ctl/pg_ctl.c +++ b/src/bin/pg_ctl/pg_ctl.c @@ -4,7 +4,7 @@ * * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.72 2006/09/24 16:59:45 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.73 2006/10/04 00:30:04 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -119,7 +119,7 @@ static void pgwin32_SetServiceStatus(DWORD); static void WINAPI pgwin32_ServiceHandler(DWORD); static void WINAPI pgwin32_ServiceMain(DWORD, LPTSTR *); static void pgwin32_doRunAsService(void); -static int CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION *processInfo); +static int CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION * processInfo); #endif static pgpid_t get_pgpid(void); static char **readfile(const char *path); @@ -336,7 +336,9 @@ static int start_postmaster(void) { char cmd[MAXPGPATH]; + #ifndef WIN32 + /* * Since there might be quotes to handle here, it is easier simply to pass * everything to a shell to process them. @@ -345,36 +347,36 @@ start_postmaster(void) snprintf(cmd, MAXPGPATH, "%s\"%s\" %s%s < \"%s\" >> \"%s\" 2>&1 &%s", SYSTEMQUOTE, postgres_path, pgdata_opt, post_opts, DEVNULL, log_file, SYSTEMQUOTE); - else + else snprintf(cmd, MAXPGPATH, "%s\"%s\" %s%s < \"%s\" 2>&1 &%s", SYSTEMQUOTE, postgres_path, pgdata_opt, post_opts, DEVNULL, SYSTEMQUOTE); return system(cmd); - -#else /* WIN32 */ - /* - * On win32 we don't use system(). So we don't need to use & - * (which would be START /B on win32). However, we still call the shell - * (CMD.EXE) with it to handle redirection etc. - */ - PROCESS_INFORMATION pi; - - if (log_file != NULL) - snprintf(cmd, MAXPGPATH, "CMD /C %s\"%s\" %s%s < \"%s\" >> \"%s\" 2>&1%s", +#else /* WIN32 */ + + /* + * On win32 we don't use system(). So we don't need to use & (which would + * be START /B on win32). However, we still call the shell (CMD.EXE) with + * it to handle redirection etc. + */ + PROCESS_INFORMATION pi; + + if (log_file != NULL) + snprintf(cmd, MAXPGPATH, "CMD /C %s\"%s\" %s%s < \"%s\" >> \"%s\" 2>&1%s", SYSTEMQUOTE, postgres_path, pgdata_opt, post_opts, DEVNULL, log_file, SYSTEMQUOTE); - else - snprintf(cmd, MAXPGPATH, "CMD /C %s\"%s\" %s%s < \"%s\" 2>&1%s", + else + snprintf(cmd, MAXPGPATH, "CMD /C %s\"%s\" %s%s < \"%s\" 2>&1%s", SYSTEMQUOTE, postgres_path, pgdata_opt, post_opts, DEVNULL, SYSTEMQUOTE); - if (!CreateRestrictedProcess(cmd, &pi)) - return GetLastError(); - CloseHandle(pi.hProcess); - CloseHandle(pi.hThread); - return 0; -#endif /* WIN32 */ + if (!CreateRestrictedProcess(cmd, &pi)) + return GetLastError(); + CloseHandle(pi.hProcess); + CloseHandle(pi.hThread); + return 0; +#endif /* WIN32 */ } @@ -1162,15 +1164,15 @@ pgwin32_doRunAsService(void) * also load the couple of functions that *do* exist in minwg headers but not * on NT4. That way, we don't break on NT4. */ -typedef BOOL (WINAPI *__CreateRestrictedToken)(HANDLE, DWORD, DWORD, PSID_AND_ATTRIBUTES, DWORD, PLUID_AND_ATTRIBUTES, DWORD, PSID_AND_ATTRIBUTES, PHANDLE); -typedef BOOL (WINAPI *__IsProcessInJob)(HANDLE, HANDLE, PBOOL); -typedef HANDLE (WINAPI *__CreateJobObject)(LPSECURITY_ATTRIBUTES, LPCTSTR); -typedef BOOL (WINAPI *__SetInformationJobObject)(HANDLE, JOBOBJECTINFOCLASS, LPVOID, DWORD); -typedef BOOL (WINAPI *__AssignProcessToJobObject)(HANDLE, HANDLE); -typedef BOOL (WINAPI *__QueryInformationJobObject)(HANDLE, JOBOBJECTINFOCLASS, LPVOID, DWORD, LPDWORD); +typedef BOOL(WINAPI * __CreateRestrictedToken) (HANDLE, DWORD, DWORD, PSID_AND_ATTRIBUTES, DWORD, PLUID_AND_ATTRIBUTES, DWORD, PSID_AND_ATTRIBUTES, PHANDLE); +typedef BOOL(WINAPI * __IsProcessInJob) (HANDLE, HANDLE, PBOOL); +typedef HANDLE(WINAPI * __CreateJobObject) (LPSECURITY_ATTRIBUTES, LPCTSTR); +typedef BOOL(WINAPI * __SetInformationJobObject) (HANDLE, JOBOBJECTINFOCLASS, LPVOID, DWORD); +typedef BOOL(WINAPI * __AssignProcessToJobObject) (HANDLE, HANDLE); +typedef BOOL(WINAPI * __QueryInformationJobObject) (HANDLE, JOBOBJECTINFOCLASS, LPVOID, DWORD, LPDWORD); /* Windows API define missing from MingW headers */ -#define DISABLE_MAX_PRIVILEGE 0x1 +#define DISABLE_MAX_PRIVILEGE 0x1 /* * Create a restricted token, a job object sandbox, and execute the specified @@ -1185,165 +1187,178 @@ typedef BOOL (WINAPI *__QueryInformationJobObject)(HANDLE, JOBOBJECTINFOCLASS, L * automatically destroyed when pg_ctl exits. */ static int -CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION *processInfo) +CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION * processInfo) { - int r; - BOOL b; - STARTUPINFO si; - HANDLE origToken; - HANDLE restrictedToken; - SID_IDENTIFIER_AUTHORITY NtAuthority = {SECURITY_NT_AUTHORITY}; - SID_AND_ATTRIBUTES dropSids[2]; - - /* Functions loaded dynamically */ - __CreateRestrictedToken _CreateRestrictedToken = NULL; - __IsProcessInJob _IsProcessInJob = NULL; - __CreateJobObject _CreateJobObject = NULL; - __SetInformationJobObject _SetInformationJobObject = NULL; - __AssignProcessToJobObject _AssignProcessToJobObject = NULL; - __QueryInformationJobObject _QueryInformationJobObject = NULL; - HANDLE Kernel32Handle; - HANDLE Advapi32Handle; - - ZeroMemory(&si, sizeof(si)); - si.cb = sizeof(si); - - Advapi32Handle = LoadLibrary("ADVAPI32.DLL"); - if (Advapi32Handle != NULL) - { - _CreateRestrictedToken = (__CreateRestrictedToken) GetProcAddress(Advapi32Handle, "CreateRestrictedToken"); - } - - if (_CreateRestrictedToken == NULL) - { - /* NT4 doesn't have CreateRestrictedToken, so just call ordinary CreateProcess */ - write_stderr("WARNING: Unable to create restricted tokens on this platform\n"); - if (Advapi32Handle != NULL) - FreeLibrary(Advapi32Handle); - return CreateProcess(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, processInfo); - } - - /* Open the current token to use as a base for the restricted one */ - if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &origToken)) - { - write_stderr("Failed to open process token: %lu\n", GetLastError()); - return 0; - } - - /* Allocate list of SIDs to remove */ - ZeroMemory(&dropSids, sizeof(dropSids)); - if (!AllocateAndInitializeSid(&NtAuthority, 2, - SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0,0,0,0,0, - 0, &dropSids[0].Sid) || - !AllocateAndInitializeSid(&NtAuthority, 2, - SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_POWER_USERS, 0,0,0,0,0, - 0, &dropSids[1].Sid)) - { - write_stderr("Failed to allocate SIDs: %lu\n", GetLastError()); - return 0; - } - - b = _CreateRestrictedToken(origToken, - DISABLE_MAX_PRIVILEGE, - sizeof(dropSids)/sizeof(dropSids[0]), - dropSids, - 0, NULL, - 0, NULL, - &restrictedToken); - - FreeSid(dropSids[1].Sid); - FreeSid(dropSids[0].Sid); - CloseHandle(origToken); - FreeLibrary(Advapi32Handle); - - if (!b) - { - write_stderr("Failed to create restricted token: %lu\n", GetLastError()); - return 0; - } - - r = CreateProcessAsUser(restrictedToken, NULL, cmd, NULL, NULL, TRUE, CREATE_SUSPENDED, NULL, NULL, &si, processInfo); - - Kernel32Handle = LoadLibrary("KERNEL32.DLL"); - if (Kernel32Handle != NULL) - { - _IsProcessInJob = (__IsProcessInJob) GetProcAddress(Kernel32Handle, "IsProcessInJob"); - _CreateJobObject = (__CreateJobObject) GetProcAddress(Kernel32Handle, "CreateJobObjectA"); - _SetInformationJobObject = (__SetInformationJobObject) GetProcAddress(Kernel32Handle, "SetInformationJobObject"); - _AssignProcessToJobObject = (__AssignProcessToJobObject) GetProcAddress(Kernel32Handle, "AssignProcessToJobObject"); - _QueryInformationJobObject = (__QueryInformationJobObject) GetProcAddress(Kernel32Handle, "QueryInformationJobObject"); - } - - /* Verify that we found all functions */ - if (_IsProcessInJob == NULL || _CreateJobObject == NULL || _SetInformationJobObject == NULL || _AssignProcessToJobObject == NULL || _QueryInformationJobObject == NULL) - { - /* IsProcessInJob() is not available on < WinXP, so there is no need to log the error every time in that case */ + int r; + BOOL b; + STARTUPINFO si; + HANDLE origToken; + HANDLE restrictedToken; + SID_IDENTIFIER_AUTHORITY NtAuthority = {SECURITY_NT_AUTHORITY}; + SID_AND_ATTRIBUTES dropSids[2]; + + /* Functions loaded dynamically */ + __CreateRestrictedToken _CreateRestrictedToken = NULL; + __IsProcessInJob _IsProcessInJob = NULL; + __CreateJobObject _CreateJobObject = NULL; + __SetInformationJobObject _SetInformationJobObject = NULL; + __AssignProcessToJobObject _AssignProcessToJobObject = NULL; + __QueryInformationJobObject _QueryInformationJobObject = NULL; + HANDLE Kernel32Handle; + HANDLE Advapi32Handle; + + ZeroMemory(&si, sizeof(si)); + si.cb = sizeof(si); + + Advapi32Handle = LoadLibrary("ADVAPI32.DLL"); + if (Advapi32Handle != NULL) + { + _CreateRestrictedToken = (__CreateRestrictedToken) GetProcAddress(Advapi32Handle, "CreateRestrictedToken"); + } + + if (_CreateRestrictedToken == NULL) + { + /* + * NT4 doesn't have CreateRestrictedToken, so just call ordinary + * CreateProcess + */ + write_stderr("WARNING: Unable to create restricted tokens on this platform\n"); + if (Advapi32Handle != NULL) + FreeLibrary(Advapi32Handle); + return CreateProcess(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, processInfo); + } + + /* Open the current token to use as a base for the restricted one */ + if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &origToken)) + { + write_stderr("Failed to open process token: %lu\n", GetLastError()); + return 0; + } + + /* Allocate list of SIDs to remove */ + ZeroMemory(&dropSids, sizeof(dropSids)); + if (!AllocateAndInitializeSid(&NtAuthority, 2, + SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, + 0, &dropSids[0].Sid) || + !AllocateAndInitializeSid(&NtAuthority, 2, + SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_POWER_USERS, 0, 0, 0, 0, 0, + 0, &dropSids[1].Sid)) + { + write_stderr("Failed to allocate SIDs: %lu\n", GetLastError()); + return 0; + } + + b = _CreateRestrictedToken(origToken, + DISABLE_MAX_PRIVILEGE, + sizeof(dropSids) / sizeof(dropSids[0]), + dropSids, + 0, NULL, + 0, NULL, + &restrictedToken); + + FreeSid(dropSids[1].Sid); + FreeSid(dropSids[0].Sid); + CloseHandle(origToken); + FreeLibrary(Advapi32Handle); + + if (!b) + { + write_stderr("Failed to create restricted token: %lu\n", GetLastError()); + return 0; + } + + r = CreateProcessAsUser(restrictedToken, NULL, cmd, NULL, NULL, TRUE, CREATE_SUSPENDED, NULL, NULL, &si, processInfo); + + Kernel32Handle = LoadLibrary("KERNEL32.DLL"); + if (Kernel32Handle != NULL) + { + _IsProcessInJob = (__IsProcessInJob) GetProcAddress(Kernel32Handle, "IsProcessInJob"); + _CreateJobObject = (__CreateJobObject) GetProcAddress(Kernel32Handle, "CreateJobObjectA"); + _SetInformationJobObject = (__SetInformationJobObject) GetProcAddress(Kernel32Handle, "SetInformationJobObject"); + _AssignProcessToJobObject = (__AssignProcessToJobObject) GetProcAddress(Kernel32Handle, "AssignProcessToJobObject"); + _QueryInformationJobObject = (__QueryInformationJobObject) GetProcAddress(Kernel32Handle, "QueryInformationJobObject"); + } + + /* Verify that we found all functions */ + if (_IsProcessInJob == NULL || _CreateJobObject == NULL || _SetInformationJobObject == NULL || _AssignProcessToJobObject == NULL || _QueryInformationJobObject == NULL) + { + /* + * IsProcessInJob() is not available on < WinXP, so there is no need + * to log the error every time in that case + */ OSVERSIONINFO osv; osv.dwOSVersionInfoSize = sizeof(osv); - if (!GetVersionEx(&osv) || /* could not get version */ - (osv.dwMajorVersion == 5 && osv.dwMinorVersion > 0) || /* 5.1=xp, 5.2=2003, etc */ - osv.dwMajorVersion > 5) /* anything newer should have the API */ - /* Log error if we can't get version, or if we're on WinXP/2003 or newer */ + if (!GetVersionEx(&osv) || /* could not get version */ + (osv.dwMajorVersion == 5 && osv.dwMinorVersion > 0) || /* 5.1=xp, 5.2=2003, etc */ + osv.dwMajorVersion > 5) /* anything newer should have the API */ + + /* + * Log error if we can't get version, or if we're on WinXP/2003 or + * newer + */ write_stderr("WARNING: Unable to locate all job object functions in system API!\n"); - } - else - { - BOOL inJob; - if (_IsProcessInJob(processInfo->hProcess, NULL, &inJob)) - { - if (!inJob) - { - /* Job objects are working, and the new process isn't in one, so we can create one safely. - If any problems show up when setting it, we're going to ignore them. */ - HANDLE job; - char jobname[128]; - - sprintf(jobname,"PostgreSQL_%lu", processInfo->dwProcessId); - - job = _CreateJobObject(NULL, jobname); - if (job) - { - JOBOBJECT_BASIC_LIMIT_INFORMATION basicLimit; - JOBOBJECT_BASIC_UI_RESTRICTIONS uiRestrictions; - JOBOBJECT_SECURITY_LIMIT_INFORMATION securityLimit; - - ZeroMemory(&basicLimit, sizeof(basicLimit)); - ZeroMemory(&uiRestrictions, sizeof(uiRestrictions)); - ZeroMemory(&securityLimit, sizeof(securityLimit)); - - basicLimit.LimitFlags = JOB_OBJECT_LIMIT_DIE_ON_UNHANDLED_EXCEPTION | JOB_OBJECT_LIMIT_PRIORITY_CLASS; - basicLimit.PriorityClass = NORMAL_PRIORITY_CLASS; - _SetInformationJobObject(job, JobObjectBasicLimitInformation, &basicLimit, sizeof(basicLimit)); - - uiRestrictions.UIRestrictionsClass = JOB_OBJECT_UILIMIT_DESKTOP | JOB_OBJECT_UILIMIT_DISPLAYSETTINGS | - JOB_OBJECT_UILIMIT_EXITWINDOWS | JOB_OBJECT_UILIMIT_HANDLES | JOB_OBJECT_UILIMIT_READCLIPBOARD | - JOB_OBJECT_UILIMIT_SYSTEMPARAMETERS | JOB_OBJECT_UILIMIT_WRITECLIPBOARD; - _SetInformationJobObject(job, JobObjectBasicUIRestrictions, &uiRestrictions, sizeof(uiRestrictions)); - - securityLimit.SecurityLimitFlags = JOB_OBJECT_SECURITY_NO_ADMIN | JOB_OBJECT_SECURITY_ONLY_TOKEN; - securityLimit.JobToken = restrictedToken; - _SetInformationJobObject(job, JobObjectSecurityLimitInformation, &securityLimit, sizeof(securityLimit)); - - _AssignProcessToJobObject(job, processInfo->hProcess); - } - } - } - } - - CloseHandle(restrictedToken); - - ResumeThread(processInfo->hThread); - - FreeLibrary(Kernel32Handle); - - /* + } + else + { + BOOL inJob; + + if (_IsProcessInJob(processInfo->hProcess, NULL, &inJob)) + { + if (!inJob) + { + /* + * Job objects are working, and the new process isn't in one, + * so we can create one safely. If any problems show up when + * setting it, we're going to ignore them. + */ + HANDLE job; + char jobname[128]; + + sprintf(jobname, "PostgreSQL_%lu", processInfo->dwProcessId); + + job = _CreateJobObject(NULL, jobname); + if (job) + { + JOBOBJECT_BASIC_LIMIT_INFORMATION basicLimit; + JOBOBJECT_BASIC_UI_RESTRICTIONS uiRestrictions; + JOBOBJECT_SECURITY_LIMIT_INFORMATION securityLimit; + + ZeroMemory(&basicLimit, sizeof(basicLimit)); + ZeroMemory(&uiRestrictions, sizeof(uiRestrictions)); + ZeroMemory(&securityLimit, sizeof(securityLimit)); + + basicLimit.LimitFlags = JOB_OBJECT_LIMIT_DIE_ON_UNHANDLED_EXCEPTION | JOB_OBJECT_LIMIT_PRIORITY_CLASS; + basicLimit.PriorityClass = NORMAL_PRIORITY_CLASS; + _SetInformationJobObject(job, JobObjectBasicLimitInformation, &basicLimit, sizeof(basicLimit)); + + uiRestrictions.UIRestrictionsClass = JOB_OBJECT_UILIMIT_DESKTOP | JOB_OBJECT_UILIMIT_DISPLAYSETTINGS | + JOB_OBJECT_UILIMIT_EXITWINDOWS | JOB_OBJECT_UILIMIT_HANDLES | JOB_OBJECT_UILIMIT_READCLIPBOARD | + JOB_OBJECT_UILIMIT_SYSTEMPARAMETERS | JOB_OBJECT_UILIMIT_WRITECLIPBOARD; + _SetInformationJobObject(job, JobObjectBasicUIRestrictions, &uiRestrictions, sizeof(uiRestrictions)); + + securityLimit.SecurityLimitFlags = JOB_OBJECT_SECURITY_NO_ADMIN | JOB_OBJECT_SECURITY_ONLY_TOKEN; + securityLimit.JobToken = restrictedToken; + _SetInformationJobObject(job, JobObjectSecurityLimitInformation, &securityLimit, sizeof(securityLimit)); + + _AssignProcessToJobObject(job, processInfo->hProcess); + } + } + } + } + + CloseHandle(restrictedToken); + + ResumeThread(processInfo->hThread); + + FreeLibrary(Kernel32Handle); + + /* * We intentionally don't close the job object handle, because we want the * object to live on until pg_ctl shuts down. */ - return r; + return r; } - #endif static void @@ -1722,13 +1737,13 @@ main(int argc, char **argv) do_wait = false; } - if (pg_data) - { - snprintf(def_postopts_file, MAXPGPATH, "%s/postmaster.opts.default", pg_data); - snprintf(postopts_file, MAXPGPATH, "%s/postmaster.opts", pg_data); - snprintf(pid_file, MAXPGPATH, "%s/postmaster.pid", pg_data); - snprintf(conf_file, MAXPGPATH, "%s/postgresql.conf", pg_data); - } + if (pg_data) + { + snprintf(def_postopts_file, MAXPGPATH, "%s/postmaster.opts.default", pg_data); + snprintf(postopts_file, MAXPGPATH, "%s/postmaster.opts", pg_data); + snprintf(pid_file, MAXPGPATH, "%s/postmaster.pid", pg_data); + snprintf(conf_file, MAXPGPATH, "%s/postgresql.conf", pg_data); + } switch (ctl_command) { diff --git a/src/bin/pg_dump/dumputils.c b/src/bin/pg_dump/dumputils.c index 6f5e2d243e..4023837408 100644 --- a/src/bin/pg_dump/dumputils.c +++ b/src/bin/pg_dump/dumputils.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/bin/pg_dump/dumputils.c,v 1.31 2006/09/08 18:05:35 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/pg_dump/dumputils.c,v 1.32 2006/10/04 00:30:05 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -104,7 +104,7 @@ fmtId(const char *rawid) * standard_conforming_strings settings. * * This is essentially equivalent to libpq's PQescapeStringInternal, - * except for the output buffer structure. We need it in situations + * except for the output buffer structure. We need it in situations * where we do not have a PGconn available. Where we do, * appendStringLiteralConn is a better choice. */ @@ -124,9 +124,9 @@ appendStringLiteral(PQExpBuffer buf, const char *str, while (*source != '\0') { - char c = *source; - int len; - int i; + char c = *source; + int len; + int i; /* Fast path for plain ASCII */ if (!IS_HIGHBIT_SET(c)) @@ -153,15 +153,15 @@ appendStringLiteral(PQExpBuffer buf, const char *str, /* * If we hit premature end of string (ie, incomplete multibyte - * character), try to pad out to the correct length with spaces. - * We may not be able to pad completely, but we will always be able - * to insert at least one pad space (since we'd not have quoted a + * character), try to pad out to the correct length with spaces. We + * may not be able to pad completely, but we will always be able to + * insert at least one pad space (since we'd not have quoted a * multibyte character). This should be enough to make a string that * the server will error out on. */ if (i < len) { - char *stop = buf->data + buf->maxlen - 2; + char *stop = buf->data + buf->maxlen - 2; for (; i < len; i++) { @@ -189,7 +189,7 @@ appendStringLiteral(PQExpBuffer buf, const char *str, void appendStringLiteralConn(PQExpBuffer buf, const char *str, PGconn *conn) { - size_t length = strlen(str); + size_t length = strlen(str); /* * XXX This is a kluge to silence escape_string_warning in our utility @@ -198,7 +198,7 @@ appendStringLiteralConn(PQExpBuffer buf, const char *str, PGconn *conn) if (strchr(str, '\\') != NULL && PQserverVersion(conn) >= 80100) { /* ensure we are not adjacent to an identifier */ - if (buf->len > 0 && buf->data[buf->len-1] != ' ') + if (buf->len > 0 && buf->data[buf->len - 1] != ' ') appendPQExpBufferChar(buf, ' '); appendPQExpBufferChar(buf, ESCAPE_STRING_SYNTAX); appendStringLiteral(buf, str, PQclientEncoding(conn), false); @@ -614,7 +614,7 @@ do { \ if (strcmp(type, "TABLE") == 0 || strcmp(type, "SEQUENCE") == 0) { CONVERT_PRIV('r', "SELECT"); - + if (strcmp(type, "SEQUENCE") == 0) /* sequence only */ CONVERT_PRIV('U', "USAGE"); diff --git a/src/bin/pg_dump/dumputils.h b/src/bin/pg_dump/dumputils.h index 7492d42f7e..b177bb4bc8 100644 --- a/src/bin/pg_dump/dumputils.h +++ b/src/bin/pg_dump/dumputils.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/bin/pg_dump/dumputils.h,v 1.17 2006/05/28 21:13:54 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/pg_dump/dumputils.h,v 1.18 2006/10/04 00:30:05 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -20,9 +20,9 @@ extern const char *fmtId(const char *identifier); extern void appendStringLiteral(PQExpBuffer buf, const char *str, - int encoding, bool std_strings); + int encoding, bool std_strings); extern void appendStringLiteralConn(PQExpBuffer buf, const char *str, - PGconn *conn); + PGconn *conn); extern void appendStringLiteralDQ(PQExpBuffer buf, const char *str, const char *dqprefix); extern int parse_version(const char *versionString); diff --git a/src/bin/pg_dump/pg_backup.h b/src/bin/pg_dump/pg_backup.h index 426b5110fb..ae4e295dbd 100644 --- a/src/bin/pg_dump/pg_backup.h +++ b/src/bin/pg_dump/pg_backup.h @@ -15,7 +15,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.42 2006/08/01 18:21:44 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.43 2006/10/04 00:30:05 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -119,7 +119,7 @@ typedef struct _restoreOptions int suppressDumpWarnings; /* Suppress output of WARNING entries * to stderr */ - bool single_txn; + bool single_txn; } RestoreOptions; diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c index 6100633d56..32b6490e6e 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -15,7 +15,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.135 2006/08/01 18:21:44 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.136 2006/10/04 00:30:05 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -278,19 +278,25 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt) _printTocEntry(AH, te, ropt, false, false); defnDumped = true; - /* If we could not create a table, ignore the respective TABLE DATA if - * -X no-data-for-failed-tables is given */ - if (ropt->noDataForFailedTables && AH->lastErrorTE == te && strcmp (te->desc, "TABLE") == 0) { - TocEntry *tes, *last; - - ahlog (AH, 1, "table %s could not be created, will not restore its data\n", te->tag); - - for (last = te, tes = te->next; tes != AH->toc; last = tes, tes = tes->next) { - if (strcmp (tes->desc, "TABLE DATA") == 0 && strcmp (tes->tag, te->tag) == 0 && - strcmp (tes->namespace ? tes->namespace : "", te->namespace ? te->namespace : "") == 0) { - /* remove this node */ - last->next = tes->next; - break; + /* + * If we could not create a table, ignore the respective TABLE + * DATA if -X no-data-for-failed-tables is given + */ + if (ropt->noDataForFailedTables && AH->lastErrorTE == te && strcmp(te->desc, "TABLE") == 0) + { + TocEntry *tes, + *last; + + ahlog(AH, 1, "table %s could not be created, will not restore its data\n", te->tag); + + for (last = te, tes = te->next; tes != AH->toc; last = tes, tes = tes->next) + { + if (strcmp(tes->desc, "TABLE DATA") == 0 && strcmp(tes->tag, te->tag) == 0 && + strcmp(tes->namespace ? tes->namespace : "", te->namespace ? te->namespace : "") == 0) + { + /* remove this node */ + last->next = tes->next; + break; } } } diff --git a/src/bin/pg_dump/pg_backup_archiver.h b/src/bin/pg_dump/pg_backup_archiver.h index 1ed3f281a6..b64b8f3d32 100644 --- a/src/bin/pg_dump/pg_backup_archiver.h +++ b/src/bin/pg_dump/pg_backup_archiver.h @@ -17,7 +17,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.72 2006/07/18 17:42:00 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.73 2006/10/04 00:30:05 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -98,29 +98,29 @@ struct _archiveHandle; struct _tocEntry; struct _restoreList; -typedef void (*ClosePtr) (struct _archiveHandle *AH); -typedef void (*ArchiveEntryPtr) (struct _archiveHandle *AH, struct _tocEntry *te); - -typedef void (*StartDataPtr) (struct _archiveHandle *AH, struct _tocEntry *te); -typedef size_t (*WriteDataPtr) (struct _archiveHandle *AH, const void *data, size_t dLen); -typedef void (*EndDataPtr) (struct _archiveHandle *AH, struct _tocEntry *te); - -typedef void (*StartBlobsPtr) (struct _archiveHandle *AH, struct _tocEntry *te); -typedef void (*StartBlobPtr) (struct _archiveHandle *AH, struct _tocEntry *te, Oid oid); -typedef void (*EndBlobPtr) (struct _archiveHandle *AH, struct _tocEntry *te, Oid oid); -typedef void (*EndBlobsPtr) (struct _archiveHandle *AH, struct _tocEntry *te); - -typedef int (*WriteBytePtr) (struct _archiveHandle *AH, const int i); -typedef int (*ReadBytePtr) (struct _archiveHandle *AH); -typedef size_t (*WriteBufPtr) (struct _archiveHandle *AH, const void *c, size_t len); -typedef size_t (*ReadBufPtr) (struct _archiveHandle *AH, void *buf, size_t len); -typedef void (*SaveArchivePtr) (struct _archiveHandle *AH); -typedef void (*WriteExtraTocPtr) (struct _archiveHandle *AH, struct _tocEntry *te); -typedef void (*ReadExtraTocPtr) (struct _archiveHandle *AH, struct _tocEntry *te); -typedef void (*PrintExtraTocPtr) (struct _archiveHandle *AH, struct _tocEntry *te); -typedef void (*PrintTocDataPtr) (struct _archiveHandle *AH, struct _tocEntry *te, RestoreOptions *ropt); - -typedef size_t (*CustomOutPtr) (struct _archiveHandle *AH, const void *buf, size_t len); +typedef void (*ClosePtr) (struct _archiveHandle * AH); +typedef void (*ArchiveEntryPtr) (struct _archiveHandle * AH, struct _tocEntry * te); + +typedef void (*StartDataPtr) (struct _archiveHandle * AH, struct _tocEntry * te); +typedef size_t (*WriteDataPtr) (struct _archiveHandle * AH, const void *data, size_t dLen); +typedef void (*EndDataPtr) (struct _archiveHandle * AH, struct _tocEntry * te); + +typedef void (*StartBlobsPtr) (struct _archiveHandle * AH, struct _tocEntry * te); +typedef void (*StartBlobPtr) (struct _archiveHandle * AH, struct _tocEntry * te, Oid oid); +typedef void (*EndBlobPtr) (struct _archiveHandle * AH, struct _tocEntry * te, Oid oid); +typedef void (*EndBlobsPtr) (struct _archiveHandle * AH, struct _tocEntry * te); + +typedef int (*WriteBytePtr) (struct _archiveHandle * AH, const int i); +typedef int (*ReadBytePtr) (struct _archiveHandle * AH); +typedef size_t (*WriteBufPtr) (struct _archiveHandle * AH, const void *c, size_t len); +typedef size_t (*ReadBufPtr) (struct _archiveHandle * AH, void *buf, size_t len); +typedef void (*SaveArchivePtr) (struct _archiveHandle * AH); +typedef void (*WriteExtraTocPtr) (struct _archiveHandle * AH, struct _tocEntry * te); +typedef void (*ReadExtraTocPtr) (struct _archiveHandle * AH, struct _tocEntry * te); +typedef void (*PrintExtraTocPtr) (struct _archiveHandle * AH, struct _tocEntry * te); +typedef void (*PrintTocDataPtr) (struct _archiveHandle * AH, struct _tocEntry * te, RestoreOptions *ropt); + +typedef size_t (*CustomOutPtr) (struct _archiveHandle * AH, const void *buf, size_t len); typedef enum _archiveMode { diff --git a/src/bin/pg_dump/pg_backup_custom.c b/src/bin/pg_dump/pg_backup_custom.c index f0b65a2f3f..8d77af19c9 100644 --- a/src/bin/pg_dump/pg_backup_custom.c +++ b/src/bin/pg_dump/pg_backup_custom.c @@ -19,7 +19,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_custom.c,v 1.35 2006/07/14 14:52:26 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_custom.c,v 1.36 2006/10/04 00:30:05 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -545,7 +545,7 @@ _PrintData(ArchiveHandle *AH) "could not read from input file: end of file\n"); else die_horribly(AH, modulename, - "could not read from input file: %s\n", strerror(errno)); + "could not read from input file: %s\n", strerror(errno)); } ctx->filePos += blkLen; @@ -673,7 +673,7 @@ _skipData(ArchiveHandle *AH) "could not read from input file: end of file\n"); else die_horribly(AH, modulename, - "could not read from input file: %s\n", strerror(errno)); + "could not read from input file: %s\n", strerror(errno)); } ctx->filePos += blkLen; diff --git a/src/bin/pg_dump/pg_backup_db.c b/src/bin/pg_dump/pg_backup_db.c index 362e053165..aeb34989e8 100644 --- a/src/bin/pg_dump/pg_backup_db.c +++ b/src/bin/pg_dump/pg_backup_db.c @@ -5,7 +5,7 @@ * Implements the basic DB functions used by the archiver. * * IDENTIFICATION - * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.74 2006/09/27 15:41:23 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.75 2006/10/04 00:30:05 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -378,9 +378,9 @@ _sendCopyLine(ArchiveHandle *AH, char *qry, char *eos) isEnd = (strcmp(AH->pgCopyBuf->data, "\\.\n") == 0); /* - * Note that we drop the data on the floor if libpq has failed to - * enter COPY mode; this allows us to behave reasonably when trying - * to continue after an error in a COPY command. + * Note that we drop the data on the floor if libpq has failed to enter + * COPY mode; this allows us to behave reasonably when trying to continue + * after an error in a COPY command. */ if (AH->pgCopyIn && PQputCopyData(AH->connection, AH->pgCopyBuf->data, @@ -619,7 +619,7 @@ ExecuteSqlCommandBuf(ArchiveHandle *AH, void *qryv, size_t bufLen) { /* * If libpq is in CopyIn mode *or* if the archive structure shows we - * are sending COPY data, treat the data as COPY data. The pgCopyIn + * are sending COPY data, treat the data as COPY data. The pgCopyIn * check is only needed for backwards compatibility with ancient * archive files that might just issue a COPY command without marking * it properly. Note that in an archive entry that has a copyStmt, diff --git a/src/bin/pg_dump/pg_backup_tar.c b/src/bin/pg_dump/pg_backup_tar.c index 9b0606b753..51d783b1a5 100644 --- a/src/bin/pg_dump/pg_backup_tar.c +++ b/src/bin/pg_dump/pg_backup_tar.c @@ -16,7 +16,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.54 2006/06/27 02:56:41 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.55 2006/10/04 00:30:05 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -363,16 +363,17 @@ tarOpen(ArchiveHandle *AH, const char *filename, char mode) #ifndef WIN32 tm->tmpFH = tmpfile(); #else + /* - * On WIN32, tmpfile() generates a filename in the root directory, - * which requires administrative permissions on certain systems. - * Loop until we find a unique file name we can create. + * On WIN32, tmpfile() generates a filename in the root directory, + * which requires administrative permissions on certain systems. Loop + * until we find a unique file name we can create. */ while (1) { - char *name; - int fd; - + char *name; + int fd; + name = _tempnam(NULL, "pg_temp_"); if (name == NULL) break; @@ -380,7 +381,7 @@ tarOpen(ArchiveHandle *AH, const char *filename, char mode) O_TEMPORARY, S_IRUSR | S_IWUSR); free(name); - if (fd != -1) /* created a file */ + if (fd != -1) /* created a file */ { tm->tmpFH = fdopen(fd, "w+b"); break; @@ -1060,7 +1061,7 @@ _tarAddFile(ArchiveHandle *AH, TAR_MEMBER *th) res = fwrite(&buf[0], 1, cnt, th->tarFH); if (res != cnt) die_horribly(AH, modulename, - "could not write to output file: %s\n", strerror(errno)); + "could not write to output file: %s\n", strerror(errno)); len += res; } diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 8e243d0d41..2b207f382b 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -12,7 +12,7 @@ * by PostgreSQL * * IDENTIFICATION - * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.449 2006/09/27 15:41:23 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.450 2006/10/04 00:30:05 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -91,15 +91,16 @@ static Oid g_last_builtin_oid; /* value of the last builtin oid */ typedef struct objnameArg { struct objnameArg *next; - char *name; /* name of the relation */ - bool is_include; /* include/exclude? */ + char *name; /* name of the relation */ + bool is_include; /* include/exclude? */ } objnameArg; -objnameArg *schemaList = NULL; /* List of schemas to include/exclude */ -objnameArg *tableList = NULL; /* List of tables to include/exclude */ +objnameArg *schemaList = NULL; /* List of schemas to include/exclude */ +objnameArg *tableList = NULL; /* List of tables to include/exclude */ -char *matchingSchemas = NULL; /* Final list of schemas to dump by oid */ -char *matchingTables = NULL; /* Final list of tables to dump by oid */ +char *matchingSchemas = NULL; /* Final list of schemas to dump by + * oid */ +char *matchingTables = NULL; /* Final list of tables to dump by oid */ char g_opaque_type[10]; /* name for the opaque type */ @@ -189,7 +190,9 @@ main(int argc, char **argv) { PQExpBuffer query = createPQExpBuffer(); PGresult *res; - objnameArg *this_obj_name, *schemaList_tail = NULL, *tableList_tail = NULL; + objnameArg *this_obj_name, + *schemaList_tail = NULL, + *tableList_tail = NULL; int c; const char *filename = NULL; const char *format = "p"; @@ -345,10 +348,10 @@ main(int argc, char **argv) ignore_version = true; break; - case 'n': /* Include schemas */ - case 'N': /* Exclude schemas */ - case 't': /* Include tables */ - case 'T': /* Exclude tables */ + case 'n': /* Include schemas */ + case 'N': /* Exclude schemas */ + case 't': /* Include tables */ + case 'T': /* Exclude tables */ if (strlen(optarg) < 1) { @@ -359,7 +362,7 @@ main(int argc, char **argv) { /* Create a struct for this name */ objnameArg *new_obj_name = (objnameArg *) - malloc(sizeof(objnameArg)); + malloc(sizeof(objnameArg)); new_obj_name->next = NULL; new_obj_name->name = strdup(optarg); @@ -567,8 +570,8 @@ main(int argc, char **argv) } /* - * Get the active encoding and the standard_conforming_strings setting, - * so we know how to escape strings. + * Get the active encoding and the standard_conforming_strings setting, so + * we know how to escape strings. */ g_fout->encoding = PQclientEncoding(g_conn); @@ -629,36 +632,36 @@ main(int argc, char **argv) /* Special case for when -N is the first argument */ if (this_obj_name == schemaList && !this_obj_name->is_include) appendPQExpBuffer(query, - "SELECT oid FROM pg_catalog.pg_namespace " - "WHERE nspname NOT LIKE 'pg_%%' AND " - " nspname != 'information_schema' EXCEPT\n"); - + "SELECT oid FROM pg_catalog.pg_namespace " + "WHERE nspname NOT LIKE 'pg_%%' AND " + " nspname != 'information_schema' EXCEPT\n"); + appendPQExpBuffer(query, "SELECT oid FROM pg_catalog.pg_namespace WHERE"); } - + appendPQExpBuffer(query, "%s nspname %c ", switch_include_exclude ? "" : " OR", - /* any meta-characters? */ - strpbrk(this_obj_name->name,"([{\\.?+") == NULL ? '=' : '~'); + /* any meta-characters? */ + strpbrk(this_obj_name->name, "([{\\.?+") == NULL ? '=' : '~'); appendStringLiteralAH(query, this_obj_name->name, g_fout); - + if (this_obj_name->next && this_obj_name->next->is_include == this_obj_name->is_include) switch_include_exclude = false; else { switch_include_exclude = true; - + /* Add the joiner if needed */ if (this_obj_name->next) appendPQExpBuffer(query, "\n%s\n", - this_obj_name->next->is_include ? "UNION" : "EXCEPT"); + this_obj_name->next->is_include ? "UNION" : "EXCEPT"); } } /* Construct OID list of matching schemas */ if (schemaList) { - int len; - + int len; + res = PQexec(g_conn, query->data); check_sql_result(res, g_conn, query->data, PGRES_TUPLES_OK); if (PQntuples(res) == 0) @@ -671,8 +674,8 @@ main(int argc, char **argv) len += strlen(PQgetvalue(res, i, 0)) + 1; /* - * Need to use comma separators so it can be used by IN. zero - * is a dummy placeholder. Format is " oid oid oid ". + * Need to use comma separators so it can be used by IN. zero is a + * dummy placeholder. Format is " oid oid oid ". */ matchingSchemas = malloc(len + 1); strcpy(matchingSchemas, " "); @@ -694,27 +697,27 @@ main(int argc, char **argv) /* Special case for when -T is the first argument */ if (this_obj_name == tableList && !this_obj_name->is_include && !strlen(query->data)) appendPQExpBuffer(query, - "SELECT pg_class.oid FROM pg_catalog.pg_class, pg_catalog.pg_namespace " - "WHERE relkind='r' AND " - " relnamespace = pg_namespace.oid AND " - " nspname NOT LIKE 'pg_%%' AND " - " nspname != 'information_schema' EXCEPT\n"); - + "SELECT pg_class.oid FROM pg_catalog.pg_class, pg_catalog.pg_namespace " + "WHERE relkind='r' AND " + " relnamespace = pg_namespace.oid AND " + " nspname NOT LIKE 'pg_%%' AND " + " nspname != 'information_schema' EXCEPT\n"); + appendPQExpBuffer(query, "SELECT oid FROM pg_catalog.pg_class WHERE relkind='r' AND ("); } - + appendPQExpBuffer(query, "%srelname %c ", switch_include_exclude ? "" : " OR ", - /* any meta-characters? */ - strpbrk(this_obj_name->name,"([{\\.?+") == NULL ? '=' : '~'); + /* any meta-characters? */ + strpbrk(this_obj_name->name, "([{\\.?+") == NULL ? '=' : '~'); appendStringLiteralAH(query, this_obj_name->name, g_fout); - + if (this_obj_name->next && this_obj_name->next->is_include == this_obj_name->is_include) switch_include_exclude = false; else { switch_include_exclude = true; appendPQExpBuffer(query, ")"); - + /* Add the joiner if needed */ if (this_obj_name->next) appendPQExpBuffer(query, "\n%s\n", this_obj_name->next->is_include ? @@ -725,18 +728,19 @@ main(int argc, char **argv) /* Construct OID list of matching tables */ if (tableList) { - int len; - + int len; + /* Restrict by schema? */ if (matchingSchemas != NULL) { - char *matchingSchemas_commas = strdup(matchingSchemas), *p; + char *matchingSchemas_commas = strdup(matchingSchemas), + *p; /* Construct "IN" SQL string by adding commas, " oid, oid, oid " */ for (p = matchingSchemas_commas; *p; p++) { /* No commas for first/last characters */ - if (*p == ' ' && p != matchingSchemas_commas && *(p+1)) + if (*p == ' ' && p != matchingSchemas_commas && *(p + 1)) *p = ','; } @@ -940,16 +944,16 @@ selectDumpableNamespace(NamespaceInfo *nsinfo) { /* * If specific tables are being dumped, do not dump any complete - * namespaces. If specific namespaces are being dumped, dump just - * those namespaces. Otherwise, dump all non-system namespaces. + * namespaces. If specific namespaces are being dumped, dump just those + * namespaces. Otherwise, dump all non-system namespaces. */ nsinfo->dobj.dump = false; if (matchingTables != NULL) - /* false */; + /* false */ ; else if (matchingSchemas != NULL) { - char *search_oid = malloc(20); + char *search_oid = malloc(20); sprintf(search_oid, " %d ", nsinfo->dobj.catId.oid); if (strstr(matchingSchemas, search_oid) != NULL) @@ -984,7 +988,7 @@ selectDumpableTable(TableInfo *tbinfo) } else { - char *search_oid = malloc(20); + char *search_oid = malloc(20); sprintf(search_oid, " %d ", tbinfo->dobj.catId.oid); if (strstr(matchingTables, search_oid) != NULL) @@ -1034,8 +1038,8 @@ static void selectDumpableObject(DumpableObject *dobj) { /* - * Default policy is to dump if parent namespace is dumpable, - * or always for non-namespace-associated items. + * Default policy is to dump if parent namespace is dumpable, or always + * for non-namespace-associated items. */ if (dobj->namespace) dobj->dump = dobj->namespace->dobj.dump; @@ -1451,7 +1455,7 @@ dumpDatabase(Archive *AH) "(%s datdba) as dba, " "pg_encoding_to_char(encoding) as encoding, " "(SELECT spcname FROM pg_tablespace t WHERE t.oid = dattablespace) as tablespace, " - "shobj_description(oid, 'pg_database') as description " + "shobj_description(oid, 'pg_database') as description " "FROM pg_database " "WHERE datname = ", @@ -1562,25 +1566,30 @@ dumpDatabase(Archive *AH) /* Dump DB comment if any */ if (g_fout->remoteVersion >= 80200) { - /* 8.2 keeps comments on shared objects in a shared table, so - * we cannot use the dumpComment used for other database objects. + /* + * 8.2 keeps comments on shared objects in a shared table, so we + * cannot use the dumpComment used for other database objects. */ - char *comment = PQgetvalue(res, 0, PQfnumber(res, "description")); - if (comment && strlen(comment)) { + char *comment = PQgetvalue(res, 0, PQfnumber(res, "description")); + + if (comment && strlen(comment)) + { resetPQExpBuffer(dbQry); appendPQExpBuffer(dbQry, "COMMENT ON DATABASE %s IS ", fmtId(datname)); appendStringLiteralAH(dbQry, comment, AH); appendPQExpBuffer(dbQry, ";\n"); ArchiveEntry(AH, dbCatId, createDumpId(), datname, NULL, NULL, - dba, false, "COMMENT", dbQry->data, "", NULL, - &dbDumpId, 1, NULL, NULL); + dba, false, "COMMENT", dbQry->data, "", NULL, + &dbDumpId, 1, NULL, NULL); } - } else { + } + else + { resetPQExpBuffer(dbQry); appendPQExpBuffer(dbQry, "DATABASE %s", fmtId(datname)); dumpComment(AH, dbQry->data, NULL, "", - dbCatId, 0, dbDumpId); + dbCatId, 0, dbDumpId); } PQclear(res); @@ -2138,12 +2147,12 @@ getTypes(int *numTypes) /* * If it's a base type, make a DumpableObject representing a shell - * definition of the type. We will need to dump that ahead of the - * I/O functions for the type. + * definition of the type. We will need to dump that ahead of the I/O + * functions for the type. * * Note: the shell type doesn't have a catId. You might think it - * should copy the base type's catId, but then it might capture - * the pg_depend entries for the type, which we don't want. + * should copy the base type's catId, but then it might capture the + * pg_depend entries for the type, which we don't want. */ if (tinfo[i].dobj.dump && tinfo[i].typtype == 'b') { @@ -2157,9 +2166,9 @@ getTypes(int *numTypes) tinfo[i].shellType = stinfo; /* - * Initially mark the shell type as not to be dumped. We'll - * only dump it if the I/O functions need to be dumped; this - * is taken care of while sorting dependencies. + * Initially mark the shell type as not to be dumped. We'll only + * dump it if the I/O functions need to be dumped; this is taken + * care of while sorting dependencies. */ stinfo->dobj.dump = false; @@ -2557,7 +2566,7 @@ getAggregates(int *numAggs) { appendPQExpBuffer(query, "SELECT tableoid, oid, aggname, " "0::oid as aggnamespace, " - "CASE WHEN aggbasetype = 0 THEN 0 ELSE 1 END as pronargs, " + "CASE WHEN aggbasetype = 0 THEN 0 ELSE 1 END as pronargs, " "aggbasetype as proargtypes, " "(%s aggowner) as rolname, " "'{=X}' as aggacl " @@ -2572,7 +2581,7 @@ getAggregates(int *numAggs) "(SELECT oid FROM pg_class WHERE relname = 'pg_aggregate') AS tableoid, " "oid, aggname, " "0::oid as aggnamespace, " - "CASE WHEN aggbasetype = 0 THEN 0 ELSE 1 END as pronargs, " + "CASE WHEN aggbasetype = 0 THEN 0 ELSE 1 END as pronargs, " "aggbasetype as proargtypes, " "(%s aggowner) as rolname, " "'{=X}' as aggacl " @@ -2625,7 +2634,8 @@ getAggregates(int *numAggs) parseOidArray(PQgetvalue(res, i, i_proargtypes), agginfo[i].aggfn.argtypes, agginfo[i].aggfn.nargs); - else /* it's just aggbasetype */ + else + /* it's just aggbasetype */ agginfo[i].aggfn.argtypes[0] = atooid(PQgetvalue(res, i, i_proargtypes)); } @@ -3095,13 +3105,13 @@ getTables(int *numTables) PQclear(res); /* - * Force sequences that are "owned" by table columns to be dumped - * whenever their owning table is being dumped. + * Force sequences that are "owned" by table columns to be dumped whenever + * their owning table is being dumped. */ for (i = 0; i < ntups; i++) { TableInfo *seqinfo = &tblinfo[i]; - int j; + int j; if (!OidIsValid(seqinfo->owning_tab)) continue; /* not an owned sequence */ @@ -3250,7 +3260,7 @@ getIndexes(TableInfo tblinfo[], int numTables) "c.tableoid as contableoid, " "c.oid as conoid, " "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) as tablespace, " - "array_to_string(t.reloptions, ', ') as options " + "array_to_string(t.reloptions, ', ') as options " "FROM pg_catalog.pg_index i " "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) " "LEFT JOIN pg_catalog.pg_depend d " @@ -3276,7 +3286,7 @@ getIndexes(TableInfo tblinfo[], int numTables) "c.tableoid as contableoid, " "c.oid as conoid, " "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) as tablespace, " - "null as options " + "null as options " "FROM pg_catalog.pg_index i " "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) " "LEFT JOIN pg_catalog.pg_depend d " @@ -3302,7 +3312,7 @@ getIndexes(TableInfo tblinfo[], int numTables) "c.tableoid as contableoid, " "c.oid as conoid, " "NULL as tablespace, " - "null as options " + "null as options " "FROM pg_catalog.pg_index i " "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) " "LEFT JOIN pg_catalog.pg_depend d " @@ -3330,7 +3340,7 @@ getIndexes(TableInfo tblinfo[], int numTables) "0::oid as contableoid, " "t.oid as conoid, " "NULL as tablespace, " - "null as options " + "null as options " "FROM pg_index i, pg_class t " "WHERE t.oid = i.indexrelid " "AND i.indrelid = '%u'::oid " @@ -3353,7 +3363,7 @@ getIndexes(TableInfo tblinfo[], int numTables) "0::oid as contableoid, " "t.oid as conoid, " "NULL as tablespace, " - "null as options " + "null as options " "FROM pg_index i, pg_class t " "WHERE t.oid = i.indexrelid " "AND i.indrelid = '%u'::oid " @@ -5211,7 +5221,7 @@ dumpBaseType(Archive *fout, TypeInfo *tinfo) else if (!PQgetisnull(res, 0, PQfnumber(res, "typdefault"))) { typdefault = PQgetvalue(res, 0, PQfnumber(res, "typdefault")); - typdefault_is_literal = true; /* it needs quotes */ + typdefault_is_literal = true; /* it needs quotes */ } else typdefault = NULL; @@ -5219,8 +5229,8 @@ dumpBaseType(Archive *fout, TypeInfo *tinfo) /* * DROP must be fully qualified in case same name appears in pg_catalog. * The reason we include CASCADE is that the circular dependency between - * the type and its I/O functions makes it impossible to drop the type - * any other way. + * the type and its I/O functions makes it impossible to drop the type any + * other way. */ appendPQExpBuffer(delq, "DROP TYPE %s.", fmtId(tinfo->dobj.namespace->dobj.name)); @@ -5375,7 +5385,7 @@ dumpDomain(Archive *fout, TypeInfo *tinfo) else if (!PQgetisnull(res, 0, PQfnumber(res, "typdefault"))) { typdefault = PQgetvalue(res, 0, PQfnumber(res, "typdefault")); - typdefault_is_literal = true; /* it needs quotes */ + typdefault_is_literal = true; /* it needs quotes */ } else typdefault = NULL; @@ -5557,11 +5567,11 @@ dumpShellType(Archive *fout, ShellTypeInfo *stinfo) /* * Note the lack of a DROP command for the shell type; any required DROP - * is driven off the base type entry, instead. This interacts with + * is driven off the base type entry, instead. This interacts with * _printTocEntry()'s use of the presence of a DROP command to decide - * whether an entry needs an ALTER OWNER command. We don't want to - * alter the shell type's owner immediately on creation; that should - * happen only after it's filled in, otherwise the backend complains. + * whether an entry needs an ALTER OWNER command. We don't want to alter + * the shell type's owner immediately on creation; that should happen only + * after it's filled in, otherwise the backend complains. */ appendPQExpBuffer(q, "CREATE TYPE %s;\n", @@ -5972,7 +5982,7 @@ dumpFunc(Archive *fout, FuncInfo *finfo) * contains quote or backslash; else use regular quoting. */ if (disable_dollar_quoting || - (strchr(prosrc, '\'') == NULL && strchr(prosrc, '\\') == NULL)) + (strchr(prosrc, '\'') == NULL && strchr(prosrc, '\\') == NULL)) appendStringLiteralAH(asPart, prosrc, fout); else appendStringLiteralDQ(asPart, prosrc, NULL); @@ -6158,7 +6168,7 @@ dumpCast(Archive *fout, CastInfo *cast) * Skip this cast if all objects are from pg_ */ if ((funcInfo == NULL || - strncmp(funcInfo->dobj.namespace->dobj.name, "pg_", 3) == 0) && + strncmp(funcInfo->dobj.namespace->dobj.name, "pg_", 3) == 0) && strncmp(sourceInfo->dobj.namespace->dobj.name, "pg_", 3) == 0 && strncmp(targetInfo->dobj.namespace->dobj.name, "pg_", 3) == 0) return; @@ -7396,8 +7406,8 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) } /* - * Default value --- suppress if inherited or to be - * printed separately. + * Default value --- suppress if inherited or to be printed + * separately. */ if (tbinfo->attrdefs[j] != NULL && !tbinfo->inhAttrDef[j] && @@ -8077,10 +8087,10 @@ dumpSequence(Archive *fout, TableInfo *tbinfo) /* * The logic we use for restoring sequences is as follows: * - * Add a CREATE SEQUENCE statement as part of a "schema" dump - * (use last_val for start if called is false, else use min_val for - * start_val). Also, if the sequence is owned by a column, add an - * ALTER SEQUENCE SET OWNED command for it. + * Add a CREATE SEQUENCE statement as part of a "schema" dump (use + * last_val for start if called is false, else use min_val for start_val). + * Also, if the sequence is owned by a column, add an ALTER SEQUENCE SET + * OWNED command for it. * * Add a 'SETVAL(seq, last_val, iscalled)' as part of a "data" dump. */ @@ -8137,9 +8147,9 @@ dumpSequence(Archive *fout, TableInfo *tbinfo) * as a separate TOC entry immediately following the sequence's own * entry. It's OK to do this rather than using full sorting logic, * because the dependency that tells us it's owned will have forced - * the table to be created first. We can't just include the ALTER - * in the TOC entry because it will fail if we haven't reassigned - * the sequence owner to match the table's owner. + * the table to be created first. We can't just include the ALTER in + * the TOC entry because it will fail if we haven't reassigned the + * sequence owner to match the table's owner. * * We need not schema-qualify the table reference because both * sequence and table must be in the same schema. @@ -8156,14 +8166,14 @@ dumpSequence(Archive *fout, TableInfo *tbinfo) appendPQExpBuffer(query, " OWNED BY %s", fmtId(owning_tab->dobj.name)); appendPQExpBuffer(query, ".%s;\n", - fmtId(owning_tab->attnames[tbinfo->owning_col - 1])); + fmtId(owning_tab->attnames[tbinfo->owning_col - 1])); ArchiveEntry(fout, nilCatalogId, createDumpId(), tbinfo->dobj.name, tbinfo->dobj.namespace->dobj.name, NULL, tbinfo->rolname, - false, "SEQUENCE OWNED BY", query->data, "", NULL, + false, "SEQUENCE OWNED BY", query->data, "", NULL, &(tbinfo->dobj.dumpId), 1, NULL, NULL); } @@ -8334,9 +8344,10 @@ dumpTrigger(Archive *fout, TriggerInfo *tginfo) { if (*s == '\'') appendPQExpBufferChar(query, '\''); + /* - * bytea unconditionally doubles backslashes, so we suppress - * the doubling for standard_conforming_strings. + * bytea unconditionally doubles backslashes, so we suppress the + * doubling for standard_conforming_strings. */ if (fout->std_strings && *s == '\\' && s[1] == '\\') s++; diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index 2a18d2cfe2..1df5ee10fa 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * - * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.82 2006/09/27 15:41:23 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.83 2006/10/04 00:30:05 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -46,7 +46,7 @@ static void dumpCreateDB(PGconn *conn); static void dumpDatabaseConfig(PGconn *conn, const char *dbname); static void dumpUserConfig(PGconn *conn, const char *username); static void makeAlterConfigCommand(PGconn *conn, const char *arrayitem, - const char *type, const char *name); + const char *type, const char *name); static void dumpDatabases(PGconn *conn); static void dumpTimestamp(char *msg); @@ -309,8 +309,8 @@ main(int argc, char *argv[]) force_password, true); /* - * Get the active encoding and the standard_conforming_strings setting, - * so we know how to escape strings. + * Get the active encoding and the standard_conforming_strings setting, so + * we know how to escape strings. */ encoding = PQclientEncoding(conn); std_strings = PQparameterStatus(conn, "standard_conforming_strings"); @@ -436,7 +436,7 @@ dumpRoles(PGconn *conn) "rolcreaterole, rolcreatedb, rolcatupdate, " "rolcanlogin, rolconnlimit, rolpassword, " "rolvaliduntil, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment " "FROM pg_authid " "ORDER BY 1"); else if (server_version >= 80100) @@ -556,7 +556,8 @@ dumpRoles(PGconn *conn) appendPQExpBuffer(buf, ";\n"); - if (!PQgetisnull(res, i, i_rolcomment)) { + if (!PQgetisnull(res, i, i_rolcomment)) + { appendPQExpBuffer(buf, "COMMENT ON ROLE %s IS ", fmtId(rolename)); appendStringLiteralConn(buf, PQgetvalue(res, i, i_rolcomment), conn); appendPQExpBuffer(buf, ";\n"); @@ -704,15 +705,15 @@ dumpTablespaces(PGconn *conn) */ if (server_version >= 80200) res = executeQuery(conn, "SELECT spcname, " - "pg_catalog.pg_get_userbyid(spcowner) AS spcowner, " + "pg_catalog.pg_get_userbyid(spcowner) AS spcowner, " "spclocation, spcacl, " - "pg_catalog.shobj_description(oid, 'pg_tablespace') " + "pg_catalog.shobj_description(oid, 'pg_tablespace') " "FROM pg_catalog.pg_tablespace " "WHERE spcname !~ '^pg_' " "ORDER BY 1"); - else + else res = executeQuery(conn, "SELECT spcname, " - "pg_catalog.pg_get_userbyid(spcowner) AS spcowner, " + "pg_catalog.pg_get_userbyid(spcowner) AS spcowner, " "spclocation, spcacl, " "null " "FROM pg_catalog.pg_tablespace " @@ -755,7 +756,8 @@ dumpTablespaces(PGconn *conn) exit(1); } - if (spccomment && strlen(spccomment)) { + if (spccomment && strlen(spccomment)) + { appendPQExpBuffer(buf, "COMMENT ON TABLESPACE %s IS ", fspcname); appendStringLiteralConn(buf, spccomment, conn); appendPQExpBuffer(buf, ";\n"); @@ -883,13 +885,12 @@ dumpCreateDB(PGconn *conn) appendStringLiteralConn(buf, dbencoding, conn); /* - * Output tablespace if it isn't the default. For default, it - * uses the default from the template database. If tablespace - * is specified and tablespace creation failed earlier, - * (e.g. no such directory), the database creation will fail - * too. One solution would be to use 'SET default_tablespace' - * like we do in pg_dump for setting non-default database - * locations. + * Output tablespace if it isn't the default. For default, it + * uses the default from the template database. If tablespace is + * specified and tablespace creation failed earlier, (e.g. no such + * directory), the database creation will fail too. One solution + * would be to use 'SET default_tablespace' like we do in pg_dump + * for setting non-default database locations. */ if (strcmp(dbtablespace, "pg_default") != 0) appendPQExpBuffer(buf, " TABLESPACE = %s", diff --git a/src/bin/pg_resetxlog/pg_resetxlog.c b/src/bin/pg_resetxlog/pg_resetxlog.c index a8308388e8..1561383279 100644 --- a/src/bin/pg_resetxlog/pg_resetxlog.c +++ b/src/bin/pg_resetxlog/pg_resetxlog.c @@ -23,7 +23,7 @@ * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.52 2006/08/21 16:16:31 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.53 2006/10/04 00:30:05 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -587,7 +587,7 @@ static void RewriteControlFile(void) { int fd; - char buffer[PG_CONTROL_SIZE]; /* need not be aligned */ + char buffer[PG_CONTROL_SIZE]; /* need not be aligned */ /* * Adjust fields as needed to force an empty XLOG starting at the next diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 28d5cef053..5bc849750b 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -3,12 +3,12 @@ * * Copyright (c) 2000-2006, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.172 2006/08/29 15:19:50 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.173 2006/10/04 00:30:05 momjian Exp $ */ #include "postgres_fe.h" #include "command.h" -#ifdef __BORLANDC__ /* needed for BCC */ +#ifdef __BORLANDC__ /* needed for BCC */ #undef mkdir #endif @@ -157,17 +157,17 @@ HandleSlashCmds(PsqlScanState scan_state, static char * read_connect_arg(PsqlScanState scan_state) { - char *result; - char quote; + char *result; + char quote; /* - * Ideally we should treat the arguments as SQL identifiers. But - * for backwards compatibility with 7.2 and older pg_dump files, - * we have to take unquoted arguments verbatim (don't downcase - * them). For now, double-quoted arguments may be stripped of - * double quotes (as if SQL identifiers). By 7.4 or so, pg_dump - * files can be expected to double-quote all mixed-case \connect - * arguments, and then we can get rid of OT_SQLIDHACK. + * Ideally we should treat the arguments as SQL identifiers. But for + * backwards compatibility with 7.2 and older pg_dump files, we have to + * take unquoted arguments verbatim (don't downcase them). For now, + * double-quoted arguments may be stripped of double quotes (as if SQL + * identifiers). By 7.4 or so, pg_dump files can be expected to + * double-quote all mixed-case \connect arguments, and then we can get rid + * of OT_SQLIDHACK. */ result = psql_scan_slash_option(scan_state, OT_SQLIDHACK, "e, true); @@ -182,7 +182,7 @@ read_connect_arg(PsqlScanState scan_state) return result; } - + /* * Subroutine to actually try to execute a backslash command. @@ -223,17 +223,15 @@ exec_command(const char *cmd, * * \c dbname user host port * - * If any of these parameters are omitted or specified as '-', the - * current value of the parameter will be used instead. If the - * parameter has no current value, the default value for that - * parameter will be used. Some examples: + * If any of these parameters are omitted or specified as '-', the current + * value of the parameter will be used instead. If the parameter has no + * current value, the default value for that parameter will be used. Some + * examples: * - * \c - - hst Connect to current database on current port of - * host "hst" as current user. - * \c - usr - prt Connect to current database on "prt" port of current - * host as user "usr". - * \c dbs Connect to "dbs" database on current port of current - * host as current user. + * \c - - hst Connect to current database on current port of host + * "hst" as current user. \c - usr - prt Connect to current database on + * "prt" port of current host as user "usr". \c dbs Connect to + * "dbs" database on current port of current host as current user. */ else if (strcmp(cmd, "c") == 0 || strcmp(cmd, "connect") == 0) { @@ -970,13 +968,13 @@ exec_command(const char *cmd, static char * prompt_for_password(const char *username) { - char *result; + char *result; if (username == NULL) result = simple_prompt("Password: ", 100, false); else { - char *prompt_text; + char *prompt_text; prompt_text = malloc(strlen(username) + 32); sprintf(prompt_text, "Password for user \"%s\": ", username); @@ -1013,9 +1011,9 @@ param_is_newly_set(const char *old_val, const char *new_val) static bool do_connect(char *dbname, char *user, char *host, char *port) { - PGconn *o_conn = pset.db, - *n_conn; - char *password = NULL; + PGconn *o_conn = pset.db, + *n_conn; + char *password = NULL; if (!dbname) dbname = PQdb(o_conn); @@ -1027,15 +1025,14 @@ do_connect(char *dbname, char *user, char *host, char *port) port = PQport(o_conn); /* - * If the user asked to be prompted for a password, ask for one - * now. If not, use the password from the old connection, provided - * the username has not changed. Otherwise, try to connect without - * a password first, and then ask for a password if we got the - * appropriate error message. + * If the user asked to be prompted for a password, ask for one now. If + * not, use the password from the old connection, provided the username + * has not changed. Otherwise, try to connect without a password first, + * and then ask for a password if we got the appropriate error message. * - * XXX: this behavior is broken. It leads to spurious connection - * attempts in the postmaster's log, and doing a string comparison - * against the returned error message is pretty fragile. + * XXX: this behavior is broken. It leads to spurious connection attempts + * in the postmaster's log, and doing a string comparison against the + * returned error message is pretty fragile. */ if (pset.getPassword) { @@ -1059,8 +1056,8 @@ do_connect(char *dbname, char *user, char *host, char *port) break; /* - * Connection attempt failed; either retry the connection - * attempt with a new password, or give up. + * Connection attempt failed; either retry the connection attempt with + * a new password, or give up. */ if (strcmp(PQerrorMessage(n_conn), PQnoPasswordSupplied) == 0) { @@ -1070,9 +1067,9 @@ do_connect(char *dbname, char *user, char *host, char *port) } /* - * Failed to connect to the database. In interactive mode, - * keep the previous connection to the DB; in scripting mode, - * close our previous connection as well. + * Failed to connect to the database. In interactive mode, keep the + * previous connection to the DB; in scripting mode, close our + * previous connection as well. */ if (pset.cur_cmd_interactive) { @@ -1375,7 +1372,7 @@ process_file(char *filename, bool single_txn) FILE *fd; int result; char *oldfilename; - PGresult *res; + PGresult *res; if (!filename) return EXIT_FAILURE; @@ -1392,11 +1389,11 @@ process_file(char *filename, bool single_txn) oldfilename = pset.inputfile; pset.inputfile = filename; - if (single_txn) - res = PSQLexec("BEGIN", false); + if (single_txn) + res = PSQLexec("BEGIN", false); result = MainLoop(fd); - if (single_txn) - res = PSQLexec("COMMIT", false); + if (single_txn) + res = PSQLexec("COMMIT", false); fclose(fd); pset.inputfile = oldfilename; diff --git a/src/bin/psql/command.h b/src/bin/psql/command.h index 2abbe499d1..cd791b1d45 100644 --- a/src/bin/psql/command.h +++ b/src/bin/psql/command.h @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2006, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/command.h,v 1.27 2006/07/18 17:42:01 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/psql/command.h,v 1.28 2006/10/04 00:30:05 momjian Exp $ */ #ifndef COMMAND_H #define COMMAND_H @@ -14,12 +14,12 @@ typedef enum _backslashResult { - PSQL_CMD_UNKNOWN = 0, /* not done parsing yet (internal only) */ - PSQL_CMD_SEND, /* query complete; send off */ - PSQL_CMD_SKIP_LINE, /* keep building query */ - PSQL_CMD_TERMINATE, /* quit program */ - PSQL_CMD_NEWEDIT, /* query buffer was changed (e.g., via \e) */ - PSQL_CMD_ERROR /* the execution of the backslash command + PSQL_CMD_UNKNOWN = 0, /* not done parsing yet (internal only) */ + PSQL_CMD_SEND, /* query complete; send off */ + PSQL_CMD_SKIP_LINE, /* keep building query */ + PSQL_CMD_TERMINATE, /* quit program */ + PSQL_CMD_NEWEDIT, /* query buffer was changed (e.g., via \e) */ + PSQL_CMD_ERROR /* the execution of the backslash command * resulted in an error */ } backslashResult; diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c index ded8ecf2b1..2e30c4e9a2 100644 --- a/src/bin/psql/common.c +++ b/src/bin/psql/common.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2006, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.129 2006/09/27 15:41:23 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.130 2006/10/04 00:30:05 momjian Exp $ */ #include "postgres_fe.h" #include "common.h" @@ -236,7 +236,7 @@ volatile bool sigint_interrupt_enabled = false; sigjmp_buf sigint_interrupt_jmp; -static PGcancel * volatile cancelConn = NULL; +static PGcancel *volatile cancelConn = NULL; #ifdef WIN32 static CRITICAL_SECTION cancelConnLock; @@ -283,7 +283,6 @@ setup_cancel_handler(void) { pqsignal(SIGINT, handle_sigint); } - #else /* WIN32 */ static BOOL WINAPI @@ -329,7 +328,6 @@ setup_cancel_handler(void) SetConsoleCtrlHandler(consoleHandler, TRUE); } - #endif /* WIN32 */ @@ -397,7 +395,7 @@ CheckConnection(void) void SetCancelConn(void) { - PGcancel *oldCancelConn; + PGcancel *oldCancelConn; #ifdef WIN32 EnterCriticalSection(&cancelConnLock); @@ -427,7 +425,7 @@ SetCancelConn(void) void ResetCancelConn(void) { - PGcancel *oldCancelConn; + PGcancel *oldCancelConn; #ifdef WIN32 EnterCriticalSection(&cancelConnLock); @@ -872,7 +870,7 @@ SendQuery(const char *query) { /* Default fetch-it-all-and-print mode */ TimevalStruct before, - after; + after; if (pset.timing) GETTIMEOFDAY(&before); @@ -979,17 +977,17 @@ static bool ExecQueryUsingCursor(const char *query, double *elapsed_msec) { bool OK = true; - PGresult *results; - PQExpBufferData buf; + PGresult *results; + PQExpBufferData buf; printQueryOpt my_popt = pset.popt; FILE *queryFout_copy = pset.queryFout; bool queryFoutPipe_copy = pset.queryFoutPipe; - bool started_txn = false; - bool did_pager = false; - int ntuples; - char fetch_cmd[64]; + bool started_txn = false; + bool did_pager = false; + int ntuples; + char fetch_cmd[64]; TimevalStruct before, - after; + after; *elapsed_msec = 0; @@ -1040,7 +1038,7 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec) if (pset.gfname) { /* keep this code in sync with PrintQueryTuples */ - pset.queryFout = stdout; /* so it doesn't get closed */ + pset.queryFout = stdout; /* so it doesn't get closed */ /* open file/pipe */ if (!setQFout(pset.gfname)) @@ -1136,9 +1134,9 @@ cleanup: GETTIMEOFDAY(&before); /* - * We try to close the cursor on either success or failure, but on - * failure ignore the result (it's probably just a bleat about - * being in an aborted transaction) + * We try to close the cursor on either success or failure, but on failure + * ignore the result (it's probably just a bleat about being in an aborted + * transaction) */ results = PQexec(pset.db, "CLOSE _psql_cursor"); if (OK) @@ -1350,9 +1348,9 @@ command_no_begin(const char *query) } /* - * Note: these tests will match DROP SYSTEM and REINDEX TABLESPACE, - * which aren't really valid commands so we don't care much. - * The other four possible matches are correct. + * Note: these tests will match DROP SYSTEM and REINDEX TABLESPACE, which + * aren't really valid commands so we don't care much. The other four + * possible matches are correct. */ if ((wordlen == 4 && pg_strncasecmp(query, "drop", 4) == 0) || (wordlen == 7 && pg_strncasecmp(query, "reindex", 7) == 0)) @@ -1406,7 +1404,7 @@ is_select_command(const char *query) if (wordlen == 6 && pg_strncasecmp(query, "select", 6) == 0) return true; - + if (wordlen == 6 && pg_strncasecmp(query, "values", 6) == 0) return true; diff --git a/src/bin/psql/common.h b/src/bin/psql/common.h index 6045b7587d..3b6d566b33 100644 --- a/src/bin/psql/common.h +++ b/src/bin/psql/common.h @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2006, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/common.h,v 1.50 2006/06/14 16:49:02 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/psql/common.h,v 1.51 2006/10/04 00:30:05 momjian Exp $ */ #ifndef COMMON_H #define COMMON_H @@ -45,6 +45,7 @@ extern volatile bool sigint_interrupt_enabled; extern sigjmp_buf sigint_interrupt_jmp; extern volatile bool cancel_pressed; + /* Note: cancel_pressed is defined in print.c, see that file for reasons */ extern void setup_cancel_handler(void); diff --git a/src/bin/psql/copy.c b/src/bin/psql/copy.c index 6e514c1c06..82d92724e2 100644 --- a/src/bin/psql/copy.c +++ b/src/bin/psql/copy.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2006, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.68 2006/08/30 23:34:22 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.69 2006/10/04 00:30:05 momjian Exp $ */ #include "postgres_fe.h" #include "copy.h" @@ -148,7 +148,7 @@ parse_slash_copy(const char *args) /* Handle COPY (SELECT) case */ if (token[0] == '(') { - int parens = 1; + int parens = 1; while (parens > 0) { @@ -318,7 +318,7 @@ parse_slash_copy(const char *args) nonstd_backslash, true, false, pset.encoding); if (token && pg_strcasecmp(token, "as") == 0) token = strtokx(NULL, whitespace, NULL, "'", - nonstd_backslash, true, false, pset.encoding); + nonstd_backslash, true, false, pset.encoding); if (token) result->delim = pg_strdup(token); else @@ -330,7 +330,7 @@ parse_slash_copy(const char *args) nonstd_backslash, true, false, pset.encoding); if (token && pg_strcasecmp(token, "as") == 0) token = strtokx(NULL, whitespace, NULL, "'", - nonstd_backslash, true, false, pset.encoding); + nonstd_backslash, true, false, pset.encoding); if (token) result->null = pg_strdup(token); else @@ -342,7 +342,7 @@ parse_slash_copy(const char *args) nonstd_backslash, true, false, pset.encoding); if (token && pg_strcasecmp(token, "as") == 0) token = strtokx(NULL, whitespace, NULL, "'", - nonstd_backslash, true, false, pset.encoding); + nonstd_backslash, true, false, pset.encoding); if (token) result->quote = pg_strdup(token); else @@ -354,7 +354,7 @@ parse_slash_copy(const char *args) nonstd_backslash, true, false, pset.encoding); if (token && pg_strcasecmp(token, "as") == 0) token = strtokx(NULL, whitespace, NULL, "'", - nonstd_backslash, true, false, pset.encoding); + nonstd_backslash, true, false, pset.encoding); if (token) result->escape = pg_strdup(token); else @@ -439,7 +439,7 @@ error: /* - * Handle one of the "string" options of COPY. If the user gave a quoted + * Handle one of the "string" options of COPY. If the user gave a quoted * string, pass it to the backend as-is; if it wasn't quoted then quote * and escape it. */ @@ -631,10 +631,10 @@ do_copy(const char *args) bool handleCopyOut(PGconn *conn, FILE *copystream) { - bool OK = true; - char *buf; - int ret; - PGresult *res; + bool OK = true; + char *buf; + int ret; + PGresult *res; for (;;) { @@ -677,7 +677,7 @@ handleCopyOut(PGconn *conn, FILE *copystream) OK = false; } PQclear(res); - + return OK; } @@ -702,11 +702,11 @@ handleCopyIn(PGconn *conn, FILE *copystream, bool isbinary) bool OK; const char *prompt; char buf[COPYBUFSIZ]; - PGresult *res; + PGresult *res; /* - * Establish longjmp destination for exiting from wait-for-input. - * (This is only effective while sigint_interrupt_enabled is TRUE.) + * Establish longjmp destination for exiting from wait-for-input. (This is + * only effective while sigint_interrupt_enabled is TRUE.) */ if (sigsetjmp(sigint_interrupt_jmp, 1) != 0) { @@ -748,7 +748,7 @@ handleCopyIn(PGconn *conn, FILE *copystream, bool isbinary) for (;;) { - int buflen; + int buflen; /* enable longjmp while waiting for input */ sigint_interrupt_enabled = true; @@ -772,7 +772,7 @@ handleCopyIn(PGconn *conn, FILE *copystream, bool isbinary) bool copydone = false; while (!copydone) - { /* for each input line ... */ + { /* for each input line ... */ bool firstload; bool linedone; @@ -781,14 +781,14 @@ handleCopyIn(PGconn *conn, FILE *copystream, bool isbinary) fputs(prompt, stdout); fflush(stdout); } - + firstload = true; linedone = false; while (!linedone) - { /* for each bufferload in line ... */ - int linelen; - char *fgresult; + { /* for each bufferload in line ... */ + int linelen; + char *fgresult; /* enable longjmp while waiting for input */ sigint_interrupt_enabled = true; @@ -806,7 +806,7 @@ handleCopyIn(PGconn *conn, FILE *copystream, bool isbinary) linelen = strlen(buf); /* current line is done? */ - if (linelen > 0 && buf[linelen-1] == '\n') + if (linelen > 0 && buf[linelen - 1] == '\n') linedone = true; /* check for EOF marker, but not on a partial line */ @@ -818,10 +818,10 @@ handleCopyIn(PGconn *conn, FILE *copystream, bool isbinary) copydone = true; break; } - + firstload = false; } - + if (PQputCopyData(conn, buf, linelen) <= 0) { OK = false; @@ -829,7 +829,7 @@ handleCopyIn(PGconn *conn, FILE *copystream, bool isbinary) break; } } - + pset.lineno++; } } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index b6fbc13580..0adc99091d 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2006, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.144 2006/08/29 15:19:51 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.145 2006/10/04 00:30:05 momjian Exp $ */ #include "postgres_fe.h" #include "describe.h" @@ -72,7 +72,7 @@ describeAggregates(const char *pattern, bool verbose) " ELSE\n" " pg_catalog.array_to_string(ARRAY(\n" " SELECT\n" - " pg_catalog.format_type(p.proargtypes[s.i], NULL)\n" + " pg_catalog.format_type(p.proargtypes[s.i], NULL)\n" " FROM\n" " pg_catalog.generate_series(0, pg_catalog.array_upper(p.proargtypes, 1)) AS s(i)\n" " ), ', ')\n" @@ -132,7 +132,7 @@ describeTablespaces(const char *pattern, bool verbose) if (verbose) appendPQExpBuffer(&buf, ",\n spcacl as \"%s\"" - ",\n pg_catalog.shobj_description(oid, 'pg_tablespace') AS \"%s\"", + ",\n pg_catalog.shobj_description(oid, 'pg_tablespace') AS \"%s\"", _("Access privileges"), _("Description")); appendPQExpBuffer(&buf, @@ -175,20 +175,20 @@ describeFunctions(const char *pattern, bool verbose) "SELECT n.nspname as \"%s\",\n" " p.proname as \"%s\",\n" " CASE WHEN p.proretset THEN 'setof ' ELSE '' END ||\n" - " pg_catalog.format_type(p.prorettype, NULL) as \"%s\",\n" + " pg_catalog.format_type(p.prorettype, NULL) as \"%s\",\n" " CASE WHEN proallargtypes IS NOT NULL THEN\n" " pg_catalog.array_to_string(ARRAY(\n" " SELECT\n" " CASE\n" " WHEN p.proargmodes[s.i] = 'i' THEN ''\n" " WHEN p.proargmodes[s.i] = 'o' THEN 'OUT '\n" - " WHEN p.proargmodes[s.i] = 'b' THEN 'INOUT '\n" + " WHEN p.proargmodes[s.i] = 'b' THEN 'INOUT '\n" " END ||\n" " CASE\n" - " WHEN COALESCE(p.proargnames[s.i], '') = '' THEN ''\n" + " WHEN COALESCE(p.proargnames[s.i], '') = '' THEN ''\n" " ELSE p.proargnames[s.i] || ' ' \n" " END ||\n" - " pg_catalog.format_type(p.proallargtypes[s.i], NULL)\n" + " pg_catalog.format_type(p.proallargtypes[s.i], NULL)\n" " FROM\n" " pg_catalog.generate_series(1, pg_catalog.array_upper(p.proallargtypes, 1)) AS s(i)\n" " ), ', ')\n" @@ -196,10 +196,10 @@ describeFunctions(const char *pattern, bool verbose) " pg_catalog.array_to_string(ARRAY(\n" " SELECT\n" " CASE\n" - " WHEN COALESCE(p.proargnames[s.i+1], '') = '' THEN ''\n" + " WHEN COALESCE(p.proargnames[s.i+1], '') = '' THEN ''\n" " ELSE p.proargnames[s.i+1] || ' '\n" " END ||\n" - " pg_catalog.format_type(p.proargtypes[s.i], NULL)\n" + " pg_catalog.format_type(p.proargtypes[s.i], NULL)\n" " FROM\n" " pg_catalog.generate_series(0, pg_catalog.array_upper(p.proargtypes, 1)) AS s(i)\n" " ), ', ')\n" @@ -225,7 +225,7 @@ describeFunctions(const char *pattern, bool verbose) "\nFROM pg_catalog.pg_proc p" "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace" "\n LEFT JOIN pg_catalog.pg_language l ON l.oid = p.prolang" - "\n JOIN pg_catalog.pg_roles r ON r.oid = p.proowner\n"); + "\n JOIN pg_catalog.pg_roles r ON r.oid = p.proowner\n"); /* * we skip in/out funcs by excluding functions that take or return cstring @@ -403,11 +403,11 @@ listAllDbs(bool verbose) } appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_database d" - "\n JOIN pg_catalog.pg_roles r ON d.datdba = r.oid\n"); + "\n JOIN pg_catalog.pg_roles r ON d.datdba = r.oid\n"); if (verbose) appendPQExpBuffer(&buf, - " JOIN pg_catalog.pg_tablespace t on d.dattablespace = t.oid\n"); - appendPQExpBuffer(&buf,"ORDER BY 1;"); + " JOIN pg_catalog.pg_tablespace t on d.dattablespace = t.oid\n"); + appendPQExpBuffer(&buf, "ORDER BY 1;"); res = PSQLexec(buf.data, false); termPQExpBuffer(&buf); if (!res) @@ -1460,7 +1460,7 @@ describeRoles(const char *pattern, bool verbose) if (verbose) appendPQExpBuffer(&buf, "\n, pg_catalog.shobj_description(r.oid, 'pg_authid') AS \"%s\"", - _("Description")); + _("Description")); appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -1540,7 +1540,7 @@ listTables(const char *tabtypes, const char *pattern, bool verbose) appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_class c" - "\n JOIN pg_catalog.pg_roles r ON r.oid = c.relowner" + "\n JOIN pg_catalog.pg_roles r ON r.oid = c.relowner" "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace"); if (showIndexes) appendPQExpBuffer(&buf, @@ -1782,7 +1782,7 @@ listSchemas(const char *pattern, bool verbose) _("Access privileges"), _("Description")); appendPQExpBuffer(&buf, - "\nFROM pg_catalog.pg_namespace n JOIN pg_catalog.pg_roles r\n" + "\nFROM pg_catalog.pg_namespace n JOIN pg_catalog.pg_roles r\n" " ON n.nspowner=r.oid\n" "WHERE (n.nspname !~ '^pg_temp_' OR\n" " n.nspname = (pg_catalog.current_schemas(true))[1])\n"); /* temp schema is first */ @@ -1859,8 +1859,8 @@ processNamePattern(PQExpBuffer buf, const char *pattern, * we assume this was NOT done by scan_option. Also, adjust shell-style * wildcard characters into regexp notation. * - * Note: the result of this pass is the actual regexp pattern we want - * to execute. Quoting/escaping it into a SQL literal will be done below. + * Note: the result of this pass is the actual regexp pattern we want to + * execute. Quoting/escaping it into a SQL literal will be done below. */ appendPQExpBufferChar(&namebuf, '^'); @@ -1929,8 +1929,8 @@ processNamePattern(PQExpBuffer buf, const char *pattern, } /* - * Now decide what we need to emit. Note there will be a leading '^' - * in the patterns in any case. + * Now decide what we need to emit. Note there will be a leading '^' in + * the patterns in any case. */ if (namebuf.len > 1) { diff --git a/src/bin/psql/input.c b/src/bin/psql/input.c index 323ef573b4..befee86357 100644 --- a/src/bin/psql/input.c +++ b/src/bin/psql/input.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2006, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/input.c,v 1.59 2006/08/29 15:19:51 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/psql/input.c,v 1.60 2006/10/04 00:30:06 momjian Exp $ */ #include "postgres_fe.h" @@ -29,7 +29,7 @@ char *psql_history; * Preserve newlines in saved queries by mapping '\n' to NL_IN_HISTORY * * It is assumed NL_IN_HISTORY will never be entered by the user - * nor appear inside a multi-byte string. 0x00 is not properly + * nor appear inside a multi-byte string. 0x00 is not properly * handled by the readline routines so it can not be used * for this purpose. */ @@ -58,7 +58,7 @@ gets_interactive(const char *prompt) #ifdef USE_READLINE if (useReadline) { - char *result; + char *result; /* Enable SIGINT to longjmp to sigint_interrupt_jmp */ sigint_interrupt_enabled = true; @@ -91,8 +91,8 @@ pg_append_history(const char *s, PQExpBuffer history_buf) appendPQExpBufferStr(history_buf, s); if (s[strlen(s) - 1] != '\n') appendPQExpBufferChar(history_buf, '\n'); - } -#endif + } +#endif } @@ -110,7 +110,7 @@ pg_send_history(PQExpBuffer history_buf) #ifdef USE_READLINE static char *prev_hist = NULL; - char *s = history_buf->data; + char *s = history_buf->data; if (useHistory && s[0]) { @@ -123,10 +123,10 @@ pg_send_history(PQExpBuffer history_buf) } else { - int i; + int i; /* Trim any trailing \n's (OK to scribble on history_buf) */ - for (i = strlen(s)-1; i >= 0 && s[i] == '\n'; i--) + for (i = strlen(s) - 1; i >= 0 && s[i] == '\n'; i--) ; s[i + 1] = '\0'; /* Save each previous line for ignoredups processing */ @@ -151,7 +151,7 @@ pg_send_history(PQExpBuffer history_buf) * * Caller *must* have set up sigint_interrupt_jmp before calling. * - * Note: we re-use a static PQExpBuffer for each call. This is to avoid + * Note: we re-use a static PQExpBuffer for each call. This is to avoid * leaking memory if interrupted by SIGINT. */ char * @@ -168,7 +168,7 @@ gets_fromFile(FILE *source) for (;;) { - char *result; + char *result; /* Enable SIGINT to longjmp to sigint_interrupt_jmp */ sigint_interrupt_enabled = true; @@ -209,7 +209,7 @@ static void encode_history(void) { HIST_ENTRY *cur_hist; - char *cur_ptr; + char *cur_ptr; history_set_pos(0); for (cur_hist = current_history(); cur_hist; cur_hist = next_history()) @@ -228,7 +228,7 @@ static void decode_history(void) { HIST_ENTRY *cur_hist; - char *cur_ptr; + char *cur_ptr; history_set_pos(0); for (cur_hist = current_history(); cur_hist; cur_hist = next_history()) @@ -239,7 +239,7 @@ decode_history(void) *cur_ptr = '\n'; } } -#endif /* USE_READLINE */ +#endif /* USE_READLINE */ /* @@ -296,8 +296,8 @@ initializeInput(int flags) /* - * This function is for saving the readline history when user - * runs \s command or when psql finishes. + * This function is for saving the readline history when user + * runs \s command or when psql finishes. * * We have an argument named encodeFlag to handle the cases differently. * In case of call via \s we don't really need to encode \n as \x01, @@ -307,11 +307,12 @@ bool saveHistory(char *fname, bool encodeFlag) { #ifdef USE_READLINE + /* - * Suppressing the write attempt when HISTFILE is set to /dev/null - * may look like a negligible optimization, but it's necessary on e.g. - * Darwin, where write_history will fail because it tries to chmod - * the target file. + * Suppressing the write attempt when HISTFILE is set to /dev/null may + * look like a negligible optimization, but it's necessary on e.g. Darwin, + * where write_history will fail because it tries to chmod the target + * file. */ if (useHistory && fname && strcmp(fname, DEVNULL) != 0) @@ -321,8 +322,8 @@ saveHistory(char *fname, bool encodeFlag) /* * return value of write_history is not standardized across GNU - * readline and libedit. Therefore, check for errno becoming set - * to see if the write failed. + * readline and libedit. Therefore, check for errno becoming set to + * see if the write failed. */ errno = 0; (void) write_history(fname); diff --git a/src/bin/psql/mainloop.c b/src/bin/psql/mainloop.c index 519230b28a..d597cb3d75 100644 --- a/src/bin/psql/mainloop.c +++ b/src/bin/psql/mainloop.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2006, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/mainloop.c,v 1.83 2006/08/29 15:19:51 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/psql/mainloop.c,v 1.84 2006/10/04 00:30:06 momjian Exp $ */ #include "postgres_fe.h" #include "mainloop.h" @@ -29,8 +29,8 @@ MainLoop(FILE *source) PQExpBuffer query_buf; /* buffer for query being accumulated */ PQExpBuffer previous_buf; /* if there isn't anything in the new buffer * yet, use this one for \e, etc. */ - PQExpBuffer history_buf; /* earlier lines of a multi-line command, - * not yet saved to readline history */ + PQExpBuffer history_buf; /* earlier lines of a multi-line command, not + * yet saved to readline history */ char *line; /* current line of input */ int added_nl_pos; bool success; @@ -89,9 +89,9 @@ MainLoop(FILE *source) } /* - * Establish longjmp destination for exiting from wait-for-input. - * We must re-do this each time through the loop for safety, since - * the jmpbuf might get changed during command execution. + * Establish longjmp destination for exiting from wait-for-input. We + * must re-do this each time through the loop for safety, since the + * jmpbuf might get changed during command execution. */ if (sigsetjmp(sigint_interrupt_jmp, 1) != 0) { @@ -235,7 +235,7 @@ MainLoop(FILE *source) * If we added a newline to query_buf, and nothing else has * been inserted in query_buf by the lexer, then strip off the * newline again. This avoids any change to query_buf when a - * line contains only a backslash command. Also, in this + * line contains only a backslash command. Also, in this * situation we force out any previous lines as a separate * history entry; we don't want SQL and backslash commands * intermixed in history if at all possible. diff --git a/src/bin/psql/mbprint.c b/src/bin/psql/mbprint.c index f0e0fa13b8..8a25955b5c 100644 --- a/src/bin/psql/mbprint.c +++ b/src/bin/psql/mbprint.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2006, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/mbprint.c,v 1.22 2006/07/14 14:52:26 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/psql/mbprint.c,v 1.23 2006/10/04 00:30:06 momjian Exp $ */ #include "postgres_fe.h" @@ -151,18 +151,19 @@ mb_utf_validate(unsigned char *pwcs) int pg_wcswidth(const unsigned char *pwcs, size_t len, int encoding) { - int width = 0; + int width = 0; while (len > 0) { - int chlen, chwidth; + int chlen, + chwidth; - chlen = PQmblen((const char*) pwcs, encoding); + chlen = PQmblen((const char *) pwcs, encoding); if (chlen > len) - break; /* Invalid string */ - + break; /* Invalid string */ + chwidth = PQdsplen((const char *) pwcs, encoding); - + if (chwidth > 0) width += chwidth; pwcs += chlen; @@ -173,60 +174,62 @@ pg_wcswidth(const unsigned char *pwcs, size_t len, int encoding) /* * pg_wcssize takes the given string in the given encoding and returns three * values: - * result_width: Width in display character of longest line in string - * result_hieght: Number of lines in display output - * result_format_size: Number of bytes required to store formatted representation of string + * result_width: Width in display character of longest line in string + * result_hieght: Number of lines in display output + * result_format_size: Number of bytes required to store formatted representation of string */ int pg_wcssize(unsigned char *pwcs, size_t len, int encoding, int *result_width, - int *result_height, int *result_format_size) + int *result_height, int *result_format_size) { - int w, - chlen = 0, - linewidth = 0; - int width = 0; - int height = 1; - int format_size = 0; + int w, + chlen = 0, + linewidth = 0; + int width = 0; + int height = 1; + int format_size = 0; for (; *pwcs && len > 0; pwcs += chlen) { chlen = PQmblen((char *) pwcs, encoding); - if (len < (size_t)chlen) + if (len < (size_t) chlen) break; w = PQdsplen((char *) pwcs, encoding); - if (chlen == 1) /* ASCII char */ + if (chlen == 1) /* ASCII char */ { - if (*pwcs == '\n') /* Newline */ + if (*pwcs == '\n') /* Newline */ { if (linewidth > width) width = linewidth; linewidth = 0; height += 1; - format_size += 1; /* For NUL char */ + format_size += 1; /* For NUL char */ } - else if (*pwcs == '\r') /* Linefeed */ + else if (*pwcs == '\r') /* Linefeed */ { linewidth += 2; format_size += 2; } - else if (w <= 0) /* Other control char */ + else if (w <= 0) /* Other control char */ { linewidth += 4; format_size += 4; } - else /* Output itself */ + else + /* Output itself */ { linewidth++; format_size += 1; } } - else if (w <= 0) /* Non-ascii control char */ + else if (w <= 0) /* Non-ascii control char */ { - linewidth += 6; /* \u0000 */ + linewidth += 6; /* \u0000 */ format_size += 6; } - else /* All other chars */ + else + /* All other chars */ { linewidth += w; format_size += chlen; @@ -236,7 +239,7 @@ pg_wcssize(unsigned char *pwcs, size_t len, int encoding, int *result_width, if (linewidth > width) width = linewidth; format_size += 1; - + /* Set results */ if (result_width) *result_width = width; @@ -244,76 +247,81 @@ pg_wcssize(unsigned char *pwcs, size_t len, int encoding, int *result_width, *result_height = height; if (result_format_size) *result_format_size = format_size; - + return width; } void pg_wcsformat(unsigned char *pwcs, size_t len, int encoding, - struct lineptr *lines, int count) + struct lineptr * lines, int count) { int w, chlen = 0; - int linewidth = 0; - unsigned char *ptr = lines->ptr; /* Pointer to data area */ + int linewidth = 0; + unsigned char *ptr = lines->ptr; /* Pointer to data area */ for (; *pwcs && len > 0; pwcs += chlen) { - chlen = PQmblen((char *) pwcs,encoding); - if (len < (size_t)chlen) + chlen = PQmblen((char *) pwcs, encoding); + if (len < (size_t) chlen) break; - w = PQdsplen((char *) pwcs,encoding); + w = PQdsplen((char *) pwcs, encoding); - if (chlen == 1) /* single byte char char */ + if (chlen == 1) /* single byte char char */ { - if (*pwcs == '\n') /* Newline */ + if (*pwcs == '\n') /* Newline */ { - *ptr++ = 0; /* NULL char */ + *ptr++ = 0; /* NULL char */ lines->width = linewidth; linewidth = 0; lines++; count--; if (count == 0) - exit(1); /* Screwup */ - + exit(1); /* Screwup */ + lines->ptr = ptr; } - else if (*pwcs == '\r') /* Linefeed */ + else if (*pwcs == '\r') /* Linefeed */ { strcpy((char *) ptr, "\\r"); linewidth += 2; ptr += 2; } - else if (w <= 0) /* Other control char */ + else if (w <= 0) /* Other control char */ { sprintf((char *) ptr, "\\x%02X", *pwcs); linewidth += 4; ptr += 4; } - else /* Output itself */ + else + /* Output itself */ { linewidth++; *ptr++ = *pwcs; } } - else if (w <= 0) /* Non-ascii control char */ + else if (w <= 0) /* Non-ascii control char */ { if (encoding == PG_UTF8) sprintf((char *) ptr, "\\u%04X", utf2ucs(pwcs)); else - /* This case cannot happen in the current - * code because only UTF-8 signals multibyte - * control characters. But we may need to - * support it at some stage */ + + /* + * This case cannot happen in the current code because only + * UTF-8 signals multibyte control characters. But we may need + * to support it at some stage + */ sprintf((char *) ptr, "\\u????"); - + ptr += 6; linewidth += 6; } - else /* All other chars */ + else + /* All other chars */ { - int i; - for (i=0; i < chlen; i++) + int i; + + for (i = 0; i < chlen; i++) *ptr++ = pwcs[i]; linewidth += w; } diff --git a/src/bin/psql/mbprint.h b/src/bin/psql/mbprint.h index 3941ce1580..61e723cbae 100644 --- a/src/bin/psql/mbprint.h +++ b/src/bin/psql/mbprint.h @@ -1,17 +1,18 @@ -/* $PostgreSQL: pgsql/src/bin/psql/mbprint.h,v 1.10 2006/07/14 14:52:26 momjian Exp $ */ +/* $PostgreSQL: pgsql/src/bin/psql/mbprint.h,v 1.11 2006/10/04 00:30:06 momjian Exp $ */ #ifndef MBPRINT_H #define MBPRINT_H -struct lineptr { +struct lineptr +{ unsigned char *ptr; - int width; + int width; }; extern unsigned char *mbvalidate(unsigned char *pwcs, int encoding); extern int pg_wcswidth(const unsigned char *pwcs, size_t len, int encoding); -extern void pg_wcsformat(unsigned char *pwcs, size_t len, int encoding, struct lineptr *lines, int count); +extern void pg_wcsformat(unsigned char *pwcs, size_t len, int encoding, struct lineptr * lines, int count); extern int pg_wcssize(unsigned char *pwcs, size_t len, int encoding, int *width, int *height, int *format_size); #endif /* MBPRINT_H */ diff --git a/src/bin/psql/print.c b/src/bin/psql/print.c index 01f47e43b4..f256212ec5 100644 --- a/src/bin/psql/print.c +++ b/src/bin/psql/print.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2006, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.89 2006/08/29 22:25:07 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.90 2006/10/04 00:30:06 momjian Exp $ * * Note: we include postgres.h not postgres_fe.h so that we can include * catalog/pg_type.h, and thereby have access to INT4OID and similar macros. @@ -180,8 +180,8 @@ print_unaligned_text(const char *title, const char *const * headers, { const char *opt_fieldsep = opt->fieldSep; const char *opt_recordsep = opt->recordSep; - bool opt_tuples_only = opt->tuples_only; - bool opt_numeric_locale = opt->numericLocale; + bool opt_tuples_only = opt->tuples_only; + bool opt_numeric_locale = opt->numericLocale; unsigned int col_count = 0; unsigned int i; const char *const * ptr; @@ -217,7 +217,8 @@ print_unaligned_text(const char *title, const char *const * headers, need_recordsep = true; } } - else /* assume continuing printout */ + else + /* assume continuing printout */ need_recordsep = true; /* print cells */ @@ -276,8 +277,8 @@ print_unaligned_vertical(const char *title, const char *const * headers, { const char *opt_fieldsep = opt->fieldSep; const char *opt_recordsep = opt->recordSep; - bool opt_tuples_only = opt->tuples_only; - bool opt_numeric_locale = opt->numericLocale; + bool opt_tuples_only = opt->tuples_only; + bool opt_numeric_locale = opt->numericLocale; unsigned int col_count = 0; unsigned int i; const char *const * ptr; @@ -304,7 +305,8 @@ print_unaligned_vertical(const char *title, const char *const * headers, need_recordsep = true; } } - else /* assume continuing printout */ + else + /* assume continuing printout */ need_recordsep = true; /* print records */ @@ -402,26 +404,28 @@ print_aligned_text(const char *title, const char *const * headers, const char *opt_align, const printTableOpt *opt, FILE *fout) { - bool opt_tuples_only = opt->tuples_only; - bool opt_numeric_locale = opt->numericLocale; + bool opt_tuples_only = opt->tuples_only; + bool opt_numeric_locale = opt->numericLocale; unsigned short int opt_border = opt->border; - int encoding = opt->encoding; + int encoding = opt->encoding; unsigned int col_count = 0; unsigned int cell_count = 0; unsigned int i; - int tmp; + int tmp; unsigned int *widths, total_w; unsigned int *heights; unsigned int *format_space; unsigned char **format_buf; - - const char *const *ptr; - - struct lineptr **col_lineptrs; /* pointers to line pointer for each column */ - struct lineptr *lineptr_list; /* complete list of linepointers */ - - int *complete; /* Array remembering which columns have completed output */ + + const char *const * ptr; + + struct lineptr **col_lineptrs; /* pointers to line pointer for each + * column */ + struct lineptr *lineptr_list; /* complete list of linepointers */ + + int *complete; /* Array remembering which columns have + * completed output */ if (cancel_pressed) return; @@ -451,7 +455,7 @@ print_aligned_text(const char *title, const char *const * headers, format_buf = NULL; complete = NULL; } - + /* count cells (rows * cols) */ for (ptr = cells; *ptr; ptr++) cell_count++; @@ -460,7 +464,9 @@ print_aligned_text(const char *title, const char *const * headers, for (i = 0; i < col_count; i++) { /* Get width & height */ - int height, space; + int height, + space; + pg_wcssize((unsigned char *) headers[i], strlen(headers[i]), encoding, &tmp, &height, &space); if (tmp > widths[i]) widths[i] = tmp; @@ -472,14 +478,15 @@ print_aligned_text(const char *title, const char *const * headers, for (i = 0, ptr = cells; *ptr; ptr++, i++) { - int numeric_locale_len; - int height, space; + int numeric_locale_len; + int height, + space; if (opt_align[i % col_count] == 'r' && opt_numeric_locale) numeric_locale_len = additional_numeric_locale_len(*ptr); - else + else numeric_locale_len = 0; - + /* Get width, ignore height */ pg_wcssize((unsigned char *) *ptr, strlen(*ptr), encoding, &tmp, &height, &space); tmp += numeric_locale_len; @@ -501,29 +508,29 @@ print_aligned_text(const char *title, const char *const * headers, for (i = 0; i < col_count; i++) total_w += widths[i]; - /* At this point: - * widths contains the max width of each column - * heights contains the max height of a cell of each column - * format_space contains maximum space required to store formatted string - * so we prepare the formatting structures + /* + * At this point: widths contains the max width of each column heights + * contains the max height of a cell of each column format_space contains + * maximum space required to store formatted string so we prepare the + * formatting structures */ if (col_count > 0) { - int heights_total = 0; + int heights_total = 0; struct lineptr *lineptr; - + for (i = 0; i < col_count; i++) heights_total += heights[i]; - + lineptr = lineptr_list = pg_local_calloc(heights_total, sizeof(*lineptr_list)); - + for (i = 0; i < col_count; i++) { col_lineptrs[i] = lineptr; lineptr += heights[i]; - + format_buf[i] = pg_local_malloc(format_space[i]); - + col_lineptrs[i]->ptr = format_buf[i]; } } @@ -536,8 +543,9 @@ print_aligned_text(const char *title, const char *const * headers, if (title && !opt_tuples_only) { /* Get width & height */ - int height; - pg_wcssize((unsigned char *)title, strlen(title), encoding, &tmp, &height, NULL); + int height; + + pg_wcssize((unsigned char *) title, strlen(title), encoding, &tmp, &height, NULL); if (tmp >= total_w) fprintf(fout, "%s\n", title); else @@ -547,18 +555,18 @@ print_aligned_text(const char *title, const char *const * headers, /* print headers */ if (!opt_tuples_only) { - int cols_todo; - int line_count; - + int cols_todo; + int line_count; + if (opt_border == 2) _print_horizontal_line(col_count, widths, opt_border, fout); for (i = 0; i < col_count; i++) - pg_wcsformat((unsigned char *)headers[i], strlen(headers[i]), encoding, col_lineptrs[i], heights[i]); - + pg_wcsformat((unsigned char *) headers[i], strlen(headers[i]), encoding, col_lineptrs[i], heights[i]); + cols_todo = col_count; line_count = 0; - memset(complete, 0, col_count*sizeof(int)); + memset(complete, 0, col_count * sizeof(int)); while (cols_todo) { if (opt_border == 2) @@ -571,6 +579,7 @@ print_aligned_text(const char *title, const char *const * headers, unsigned int nbspace; struct lineptr *this_line = col_lineptrs[i] + line_count; + if (!complete[i]) { nbspace = widths[i] - this_line->width; @@ -579,7 +588,7 @@ print_aligned_text(const char *title, const char *const * headers, fprintf(fout, "%-*s%s%-*s", nbspace / 2, "", this_line->ptr, (nbspace + 1) / 2, ""); - if (line_count == (heights[i]-1) || !(this_line+1)->ptr) + if (line_count == (heights[i] - 1) || !(this_line + 1)->ptr) { cols_todo--; complete[i] = 1; @@ -609,20 +618,20 @@ print_aligned_text(const char *title, const char *const * headers, } /* print cells */ - for (i = 0, ptr = cells; *ptr; i+=col_count, ptr+=col_count) + for (i = 0, ptr = cells; *ptr; i += col_count, ptr += col_count) { - int j; - int cols_todo = col_count; - int line_count; /* Number of lines output so far in row */ + int j; + int cols_todo = col_count; + int line_count; /* Number of lines output so far in row */ if (cancel_pressed) break; for (j = 0; j < col_count; j++) - pg_wcsformat((unsigned char*)ptr[j], strlen(ptr[j]), encoding, col_lineptrs[j], heights[j]); - + pg_wcsformat((unsigned char *) ptr[j], strlen(ptr[j]), encoding, col_lineptrs[j], heights[j]); + line_count = 0; - memset(complete, 0, col_count*sizeof(int)); + memset(complete, 0, col_count * sizeof(int)); while (cols_todo) { /* beginning of line */ @@ -634,9 +643,9 @@ print_aligned_text(const char *title, const char *const * headers, for (j = 0; j < col_count; j++) { struct lineptr *this_line = col_lineptrs[j] + line_count; - bool finalspaces = (opt_border == 2 || j != col_count-1); + bool finalspaces = (opt_border == 2 || j != col_count - 1); - if (complete[j]) /* Just print spaces... */ + if (complete[j]) /* Just print spaces... */ { if (finalspaces) fprintf(fout, "%*s", widths[j], ""); @@ -651,10 +660,11 @@ print_aligned_text(const char *title, const char *const * headers, /* * Assumption: This code used only on strings * without multibyte characters, otherwise - * this_line->width < strlen(this_ptr) and we - * get an overflow + * this_line->width < strlen(this_ptr) and we get + * an overflow */ - char *my_cell = format_numeric_locale((char *) this_line->ptr); + char *my_cell = format_numeric_locale((char *) this_line->ptr); + fprintf(fout, "%*s%s", (int) (widths[i % col_count] - strlen(my_cell)), "", my_cell); @@ -667,15 +677,15 @@ print_aligned_text(const char *title, const char *const * headers, } else fprintf(fout, "%-s%*s", this_line->ptr, - finalspaces ? (widths[j] - this_line->width) : 0, ""); + finalspaces ? (widths[j] - this_line->width) : 0, ""); /* If at the right height, done this col */ - if (line_count == heights[j]-1 || !this_line[1].ptr) + if (line_count == heights[j] - 1 || !this_line[1].ptr) { complete[j] = 1; cols_todo--; } } - + /* divider */ if ((j + 1) % col_count) { @@ -684,7 +694,7 @@ print_aligned_text(const char *title, const char *const * headers, else if (line_count == 0) fputs(" | ", fout); else - fprintf(fout, " %c ", complete[j+1] ? ' ' : ':'); + fprintf(fout, " %c ", complete[j + 1] ? ' ' : ':'); } } if (opt_border == 2) @@ -705,8 +715,8 @@ print_aligned_text(const char *title, const char *const * headers, fprintf(fout, "%s\n", *ptr); /* - * for some reason MinGW (and MSVC) outputs an extra newline, - * so this suppresses it + * for some reason MinGW (and MSVC) outputs an extra newline, so this + * suppresses it */ #ifndef WIN32 fputc('\n', fout); @@ -720,7 +730,7 @@ print_aligned_text(const char *title, const char *const * headers, free(format_space); free(complete); free(lineptr_list); - for (i= 0; i < col_count; i++) + for (i = 0; i < col_count; i++) free(format_buf[i]); free(format_buf); } @@ -732,10 +742,10 @@ print_aligned_vertical(const char *title, const char *const * headers, const char *opt_align, const printTableOpt *opt, FILE *fout) { - bool opt_tuples_only = opt->tuples_only; - bool opt_numeric_locale = opt->numericLocale; + bool opt_tuples_only = opt->tuples_only; + bool opt_numeric_locale = opt->numericLocale; unsigned short int opt_border = opt->border; - int encoding = opt->encoding; + int encoding = opt->encoding; unsigned int col_count = 0; unsigned long record = opt->prior_records + 1; const char *const * ptr; @@ -746,17 +756,18 @@ print_aligned_vertical(const char *title, const char *const * headers, dheight = 1, hformatsize = 0, dformatsize = 0; - int tmp = 0; + int tmp = 0; char *divider; unsigned int cell_count = 0; - struct lineptr *hlineptr, *dlineptr; + struct lineptr *hlineptr, + *dlineptr; if (cancel_pressed) return; if (opt_border > 2) opt_border = 2; - + if (cells[0] == NULL && opt->start_table && opt->stop_table) { fprintf(fout, _("(No rows)\n")); @@ -770,7 +781,9 @@ print_aligned_vertical(const char *title, const char *const * headers, /* Find the maximum dimensions for the headers */ for (i = 0; i < col_count; i++) { - int height, fs; + int height, + fs; + pg_wcssize((unsigned char *) headers[i], strlen(headers[i]), encoding, &tmp, &height, &fs); if (tmp > hwidth) hwidth = tmp; @@ -787,12 +800,13 @@ print_aligned_vertical(const char *title, const char *const * headers, /* find longest data cell */ for (i = 0, ptr = cells; *ptr; ptr++, i++) { - int numeric_locale_len; - int height, fs; + int numeric_locale_len; + int height, + fs; if (opt_align[i % col_count] == 'r' && opt_numeric_locale) numeric_locale_len = additional_numeric_locale_len(*ptr); - else + else numeric_locale_len = 0; pg_wcssize((unsigned char *) *ptr, strlen(*ptr), encoding, &tmp, &height, &fs); @@ -804,11 +818,14 @@ print_aligned_vertical(const char *title, const char *const * headers, if (fs > dformatsize) dformatsize = fs; } - - /* We now have all the information we need to setup the formatting structures */ + + /* + * We now have all the information we need to setup the formatting + * structures + */ dlineptr = pg_local_malloc(sizeof(*dlineptr) * dheight); hlineptr = pg_local_malloc(sizeof(*hlineptr) * hheight); - + dlineptr->ptr = pg_local_malloc(dformatsize); hlineptr->ptr = pg_local_malloc(hformatsize); @@ -838,8 +855,10 @@ print_aligned_vertical(const char *title, const char *const * headers, /* print records */ for (i = 0, ptr = cells; *ptr; i++, ptr++) { - int line_count, dcomplete, hcomplete; - + int line_count, + dcomplete, + hcomplete; + if (i % col_count == 0) { if (cancel_pressed) @@ -877,11 +896,11 @@ print_aligned_vertical(const char *title, const char *const * headers, } /* Format the header */ - pg_wcsformat((unsigned char*)headers[i % col_count], - strlen(headers[i % col_count]), encoding, hlineptr, hheight); + pg_wcsformat((unsigned char *) headers[i % col_count], + strlen(headers[i % col_count]), encoding, hlineptr, hheight); /* Format the data */ - pg_wcsformat((unsigned char*)*ptr, strlen(*ptr), encoding, dlineptr, dheight); - + pg_wcsformat((unsigned char *) *ptr, strlen(*ptr), encoding, dlineptr, dheight); + line_count = 0; dcomplete = hcomplete = 0; while (!dcomplete || !hcomplete) @@ -892,51 +911,52 @@ print_aligned_vertical(const char *title, const char *const * headers, { fprintf(fout, "%-s%*s", hlineptr[line_count].ptr, hwidth - hlineptr[line_count].width, ""); - - if (line_count == (hheight-1) || !hlineptr[line_count+1].ptr) + + if (line_count == (hheight - 1) || !hlineptr[line_count + 1].ptr) hcomplete = 1; } else fprintf(fout, "%*s", hwidth, ""); - + if (opt_border > 0) - fprintf(fout, " %c ", (line_count==0)?'|':':'); + fprintf(fout, " %c ", (line_count == 0) ? '|' : ':'); else fputs(" ", fout); if (!dcomplete) { - if (opt_align[i % col_count] == 'r' && opt_numeric_locale) - { - char *my_cell = format_numeric_locale((char *) dlineptr[line_count].ptr); - if (opt_border < 2) - fprintf(fout, "%s\n", my_cell); - else - fprintf(fout, "%-s%*s |\n", my_cell, + if (opt_align[i % col_count] == 'r' && opt_numeric_locale) + { + char *my_cell = format_numeric_locale((char *) dlineptr[line_count].ptr); + + if (opt_border < 2) + fprintf(fout, "%s\n", my_cell); + else + fprintf(fout, "%-s%*s |\n", my_cell, (int) (dwidth - strlen(my_cell)), ""); - free(my_cell); - } - else - { - if (opt_border < 2) - fprintf(fout, "%s\n", dlineptr[line_count].ptr); - else - fprintf(fout, "%-s%*s |\n", dlineptr[line_count].ptr, + free(my_cell); + } + else + { + if (opt_border < 2) + fprintf(fout, "%s\n", dlineptr[line_count].ptr); + else + fprintf(fout, "%-s%*s |\n", dlineptr[line_count].ptr, dwidth - dlineptr[line_count].width, ""); - } - - if (line_count == dheight - 1 || !dlineptr[line_count+1].ptr) - dcomplete = 1; - } - else - { - if (opt_border < 2) - fputc('\n', fout); - else - fprintf(fout, "%*s |\n", dwidth, ""); - } - line_count++; - } + } + + if (line_count == dheight - 1 || !dlineptr[line_count + 1].ptr) + dcomplete = 1; + } + else + { + if (opt_border < 2) + fputc('\n', fout); + else + fprintf(fout, "%*s |\n", dwidth, ""); + } + line_count++; + } } if (opt->stop_table) @@ -1016,8 +1036,8 @@ print_html_text(const char *title, const char *const * headers, const char *opt_align, const printTableOpt *opt, FILE *fout) { - bool opt_tuples_only = opt->tuples_only; - bool opt_numeric_locale = opt->numericLocale; + bool opt_tuples_only = opt->tuples_only; + bool opt_numeric_locale = opt->numericLocale; unsigned short int opt_border = opt->border; const char *opt_table_attr = opt->tableAttr; unsigned int col_count = 0; @@ -1117,8 +1137,8 @@ print_html_vertical(const char *title, const char *const * headers, const char *opt_align, const printTableOpt *opt, FILE *fout) { - bool opt_tuples_only = opt->tuples_only; - bool opt_numeric_locale = opt->numericLocale; + bool opt_tuples_only = opt->tuples_only; + bool opt_numeric_locale = opt->numericLocale; unsigned short int opt_border = opt->border; const char *opt_table_attr = opt->tableAttr; unsigned int col_count = 0; @@ -1255,8 +1275,8 @@ print_latex_text(const char *title, const char *const * headers, const char *opt_align, const printTableOpt *opt, FILE *fout) { - bool opt_tuples_only = opt->tuples_only; - bool opt_numeric_locale = opt->numericLocale; + bool opt_tuples_only = opt->tuples_only; + bool opt_numeric_locale = opt->numericLocale; unsigned short int opt_border = opt->border; unsigned int col_count = 0; unsigned int i; @@ -1368,8 +1388,8 @@ print_latex_vertical(const char *title, const char *const * headers, const char *opt_align, const printTableOpt *opt, FILE *fout) { - bool opt_tuples_only = opt->tuples_only; - bool opt_numeric_locale = opt->numericLocale; + bool opt_tuples_only = opt->tuples_only; + bool opt_numeric_locale = opt->numericLocale; unsigned short int opt_border = opt->border; unsigned int col_count = 0; unsigned long record = opt->prior_records + 1; @@ -1495,8 +1515,8 @@ print_troff_ms_text(const char *title, const char *const * headers, const char *opt_align, const printTableOpt *opt, FILE *fout) { - bool opt_tuples_only = opt->tuples_only; - bool opt_numeric_locale = opt->numericLocale; + bool opt_tuples_only = opt->tuples_only; + bool opt_numeric_locale = opt->numericLocale; unsigned short int opt_border = opt->border; unsigned int col_count = 0; unsigned int i; @@ -1594,12 +1614,12 @@ print_troff_ms_text(const char *title, const char *const * headers, static void print_troff_ms_vertical(const char *title, const char *const * headers, - const char *const * cells, const char *const * footers, + const char *const * cells, const char *const * footers, const char *opt_align, const printTableOpt *opt, FILE *fout) { - bool opt_tuples_only = opt->tuples_only; - bool opt_numeric_locale = opt->numericLocale; + bool opt_tuples_only = opt->tuples_only; + bool opt_numeric_locale = opt->numericLocale; unsigned short int opt_border = opt->border; unsigned int col_count = 0; unsigned long record = opt->prior_records + 1; @@ -1737,7 +1757,7 @@ PageOutput(int lines, unsigned short int pager) ) { const char *pagerprog; - FILE *pagerpipe; + FILE *pagerpipe; #ifdef TIOCGWINSZ int result; @@ -1779,10 +1799,10 @@ ClosePager(FILE *pagerpipe) /* * If printing was canceled midstream, warn about it. * - * Some pagers like less use Ctrl-C as part of their command - * set. Even so, we abort our processing and warn the user - * what we did. If the pager quit as a result of the - * SIGINT, this message won't go anywhere ... + * Some pagers like less use Ctrl-C as part of their command set. Even + * so, we abort our processing and warn the user what we did. If the + * pager quit as a result of the SIGINT, this message won't go + * anywhere ... */ if (cancel_pressed) fprintf(pagerpipe, _("Interrupted\n")); @@ -1923,8 +1943,8 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, FILE *f headers = pg_local_calloc(nfields + 1, sizeof(*headers)); for (i = 0; i < nfields; i++) - headers[i] = (char*) mbvalidate((unsigned char *) PQfname(result, i), - opt->topt.encoding); + headers[i] = (char *) mbvalidate((unsigned char *) PQfname(result, i), + opt->topt.encoding); /* set cells */ ncells = PQntuples(result) * nfields; @@ -1935,8 +1955,8 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, FILE *f if (PQgetisnull(result, i / nfields, i % nfields)) cells[i] = opt->nullPrint ? opt->nullPrint : ""; else - cells[i] = (char*) - mbvalidate((unsigned char*) PQgetvalue(result, i / nfields, i % nfields), + cells[i] = (char *) + mbvalidate((unsigned char *) PQgetvalue(result, i / nfields, i % nfields), opt->topt.encoding); } diff --git a/src/bin/psql/settings.h b/src/bin/psql/settings.h index 3e34f93b95..c294c4be2d 100644 --- a/src/bin/psql/settings.h +++ b/src/bin/psql/settings.h @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2006, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/settings.h,v 1.30 2006/08/29 22:25:07 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/psql/settings.h,v 1.31 2006/10/04 00:30:06 momjian Exp $ */ #ifndef SETTINGS_H #define SETTINGS_H @@ -87,9 +87,9 @@ typedef struct _psqlSettings VariableSpace vars; /* "shell variable" repository */ /* - * The remaining fields are set by assign hooks associated with - * entries in "vars". They should not be set directly except by - * those hook functions. + * The remaining fields are set by assign hooks associated with entries in + * "vars". They should not be set directly except by those hook + * functions. */ bool autocommit; bool on_error_stop; diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c index 6cbd95da9e..5c79002092 100644 --- a/src/bin/psql/startup.c +++ b/src/bin/psql/startup.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2006, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.137 2006/08/29 22:25:08 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.138 2006/10/04 00:30:06 momjian Exp $ */ #include "postgres_fe.h" @@ -75,7 +75,7 @@ struct adhoc_opts char *action_string; bool no_readline; bool no_psqlrc; - bool single_txn; + bool single_txn; }; static int parse_version(const char *versionString); @@ -760,7 +760,6 @@ checkWin32Codepage(void) concp, wincp); } } - #endif diff --git a/src/bin/psql/stringutils.c b/src/bin/psql/stringutils.c index 9b089d84f8..f8060002db 100644 --- a/src/bin/psql/stringutils.c +++ b/src/bin/psql/stringutils.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2006, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/stringutils.c,v 1.44 2006/07/14 14:52:27 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/psql/stringutils.c,v 1.45 2006/10/04 00:30:06 momjian Exp $ */ #include "postgres_fe.h" @@ -31,7 +31,7 @@ static void strip_quotes(char *source, char quote, char escape, int encoding); * quote - set of characters that can quote a token (NULL if none) * escape - character that can quote quotes (0 if none) * e_strings - if TRUE, treat E'...' syntax as a valid token - * del_quotes - if TRUE, strip quotes from the returned token, else return + * del_quotes - if TRUE, strip quotes from the returned token, else return * it exactly as found in the string * encoding - the active character-set encoding * diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 64b9576a66..b04f2846aa 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2006, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.155 2006/09/22 21:39:57 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.156 2006/10/04 00:30:06 momjian Exp $ */ /*---------------------------------------------------------------------- @@ -480,7 +480,7 @@ static PGresult *exec_query(const char *query); static char *previous_word(int point, int skip); -static int find_open_parenthesis(int end); +static int find_open_parenthesis(int end); #if 0 static char *quote_file_name(char *text, int match_type, char *quote_pointer); @@ -767,13 +767,16 @@ psql_completion(char *text, int start, int end) pg_strcasecmp(prev_wd, "RENAME") == 0)) COMPLETE_WITH_ATTR(prev2_wd, " UNION SELECT 'COLUMN'"); - /* If we have TABLE <sth> ALTER COLUMN|RENAME COLUMN, provide list of columns */ + /* + * If we have TABLE <sth> ALTER COLUMN|RENAME COLUMN, provide list of + * columns + */ else if (pg_strcasecmp(prev4_wd, "TABLE") == 0 && (pg_strcasecmp(prev2_wd, "ALTER") == 0 || pg_strcasecmp(prev2_wd, "RENAME") == 0) && pg_strcasecmp(prev_wd, "COLUMN") == 0) COMPLETE_WITH_ATTR(prev3_wd, ""); - + /* ALTER TABLE xxx RENAME yyy */ else if (pg_strcasecmp(prev4_wd, "TABLE") == 0 && pg_strcasecmp(prev2_wd, "RENAME") == 0 && @@ -951,7 +954,7 @@ psql_completion(char *text, int start, int end) {"CAST", "CONVERSION", "DATABASE", "INDEX", "LANGUAGE", "RULE", "SCHEMA", "SEQUENCE", "TABLE", "TYPE", "VIEW", "COLUMN", "AGGREGATE", "FUNCTION", "OPERATOR", "TRIGGER", "CONSTRAINT", "DOMAIN", "LARGE OBJECT", - "TABLESPACE", "ROLE", NULL}; + "TABLESPACE", "ROLE", NULL}; COMPLETE_WITH_LIST(list_COMMENT); } @@ -1048,11 +1051,11 @@ psql_completion(char *text, int start, int end) if (find_open_parenthesis(end)) COMPLETE_WITH_ATTR(prev_wd, ""); else - COMPLETE_WITH_CONST("("); + COMPLETE_WITH_CONST("("); } else if (pg_strcasecmp(prev5_wd, "INDEX") == 0 && - pg_strcasecmp(prev3_wd, "ON") == 0 && - pg_strcasecmp(prev_wd, "(") == 0) + pg_strcasecmp(prev3_wd, "ON") == 0 && + pg_strcasecmp(prev_wd, "(") == 0) COMPLETE_WITH_ATTR(prev2_wd, ""); /* same if you put in USING */ else if (pg_strcasecmp(prev4_wd, "ON") == 0 && @@ -1264,7 +1267,8 @@ psql_completion(char *text, int start, int end) if (find_open_parenthesis(end)) { static const char func_args_query[] = "select pg_catalog.oidvectortypes(proargtypes)||')' from pg_proc where proname='%s'"; - char *tmp_buf = malloc(strlen(func_args_query) + strlen(prev_wd)); + char *tmp_buf = malloc(strlen(func_args_query) + strlen(prev_wd)); + sprintf(tmp_buf, func_args_query, prev_wd); COMPLETE_WITH_QUERY(tmp_buf); free(tmp_buf); @@ -1278,16 +1282,17 @@ psql_completion(char *text, int start, int end) { static const char *const list_DROPCR[] = {"CASCADE", "RESTRICT", NULL}; - + COMPLETE_WITH_LIST(list_DROPCR); } } else if (pg_strcasecmp(prev4_wd, "DROP") == 0 && - pg_strcasecmp(prev3_wd, "FUNCTION") == 0 && - pg_strcasecmp(prev_wd, "(") == 0) + pg_strcasecmp(prev3_wd, "FUNCTION") == 0 && + pg_strcasecmp(prev_wd, "(") == 0) { static const char func_args_query[] = "select pg_catalog.oidvectortypes(proargtypes)||')' from pg_proc where proname='%s'"; - char *tmp_buf = malloc(strlen(func_args_query) + strlen(prev2_wd)); + char *tmp_buf = malloc(strlen(func_args_query) + strlen(prev2_wd)); + sprintf(tmp_buf, func_args_query, prev2_wd); COMPLETE_WITH_QUERY(tmp_buf); free(tmp_buf); @@ -1376,8 +1381,8 @@ psql_completion(char *text, int start, int end) { static const char *const list_privileg[] = {"SELECT", "INSERT", "UPDATE", "DELETE", "RULE", "REFERENCES", - "TRIGGER", "CREATE", "CONNECT", "TEMPORARY", "EXECUTE", "USAGE", - "ALL", NULL}; + "TRIGGER", "CREATE", "CONNECT", "TEMPORARY", "EXECUTE", "USAGE", + "ALL", NULL}; COMPLETE_WITH_LIST(list_privileg); } @@ -2394,22 +2399,24 @@ previous_word(int point, int skip) /* Find the parenthesis after the last word */ -static int find_open_parenthesis(int end) +static int +find_open_parenthesis(int end) { - int i = end-1; - - while((rl_line_buffer[i]!=' ')&&(i>=0)) + int i = end - 1; + + while ((rl_line_buffer[i] != ' ') && (i >= 0)) { - if (rl_line_buffer[i]=='(') return 1; + if (rl_line_buffer[i] == '(') + return 1; i--; } - while((rl_line_buffer[i]==' ')&&(i>=0)) + while ((rl_line_buffer[i] == ' ') && (i >= 0)) { i--; } - if (rl_line_buffer[i]=='(') + if (rl_line_buffer[i] == '(') { - return 1; + return 1; } return 0; diff --git a/src/bin/psql/variables.h b/src/bin/psql/variables.h index e4dce97a0a..348b3a0e49 100644 --- a/src/bin/psql/variables.h +++ b/src/bin/psql/variables.h @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2006, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/variables.h,v 1.19 2006/08/29 15:19:51 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/psql/variables.h,v 1.20 2006/10/04 00:30:06 momjian Exp $ */ #ifndef VARIABLES_H #define VARIABLES_H @@ -39,7 +39,7 @@ typedef struct _variable *VariableSpace; VariableSpace CreateVariableSpace(void); const char *GetVariable(VariableSpace space, const char *name); -bool ParseVariableBool(const char *val); +bool ParseVariableBool(const char *val); int ParseVariableNum(const char *val, int defaultval, int faultval, diff --git a/src/bin/scripts/common.c b/src/bin/scripts/common.c index d5f0262054..5190534268 100644 --- a/src/bin/scripts/common.c +++ b/src/bin/scripts/common.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/bin/scripts/common.c,v 1.23 2006/10/03 21:45:20 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/scripts/common.c,v 1.24 2006/10/04 00:30:06 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -206,15 +206,18 @@ executeCommand(PGconn *conn, const char *query, bool yesno_prompt(const char *question) { - char prompt[256]; + char prompt[256]; - /* translator: This is a question followed by the translated options for "yes" and "no". */ + /* + * translator: This is a question followed by the translated options for + * "yes" and "no". + */ snprintf(prompt, sizeof(prompt), _("%s (%s/%s) "), _(question), _(PG_YESLETTER), _(PG_NOLETTER)); for (;;) { - char *resp; + char *resp; resp = simple_prompt(prompt, 1, true); diff --git a/src/bin/scripts/createuser.c b/src/bin/scripts/createuser.c index a3f5747004..b1351c7693 100644 --- a/src/bin/scripts/createuser.c +++ b/src/bin/scripts/createuser.c @@ -5,7 +5,7 @@ * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/bin/scripts/createuser.c,v 1.33 2006/09/22 18:50:41 petere Exp $ + * $PostgreSQL: pgsql/src/bin/scripts/createuser.c,v 1.34 2006/10/04 00:30:06 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -17,7 +17,8 @@ static void help(const char *progname); -enum trivalue { +enum trivalue +{ TRI_DEFAULT, TRI_NO, TRI_YES @@ -66,13 +67,14 @@ main(int argc, char *argv[]) char *conn_limit = NULL; bool pwprompt = false; char *newpassword = NULL; - /* Tri-valued variables. */ - enum trivalue createdb = TRI_DEFAULT, - superuser = TRI_DEFAULT, - createrole = TRI_DEFAULT, - inherit = TRI_DEFAULT, - login = TRI_DEFAULT, - encrypted = TRI_DEFAULT; + + /* Tri-valued variables. */ + enum trivalue createdb = TRI_DEFAULT, + superuser = TRI_DEFAULT, + createrole = TRI_DEFAULT, + inherit = TRI_DEFAULT, + login = TRI_DEFAULT, + encrypted = TRI_DEFAULT; PQExpBufferData sql; |
