3939 * Portions Copyright (c) 1994, Regents of the University of California
4040 * Portions taken from FreeBSD.
4141 *
42- * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.70 2004/11/29 03:05:03 tgl Exp $
42+ * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.71 2004/12/27 20:39:21 tgl Exp $
4343 *
4444 *-------------------------------------------------------------------------
4545 */
@@ -147,9 +147,10 @@ charbackend_exec[MAXPGPATH];
147147
148148static void * xmalloc (size_t size );
149149static char * xstrdup (const char * s );
150- static char * * replace_token (char * * lines ,char * token ,char * replacement );
150+ static char * * replace_token (char * * lines ,
151+ const char * token ,const char * replacement );
151152#ifndef HAVE_UNIX_SOCKETS
152- static char * * filter_lines_with_token (char * * lines ,char * token );
153+ static char * * filter_lines_with_token (char * * lines ,const char * token );
153154#endif
154155static char * * readfile (char * path );
155156static void writefile (char * path ,char * * lines );
@@ -275,7 +276,7 @@ xstrdup(const char *s)
275276 * doesn't need any regexp stuff.
276277 */
277278static char * *
278- replace_token (char * * lines ,char * token ,char * replacement )
279+ replace_token (char * * lines ,const char * token ,const char * replacement )
279280{
280281int numlines = 1 ;
281282int i ;
@@ -300,7 +301,6 @@ replace_token(char **lines, char *token, char *replacement)
300301int pre ;
301302
302303/* just copy pointer if NULL or no change needed */
303-
304304if (lines [i ]== NULL || (where = strstr (lines [i ],token ))== NULL )
305305{
306306result [i ]= lines [i ];
@@ -320,21 +320,19 @@ replace_token(char **lines, char *token, char *replacement)
320320strcpy (newline + pre + replen ,lines [i ]+ pre + toklen );
321321
322322result [i ]= newline ;
323-
324323}
325324
326325return result ;
327-
328326}
329327
330328/*
331329 * make a copy of lines without any that contain the token
332- * a sort of poor man's grep -v
333330 *
331+ * a sort of poor man's grep -v
334332 */
335333#ifndef HAVE_UNIX_SOCKETS
336334static char * *
337- filter_lines_with_token (char * * lines ,char * token )
335+ filter_lines_with_token (char * * lines ,const char * token )
338336{
339337int numlines = 1 ;
340338int i ,src ,dst ;
@@ -1165,6 +1163,11 @@ setup_config(void)
11651163snprintf (repltok ,sizeof (repltok ),"shared_buffers = %d" ,n_buffers );
11661164conflines = replace_token (conflines ,"#shared_buffers = 1000" ,repltok );
11671165
1166+ #if DEF_PGPORT != 5432
1167+ snprintf (repltok ,sizeof (repltok ),"#port = %d" ,DEF_PGPORT );
1168+ conflines = replace_token (conflines ,"#port = 5432" ,repltok );
1169+ #endif
1170+
11681171lc_messages = escape_quotes (lc_messages );
11691172snprintf (repltok ,sizeof (repltok ),"lc_messages = '%s'" ,lc_messages );
11701173conflines = replace_token (conflines ,"#lc_messages = 'C'" ,repltok );