10
10
* Written by Peter Eisentraut <peter_e@gmx.net>.
11
11
*
12
12
* 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 $
14
14
*
15
15
*--------------------------------------------------------------------
16
16
*/
@@ -168,6 +168,14 @@ static const char *show_tcp_keepalives_count(void);
168
168
static bool assign_autovacuum_max_workers (int newval , bool doit , GucSource source );
169
169
static bool assign_maxconnections (int newval , bool doit , GucSource source );
170
170
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
+
171
179
/*
172
180
* Options for enum values defined in this module.
173
181
*/
@@ -3134,8 +3142,9 @@ InitializeGUCOptions(void)
3134
3142
if (conf -> assign_hook )
3135
3143
if (!(* conf -> assign_hook ) (conf -> boot_val , true,
3136
3144
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 ));
3139
3148
* conf -> variable = conf -> reset_val = conf -> boot_val ;
3140
3149
break ;
3141
3150
}
@@ -4230,7 +4239,7 @@ config_enum_lookup_value(struct config_enum *record, int val)
4230
4239
* Lookup the value for an enum option with the selected name
4231
4240
* (case-insensitive).
4232
4241
* 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 .
4234
4243
*
4235
4244
*/
4236
4245
static bool
@@ -4243,7 +4252,7 @@ config_enum_lookup_name(struct config_enum *record, const char *value, int *retv
4243
4252
4244
4253
while (entry && entry -> name )
4245
4254
{
4246
- if (! pg_strcasecmp (value , entry -> name ))
4255
+ if (pg_strcasecmp (value , entry -> name ) == 0 )
4247
4256
{
4248
4257
* retval = entry -> val ;
4249
4258
return TRUE;
@@ -4255,10 +4264,10 @@ config_enum_lookup_name(struct config_enum *record, const char *value, int *retv
4255
4264
4256
4265
4257
4266
/*
4258
- * Returna list of all available options for an enum, separated
4267
+ * Return a list of all available options for an enum, separated
4259
4268
* 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.
4262
4271
*/
4263
4272
static char *
4264
4273
config_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,
4895
4904
{
4896
4905
ereport (elevel ,
4897
4906
(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 ))));
4900
4910
return false;
4901
4911
}
4902
4912
@@ -5592,6 +5602,30 @@ DefineCustomStringVariable(const char *name,
5592
5602
define_custom_variable (& var -> gen );
5593
5603
}
5594
5604
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
+
5595
5629
void
5596
5630
EmitWarningsOnPlaceholders (const char * className )
5597
5631
{
0 commit comments