3
* Scanner for the configuration file
5
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
7
* $PostgreSQL: pgsql/src/backend/utils/misc/guc-file.l,v 1.29 2005-01-01 05:43:08 momjian Exp $
17
#include "miscadmin.h"
18
#include "storage/fd.h"
19
#include "utils/guc.h"
21
/* Avoid exit() on fatal scanner errors (a bit ugly -- see yy_fatal_error) */
22
#define fprintf(file, fmt, msg) ereport(ERROR, (errmsg_internal("%s", msg)))
24
static unsigned ConfigFileLineno;
32
GUC_UNQUOTED_STRING = 6,
38
/* prototype, so compiler is happy with our high warnings setting */
40
static char *GUC_scanstr(char *);
44
%option never-interactive
54
INTEGER {SIGN}?({DIGIT}+|0x{HEXDIGIT}+)
56
EXPONENT [Ee]{SIGN}?{DIGIT}+
57
REAL {SIGN}?{DIGIT}*"."{DIGIT}*{EXPONENT}?
59
LETTER [A-Za-z_\200-\377]
60
LETTER_OR_DIGIT [A-Za-z_0-9\200-\377]
62
ID {LETTER}{LETTER_OR_DIGIT}*
63
QUALIFIED_ID {ID}"."{ID}
65
UNQUOTED_STRING {LETTER}({LETTER_OR_DIGIT}|[-._:/])*
66
STRING \'([^'\n]|\\.)*\'
70
\n ConfigFileLineno++; return GUC_EOL;
71
[ \t\r]+ /* eat whitespace */
72
#.*$ /* eat comment */
75
{QUALIFIED_ID} return GUC_QUALIFIED_ID;
76
{STRING} return GUC_STRING;
77
{UNQUOTED_STRING} return GUC_UNQUOTED_STRING;
78
{INTEGER} return GUC_INTEGER;
79
{REAL} return GUC_REAL;
87
struct name_value_pair
91
struct name_value_pair *next;
96
* Free a list of name/value pairs, including the names and the values
99
free_name_value_list(struct name_value_pair * list)
101
struct name_value_pair *item;
106
struct name_value_pair *save;
118
* Official function to read and process the configuration file. The
119
* parameter indicates in what context the file is being read --- either
120
* postmaster startup (including standalone-backend startup) or SIGHUP.
121
* All options mentioned in the configuration file are set to new values.
122
* If an error occurs, no values will be changed.
125
ProcessConfigFile(GucContext context)
128
int token, parse_state;
129
char *opt_name, *opt_value;
130
struct name_value_pair *item, *head, *tail;
133
Assert(context == PGC_POSTMASTER || context == PGC_SIGHUP);
135
if (context == PGC_SIGHUP)
138
* To avoid cluttering the log, only the postmaster bleats loudly
139
* about problems with the config file.
141
elevel = IsUnderPostmaster ? DEBUG2 : LOG;
146
fp = AllocateFile(ConfigFileName, "r");
150
(errcode_for_file_access(),
151
errmsg("could not open configuration file \"%s\": %m",
162
opt_name = opt_value = NULL;
163
ConfigFileLineno = 1;
165
while ((token = yylex()))
169
case 0: /* no previous input */
170
if (token == GUC_EOL) /* empty line */
172
if (token != GUC_ID && token != GUC_QUALIFIED_ID)
174
opt_name = pstrdup(yytext);
178
case 1: /* found name */
179
/* ignore equals sign */
180
if (token == GUC_EQUALS)
183
if (token != GUC_ID && token != GUC_STRING &&
184
token != GUC_INTEGER &&
186
token != GUC_UNQUOTED_STRING)
188
opt_value = pstrdup(yytext);
189
if (token == GUC_STRING)
191
/* remove the beginning and ending quote/apostrophe */
192
/* first: shift the whole thing down one character */
193
memmove(opt_value, opt_value+1, strlen(opt_value)-1);
194
/* second: null out the 2 characters we shifted */
195
opt_value[strlen(opt_value)-2] = '\0';
196
/* do the escape thing. pfree()'s the pstrdup above */
197
opt_value = GUC_scanstr(opt_value);
202
case 2: /* now we'd like an end of line */
203
if (token != GUC_EOL)
206
if (strcmp(opt_name, "custom_variable_classes") == 0)
209
* This variable must be processed first as it controls
210
* the validity of other variables; so apply immediately.
212
if (!set_config_option(opt_name, opt_value, context,
213
PGC_S_FILE, false, true))
226
item = palloc(sizeof *item);
227
item->name = opt_name;
228
item->value = opt_value;
245
* Check if all options are valid
247
for(item = head; item; item=item->next)
249
if (!set_config_option(item->name, item->value, context,
250
PGC_S_FILE, false, false))
254
/* If we got here all the options parsed okay, so apply them. */
255
for(item = head; item; item=item->next)
257
set_config_option(item->name, item->value, context,
258
PGC_S_FILE, false, true);
262
free_name_value_list(head);
267
free_name_value_list(head);
268
if (token == GUC_EOL)
270
(errcode(ERRCODE_SYNTAX_ERROR),
271
errmsg("syntax error in file \"%s\" line %u, near end of line",
272
ConfigFileName, ConfigFileLineno - 1)));
275
(errcode(ERRCODE_SYNTAX_ERROR),
276
errmsg("syntax error in file \"%s\" line %u, near token \"%s\"",
277
ConfigFileName, ConfigFileLineno, yytext)));
285
* if the string passed in has escaped codes, map the escape codes to actual
288
* the string returned is palloc'd and should eventually be pfree'd by the
289
* caller; also we assume we should pfree the input string.
301
if (s == NULL || s[0] == '\0')
309
newStr = palloc(len + 1); /* string cannot get longer */
311
for (i = 0, j = 0; i < len; i++)
346
s[i + k] >= '0' && s[i + k] <= '7' && k < 3;
348
octVal = (octVal << 3) + (s[i + k] - '0');
350
newStr[j] = ((char) octVal);