2
2
* Routines for handling of 'SET var TO', 'SHOW var' and 'RESET var'
3
3
* statements.
4
4
*
5
- * $Id: variable.c,v 1.11 1997/06/03 06:29:31 vadim Exp $
5
+ * $Id: variable.c,v 1.12 1997/06/20 17:17:03 thomas Exp $
6
6
*
7
7
*/
8
8
9
9
#include <stdio.h>
10
10
#include <string.h>
11
+ #include <ctype.h>
11
12
#include "postgres.h"
12
13
#include "miscadmin.h"
13
14
#include "tcop/variable.h"
@@ -38,78 +39,82 @@ static const char *get_token(char **tok, char **val, const char *str)
38
39
{
39
40
const char * start ;
40
41
int len = 0 ;
41
-
42
- * tok = * val = NULL ;
43
-
42
+
43
+ * tok = NULL ;
44
+ if (val != NULL ) * val = NULL ;
45
+
44
46
if ( !(* str ) )
45
47
return NULL ;
46
-
48
+
47
49
/* skip white spaces */
48
- while ( * str == ' ' || * str == '\t' )
49
- str ++ ;
50
+ while (isspace (* str )) str ++ ;
50
51
if ( * str == ',' || * str == '=' )
51
52
elog (WARN , "Syntax error near (%s): empty setting" , str );
53
+
54
+ /* end of string? then return NULL */
52
55
if ( !(* str ) )
53
56
return NULL ;
54
-
57
+
58
+ /* OK, at beginning of non-NULL string... */
55
59
start = str ;
56
-
60
+
57
61
/*
58
62
* count chars in token until we hit white space or comma
59
63
* or '=' or end of string
60
64
*/
61
- while ( * str && * str != ' ' && * str != '\t'
62
- && * str != ',' && * str != '=' )
65
+ while ( * str && (! isspace ( * str ))
66
+ && * str != ',' && * str != '=' )
63
67
{
64
68
str ++ ;
65
69
len ++ ;
66
70
}
67
71
68
- * tok = (char * ) palloc (len + 1 );
72
+ * tok = (char * ) PALLOC (len + 1 );
69
73
strncpy (* tok , start , len );
70
74
(* tok )[len ] = '\0' ;
71
75
72
76
/* skip white spaces */
73
- while ( * str == ' ' || * str == '\t' )
74
- str ++ ;
75
-
76
- if ( !(* str ) )
77
- return (NULL );
78
- if ( * str == ',' )
77
+ while ( isspace (* str )) str ++ ;
78
+
79
+ /* end of string? */
80
+ if ( !(* str ) ) {
81
+ return (str );
82
+
83
+ /* delimiter? */
84
+ } else if ( * str == ',' ) {
79
85
return (++ str );
80
86
81
- if ( * str != '=' )
87
+ } else if (( val == NULL ) || ( * str != '=' )) {
82
88
elog (WARN , "Syntax error near (%s)" , str );
89
+ };
83
90
84
91
str ++ ; /* '=': get value */
85
92
len = 0 ;
86
93
87
94
/* skip white spaces */
88
- while ( * str == ' ' || * str == '\t' )
89
- str ++ ;
95
+ while ( isspace (* str )) str ++ ;
90
96
91
97
if ( * str == ',' || !(* str ) )
92
98
elog (WARN , "Syntax error near (=%s)" , str );
93
99
94
100
start = str ;
95
101
96
102
/*
97
- * count chars in token' value until we hit white space or comma
103
+ * count chars in token's value until we hit white space or comma
98
104
* or end of string
99
105
*/
100
- while ( * str && * str != ' ' && * str != '\t' && * str != ',' )
106
+ while ( * str && (! isspace ( * str )) && * str != ',' )
101
107
{
102
108
str ++ ;
103
109
len ++ ;
104
110
}
105
111
106
- * val = (char * ) palloc (len + 1 );
112
+ * val = (char * ) PALLOC (len + 1 );
107
113
strncpy (* val , start , len );
108
114
(* val )[len ] = '\0' ;
109
115
110
116
/* skip white spaces */
111
- while ( * str == ' ' || * str == '\t' )
112
- str ++ ;
117
+ while ( isspace (* str )) str ++ ;
113
118
114
119
if ( !(* str ) )
115
120
return (NULL );
@@ -120,23 +125,23 @@ static const char *get_token(char **tok, char **val, const char *str)
120
125
121
126
return str ;
122
127
}
123
-
128
+
124
129
/*-----------------------------------------------------------------------*/
125
130
static bool parse_null (const char * value )
126
131
{
127
132
return TRUE;
128
133
}
129
-
134
+
130
135
static bool show_null (const char * value )
131
136
{
132
137
return TRUE;
133
138
}
134
-
139
+
135
140
static bool reset_null (const char * value )
136
141
{
137
142
return TRUE;
138
143
}
139
-
144
+
140
145
static bool parse_geqo (const char * value )
141
146
{
142
147
const char * rest ;
@@ -146,8 +151,8 @@ static bool parse_geqo (const char *value)
146
151
if ( tok == NULL )
147
152
elog (WARN , "Value undefined" );
148
153
149
- if ( rest )
150
- elog (WARN , "Unacceptable data (%s) " , rest );
154
+ if (( rest ) && ( * rest != '\0' ) )
155
+ elog (WARN , "Unable to parse '%s' " , value );
151
156
152
157
if ( strcasecmp (tok , "on" ) == 0 )
153
158
{
@@ -158,29 +163,29 @@ static bool parse_geqo (const char *value)
158
163
geqo_rels = pg_atoi (val , sizeof (int32 ), '\0' );
159
164
if ( geqo_rels <= 1 )
160
165
elog (WARN , "Bad value for # of relations (%s)" , val );
161
- pfree (val );
166
+ PFREE (val );
162
167
}
163
168
_use_geqo_ = true;
164
169
_use_geqo_rels_ = geqo_rels ;
165
170
}
166
171
else if ( strcasecmp (tok , "off" ) == 0 )
167
172
{
168
- if ( val != NULL )
169
- elog (WARN , "Unacceptable data (%s)" , val );
173
+ if (( val != NULL ) && ( * val != '\0' ) )
174
+ elog (WARN , "%s does not allow a parameter" , tok );
170
175
_use_geqo_ = false;
171
176
}
172
177
else
173
178
elog (WARN , "Bad value for GEQO (%s)" , value );
174
179
175
- pfree (tok );
180
+ PFREE (tok );
176
181
return TRUE;
177
182
}
178
183
179
184
static bool show_geqo ()
180
185
{
181
186
182
187
if ( _use_geqo_ )
183
- elog (NOTICE , "GEQO is ON begining with %d relations" , _use_geqo_rels_ );
188
+ elog (NOTICE , "GEQO is ON beginning with %d relations" , _use_geqo_rels_ );
184
189
else
185
190
elog (NOTICE , "GEQO is OFF" );
186
191
return TRUE;
@@ -197,7 +202,7 @@ static bool reset_geqo ()
197
202
_use_geqo_rels_ = GEQO_RELS ;
198
203
return TRUE;
199
204
}
200
-
205
+
201
206
static bool parse_r_plans (const char * value )
202
207
{
203
208
@@ -231,7 +236,7 @@ static bool reset_r_plans ()
231
236
#endif
232
237
return TRUE;
233
238
}
234
-
239
+
235
240
static bool parse_cost_heap (const char * value )
236
241
{
237
242
float32 res = float4in ((char * )value );
@@ -278,16 +283,13 @@ static bool reset_cost_index ()
278
283
279
284
static bool parse_date (const char * value )
280
285
{
281
- char * tok , * val ;
286
+ char * tok ;
282
287
int dcnt = 0 , ecnt = 0 ;
283
-
284
- while ((value = get_token (& tok , & val , value )) != 0 )
288
+
289
+ while ((value = get_token (& tok , NULL , value )) != 0 )
285
290
{
286
- if ( val != NULL )
287
- elog (WARN , "Syntax error near (%s)" , val );
288
-
289
291
/* Ugh. Somebody ought to write a table driven version -- mjl */
290
-
292
+
291
293
if (!strcasecmp (tok , "iso" ))
292
294
{
293
295
DateStyle = USE_ISO_DATES ;
@@ -324,15 +326,15 @@ static bool parse_date(const char *value)
324
326
{
325
327
elog (WARN , "Bad value for date style (%s)" , tok );
326
328
}
327
- pfree (tok );
329
+ PFREE (tok );
328
330
}
329
-
331
+
330
332
if (dcnt > 1 || ecnt > 1 )
331
333
elog (NOTICE , "Conflicting settings for date" );
332
334
333
335
return TRUE;
334
336
}
335
-
337
+
336
338
static bool show_date ()
337
339
{
338
340
char buf [64 ];
@@ -357,15 +359,15 @@ static bool show_date()
357
359
358
360
return TRUE;
359
361
}
360
-
362
+
361
363
static bool reset_date ()
362
364
{
363
365
DateStyle = USE_POSTGRES_DATES ;
364
366
EuroDates = FALSE;
365
367
366
368
return TRUE;
367
369
}
368
-
370
+
369
371
/*-----------------------------------------------------------------------*/
370
372
struct VariableParsers
371
373
{
@@ -390,13 +392,13 @@ struct VariableParsers
390
392
bool SetPGVariable (const char * name , const char * value )
391
393
{
392
394
struct VariableParsers * vp ;
393
-
395
+
394
396
for (vp = VariableParsers ; vp -> name ; vp ++ )
395
397
{
396
398
if (!strcasecmp (vp -> name , name ))
397
399
return (vp -> parser )(value );
398
400
}
399
-
401
+
400
402
elog (NOTICE , "Unrecognized variable %s" , name );
401
403
402
404
return TRUE;
@@ -406,13 +408,13 @@ bool SetPGVariable(const char *name, const char *value)
406
408
bool GetPGVariable (const char * name )
407
409
{
408
410
struct VariableParsers * vp ;
409
-
411
+
410
412
for (vp = VariableParsers ; vp -> name ; vp ++ )
411
413
{
412
414
if (!strcasecmp (vp -> name , name ))
413
415
return (vp -> show )();
414
416
}
415
-
417
+
416
418
elog (NOTICE , "Unrecognized variable %s" , name );
417
419
418
420
return TRUE;
@@ -422,13 +424,13 @@ bool GetPGVariable(const char *name)
422
424
bool ResetPGVariable (const char * name )
423
425
{
424
426
struct VariableParsers * vp ;
425
-
427
+
426
428
for (vp = VariableParsers ; vp -> name ; vp ++ )
427
429
{
428
430
if (!strcasecmp (vp -> name , name ))
429
431
return (vp -> reset )();
430
432
}
431
-
433
+
432
434
elog (NOTICE , "Unrecognized variable %s" , name );
433
435
434
436
return TRUE;
0 commit comments