diff -u \cvs\pgsql\src\bin\psql\command.c \cvs\pgsql.nw2\src\bin\psql\command.c
--- \cvs\pgsql\src\bin\psql\command.c	Sat Aug 10 03:56:23 2002
+++ \cvs\pgsql.nw2\src\bin\psql\command.c	Wed Aug 14 23:04:44 2002
@@ -282,7 +282,7 @@
 			dir = opt;
 		else
 		{
-#ifndef WIN32
+#if !defined(WIN32) && !defined(N_PLAT_NLM)
 			struct passwd *pw;
 
 			pw = getpwuid(geteuid());
@@ -299,7 +299,7 @@
 			 * directory, so if someone wants to code this here instead...
 			 */
 			dir = "/";
-#endif   /* WIN32 */
+#endif   /* WIN32 N_PLAT_NLM */
 		}
 
 		if (chdir(dir) == -1)
@@ -1600,7 +1600,7 @@
 	if (!error)
 		error = !editFile(fname);
 
-#ifndef WIN32
+#if !defined(WIN32) && !defined(N_PLAT_NLM)
 	if (!error && stat(fname, &after) != 0)
 	{
 		psql_error("%s: %s\n", fname, strerror(errno));
Common subdirectories: \cvs\pgsql\src\bin\psql\CVS and \cvs\pgsql.nw2\src\bin\psql\CVS
diff -u \cvs\pgsql\src\bin\psql\help.c \cvs\pgsql.nw2\src\bin\psql\help.c
--- \cvs\pgsql\src\bin\psql\help.c	Sat Aug 10 19:35:01 2002
+++ \cvs\pgsql.nw2\src\bin\psql\help.c	Wed Aug 14 22:58:46 2002
@@ -53,7 +53,7 @@
 	const char *env;
 	const char *user;
 
-#ifndef WIN32
+#if !defined(WIN32) && !defined(N_PLAT_NLM)
 	struct passwd *pw = NULL;
 #endif
 
@@ -61,6 +61,7 @@
 	user = getenv("PGUSER");
 	if (!user)
 	{
+#ifndef N_PLAT_NLM
 #ifndef WIN32
 		pw = getpwuid(geteuid());
 		if (pw)
@@ -77,6 +78,9 @@
 		if (GetUserName(buf, &bufsize))
 			user = buf;
 #endif /* WIN32 */
+#else
+		user = "?";
+#endif /* N_PLAT_NLM */ 
 	}
 
 /* If this " is the start of the string then it ought to end there to fit in 80 columns >> " */
@@ -110,6 +114,9 @@
 	puts(_("  -l              List available databases, then exit"));
 	puts(_("  -n              Disable enhanced command line editing (readline)"));
 	puts(_("  -o FILENAME     Send query results to file (or |pipe)"));
+#ifdef N_PLAT_NLM
+	pressanykey();
+#endif
 
 	/* Display default port */
 	env = getenv("PGPORT");
diff -u \cvs\pgsql\src\bin\psql\print.c \cvs\pgsql.nw2\src\bin\psql\print.c
--- \cvs\pgsql\src\bin\psql\print.c	Thu Jul 18 04:46:24 2002
+++ \cvs\pgsql.nw2\src\bin\psql\print.c	Wed Aug 14 23:02:54 2002
@@ -1053,6 +1053,7 @@
 	{
 		const char *pagerprog;
 
+#ifndef N_PLAT_NLM
 #ifdef TIOCGWINSZ
 		unsigned int col_count = 0,
 					row_count = 0,
@@ -1089,6 +1090,7 @@
 #ifdef TIOCGWINSZ
 		}
 #endif
+#endif /* N_PLAT_NLM */
 	}
 
 	if (pagerfd)
diff -u \cvs\pgsql\src\bin\psql\startup.c \cvs\pgsql.nw2\src\bin\psql\startup.c
--- \cvs\pgsql\src\bin\psql\startup.c	Sat Aug 10 19:35:01 2002
+++ \cvs\pgsql.nw2\src\bin\psql\startup.c	Wed Aug 14 23:01:38 2002
@@ -120,11 +120,17 @@
 	{
 		if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
 		{
+#ifdef N_PLAT_NLM
+			setscreenmode(0);
+#endif
 			usage();
 			exit(EXIT_SUCCESS);
 		}
 		if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
 		{
+#ifdef N_PLAT_NLM
+			setscreenmode(0);
+#endif
 			showVersion();
 			exit(EXIT_SUCCESS);
 		}
@@ -207,6 +213,15 @@
 	{
 		fprintf(stderr, "%s: %s", pset.progname, PQerrorMessage(pset.db));
 		PQfinish(pset.db);
+
+		DeleteVariable(pset.vars, "VERSION");
+		DeleteVariable(pset.vars, "ECHO");
+		DeleteVariable(pset.vars, "ECHO_HIDDEN");
+		DeleteVariable(pset.vars, "ECHO");
+		DestroyVariableSpace(pset.vars);
+		free(pset.popt.topt.fieldSep);
+		free(pset.popt.topt.recordSep);
+
 		exit(EXIT_BADCONN);
 	}
 
@@ -308,6 +323,22 @@
 	/* clean up */
 	PQfinish(pset.db);
 	setQFout(NULL);
+
+	DeleteVariable(pset.vars, "PROMPT3");
+	DeleteVariable(pset.vars, "PROMPT2");
+	DeleteVariable(pset.vars, "PROMPT1");
+	DeleteVariable(pset.vars, "ENCODING");
+	DeleteVariable(pset.vars, "PORT");
+	DeleteVariable(pset.vars, "HOST");
+	DeleteVariable(pset.vars, "USER");
+	DeleteVariable(pset.vars, "DBNAME");
+	DeleteVariable(pset.vars, "VERSION");
+	DeleteVariable(pset.vars, "ECHO");
+	DeleteVariable(pset.vars, "ECHO_HIDDEN");
+	DeleteVariable(pset.vars, "ECHO");
+	DestroyVariableSpace(pset.vars);
+	free(pset.popt.topt.fieldSep);
+	free(pset.popt.topt.recordSep);
 
 	return successResult;
 }
diff -u \cvs\pgsql\src\bin\psql\variables.c \cvs\pgsql.nw2\src\bin\psql\variables.c
--- \cvs\pgsql\src\bin\psql\variables.c	Sat Feb 10 01:31:28 2001
+++ \cvs\pgsql.nw2\src\bin\psql\variables.c	Wed Aug 14 22:55:16 2002
@@ -159,5 +159,7 @@
 		return;
 
 	DestroyVariableSpace(space->next);
+	free(space->name);
+	free(space->value);
 	free(space);
 }
