Alvaro Herrera <alvhe...@commandprompt.com> writes:
> Hmm, this needs some cleanup; the comments still talk about the old
> function name; and about just the recovery.conf file.

Ah yes, thinking it's an easy patch is not helping. Please find attached
a revised version of it.

Regards,
-- 
Dimitri Fontaine
http://2ndQuadrant.fr     PostgreSQL : Expertise, Formation et Support

*** a/src/backend/access/transam/xlog.c
--- b/src/backend/access/transam/xlog.c
***************
*** 55,60 ****
--- 55,61 ----
  #include "utils/guc.h"
  #include "utils/ps_status.h"
  #include "utils/relmapper.h"
+ #include "utils/cfparser.h"
  #include "pg_trace.h"
  
  
***************
*** 5018,5117 **** str_time(pg_time_t tnow)
  }
  
  /*
-  * Parse one line from recovery.conf. 'cmdline' is the raw line from the
-  * file. If the line is parsed successfully, returns true, false indicates
-  * syntax error. On success, *key_p and *value_p are set to the parameter
-  * name and value on the line, respectively. If the line is an empty line,
-  * consisting entirely of whitespace and comments, function returns true
-  * and *keyp_p and *value_p are set to NULL.
-  *
-  * The pointers returned in *key_p and *value_p point to an internal buffer
-  * that is valid only until the next call of parseRecoveryCommandFile().
-  */
- static bool
- parseRecoveryCommandFileLine(char *cmdline, char **key_p, char **value_p)
- {
- 	char	   *ptr;
- 	char	   *bufp;
- 	char	   *key;
- 	char	   *value;
- 	static char *buf = NULL;
- 
- 	*key_p = *value_p = NULL;
- 
- 	/*
- 	 * Allocate the buffer on first use. It's used to hold both the parameter
- 	 * name and value.
- 	 */
- 	if (buf == NULL)
- 		buf = malloc(MAXPGPATH + 1);
- 	bufp = buf;
- 
- 	/* Skip any whitespace at the beginning of line */
- 	for (ptr = cmdline; *ptr; ptr++)
- 	{
- 		if (!isspace((unsigned char) *ptr))
- 			break;
- 	}
- 	/* Ignore empty lines */
- 	if (*ptr == '\0' || *ptr == '#')
- 		return true;
- 
- 	/* Read the parameter name */
- 	key = bufp;
- 	while (*ptr && !isspace((unsigned char) *ptr) &&
- 		   *ptr != '=' && *ptr != '\'')
- 		*(bufp++) = *(ptr++);
- 	*(bufp++) = '\0';
- 
- 	/* Skip to the beginning quote of the parameter value */
- 	ptr = strchr(ptr, '\'');
- 	if (!ptr)
- 		return false;
- 	ptr++;
- 
- 	/* Read the parameter value to *bufp. Collapse any '' escapes as we go. */
- 	value = bufp;
- 	for (;;)
- 	{
- 		if (*ptr == '\'')
- 		{
- 			ptr++;
- 			if (*ptr == '\'')
- 				*(bufp++) = '\'';
- 			else
- 			{
- 				/* end of parameter */
- 				*bufp = '\0';
- 				break;
- 			}
- 		}
- 		else if (*ptr == '\0')
- 			return false;		/* unterminated quoted string */
- 		else
- 			*(bufp++) = *ptr;
- 
- 		ptr++;
- 	}
- 	*(bufp++) = '\0';
- 
- 	/* Check that there's no garbage after the value */
- 	while (*ptr)
- 	{
- 		if (*ptr == '#')
- 			break;
- 		if (!isspace((unsigned char) *ptr))
- 			return false;
- 		ptr++;
- 	}
- 
- 	/* Success! */
- 	*key_p = key;
- 	*value_p = value;
- 	return true;
- }
- 
- /*
   * See if there is a recovery command file (recovery.conf), and if so
   * read in parameters for archive recovery and XLOG streaming.
   *
--- 5019,5024 ----
***************
*** 5147,5153 **** readRecoveryCommandFile(void)
  		char	   *tok1;
  		char	   *tok2;
  
! 		if (!parseRecoveryCommandFileLine(cmdline, &tok1, &tok2))
  		{
  			syntaxError = true;
  			break;
--- 5054,5060 ----
  		char	   *tok1;
  		char	   *tok2;
  
! 		if (!cfParseOneLine(cmdline, &tok1, &tok2))
  		{
  			syntaxError = true;
  			break;
*** a/src/backend/utils/misc/Makefile
--- b/src/backend/utils/misc/Makefile
***************
*** 15,21 **** include $(top_builddir)/src/Makefile.global
  override CPPFLAGS := -I. -I$(srcdir) $(CPPFLAGS)
  
  OBJS = guc.o help_config.o pg_rusage.o ps_status.o superuser.o tzparser.o \
!        rbtree.o
  
  # This location might depend on the installation directories. Therefore
  # we can't subsitute it into pg_config.h.
--- 15,21 ----
  override CPPFLAGS := -I. -I$(srcdir) $(CPPFLAGS)
  
  OBJS = guc.o help_config.o pg_rusage.o ps_status.o superuser.o tzparser.o \
!        rbtree.o cfparser.o
  
  # This location might depend on the installation directories. Therefore
  # we can't subsitute it into pg_config.h.
*** /dev/null
--- b/src/backend/utils/misc/cfparser.c
***************
*** 0 ****
--- 1,114 ----
+ /*-------------------------------------------------------------------------
+  *
+  * cfparser.c
+  *	  Function for parsing RecoveryCommandFile and Extension Control files
+  *
+  * This very simple file format (line oriented, variable = 'value') is used
+  * as the recovery.conf and the extension control file format.
+  *
+  * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
+  * Portions Copyright (c) 1994, Regents of the University of California
+  *
+  * IDENTIFICATION
+  *	  src/backend/utils/misc/cfparser.c
+  *
+  *-------------------------------------------------------------------------
+  */
+ 
+ #include "postgres.h"
+ 
+ /*
+  * Parse one line from recovery.conf or an extension control file.
+  *
+  * 'cmdline' is the raw line from the file. If the line is parsed
+  * successfully, returns true, false indicates syntax error. On success,
+  * *key_p and *value_p are set to the parameter name and value on the line,
+  * respectively. If the line is an empty line, consisting entirely of
+  * whitespace and comments, function returns true and *keyp_p and *value_p
+  * are set to NULL.
+  *
+  * The pointers returned in *key_p and *value_p point to an internal buffer
+  * that is valid only until the next call of cfParseOneLine().
+  */
+ bool
+ cfParseOneLine(char *cmdline, char **key_p, char **value_p)
+ {
+ 	char	   *ptr;
+ 	char	   *bufp;
+ 	char	   *key;
+ 	char	   *value;
+ 	static char *buf = NULL;
+ 
+ 	*key_p = *value_p = NULL;
+ 
+ 	/*
+ 	 * Allocate the buffer on first use. It's used to hold both the parameter
+ 	 * name and value.
+ 	 */
+ 	if (buf == NULL)
+ 		buf = malloc(MAXPGPATH + 1);
+ 	bufp = buf;
+ 
+ 	/* Skip any whitespace at the beginning of line */
+ 	for (ptr = cmdline; *ptr; ptr++)
+ 	{
+ 		if (!isspace((unsigned char) *ptr))
+ 			break;
+ 	}
+ 	/* Ignore empty lines */
+ 	if (*ptr == '\0' || *ptr == '#')
+ 		return true;
+ 
+ 	/* Read the parameter name */
+ 	key = bufp;
+ 	while (*ptr && !isspace((unsigned char) *ptr) &&
+ 		   *ptr != '=' && *ptr != '\'')
+ 		*(bufp++) = *(ptr++);
+ 	*(bufp++) = '\0';
+ 
+ 	/* Skip to the beginning quote of the parameter value */
+ 	ptr = strchr(ptr, '\'');
+ 	if (!ptr)
+ 		return false;
+ 	ptr++;
+ 
+ 	/* Read the parameter value to *bufp. Collapse any '' escapes as we go. */
+ 	value = bufp;
+ 	for (;;)
+ 	{
+ 		if (*ptr == '\'')
+ 		{
+ 			ptr++;
+ 			if (*ptr == '\'')
+ 				*(bufp++) = '\'';
+ 			else
+ 			{
+ 				/* end of parameter */
+ 				*bufp = '\0';
+ 				break;
+ 			}
+ 		}
+ 		else if (*ptr == '\0')
+ 			return false;		/* unterminated quoted string */
+ 		else
+ 			*(bufp++) = *ptr;
+ 
+ 		ptr++;
+ 	}
+ 	*(bufp++) = '\0';
+ 
+ 	/* Check that there's no garbage after the value */
+ 	while (*ptr)
+ 	{
+ 		if (*ptr == '#')
+ 			break;
+ 		if (!isspace((unsigned char) *ptr))
+ 			return false;
+ 		ptr++;
+ 	}
+ 
+ 	/* Success! */
+ 	*key_p = key;
+ 	*value_p = value;
+ 	return true;
+ }
*** /dev/null
--- b/src/include/utils/cfparser.h
***************
*** 0 ****
--- 1,18 ----
+ /*-------------------------------------------------------------------------
+  *
+  * cfparser.h
+  *	  Function for parsing RecoveryCommandFile lines
+  *
+  * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
+  * Portions Copyright (c) 1994, Regents of the University of California
+  *
+  * src/include/utils/cfparser.h
+  *
+  *-------------------------------------------------------------------------
+  */
+ #ifndef CFPARSER_H
+ #define CFPARSER_H
+ 
+ bool cfParseOneLine(char *cmdline, char **key_p, char **value_p);
+ 
+ #endif   /* CFPARSER_H */
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to