1010 * Written by Peter Eisentraut <peter_e@gmx.net>.
1111 *
1212 * IDENTIFICATION
13- * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.437 2008/03/10 12:55:13 mha Exp $
13+ * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.438 2008/03/16 16:42:44 mha Exp $
1414 *
1515 *--------------------------------------------------------------------
1616 */
@@ -168,6 +168,14 @@ static const char *show_tcp_keepalives_count(void);
168168static bool assign_autovacuum_max_workers (int newval , bool doit , GucSource source );
169169static bool assign_maxconnections (int newval , bool doit , GucSource source );
170170
171+ static const char * config_enum_lookup_value (struct config_enum * record , int val );
172+ static bool config_enum_lookup_name (struct config_enum * record ,
173+ const char * value , int * retval );
174+ static char * config_enum_get_options (struct config_enum * record ,
175+ const char * prefix , const char * suffix );
176+
177+
178+
171179/*
172180 * Options for enum values defined in this module.
173181 */
@@ -3134,8 +3142,9 @@ InitializeGUCOptions(void)
31343142 if (conf -> assign_hook )
31353143 if (!(* conf -> assign_hook ) (conf -> boot_val , true,
31363144 PGC_S_DEFAULT ))
3137- elog (FATAL , "failed to initialize %s to %d" ,
3138- conf -> gen .name , conf -> boot_val );
3145+ elog (FATAL , "failed to initialize %s to %s" ,
3146+ conf -> gen .name ,
3147+ config_enum_lookup_value (conf , conf -> boot_val ));
31393148 * conf -> variable = conf -> reset_val = conf -> boot_val ;
31403149 break ;
31413150 }
@@ -4230,7 +4239,7 @@ config_enum_lookup_value(struct config_enum *record, int val)
42304239 * Lookup the value for an enum option with the selected name
42314240 * (case-insensitive).
42324241 * If the enum option is found, sets the retval value and returns
4233- * true. If it's not found, return FALSE and don't touch retval .
4242+ * true. If it's not found, return FALSE and retval is set to 0 .
42344243 *
42354244 */
42364245static bool
@@ -4243,7 +4252,7 @@ config_enum_lookup_name(struct config_enum *record, const char *value, int *retv
42434252
42444253 while (entry && entry -> name )
42454254 {
4246- if (! pg_strcasecmp (value , entry -> name ))
4255+ if (pg_strcasecmp (value , entry -> name ) == 0 )
42474256 {
42484257 * retval = entry -> val ;
42494258 return TRUE;
@@ -4255,10 +4264,10 @@ config_enum_lookup_name(struct config_enum *record, const char *value, int *retv
42554264
42564265
42574266/*
4258- * Returna list of all available options for an enum, separated
4267+ * Return a list of all available options for an enum, separated
42594268 * by ", " (comma-space).
4260- * If prefix is gievn , it is added before the first enum value.
4261- * If suffix is given , it is added to the end of the string.
4269+ * If prefix is non-NULL , it is added before the first enum value.
4270+ * If suffix is non-NULL , it is added to the end of the string.
42624271 */
42634272static char *
42644273config_enum_get_options (struct config_enum * record , const char * prefix , const char * suffix )
@@ -4895,8 +4904,9 @@ set_config_option(const char *name, const char *value,
48954904 {
48964905 ereport (elevel ,
48974906 (errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
4898- errmsg ("invalid value for parameter \"%s\": \"%d\"" ,
4899- name , newval )));
4907+ errmsg ("invalid value for parameter \"%s\": \"%s\"" ,
4908+ name ,
4909+ config_enum_lookup_value (conf , newval ))));
49004910 return false;
49014911 }
49024912
@@ -5592,6 +5602,30 @@ DefineCustomStringVariable(const char *name,
55925602 define_custom_variable (& var -> gen );
55935603}
55945604
5605+ void
5606+ DefineCustomEnumVariable (const char * name ,
5607+ const char * short_desc ,
5608+ const char * long_desc ,
5609+ int * valueAddr ,
5610+ const struct config_enum_entry * options ,
5611+ GucContext context ,
5612+ GucEnumAssignHook assign_hook ,
5613+ GucShowHook show_hook )
5614+ {
5615+ struct config_enum * var ;
5616+
5617+ var = (struct config_enum * )
5618+ init_custom_variable (name , short_desc , long_desc , context ,
5619+ PGC_ENUM , sizeof (struct config_enum ));
5620+ var -> variable = valueAddr ;
5621+ var -> boot_val = * valueAddr ;
5622+ var -> reset_val = * valueAddr ;
5623+ var -> options = options ;
5624+ var -> assign_hook = assign_hook ;
5625+ var -> show_hook = show_hook ;
5626+ define_custom_variable (& var -> gen );
5627+ }
5628+
55955629void
55965630EmitWarningsOnPlaceholders (const char * className )
55975631{
0 commit comments